function startDispute($playerId, $gameId, $against, $description) { $date = getDateNow(); // make sure there are more then 2 people in the game $sql = "SELECT * FROM participations WHERE gameId='{$gameId}' AND state='ACTIVE' ;"; $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); if (mysql_num_rows($result) <= 2) { $ret = array("status" => "DISPUTE_DISABLED"); print json_encode($ret); return; } // get the targetId if ($against == 'ASS') { $sql = "SELECT assassinId AS targetId FROM assassinations WHERE state='PENDING' AND gameId='{$gameId}' AND victimId='{$playerId}' LIMIT 1;"; } else { $sql = "SELECT victimId AS targetId FROM assassinations WHERE state='PENDING' AND gameId='{$gameId}' AND assassinId='{$playerId}' LIMIT 1;"; } $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); if ($row = mysql_fetch_assoc($result)) { $targetId = $row['targetId']; } else { $ret = array("status" => "BAD_REQUEST"); print json_encode($ret); return; } // check that the dispute does not already exists $sql = "SELECT * FROM disputes WHERE gameId='{$gameId}' AND accuserId='{$playerId}' AND defendantId='{$targetId}' LIMIT 1;"; $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); if ($row = mysql_fetch_assoc($result)) { $ret = array("status" => "DISPUTE_EXISTS"); print json_encode($ret); return; } // get the number of accuser, defendant disputes $sql = "SELECT disputes FROM participations WHERE gameId='{$gameId}' AND playerId='{$playerId}' LIMIT 1;"; $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); if ($row = mysql_fetch_assoc($result)) { $accuserDisputes = intval($row['disputes']); } else { $ret = array("status" => "IMPOSSIBLE5.1"); die(json_encode($ret)); } $sql = "SELECT disputes FROM participations WHERE gameId='{$gameId}' AND playerId='{$targetId}' LIMIT 1;"; $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); if ($row = mysql_fetch_assoc($result)) { $targetDisputes = intval($row['disputes']); } else { $ret = array("status" => "IMPOSSIBLE5.2"); die(json_encode($ret)); } $sql = "UPDATE participations SET disputes=disputes+1 WHERE gameId='{$gameId}' AND (playerId='{$playerId}' OR playerId='{$targetId}') LIMIT 2;"; mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); // deciede the dispute $trial = rand() / getrandmax(); $p = ($accuserDisputes + 1) / ($accuserDisputes + $targetDisputes + 2); if ($trial < $p) { // accusor lost $won = 'DEF'; $return = 'FAIL'; } else { // accusor won $won = 'ACC'; $return = 'SUCCESS'; if ($against == 'ASS') { killPlayer($targetId, $gameId, false, false); // also insert the assassination by this player $sql = "INSERT INTO assassinations (gameId, assassinId, victimId, state, startDate, endDate, detailsState) VALUES ('{$gameId}', '{$playerId}', '{$targetId}', 'SELF_DEFENSE', '{$date}', '{$date}', 'ADDED');"; mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); } else { killPlayer($targetId, $gameId, true, false); } } // start the dispute $sql = " INSERT INTO disputes (gameId, accuserId, defendantId, won, status, accusation, defense, createdTime, rebutedTime, resolvedTime) "; $sql .= " VALUES ('{$gameId}', '{$playerId}', '{$targetId}', '{$won}', 'CREATED', '{$description}', '', '{$date}', '0000-00-00 00:00:00', '0000-00-00 00:00:00');"; mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); require_once 'handler.php'; handleStartDispute($playerId, $targetId, $won, $description); // return the result $game = getGameObject($playerId, $gameId); $ret = array("status" => "OK", "dispute" => $return, "game" => $game); print json_encode($ret); }
killPlayer(); system('sudo reboot'); header('Location: index.php'); } if (isset($_GET['h'])) { killPlayer(); system('sudo shutdown -hP now'); header('Location: index.php'); } if (isset($_GET['s'])) { killPlayer(); header('Location: index.php'); } if (isset($_GET['p'])) { global $root_folder; killPlayer(); system('sudo screen -dmS player python ' . $root_folder . 'player/player.py'); header('Location: index.php'); } ?> <!DOCTYPE html> <html> <body> <?php // check if a new current file should be set if (isset($_GET['f'])) { if (isset($_GET['o'])) { if ($_GET['o'] == 'u') { if (file_exists($upload_dir . $_GET['f'])) {