Ejemplo n.º 1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $redis = new Client(sprintf('tcp://%s:%d', ConfigurationLoader::get('client.async.redis.host'), ConfigurationLoader::get('client.async.redis.port')));
     $logger = LoggerFactory::create('Client #' . $input->getArgument('client_id'), true);
     $client = ClientFactory::create($logger, $redis, $input->getArgument('account_key'), $input->getArgument('client_id'), true);
     $connector = new ClientWorker($logger, $client, $redis);
     $connector->listen();
 }
Ejemplo n.º 2
0
 /**
  * Create client instances & auth
  *
  * @return bool True if one or more clients are connected, false otherwise
  *
  * @throws ServerException
  */
 public function connect()
 {
     $this->logger->info('Starting clients...');
     $tmpClients = [];
     $accounts = ConfigurationLoader::get('client.accounts');
     foreach ($accounts as $accountKey => $account) {
         $client = ClientFactory::create($this->logger, $this->redis, $accountKey, $this->getNextClientId());
         $client->authenticate();
         $tmpClients[] = $client;
     }
     $nbClients = count($tmpClients);
     $isAsync = true === ConfigurationLoader::get('client.async.enabled');
     $i = 0;
     $connectedCount = 0;
     /** @var LOLClientInterface $client */
     while ($i < $nbClients) {
         $deleteClients = [];
         foreach ($tmpClients as $j => $client) {
             $isAuthenticated = $client->isAuthenticated();
             if (null !== $isAuthenticated) {
                 if (true === $isAuthenticated) {
                     if (!$isAsync && isset($this->clients[$client->getRegion()])) {
                         throw new ServerException('Multiple account for the same region in synchronous mode is not allowed. Please enable the asynchronous mode in the configuration file');
                     }
                     $this->clients[$client->getRegion()][] = $client;
                     $this->logger->info('Client ' . $client . ' is connected');
                     $connectedCount++;
                 } else {
                     if ($isAsync) {
                         $this->cleanAsyncClients(false, $client);
                     }
                 }
                 $i++;
                 $deleteClients[] = $j;
             }
         }
         foreach ($deleteClients as $deleteClientId) {
             unset($tmpClients[$deleteClientId]);
         }
         if ($isAsync) {
             pcntl_signal_dispatch();
             LoggerFactory::subscribe();
             sleep(1);
         }
     }
     // No connected client, abort
     if (0 == $connectedCount) {
         return false;
     }
     $totalClientCount = count($accounts);
     $message = sprintf('%d/%d client%s successfully connected', $connectedCount, $totalClientCount, $connectedCount > 1 ? 's' : '');
     if ($connectedCount < $totalClientCount) {
         $this->logger->alert('Only ' . $message);
     } else {
         $this->logger->info($message);
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * @param ApiManager $apiManager
  */
 public function __construct(ApiManager $apiManager)
 {
     $this->apiManager = $apiManager;
     $this->logger = LoggerFactory::create();
     $this->formatters = ['native' => new NativeClientFormatter(), 'json' => new JsonClientFormatter(), 'xml' => new XmlClientFormatter()];
 }