Preparing network functions to let a player show his cards.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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<NetPacket> 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)
|
||||
{
|
||||
|
||||
@@ -923,16 +923,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> 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<ServerGame> 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<ServerGame> server)
|
||||
{
|
||||
server->GetStateTimer().cancel();
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateWaitNextHand::HandleNewSession(boost::shared_ptr<ServerGame> 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<ServerGame> server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
if (packet->GetMsg()->present == PokerTHMessage_PR_showMyCardsRequestMessage)
|
||||
{
|
||||
// TODO perform action.
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateWaitNextHand::TimerTimeout(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server)
|
||||
{
|
||||
if (!ec && &server->GetState() == this)
|
||||
{
|
||||
ServerGameStateHand::StartNewHand(server);
|
||||
server->SetState(ServerGameStateHand::Instance());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerGameStateFinal ServerGameStateFinal::s_state;
|
||||
|
||||
ServerGameStateFinal &
|
||||
|
||||
@@ -179,6 +179,7 @@ friend class ServerGameStateWaitAck;
|
||||
friend class ServerGameStateStartGame;
|
||||
friend class ServerGameStateHand;
|
||||
friend class ServerGameStateWaitPlayerAction;
|
||||
friend class ServerGameStateWaitNextHand;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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<ServerGame> server);
|
||||
virtual void Exit(boost::shared_ptr<ServerGame> server);
|
||||
|
||||
virtual ~ServerGameStateWaitNextHand();
|
||||
|
||||
virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> /*server*/) {}
|
||||
virtual void HandleNewSession(boost::shared_ptr<ServerGame> server, SessionWrapper session);
|
||||
|
||||
protected:
|
||||
ServerGameStateWaitNextHand();
|
||||
|
||||
virtual void InternalProcessPacket(boost::shared_ptr<ServerGame> server, SessionWrapper session, boost::shared_ptr<NetPacket> packet);
|
||||
void TimerTimeout(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);
|
||||
|
||||
private:
|
||||
static ServerGameStateWaitNextHand s_state;
|
||||
};
|
||||
|
||||
class ServerGameStateFinal : public ServerGameState
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user