From 856dc1c999f5e754cb06d30462cfc9e90e291b0b Mon Sep 17 00:00:00 2001 From: elexis Date: Thu, 19 May 2016 21:03:46 +0000 Subject: [PATCH] Network cleanup. Send the "client has rejoined" message after the synchronization finished instead of right after the loading screen. Patch by echotangoecho, refs #1949, #1950. This was SVN commit r18203. --- .../mods/public/gui/credits/texts/programming.json | 1 + binaries/data/mods/public/gui/loading/loading.js | 4 ---- source/gui/scripting/ScriptFunctions.cpp | 8 -------- source/network/NetClient.cpp | 12 ++++++++---- source/network/NetClient.h | 3 +++ 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/binaries/data/mods/public/gui/credits/texts/programming.json b/binaries/data/mods/public/gui/credits/texts/programming.json index e9931dfe3a..5d921e5a9c 100644 --- a/binaries/data/mods/public/gui/credits/texts/programming.json +++ b/binaries/data/mods/public/gui/credits/texts/programming.json @@ -57,6 +57,7 @@ {"nick": "dumbo"}, {"nick": "dvangennip", "name": "Doménique"}, {"nick": "Echelon9", "name": "Rhys Kidd"}, + {"nick": "echotangoecho"}, {"nick": "eihrul", "name": "Lee Salzman"}, {"nick": "elexis", "name": "Alexander Heinsius"}, {"nick": "EmjeR", "name": "Matthijs de Rijk"}, diff --git a/binaries/data/mods/public/gui/loading/loading.js b/binaries/data/mods/public/gui/loading/loading.js index e912480f80..30e08aa39d 100644 --- a/binaries/data/mods/public/gui/loading/loading.js +++ b/binaries/data/mods/public/gui/loading/loading.js @@ -105,8 +105,4 @@ function reallyStartGame() // Restore default cursor. Engine.SetCursor("arrow-default"); - - // Notify the other clients that we have finished the loading screen - if (g_Data.isNetworked && g_Data.isRejoining) - Engine.SendNetworkRejoined(); } diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 925bc230b1..55ed70f4db 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -458,13 +458,6 @@ void SendNetworkReady(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int messag g_NetClient->SendReadyMessage(message); } -void SendNetworkRejoined(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) -{ - ENSURE(g_NetClient); - - g_NetClient->SendRejoinedMessage(); -} - JS::Value GetAIs(ScriptInterface::CxPrivate* pCxPrivate) { return ICmpAIManager::GetAIs(*(pCxPrivate->pScriptInterface)); @@ -1052,7 +1045,6 @@ void GuiScriptingInit(ScriptInterface& scriptInterface) scriptInterface.RegisterFunction("ClearAllPlayerReady"); scriptInterface.RegisterFunction("SendNetworkChat"); scriptInterface.RegisterFunction("SendNetworkReady"); - scriptInterface.RegisterFunction("SendNetworkRejoined"); scriptInterface.RegisterFunction("GetAIs"); scriptInterface.RegisterFunction("GetEngineInfo"); diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index 2a59c50b07..7ab5af3518 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -72,7 +72,8 @@ CNetClient::CNetClient(CGame* game, bool isLocalClient) : m_GUID(ps_generate_guid()), m_HostID((u32)-1), m_ClientTurnManager(NULL), m_Game(game), m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetContext()), m_IsLocalClient(isLocalClient), - m_LastConnectionCheck(0) + m_LastConnectionCheck(0), + m_Rejoin(false) { m_Game->SetTurnManager(NULL); // delete the old local turn manager so we don't accidentally use it @@ -487,13 +488,12 @@ bool CNetClient::OnAuthenticate(void* context, CFsmEvent* event) LOGMESSAGE("Net: Authentication result: host=%u, %s", message->m_HostID, utf8_from_wstring(message->m_Message)); - bool isRejoining = (message->m_Code == ARC_OK_REJOINING); - client->m_HostID = message->m_HostID; + client->m_Rejoin = message->m_Code == ARC_OK_REJOINING; JS::RootedValue msg(cx); client->GetScriptInterface().Eval("({'type':'netstatus','status':'authenticated'})", &msg); - client->GetScriptInterface().SetProperty(msg, "rejoining", isRejoining); + client->GetScriptInterface().SetProperty(msg, "rejoining", client->m_Rejoin); client->PushGuiMessage(msg); return true; @@ -743,6 +743,10 @@ bool CNetClient::OnLoadedGame(void* context, CFsmEvent* event) client->GetScriptInterface().Eval("({'type':'netstatus','status':'active'})", &msg); client->PushGuiMessage(msg); + // If we have rejoined an in progress game, send the rejoined message to the server. + if (client->m_Rejoin) + client->SendRejoinedMessage(); + return true; } diff --git a/source/network/NetClient.h b/source/network/NetClient.h index e65b4aa320..9a84a15fa5 100644 --- a/source/network/NetClient.h +++ b/source/network/NetClient.h @@ -239,6 +239,9 @@ private: /// Unique-per-game identifier of this client, used to identify the sender of simulation commands u32 m_HostID; + /// True if the player is currently rejoining or has already rejoined the game. + bool m_Rejoin; + /// Whether to prevent the client of the host from timing out bool m_IsLocalClient;