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; }
<?php require_once dirname(__FILE__) . '/../classes/WarOfNationsDataExtractor.class.php'; require_once dirname(__FILE__) . '/../classes/data/Device.class.php'; $de = new WarOfNationsDataExtractor(); $a = new WarOfNationsAuthentication(); $params = array('session_id' => mt_rand(1000000, 9999999)); $device = DeviceDAO::getActiveDevice($de->db); $de->AddCacheParam('device_id', $device['device_uuid']); $de->AddCacheParam('mac_address', $device['mac_address']); $de->AddCacheParam('device_platform', $device['platform']); $de->AddCacheParam('device_version', $device['version']); $de->AddCacheParam('device_type', $device['device_type']); $de->BuildRequest('AUTHENTICATE', $params);