Пример #1
0
<?php

require_once dirname(__FILE__) . '/../classes/WarOfNations2.class.php';
require_once dirname(__FILE__) . '/../classes/data/DataLoad.class.php';
if (count($argv) == 2) {
    $world = $argv[1];
    echo "Got Command Line Argument for World [{$world}]\r\n";
} else {
    $world = 13;
    echo "No Command Line Argument Found.  Using Default World [{$world}]\r\n";
}
$won = new WarOfNations();
$won->setDataLoadId(DataLoadDAO::initNewLoad($won->db, 'JOIN_WORLD', 0, "World {$world}"));
DataLoadDAO::startLoad($won->db, $won->data_load_id);
$won->JoinNewWorld($world);
DataLoadDAO::loadComplete($won->db, $won->data_load_id);
 private function ValidateResponse($json_array, $func_log_id, $request_id)
 {
     // These statuses will trigger an error state but not kill the program
     $response_whitelist = array('EVENT_QUEUE_EXECUTE_NOW_FAILED');
     // Validate that the request completed successfully
     if ($json_array['status'] == 'OK' && array_key_exists(0, $json_array['responses']) && array_key_exists('status', $json_array['responses'][0])) {
         if ($json_array['responses'][0]['status'] == 'OK') {
             DataLoadLogDAO::completeFunction($this->db, $func_log_id, 'Request Successful');
         } elseif (in_array($json_array['responses'][0]['status'], $response_whitelist)) {
             $status_str = "Statuses: [{$json_array['status']}], [{$json_array['responses'][0]['status']}]";
             echo "Request Failed.  {$status_str}\nContinuing...\n";
             DataLoadLogDAO::webServiceStatusFailure($this->db, $request_id);
             DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Request Failed.  {$status_str}", 1);
             return 'retry';
         } else {
             $status_str = "Statuses: [{$json_array['status']}], [{$json_array['responses'][0]['status']}]";
             DataLoadLogDAO::webServiceStatusFailure($this->db, $request_id);
             DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Request Failed.  {$status_str}", 1);
             DataLoadDAO::loadFailed($this->db, $this->data_load_id);
             die("Data Load Failed. {$status_str}\n");
         }
     } elseif (array_key_exists(0, $json_array['responses']) && substr($json_array['responses'][0], 0, 9) === 'EXCEPTION') {
         $status_str = "Statuses: [{$json_array['status']}], [{$json_array['responses'][0]}]";
         echo "Request Failed.  {$status_str}\nContinuing...\n";
         DataLoadLogDAO::webServiceStatusFailure($this->db, $request_id);
         DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Request Failed.  {$status_str}", 1);
         return 'retry';
     } else {
         $status_str = "Statuses: [{$json_array['status']}], [{$json_array['responses'][0]}]";
         DataLoadLogDAO::webServiceStatusFailure($this->db, $request_id);
         DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Request Failed.  {$status_str}", 1);
         DataLoadDAO::loadFailed($this->db, $this->data_load_id);
         die("Data Load Failed. {$status_str}\n");
     }
     return true;
 }
<?php

require_once dirname(__FILE__) . '/../classes/WarOfNations2.class.php';
require_once dirname(__FILE__) . '/../classes/data/DataLoad.class.php';
$won = new WarOfNations();
$won->setDataLoadId(DataLoadDAO::initNewLoad($won->db, 'TEST_LEADERBOARDS2', 0));
DataLoadDAO::startLoad($won->db, $won->data_load_id);
$won->GetLeaderboard(1, 0);
<?php

require_once dirname(__FILE__) . '/../classes/WarOfNations2.class.php';
require_once dirname(__FILE__) . '/../classes/data/DataLoad.class.php';
$won = new WarOfNations();
$rows_updated = DataLoadDAO::cleanupWebserviceLogs($won->db);
echo "Updated {$rows_updated} web service log records\r\n";
 public function Run()
 {
     $heartbeat_msg = '{"payload":{},"type":"heartbeat"}';
     $log_seq = 0;
     $func_args = func_get_args();
     $func_log_id = DataLoadLogDAO::startFunction($this->db, $this->data_load_id, __CLASS__, __FUNCTION__, $func_args);
     $seconds_between_heartbeat = 30;
     $closed = false;
     while (1) {
         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', "Send heartbeat message");
         echo "Sending: {$heartbeat_msg}\n----------\n";
         $this->client->send($heartbeat_msg);
         $last_heartbeat = microtime(true);
         DataLoadDAO::operationComplete($this->db, $this->data_load_id);
         // This loop controls how many times we will try go receive in between heartbeats
         //for($i = 0; $i < 1; $i++) {
         // Continue reading until we run out of content to read, disconnect, or reach our heartbeat time
         while (1) {
             try {
                 $message_handled = false;
                 $opcode = '';
                 DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', "Listening...");
                 $seconds_since_heartbeat = microtime(true) - $last_heartbeat;
                 echo "Seconds Since Heartbeat: {$seconds_since_heartbeat}\n";
                 $new_timeout = round($seconds_between_heartbeat - $seconds_since_heartbeat, 0);
                 if ($new_timeout <= 0) {
                     break;
                 }
                 echo "New Heartbeat Timeout: {$new_timeout} seconds\n";
                 echo "Receiving: ";
                 $this->client->setTimeout($new_timeout);
                 $data = $this->client->receive();
                 $opcode = $this->client->getLastOpcode();
                 echo "{$opcode}\n";
                 DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'MESSAGE', "Receive Complete [{$opcode}]");
                 //, $data);
                 // Handle special cases here
                 switch ($opcode) {
                     case 'ping':
                         // Respond with pong
                         echo "Sending Pong\n----------\n";
                         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', "Sending pong message");
                         $this->client->send('', 'pong');
                         $message_handled = true;
                         break;
                     case 'close':
                         echo "Received Close.  Disconnecting...\n";
                         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', "Sending pong message");
                         $message_handled = true;
                         $closed = true;
                         break;
                 }
                 // If we already handled this message, go receive a new one
                 if ($message_handled) {
                     break;
                 }
                 try {
                     echo "Trying to decode string\n";
                     $decoded_data = @gzdecode($data);
                     if ($decoded_data == false) {
                         echo "String not compressed\n{$data}\n==========\n";
                         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'MESSAGE', "[{$opcode}] Message Not Compressed", $data);
                     } else {
                         $data = $decoded_data;
                         echo "DECODED:\n{$data}\n==========\n";
                         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'MESSAGE', "Decoded [{$opcode}] message", $data);
                     }
                 } catch (Exception $ex) {
                     echo "Error\n";
                 }
             } catch (Exception $ex) {
                 echo "No Data Found\n";
                 DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "No Data Found [{$opcode}]", $ex->getMessage(), 1);
                 //usleep(5000000);
                 //break;
             }
         }
         //}
         if ($closed) {
             break;
         }
     }
     DataLoadLogDAO::completeFunction($this->db, $func_log_id, 'Finished with Listener, this should never happen');
 }