/** * Listens for PlayerSetNameMessage and changes the player name. * * @param Connection $connection */ private function handlePlayerNameChange(Connection $connection) { $connection->waitOnMessage(PlayerSetNameMessage::class, 9999)->then(function (PlayerSetNameMessage $message) use($connection) { $player = $connection->getPlayer(); if ($player->getSeat() === null || $player->getTable() === null) { return; } if (!$message->isValid()) { $this->logger->info('Player sent invalid name', ['player' => $player->getName(), 'newName' => $message->getNewName()]); return; } $player->setName($message->getNewName()); $table = $player->getTable(); if ($table instanceof WebSocketObservableTable) { $table->broadcast(new PlayerNameChangedMessage($player)); } }); }
/** * @param HandBetPair $hand * @param DealerHand $dealerHand * * @return Promise */ public function requestAction(HandBetPair $hand, DealerHand $dealerHand) { $this->connection->sendMessage(new RequestActionMessage($this, $dealerHand, $hand->getHand())); return $this->connection->waitOnMessage(PlayerActionMessage::class); }