protected function process($user, $message) { #Turn the message into XML to parse. $this->debugLog("Server Process - Processing this: " . $message); $parsedMsg = simplexml_load_string($message); $validLogin = true; if ($parsedMsg !== false) { $response = "<response>"; if (isset($user->playerID) && $user->playerID === -1) { $this->debugLog("Server Process - Attempting to log player in"); #If there is a register node $registered = true; if (isset($parsedMsg->registration)) { #Call registerPlayer.php $registered = registerPlayer($parsedMsg->registration); array_push($this->fullUpdateBacklog, $user); } if ($registered) { #If there is a login node if (isset($parsedMsg->login)) { $this->debugLog("Server Process - Logging player in"); #Call logInPlayer.php to set player info for this user. $user->playerID = logInPlayer($parsedMsg->login, true); #Count how many users are logged into this playerID. $count = 0; foreach ($this->users as $compUser) { if ($compUser->playerID === $user->playerID) { $count++; } } if ($count > 1) { $user->playerID = -1; $response .= "<loginError>That player is already logged in.</loginError>"; } } } } else { if (isset($user->playerID)) { if (isset($parsedMsg->login)) { $checkAgainst = logInPlayer($parsedMsg->login, false); if ($user->playerID !== $checkAgainst) { $validLogin = false; $response .= "<loginError>You are not the same player you logged in as.</loginError>"; } } else { $response .= "<loginError>No login information provided.</loginError>"; } } } if ($user->playerID !== -1 && $validLogin) { $this->debugLog("Server Process - Player is logged in"); $this->debugLog("Server Processing Diagnostics"); $this->debugLog("this->gameCreationTimestamp=" . $this->gameCreationTimestamp); $this->debugLog("this->gameID=" . $this->gameID); $this->debugLog("XML has action = " . isset($parsedMsg->action)); $this->debugLog("XML has chat = " . isset($parsedMsg->chat)); $response .= "<login>1</login>"; if (isset($this->gameID) && $this->gameCreationTimestamp === -1) { #If there is an action node if (isset($parsedMsg->action)) { $this->debugLog("Server Process - Adding found action to queue"); #Call submitAction.php $response .= submitAction($user->playerID, $this->gameID, $parsedMsg->action); $this->debugLog("Server Process - Action addition response " . $response); #Check if we should set up an auto-resolution task or not. $timeToAdd = queryResolutions($this->gameID); if ($timeToAdd !== -1) { $this->resolveActionsTimestamp = time() + $timeToAdd; } } } #If there is a chat node if (isset($parsedMsg->chat)) { $this->debugLog("Server Process - Adding found chat message to chat"); #Call submitGameChat.php $response .= submitGameChat($user->playerID, $parsedMsg->chat); } } else { $response .= "<loginError>You need to log in or register first.</loginError>"; } #Return the compilation of successes/errors to user. $response .= "</response>"; $this->send($user, $response); } else { $this->debugLog("Server Process - Invalid XML sent to server"); } }
} $params = ['index' => 'users', 'type' => 'info', 'id' => $id, 'body' => $body]; return $es->update($params); } function getUserinfo($user) { global $es; $params = ['index' => 'users', 'type' => 'info', 'id' => $user]; $usrInfo = $es->get($params); unset($usrInfo['_source']['email']); return $usrInfo; } $result = submitAction($input->username, 'followers', $_SESSION['username']); $following = getUserinfo($input->username); if ($result['_id']) { $follower = submitAction($_SESSION['username'], 'following', $input->username); if ($follower['_id']) { $userinfo = getUserinfo($_SESSION['username']); echo json_encode(array("userinfoLoggedIn" => $userinfo['_source'], "userinfoScope" => $following['_source'])); } } else { } } else { $abort = true; $errorArray[] = "Invalid action recieved by server."; } } else { $abort = true; $errorArray[] = "Username not recieved by server."; } } else {