Adding error handling so that an error within a game does not terminate the server, only the single game.
This commit is contained in:
@@ -662,6 +662,20 @@ void
|
||||
ServerGameStateHand::TimerLoop(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server)
|
||||
{
|
||||
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();
|
||||
|
||||
@@ -864,7 +878,6 @@ ServerGameStateHand::TimerLoop(const boost::system::error_code &ec, boost::share
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateHand::TimerShowCards(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server)
|
||||
@@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user