Ejemplo n.º 1
0
 public function listen($port)
 {
     $server = new SocketServer($this->loop);
     $server->on('connection', function (SocketConnection $connection) {
         try {
             $this->connectionManager->accept($connection);
         } catch (\Exception $e) {
             $this->logger->error('Connection failed', ['error' => $e->getMessage()]);
         }
     });
     $server->listen($port, '0.0.0.0');
     $this->logger->info('Started socket server', ['port' => $port]);
 }
Ejemplo n.º 2
0
 /**
  * Request player bets in parallel.
  * Players which do not respond in time are not allowed to play this hand.
  *
  * @return Promise
  */
 private function requestBets()
 {
     $promises = [];
     foreach ($this->table->getSeats() as $seat) {
         if ($seat->isFree()) {
             continue;
         }
         $player = $seat->getPlayer();
         if ($player->getChips()->getAmount() < $this->table->getMinimumBet()) {
             $this->connectionManager->kickPlayer($player, KickedMessage::REASON_INSUFFICIENT_FUNDS);
             continue;
         }
         $promises[] = $this->table->requestPlayerBet($player)->then(function ($amount) use($seat) {
             $this->table->acceptPlayerBet($seat->getPlayer(), $seat->getHands()[0], $amount);
             $seat->setInPlay(true);
             $this->logger->info('Player bet', ['player' => $seat->getPlayer()->getName(), 'amount' => $amount, 'stack' => $seat->getPlayer()->getChips()->getAmount()]);
             return null;
         })->otherwise(function (\Exception $reason) use($seat) {
             $seat->setInPlay(false);
             $this->logger->info('Player unable to bet', ['player' => $seat->getPlayer()->getName(), 'stack' => $seat->getPlayer()->getChips()->getAmount(), 'reason' => $reason->getMessage()]);
             return null;
         });
     }
     return \React\Promise\all($promises)->then(function () {
         return \Blackjack\Promise\timedResolve(self::PAUSE_SPEED);
     });
 }
Ejemplo n.º 3
0
 /**
  * @param ServerMessageInterface $message
  */
 public function sendMessage(ServerMessageInterface $message)
 {
     $this->connectionManager->enqueueMessage($this->getPlayer(), $message);
 }