mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Change the NetServer Broadcast function to send the given message to clients that are in one of the states specified by the caller.
Thus remove the peculiarity to broadcast to clients that are in the gamesetup, loading screen or ingame, but not rejoining ones. Fix "unknown player" errors in the GUI by broadcasting player assignments to rejoining players too. Fixes #4036. Differential Revision: D17 Reviewed By: Imarok This was SVN commit r19171.
This commit is contained in:
parent
f958c6a168
commit
9964bee5bb
3 changed files with 23 additions and 25 deletions
|
|
@ -339,19 +339,19 @@ bool CNetServerWorker::SendMessage(ENetPeer* peer, const CNetMessage* message)
|
|||
return CNetHost::SendMessage(message, peer, DebugName(session).c_str());
|
||||
}
|
||||
|
||||
bool CNetServerWorker::Broadcast(const CNetMessage* message)
|
||||
bool CNetServerWorker::Broadcast(const CNetMessage* message, const std::vector<NetServerSessionState>& targetStates)
|
||||
{
|
||||
ENSURE(m_Host);
|
||||
|
||||
bool ok = true;
|
||||
|
||||
// Send to all sessions that are active and has finished authentication
|
||||
// TODO: this does lots of repeated message serialisation if we have lots
|
||||
// of remote peers; could do it more efficiently if that's a real problem
|
||||
|
||||
for (CNetServerSession* session : m_Sessions)
|
||||
if (session->GetCurrState() == NSS_PREGAME || session->GetCurrState() == NSS_INGAME)
|
||||
if (!session->SendMessage(message))
|
||||
ok = false;
|
||||
if (std::find(targetStates.begin(), targetStates.end(), session->GetCurrState()) != targetStates.end() &&
|
||||
!session->SendMessage(message))
|
||||
ok = false;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
|
@ -809,9 +809,7 @@ void CNetServerWorker::KickPlayer(const CStrW& playerName, const bool ban)
|
|||
CKickedMessage kickedMessage;
|
||||
kickedMessage.m_Name = playerName;
|
||||
kickedMessage.m_Ban = ban;
|
||||
for (CNetServerSession* session : m_Sessions)
|
||||
if (session->GetCurrState() > NSS_AUTHENTICATE)
|
||||
session->SendMessage(&kickedMessage);
|
||||
Broadcast(&kickedMessage, { NSS_PREGAME, NSS_JOIN_SYNCING, NSS_INGAME });
|
||||
}
|
||||
|
||||
void CNetServerWorker::AssignPlayer(int playerID, const CStr& guid)
|
||||
|
|
@ -850,7 +848,7 @@ void CNetServerWorker::SendPlayerAssignments()
|
|||
{
|
||||
CPlayerAssignmentMessage message;
|
||||
ConstructPlayerAssignmentMessage(message);
|
||||
Broadcast(&message);
|
||||
Broadcast(&message, { NSS_PREGAME, NSS_JOIN_SYNCING, NSS_INGAME });
|
||||
}
|
||||
|
||||
ScriptInterface& CNetServerWorker::GetScriptInterface()
|
||||
|
|
@ -1051,8 +1049,9 @@ bool CNetServerWorker::OnInGame(void* context, CFsmEvent* event)
|
|||
if (!cheatsEnabled && (it == server.m_PlayerAssignments.end() || it->second.m_PlayerID != simMessage->m_Player))
|
||||
return true;
|
||||
|
||||
// Send it back to all clients immediately
|
||||
server.Broadcast(simMessage);
|
||||
// Send it back to all clients that have finished
|
||||
// the loading screen (and the synchronization when rejoining)
|
||||
server.Broadcast(simMessage, { NSS_INGAME });
|
||||
|
||||
// Save all the received commands
|
||||
if (server.m_SavedCommands.size() < simMessage->m_Turn + 1)
|
||||
|
|
@ -1087,7 +1086,7 @@ bool CNetServerWorker::OnChat(void* context, CFsmEvent* event)
|
|||
|
||||
message->m_GUID = session->GetGUID();
|
||||
|
||||
server.Broadcast(message);
|
||||
server.Broadcast(message, { NSS_PREGAME, NSS_INGAME });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1103,7 +1102,7 @@ bool CNetServerWorker::OnReady(void* context, CFsmEvent* event)
|
|||
|
||||
message->m_GUID = session->GetGUID();
|
||||
|
||||
server.Broadcast(message);
|
||||
server.Broadcast(message, { NSS_PREGAME });
|
||||
server.SetPlayerReady(message->m_GUID, message->m_Status);
|
||||
|
||||
return true;
|
||||
|
|
@ -1237,11 +1236,10 @@ bool CNetServerWorker::OnRejoined(void* context, CFsmEvent* event)
|
|||
CNetServerSession* session = (CNetServerSession*)context;
|
||||
CNetServerWorker& server = session->GetServer();
|
||||
|
||||
// Inform everyone of the client having rejoined
|
||||
CRejoinedMessage* message = (CRejoinedMessage*)event->GetParamRef();
|
||||
|
||||
message->m_GUID = session->GetGUID();
|
||||
|
||||
server.Broadcast(message);
|
||||
server.Broadcast(message, { NSS_INGAME });
|
||||
|
||||
// Send all pausing players to the rejoined client.
|
||||
for (const CStr& guid : server.m_PausingPlayers)
|
||||
|
|
@ -1327,9 +1325,10 @@ void CNetServerWorker::CheckGameLoadStatus(CNetServerSession* changedSession)
|
|||
if (session != changedSession && session->GetCurrState() != NSS_INGAME)
|
||||
return;
|
||||
|
||||
// Inform clients that everyone has loaded the map and that the game can start
|
||||
CLoadedGameMessage loaded;
|
||||
loaded.m_CurrentTurn = 0;
|
||||
Broadcast(&loaded);
|
||||
Broadcast(&loaded, { NSS_PREGAME });
|
||||
|
||||
m_State = SERVER_STATE_INGAME;
|
||||
}
|
||||
|
|
@ -1356,7 +1355,7 @@ void CNetServerWorker::StartGame()
|
|||
SendPlayerAssignments();
|
||||
|
||||
CGameStartMessage gameStart;
|
||||
Broadcast(&gameStart);
|
||||
Broadcast(&gameStart, { NSS_PREGAME });
|
||||
}
|
||||
|
||||
void CNetServerWorker::UpdateGameAttributes(JS::MutableHandleValue attrs)
|
||||
|
|
@ -1368,7 +1367,7 @@ void CNetServerWorker::UpdateGameAttributes(JS::MutableHandleValue attrs)
|
|||
|
||||
CGameSetupMessage gameSetupMessage(GetScriptInterface());
|
||||
gameSetupMessage.m_Data = m_GameAttributes;
|
||||
Broadcast(&gameSetupMessage);
|
||||
Broadcast(&gameSetupMessage, { NSS_PREGAME });
|
||||
}
|
||||
|
||||
CStrW CNetServerWorker::SanitisePlayerName(const CStrW& original)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2016 Wildfire Games.
|
||||
/* Copyright (C) 2017 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
|
|
@ -168,10 +168,9 @@ public:
|
|||
void KickPlayer(const CStrW& playerName, const bool ban);
|
||||
|
||||
/**
|
||||
* Send a message to all clients who have completed the full connection process
|
||||
* (i.e. are in the pre-game or in-game states).
|
||||
* Send a message to all clients who match one of the given states.
|
||||
*/
|
||||
bool Broadcast(const CNetMessage* message);
|
||||
bool Broadcast(const CNetMessage* message, const std::vector<NetServerSessionState>& targetStates);
|
||||
|
||||
private:
|
||||
friend class CNetServer;
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ void CNetServerTurnManager::CheckClientsReady()
|
|||
CEndCommandBatchMessage msg;
|
||||
msg.m_TurnLength = m_TurnLength;
|
||||
msg.m_Turn = m_ReadyTurn;
|
||||
m_NetServer.Broadcast(&msg);
|
||||
m_NetServer.Broadcast(&msg, { NSS_INGAME });
|
||||
|
||||
ENSURE(m_SavedTurnLengths.size() == m_ReadyTurn);
|
||||
m_SavedTurnLengths.push_back(m_TurnLength);
|
||||
|
|
@ -130,7 +130,7 @@ void CNetServerTurnManager::NotifyFinishedClientUpdate(int client, const CStrW&
|
|||
h.m_Name = playername;
|
||||
msg.m_PlayerNames.push_back(h);
|
||||
}
|
||||
m_NetServer.Broadcast(&msg);
|
||||
m_NetServer.Broadcast(&msg, { NSS_INGAME });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue