function __construct($db)
 {
     $this->db = $db;
     $this->request_cache = array();
     $this->params_cache = array();
     $this->params_cache['game_data_version'] = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'GAME_INFO', 'DATA_VERSION');
     $this->params_cache['game_name'] = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'GAME_INFO', 'NAME');
     $this->params_cache['client_build'] = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'CLIENT', 'BUILD');
     $this->params_cache['client_version'] = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'CLIENT', 'VERSION');
     $this->params_cache['api_version'] = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'API', 'VERSION');
     $url_base = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'URL_BASE');
     $hmac_key = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'TOKENS', 'HMAC_KEY');
     $proxies = ProxyDAO::getActiveProxies($this->db);
     $this->ws = new WarOfnationsWS($this->db, $proxies, $url_base, $hmac_key);
 }
 function SendWarningText($message, $ringer = false, $debug = 0)
 {
     // If we need to get the alert immediately, turn on the ringer
     if ($ringer) {
         $message = PgrmConfigDAO::getConfigProperty($this->db, 'SMTP', 'SERVER', 'value1') . ' | ' . $message;
     }
     $log_seq = 0;
     $func_args = func_get_args();
     $func_log_id = DataLoadLogDAO::startFunction($this->db, $this->data_load_id, __CLASS__, __FUNCTION__, $func_args);
     //Create a new PHPMailer instance
     $mail = new PHPMailer();
     //Tell PHPMailer to use SMTP
     $mail->isSMTP();
     //Enable SMTP debugging
     // 0 = off (for production use)
     // 1 = client messages
     // 2 = client and server messages
     $mail->SMTPDebug = $debug;
     //Ask for HTML-friendly debug output
     $mail->Debugoutput = 'html';
     //Set the hostname of the mail server
     $server = PgrmConfigDAO::getConfigProperties($this->db, 'SMTP', 'SERVER');
     $mail->Host = $server['value1'];
     //Set the SMTP port number - likely to be 25, 465 or 587
     $mail->Port = $server['value2'];
     //Whether to use SMTP authentication
     $mail->SMTPAuth = true;
     //Username to use for SMTP authentication
     $credentials = PgrmConfigDAO::getConfigProperties($this->db, 'SMTP', 'CREDENTIALS');
     $mail->Username = $credentials['value1'];
     //Password to use for SMTP authentication
     $mail->Password = $credentials['value2'];
     //Set who the message is to be sent from
     $from_email = PgrmConfigDAO::getConfigProperties($this->db, 'SMTP', 'FROM_EMAIL');
     $mail->setFrom($from_email['value1'], $from_email['value2']);
     //Set who the message is to be sent to
     $text_to = PgrmConfigDAO::getConfigProperties($this->db, 'SMTP', 'WARNING_TEXT_TO');
     $mail->addAddress($text_to['value1'], $text_to['value2']);
     //Set the subject line
     $mail->Subject = '';
     //Set the body of the message
     $mail->isHTML(false);
     $mail->Body = $message;
     //send the message, check for errors
     if (!$mail->send()) {
         echo "Mailer Error: " . $mail->ErrorInfo . "\r\n";
         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', 'Error Sending Message', $mail->ErrorInfo, 1);
         DataLoadLogDAO::completeFunction($this->db, $func_log_id, 'Error Sending Message', 1);
         return false;
     } else {
         //echo "Message sent!";
         DataLoadLogDAO::completeFunction($this->db, $func_log_id, 'Message Sent');
         return true;
     }
 }
 public function Authenticate($new = false, $device_id = false, $return_full_response = false)
 {
     /*
     POST /hc//index.php/json_gateway?svc=BatchController.authenticate_iphone HTTP/1.1
     Accept: application/json
     Content-type: application/json; charset=UTF-8;
     X-Signature: d9bf3c4270e31b7e5d88d80d017d2a32
     X-Timestamp: 1410113097
     User-Agent: Dalvik/1.4.0 (Linux; U; Android 2.3.4; DROID3 Build/5.5.1_84_D3G-66_M2-10)
     Host: gcand.gree-apps.net
     Connection: Keep-Alive
     Content-Length: 630
     Accept-Encoding: gzip
     
     [{"mac_address":"c8:aa:21:40:0a:2a","identifier_for_vendor":"8763af18eb4deace1840060a3bd9086b","app_uuid":"8763af18eb4deace1840060a3bd9086b","udid":"8763af18eb4deace1840060a3bd9086b"},{"android_version":"2.3.4","platform":"android","transaction_time":1410113097979,"session_id":"8509859","data_connection_type":"WiFi","client_static_table_data":{"active":"hc_20140829_38449","using":"hc_20140829_38449"},"device_type":"DROID3","seconds_from_gmt":-18000,"game_data_version":"hc_20140829_38449","client_build":"251","game_name":"HCGame","client_version":"1.8.4"},[{"service":"start.game","method":"load","_explicitType":"Command"}]]
     */
     $log_seq = 0;
     $func_args = func_get_args();
     $func_log_id = DataLoadLogDAO::startFunction($this->db, $this->data_load_id, __CLASS__, __FUNCTION__, $func_args);
     // If we've previously been authenticated, don't re-authenticate as a different account
     if ($this->authenticated && $new === false && $device_id === false) {
         $new = false;
         $device_id = $this->local_device_id;
     }
     // If we're not making a new device, then get the active device from our database
     if (!$new) {
         if (!($device_id === false)) {
             $device = DeviceDAO::getDeviceById($this->db, $device_id);
         } else {
             $device = DeviceDAO::getActiveDevice($this->db);
         }
         $this->local_device_id = $device['id'];
         $this->device_id = $device['device_uuid'];
         $this->mac_address = $device['mac_address'];
         $this->device_platform = $device['platform'];
         $this->device_version = $device['version'];
         $this->device_type = $device['device_type'];
         $this->use_proxy = $device['use_proxy'];
     } else {
         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', 'Creating New Device');
         $this->device_id = self::generate_device_id();
         $this->mac_address = self::generate_mac_address();
         $this->device_platform = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'NEW_DEVICE', 'PLATFORM');
         $this->device_version = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'NEW_DEVICE', 'VERSION');
         $this->device_type = PgrmConfigDAO::getConfigProperty($this->db, 'value1', 'NEW_DEVICE', 'TYPE');
         $this->use_proxy = 1;
     }
     if ($this->use_proxy == 0) {
         $this->de->DisableProxy();
     }
     // Cache our device information as parameters in the data extractor
     $this->de->AddCacheParam('device_id', $this->device_id);
     $this->de->AddCacheParam('mac_address', $this->mac_address);
     $this->de->AddCacheParam('device_platform', $this->device_platform);
     $this->de->AddCacheParam('device_version', $this->device_version);
     $this->de->AddCacheParam('device_type', $this->device_type);
     $this->de->AddCacheParam('session_id', self::generate_session_id());
     $log_msg = "Device ID: {$this->device_id}\r\nMAC Address: {$this->mac_address}\r\nDevice Platform: {$this->device_platform}\r\nDevice Version: {$this->device_version}\r\nDevice Type: {$this->device_type}";
     DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'DATA', "Authenticating as Device ID: {$this->device_id}", $log_msg);
     echo "Authenticating...\r\n";
     $response = $this->de->MakeRequest('AUTHENTICATE');
     if (!$response) {
         return false;
     }
     echo "Done!\r\n\r\n";
     // Save the player ID and Session ID
     $this->user_id = $response['metadata']['user']['id'];
     $this->player_id = $response['metadata']['user']['active_player_id'];
     $this->session_id = $response['session']['session_id'];
     // Cache the player ID so that we have it for other requests later
     $this->de->AddCacheParam('player_id', $this->player_id);
     //$log_msg = "Player ID: {$this->player_id}, Session ID: {$this->session_id}";
     // If this was a new device, then save it to the database for future use
     if ($new) {
         $device = new Device();
         $device->device_uuid = $this->device_id;
         $device->mac_address = $this->mac_address;
         $device->platform = $this->device_platform;
         $device->version = $this->device_version;
         $device->device_type = $this->device_type;
         $device->use_proxy = 1;
         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'DATA', "Saving New Device", print_r($device, true));
         $this->local_device_id = DeviceDAO::insertDevice($this->db, $device);
         if ($this->db->hasError()) {
             echo 'Error creating Device: ';
             print_r($this->db->getError());
             echo "\r\n";
             $log_msg = print_r($device, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
             DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error Saving New Device", $log_message, 1);
         }
         $this->local_user_id = PgrmUserDAO::createUser($this->db, $this->user_id, $this->local_device_id);
         if ($this->db->hasError()) {
             echo 'Error creating User: '******'ERROR', "Error Saving New User", $log_msg, 1);
         }
     }
     // Get the local World ID from our database
     if (!$new) {
         $this->world_id = (int) WorldDAO::getLocalIdFromGameId($this->db, $response['metadata']['player']['world_id']);
     }
     $this->authenticated = true;
     DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Authenticated into World {$this->world_id} as player {$this->player_id}");
     // This allows other features of the program to use additional information about the user if needed after authenticating
     if ($return_full_response) {
         return $response;
     }
     return true;
 }
Пример #4
0
    $device_id = PgrmConfigDAO::getConfigProperty($won->db, 'value1', 'MAIN_DEVICE_ID');
}
// Authenticate
$auth_result = $won->Authenticate(false, $device_id, true);
$last_session_time = time();
//$auth_result = json_decode(file_get_contents('auth_result.json'), true);
//print_r($auth_result['responses'][0]['return_value']['player_towns']);
//print_r($auth_result['responses'][0]['return_value']['player_town_reserves']);
// Get an instance of our game operations class
$game = $won->GetGameOperations();
$unit_map = $game::GetUnitMap();
$log_seq = 0;
$func_log_id = DataLoadLogDAO::startFunction($won->db, $won->data_load_id, 'FlyTroops', 'Main');
while (true) {
    // Check configuration to make sure we aren't supposed to stop - this is the kill switch
    $stop = PgrmConfigDAO::getConfigProperty($won->db, 'value1', 'STOP_TROOP_FLYER');
    if ($stop == 'Y') {
        echo "Stop Signal Detected!\n";
        DataLoadLogDAO::logEvent2($won->db, $func_log_id, $log_seq++, 'INFO', 'Stop Signal Detected!');
        break;
    }
    // If enough time has passed, start out with a new session
    if (time() - $last_session_time > $hours_between_sessions * 60 * 60) {
        DataLoadLogDAO::logEvent2($won->db, $func_log_id, $log_seq++, 'INFO', "At least {$hours_between_sessions} hour(s) have passed. Starting new session.\n");
        // Save the data load for later, we don't want a new one
        $data_load_id = $won->data_load_id;
        // Re-initialize the WarOfNations object
        unset($won);
        $won = new WarOfNations();
        // Set the data load back
        $won->setDataLoadId($data_load_id);