Index: binaries/data/mods/public/gui/gamesetup/NetMessages/NetMessages.js =================================================================== --- binaries/data/mods/public/gui/gamesetup/NetMessages/NetMessages.js +++ binaries/data/mods/public/gui/gamesetup/NetMessages/NetMessages.js @@ -35,8 +35,6 @@ if (!message) break; - log("Net message: " + uneval(message)); - if (this.netMessageHandlers[message.type]) for (let handler of this.netMessageHandlers[message.type]) handler(message); Index: binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js =================================================================== --- binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js +++ binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js @@ -190,7 +190,6 @@ if (!message) break; - log(sprintf(translate("Net message: %(message)s"), { "message": uneval(message) })); // If we're rejoining an active game, we don't want to actually display // the game setup screen, so perform similar processing to gamesetup.js // in this screen @@ -350,7 +349,7 @@ Engine.ConfigDB_CreateValue("user", "playername.multiplayer", playername); Engine.ConfigDB_CreateValue("user", "multiplayerhosting.port", port); Engine.ConfigDB_SaveChanges("user"); - + let hostFeedback = Engine.GetGUIObjectByName("hostFeedback"); // Disallow identically named games in the multiplayer lobby Index: binaries/data/mods/public/gui/session/messages.js =================================================================== --- binaries/data/mods/public/gui/session/messages.js +++ binaries/data/mods/public/gui/session/messages.js @@ -433,8 +433,6 @@ if (!msg) return; - log("Net message: " + uneval(msg)); - if (g_NetMessageTypes[msg.type]) g_NetMessageTypes[msg.type](msg); else Index: source/network/NetClient.cpp =================================================================== --- source/network/NetClient.cpp +++ source/network/NetClient.cpp @@ -43,6 +43,14 @@ #include "simulation2/Simulation2.h" #include "network/StunClient.h" +#if NDEBUG +#define LOGNETWORKMESSAGE(msg) +#define LOGNETWORKMESSAGERENDER(msg) +#else +#define LOGNETWORKMESSAGE(msg) LOGMESSAGE(msg) +#define LOGNETWORKMESSAGERENDER(msg) LOGMESSAGERENDER(msg) +#endif + /** * Once ping goes above turn length * command delay, * the game will start 'freezing' for other clients while we catch up. @@ -300,7 +308,7 @@ port = enetClient->address.port; } - LOGMESSAGE("NetClient: connecting to server at %s:%i", m_ServerAddress, m_ServerPort); + LOGNETWORKMESSAGE("NetClient: connecting to server at %s:%i", m_ServerAddress, m_ServerPort); if (!ip.empty()) { @@ -562,7 +570,7 @@ std::stringstream stream; - LOGMESSAGERENDER("Serializing game at turn %u for rejoining player", m_ClientTurnManager->GetCurrentTurn()); + LOGNETWORKMESSAGERENDER("Serializing game at turn %u for rejoining player", m_ClientTurnManager->GetCurrentTurn()); u32 turn = to_le32(m_ClientTurnManager->GetCurrentTurn()); stream.write((char*)&turn, sizeof(turn)); @@ -602,7 +610,7 @@ stream.read((char*)&turn, sizeof(turn)); turn = to_le32(turn); - LOGMESSAGE("Rejoining client deserializing state at turn %u\n", turn); + LOGNETWORKMESSAGE("Rejoining client deserializing state at turn %u\n", turn); bool ok = m_Game->GetSimulation2()->DeserializeState(stream); ENSURE(ok); @@ -683,7 +691,7 @@ "status", "disconnected", "reason", static_cast(NDR_LOBBY_AUTH_FAILED)); - LOGMESSAGE("Net client: Couldn't send lobby auth xmpp message"); + LOGNETWORKMESSAGE("Net client: Couldn't send lobby auth xmpp message"); } return true; } @@ -708,7 +716,7 @@ CNetClient* client = static_cast(context); CAuthenticateResultMessage* message = static_cast(event->GetParamRef()); - LOGMESSAGE("Net: Authentication result: host=%u, %s", message->m_HostID, utf8_from_wstring(message->m_Message)); + LOGNETWORKMESSAGE("Net: Authentication result: host=%u, %s", message->m_HostID, utf8_from_wstring(message->m_Message)); client->m_HostID = message->m_HostID; client->m_Rejoin = message->m_Code == ARC_OK_REJOINING; Index: source/network/NetHost.cpp =================================================================== --- source/network/NetHost.cpp +++ source/network/NetHost.cpp @@ -23,13 +23,21 @@ #include "network/NetMessage.h" #include "ps/CLogger.h" +#if NDEBUG +#define LOGNETWORKMESSAGE(msg) +#define LOGNETWORKMESSAGERENDER(msg) +#else +#define LOGNETWORKMESSAGE(msg) LOGMESSAGE(msg) +#define LOGNETWORKMESSAGERENDER(msg) LOGMESSAGERENDER(msg) +#endif + bool CNetHost::SendMessage(const CNetMessage* message, ENetPeer* peer, const char* peerName) { ENetPacket* packet = CreatePacket(message); if (!packet) return false; - LOGMESSAGE("Net: Sending message %s of size %lu to %s", message->ToString().c_str(), (unsigned long)packet->dataLength, peerName); + LOGNETWORKMESSAGE("Net: Sending message %s of size %lu to %s", message->ToString().c_str(), (unsigned long)packet->dataLength, peerName); // Let ENet send the message to peer if (enet_peer_send(peer, DEFAULT_CHANNEL, packet) < 0) Index: source/network/NetServer.cpp =================================================================== --- source/network/NetServer.cpp +++ source/network/NetServer.cpp @@ -50,6 +50,14 @@ #include +#if NDEBUG +#define LOGNETWORKMESSAGE(msg) +#define LOGNETWORKMESSAGERENDER(msg) +#else +#define LOGNETWORKMESSAGE(msg) LOGMESSAGE(msg) +#define LOGNETWORKMESSAGERENDER(msg) LOGMESSAGERENDER(msg) +#endif + /** * Number of peers to allocate for the enet host. * Limited by ENET_PROTOCOL_MAXIMUM_PEER_ID (4096). @@ -120,7 +128,7 @@ if (!session) { - LOGMESSAGE("Net server: rejoining client disconnected before we sent to it"); + LOGNETWORKMESSAGE("Net server: rejoining client disconnected before we sent to it"); return; } @@ -286,14 +294,14 @@ std::string rootDescURL; CFG_GET_VAL("network.upnprootdescurl", rootDescURL); if (!rootDescURL.empty()) - LOGMESSAGE("Net server: attempting to use cached root descriptor URL: %s", rootDescURL.c_str()); + LOGNETWORKMESSAGE("Net server: attempting to use cached root descriptor URL: %s", rootDescURL.c_str()); int ret = 0; // Try a cached URL first if (!rootDescURL.empty() && UPNP_GetIGDFromUrl(rootDescURL.c_str(), &urls, &data, internalIPAddress, sizeof(internalIPAddress))) { - LOGMESSAGE("Net server: using cached IGD = %s", urls.controlURL); + LOGNETWORKMESSAGE("Net server: using cached IGD = %s", urls.controlURL); ret = 1; } // No cached URL, or it did not respond. Try getting a valid UPnP device for 10 seconds. @@ -308,7 +316,7 @@ } else { - LOGMESSAGE("Net server: upnpDiscover failed and no working cached URL."); + LOGNETWORKMESSAGE("Net server: upnpDiscover failed and no working cached URL."); freeUPnP(); return; } @@ -316,16 +324,16 @@ switch (ret) { case 0: - LOGMESSAGE("Net server: No IGD found"); + LOGNETWORKMESSAGE("Net server: No IGD found"); break; case 1: - LOGMESSAGE("Net server: found valid IGD = %s", urls.controlURL); + LOGNETWORKMESSAGE("Net server: found valid IGD = %s", urls.controlURL); break; case 2: - LOGMESSAGE("Net server: found a valid, not connected IGD = %s, will try to continue anyway", urls.controlURL); + LOGNETWORKMESSAGE("Net server: found a valid, not connected IGD = %s, will try to continue anyway", urls.controlURL); break; case 3: - LOGMESSAGE("Net server: found a UPnP device unrecognized as IGD = %s, will try to continue anyway", urls.controlURL); + LOGNETWORKMESSAGE("Net server: found a UPnP device unrecognized as IGD = %s, will try to continue anyway", urls.controlURL); break; default: debug_warn(L"Unrecognized return value from UPNP_GetValidIGD"); @@ -335,18 +343,18 @@ ret = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress); if (ret != UPNPCOMMAND_SUCCESS) { - LOGMESSAGE("Net server: GetExternalIPAddress failed with code %d (%s)", ret, strupnperror(ret)); + LOGNETWORKMESSAGE("Net server: GetExternalIPAddress failed with code %d (%s)", ret, strupnperror(ret)); freeUPnP(); return; } - LOGMESSAGE("Net server: ExternalIPAddress = %s", externalIPAddress); + LOGNETWORKMESSAGE("Net server: ExternalIPAddress = %s", externalIPAddress); // Try to setup port forwarding. ret = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, psPort, psPort, internalIPAddress, description, protocall, 0, leaseDuration); if (ret != UPNPCOMMAND_SUCCESS) { - LOGMESSAGE("Net server: AddPortMapping(%s, %s, %s) failed with code %d (%s)", + LOGNETWORKMESSAGE("Net server: AddPortMapping(%s, %s, %s) failed with code %d (%s)", psPort, psPort, internalIPAddress, ret, strupnperror(ret)); freeUPnP(); return; @@ -364,18 +372,18 @@ if (ret != UPNPCOMMAND_SUCCESS) { - LOGMESSAGE("Net server: GetSpecificPortMappingEntry() failed with code %d (%s)", ret, strupnperror(ret)); + LOGNETWORKMESSAGE("Net server: GetSpecificPortMappingEntry() failed with code %d (%s)", ret, strupnperror(ret)); freeUPnP(); return; } - LOGMESSAGE("Net server: External %s:%s %s is redirected to internal %s:%s (duration=%s)", + LOGNETWORKMESSAGE("Net server: External %s:%s %s is redirected to internal %s:%s (duration=%s)", externalIPAddress, psPort, protocall, intClient, intPort, duration); // Cache root descriptor URL to try to avoid discovery next time. g_ConfigDB.SetValueString(CFG_USER, "network.upnprootdescurl", urls.controlURL); g_ConfigDB.WriteValueToFile(CFG_USER, "network.upnprootdescurl", urls.controlURL); - LOGMESSAGE("Net server: cached UPnP root descriptor URL as %s", urls.controlURL); + LOGNETWORKMESSAGE("Net server: cached UPnP root descriptor URL as %s", urls.controlURL); freeUPnP(); } @@ -520,7 +528,7 @@ // Report the client address char hostname[256] = "(error)"; enet_address_get_host_ip(&event.peer->address, hostname, ARRAY_SIZE(hostname)); - LOGMESSAGE("Net server: Received connection from %s:%u", hostname, (unsigned int)event.peer->address.port); + LOGNETWORKMESSAGE("Net server: Received connection from %s:%u", hostname, (unsigned int)event.peer->address.port); // Set up a session object for this peer @@ -545,7 +553,7 @@ CNetServerSession* session = static_cast(event.peer->data); if (session) { - LOGMESSAGE("Net server: Disconnected %s", DebugName(session).c_str()); + LOGNETWORKMESSAGE("Net server: Disconnected %s", DebugName(session).c_str()); // Remove the session first, so we won't send player-update messages to it // when updating the FSM @@ -574,7 +582,7 @@ CNetMessage* msg = CNetMessageFactory::CreateMessage(event.packet->data, event.packet->dataLength, GetScriptInterface()); if (msg) { - LOGMESSAGE("Net server: Received message %s of size %lu from %s", msg->ToString().c_str(), (unsigned long)msg->GetSerializedLength(), DebugName(session).c_str()); + LOGNETWORKMESSAGE("Net server: Received message %s of size %lu from %s", msg->ToString().c_str(), (unsigned long)msg->GetSerializedLength(), DebugName(session).c_str()); HandleMessageReceive(msg, session); @@ -909,7 +917,7 @@ void CNetServerWorker::ProcessLobbyAuth(const CStr& name, const CStr& token) { - LOGMESSAGE("Net Server: Received lobby auth message from %s with %s", name, token); + LOGNETWORKMESSAGE("Net Server: Received lobby auth message from %s with %s", name, token); // Find the user with that guid std::vector::iterator it = std::find_if(m_Sessions.begin(), m_Sessions.end(), [&](CNetServerSession* session) @@ -983,7 +991,7 @@ // Prohibit joins while the game is loading if (server.m_State == SERVER_STATE_LOADING) { - LOGMESSAGE("Refused connection while the game is loading"); + LOGNETWORKMESSAGE("Refused connection while the game is loading"); session->Disconnect(NDR_SERVER_LOADING); return true; } @@ -1108,7 +1116,7 @@ if (!isRejoining) { - LOGMESSAGE("Refused connection after game start from not-previously-known user \"%s\"", utf8_from_wstring(username)); + LOGNETWORKMESSAGE("Refused connection after game start from not-previously-known user \"%s\"", utf8_from_wstring(username)); session->Disconnect(NDR_SERVER_ALREADY_IN_GAME); return true; } Index: source/network/NetSession.cpp =================================================================== --- source/network/NetSession.cpp +++ source/network/NetSession.cpp @@ -27,6 +27,14 @@ #include "ps/CLogger.h" #include "ps/Profile.h" +#if NDEBUG +#define LOGNETWORKMESSAGE(msg) +#define LOGNETWORKMESSAGERENDER(msg) +#else +#define LOGNETWORKMESSAGE(msg) LOGMESSAGE(msg) +#define LOGNETWORKMESSAGERENDER(msg) LOGMESSAGERENDER(msg) +#endif + constexpr int NETCLIENT_POLL_TIMEOUT = 50; constexpr int CHANNEL_COUNT = 1; @@ -133,7 +141,7 @@ // Report the server address immediately. char hostname[256] = "(error)"; enet_address_get_host_ip(&event.peer->address, hostname, ARRAY_SIZE(hostname)); - LOGMESSAGE("Net client: Connected to %s:%u", hostname, (unsigned int)event.peer->address.port); + LOGNETWORKMESSAGE("Net client: Connected to %s:%u", hostname, (unsigned int)event.peer->address.port); m_Connected = true; m_IncomingMessages.push(event); @@ -143,7 +151,7 @@ ENSURE(event.peer == m_Server); // Report immediately. - LOGMESSAGE("Net client: Disconnected"); + LOGNETWORKMESSAGE("Net client: Disconnected"); m_Connected = false; m_IncomingMessages.push(event); @@ -162,7 +170,7 @@ if (m_Connected) LOGERROR("NetClient: Failed to send packet to server"); else - LOGMESSAGE("NetClient: Failed to send packet to server"); + LOGNETWORKMESSAGE("NetClient: Failed to send packet to server"); } enet_host_flush(m_Host); @@ -186,7 +194,7 @@ CNetMessage* msg = CNetMessageFactory::CreateMessage(event.packet->data, event.packet->dataLength, m_Client.GetScriptInterface()); if (msg) { - LOGMESSAGE("Net client: Received message %s of size %lu from server", msg->ToString().c_str(), (unsigned long)msg->GetSerializedLength()); + LOGNETWORKMESSAGE("Net client: Received message %s of size %lu from server", msg->ToString().c_str(), (unsigned long)msg->GetSerializedLength()); m_Client.HandleMessage(msg); }