예제 #1
0
 public function startNewGame()
 {
     if (XmlRequestValidator::isValidStartPendingGameRequest($this->requestData)) {
         $session = $this->requestData->body->session;
         $size = $this->requestData->body->size;
         if (safe_input::is_valid_session_hash($session) && safe_input::is_number($size) && $size > 1) {
             //chkec if the session hash exists
             $session_info = session::get_session_by_hash($session);
             if ($session_info != null) {
                 $res = Execute::newPendingGame($session, $size);
                 if ($res) {
                     $this->response = XmlBuilder::startNewPendingGameSuccessfullResponse("plain", $session);
                 } else {
                     //faild to add new game
                     Report::error(__METHOD__ . "," . __LINE__, "failed to add new pending game");
                     $this->response = XmlBuilder::failed_response("plain", 5, 0, "failed to add new pending game, try again");
                 }
             } else {
                 //the given hash doesn't exist in the database
                 Report::warning(__METHOD__ . "," . __LINE__, "start new pending game request contains a session hash that does not exist in the database: hash=" . $session);
                 $this->response = XmlBuilder::failed_response("plain", 5, 1, "expired session");
             }
         } else {
             //invalid data passed
             Report::error(__METHOD__ . "," . __LINE__, "start new pending game request contains an incorrectly formatted session hash or game size, size:" . $size);
             $this->response = XmlBuilder::failed_response("plain", 5, 0, "invalid session or gcm id");
         }
     } else {
         //xml request was not formatted correctly
         Report::error(__METHOD__ . "," . __LINE__, "invalid new pending game request!");
         $this->invalidRequest();
     }
 }