Adding error handling so that an error within a game does not terminate the server, only the single game.

This commit is contained in:
lotodore
2009-06-19 20:48:57 +00:00
parent 993c2529c3
commit 4c8248353a
2 changed files with 209 additions and 181 deletions
+29 -2
View File
@@ -663,6 +663,20 @@ ServerGameStateHand::TimerLoop(const boost::system::error_code &ec, boost::share
{
if (!ec && &server->GetState() == this)
{
try
{
EngineLoop(server);
}
catch (const PokerTHException &e)
{
server->RemoveAllSessions(); // Close this game on error.
}
}
}
void
ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
{
Game &curGame = server->GetGame();
// Main game loop.
@@ -863,7 +877,6 @@ ServerGameStateHand::TimerLoop(const boost::system::error_code &ec, boost::share
}
}
}
}
}
void
@@ -886,12 +899,19 @@ void
ServerGameStateHand::TimerComputerAction(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server)
{
if (!ec && &server->GetState() == this)
{
try
{
boost::shared_ptr<PlayerInterface> tmpPlayer = server->GetGame().getCurrentPlayer();
tmpPlayer->action();
SendPlayerAction(*server, tmpPlayer);
TimerLoop(ec, server);
EngineLoop(server);
}
catch (const PokerTHException &e)
{
server->RemoveAllSessions(); // Close this game on error.
}
}
}
@@ -1174,6 +1194,8 @@ void
ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server)
{
if (!ec && &server->GetState() == this)
{
try
{
Game &curGame = server->GetGame();
// Retrieve current player.
@@ -1189,6 +1211,11 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e
server->SetState(ServerGameStateHand::Instance());
}
catch (const PokerTHException &e)
{
server->RemoveAllSessions(); // Close this game on error.
}
}
}
//-----------------------------------------------------------------------------
+1
View File
@@ -140,6 +140,7 @@ protected:
virtual int InternalProcessPacket(boost::shared_ptr<ServerGame> server, SessionWrapper session, boost::shared_ptr<NetPacket> packet);
void TimerLoop(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);
void EngineLoop(boost::shared_ptr<ServerGame> server);
void TimerShowCards(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);
void TimerComputerAction(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);
void TimerNextHand(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);