Index: binaries/data/mods/public/gui/common/functions_global_object.js =================================================================== --- binaries/data/mods/public/gui/common/functions_global_object.js +++ binaries/data/mods/public/gui/common/functions_global_object.js @@ -66,7 +66,7 @@ { Engine.EndGame(); - if (Engine.HasXmppClient()) + if (Engine.HasXmppClient && Engine.HasXmppClient()) Engine.StopXmppClient(); Engine.SwitchGuiPage("page_pregame.xml"); Index: binaries/data/mods/public/gui/gamesetup/gamesetup.js =================================================================== --- binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -919,7 +919,7 @@ "lockTeams": { "title": () => translate("Teams Locked"), "tooltip": () => translate("Toggle locked teams."), - "default": () => Engine.HasXmppClient(), + "default": () => Engine.HasXmppClient && Engine.HasXmppClient(), "defined": () => g_GameAttributes.settings.LockTeams !== undefined, "get": () => g_GameAttributes.settings.LockTeams, "set": checked => { @@ -959,6 +959,8 @@ "enabled": () => !g_GameAttributes.settings.RatingEnabled, "initOrder": 1000 }, + }, + Engine.HasXmppClient && { "enableRating": { "title": () => translate("Rated Game"), "tooltip": () => translate("Toggle if this game will be rated for the leaderboard."), @@ -1044,7 +1046,7 @@ "cancelGame": { "caption": () => translate("Back"), "tooltip": () => - Engine.HasXmppClient() ? + Engine.HasXmppClient && Engine.HasXmppClient() ? translate("Return to the lobby.") : translate("Return to the main menu."), "onPress": () => cancelSetup, @@ -1136,10 +1138,10 @@ }, "lobbyButton": { "onPress": () => function() { - if (Engine.HasXmppClient()) + if (Engine.HasXmppClient && Engine.HasXmppClient()) Engine.PushGuiPage("page_lobby.xml", { "dialog": true }); }, - "hidden": () => !Engine.HasXmppClient() + "hidden": () => !Engine.HasXmppClient || !Engine.HasXmppClient() }, "spTips": { "hidden": () => { @@ -1632,7 +1634,7 @@ function handleGamestartMessage(message) { // Immediately inform the lobby server instead of waiting for the load to finish - if (g_IsController && Engine.HasXmppClient()) + if (g_IsController && Engine.HasXmppClient && Engine.HasXmppClient()) { sendRegisterGameStanzaImmediate(); let clients = formatClientsForStanza(); @@ -1987,8 +1989,11 @@ reloadMapFilterList(); reloadMapSpecific(); - g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient(); - Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled); + if (Engine.HasXmppClient) + { + g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient(); + Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled); + } supplementDefaults(); @@ -2048,7 +2053,7 @@ Engine.DisconnectNetworkGame(); - if (Engine.HasXmppClient()) + if (Engine.HasXmppClient && Engine.HasXmppClient()) { Engine.LobbySetPlayerPresence("available"); @@ -2705,7 +2710,7 @@ */ function sendRegisterGameStanzaImmediate() { - if (!g_IsController || !Engine.HasXmppClient()) + if (!g_IsController || !Engine.HasXmppClient || !Engine.HasXmppClient()) return; if (g_GameStanzaTimer !== undefined) @@ -2746,7 +2751,7 @@ */ function sendRegisterGameStanza() { - if (!g_IsController || !Engine.HasXmppClient()) + if (!g_IsController || !Engine.HasXmppClient || !Engine.HasXmppClient()) return; if (g_GameStanzaTimer !== undefined) 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 @@ -36,7 +36,7 @@ { case "join": { - if (Engine.HasXmppClient()) + if (Engine.HasXmppClient && Engine.HasXmppClient()) { if (startJoin(attribs.name, attribs.ip, getValidPort(attribs.port), attribs.useSTUN, attribs.hostJID)) switchSetupPage("pageConnecting"); @@ -47,8 +47,8 @@ } case "host": { - Engine.GetGUIObjectByName("hostSTUNWrapper").hidden = !Engine.HasXmppClient(); - if (Engine.HasXmppClient()) + Engine.GetGUIObjectByName("hostSTUNWrapper").hidden = !Engine.HasXmppClient || !Engine.HasXmppClient(); + if (Engine.HasXmppClient && Engine.HasXmppClient()) { Engine.GetGUIObjectByName("hostPlayerName").caption = attribs.name; Engine.GetGUIObjectByName("hostServerName").caption = @@ -71,11 +71,11 @@ if (g_IsConnecting) Engine.DisconnectNetworkGame(); - if (Engine.HasXmppClient()) + if (Engine.HasXmppClient && Engine.HasXmppClient()) Engine.LobbySetPlayerPresence("available"); // Keep the page open if an attempt to join/host by ip failed - if (!g_IsConnecting || (Engine.HasXmppClient() && g_GameType == "client")) + if (!g_IsConnecting || (Engine.HasXmppClient && Engine.HasXmppClient() && g_GameType == "client")) { Engine.PopGuiPage(); return; @@ -263,10 +263,12 @@ if (page.name.startsWith("page")) page.hidden = true; + let hasXmpp = Engine.HasXmppClient && Engine.HasXmppClient(); + if (newPage == "pageJoin" || newPage == "pageHost") { let pageSize = multiplayerPages.size; - let halfHeight = newPage == "pageJoin" ? 130 : Engine.HasXmppClient() ? 125 : 110; + let halfHeight = newPage == "pageJoin" ? 130 : hasXmpp ? 125 : 110; pageSize.top = -halfHeight; pageSize.bottom = halfHeight; multiplayerPages.size = pageSize; @@ -274,8 +276,8 @@ Engine.GetGUIObjectByName(newPage).hidden = false; - Engine.GetGUIObjectByName("hostPlayerNameWrapper").hidden = Engine.HasXmppClient(); - Engine.GetGUIObjectByName("hostServerNameWrapper").hidden = !Engine.HasXmppClient(); + Engine.GetGUIObjectByName("hostPlayerNameWrapper").hidden = hasXmpp; + Engine.GetGUIObjectByName("hostServerNameWrapper").hidden = !hasXmpp; Engine.GetGUIObjectByName("continueButton").hidden = newPage == "pageConnecting"; } @@ -290,8 +292,10 @@ let hostFeedback = Engine.GetGUIObjectByName("hostFeedback"); + let hasXmpp = Engine.HasXmppClient && Engine.HasXmppClient(); + // Disallow identically named games in the multiplayer lobby - if (Engine.HasXmppClient() && + if (hasXmpp && Engine.GetGameList().some(game => game.name == servername)) { cancelSetup(); @@ -299,7 +303,7 @@ return false; } - if (Engine.HasXmppClient() && Engine.GetGUIObjectByName("useSTUN").checked) + if (hasXmpp && Engine.GetGUIObjectByName("useSTUN").checked) { g_StunEndpoint = Engine.FindStunEndpoint(port); if (!g_StunEndpoint) @@ -328,7 +332,7 @@ g_ServerName = servername; g_ServerPort = port; - if (Engine.HasXmppClient()) + if (hasXmpp) Engine.LobbySetPlayerPresence("playing"); return true; @@ -356,7 +360,7 @@ startConnectionStatus("client"); - if (Engine.HasXmppClient()) + if (Engine.HasXmppClient && Engine.HasXmppClient()) Engine.LobbySetPlayerPresence("playing"); else { Index: binaries/data/mods/public/gui/prelobby/common/feedback/feedback.js =================================================================== --- binaries/data/mods/public/gui/prelobby/common/feedback/feedback.js +++ binaries/data/mods/public/gui/prelobby/common/feedback/feedback.js @@ -33,7 +33,7 @@ function cancelButton() { - if (Engine.HasXmppClient()) + if (Engine.HasXmppClient && Engine.HasXmppClient()) Engine.StopXmppClient(); Engine.PopGuiPage(); } Index: binaries/data/mods/public/gui/session/menu.js =================================================================== --- binaries/data/mods/public/gui/session/menu.js +++ binaries/data/mods/public/gui/session/menu.js @@ -127,7 +127,7 @@ function lobbyDialogButton() { - if (!Engine.HasXmppClient()) + if (!Engine.HasXmppClient || !Engine.HasXmppClient()) return; closeOpenDialogs(); Index: binaries/data/mods/public/gui/session/session.js =================================================================== --- binaries/data/mods/public/gui/session/session.js +++ binaries/data/mods/public/gui/session/session.js @@ -701,7 +701,7 @@ Engine.GetGUIObjectByName("pauseButton").enabled = !g_IsObserver || !g_IsNetworked || g_IsController; Engine.GetGUIObjectByName("menuResignButton").enabled = !g_IsObserver; - Engine.GetGUIObjectByName("lobbyButton").enabled = Engine.HasXmppClient(); + Engine.GetGUIObjectByName("lobbyButton").enabled = Engine.HasXmppClient && Engine.HasXmppClient(); } /** @@ -742,7 +742,7 @@ if (!g_IsReplay) Engine.AddReplayToCache(replayDirectory); - if (g_IsController && Engine.HasXmppClient()) + if (g_IsController && Engine.HasXmppClient && Engine.HasXmppClient()) Engine.SendUnregisterGame(); Engine.SwitchGuiPage("page_summary.xml", { @@ -1468,7 +1468,7 @@ */ function sendLobbyPlayerlistUpdate() { - if (!g_IsController || !Engine.HasXmppClient()) + if (!g_IsController || !Engine.HasXmppClient || !Engine.HasXmppClient()) return; // Extract the relevant player data and minimize packet load @@ -1528,7 +1528,7 @@ function reportGame() { // Only 1v1 games are rated (and Gaia is part of g_Players) - if (!Engine.HasXmppClient() || !Engine.IsRankedGame() || + if (!Engine.HasXmppClient || !Engine.HasXmppClient() || !Engine.IsRankedGame() || g_Players.length != 3 || Engine.GetPlayerID() == -1) return; Index: binaries/data/mods/public/gui/summary/summary.js =================================================================== --- binaries/data/mods/public/gui/summary/summary.js +++ binaries/data/mods/public/gui/summary/summary.js @@ -449,7 +449,7 @@ }); else if (g_GameData.gui.dialog) Engine.PopGuiPage(); - else if (Engine.HasXmppClient()) + else if (Engine.HasXmppClient && Engine.HasXmppClient()) Engine.SwitchGuiPage("page_lobby.xml", { "dialog": false }); else if (g_GameData.gui.isReplay) Engine.SwitchGuiPage("page_replaymenu.xml", { @@ -523,7 +523,7 @@ let lobbyButton = Engine.GetGUIObjectByName("lobbyButton"); lobbyButton.tooltip = colorizeHotkey(translate("%(hotkey)s: Toggle the multiplayer lobby in a dialog window."), "lobby"); - lobbyButton.hidden = g_GameData.gui.isInGame || !Engine.HasXmppClient(); + lobbyButton.hidden = g_GameData.gui.isInGame || !Engine.HasXmppClient || !Engine.HasXmppClient(); // Right-align lobby button let lobbyButtonSize = lobbyButton.size; Index: binaries/data/mods/public/gui/summary/summary.xml =================================================================== --- binaries/data/mods/public/gui/summary/summary.xml +++ binaries/data/mods/public/gui/summary/summary.xml @@ -218,7 +218,7 @@ hotkey="lobby" > - if (Engine.HasXmppClient()) + if (Engine.HasXmppClient && Engine.HasXmppClient()) Engine.PushGuiPage("page_lobby.xml", { "dialog": true }); Index: build/premake/premake5.lua =================================================================== --- build/premake/premake5.lua +++ build/premake/premake5.lua @@ -641,18 +641,6 @@ setup_static_lib_project("glooxwrapper", source_dirs, extern_libs, {}) end end - else - source_dirs = { - "lobby/scripting", - "third_party/encryption" - } - extern_libs = { - "spidermonkey", - "boost", - "libsodium" - } - setup_static_lib_project("lobby", source_dirs, extern_libs, {}) - files { source_root.."lobby/Globals.cpp" } end @@ -1320,8 +1308,10 @@ local test_files = {} for i,v in pairs(all_files) do -- Don't include sysdep tests on the wrong sys + -- Don't include pbkdf2 tests unless pbkdf2/lobby is being built -- Don't include Atlas tests unless Atlas is being built if not (string.find(v, "/sysdep/os/win/") and not os.istarget("windows")) and + not (string.find(v, "/third_party/encryption/") and _OPTIONS["without-lobby"]) and not (string.find(v, "/tools/atlas/") and not _OPTIONS["atlas"]) and not (string.find(v, "/sysdep/arch/x86_x64/") and ((arch ~= "amd64") or (arch ~= "x86"))) then Index: source/graphics/GameView.cpp =================================================================== --- source/graphics/GameView.cpp +++ source/graphics/GameView.cpp @@ -37,7 +37,9 @@ #include "graphics/scripting/JSInterface_GameView.h" #include "lib/input.h" #include "lib/timer.h" +#if CONFIG2_LOBBY #include "lobby/IXmppClient.h" +#endif #include "maths/BoundingBoxAligned.h" #include "maths/MathUtil.h" #include "maths/Matrix3D.h" @@ -1039,9 +1041,11 @@ if (hotkey == "wireframe") { +#if CONFIG2_LOBBY if (g_XmppClient && g_rankedGame == true) break; - else if (g_Renderer.GetModelRenderMode() == SOLID) +#endif + if (g_Renderer.GetModelRenderMode() == SOLID) { g_Renderer.SetTerrainRenderMode(EDGED_FACES); g_Renderer.SetWaterRenderMode(EDGED_FACES); Index: source/gui/scripting/ScriptFunctions.cpp =================================================================== --- source/gui/scripting/ScriptFunctions.cpp +++ source/gui/scripting/ScriptFunctions.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -24,7 +24,10 @@ #include "gui/scripting/JSInterface_GUIManager.h" #include "gui/scripting/JSInterface_GUITypes.h" #include "i18n/scripting/JSInterface_L10n.h" +#include "lib/config2.h" +#if CONFIG2_LOBBY #include "lobby/scripting/JSInterface_Lobby.h" +#endif #include "network/scripting/JSInterface_Network.h" #include "ps/scripting/JSInterface_ConfigDB.h" #include "ps/scripting/JSInterface_Console.h" @@ -59,7 +62,9 @@ JSI_Game::RegisterScriptFunctions(scriptInterface); JSI_GameView::RegisterScriptFunctions(scriptInterface); JSI_L10n::RegisterScriptFunctions(scriptInterface); +#if CONFIG2_LOBBY JSI_Lobby::RegisterScriptFunctions(scriptInterface); +#endif JSI_Main::RegisterScriptFunctions(scriptInterface); JSI_Mod::RegisterScriptFunctions(scriptInterface); JSI_ModIo::RegisterScriptFunctions(scriptInterface); Index: source/lobby/scripting/JSInterface_Lobby.h =================================================================== --- source/lobby/scripting/JSInterface_Lobby.h +++ source/lobby/scripting/JSInterface_Lobby.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_JSI_LOBBY #define INCLUDED_JSI_LOBBY -#include "lib/config2.h" #include "scriptinterface/ScriptInterface.h" #include @@ -30,8 +29,6 @@ bool HasXmppClient(ScriptInterface::CxPrivate* pCxPrivate); bool IsRankedGame(ScriptInterface::CxPrivate* pCxPrivate); void SetRankedGame(ScriptInterface::CxPrivate* pCxPrivate, bool isRanked); - -#if CONFIG2_LOBBY void StartXmppClient(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& username, const std::wstring& password, const std::wstring& room, const std::wstring& nick, int historyRequestSize); void StartRegisterXmppClient(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& username, const std::wstring& password); void StopXmppClient(ScriptInterface::CxPrivate* pCxPrivate); @@ -66,7 +63,6 @@ // Public hash interface. std::wstring EncryptPassword(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& pass, const std::wstring& user); -#endif // CONFIG2_LOBBY } #endif // INCLUDED_JSI_LOBBY Index: source/lobby/scripting/JSInterface_Lobby.cpp =================================================================== --- source/lobby/scripting/JSInterface_Lobby.cpp +++ source/lobby/scripting/JSInterface_Lobby.cpp @@ -39,7 +39,6 @@ scriptInterface.RegisterFunction("HasXmppClient"); scriptInterface.RegisterFunction("IsRankedGame"); scriptInterface.RegisterFunction("SetRankedGame"); -#if CONFIG2_LOBBY // Allow the lobby to be disabled scriptInterface.RegisterFunction("StartXmppClient"); scriptInterface.RegisterFunction("StartRegisterXmppClient"); scriptInterface.RegisterFunction("StopXmppClient"); @@ -69,7 +68,6 @@ scriptInterface.RegisterFunction("LobbyGetPlayerRole"); scriptInterface.RegisterFunction("EncryptPassword"); scriptInterface.RegisterFunction("LobbyGetRoomSubject"); -#endif // CONFIG2_LOBBY } bool JSI_Lobby::HasXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) @@ -87,8 +85,6 @@ g_rankedGame = isRanked; } -#if CONFIG2_LOBBY - void JSI_Lobby::StartXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& username, const std::wstring& password, const std::wstring& room, const std::wstring& nick, int historyRequestSize) { ENSURE(!g_XmppClient); @@ -386,4 +382,3 @@ return wstring_from_utf8(subject); } -#endif Index: source/main.cpp =================================================================== --- source/main.cpp +++ source/main.cpp @@ -33,6 +33,7 @@ #include +#include "lib/config2.h" #include "lib/debug.h" #include "lib/status.h" #include "lib/secure_crt.h" @@ -70,7 +71,9 @@ #include "network/NetClient.h" #include "network/NetServer.h" #include "network/NetSession.h" +#if CONFIG2_LOBBY #include "lobby/IXmppClient.h" +#endif #include "graphics/Camera.h" #include "graphics/GameView.h" #include "graphics/TextureManager.h" @@ -399,9 +402,11 @@ if (g_NetClient) g_NetClient->Flush(); +#if CONFIG2_LOBBY // Keep us connected to any XMPP servers if (g_XmppClient) g_XmppClient->recv(); +#endif g_UserReporter.Update(); Index: source/network/NetClient.cpp =================================================================== --- source/network/NetClient.cpp +++ source/network/NetClient.cpp @@ -24,9 +24,12 @@ #include "NetSession.h" #include "lib/byte_order.h" +#include "lib/config2.h" #include "lib/external_libraries/enet.h" #include "lib/sysdep/sysdep.h" +#if CONFIG2_LOBBY #include "lobby/IXmppClient.h" +#endif #include "ps/CConsole.h" #include "ps/CLogger.h" #include "ps/Compress.h" @@ -517,6 +520,7 @@ if (message->m_Flags & PS_NETWORK_FLAG_REQUIRE_LOBBYAUTH) { +#if CONFIG2_LOBBY if (g_XmppClient && !client->m_HostingPlayerName.empty()) g_XmppClient->SendIqLobbyAuth(client->m_HostingPlayerName, client->m_GUID); else @@ -525,9 +529,11 @@ "type", "netstatus", "status", "disconnected", "reason", static_cast(NDR_LOBBY_AUTH_FAILED)); - LOGMESSAGE("Net client: Couldn't send lobby auth xmpp message"); } +#else + LOGERROR("Net client: Cannot use lobby authentication without lobby being compiled!"); +#endif // CONFIG2_LOBBY return true; } Index: source/network/scripting/JSInterface_Network.cpp =================================================================== --- source/network/scripting/JSInterface_Network.cpp +++ source/network/scripting/JSInterface_Network.cpp @@ -19,10 +19,13 @@ #include "JSInterface_Network.h" +#include "lib/config2.h" #include "lib/external_libraries/enet.h" #include "lib/external_libraries/libsdl.h" #include "lib/types.h" +#if CONFIG2_LOBBY #include "lobby/IXmppClient.h" +#endif #include "network/NetClient.h" #include "network/NetMessage.h" #include "network/NetServer.h" @@ -57,8 +60,13 @@ ENSURE(!g_NetServer); ENSURE(!g_Game); +#if CONFIG2_LOBBY // Always use lobby authentication for lobby matches to prevent impersonation and smurfing, in particular through mods that implemented an UI for arbitrary or other players nicknames. g_NetServer = new CNetServer(static_cast(g_XmppClient)); +#else + g_NetServer = new CNetServer(false); +#endif + if (!g_NetServer->SetupConnection(serverPort)) { pCxPrivate->pScriptInterface->ReportError("Failed to start server"); @@ -86,6 +94,8 @@ ENSURE(!g_Game); ENetHost* enetClient = nullptr; + +#if CONFIG2_LOBBY if (g_XmppClient && useSTUN) { // Find an unused port @@ -115,14 +125,23 @@ SDL_Delay(1000); } +#else + if (useSTUN) + { + pCxPrivate->pScriptInterface->ReportError("STUN cannot be used without lobby implementation!"); + return; + } +#endif // CONFIG2_LOBBY g_Game = new CGame(true); g_NetClient = new CNetClient(g_Game, false); g_NetClient->SetUserName(playerName); g_NetClient->SetHostingPlayerName(hostJID.substr(0, hostJID.find("@"))); +#if CONFIG2_LOBBY if (g_XmppClient && useSTUN) StunClient::SendHolePunchingMessages(*enetClient, serverAddress, serverPort); +#endif if (!g_NetClient->SetupConnection(serverAddress, serverPort, enetClient)) { Index: source/ps/GameSetup/GameSetup.cpp =================================================================== --- source/ps/GameSetup/GameSetup.cpp +++ source/ps/GameSetup/GameSetup.cpp @@ -81,7 +81,9 @@ #include "scriptinterface/ScriptConversions.h" #include "scriptinterface/ScriptRuntime.h" #include "simulation2/Simulation2.h" +#if CONFIG2_LOBBY #include "lobby/IXmppClient.h" +#endif #include "soundmanager/scripting/JSInterface_Sound.h" #include "soundmanager/ISoundManager.h" #include "tools/atlas/GameInterface/GameLoop.h" @@ -720,7 +722,9 @@ EndGame(); +#if CONFIG2_LOBBY SAFE_DELETE(g_XmppClient); +#endif SAFE_DELETE(g_ModIo);