<?

include "conf.php";

$data = mysql_connect($base_name, $base_user, $base_pass);
mysql_select_db($db_name,$data);
$sql  = mysql_query("SELECT * FROM users WHERE login='$login'");
$db   = mysql_fetch_array($sql);
$room = $db["room"];
$city = $db["city_game"];
$city2 = $db["city"];

$online = 0;

$SEARCH = mysql_query("SELECT * FROM online WHERE login = '$login'");

	if(mysql_fetch_array($SEARCH)){$online = 1;}
	

	if($online == 0){
	$time = time();
	$INSERT = mysql_query("INSERT INTO online(city,room,login,last_time) VALUES('$city','$room','$login','$time')");
	}
	else if($online == 1){
	$time = time();
	$UPDATE = mysql_query("UPDATE online SET last_time = '$time',room='$room',city='$city' WHERE login = '$login'");
	}

$CLEAR = mysql_query("SELECT * FROM online");

	while($DATA = mysql_fetch_array($CLEAR)){
	$min_time = time() - $DATA["last_time"];
		if($min_time>20){
		$CLEAR_LOGIN = $DATA["login"];
		$DELETE = mysql_query("DELETE FROM online WHERE login='$CLEAR_LOGIN'");
		}
	}

?>