include("../SP.pm"); $dbh = db_connect(); $user_login = $_COOKIE[user_login]; $game_id = $_POST[game_id]; $user = $_POST[user]; $action = $_GET[action]; if($game_id=="") { $game_id = $_GET[game_id]; } #print_header($dbh, $user_login, $zoom, $game_id, 2); verify_user_logged_in($user_login, "join_game.php?game_id=$game_id"); if($action=="boot") { $player = $_GET[player]; $game_id = $_GET[game_id]; $game_id+=0; if($game_id==0) { print "error - invalid game_id."; exit; } verify_host($dbh, $user_login, $game_id); $sql = "delete from SP_PLAYER where row_id = '$player'"; execute_sql($dbh, $sql); $player_list = get_sql_item($dbh, "select player_list from SP_GAME where row_id = '$game_id'"); if($player_list=="") { print "error - invalid player_list."; exit; } $player_array = split("\+", $player_list); $new_list=""; foreach($player_array as $player_id) { if($player_id!=$player) { $new_list .= "$player_id+"; } } $new_list=substr($new_list,0,-1); execute_sql($dbh, "update SP_GAME set player_list = '$new_list', orig_player_list = '$new_list' where row_id = '$game_id'"); auto_redirect_linkx($dbh, "show_game.php"); print ""; exit; } if($action=="") $action = $_POST[action]; if($action=="add_computer") { $user_login = "Computer"; } $game_id+=0; if($game_id==0) { print "error - invalid game_id."; exit; } if($user_login=="Rick" and $user != "") { $user_login = $user; } $user_id = get_sql_item($dbh, "select row_id from SP_USER where name = '$user_login'"); if($user_id=="") { print "error - invalid user."; exit; } $player_list = get_sql_item($dbh, "select player_list from SP_GAME where row_id = '$game_id'"); if($player_list=="") { print "error - invalid player_list."; exit; } $player_array = split("\+", $player_list); $player_count=0; foreach($player_array as $player) { $player_count++; $uid = get_sql_item($dbh, "select user from SP_PLAYER where row_id = '$player'"); if($uid == $user_id and $uid != 30) { print "Error, You are already in this game!"; exit; } } $rank = get_sql_item($dbh, "select rank from SP_USER where row_id = '$user_id'"); if($rank<=1) { print "
Sorry, you must complete a singer player game before joining live games!"; exit;
}
$max_players = get_sql_item($dbh, "select max_players from SP_GAME where row_id = '$game_id'");
if($player_count>=$max_players) { print "Sorry, that game is full!"; exit; }
$player_id = create_player($dbh, $game_id, $user_id);
array_push($player_array, $player_id);
$player_list = join("+", $player_array);
# print "player_list: $player_list
";
execute_sql($dbh, "update SP_USER set primary_game = '$game_id' where row_id = '$user_id'");
execute_sql($dbh, "update SP_GAME set player_list = '$player_list', orig_player_list = '$player_list' where row_id = '$game_id'");
$type = get_sql_item($dbh, "select type from SP_GAME where row_id = '$game_id'");
if($type=="locked" and $max_players>2) { print ""; }
else {
$auto_start_flg = get_sql_item($dbh, "select auto_start_flg from SP_GAME where row_id = '$game_id'");
if($auto_start_flg=="Y") {
$num_players = get_num_players2($dbh, $game_id);
$max_players = get_sql_item($dbh, "select max_players from SP_GAME where row_id = '$game_id'");
if($num_players==$max_players) {
auto_redirect_linkx($dbh, "start_game.php?game_id=$game_id");
print "";
mysql_close($dbh);
exit;
}
} #<-- if
auto_redirect_linkx($dbh, "mygames.php");
print "";
} #<-- else
#-----------------------
mysql_close($dbh);
?>