Index: binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/JoinButton.js =================================================================== --- binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/JoinButton.js +++ binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/JoinButton.js @@ -67,34 +67,19 @@ if (!game) return; - let ip; let port; let stanza = game.stanza; if (stanza.stunIP) { - ip = stanza.stunIP; port = stanza.stunPort; } else { - ip = stanza.ip; port = stanza.port; } - if (ip.split('.').length != 4) - { - messageBox( - 400, 250, - sprintf( - translate("This game's address '%(ip)s' does not appear to be valid."), - { "ip": escapeText(stanza.ip) }), - translate("Error")); - return; - } - - Engine.PushGuiPage("page_gamesetup_mp.xml", { + Engine.PushGuiPage("page_gamesetup_lobby_mp.xml", { "multiplayerGameType": "join", - "ip": ip, "port": port, "name": g_Nickname, "rating": this.getRejoinRating(stanza), Index: binaries/data/mods/public/gui/lobby/LobbyPage/Game.js =================================================================== --- binaries/data/mods/public/gui/lobby/LobbyPage/Game.js +++ binaries/data/mods/public/gui/lobby/LobbyPage/Game.js @@ -270,9 +270,7 @@ */ Game.prototype.StanzaKeys = [ "name", - "ip", "port", - "stunIP", "stunPort", "hostUsername", "state", Index: binaries/data/mods/public/gui/lobby/LobbyPage/GameList.js =================================================================== --- binaries/data/mods/public/gui/lobby/LobbyPage/GameList.js +++ binaries/data/mods/public/gui/lobby/LobbyPage/GameList.js @@ -97,13 +97,13 @@ let newGames = {}; for (let stanza of gameListData) { - let game = this.games[stanza.ip] || undefined; + let game = this.games[stanza.hostUsername] || undefined; let exists = !!game; if (!exists) game = new Game(this.mapCache); game.update(stanza, selectedColumn); - newGames[stanza.ip] = game; + newGames[stanza.hostUsername] = game; } this.games = newGames; Engine.ProfileStop(); @@ -157,8 +157,7 @@ this.list_maxnbp[i] = displayData.playerCount; this.list_gameRating[i] = game.gameRating; this.list[i] = ""; - - if (selectedGame && game.stanza.ip == selectedGame.stanza.ip && game.stanza.port == selectedGame.stanza.port) + if (selectedGame && game.hostUsername == selectedGame.hostUsername && game.stanza.port == selectedGame.stanza.port) selectedGameIndex = i; }); Engine.ProfileStop(); Index: source/lobby/IXmppClient.h =================================================================== --- source/lobby/IXmppClient.h +++ source/lobby/IXmppClient.h @@ -59,6 +59,8 @@ virtual JS::Value GuiPollNewMessages(const ScriptInterface& scriptInterface) = 0; virtual JS::Value GuiPollHistoricMessages(const ScriptInterface& scriptInterface) = 0; virtual bool GuiPollHasPlayerListUpdate() = 0; + + virtual std::string GetGameIp(const ScriptInterface& scriptInterface, const std::string& hostname, bool stun) = 0; virtual void SendMUCMessage(const std::string& message) = 0; virtual void SendStunEndpointToHost(const StunClient::StunEndpoint& stunEndpoint, const std::string& hostJID) = 0; Index: source/lobby/XmppClient.h =================================================================== --- source/lobby/XmppClient.h +++ source/lobby/XmppClient.h @@ -97,6 +97,8 @@ void GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret); void GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret); + std::string GetGameIp(const ScriptInterface& scriptInterface, const std::string& hostname, bool stun); + void SendStunEndpointToHost(const StunClient::StunEndpoint& stunEndpoint, const std::string& hostJID); /** Index: source/lobby/XmppClient.cpp =================================================================== --- source/lobby/XmppClient.cpp +++ source/lobby/XmppClient.cpp @@ -392,6 +392,21 @@ m_client->send(iq); }; +std::string XmppClient::GetGameIp(const ScriptInterface& scriptInterface, const std::string& hostName, bool stun) +{ + ScriptRequest rq(scriptInterface); + for (const glooxwrapper::Tag* const& t : m_GameList) + { + JS::RootedValue game(rq.cx); + ScriptInterface::CreateObject(rq, &game); + glooxwrapper::string userName = t->findAttribute("hostUsername"); + LOGWARNING(userName.to_string()); + if (userName.to_string().compare(hostName) == 0) + return t->findAttribute(stun ? "stunIP" : "ip").to_string(); + } + return ""; +} + /** * Send a request to register a game to the server. * @@ -571,7 +586,7 @@ ScriptInterface::CreateArray(rq, ret); int j = 0; - const char* stats[] = { "name", "ip", "port", "stunIP", "stunPort", "hostUsername", "state", + const char* stats[] = { "name", "port", "stunPort", "hostUsername", "state", "nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryConditions", "startTime", "mods" }; Index: source/network/scripting/JSInterface_Network.h =================================================================== --- source/network/scripting/JSInterface_Network.h +++ source/network/scripting/JSInterface_Network.h @@ -31,6 +31,7 @@ void SetNetworkGameAttributes(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue attribs1); void StartNetworkHost(ScriptInterface::CmptPrivate* pCmptPrivate, const CStrW& playerName, const u16 serverPort, const CStr& hostLobbyName); void StartNetworkJoin(ScriptInterface::CmptPrivate* pCmptPrivate, const CStrW& playerName, const CStr& serverAddress, u16 serverPort, bool useSTUN, const CStr& hostJID); + void StartNetworkJoinSafe(ScriptInterface::CmptPrivate* pCmptPrivate, const CStrW& playerName, u16 serverPort, bool useSTUN, const CStr& hostJID); JS::Value FindStunEndpoint(ScriptInterface::CmptPrivate* pCmptPrivate, int port); void DisconnectNetworkGame(ScriptInterface::CmptPrivate* pCmptPrivate); JS::Value PollNetworkClient(ScriptInterface::CmptPrivate* pCmptPrivate); Index: source/network/scripting/JSInterface_Network.cpp =================================================================== --- source/network/scripting/JSInterface_Network.cpp +++ source/network/scripting/JSInterface_Network.cpp @@ -137,6 +137,23 @@ } } +/*** +* Require XmppClient to communicate with game server. +*/ +void JSI_Network::StartNetworkJoinSafe(ScriptInterface::CmptPrivate* pCmptPrivate, const CStrW& playerName, u16 serverPort, bool useSTUN, const CStr& hostJID) +{ + ENSURE(!!g_XmppClient); + // Get ip of server + const CStr serverAddress = CStr(g_XmppClient->GetGame(*pCmptPrivate->pScriptInterface, hostJID.c_str(), useSTUN)); + if (serverAddress.size() == 0) + { + ScriptRequest rq(pCmptPrivate->pScriptInterface); + ScriptException::Raise(rq, "Could not retrieve server address."); + return; + } + StartNetworkJoin(pCmptPrivate, playerName, serverAddress, serverPort, useSTUN, hostJID); +} + void JSI_Network::DisconnectNetworkGame(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) { // TODO: we ought to do async reliable disconnections @@ -234,6 +251,7 @@ scriptInterface.RegisterFunction("FindStunEndpoint"); scriptInterface.RegisterFunction("StartNetworkHost"); scriptInterface.RegisterFunction("StartNetworkJoin"); + scriptInterface.RegisterFunction("StartNetworkJoinSafe"); scriptInterface.RegisterFunction("DisconnectNetworkGame"); scriptInterface.RegisterFunction("GetPlayerGUID"); scriptInterface.RegisterFunction("PollNetworkClient");