<?php

include("db.php");

// Abgelaufene Sessions löschen
// Multi-Delete funktioniert bei MySQL 5.0 nicht richtig, darum müssen wir das von Hand machen
$deadline = time() - 300;
$result = $db->sql_query("SELECT session_id FROM pacmp_sessions WHERE activity < $deadline");
while($row = $db->sql_fetchrow($result))
{
    $session = $row['session_id'];
    $db->sql_query("DELETE FROM pacmp_table WHERE session_id = $session");
    $db->sql_query("DELETE FROM pacmp_sessions WHERE session_id = $session");
}

// Neue Session anlegen und ID zurückgeben
$now = time();
$db->sql_query("INSERT INTO pacmp_sessions (activity) VALUES($now)");
$session = $db->last_insert_id();
$db->sql_query("INSERT INTO pacmp_table (session_id, player_id, x, y) VALUES ($session, 1, 18, 13)");
$db->sql_query("INSERT INTO pacmp_table (session_id, player_id, x, y) VALUES ($session, 2, 15, 13)");

header('text/plain');
echo $session;

?>