Ticket #3264: t3264_show_network_warnings_WIP_v1.patch
File t3264_show_network_warnings_WIP_v1.patch, 26.5 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_global_object.js
1 /* 2 DESCRIPTION : Contains global GUI functions, which will later be accessible from every GUI script/file. 3 NOTES : So far, only the message box-related functions are implemented. 4 */ 1 /** 2 * Contains global GUI functions accessible from every GUI script/file. 3 * File will be reloaded when switching pages or showing message boxes! 4 */ 5 6 /** 7 * Number of milliseconds to display network warnings. 8 */ 9 var g_NetworkWarningTimeout = 3000; 10 11 /** 12 * Currently displayed network warnings. At most one message per user. 13 */ 14 var g_NetworkWarnings = {}; 5 15 6 16 // ******************************************* 7 17 // messageBox 8 18 // ******************************************* 9 19 // @params: int mbWidth, int mbHeight, string mbMessage, string mbTitle, int mbMode, arr mbButtonCaptions, function mbBtnCode, var mbCallbackArgs … … function updateCounters() 138 148 139 149 var dataCounter = Engine.GetGUIObjectByName("dataCounter"); 140 150 dataCounter.caption = caption; 141 151 dataCounter.size = sprintf("100%%-100 40 100%%-5 %(bottom)s", { bottom: 40 + 14 * linesCount }); 142 152 } 153 154 /** 155 * @param msg - GUI message sent by NetServer or NetClient 156 */ 157 function addNetworkWarning(msg) 158 { 159 let text; 160 161 switch (msg.warntype) 162 { 163 case "server-timeout": 164 text = sprintf(translate("Losing connection to server (%(seconds)s)"), { 165 "seconds": msg.lastReceivedTime 166 }); 167 break; 168 case "client-timeout": 169 text = sprintf(translate("%(player)s losing connection (%(seconds)s)"), { 170 "player": colorizePlayernameByGUID(msg.guid), 171 "seconds": msg.lastReceivedTime 172 }); 173 break; 174 case "server-latency": 175 text = sprintf(translate("Bad connection to server (%(milliseconds)sms)"), { 176 "milliseconds": msg.meanRTT 177 }); 178 break; 179 case "client-latency": 180 text = sprintf(translate("Bad connection to %(player)s (%(milliseconds)sms)"), { 181 "player": colorizePlayernameByGUID(msg.guid), 182 "milliseconds": msg.meanRTT 183 }); 184 break; 185 } 186 187 g_NetworkWarnings[msg.guid || "server"] = { 188 "added": Date.now(), 189 "text": text 190 }; 191 } 192 /** 193 * Displays the most recent network warning of each client onscreen. 194 */ 195 function displayNetworkWarnings() 196 { 197 // Remove old messages 198 for (let guid in g_NetworkWarnings) 199 if (Date.now() - g_NetworkWarnings[guid].added > g_NetworkWarningTimeout) 200 delete g_NetworkWarnings[guid]; 201 202 let messages = Object.keys(g_NetworkWarnings).map(guid => g_NetworkWarnings[guid].text); 203 204 let networkWarnings = Engine.GetGUIObjectByName("networkWarnings"); 205 networkWarnings.caption = messages.join("\n"); 206 networkWarnings.size = "100%-410 40 100%-110 "+ (40 + 14 * messages.length); 207 } -
binaries/data/mods/public/gui/common/global.xml
12 12 13 13 <object> 14 14 15 15 <!-- 16 16 ========================================== 17 - NETWORK WARNINGS 18 ========================================== 19 --> 20 <object name="networkWarnings" 21 type="text" 22 ghost="true" 23 z="199" 24 size="100%-410 40 100%-95 40" 25 font="mono-stroke-10" 26 textcolor="orange" 27 text_align="center" 28 text_valign="top" 29 sprite="color: 0 0 0 100" 30 > 31 <action on="Tick"> 32 displayNetworkWarnings(); 33 </action> 34 </object> 35 36 <!-- 37 ========================================== 17 38 - FPS & REAL TIME & GAME TIME COUNTER 18 39 ========================================== 19 40 --> 20 41 <object name="dataCounter" 21 42 type="text" -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
const g_MapPath = { 26 26 /** 27 27 * Processes a CNetMessage (see NetMessage.h, NetMessages.h) sent by the CNetServer. 28 28 */ 29 29 const g_NetMessageTypes = { 30 30 "netstatus": msg => handleNetStatusMessage(msg), 31 "netwarn": msg => addNetworkWarning(msg), 31 32 "gamesetup": msg => handleGamesetupMessage(msg), 32 33 "players": msg => handlePlayerAssignmentMessage(msg), 33 34 "ready": msg => handleReadyMessage(msg), 34 35 "start": msg => handleGamestartMessage(msg), 35 36 "kicked": msg => addChatMessage({ "type": "kicked", "username": msg.username }), -
binaries/data/mods/public/gui/gamesetup/gamesetup_mp.js
function pollAndHandleNetworkClient() 124 124 "playerAssignments": g_PlayerAssignments 125 125 }); 126 126 break; 127 127 128 128 case "chat": 129 // Ignore, since we have nowhere to display chat messages 129 break; 130 131 case "netwarn": 130 132 break; 131 133 132 134 default: 133 135 error(sprintf("Unrecognised net message type %(messageType)s", { messageType: message.type })); 134 136 } … … function pollAndHandleNetworkClient() 167 169 default: 168 170 error(sprintf("Unrecognised netstatus type %(netType)s", { netType: message.status })); 169 171 break; 170 172 } 171 173 break; 174 175 case "netwarn": 176 break; 177 172 178 default: 173 179 error(sprintf("Unrecognised net message type %(messageType)s", { messageType: message.type })); 174 180 break; 175 181 } 176 182 } -
binaries/data/mods/public/gui/session/messages.js
var g_ChatTimers = []; 27 27 /** 28 28 * Handle all netmessage types that can occur. 29 29 */ 30 30 var g_NetMessageTypes = { 31 31 "netstatus": msg => handleNetStatusMessage(msg), 32 "netwarn": msg => addNetworkWarning(msg), 32 33 "players": msg => handlePlayerAssignmentsMessage(msg), 33 34 "rejoined": msg => addChatMessage({ "type": "rejoined", "guid": msg.guid }), 34 35 "kicked": msg => addChatMessage({ "type": "system", "text": sprintf(translate("%(username)s has been kicked"), { "username": msg.username }) }), 35 36 "banned": msg => addChatMessage({ "type": "system", "text": sprintf(translate("%(username)s has been banned"), { "username": msg.username }) }), 36 37 "chat": msg => addChatMessage({ "type": "message", "guid": msg.guid, "text": msg.text }), -
source/network/NetClient.cpp
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … private: 68 68 69 69 CNetClient::CNetClient(CGame* game) : 70 70 m_Session(NULL), 71 71 m_UserName(L"anonymous"), 72 72 m_GUID(ps_generate_guid()), m_HostID((u32)-1), m_ClientTurnManager(NULL), m_Game(game), 73 m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetContext()) 73 m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetContext()), 74 m_LastConnectionCheck(0) 74 75 { 75 76 m_Game->SetTurnManager(NULL); // delete the old local turn manager so we don't accidentally use it 76 77 77 78 void* context = this; 78 79 … … CNetClient::CNetClient(CGame* game) : 92 93 AddTransition(NCS_PREGAME, (uint)NMT_CHAT, NCS_PREGAME, (void*)&OnChat, context); 93 94 AddTransition(NCS_PREGAME, (uint)NMT_READY, NCS_PREGAME, (void*)&OnReady, context); 94 95 AddTransition(NCS_PREGAME, (uint)NMT_GAME_SETUP, NCS_PREGAME, (void*)&OnGameSetup, context); 95 96 AddTransition(NCS_PREGAME, (uint)NMT_PLAYER_ASSIGNMENT, NCS_PREGAME, (void*)&OnPlayerAssignment, context); 96 97 AddTransition(NCS_PREGAME, (uint)NMT_KICKED, NCS_PREGAME, (void*)&OnKicked, context); 98 AddTransition(NCS_PREGAME, (uint)NMT_CLIENT_TIMEOUT, NCS_PREGAME, (void*)&OnClientTimeout, context); 99 AddTransition(NCS_PREGAME, (uint)NMT_CLIENT_PERFORMANCE, NCS_PREGAME, (void*)&OnClientPerformance, context); 97 100 AddTransition(NCS_PREGAME, (uint)NMT_GAME_START, NCS_LOADING, (void*)&OnGameStart, context); 98 101 AddTransition(NCS_PREGAME, (uint)NMT_JOIN_SYNC_START, NCS_JOIN_SYNCING, (void*)&OnJoinSyncStart, context); 99 102 100 103 AddTransition(NCS_JOIN_SYNCING, (uint)NMT_CHAT, NCS_JOIN_SYNCING, (void*)&OnChat, context); 101 104 AddTransition(NCS_JOIN_SYNCING, (uint)NMT_GAME_SETUP, NCS_JOIN_SYNCING, (void*)&OnGameSetup, context); … … CNetClient::CNetClient(CGame* game) : 110 113 AddTransition(NCS_LOADING, (uint)NMT_PLAYER_ASSIGNMENT, NCS_LOADING, (void*)&OnPlayerAssignment, context); 111 114 AddTransition(NCS_LOADING, (uint)NMT_LOADED_GAME, NCS_INGAME, (void*)&OnLoadedGame, context); 112 115 113 116 AddTransition(NCS_INGAME, (uint)NMT_REJOINED, NCS_INGAME, (void*)&OnRejoined, context); 114 117 AddTransition(NCS_INGAME, (uint)NMT_KICKED, NCS_INGAME, (void*)&OnKicked, context); 118 AddTransition(NCS_INGAME, (uint)NMT_CLIENT_TIMEOUT, NCS_INGAME, (void*)&OnClientTimeout, context); 119 AddTransition(NCS_INGAME, (uint)NMT_CLIENT_PERFORMANCE, NCS_INGAME, (void*)&OnClientPerformance, context); 115 120 AddTransition(NCS_INGAME, (uint)NMT_CHAT, NCS_INGAME, (void*)&OnChat, context); 116 121 AddTransition(NCS_INGAME, (uint)NMT_GAME_SETUP, NCS_INGAME, (void*)&OnGameSetup, context); 117 122 AddTransition(NCS_INGAME, (uint)NMT_PLAYER_ASSIGNMENT, NCS_INGAME, (void*)&OnPlayerAssignment, context); 118 123 AddTransition(NCS_INGAME, (uint)NMT_SIMULATION_COMMAND, NCS_INGAME, (void*)&OnInGame, context); 119 124 AddTransition(NCS_INGAME, (uint)NMT_SYNC_ERROR, NCS_INGAME, (void*)&OnInGame, context); … … void CNetClient::DestroyConnection() 168 173 SAFE_DELETE(m_Session); 169 174 } 170 175 171 176 void CNetClient::Poll() 172 177 { 173 if (m_Session) 174 m_Session->Poll(); 178 if (!m_Session) 179 return; 180 181 CheckServerConnection(); 182 m_Session->Poll(); 183 } 184 185 void CNetClient::CheckServerConnection() 186 { 187 // Send net-warnings at most once per second 188 u32 now = std::time(nullptr); 189 if (now <= m_LastConnectionCheck) 190 return; 191 m_LastConnectionCheck = now; 192 193 JSContext* cx = GetScriptInterface().GetContext(); 194 195 // Report if we are losing the connection to the server 196 u32 lastReceived = m_Session->GetLastReceivedTime() / 1000; 197 if (lastReceived > NETWORK_WARNING_TIMEOUT) 198 { 199 JS::RootedValue msg(cx); 200 GetScriptInterface().Eval("({ 'type':'netwarn', 'warntype': 'server-timeout' })", &msg); 201 GetScriptInterface().SetProperty(msg, "lastReceivedTime", lastReceived); 202 PushGuiMessage(msg); 203 return; 204 } 205 206 // Report if we have a bad ping to the server 207 u32 meanRTT = m_Session->GetMeanRTT(); 208 if (m_ClientTurnManager && meanRTT > m_ClientTurnManager->GetCurrentTurnLength() * NETWORK_WARNING_LATENCY) 209 { 210 JS::RootedValue msg(cx); 211 GetScriptInterface().Eval("({ 'type':'netwarn', 'warntype': 'server-latency' })", &msg); 212 GetScriptInterface().SetProperty(msg, "meanRTT", meanRTT); 213 PushGuiMessage(msg); 214 } 175 215 } 176 216 177 217 void CNetClient::Flush() 178 218 { 179 219 if (m_Session) … … bool CNetClient::OnKicked(void *context, 625 665 client->PushGuiMessage(msg); 626 666 627 667 return true; 628 668 } 629 669 670 bool CNetClient::OnClientTimeout(void *context, CFsmEvent* event) 671 { 672 ENSURE(event->GetType() == (uint)NMT_CLIENT_TIMEOUT); 673 674 CNetClient* client = (CNetClient*)context; 675 JSContext* cx = client->GetScriptInterface().GetContext(); 676 677 CClientTimeoutMessage* message = (CClientTimeoutMessage*)event->GetParamRef(); 678 JS::RootedValue msg(cx); 679 680 client->GetScriptInterface().Eval("({'type':'netwarn', 'warntype': 'client-timeout' })", &msg); 681 client->GetScriptInterface().SetProperty(msg, "guid", std::string(message->m_GUID)); 682 client->GetScriptInterface().SetProperty(msg, "lastReceivedTime", message->m_LastReceivedTime); 683 client->PushGuiMessage(msg); 684 685 return true; 686 } 687 688 bool CNetClient::OnClientPerformance(void *context, CFsmEvent* event) 689 { 690 ENSURE(event->GetType() == (uint)NMT_CLIENT_PERFORMANCE); 691 692 CNetClient* client = (CNetClient*)context; 693 JSContext* cx = client->GetScriptInterface().GetContext(); 694 695 CClientPerformanceMessage* message = (CClientPerformanceMessage*)event->GetParamRef(); 696 std::vector<CClientPerformanceMessage::S_m_Clients> clients = message->m_Clients; 697 698 for (size_t i = 0; i < clients.size(); ++i) 699 { 700 u32 meanRTT = clients[i].m_MeanRTT; 701 702 if (!client->m_ClientTurnManager || meanRTT < client->m_ClientTurnManager->GetCurrentTurnLength() * NETWORK_WARNING_LATENCY) 703 continue; 704 705 JS::RootedValue msg(cx); 706 client->GetScriptInterface().Eval("({'type':'netwarn', 'warntype': 'client-latency' })", &msg); 707 client->GetScriptInterface().SetProperty(msg, "guid", clients[i].m_GUID); 708 client->GetScriptInterface().SetProperty(msg, "meanRTT", meanRTT); 709 client->PushGuiMessage(msg); 710 } 711 712 return true; 713 } 714 630 715 bool CNetClient::OnLoadedGame(void* context, CFsmEvent* event) 631 716 { 632 717 ENSURE(event->GetType() == (uint)NMT_LOADED_GAME); 633 718 634 719 CNetClient* client = (CNetClient*)context; -
source/network/NetClient.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … public: 107 107 * This must be called frequently (i.e. once per frame). 108 108 */ 109 109 void Poll(); 110 110 111 111 /** 112 * Sends a GUI message if the connection is being lost or has bad latency. 113 */ 114 void CheckServerConnection(); 115 116 /** 112 117 * Flush any queued outgoing network messages. 113 118 * This should be called soon after sending a group of messages that may be batched together. 114 119 */ 115 120 void Flush(); 116 121 … … private: 200 205 static bool OnGameStart(void* context, CFsmEvent* event); 201 206 static bool OnJoinSyncStart(void* context, CFsmEvent* event); 202 207 static bool OnJoinSyncEndCommandBatch(void* context, CFsmEvent* event); 203 208 static bool OnRejoined(void* context, CFsmEvent* event); 204 209 static bool OnKicked(void* context, CFsmEvent* event); 210 static bool OnClientTimeout(void* context, CFsmEvent* event); 211 static bool OnClientPerformance(void* context, CFsmEvent* event); 205 212 static bool OnLoadedGame(void* context, CFsmEvent* event); 206 213 207 214 /** 208 215 * Take ownership of a session object, and use it for all network communication. 209 216 */ … … private: 238 245 /// Queue of messages for GuiPoll 239 246 std::deque<JS::Heap<JS::Value> > m_GuiMessageQueue; 240 247 241 248 /// Serialized game state received when joining an in-progress game 242 249 std::string m_JoinSyncBuffer; 250 251 /// Time when the server was last checked for timeout 252 u32 m_LastConnectionCheck; 243 253 }; 244 254 245 255 /// Global network client for the standard game 246 256 extern CNetClient *g_NetClient; 247 257 -
source/network/NetMessage.cpp
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … CNetMessage* CNetMessageFactory::CreateM 137 137 138 138 case NMT_KICKED: 139 139 pNewMessage = new CKickedMessage; 140 140 break; 141 141 142 case NMT_CLIENT_TIMEOUT: 143 pNewMessage = new CClientTimeoutMessage; 144 break; 145 146 case NMT_CLIENT_PERFORMANCE: 147 pNewMessage = new CClientPerformanceMessage; 148 break; 149 142 150 case NMT_LOADED_GAME: 143 151 pNewMessage = new CLoadedGameMessage; 144 152 break; 145 153 146 154 case NMT_SERVER_HANDSHAKE: -
source/network/NetMessages.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … 26 26 #include "ps/CStr.h" 27 27 #include "scriptinterface/ScriptVal.h" 28 28 29 29 #define PS_PROTOCOL_MAGIC 0x5073013f // 'P', 's', 0x01, '?' 30 30 #define PS_PROTOCOL_MAGIC_RESPONSE 0x50630121 // 'P', 'c', 0x01, '!' 31 #define PS_PROTOCOL_VERSION 0x0101000 8// Arbitrary protocol31 #define PS_PROTOCOL_VERSION 0x01010009 // Arbitrary protocol 32 32 #define PS_DEFAULT_PORT 0x5073 // 'P', 's' 33 33 34 34 // Defines the list of message types. The order of the list must not change. 35 35 // The message types having a negative value are used internally and not sent 36 36 // over the network. The message types used for network communication have … … enum NetMessageType 58 58 NMT_JOIN_SYNC_START, 59 59 60 60 NMT_REJOINED, 61 61 NMT_KICKED, 62 62 63 NMT_CLIENT_TIMEOUT, 64 NMT_CLIENT_PERFORMANCE, 65 63 66 NMT_LOADED_GAME, 64 67 NMT_GAME_START, 65 68 NMT_END_COMMAND_BATCH, 66 69 NMT_SYNC_CHECK, // OOS-detection hash checking 67 70 NMT_SYNC_ERROR, // OOS-detection error … … END_NMT_CLASS() 165 168 START_NMT_CLASS_(Kicked, NMT_KICKED) 166 169 NMT_FIELD(CStrW, m_Name) 167 170 NMT_FIELD_INT(m_Ban, u8, 1) 168 171 END_NMT_CLASS() 169 172 173 START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT) 174 NMT_FIELD(CStr8, m_GUID) 175 NMT_FIELD_INT(m_LastReceivedTime, u16, 2) 176 END_NMT_CLASS() 177 178 START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE) 179 NMT_START_ARRAY(m_Clients) 180 NMT_FIELD(CStr8, m_GUID) 181 NMT_FIELD_INT(m_MeanRTT, u16, 2) 182 NMT_END_ARRAY() 183 END_NMT_CLASS() 184 170 185 START_NMT_CLASS_(LoadedGame, NMT_LOADED_GAME) 171 186 NMT_FIELD_INT(m_CurrentTurn, u32, 4) 172 187 END_NMT_CLASS() 173 188 174 189 START_NMT_CLASS_(GameStart, NMT_GAME_START) -
source/network/NetServer.cpp
private: 119 119 120 120 CNetServerWorker::CNetServerWorker(int autostartPlayers) : 121 121 m_AutostartPlayers(autostartPlayers), 122 122 m_Shutdown(false), 123 123 m_ScriptInterface(NULL), 124 m_NextHostID(1), m_Host(NULL), m_HostGUID(), m_Stats(NULL) 124 m_NextHostID(1), m_Host(NULL), m_HostGUID(), m_Stats(NULL), 125 m_LastConnectionCheck(0) 125 126 { 126 127 m_State = SERVER_STATE_UNCONNECTED; 127 128 128 129 m_ServerTurnManager = NULL; 129 130 … … bool CNetServerWorker::RunStep() 449 450 450 451 // Perform file transfers 451 452 for (size_t i = 0; i < m_Sessions.size(); ++i) 452 453 m_Sessions[i]->GetFileTransferer().Poll(); 453 454 455 CheckClientConnections(); 456 454 457 // Process network events: 455 458 456 459 ENetEvent event; 457 int status = enet_host_service(m_Host, &event, HOST_SERVICE_TIMEOUT);460 int status = enet_host_service(m_Host, &event, NETWORK_WARNING_TIMEOUT); 458 461 if (status < 0) 459 462 { 460 463 LOGERROR("CNetServerWorker: enet_host_service failed (%d)", status); 461 464 // TODO: notify game that the server has shut down 462 465 return false; … … bool CNetServerWorker::RunStep() 547 550 } 548 551 549 552 return true; 550 553 } 551 554 555 void CNetServerWorker::CheckClientConnections() 556 { 557 // Send messages at most once per second 558 u32 now = std::time(nullptr); 559 if (now <= m_LastConnectionCheck) 560 return; 561 562 m_LastConnectionCheck = now; 563 564 for (size_t i = 0; i < m_Sessions.size(); ++i) 565 { 566 CNetMessage* message = nullptr; 567 568 // Report if we didn't hear from the client since few seconds 569 u32 lastReceived = m_Sessions[i]->GetLastReceivedTime() / 1000; 570 if (lastReceived > NETWORK_WARNING_TIMEOUT) 571 { 572 CClientTimeoutMessage* msg = new CClientTimeoutMessage(); 573 msg->m_GUID = m_Sessions[i]->GetGUID(); 574 msg->m_LastReceivedTime = lastReceived; 575 message = msg; 576 } 577 578 // Else report if the client has bad ping 579 u32 meanRTT = m_Sessions[i]->GetMeanRTT(); 580 if (!message && m_ServerTurnManager && meanRTT > m_ServerTurnManager->GetCurrentTurnLength() * NETWORK_WARNING_LATENCY) 581 { 582 CClientPerformanceMessage* msg = new CClientPerformanceMessage(); 583 CClientPerformanceMessage::S_m_Clients client; 584 client.m_GUID = m_Sessions[i]->GetGUID(); 585 client.m_MeanRTT = meanRTT; 586 msg->m_Clients.push_back(client); 587 message = msg; 588 } 589 590 // Send to all users except the affected one 591 if (message) 592 for (size_t j = 0; j < m_Sessions.size(); ++j) 593 if (i != j) 594 m_Sessions[j]->SendMessage(message); 595 } 596 } 597 552 598 void CNetServerWorker::HandleMessageReceive(const CNetMessage* message, CNetServerSession* session) 553 599 { 554 600 // Handle non-FSM messages first 555 601 Status status = session->GetFileTransferer().HandleMessageReceive(message); 556 602 if (status != INFO::SKIPPED) -
source/network/NetServer.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … private: 279 279 280 280 void ConstructPlayerAssignmentMessage(CPlayerAssignmentMessage& message); 281 281 282 282 void HandleMessageReceive(const CNetMessage* message, CNetServerSession* session); 283 283 284 /** 285 * Send a network warning if the connection to a client is being lost or has bad latency. 286 */ 287 void CheckClientConnections(); 284 288 285 289 /** 286 290 * Internal script context for (de)serializing script messages, 287 291 * and for storing game attributes. 288 292 * (TODO: we shouldn't bother deserializing (except for debug printing of messages), … … private: 329 333 * The latest copy of the simulation state, received from an existing 330 334 * client when a new client has asked to rejoin the game. 331 335 */ 332 336 std::string m_JoinSyncFile; 333 337 338 /** 339 * Time when the clients connections were last checked for timeouts and latency. 340 */ 341 u32 m_LastConnectionCheck; 342 334 343 private: 335 344 // Thread-related stuff: 336 345 337 346 #if CONFIG2_MINIUPNPC 338 347 /** -
source/network/NetSession.cpp
bool CNetClientSession::SendMessage(cons 166 166 ENSURE(m_Host && m_Server); 167 167 168 168 return CNetHost::SendMessage(message, m_Server, "server"); 169 169 } 170 170 171 u32 CNetClientSession::GetLastReceivedTime() const 172 { 173 return m_Server ? enet_time_get() - m_Server->lastReceiveTime : 0; 174 } 175 176 u32 CNetClientSession::GetMeanRTT() const 177 { 178 return m_Server ? m_Server->roundTripTime : 0; 179 } 180 171 181 172 182 173 183 CNetServerSession::CNetServerSession(CNetServerWorker& server, ENetPeer* peer) : 174 184 m_Server(server), m_FileTransferer(this), m_Peer(peer) 175 185 { … … CStr CNetServerSession::GetIPAddress() c 182 192 LOGMESSAGE("Could not get IP address of a client!"); 183 193 184 194 return ipAddress; 185 195 } 186 196 197 u32 CNetServerSession::GetLastReceivedTime() const 198 { 199 return m_Peer ? enet_time_get() - m_Peer->lastReceiveTime : 0; 200 } 201 202 u32 CNetServerSession::GetMeanRTT() const 203 { 204 return m_Peer ? m_Peer->roundTripTime : 0; 205 } 206 187 207 void CNetServerSession::Disconnect(u32 reason) 188 208 { 189 209 Update((uint)NMT_CONNECTION_LOST, NULL); 190 210 191 211 enet_peer_disconnect(m_Peer, reason); -
source/network/NetSession.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … 22 22 #include "network/NetFileTransfer.h" 23 23 #include "network/NetHost.h" 24 24 #include "ps/CStr.h" 25 25 #include "scriptinterface/ScriptVal.h" 26 26 27 /** 28 * Report the peer if we didn't receive a packet after this number of seconds. 29 */ 30 static const int NETWORK_WARNING_TIMEOUT = 4; 31 32 /** 33 * Report the peer if the mean RTT takes longer than this multiple of a turnlength. 34 */ 35 static const float NETWORK_WARNING_LATENCY = 1.1f; 36 27 37 class CNetClient; 28 38 class CNetServerWorker; 29 39 30 40 class CNetStatsTable; 31 41 … … public: 81 91 /** 82 92 * Send a message to the server. 83 93 */ 84 94 virtual bool SendMessage(const CNetMessage* message); 85 95 96 /** 97 * Number of milliseconds since the most recent packet of the server was received. 98 */ 99 u32 GetLastReceivedTime() const; 100 101 /** 102 * Average round trip time to the server. 103 */ 104 u32 GetMeanRTT() const; 105 86 106 CNetFileTransferer& GetFileTransferer() { return m_FileTransferer; } 87 107 88 108 private: 89 109 CNetClient& m_Client; 90 110 … … public: 123 143 void SetHostID(u32 id) { m_HostID = id; } 124 144 125 145 CStr GetIPAddress() const; 126 146 127 147 /** 148 * Number of milliseconds since the latest packet of that client was received. 149 */ 150 u32 GetLastReceivedTime() const; 151 152 /** 153 * Average round trip time to the client. 154 */ 155 u32 GetMeanRTT() const; 156 157 /** 128 158 * Sends a disconnection notification to the client, 129 159 * and sends a NMT_CONNECTION_LOST message to the session FSM. 130 160 * The server will receive a disconnection notification after a while. 131 161 * The server will not receive any further messages sent via this session. 132 162 */ -
source/network/NetTurnManager.h
public: 139 139 void RewindTimeWarp(); 140 140 141 141 void QuickSave(); 142 142 void QuickLoad(); 143 143 144 u32 GetCurrentTurn() { return m_CurrentTurn; } 144 u32 GetCurrentTurn() const { return m_CurrentTurn; } 145 u32 GetCurrentTurnLength() const { return m_TurnLength; }; 145 146 146 147 protected: 147 148 /** 148 149 * Store a command to be executed at a given turn. 149 150 */ … … public: 318 319 * Returns the turn length that was used for the given turn. 319 320 * Requires turn <= GetReadyTurn(). 320 321 */ 321 322 u32 GetSavedTurnLength(u32 turn); 322 323 324 /** 325 * Returns the used turn length in milliseconds. 326 */ 327 u32 GetCurrentTurnLength() const { return m_TurnLength; }; 328 323 329 protected: 324 330 void CheckClientsReady(); 325 331 326 332 /// The latest turn for which we have received all commands from all clients 327 333 u32 m_ReadyTurn;