Further paranoia changes to prevent timer callbacks from occurring in an uncontrolled state.

This commit is contained in:
lotodore
2009-06-15 22:34:07 +00:00
parent 3d57f65e2b
commit 22edd63dde
6 changed files with 66 additions and 5 deletions
+18 -1
View File
@@ -26,6 +26,7 @@
#include <string> #include <string>
#define CLIENT_INITIAL_STATE ClientStateInit #define CLIENT_INITIAL_STATE ClientStateInit
#define CLIENT_FINAL_STATE ClientStateFinal
class ClientThread; class ClientThread;
class ClientCallback; class ClientCallback;
@@ -42,7 +43,7 @@ public:
virtual void Enter(boost::shared_ptr<ClientThread> client) = 0; virtual void Enter(boost::shared_ptr<ClientThread> client) = 0;
virtual void Exit(boost::shared_ptr<ClientThread> client) = 0; virtual void Exit(boost::shared_ptr<ClientThread> client) = 0;
virtual void HandlePacket(boost::shared_ptr<ClientThread> /*client*/, boost::shared_ptr<NetPacket> /*tmpPacket*/) = 0; virtual void HandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket) = 0;
}; };
// State: Initialization. // State: Initialization.
@@ -401,4 +402,20 @@ protected:
static void ResetPlayerSets(Game &curGame); static void ResetPlayerSets(Game &curGame);
}; };
class ClientStateFinal : public ClientState
{
public:
static ClientStateFinal &Instance();
virtual ~ClientStateFinal() {}
virtual void Enter(boost::shared_ptr<ClientThread> /*client*/) {}
virtual void Exit(boost::shared_ptr<ClientThread> /*client*/) {}
virtual void HandlePacket(boost::shared_ptr<ClientThread> /*client*/, boost::shared_ptr<NetPacket> /*tmpPacket*/) {}
protected:
// Protected constructor - this is a singleton.
ClientStateFinal() {}
};
#endif #endif
+9 -1
View File
@@ -1156,7 +1156,7 @@ ClientStateSynchronizeStart::TimerLoop(const boost::system::error_code& ec, boos
} }
void void
ClientStateSynchronizeStart::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket) ClientStateSynchronizeStart::InternalHandlePacket(boost::shared_ptr<ClientThread> /*client*/, boost::shared_ptr<NetPacket> tmpPacket)
{ {
if (tmpPacket->ToNetPacketGameStart()) if (tmpPacket->ToNetPacketGameStart())
throw ClientException(__FILE__, __LINE__, ERR_NET_START_TIMEOUT, 0); throw ClientException(__FILE__, __LINE__, ERR_NET_START_TIMEOUT, 0);
@@ -1630,3 +1630,11 @@ ClientStateRunHand::ResetPlayerSets(Game &curGame)
} }
} }
//-----------------------------------------------------------------------------
ClientStateFinal &
ClientStateFinal::Instance()
{
static ClientStateFinal state;
return state;
}
+3
View File
@@ -444,6 +444,9 @@ ClientThread::Main()
// Execute remaining ready handlers. // Execute remaining ready handlers.
m_ioService->reset(); m_ioService->reset();
m_ioService->poll(); m_ioService->poll();
// Set a state which does not do anything.
SetState(CLIENT_FINAL_STATE::Instance());
} catch (const PokerTHException &e) } catch (const PokerTHException &e)
{ {
GetCallback().SignalNetClientError(e.GetErrorId(), e.GetOsErrorCode()); GetCallback().SignalNetClientError(e.GetErrorId(), e.GetOsErrorCode());
+2 -3
View File
@@ -69,8 +69,7 @@ void
ServerGame::Exit() ServerGame::Exit()
{ {
m_voteKickTimer.cancel(); m_voteKickTimer.cancel();
if (m_curState) SetState(ServerGameStateFinal::Instance());
m_curState->Exit(shared_from_this());
} }
u_int32_t u_int32_t
@@ -131,7 +130,7 @@ ServerGame::RemoveAllSessions()
void void
ServerGame::TimerVoteKick(const boost::system::error_code &ec) ServerGame::TimerVoteKick(const boost::system::error_code &ec)
{ {
if (!ec) if (!ec && m_curState != &ServerGameStateFinal::Instance())
{ {
// Check whether someone should be kicked, or whether a vote kick should be aborted. // Check whether someone should be kicked, or whether a vote kick should be aborted.
// Only one vote kick can be active at a time. // Only one vote kick can be active at a time.
+10
View File
@@ -1193,3 +1193,13 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
ServerGameStateFinal ServerGameStateFinal::s_state;
ServerGameStateFinal &
ServerGameStateFinal::Instance()
{
return s_state;
}
//-----------------------------------------------------------------------------
+24
View File
@@ -176,6 +176,30 @@ private:
static ServerGameStateWaitPlayerAction s_state; static ServerGameStateWaitPlayerAction s_state;
}; };
class ServerGameStateFinal : public ServerGameState
{
public:
static ServerGameStateFinal &Instance();
virtual ~ServerGameStateFinal() {}
virtual void Enter(boost::shared_ptr<ServerGame> server) {}
virtual void Exit(boost::shared_ptr<ServerGame> server) {}
virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> server) {}
// Handling of a new session.
virtual void HandleNewSession(boost::shared_ptr<ServerGame> server, SessionWrapper session) {}
// Main processing function of the current state.
virtual int ProcessPacket(boost::shared_ptr<ServerGame> server, SessionWrapper session, boost::shared_ptr<NetPacket> packet) {}
protected:
ServerGameStateFinal() {}
private:
static ServerGameStateFinal s_state;
};
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif