<?php include 'include/game.php'; //Starting and initializing game $deck = startGame($deck); $cardAmount = generateCardAmount($cardAmount); $score = calculateScore($cardAmount, $deck, $score); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame Remove this if you use the .htaccess --> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Silverjack</title> <meta name="description" content=""> <meta name="author" content="The Incompetent Tigers"> <meta name="viewport" content="width=device-width; initial-scale=1.0"> <!-- External CSS --> <link href="css/style.css" rel="stylesheet" /> </head>
<?php if ($_SERVER["REQUEST_METHOD"] == "GET") { if (isset($_GET["start"]) && isset($_GET["gameid"])) { $gameid = $_GET["gameid"]; startGame($gameid); assignRoles($gameid); } } function startGame($gameid) { $servername = "localhost"; $username = "******"; $password = ""; $dbname = "mafia"; try { $conn = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "UPDATE mafia SET status = 1 WHERE gameid = '{$gameid}'"; $conn->exec($sql); } catch (PDOException $e) { //echo $sql . "<br>" . $e->getMessage(); } $conn = null; } function assignRoles($gameid) { $servername = "localhost"; $username = "******"; $password = ""; $dbname = "mafia";
trace("Start games that need to be started"); // select all pending games $sql = "SELECT gameId, name FROM games WHERE state='PENDING' AND startDate < '{$date}';"; $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); while ($row = mysql_fetch_assoc($result)) { $gameId = $row['gameId']; $name = $row['name']; trace("Checking {$name}"); $players = array(); // Find the players that are waiting for a game. $sql = "SELECT playerId FROM participations WHERE gameId='{$gameId}'"; $result2 = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); while ($row = mysql_fetch_assoc($result2)) { array_push($players, intval($row['playerId'])); } startGame($gameId, $name, $players); } function startGame($gameId, $gameName, $players) { $playerNumber = count($players); if ($playerNumber < 3) { return; } $date = getDateNow(); $dateLimit = getDateLimit(); // Start the game $sql = "UPDATE games SET state='ACTIVE' WHERE gameId='{$gameId}' LIMIT 1;"; mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]); // Randomize the players shuffle($players); $assassinationList = '';
function handleMessage($tst_msg, $userSocket) { global $openGames; switch ($tst_msg->type) { case "message": $user_name = $tst_msg->name; //sender name $user_message = $tst_msg->message; //message text $user_color = $tst_msg->color; //color //prepare data to be sent to client $response_text = mask(json_encode(array('type' => 'usermsg', 'name' => $user_name, 'message' => $user_message, 'color' => $user_color))); send_message($response_text); //send data echo "User: "******"Send message " . $response_text . "<br>"; break; //exist this loop //exist this loop case "move": makeMove($tst_msg->gameID, $tst_msg->playerID, $tst_msg->oldSpot, $tst_msg->newSpot); echo "process a move from user " . $userSocket . "\n"; break; case "showOpenGames": echo "Show open games:\n"; print_r($openGames); $response_text = mask(json_encode(array('type' => 'script', 'message' => 'showGames([' . implode(",", $openGames) . '])'))); send_message($response_text); //send data break; case "startGame": startGame($tst_msg); //$response_text = mask(json_encode(array('type'=>'script', 'name'=>'nada', 'message'=>'console.log("recveive a script message")'))); //send_message($response_text); //send data break; case "join": joinGame($tst_msg, $userSocket); break; case "newGame": createGame($tst_msg->playerID, $userSocket); break; } }
<?php $gameID = 'ygvd1z3kzeqxuygt1ycgzg'; $gameName = 'Empire of the sinking sun'; startGame($gameID); //todo: http://play.textadventures.co.uk/KeepAlive.ashx function startGame($gameID) { error_reporting(0); $api = curl_init('http://play.textadventures.co.uk/Play.aspx?id=' . $gameID); curl_setopt($api, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($api, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($api, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($api, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($api); $dom = new DOMDocument(); $dom->loadHTML($result); $viewState = $dom->getElementById('__VIEWSTATE'); $viewStateGenerator = $dom->getElementById('__VIEWSTATEGENERATOR'); $eventValidation = $dom->getElementById('__EVENTVALIDATION'); $viewState = $viewState->attributes->getNamedItem('value')->nodeValue; $viewStateGenerator = $viewStateGenerator->attributes->getNamedItem('value')->nodeValue; $eventValidation = $eventValidation->attributes->getNamedItem('value')->nodeValue; echo '"' . $eventValidation . '"<br>'; echo '"' . $viewState . '"<br>'; echo '"' . $viewStateGenerator . '"<br>'; echo '------------------<br>'; error_reporting(-1); //sleep(1); startGame_stage2($gameID, $viewState, $viewStateGenerator, $eventValidation); }
//Decrement days left where people are zombies mysqli_query($con, "update _" . $dates[0] . " set daysLeft=daysLeft - 1 where status=0") or die("Error: " . mysqli_error($con)); echo "Decremented daysLeft on all zombies.<br>"; //Kill people who have no days left mysqli_query($con, "update _" . $dates[0] . " set status=-1 where daysLeft<1") or die("Error: " . mysqli_error($con)); echo "Killed all zombies with no days left to live.<br>"; } //Check which button was pressed if (isset($_POST["initServer"])) { initiateServer(dbConnect()); } if (isset($_POST["endGame"])) { endGame(dbConnect()); } if (isset($_POST["scheduleZombies"])) { scheduleZombies(dbConnect()); } if (isset($_POST["scheduleAssassins"])) { scheduleAssassins(dbConnect()); } if (isset($_POST["startGame"])) { startGame(dbConnect()); } if (isset($_POST["newDay"])) { newDay(dbConnect()); } ?> </body> </html>
echo "<input type=hidden name=engage value=2>"; echo "<input type=hidden name=swordfish value={$swordfish}>"; echo "<input type=submit value=Next>"; echo "</form>"; break; case "9": transferData(2); echo "Copied players, accounts and zones.<br>Click next to restart game!"; echo "<form action=new_game.php method=post>"; echo "<input type=hidden name=step value=10>"; echo "<input type=hidden name=engage value=2>"; echo "<input type=hidden name=swordfish value={$swordfish}>"; echo "<input type=submit value=Next>"; echo "</form>"; break; case "10": startGame(); echo "Game restarted!<BR>"; break; default: echo "<form action=new_game.php method=post>"; echo "Password: <input type=password name=swordfish size=20 maxlength=20> "; echo "<input type=submit value=Submit><input type=hidden name=step value=1>"; echo "<input type=reset value=Reset>"; echo "</form>"; break; } $StopTime = $BenchmarkTimer->stop(); $Elapsed = $BenchmarkTimer->elapsed(); PrintFlush("<br>Elapsed Time: {$Elapsed}"); include "footer.php";