Adding error handling so that an error within a game does not terminate the server, only the single game.
This commit is contained in:
@@ -663,6 +663,20 @@ ServerGameStateHand::TimerLoop(const boost::system::error_code &ec, boost::share
|
|||||||
{
|
{
|
||||||
if (!ec && &server->GetState() == this)
|
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();
|
Game &curGame = server->GetGame();
|
||||||
|
|
||||||
// Main game loop.
|
// Main game loop.
|
||||||
@@ -863,7 +877,6 @@ ServerGameStateHand::TimerLoop(const boost::system::error_code &ec, boost::share
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -886,12 +899,19 @@ void
|
|||||||
ServerGameStateHand::TimerComputerAction(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server)
|
ServerGameStateHand::TimerComputerAction(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server)
|
||||||
{
|
{
|
||||||
if (!ec && &server->GetState() == this)
|
if (!ec && &server->GetState() == this)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr<PlayerInterface> tmpPlayer = server->GetGame().getCurrentPlayer();
|
boost::shared_ptr<PlayerInterface> tmpPlayer = server->GetGame().getCurrentPlayer();
|
||||||
|
|
||||||
tmpPlayer->action();
|
tmpPlayer->action();
|
||||||
SendPlayerAction(*server, tmpPlayer);
|
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)
|
ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server)
|
||||||
{
|
{
|
||||||
if (!ec && &server->GetState() == this)
|
if (!ec && &server->GetState() == this)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Game &curGame = server->GetGame();
|
Game &curGame = server->GetGame();
|
||||||
// Retrieve current player.
|
// Retrieve current player.
|
||||||
@@ -1189,6 +1211,11 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e
|
|||||||
|
|
||||||
server->SetState(ServerGameStateHand::Instance());
|
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);
|
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 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 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 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);
|
void TimerNextHand(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);
|
||||||
|
|||||||
Reference in New Issue
Block a user