Fixed nasty synchronization bug when players leave during start of a game. Fixed netpacket error which occured occasionally during game start when only one player was left, the last player will be removed from the game now, but stay in the lobby. Added new stat to IRC bot.

This commit is contained in:
lotodore
2008-04-02 21:41:39 +00:00
parent e0be7e9490
commit 91b62abf7b
5 changed files with 54 additions and 21 deletions
+7
View File
@@ -100,6 +100,7 @@ using namespace std;
#define NET_REMOVED_GAME_ALREADY_RUNNING 0x0002
#define NET_REMOVED_KICKED 0x0003
#define NET_REMOVED_TIMEOUT 0x0004
#define NET_REMOVED_START_FAILED 0x0005
#define NET_REMOVED_OTHER_REASON 0xFFFF
// Reasons for timeout warning
@@ -4281,6 +4282,9 @@ NetPacketRemovedFromGame::SetData(const NetPacketRemovedFromGame::Data &inData)
case NTF_NET_REMOVED_TIMEOUT :
tmpData->removeReason = htons(NET_REMOVED_TIMEOUT);
break;
case NTF_NET_REMOVED_START_FAILED :
tmpData->removeReason = htons(NET_REMOVED_START_FAILED);
break;
default :
tmpData->removeReason = htons(NET_REMOVED_OTHER_REASON);
break;
@@ -4313,6 +4317,9 @@ NetPacketRemovedFromGame::GetData(NetPacketRemovedFromGame::Data &outData) const
case NET_REMOVED_TIMEOUT :
outData.removeReason = NTF_NET_REMOVED_TIMEOUT;
break;
case NET_REMOVED_START_FAILED :
outData.removeReason = NTF_NET_REMOVED_START_FAILED;
break;
default :
outData.removeReason = NTF_NET_INTERNAL;
break;
+38 -21
View File
@@ -458,6 +458,7 @@ ServerGameStateWaitAck::Process(ServerGameThread &server)
if (server.GetStateTimer().elapsed().total_seconds() >= SERVER_START_GAME_TIMEOUT_SEC)
{
// On timeout: start anyway.
server.GetSessionManager().ResetAllReadyFlags();
server.SetState(SERVER_START_GAME_STATE::Instance());
retVal = MSG_SOCK_INIT_DONE;
}
@@ -509,33 +510,49 @@ ServerGameStateStartGame::~ServerGameStateStartGame()
int
ServerGameStateStartGame::Process(ServerGameThread &server)
{
server.InternalStartGame();
int retVal = MSG_SOCK_INTERNAL_PENDING;
boost::shared_ptr<NetPacket> answer(new NetPacketGameStart);
NetPacketGameStart::Data gameStartData;
gameStartData.startData = server.GetStartData();
// Send player order to clients.
// Assume player list is sorted by number.
PlayerDataList tmpPlayerList = server.GetFullPlayerDataList();
PlayerDataList::iterator player_i = tmpPlayerList.begin();
PlayerDataList::iterator player_end = tmpPlayerList.end();
while (player_i != player_end)
if (tmpPlayerList.size() <= 1)
{
NetPacketGameStart::PlayerSlot tmpPlayerSlot;
tmpPlayerSlot.playerId = (*player_i)->GetUniqueId();
gameStartData.playerSlots.push_back(tmpPlayerSlot);
if (!tmpPlayerList.empty())
{
boost::shared_ptr<PlayerData> tmpPlayer(tmpPlayerList.front());
SessionWrapper tmpSession = server.GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->GetUniqueId());
if (tmpSession.sessionData.get())
server.MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_START_FAILED);
}
}
else
{
server.InternalStartGame();
++player_i;
boost::shared_ptr<NetPacket> answer(new NetPacketGameStart);
NetPacketGameStart::Data gameStartData;
gameStartData.startData = server.GetStartData();
// Send player order to clients.
// Assume player list is sorted by number.
PlayerDataList::iterator player_i = tmpPlayerList.begin();
PlayerDataList::iterator player_end = tmpPlayerList.end();
while (player_i != player_end)
{
NetPacketGameStart::PlayerSlot tmpPlayerSlot;
tmpPlayerSlot.playerId = (*player_i)->GetUniqueId();
gameStartData.playerSlots.push_back(tmpPlayerSlot);
++player_i;
}
static_cast<NetPacketGameStart *>(answer.get())->SetData(gameStartData);
server.SendToAllPlayers(answer, SessionData::Game);
server.SetState(ServerGameStateStartHand::Instance());
retVal = MSG_NET_GAME_SERVER_START;
}
static_cast<NetPacketGameStart *>(answer.get())->SetData(gameStartData);
server.SendToAllPlayers(answer, SessionData::Game);
server.SetState(ServerGameStateStartHand::Instance());
return MSG_NET_GAME_SERVER_START;
return retVal;
}
//-----------------------------------------------------------------------------
+2
View File
@@ -404,6 +404,8 @@ void
ServerGameThread::MoveSessionToLobby(SessionWrapper session, int reason)
{
GracefulRemoveSession(session);
// Reset ready flag - just in case it is set, player may leave at any time.
session.sessionData->ResetReadyFlag();
GetLobbyThread().ReAddSession(session, reason);
}
+6
View File
@@ -124,6 +124,12 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string &
<< "Players currently on Server.. " << tmpStats.numberOfPlayersOnServer;
m_ircThread->SendChatMessage(statStream.str());
}
{
ostringstream statStream;
statStream
<< "Games currently open......... " << tmpStats.numberOfGamesOpen;
m_ircThread->SendChatMessage(statStream.str());
}
{
ostringstream statStream;
statStream
+1
View File
@@ -91,6 +91,7 @@
#define NTF_NET_REMOVED_ALREADY_RUNNING 204
#define NTF_NET_REMOVED_KICKED 205
#define NTF_NET_REMOVED_TIMEOUT 206
#define NTF_NET_REMOVED_START_FAILED 207
// Notifications - join failed
#define NTF_NET_JOIN_GAME_FULL 210