Example #1
0
 /**
  * Login process
  */
 protected function login()
 {
     $ipAddress = $this->getIpAddress();
     $this->token = $this->getAuthToken();
     $body = new \SabreAMF_TypedObject('com.riotgames.platform.login.AuthenticationCredentials', array('username' => $this->username, 'password' => $this->password, 'authToken' => $this->token, 'clientVersion' => $this->clientVersion, 'ipAddress' => $ipAddress, 'locale' => $this->locale, 'domain' => 'lolclient.lol.riotgames.com', 'operatingSystem' => 'LoLRTMPSClient', 'securityAnswer' => null, 'oldPassword' => null, 'partnerCredentials' => null));
     $response = $this->syncInvoke('loginService', 'login', array($body));
     // Checking errors
     if ('_error' == $response['result']) {
         $root = $response['data']->getData()->rootCause->getAMFData();
         if ('com.riotgames.platform.login.impl.ClientVersionMismatchException' == $root['rootCauseClassname']) {
             $newVersion = $root['substitutionArguments'][1];
             $updateVersion = function () use($newVersion) {
                 $this->logger->alert('Your client version configuration is outdated, it will be automatically updated with this version : ' . $newVersion . ' (configuration key: client.version)');
                 $this->logger->alert('Automatic restart with the new client version...');
                 // Save the new version into the config.yml file
                 $filePath = __DIR__ . '/../../../../config/config.yml';
                 $configs = ConfigurationLoader::getAll();
                 $configs['config']['client']['version'] = $newVersion;
                 $dumper = new Dumper();
                 file_put_contents($filePath, $dumper->dump($configs, 99));
             };
             // Avoid multiple warnings in async
             if (true === ConfigurationLoader::get('client.async.enabled')) {
                 $key = ConfigurationLoader::get('client.async.redis.key') . '.clients.errors.wrong_version';
                 if (null === $this->redis->get($key)) {
                     $updateVersion();
                     $this->redis->set($key, true);
                 }
             } else {
                 $updateVersion();
             }
             $this->clientVersion = $newVersion;
             return $this->reconnect();
         } elseif ('com.riotgames.platform.login.LoginFailedException' == $root['rootCauseClassname']) {
             $this->logger->warning('Client ' . $this . ': error on authentication (normal in case of busy server). Restarting client...');
             sleep(1);
             return $this->reconnect();
         }
     }
     $data = $response['data']->getData();
     $body = $data->body->getAMFData();
     $token = $body['token'];
     $this->accountId = $body['accountSummary']->getAMFData()['accountId'];
     $authToken = strtolower($this->username) . ':' . $token;
     $authToken = base64_encode($authToken);
     $this->syncInvoke('auth', 8, $authToken, 'flex.messaging.messages.CommandMessage');
     $this->syncInvoke('messagingDestination', 0, null, 'flex.messaging.messages.CommandMessage', array('DSSubtopic' => 'bc'), array('clientId' => 'bc-' . $this->accountId));
     $this->syncInvoke("messagingDestination", 0, null, "flex.messaging.messages.CommandMessage", array('DSSubtopic' => 'cn-' . $this->accountId), array('clientId' => 'cn-' . $this->accountId));
     $this->syncInvoke("messagingDestination", 0, null, "flex.messaging.messages.CommandMessage", array('DSSubtopic' => 'gn-' . $this->accountId), array('clientId' => 'gn-' . $this->accountId));
 }