예제 #1
0
파일: server.php 프로젝트: nfriend/Rook
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)");
}
예제 #2
0
파일: Classes.php 프로젝트: nfriend/Rook
 function PrematureEnd($quitId)
 {
     global $gameArray;
     if ($this->State->Location === "table") {
         $playerArray = array();
         if ($this->Team1 && $this->Team1->Player1) {
             array_push($playerArray, $this->Team1->Player1->ClientId);
         }
         if ($this->Team1 && $this->Team1->Player2) {
             array_push($playerArray, $this->Team1->Player2->ClientId);
         }
         if ($this->Team2 && $this->Team2->Player1) {
             array_push($playerArray, $this->Team2->Player1->ClientId);
         }
         if ($this->Team2 && $this->Team2->Player2) {
             array_push($playerArray, $this->Team2->Player2->ClientId);
         }
         foreach ($playerArray as $id) {
             $response = array("action" => "command", "message" => "abortgame", "data" => "");
             if ($quitId !== $id && !is_null($id) && $id != "") {
                 sendJson($id, $response);
             }
             $response = array("action" => "command", "message" => "gainpermission");
             if ($quitId !== $id && !is_null($id) && $id != "") {
                 sendJson($id, $response);
             }
         }
         if ($this->Team1 && $this->Team1->Player1) {
             $this->Team1->Player1 = null;
         }
         if ($this->Team1 && $this->Team1->Player2) {
             $this->Team1->Player2 = null;
         }
         if ($this->Team2 && $this->Team2->Player1) {
             $this->Team2->Player1 = null;
         }
         if ($this->Team2 && $this->Team2->Player2) {
             $this->Team2->Player2 = null;
         }
         $this->DeleteMe = true;
         $index = array_search($this, $gameArray);
         unset($gameArray[$index]);
     } else {
         leaveGame($quitId);
     }
 }