diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 401cae51..d40329e8 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -78,6 +78,7 @@ public: void SendResetTimeout(); void SendAskKickPlayer(unsigned playerId); void SendVoteKick(bool doKick); + void SendShowMyCards(); void SendInvitePlayerToCurrentGame(unsigned playerId); void SendRejectGameInvitation(unsigned gameId, DenyGameInvitationReason reason); diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 12212cc7..62c36941 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -310,6 +310,14 @@ ClientThread::SendVoteKick(bool doKick) m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); } +void +ClientThread::SendShowMyCards() +{ + boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); + packet->GetMsg()->present = PokerTHMessage_PR_showMyCardsRequestMessage; + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); +} + void ClientThread::SendInvitePlayerToCurrentGame(unsigned playerId) { diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index cdb31987..187c8f69 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -923,16 +923,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) } else { -#ifdef POKERTH_TEST - server->GetStateTimer().expires_from_now( - boost::posix_time::seconds(0)); -#else - server->GetStateTimer().expires_from_now( - boost::posix_time::seconds(server->GetGameData().delayBetweenHandsSec)); -#endif - server->GetStateTimer().async_wait( - boost::bind( - &ServerGameStateHand::TimerNextHand, this, boost::asio::placeholders::error, server)); + server->SetState(ServerGameStateWaitNextHand::Instance()); } } } @@ -1289,6 +1280,74 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e //----------------------------------------------------------------------------- + +ServerGameStateWaitNextHand ServerGameStateWaitNextHand::s_state; + +ServerGameStateWaitNextHand & +ServerGameStateWaitNextHand::Instance() +{ + return s_state; +} + +ServerGameStateWaitNextHand::ServerGameStateWaitNextHand() +{ +} + +ServerGameStateWaitNextHand::~ServerGameStateWaitNextHand() +{ +} + +void +ServerGameStateWaitNextHand::Enter(boost::shared_ptr server) +{ +#ifdef SERVER_TEST + int timeoutSec = 0; +#else + int timeoutSec = server->GetGameData().delayBetweenHandsSec; +#endif + + server->GetStateTimer().expires_from_now( + boost::posix_time::seconds(timeoutSec)); + + server->GetStateTimer().async_wait( + boost::bind( + &ServerGameStateWaitNextHand::TimerTimeout, this, boost::asio::placeholders::error, server)); +} + +void +ServerGameStateWaitNextHand::Exit(boost::shared_ptr server) +{ + server->GetStateTimer().cancel(); +} + +void +ServerGameStateWaitNextHand::HandleNewSession(boost::shared_ptr server, SessionWrapper session) +{ + // Do not accept new sessions in this state. + server->MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING); +} + +void +ServerGameStateWaitNextHand::InternalProcessPacket(boost::shared_ptr server, SessionWrapper session, boost::shared_ptr packet) +{ + if (packet->GetMsg()->present == PokerTHMessage_PR_showMyCardsRequestMessage) + { + // TODO perform action. + } +} + +void +ServerGameStateWaitNextHand::TimerTimeout(const boost::system::error_code &ec, boost::shared_ptr server) +{ + if (!ec && &server->GetState() == this) + { + ServerGameStateHand::StartNewHand(server); + server->SetState(ServerGameStateHand::Instance()); + } +} + +//----------------------------------------------------------------------------- + ServerGameStateFinal ServerGameStateFinal::s_state; ServerGameStateFinal & diff --git a/src/net/servergame.h b/src/net/servergame.h index a0c62270..efb0c204 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -179,6 +179,7 @@ friend class ServerGameStateWaitAck; friend class ServerGameStateStartGame; friend class ServerGameStateHand; friend class ServerGameStateWaitPlayerAction; +friend class ServerGameStateWaitNextHand; }; #endif diff --git a/src/net/servergamestate.h b/src/net/servergamestate.h index 174bd84c..931fa914 100644 --- a/src/net/servergamestate.h +++ b/src/net/servergamestate.h @@ -153,6 +153,7 @@ private: static ServerGameStateHand s_state; friend class ServerGameStateStartGame; +friend class ServerGameStateWaitNextHand; }; // State: Wait for a player action. @@ -178,6 +179,29 @@ private: static ServerGameStateWaitPlayerAction s_state; }; +// State: Wait for the next hand. +class ServerGameStateWaitNextHand : public AbstractServerGameStateReceiving +{ +public: + static ServerGameStateWaitNextHand &Instance(); + virtual void Enter(boost::shared_ptr server); + virtual void Exit(boost::shared_ptr server); + + virtual ~ServerGameStateWaitNextHand(); + + virtual void NotifyGameAdminChanged(boost::shared_ptr /*server*/) {} + virtual void HandleNewSession(boost::shared_ptr server, SessionWrapper session); + +protected: + ServerGameStateWaitNextHand(); + + virtual void InternalProcessPacket(boost::shared_ptr server, SessionWrapper session, boost::shared_ptr packet); + void TimerTimeout(const boost::system::error_code &ec, boost::shared_ptr server); + +private: + static ServerGameStateWaitNextHand s_state; +}; + class ServerGameStateFinal : public ServerGameState { public: diff --git a/src/session.cpp b/src/session.cpp index 3d9d9776..44625eca 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -459,6 +459,13 @@ void Session::voteKick(bool doKick) myNetClient->SendVoteKick(doKick); } +void Session::showMyCards() +{ + if (!myNetClient) + return; // only act if client is running. + myNetClient->SendShowMyCards(); +} + bool Session::isNetworkClientRunning() const { // This, and every place which calls this, is a HACK. diff --git a/src/session.h b/src/session.h index 717458ee..a746c0a2 100755 --- a/src/session.h +++ b/src/session.h @@ -87,6 +87,7 @@ public: void kickPlayer(const std::string &playerName); void startVoteKickPlayer(unsigned playerId); void voteKick(bool doKick); + void showMyCards(); void selectServer(unsigned serverId); void setLogin(const std::string &userName, const std::string &password, bool isGuest);