function wsOnMessage($clientID, $message, $messageLength, $binary) { global $Server, $gameArray, $wsClientNames; $ip = long2ip($Server->wsClients[$clientID][6]); $jsonMessage = json_decode($message, true); $action = (string) $jsonMessage["action"]; $data = $jsonMessage["data"]; switch ($action) { case "new": $response = array("action" => "log", "message" => "Creating new game..."); sendJson($clientID, $response); addGame($clientID, $data); break; case "join": $response = array("action" => "log", "message" => "Joining a game"); $gameNumber = (int) $data["game"]; $teamNumber = (int) $data["team"]; sendJson($clientID, $response); joinGame($clientID, $gameNumber, $teamNumber); break; case "leave": $response = array("action" => "log", "message" => "Attempting to leave current game."); sendJson($clientID, $response); leaveGame($clientID); break; case "changename": $wsClientNames[$clientID] = (string) $data; foreach ($Server->wsClients as $id => $client) { if ($id != $clientID) { $response = array("action" => "chat", "message" => (string) $data . " has entered the lobby."); sendJson($id, $response); } } break; case "confirm": confirmClient($clientID); break; case "game": forwardCommand($clientID, $data); break; case "chat": chat($clientID, (string) $data); break; default: $response = array("action" => "log", "message" => "Didn't recognize that command."); sendJson($clientID, $response); } // check if message length is 0 if ($messageLength == 0) { $Server->wsClose($clientID); return; } //foreach ( $Server->wsClients as $id => $client ) //$Server->wsSend($id, "Visitor $clientID ($ip) said \"$message\""); //$Server->wsSend($id, "Server response: ($responseMessage)"); //$arrayCount = (string)count($gameArray); //$Server->wsSend($id, "number of open games: ($arrayCount)"); }
function updateGames($data, $database) { updateDevelopers($data, $database); updateRatings($data, $database); //get game FROM database try { $sql = 'SELECT * FROM game'; $results = $database->query($sql); } catch (Expcetion $e) { echo $e->getMessage(); die; } //gets all game titles in the database and stores in array $inDBGameTitlesArray[] = ""; foreach ($results as $game) { $inDBGameTitle = $game['title']; if (!in_array($inDBGameTitle, $inDBGameTitlesArray)) { $inDBGameTitlesArray[] = $inDBGameTitle; } } //gets all game and game title in JSON and stores in arrays $inJSONGames[] = ""; unset($inJSONGames[0]); foreach ($data['library'] as $game) { $inJSONGameTitle = $game['title']; if (!in_array($inJSONGameTitle, $inDBGameTitlesArray)) { $inJSONGames[] = $game; } } //Adds new games to database foreach ($inJSONGames as $game) { addGame($game, $database); } }
<?php require_once "UserClass.php"; require_once "generalFunctions.php"; session_start(); $refererPage = "mainMenusPage_TABLE.php"; $SelfrefererPage = "gaming.php"; include "validateSession.php"; //validate session //SET PERMISSIONS $allowEditing = $loggedUser->checkIfAllowed("editGames"); /////// END OF VALIDATIONS /////////////// addGame(); /** need to test why duplicate games are entered */ deleteGames(); ?> <html> <style type="text/css"> @import url(zivStyle.css); </style> <script language="javascript" src="javascripts/javaScriptFunctions.js"></script> <head> </head> <body> <FORM method="post" action="gaming.php" name="addGames"> <?php if (isset($_POST[help])) { drawHelpPage(); } else { if (isset($_POST[displayGameId]) && !isset($_POST[add_game]) && !isset($_POST[delete_games])) { drawGameMode($_POST[displayGameId]);