2025-12-31 03:28:08 -08:00
|
|
|
/* Copyright (C) 2026 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2013-11-07 12:07:24 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2013-11-07 12:07:24 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2013-11-07 12:07:24 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2013-11-07 12:07:24 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
2018-08-24 04:29:38 -07:00
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
#include "XmppClient.h"
|
|
|
|
|
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "StanzaExtensions.h"
|
2014-11-12 17:26:36 -08:00
|
|
|
#include "i18n/L10n.h"
|
2026-03-19 10:36:52 -07:00
|
|
|
#include "lib/code_annotation.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "lib/external_libraries/gloox.h"
|
2026-03-19 10:36:52 -07:00
|
|
|
#include "lib/types.h"
|
2013-11-09 15:26:17 -08:00
|
|
|
#include "lib/utf8.h"
|
2026-03-25 10:58:37 -07:00
|
|
|
#include "lobby/GlooxConversion.h"
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
#include "network/NetClient.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "network/NetServer.h"
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
#include "network/StunClient.h"
|
2013-11-07 12:07:24 -08:00
|
|
|
#include "ps/CLogger.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "ps/CStr.h"
|
2013-11-07 12:07:24 -08:00
|
|
|
#include "ps/ConfigDB.h"
|
2021-05-09 05:51:32 -07:00
|
|
|
#include "ps/GUID.h"
|
2015-08-01 16:03:13 -07:00
|
|
|
#include "ps/Pyrogenesis.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "scriptinterface/Object.h"
|
|
|
|
|
#include "scriptinterface/ScriptConversions.h"
|
2014-11-12 17:26:36 -08:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "scriptinterface/ScriptRequest.h"
|
2021-05-10 04:51:32 -07:00
|
|
|
#include "scriptinterface/StructuredClone.h"
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
#include <ctime>
|
|
|
|
|
#include <deque>
|
2020-12-09 06:39:14 -08:00
|
|
|
#include <iostream>
|
2026-03-19 10:36:52 -07:00
|
|
|
#include <js/GCVector.h>
|
2025-06-19 15:06:41 -07:00
|
|
|
#include <js/PropertyAndElement.h>
|
|
|
|
|
#include <js/PropertyDescriptor.h>
|
2026-03-19 10:36:52 -07:00
|
|
|
#include <js/TracingAPI.h>
|
|
|
|
|
#include <js/TypeDecls.h>
|
|
|
|
|
#include <js/Value.h>
|
|
|
|
|
#include <js/Vector.h>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <optional>
|
|
|
|
|
#include <string>
|
2025-06-19 15:06:41 -07:00
|
|
|
#include <tuple>
|
|
|
|
|
#include <unicode/locid.h>
|
|
|
|
|
#include <unicode/utypes.h>
|
|
|
|
|
#include <utility>
|
2026-03-19 10:36:52 -07:00
|
|
|
#include <vector>
|
2020-12-09 06:39:14 -08:00
|
|
|
|
2026-03-26 10:08:04 -07:00
|
|
|
namespace
|
|
|
|
|
{
|
2013-11-07 12:07:24 -08:00
|
|
|
//debug
|
|
|
|
|
#if 1
|
|
|
|
|
#define DbgXMPP(x)
|
|
|
|
|
#else
|
2026-01-03 11:29:10 -08:00
|
|
|
#define DbgXMPP(x) std::cout << "XMPP DEBUG: " << x << std::endl;
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-26 10:08:04 -07:00
|
|
|
std::string tag_xml(const gloox::IQ& iq)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
return iq.tag()->xml();
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-03-26 10:08:04 -07:00
|
|
|
std::string tag_name(const gloox::IQ& iq)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
return iq.tag()->name();
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 10:08:04 -07:00
|
|
|
/**
|
|
|
|
|
* Parse and return the timestamp of a historic chat message and return the current time for new chat messages.
|
|
|
|
|
* Historic chat messages are implement as DelayedDelivers as specified in XEP-0203.
|
|
|
|
|
* Hence, their timestamp MUST be in UTC and conform to the DateTime format XEP-0082.
|
|
|
|
|
*
|
|
|
|
|
* @returns Seconds since the epoch.
|
|
|
|
|
*/
|
|
|
|
|
std::time_t ComputeTimestamp(const gloox::Message& msg)
|
|
|
|
|
{
|
|
|
|
|
// Only historic messages contain a timestamp!
|
|
|
|
|
if (!msg.when())
|
|
|
|
|
return std::time(nullptr);
|
|
|
|
|
|
|
|
|
|
// The locale is irrelevant, because the XMPP date format doesn't contain written month names
|
|
|
|
|
for (const std::string& format : std::vector<std::string>{ "Y-M-d'T'H:m:sZ", "Y-M-d'T'H:m:s.SZ" })
|
|
|
|
|
{
|
|
|
|
|
UDate dateTime = g_L10n.ParseDateTime(msg.when()->stamp(), format, icu::Locale::getUS());
|
|
|
|
|
if (dateTime)
|
|
|
|
|
return dateTime / 1000.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::time(nullptr);
|
|
|
|
|
}
|
2026-03-27 11:23:58 -07:00
|
|
|
|
|
|
|
|
gloox::Client CreateClient(const bool regOpt, const std::string& username, const std::string& servername,
|
|
|
|
|
const std::string& password)
|
|
|
|
|
{
|
|
|
|
|
// If we are connecting, use the full jid and a password
|
|
|
|
|
// If we are registering, only use the server name
|
|
|
|
|
if (regOpt)
|
|
|
|
|
return gloox::Client{servername};
|
|
|
|
|
|
|
|
|
|
// Generate a unique, unpredictable resource to allow multiple 0 A.D. instances to connect to the lobby.
|
|
|
|
|
gloox::JID clientJid(username + "@" + servername + "/0ad-" + ps_generate_guid());
|
|
|
|
|
return gloox::Client{clientJid, password};
|
|
|
|
|
}
|
2026-03-27 11:44:54 -07:00
|
|
|
|
|
|
|
|
std::optional<gloox::MUCRoom> CreateMucRoom(gloox::MUCRoomHandler* handler, const bool regOpt, gloox::Client& client,
|
|
|
|
|
const std::string& room, const std::string& servername, const std::string& nick)
|
|
|
|
|
{
|
|
|
|
|
if (regOpt)
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
|
|
// Generate a unique, unpredictable resource to allow multiple 0 A.D. instances to connect to the lobby.
|
|
|
|
|
gloox::JID roomJid(room + "@conference." + servername + "/" + nick);
|
|
|
|
|
return std::make_optional<gloox::MUCRoom>(&client, roomJid, handler);
|
|
|
|
|
}
|
2026-03-26 10:08:04 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
class XmppClient::Impl : public gloox::ConnectionListener, public gloox::MUCRoomHandler,
|
|
|
|
|
public gloox::IqHandler, public gloox::RegistrationHandler, public gloox::MessageHandler,
|
|
|
|
|
public gloox::Jingle::SessionHandler, public gloox::LogHandler
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
public:
|
|
|
|
|
// Basic
|
|
|
|
|
Impl(const ScriptInterface* scriptInterface, const std::string& sUsername,
|
|
|
|
|
const std::string& sPassword, const std::string& sRoom, const std::string& sNick,
|
|
|
|
|
const int historyRequestSize, const bool regOpt);
|
|
|
|
|
|
|
|
|
|
std::string m_server;
|
|
|
|
|
|
|
|
|
|
// Components
|
|
|
|
|
gloox::Client m_client;
|
|
|
|
|
std::optional<gloox::MUCRoom> m_mucRoom;
|
|
|
|
|
gloox::Registration m_registration;
|
|
|
|
|
gloox::Jingle::SessionManager m_sessionManager;
|
|
|
|
|
|
|
|
|
|
// Account infos
|
|
|
|
|
std::string m_username;
|
|
|
|
|
std::string m_password;
|
|
|
|
|
std::string m_room;
|
|
|
|
|
std::string m_nick;
|
|
|
|
|
std::string m_xpartamuppId;
|
|
|
|
|
std::string m_echelonId;
|
|
|
|
|
|
|
|
|
|
// Security
|
|
|
|
|
std::string m_connectionDataJid;
|
|
|
|
|
std::string m_connectionDataIqId;
|
|
|
|
|
|
|
|
|
|
// State
|
|
|
|
|
gloox::CertStatus m_certStatus;
|
|
|
|
|
bool m_initialLoadComplete;
|
|
|
|
|
bool m_regOpt;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/* Xmpp handlers */
|
|
|
|
|
/* MUC handlers */
|
|
|
|
|
void handleMUCParticipantPresence(gloox::MUCRoom* room, gloox::MUCRoomParticipant,
|
|
|
|
|
const gloox::Presence&) override;
|
|
|
|
|
void handleMUCError(gloox::MUCRoom* room, gloox::StanzaError) override;
|
|
|
|
|
void handleMUCMessage(gloox::MUCRoom* room, const gloox::Message& msg, bool priv) override;
|
|
|
|
|
void handleMUCSubject(gloox::MUCRoom* room, const std::string& nick,
|
|
|
|
|
const std::string& subject) override;
|
|
|
|
|
// Currently unused, provide noop implemtation for pure virtual functions.
|
|
|
|
|
bool handleMUCRoomCreation(gloox::MUCRoom*) override { return false; }
|
|
|
|
|
void handleMUCInviteDecline(gloox::MUCRoom*, const gloox::JID&, const std::string&) override {}
|
|
|
|
|
void handleMUCInfo(gloox::MUCRoom*, int, const std::string&, const gloox::DataForm*) override {}
|
|
|
|
|
void handleMUCItems(gloox::MUCRoom*, const std::list<gloox::Disco::Item*,
|
|
|
|
|
std::allocator<gloox::Disco::Item*>>&) override {}
|
|
|
|
|
|
|
|
|
|
/* Log handler */
|
|
|
|
|
void handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message) override;
|
|
|
|
|
|
|
|
|
|
/* ConnectionListener handlers*/
|
|
|
|
|
void onConnect() override;
|
|
|
|
|
void onDisconnect(gloox::ConnectionError e) override;
|
|
|
|
|
bool onTLSConnect(const gloox::CertInfo& info) override;
|
|
|
|
|
|
|
|
|
|
/* Iq Handlers */
|
|
|
|
|
bool handleIq(const gloox::IQ& iq) override;
|
|
|
|
|
void handleIqID(const gloox::IQ&, int) override {}
|
|
|
|
|
|
|
|
|
|
/* Registration Handlers */
|
|
|
|
|
void handleRegistrationFields(const gloox::JID& /*from*/, int fields,
|
|
|
|
|
std::string instructions) override;
|
|
|
|
|
#if GLOOXVERSION >= 0x010100
|
|
|
|
|
void handleRegistrationResult(const gloox::JID& /*from*/, gloox::RegistrationResult result,
|
|
|
|
|
const gloox::Error* /*error*/) override;
|
|
|
|
|
#else
|
|
|
|
|
void handleRegistrationResult(const gloox::JID& /*from*/, gloox::RegistrationResult result) override;
|
|
|
|
|
#endif
|
|
|
|
|
void handleAlreadyRegistered(const gloox::JID& /*from*/) override;
|
|
|
|
|
void handleDataForm(const gloox::JID& /*from*/, const gloox::DataForm& /*form*/) override;
|
|
|
|
|
void handleOOB(const gloox::JID& /*from*/, const gloox::OOB& oob) override;
|
|
|
|
|
|
|
|
|
|
/* Message Handler */
|
|
|
|
|
void handleMessage(const gloox::Message& msg, gloox::MessageSession* session) override;
|
|
|
|
|
|
|
|
|
|
/* Session Handler */
|
|
|
|
|
void handleSessionAction(gloox::Jingle::Action action, gloox::Jingle::Session* session,
|
|
|
|
|
const gloox::Jingle::Session::Jingle* jingle) override;
|
|
|
|
|
void handleSessionActionError(gloox::Jingle::Action /*action*/, gloox::Jingle::Session* /*session*/,
|
|
|
|
|
const gloox::Error* /*error*/) override {}
|
|
|
|
|
void handleIncomingSession(gloox::Jingle::Session* /*session*/) override {}
|
|
|
|
|
|
|
|
|
|
void handleSessionInitiation(gloox::Jingle::Session* session,
|
|
|
|
|
const gloox::Jingle::Session::Jingle* jingle);
|
|
|
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
|
void CreateGUIMessage(
|
|
|
|
|
const std::string& type,
|
|
|
|
|
const std::string& level,
|
|
|
|
|
const std::time_t time,
|
|
|
|
|
Args const&... args);
|
|
|
|
|
|
|
|
|
|
struct SPlayer {
|
|
|
|
|
SPlayer(const gloox::Presence::PresenceType presence, const gloox::MUCRoomRole role,
|
|
|
|
|
const std::string& rating)
|
|
|
|
|
: m_Presence(presence), m_Role(role), m_Rating(rating)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
gloox::Presence::PresenceType m_Presence;
|
|
|
|
|
gloox::MUCRoomRole m_Role;
|
|
|
|
|
std::string m_Rating;
|
|
|
|
|
};
|
|
|
|
|
using PlayerMap = std::map<std::string, SPlayer>;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/// Map of players
|
|
|
|
|
PlayerMap m_PlayerMap;
|
|
|
|
|
/// Whether or not the playermap has changed since the last time the GUI checked.
|
|
|
|
|
bool m_PlayerMapUpdate;
|
|
|
|
|
/// List of games
|
|
|
|
|
std::vector<std::unique_ptr<const gloox::Tag>> m_GameList;
|
|
|
|
|
/// List of rankings
|
|
|
|
|
std::vector<std::unique_ptr<const gloox::Tag>> m_BoardList;
|
|
|
|
|
/// Profile data
|
|
|
|
|
std::vector<std::unique_ptr<const gloox::Tag>> m_Profile;
|
|
|
|
|
/// ScriptInterface to root the values
|
|
|
|
|
const ScriptInterface* m_ScriptInterface;
|
|
|
|
|
/// Queue of messages for the GUI
|
|
|
|
|
JS::PersistentRootedVector<JS::Value> m_GuiMessageQueue;
|
|
|
|
|
/// Cache of all GUI messages received since the login
|
|
|
|
|
JS::PersistentRootedVector<JS::Value> m_HistoricGuiMessages;
|
|
|
|
|
/// Current room subject/topic.
|
|
|
|
|
std::wstring m_Subject;
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
/**
|
2014-01-25 21:39:55 -08:00
|
|
|
* Construct the XMPP client.
|
|
|
|
|
*
|
2019-09-05 22:14:20 -07:00
|
|
|
* @param scriptInterface - ScriptInterface to be used for storing GUI messages.
|
|
|
|
|
* Can be left blank for non-visual applications.
|
2014-01-25 21:39:55 -08:00
|
|
|
* @param sUsername Username to login with of register.
|
|
|
|
|
* @param sPassword Password to login with or register.
|
|
|
|
|
* @param sRoom MUC room to join.
|
|
|
|
|
* @param sNick Nick to join with.
|
|
|
|
|
* @param historyRequestSize Number of stanzas of room history to request.
|
|
|
|
|
* @param regOpt If we are just registering or not.
|
2013-11-07 12:07:24 -08:00
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
XmppClient::XmppClient(const ScriptInterface* scriptInterface, const std::string& username,
|
|
|
|
|
const std::string& password, const std::string& room, const std::string& nick,
|
|
|
|
|
const int historyRequestSize, bool regOpt) :
|
|
|
|
|
m_Impl{std::make_unique<Impl>(scriptInterface, username, password, room, nick, historyRequestSize,
|
|
|
|
|
regOpt)}
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
XmppClient::Impl::Impl(const ScriptInterface* scriptInterface, const std::string& sUsername,
|
|
|
|
|
const std::string& sPassword, const std::string& sRoom, const std::string& sNick,
|
|
|
|
|
const int historyRequestSize, bool regOpt)
|
2026-03-27 11:23:58 -07:00
|
|
|
: m_server{g_ConfigDB.Get("lobby.server", std::string{})},
|
|
|
|
|
// If we are connecting, use the full jid and a password
|
|
|
|
|
// If we are registering, only use the server name
|
|
|
|
|
m_client{CreateClient(regOpt, sUsername, m_server, sPassword)},
|
2026-03-27 11:44:54 -07:00
|
|
|
m_mucRoom{CreateMucRoom(this, regOpt, m_client, sRoom, m_server, sNick)},
|
2026-03-27 11:51:03 -07:00
|
|
|
m_registration{&m_client},
|
2026-03-27 11:31:53 -07:00
|
|
|
m_sessionManager{&m_client, this},
|
2024-10-21 10:17:25 -07:00
|
|
|
m_regOpt(regOpt),
|
2019-09-09 13:50:17 -07:00
|
|
|
m_username(sUsername),
|
|
|
|
|
m_password(sPassword),
|
|
|
|
|
m_room(sRoom),
|
|
|
|
|
m_nick(sNick),
|
2025-01-29 07:38:52 -08:00
|
|
|
m_xpartamuppId{g_ConfigDB.Get("lobby.xpartamupp", std::string{}) + "@" + m_server + "/CC"},
|
|
|
|
|
m_echelonId{g_ConfigDB.Get("lobby.echelon", std::string{}) + "@" + m_server + "/CC"},
|
2019-09-09 13:50:17 -07:00
|
|
|
m_initialLoadComplete(false),
|
|
|
|
|
m_certStatus(gloox::CertStatus::CertOk),
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
m_PlayerMapUpdate(false),
|
|
|
|
|
m_connectionDataJid(),
|
2026-03-26 10:49:22 -07:00
|
|
|
m_connectionDataIqId(),
|
2026-03-27 11:23:58 -07:00
|
|
|
m_ScriptInterface(scriptInterface),
|
2026-03-26 10:49:22 -07:00
|
|
|
m_GuiMessageQueue{m_ScriptInterface->GetGeneralJSContext()},
|
|
|
|
|
m_HistoricGuiMessages{m_ScriptInterface->GetGeneralJSContext()}
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2018-08-24 04:29:38 -07:00
|
|
|
// Optionally join without a TLS certificate, so a local server can be tested quickly.
|
|
|
|
|
// Security risks from malicious JS mods can be mitigated if this option and also the hostname and login are shielded from JS access.
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.setTls(g_ConfigDB.Get("lobby.tls", true) ? gloox::TLSRequired : gloox::TLSDisabled);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Disable use of the SASL PLAIN mechanism, to prevent leaking credentials
|
|
|
|
|
// if the server doesn't list any supported SASL mechanism or the response
|
|
|
|
|
// has been modified to exclude those.
|
|
|
|
|
const int mechs = gloox::SaslMechAll ^ gloox::SaslMechPlain;
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.setSASLMechanisms(mechs);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.registerConnectionListener(this);
|
|
|
|
|
m_client.setPresence(gloox::Presence::Available, -1);
|
|
|
|
|
m_client.disco()->setVersion("Pyrogenesis", PS_SERIALIZATION_VERSION);
|
|
|
|
|
m_client.disco()->setIdentity("client", "bot");
|
|
|
|
|
m_client.setCompression(false);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.registerStanzaExtension(new GameListQuery());
|
|
|
|
|
m_client.registerIqHandler(this, EXTGAMELISTQUERY);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.registerStanzaExtension(new BoardListQuery());
|
|
|
|
|
m_client.registerIqHandler(this, EXTBOARDLISTQUERY);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.registerStanzaExtension(new ProfileQuery());
|
|
|
|
|
m_client.registerIqHandler(this, EXTPROFILEQUERY);
|
2014-09-20 08:35:26 -07:00
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.registerStanzaExtension(new LobbyAuth());
|
|
|
|
|
m_client.registerIqHandler(this, EXTLOBBYAUTH);
|
2018-03-11 17:23:40 -07:00
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.registerStanzaExtension(new ConnectionData());
|
|
|
|
|
m_client.registerIqHandler(this, EXTCONNECTIONDATA);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.registerMessageHandler(this);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-27 11:51:03 -07:00
|
|
|
m_registration.registerRegistrationHandler(this);
|
2024-10-21 10:17:25 -07:00
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
// Uncomment to see the raw stanzas
|
2026-03-27 11:23:58 -07:00
|
|
|
// m_client.logInstance().registerLogHandler(gloox::LogLevelDebug, gloox::LogAreaAll, this);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
if (!regOpt)
|
2014-01-25 21:39:55 -08:00
|
|
|
m_mucRoom->setRequestHistory(historyRequestSize, gloox::MUCRoom::HistoryMaxStanzas);
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
|
|
|
|
|
// Register plugins to allow gloox parse them in incoming sessions
|
2026-03-27 11:31:53 -07:00
|
|
|
m_sessionManager.registerPlugin(new gloox::Jingle::Content());
|
|
|
|
|
m_sessionManager.registerPlugin(new gloox::Jingle::ICEUDP());
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destroy the xmpp client
|
|
|
|
|
*/
|
|
|
|
|
XmppClient::~XmppClient()
|
|
|
|
|
{
|
2025-04-04 23:01:18 -07:00
|
|
|
this->disconnect();
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
DbgXMPP("XmppClient destroyed");
|
|
|
|
|
|
|
|
|
|
// Workaround for memory leak in gloox 1.0/1.0.1
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.removePresenceExtension(gloox::ExtCaps);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Network
|
|
|
|
|
void XmppClient::connect()
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_initialLoadComplete = false;
|
|
|
|
|
m_Impl->m_client.connect(false);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XmppClient::disconnect()
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.disconnect();
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2018-01-14 20:30:33 -08:00
|
|
|
bool XmppClient::isConnected()
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
return m_Impl->m_client.state() == gloox::StateConnected;
|
2018-01-14 20:30:33 -08:00
|
|
|
}
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
void XmppClient::recv()
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.recv(1);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Log (debug) Handler
|
|
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
std::cout << "log: level: " << level << ", area: " << area << ", message: " << message << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
|
* Connection handlers *
|
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle connection
|
|
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::onConnect()
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
if (m_mucRoom)
|
|
|
|
|
{
|
2019-09-05 22:14:20 -07:00
|
|
|
CreateGUIMessage("system", "connected", std::time(nullptr));
|
2013-11-07 12:07:24 -08:00
|
|
|
m_mucRoom->join();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 10:17:25 -07:00
|
|
|
if (m_regOpt)
|
2026-03-27 11:51:03 -07:00
|
|
|
m_registration.fetchRegistrationFields();
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle disconnection
|
|
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::onDisconnect(gloox::ConnectionError error)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
// Make sure we properly leave the room so that
|
|
|
|
|
// everything works if we decide to come back later
|
|
|
|
|
if (m_mucRoom)
|
|
|
|
|
m_mucRoom->leave();
|
|
|
|
|
|
|
|
|
|
// Clear game, board and player lists.
|
|
|
|
|
m_GameList.clear();
|
2026-03-27 11:02:53 -07:00
|
|
|
m_BoardList.clear();
|
|
|
|
|
m_Profile.clear();
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
m_PlayerMap.clear();
|
2019-09-11 04:51:34 -07:00
|
|
|
m_PlayerMapUpdate = true;
|
2017-08-29 09:04:45 -07:00
|
|
|
m_HistoricGuiMessages.clear();
|
2020-01-02 14:14:14 -08:00
|
|
|
m_initialLoadComplete = false;
|
2019-09-11 04:51:34 -07:00
|
|
|
|
2019-09-09 14:26:58 -07:00
|
|
|
CreateGUIMessage(
|
|
|
|
|
"system",
|
|
|
|
|
"disconnected",
|
|
|
|
|
std::time(nullptr),
|
2019-09-12 10:23:33 -07:00
|
|
|
"reason", error,
|
|
|
|
|
"certificate_status", m_certStatus);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-08-24 04:29:38 -07:00
|
|
|
* Handle TLS connection.
|
2013-11-07 12:07:24 -08:00
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
bool XmppClient::Impl::onTLSConnect(const gloox::CertInfo& info)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-01-03 11:29:10 -08:00
|
|
|
DbgXMPP("onTLSConnect:" <<
|
|
|
|
|
" status: " << info.status <<
|
|
|
|
|
", issuer: " << info.issuer <<
|
|
|
|
|
", peer: " << info.server <<
|
|
|
|
|
", protocol: " << info.protocol <<
|
|
|
|
|
", mac: " << info.mac <<
|
|
|
|
|
", cipher: " << info.cipher <<
|
|
|
|
|
", compression: " << info.compression);
|
2018-08-24 04:29:38 -07:00
|
|
|
|
2018-10-09 10:50:08 -07:00
|
|
|
m_certStatus = static_cast<gloox::CertStatus>(info.status);
|
|
|
|
|
|
2018-08-24 04:29:38 -07:00
|
|
|
// Optionally accept invalid certificates, see require_tls option.
|
2025-01-29 07:38:52 -08:00
|
|
|
return info.status == gloox::CertOk || !g_ConfigDB.Get("lobby.verify_certificate", true);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle MUC room errors
|
|
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleMUCError(gloox::MUCRoom*, gloox::StanzaError err)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2019-09-13 08:24:44 -07:00
|
|
|
DbgXMPP("MUC Error " << ": " << StanzaErrorToString(err));
|
2019-09-12 10:23:33 -07:00
|
|
|
CreateGUIMessage("system", "error", std::time(nullptr), "text", err);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
|
* Requests to server *
|
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Request the leaderboard data from the server.
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::SendIqGetBoardList()
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::JID echelonJid(m_Impl->m_echelonId);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Send IQ
|
2014-01-23 15:13:13 -08:00
|
|
|
BoardListQuery* b = new BoardListQuery();
|
|
|
|
|
b->m_Command = "getleaderboard";
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::IQ iq(gloox::IQ::Get, echelonJid, m_Impl->m_client.getID());
|
2014-01-23 15:13:13 -08:00
|
|
|
iq.addExtension(b);
|
2013-11-07 12:07:24 -08:00
|
|
|
DbgXMPP("SendIqGetBoardList [" << tag_xml(iq) << "]");
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.send(iq);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2014-09-20 08:35:26 -07:00
|
|
|
/**
|
|
|
|
|
* Request the profile data from the server.
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::SendIqGetProfile(const std::string& player)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::JID echelonJid(m_Impl->m_echelonId);
|
2014-09-20 08:35:26 -07:00
|
|
|
|
|
|
|
|
// Send IQ
|
|
|
|
|
ProfileQuery* b = new ProfileQuery();
|
|
|
|
|
b->m_Command = player;
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::IQ iq(gloox::IQ::Get, echelonJid, m_Impl->m_client.getID());
|
2014-09-20 08:35:26 -07:00
|
|
|
iq.addExtension(b);
|
|
|
|
|
DbgXMPP("SendIqGetProfile [" << tag_xml(iq) << "]");
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.send(iq);
|
2014-09-20 08:35:26 -07:00
|
|
|
}
|
|
|
|
|
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
/**
|
|
|
|
|
* Request the Connection data (ip, port...) from the server.
|
|
|
|
|
*/
|
2021-05-18 07:47:36 -07:00
|
|
|
void XmppClient::SendIqGetConnectionData(const std::string& jid, const std::string& password, const std::string& clientSalt, bool localIP)
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::JID targetJID(jid);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
|
|
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
|
|
|
|
connectionData->m_Password = password;
|
2021-05-18 07:47:36 -07:00
|
|
|
connectionData->m_ClientSalt = clientSalt;
|
2021-05-16 08:34:38 -07:00
|
|
|
connectionData->m_IsLocalIP = localIP ? "1" : "0";
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::IQ iq(gloox::IQ::Get, targetJID, m_Impl->m_client.getID());
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
iq.addExtension(connectionData);
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_connectionDataJid = iq.from().full();
|
|
|
|
|
m_Impl->m_connectionDataIqId = iq.id();
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
DbgXMPP("SendIqGetConnectionData [" << tag_xml(iq) << "]");
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.send(iq);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
}
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
/**
|
|
|
|
|
* Send game report containing numerous game properties to the server.
|
|
|
|
|
*
|
|
|
|
|
* @param data A JS array of game statistics
|
|
|
|
|
*/
|
2021-05-13 10:23:52 -07:00
|
|
|
void XmppClient::SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::JID echelonJid(m_Impl->m_echelonId);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Setup some base stanza attributes
|
|
|
|
|
GameReport* game = new GameReport();
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::Tag* report = new gloox::Tag("game");
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Iterate through all the properties reported and add them to the stanza.
|
|
|
|
|
std::vector<std::string> properties;
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::EnumeratePropertyNames(rq, data, true, properties);
|
2026-01-25 12:01:11 -08:00
|
|
|
|
|
|
|
|
// https://gitea.wildfiregames.com/0ad/0ad/issues/8687
|
|
|
|
|
const std::map<std::string, std::string> mappings{
|
|
|
|
|
{ "civilianUnitsLost", "femaleCitizenUnitsLost" },
|
|
|
|
|
{ "civilianUnitsTrained", "femaleCitizenUnitsTrained" },
|
|
|
|
|
{ "enemyCivilianUnitsKilled", "enemyFemaleCitizenUnitsKilled"}
|
|
|
|
|
};
|
2015-06-19 10:25:28 -07:00
|
|
|
for (const std::string& p : properties)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2013-11-09 15:26:17 -08:00
|
|
|
std::wstring value;
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::GetProperty(rq, data, p.c_str(), value);
|
2026-01-25 12:01:11 -08:00
|
|
|
if (mappings.contains(p))
|
|
|
|
|
report->addAttribute(mappings.at(p), utf8_from_wstring(value));
|
|
|
|
|
else
|
|
|
|
|
report->addAttribute(p, utf8_from_wstring(value));
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add stanza to IQ
|
2015-06-19 10:25:28 -07:00
|
|
|
game->m_GameReport.emplace_back(report);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Send IQ
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::IQ iq(gloox::IQ::Set, echelonJid, m_Impl->m_client.getID());
|
2013-11-07 12:07:24 -08:00
|
|
|
iq.addExtension(game);
|
|
|
|
|
DbgXMPP("SendGameReport [" << tag_xml(iq) << "]");
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.send(iq);
|
2013-11-07 12:07:24 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a request to register a game to the server.
|
|
|
|
|
*
|
|
|
|
|
* @param data A JS array of game attributes
|
|
|
|
|
*/
|
2021-05-13 10:23:52 -07:00
|
|
|
void XmppClient::SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue data)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::JID xpartamuppJid(m_Impl->m_xpartamuppId);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Setup some base stanza attributes
|
2021-05-09 05:51:32 -07:00
|
|
|
std::unique_ptr<GameListQuery> g = std::make_unique<GameListQuery>();
|
2013-11-07 12:07:24 -08:00
|
|
|
g->m_Command = "register";
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::Tag* game = new gloox::Tag("game");
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Iterate through all the properties reported and add them to the stanza.
|
|
|
|
|
std::vector<std::string> properties;
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::EnumeratePropertyNames(rq, data, true, properties);
|
2015-06-19 10:25:28 -07:00
|
|
|
for (const std::string& p : properties)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2021-05-09 05:51:32 -07:00
|
|
|
std::string value;
|
2021-05-13 10:23:52 -07:00
|
|
|
if (!Script::GetProperty(rq, data, p.c_str(), value))
|
2021-05-09 05:51:32 -07:00
|
|
|
{
|
|
|
|
|
LOGERROR("Could not parse attribute '%s' as string.", p);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
game->addAttribute(p, value);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2021-05-09 05:51:32 -07:00
|
|
|
// Overwrite some attributes to make it slightly less trivial to do bad things,
|
|
|
|
|
// and explicit some invariants.
|
|
|
|
|
|
|
|
|
|
// The JID must point to ourself.
|
|
|
|
|
game->addAttribute("hostJID", GetJID());
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
// Push the stanza onto the IQ
|
2015-06-19 10:25:28 -07:00
|
|
|
g->m_GameList.emplace_back(game);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Send IQ
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::IQ iq(gloox::IQ::Set, xpartamuppJid, m_Impl->m_client.getID());
|
2021-05-09 05:51:32 -07:00
|
|
|
iq.addExtension(g.release());
|
2013-11-07 12:07:24 -08:00
|
|
|
DbgXMPP("SendIqRegisterGame [" << tag_xml(iq) << "]");
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.send(iq);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a request to unregister a game to the server.
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::SendIqUnregisterGame()
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::JID xpartamuppJid(m_Impl->m_xpartamuppId);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Send IQ
|
|
|
|
|
GameListQuery* g = new GameListQuery();
|
|
|
|
|
g->m_Command = "unregister";
|
2024-11-12 12:24:25 -08:00
|
|
|
g->m_GameList.emplace_back(new gloox::Tag("game"));
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::IQ iq(gloox::IQ::Set, xpartamuppJid, m_Impl->m_client.getID());
|
2015-06-19 10:25:28 -07:00
|
|
|
iq.addExtension(g);
|
2013-11-07 12:07:24 -08:00
|
|
|
DbgXMPP("SendIqUnregisterGame [" << tag_xml(iq) << "]");
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.send(iq);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a request to change the state of a registered game on the server.
|
|
|
|
|
*
|
|
|
|
|
* A game can either be in the 'running' or 'waiting' state - the server
|
|
|
|
|
* decides which - but we need to update the current players that are
|
|
|
|
|
* in-game so the server can make the calculation.
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::SendIqChangeStateGame(const std::string& nbp, const std::string& players)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::JID xpartamuppJid(m_Impl->m_xpartamuppId);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
|
|
|
|
// Send IQ
|
|
|
|
|
GameListQuery* g = new GameListQuery();
|
|
|
|
|
g->m_Command = "changestate";
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::Tag* game = new gloox::Tag("game");
|
2013-11-07 12:07:24 -08:00
|
|
|
game->addAttribute("nbp", nbp);
|
|
|
|
|
game->addAttribute("players", players);
|
2015-06-19 10:25:28 -07:00
|
|
|
g->m_GameList.emplace_back(game);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::IQ iq(gloox::IQ::Set, xpartamuppJid, m_Impl->m_client.getID());
|
2015-06-19 10:25:28 -07:00
|
|
|
iq.addExtension(g);
|
2013-11-07 12:07:24 -08:00
|
|
|
DbgXMPP("SendIqChangeStateGame [" << tag_xml(iq) << "]");
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.send(iq);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2018-03-11 17:23:40 -07:00
|
|
|
/*****************************************************
|
|
|
|
|
* iq to clients *
|
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send lobby authentication token.
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::SendIqLobbyAuth(const std::string& to, const std::string& token)
|
|
|
|
|
{
|
|
|
|
|
LobbyAuth* auth = new LobbyAuth();
|
|
|
|
|
auth->m_Token = token;
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::JID clientJid(to);
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::IQ iq(gloox::IQ::Set, clientJid, m_Impl->m_client.getID());
|
2018-03-11 17:23:40 -07:00
|
|
|
iq.addExtension(auth);
|
|
|
|
|
DbgXMPP("SendIqLobbyAuth [" << tag_xml(iq) << "]");
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_client.send(iq);
|
2018-03-11 17:23:40 -07:00
|
|
|
}
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
/*****************************************************
|
|
|
|
|
* Account registration *
|
|
|
|
|
*****************************************************/
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleRegistrationFields(const gloox::JID&, int fields, std::string)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::RegistrationFields vals;
|
2013-11-07 12:07:24 -08:00
|
|
|
vals.username = m_username;
|
|
|
|
|
vals.password = m_password;
|
2026-03-27 11:51:03 -07:00
|
|
|
m_registration.createAccount(fields, vals);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
#if GLOOXVERSION >= 0x010100
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleRegistrationResult(const gloox::JID&, gloox::RegistrationResult result,
|
|
|
|
|
const gloox::Error* /*error*/)
|
2024-11-12 12:24:25 -08:00
|
|
|
#else
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleRegistrationResult(const gloox::JID&, gloox::RegistrationResult result)
|
2024-11-12 12:24:25 -08:00
|
|
|
#endif
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
if (result == gloox::RegistrationSuccess)
|
2019-09-05 22:14:20 -07:00
|
|
|
CreateGUIMessage("system", "registered", std::time(nullptr));
|
2013-11-07 12:07:24 -08:00
|
|
|
else
|
2019-09-12 10:23:33 -07:00
|
|
|
CreateGUIMessage("system", "error", std::time(nullptr), "text", result);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleAlreadyRegistered(const gloox::JID&)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
DbgXMPP("the account already exists");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleDataForm(const gloox::JID&, const gloox::DataForm&)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
DbgXMPP("dataForm received");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleOOB(const gloox::JID&, const gloox::OOB&)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
DbgXMPP("OOB registration requested");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
|
* Requests from GUI *
|
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle requests from the GUI for the list of players.
|
|
|
|
|
*
|
|
|
|
|
* @return A JS array containing all known players and their presences
|
|
|
|
|
*/
|
2021-05-13 10:23:52 -07:00
|
|
|
JS::Value XmppClient::GUIGetPlayerList(const ScriptRequest& rq)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-02-02 09:24:57 -08:00
|
|
|
JS::RootedValueVector players{rq.cx};
|
2014-01-25 20:25:35 -08:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
for (const auto& p : m_Impl->m_PlayerMap)
|
2014-01-25 20:25:35 -08:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue player(rq.cx);
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-07-22 12:35:14 -07:00
|
|
|
&player,
|
2019-09-12 10:23:33 -07:00
|
|
|
"name", p.first,
|
|
|
|
|
"presence", p.second.m_Presence,
|
|
|
|
|
"rating", p.second.m_Rating,
|
|
|
|
|
"role", p.second.m_Role);
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2026-02-02 09:24:57 -08:00
|
|
|
if (!players.append(player))
|
|
|
|
|
throw std::runtime_error{"Append failed"};
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
2026-02-02 09:24:57 -08:00
|
|
|
return JS::ObjectValue(*JS::NewArrayObject(rq.cx, players));
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle requests from the GUI for the list of all active games.
|
|
|
|
|
*
|
|
|
|
|
* @return A JS array containing all known games
|
|
|
|
|
*/
|
2021-05-13 10:23:52 -07:00
|
|
|
JS::Value XmppClient::GUIGetGameList(const ScriptRequest& rq)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-02-02 09:24:57 -08:00
|
|
|
JS::RootedValueVector games{rq.cx};
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2021-05-09 05:51:32 -07:00
|
|
|
const char* stats[] = { "name", "hostUsername", "hostJID", "state", "hasPassword",
|
2018-02-21 09:27:33 -08:00
|
|
|
"nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType",
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
"victoryConditions", "startTime", "mods" };
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
for(const std::unique_ptr<const gloox::Tag>& t : m_Impl->m_GameList)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue game(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(rq, &game);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2014-09-20 08:35:26 -07:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(stats); ++i)
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::SetProperty(rq, game, stats[i], t->findAttribute(stats[i]));
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-02-02 09:24:57 -08:00
|
|
|
if (!games.append(game))
|
|
|
|
|
throw std::runtime_error{"Append failed"};
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
2026-02-02 09:24:57 -08:00
|
|
|
return JS::ObjectValue(*JS::NewArrayObject(rq.cx, games));
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle requests from the GUI for leaderboard data.
|
|
|
|
|
*
|
|
|
|
|
* @return A JS array containing all known leaderboard data
|
|
|
|
|
*/
|
2021-05-13 10:23:52 -07:00
|
|
|
JS::Value XmppClient::GUIGetBoardList(const ScriptRequest& rq)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-02-02 09:24:57 -08:00
|
|
|
JS::RootedValueVector boardList{rq.cx};
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2015-06-19 10:25:28 -07:00
|
|
|
const char* attributes[] = { "name", "rank", "rating" };
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
for(const std::unique_ptr<const gloox::Tag>& t : m_Impl->m_BoardList)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue board(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(rq, &board);
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2014-09-20 08:35:26 -07:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(attributes); ++i)
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::SetProperty(rq, board, attributes[i], t->findAttribute(attributes[i]));
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2026-02-02 09:24:57 -08:00
|
|
|
if (!boardList.append(board))
|
|
|
|
|
throw std::runtime_error{"Append failed"};
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
2026-02-02 09:24:57 -08:00
|
|
|
return JS::ObjectValue(*JS::NewArrayObject(rq.cx, boardList));
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2014-09-20 08:35:26 -07:00
|
|
|
/**
|
|
|
|
|
* Handle requests from the GUI for profile data.
|
|
|
|
|
*
|
|
|
|
|
* @return A JS array containing the specific user's profile data
|
|
|
|
|
*/
|
2021-05-13 10:23:52 -07:00
|
|
|
JS::Value XmppClient::GUIGetProfile(const ScriptRequest& rq)
|
2014-09-20 08:35:26 -07:00
|
|
|
{
|
2026-02-02 09:24:57 -08:00
|
|
|
JS::RootedValueVector profileData{rq.cx};
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2014-09-20 08:35:26 -07:00
|
|
|
const char* stats[] = { "player", "rating", "totalGamesPlayed", "highestRating", "wins", "losses", "rank" };
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
for (const std::unique_ptr<const gloox::Tag>& t : m_Impl->m_Profile)
|
2014-09-20 08:35:26 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue profile(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(rq, &profile);
|
2014-09-20 08:35:26 -07:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(stats); ++i)
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::SetProperty(rq, profile, stats[i], t->findAttribute(stats[i]));
|
2014-09-20 08:35:26 -07:00
|
|
|
|
2026-02-02 09:24:57 -08:00
|
|
|
if (!profileData.append(profile))
|
|
|
|
|
throw std::runtime_error{"Append failed"};
|
2014-09-20 08:35:26 -07:00
|
|
|
}
|
2026-02-02 09:24:57 -08:00
|
|
|
return JS::ObjectValue(*JS::NewArrayObject(rq.cx, profileData));
|
2014-09-20 08:35:26 -07:00
|
|
|
}
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
/*****************************************************
|
|
|
|
|
* Message interfaces *
|
|
|
|
|
*****************************************************/
|
|
|
|
|
|
2025-06-03 05:13:41 -07:00
|
|
|
void SetGUIMessageProperty(const ScriptRequest&, JS::HandleObject /*messageObj*/)
|
2017-08-28 10:47:43 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 22:14:20 -07:00
|
|
|
template<typename T, typename... Args>
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
void SetGUIMessageProperty(const ScriptRequest& rq, JS::HandleObject messageObj, const std::string& propertyName, const T& propertyValue, Args const&... args)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue scriptPropertyValue(rq.cx);
|
2021-05-13 02:43:33 -07:00
|
|
|
Script::ToJSVal(rq, &scriptPropertyValue, propertyValue);
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_DefineProperty(rq.cx, messageObj, propertyName.c_str(), scriptPropertyValue, JSPROP_ENUMERATE);
|
|
|
|
|
SetGUIMessageProperty(rq, messageObj, args...);
|
2019-09-05 22:14:20 -07:00
|
|
|
}
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2019-09-05 22:14:20 -07:00
|
|
|
template<typename... Args>
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::CreateGUIMessage(
|
2019-09-05 22:14:20 -07:00
|
|
|
const std::string& type,
|
|
|
|
|
const std::string& level,
|
|
|
|
|
const std::time_t time,
|
|
|
|
|
Args const&... args)
|
|
|
|
|
{
|
|
|
|
|
if (!m_ScriptInterface)
|
|
|
|
|
return;
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(m_ScriptInterface);
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue message(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-11 03:15:13 -07:00
|
|
|
&message,
|
|
|
|
|
"type", type,
|
|
|
|
|
"level", level,
|
|
|
|
|
"historic", false,
|
|
|
|
|
"time", static_cast<double>(time));
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedObject messageObj(rq.cx, message.toObjectOrNull());
|
|
|
|
|
SetGUIMessageProperty(rq, messageObj, args...);
|
2024-11-17 07:25:17 -08:00
|
|
|
Script::DeepFreezeObject(rq, message);
|
2026-03-26 10:49:22 -07:00
|
|
|
if (!m_GuiMessageQueue.append(message))
|
|
|
|
|
throw std::runtime_error{"Append failed"};
|
2017-08-29 09:04:45 -07:00
|
|
|
}
|
|
|
|
|
|
2019-09-11 04:51:34 -07:00
|
|
|
bool XmppClient::GuiPollHasPlayerListUpdate()
|
2019-09-05 19:53:22 -07:00
|
|
|
{
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
// The initial playerlist will be received in multiple messages
|
|
|
|
|
// Only inform the GUI after all of these playerlist fragments were received.
|
2026-03-19 10:36:52 -07:00
|
|
|
if (!m_Impl->m_initialLoadComplete)
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
return false;
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
return std::exchange(m_Impl->m_PlayerMapUpdate, false);
|
2019-09-05 19:53:22 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-10 04:51:32 -07:00
|
|
|
JS::Value XmppClient::GuiPollNewMessages(const ScriptInterface& guiInterface)
|
2017-08-29 09:04:45 -07:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
if ((isConnected() && !m_Impl->m_initialLoadComplete) || m_Impl->m_GuiMessageQueue.empty())
|
2017-08-29 09:04:45 -07:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
ScriptRequest rq(m_Impl->m_ScriptInterface);
|
2019-09-05 22:14:20 -07:00
|
|
|
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
// Optimize for batch message processing that is more
|
|
|
|
|
// performance demanding than processing a lone message.
|
2026-02-02 09:24:57 -08:00
|
|
|
JS::RootedValueVector messages{rq.cx};
|
2017-08-29 09:04:45 -07:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
for (const JS::Value& message : m_Impl->m_GuiMessageQueue)
|
2019-09-05 22:14:20 -07:00
|
|
|
{
|
2026-02-02 09:24:57 -08:00
|
|
|
if (!messages.append(message))
|
|
|
|
|
throw std::runtime_error{"Append failed"};
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
|
|
|
|
|
// Store historic chat messages.
|
|
|
|
|
// Only store relevant messages to minimize memory footprint.
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue rootedMessage(rq.cx, message);
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
std::string type;
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::GetProperty(rq, rootedMessage, "type", type);
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
if (type != "chat")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
std::string level;
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::GetProperty(rq, rootedMessage, "level", level);
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
if (level != "room-message" && level != "private-message")
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-05-10 04:51:32 -07:00
|
|
|
JS::RootedValue historicMessage(rq.cx, Script::DeepCopy(rq, rootedMessage));
|
|
|
|
|
if (true)
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
{
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::SetProperty(rq, historicMessage, "historic", true);
|
2024-11-17 07:25:17 -08:00
|
|
|
Script::DeepFreezeObject(rq, historicMessage);
|
2026-03-19 10:36:52 -07:00
|
|
|
if (!m_Impl->m_HistoricGuiMessages.append(historicMessage))
|
2026-03-26 10:49:22 -07:00
|
|
|
throw std::runtime_error{"Append failed"};
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
LOGERROR("Could not clone historic lobby GUI message!");
|
2019-09-05 22:14:20 -07:00
|
|
|
}
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_GuiMessageQueue.clear();
|
2020-10-31 03:13:33 -07:00
|
|
|
|
|
|
|
|
// Copy the messages over to the caller script interface.
|
2026-03-19 10:36:52 -07:00
|
|
|
return Script::CloneValueFromOtherCompartment(guiInterface, *m_Impl->m_ScriptInterface,
|
2026-02-02 09:24:57 -08:00
|
|
|
JS::RootedValue{rq.cx, JS::ObjectValue(*JS::NewArrayObject(rq.cx, messages))});
|
2017-08-29 09:04:45 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-10 04:51:32 -07:00
|
|
|
JS::Value XmppClient::GuiPollHistoricMessages(const ScriptInterface& guiInterface)
|
2017-08-29 09:04:45 -07:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
if (m_Impl->m_HistoricGuiMessages.empty())
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
ScriptRequest rq(m_Impl->m_ScriptInterface);
|
2017-08-29 09:04:45 -07:00
|
|
|
|
2026-02-02 09:24:57 -08:00
|
|
|
JS::RootedValueVector messages{rq.cx};
|
2019-07-22 12:35:14 -07:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
for (const JS::Value& message : m_Impl->m_HistoricGuiMessages)
|
2026-02-02 09:24:57 -08:00
|
|
|
{
|
|
|
|
|
if (!messages.append(message))
|
|
|
|
|
throw std::runtime_error{"Append failed"};
|
|
|
|
|
}
|
2019-09-05 22:14:20 -07:00
|
|
|
|
2020-10-31 03:13:33 -07:00
|
|
|
// Copy the messages over to the caller script interface.
|
2026-03-19 10:36:52 -07:00
|
|
|
return Script::CloneValueFromOtherCompartment(guiInterface, *m_Impl->m_ScriptInterface,
|
2026-02-02 09:24:57 -08:00
|
|
|
JS::RootedValue{rq.cx, JS::ObjectValue(*JS::NewArrayObject(rq.cx, messages))});
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a standard MUC textual message.
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::SendMUCMessage(const std::string& message)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_mucRoom->send(message);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-31 09:08:23 -08:00
|
|
|
* Handle a room message.
|
2013-11-07 12:07:24 -08:00
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleMUCMessage(gloox::MUCRoom*, const gloox::Message& msg, bool priv)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
DbgXMPP(msg.from().resource() << " said " << msg.body());
|
|
|
|
|
|
2017-08-28 10:47:43 -07:00
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
|
|
|
|
priv ? "private-message" : "room-message",
|
2019-09-05 22:14:20 -07:00
|
|
|
ComputeTimestamp(msg),
|
2019-09-12 10:23:33 -07:00
|
|
|
"from", msg.from().resource(),
|
|
|
|
|
"text", msg.body());
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-31 09:08:23 -08:00
|
|
|
* Handle a private message.
|
2013-11-07 12:07:24 -08:00
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleMessage(const gloox::Message& msg, gloox::MessageSession*)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
DbgXMPP("type " << msg.subtype() << ", subject " << msg.subject()
|
|
|
|
|
<< ", message " << msg.body() << ", thread id " << msg.thread());
|
|
|
|
|
|
2017-08-28 10:47:43 -07:00
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
2024-08-09 22:08:31 -07:00
|
|
|
msg.subtype() == gloox::Message::MessageType::Headline ? "headline" : "private-message",
|
2019-09-05 22:14:20 -07:00
|
|
|
ComputeTimestamp(msg),
|
2019-09-12 10:23:33 -07:00
|
|
|
"from", msg.from().resource(),
|
2024-08-09 22:08:31 -07:00
|
|
|
"subject", msg.subject(),
|
2019-09-12 10:23:33 -07:00
|
|
|
"text", msg.body());
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle portions of messages containing custom stanza extensions.
|
|
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
bool XmppClient::Impl::handleIq(const gloox::IQ& iq)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
DbgXMPP("handleIq [" << tag_xml(iq) << "]");
|
|
|
|
|
|
2015-06-19 10:25:28 -07:00
|
|
|
if (iq.subtype() == gloox::IQ::Result)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2015-06-19 10:25:28 -07:00
|
|
|
const GameListQuery* gq = iq.findExtension<GameListQuery>(EXTGAMELISTQUERY);
|
|
|
|
|
const BoardListQuery* bq = iq.findExtension<BoardListQuery>(EXTBOARDLISTQUERY);
|
|
|
|
|
const ProfileQuery* pq = iq.findExtension<ProfileQuery>(EXTPROFILEQUERY);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
const ConnectionData* cd = iq.findExtension<ConnectionData>(EXTCONNECTIONDATA);
|
|
|
|
|
if (cd)
|
|
|
|
|
{
|
|
|
|
|
if (g_NetServer || !g_NetClient)
|
|
|
|
|
return true;
|
|
|
|
|
|
2021-01-20 11:54:16 -08:00
|
|
|
if (!m_connectionDataJid.empty() && m_connectionDataJid.compare(iq.from().full()) != 0) {
|
|
|
|
|
LOGMESSAGE("XmppClient: Received connection data from invalid host: %s", iq.from().username());
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
return true;
|
2021-01-20 11:54:16 -08:00
|
|
|
}
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
if (!m_connectionDataIqId.empty() && m_connectionDataIqId.compare(iq.id()) != 0) {
|
2021-05-09 05:51:32 -07:00
|
|
|
LOGMESSAGE("XmppClient: Received connection data with invalid id");
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
return true;
|
2021-01-20 11:54:16 -08:00
|
|
|
}
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
|
|
|
|
|
if (!cd->m_Error.empty())
|
|
|
|
|
{
|
|
|
|
|
g_NetClient->HandleGetServerDataFailed(cd->m_Error.c_str());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 12:35:28 -08:00
|
|
|
g_NetClient->TryToConnectWithSTUN(cd->m_Ip, stoi(cd->m_Port), iq.from().full(), !cd->m_IsLocalIP.empty());
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
}
|
2015-06-19 10:25:28 -07:00
|
|
|
if (gq)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2024-08-12 21:59:38 -07:00
|
|
|
if (iq.from().full() != m_xpartamuppId)
|
|
|
|
|
{
|
|
|
|
|
LOGWARNING("XmppClient: Received game list response from unexpected sender: %s", iq.from().full());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
m_GameList.clear();
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
for (const gloox::Tag* const& t : gq->m_GameList)
|
2015-06-19 10:25:28 -07:00
|
|
|
m_GameList.emplace_back(t->clone());
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2019-09-05 22:14:20 -07:00
|
|
|
CreateGUIMessage("game", "gamelist", std::time(nullptr));
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
2015-06-19 10:25:28 -07:00
|
|
|
if (bq)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2024-08-12 21:59:38 -07:00
|
|
|
if (iq.from().full() != m_echelonId)
|
|
|
|
|
{
|
|
|
|
|
LOGWARNING("XmppClient: Received board list response from unexpected sender: %s", iq.from().full());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 15:13:13 -08:00
|
|
|
if (bq->m_Command == "boardlist")
|
|
|
|
|
{
|
|
|
|
|
m_BoardList.clear();
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
for (const gloox::Tag* const& t : bq->m_StanzaBoardList)
|
2015-06-19 10:25:28 -07:00
|
|
|
m_BoardList.emplace_back(t->clone());
|
2014-01-23 15:13:13 -08:00
|
|
|
|
2019-09-05 22:14:20 -07:00
|
|
|
CreateGUIMessage("game", "leaderboard", std::time(nullptr));
|
2014-01-23 15:13:13 -08:00
|
|
|
}
|
|
|
|
|
else if (bq->m_Command == "ratinglist")
|
|
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
for (const gloox::Tag* const& t : bq->m_StanzaBoardList)
|
2014-01-26 11:01:21 -08:00
|
|
|
{
|
2019-09-12 10:23:33 -07:00
|
|
|
const PlayerMap::iterator it = m_PlayerMap.find(t->findAttribute("name"));
|
|
|
|
|
if (it != m_PlayerMap.end())
|
2019-09-11 04:51:34 -07:00
|
|
|
{
|
2019-09-12 10:23:33 -07:00
|
|
|
it->second.m_Rating = t->findAttribute("rating");
|
2019-09-11 04:51:34 -07:00
|
|
|
m_PlayerMapUpdate = true;
|
|
|
|
|
}
|
2014-01-26 11:01:21 -08:00
|
|
|
}
|
2019-09-05 22:14:20 -07:00
|
|
|
CreateGUIMessage("game", "ratinglist", std::time(nullptr));
|
2014-01-23 15:13:13 -08:00
|
|
|
}
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
2014-09-20 08:35:26 -07:00
|
|
|
if (pq)
|
|
|
|
|
{
|
2024-08-12 21:59:38 -07:00
|
|
|
if (iq.from().full() != m_echelonId)
|
|
|
|
|
{
|
|
|
|
|
LOGWARNING("XmppClient: Received profile response from unexpected sender: %s", iq.from().full());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-20 08:35:26 -07:00
|
|
|
m_Profile.clear();
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
for (const gloox::Tag* const& t : pq->m_StanzaProfile)
|
2015-06-19 10:25:28 -07:00
|
|
|
m_Profile.emplace_back(t->clone());
|
2014-09-20 08:35:26 -07:00
|
|
|
|
2019-09-05 22:14:20 -07:00
|
|
|
CreateGUIMessage("game", "profile", std::time(nullptr));
|
2014-09-20 08:35:26 -07:00
|
|
|
}
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
2018-03-11 17:23:40 -07:00
|
|
|
else if (iq.subtype() == gloox::IQ::Set)
|
|
|
|
|
{
|
|
|
|
|
const LobbyAuth* lobbyAuth = iq.findExtension<LobbyAuth>(EXTLOBBYAUTH);
|
|
|
|
|
if (lobbyAuth)
|
|
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
LOGMESSAGE("XmppClient: Received lobby auth: %s from %s", lobbyAuth->m_Token, iq.from().username());
|
2018-03-11 17:23:40 -07:00
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.send(response);
|
2018-03-11 17:23:40 -07:00
|
|
|
|
|
|
|
|
if (g_NetServer)
|
2024-11-12 12:24:25 -08:00
|
|
|
g_NetServer->OnLobbyAuth(iq.from().username(), lobbyAuth->m_Token);
|
2018-11-07 14:56:05 -08:00
|
|
|
else
|
2021-05-09 05:51:32 -07:00
|
|
|
LOGMESSAGE("Received lobby authentication request, but not hosting currently!");
|
2018-03-11 17:23:40 -07:00
|
|
|
}
|
|
|
|
|
}
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
else if (iq.subtype() == gloox::IQ::Get)
|
|
|
|
|
{
|
|
|
|
|
const ConnectionData* cd = iq.findExtension<ConnectionData>(EXTCONNECTIONDATA);
|
|
|
|
|
if (cd)
|
|
|
|
|
{
|
2021-03-10 08:50:15 -08:00
|
|
|
LOGMESSAGE("XmppClient: Received request for connection data from %s", iq.from().username());
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
if (!g_NetServer)
|
|
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
|
|
|
|
connectionData->m_Error = "not_server";
|
|
|
|
|
|
|
|
|
|
response.addExtension(connectionData);
|
|
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.send(response);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
2021-01-26 12:20:48 -08:00
|
|
|
if (g_NetServer->IsBanned(iq.from().username()))
|
|
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
2021-01-26 12:20:48 -08:00
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
|
|
|
|
connectionData->m_Error = "banned";
|
|
|
|
|
|
|
|
|
|
response.addExtension(connectionData);
|
|
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.send(response);
|
2021-01-26 12:20:48 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
2024-11-12 12:24:25 -08:00
|
|
|
if (!g_NetServer->CheckPasswordAndIncrement(iq.from().username(), cd->m_Password, cd->m_ClientSalt))
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
|
|
|
|
connectionData->m_Error = "invalid_password";
|
|
|
|
|
|
|
|
|
|
response.addExtension(connectionData);
|
|
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.send(response);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
2021-05-16 08:34:38 -07:00
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
if (cd->m_IsLocalIP == "0")
|
2021-05-16 08:34:38 -07:00
|
|
|
{
|
|
|
|
|
connectionData->m_Ip = g_NetServer->GetPublicIp();
|
|
|
|
|
connectionData->m_Port = std::to_string(g_NetServer->GetPublicPort());
|
2021-05-22 01:34:00 -07:00
|
|
|
connectionData->m_IsLocalIP = "";
|
2021-05-16 08:34:38 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CStr ip;
|
|
|
|
|
if (StunClient::FindLocalIP(ip))
|
|
|
|
|
{
|
|
|
|
|
connectionData->m_Ip = ip;
|
|
|
|
|
connectionData->m_Port = std::to_string(g_NetServer->GetLocalPort());
|
2021-05-22 01:34:00 -07:00
|
|
|
connectionData->m_IsLocalIP = "true";
|
2021-05-16 08:34:38 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
connectionData->m_Error = "local_ip_failed";
|
|
|
|
|
}
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
|
|
|
|
|
response.addExtension(connectionData);
|
|
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
m_client.send(response);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2014-09-20 08:35:26 -07:00
|
|
|
else if (iq.subtype() == gloox::IQ::Error)
|
2024-11-12 12:24:25 -08:00
|
|
|
CreateGUIMessage("system", "error", std::time(nullptr), "text", iq.error()->error());
|
2013-11-07 12:07:24 -08:00
|
|
|
else
|
|
|
|
|
{
|
2019-09-12 10:23:33 -07:00
|
|
|
CreateGUIMessage("system", "error", std::time(nullptr), "text", wstring_from_utf8(g_L10n.Translate("unknown subtype (see logs)")));
|
2017-08-28 10:47:43 -07:00
|
|
|
LOGMESSAGE("unknown subtype '%s'", tag_name(iq).c_str());
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
2019-09-12 10:23:33 -07:00
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update local data when a user changes presence.
|
|
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleMUCParticipantPresence(gloox::MUCRoom*, const gloox::MUCRoomParticipant participant,
|
2025-06-03 23:10:15 -07:00
|
|
|
const gloox::Presence& presence)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
const std::string& nick = participant.nick->resource();
|
2017-05-04 18:13:12 -07:00
|
|
|
|
2019-09-12 10:23:33 -07:00
|
|
|
if (presence.presence() == gloox::Presence::Unavailable)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
|
|
|
|
if (!participant.newNick.empty() && (participant.flags & (gloox::UserNickChanged | gloox::UserSelf)))
|
|
|
|
|
{
|
|
|
|
|
// we have a nick change
|
2019-09-12 10:23:33 -07:00
|
|
|
if (m_PlayerMap.find(participant.newNick) == m_PlayerMap.end())
|
|
|
|
|
m_PlayerMap.emplace(
|
|
|
|
|
std::piecewise_construct,
|
|
|
|
|
std::forward_as_tuple(participant.newNick),
|
|
|
|
|
std::forward_as_tuple(presence.presence(), participant.role, std::move(m_PlayerMap.at(nick).m_Rating)));
|
|
|
|
|
else
|
|
|
|
|
LOGERROR("Nickname changed to an existing nick!");
|
|
|
|
|
|
|
|
|
|
DbgXMPP(nick << " is now known as " << participant.newNick);
|
|
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
|
|
|
|
"nick",
|
|
|
|
|
std::time(nullptr),
|
|
|
|
|
"oldnick", nick,
|
|
|
|
|
"newnick", participant.newNick);
|
2017-02-28 03:16:46 -08:00
|
|
|
}
|
|
|
|
|
else if (participant.flags & gloox::UserKicked)
|
|
|
|
|
{
|
2019-09-12 10:23:33 -07:00
|
|
|
DbgXMPP(nick << " was kicked. Reason: " << participant.reason);
|
|
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
|
|
|
|
"kicked",
|
|
|
|
|
std::time(nullptr),
|
|
|
|
|
"nick", nick,
|
|
|
|
|
"reason", participant.reason);
|
2017-02-28 03:16:46 -08:00
|
|
|
}
|
|
|
|
|
else if (participant.flags & gloox::UserBanned)
|
|
|
|
|
{
|
2019-09-12 10:23:33 -07:00
|
|
|
DbgXMPP(nick << " was banned. Reason: " << participant.reason);
|
|
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
|
|
|
|
"banned",
|
|
|
|
|
std::time(nullptr),
|
|
|
|
|
"nick", nick,
|
|
|
|
|
"reason", participant.reason);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
else
|
2017-02-28 03:16:46 -08:00
|
|
|
{
|
2017-07-31 09:33:14 -07:00
|
|
|
DbgXMPP(nick << " left the room (flags " << participant.flags << ")");
|
2019-09-12 10:23:33 -07:00
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
|
|
|
|
"leave",
|
|
|
|
|
std::time(nullptr),
|
|
|
|
|
"nick", nick);
|
2017-02-28 03:16:46 -08:00
|
|
|
}
|
2013-11-07 12:07:24 -08:00
|
|
|
m_PlayerMap.erase(nick);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-12 10:23:33 -07:00
|
|
|
const PlayerMap::iterator it = m_PlayerMap.find(nick);
|
|
|
|
|
|
2019-04-07 09:06:10 -07:00
|
|
|
/* During the initialization process, we receive join messages for everyone
|
2015-08-30 05:56:48 -07:00
|
|
|
* currently in the room. We don't want to display these, so we filter them
|
|
|
|
|
* out. We will always be the last to join during initialization.
|
|
|
|
|
*/
|
|
|
|
|
if (!m_initialLoadComplete)
|
|
|
|
|
{
|
2019-09-12 10:23:33 -07:00
|
|
|
if (m_mucRoom->nick() == nick)
|
2015-08-30 05:56:48 -07:00
|
|
|
m_initialLoadComplete = true;
|
|
|
|
|
}
|
2019-09-12 10:23:33 -07:00
|
|
|
else if (it == m_PlayerMap.end())
|
|
|
|
|
{
|
|
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
|
|
|
|
"join",
|
|
|
|
|
std::time(nullptr),
|
|
|
|
|
"nick", nick);
|
|
|
|
|
}
|
|
|
|
|
else if (it->second.m_Role != participant.role)
|
|
|
|
|
{
|
|
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
|
|
|
|
"role",
|
|
|
|
|
std::time(nullptr),
|
|
|
|
|
"nick", nick,
|
|
|
|
|
"oldrole", it->second.m_Role,
|
2026-01-04 11:31:45 -08:00
|
|
|
"newrole", participant.role,
|
|
|
|
|
"reason", participant.reason);
|
2019-09-12 10:23:33 -07:00
|
|
|
}
|
2013-11-07 12:07:24 -08:00
|
|
|
else
|
2019-09-11 04:51:34 -07:00
|
|
|
{
|
2019-09-05 19:53:22 -07:00
|
|
|
// Don't create a GUI message for regular presence changes, because
|
|
|
|
|
// several hundreds of them accumulate during a match, impacting performance terribly and
|
|
|
|
|
// the only way they are used is to determine whether to update the playerlist.
|
2019-09-11 04:51:34 -07:00
|
|
|
}
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2019-09-12 10:23:33 -07:00
|
|
|
DbgXMPP(
|
|
|
|
|
nick << " is in the room, "
|
|
|
|
|
"presence: " << GetPresenceString(presence.presence()) << ", "
|
|
|
|
|
"role: "<< GetRoleString(participant.role));
|
|
|
|
|
|
|
|
|
|
if (it == m_PlayerMap.end())
|
|
|
|
|
{
|
|
|
|
|
m_PlayerMap.emplace(
|
|
|
|
|
std::piecewise_construct,
|
|
|
|
|
std::forward_as_tuple(nick),
|
|
|
|
|
std::forward_as_tuple(presence.presence(), participant.role, std::string()));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
it->second.m_Presence = presence.presence();
|
|
|
|
|
it->second.m_Role = participant.role;
|
|
|
|
|
}
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
2019-09-11 04:51:34 -07:00
|
|
|
|
|
|
|
|
m_PlayerMapUpdate = true;
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2014-01-24 10:20:15 -08:00
|
|
|
/**
|
|
|
|
|
* Update local cache when subject changes.
|
|
|
|
|
*/
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleMUCSubject(gloox::MUCRoom*, const std::string& nick, const std::string& subject)
|
2014-01-24 10:20:15 -08:00
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
m_Subject = wstring_from_utf8(subject);
|
2019-09-12 10:23:33 -07:00
|
|
|
|
|
|
|
|
CreateGUIMessage(
|
|
|
|
|
"chat",
|
|
|
|
|
"subject",
|
|
|
|
|
std::time(nullptr),
|
|
|
|
|
"nick", nick,
|
|
|
|
|
"subject", m_Subject);
|
2014-01-24 10:20:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get current subject.
|
|
|
|
|
*/
|
2019-09-12 10:23:33 -07:00
|
|
|
const std::wstring& XmppClient::GetSubject()
|
2014-01-24 10:20:15 -08:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
return m_Impl->m_Subject;
|
2014-01-24 10:20:15 -08:00
|
|
|
}
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
/**
|
2025-05-19 07:51:33 -07:00
|
|
|
* Request MUC nick change, real change via mucRoomHandler.
|
2013-11-07 12:07:24 -08:00
|
|
|
*
|
2025-05-19 07:51:33 -07:00
|
|
|
* @param nick Desired MUC nickname
|
2013-11-07 12:07:24 -08:00
|
|
|
*/
|
|
|
|
|
void XmppClient::SetNick(const std::string& nick)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_mucRoom->setNick(nick);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-05-19 07:51:33 -07:00
|
|
|
* Get current MUC nickname.
|
2013-11-07 12:07:24 -08:00
|
|
|
*/
|
2021-05-09 05:51:32 -07:00
|
|
|
std::string XmppClient::GetNick() const
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
return m_Impl->m_mucRoom->nick();
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 11:23:58 -07:00
|
|
|
std::string XmppClient::GetJID()
|
2021-05-09 05:51:32 -07:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
return m_Impl->m_client.jid().full();
|
2021-05-09 05:51:32 -07:00
|
|
|
}
|
|
|
|
|
|
2025-05-19 07:51:33 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the XMPP username.
|
|
|
|
|
*
|
|
|
|
|
* @return current XMPP username
|
|
|
|
|
*/
|
|
|
|
|
std::string XmppClient::GetUsername() const
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
return m_Impl->m_username;
|
2025-05-19 07:51:33 -07:00
|
|
|
}
|
|
|
|
|
|
2024-10-21 10:17:25 -07:00
|
|
|
/**
|
|
|
|
|
* Change password for authenticated user.
|
|
|
|
|
*
|
|
|
|
|
* @param newPassword New password
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::ChangePassword(const std::string& newPassword)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_registration.changePassword(m_Impl->m_client.jid().username(), newPassword);
|
2024-10-21 10:17:25 -07:00
|
|
|
}
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
/**
|
|
|
|
|
* Kick a player from the current room.
|
|
|
|
|
*
|
|
|
|
|
* @param nick Nickname to be kicked
|
|
|
|
|
* @param reason Reason the player was kicked
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::kick(const std::string& nick, const std::string& reason)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_mucRoom->kick(nick, reason);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ban a player from the current room.
|
|
|
|
|
*
|
|
|
|
|
* @param nick Nickname to be banned
|
|
|
|
|
* @param reason Reason the player was banned
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::ban(const std::string& nick, const std::string& reason)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
m_Impl->m_mucRoom->ban(nick, reason);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Change the xmpp presence of the client.
|
|
|
|
|
*
|
|
|
|
|
* @param presence A string containing the desired presence
|
|
|
|
|
*/
|
|
|
|
|
void XmppClient::SetPresence(const std::string& presence)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
#define IF(x,y) if (presence == x) m_Impl->m_mucRoom->setPresence(gloox::Presence::y)
|
2013-11-07 12:07:24 -08:00
|
|
|
IF("available", Available);
|
|
|
|
|
else IF("chat", Chat);
|
|
|
|
|
else IF("away", Away);
|
|
|
|
|
else IF("playing", DND);
|
|
|
|
|
else IF("offline", Unavailable);
|
|
|
|
|
// The others are not to be set
|
|
|
|
|
#undef IF
|
2015-01-22 12:36:24 -08:00
|
|
|
else LOGERROR("Unknown presence '%s'", presence.c_str());
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current xmpp presence of the given nick.
|
|
|
|
|
*/
|
2019-09-12 10:23:33 -07:00
|
|
|
const char* XmppClient::GetPresence(const std::string& nick)
|
2013-11-07 12:07:24 -08:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
const auto it = m_Impl->m_PlayerMap.find(nick);
|
2019-09-12 10:23:33 -07:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
if (it == m_Impl->m_PlayerMap.end())
|
2019-09-12 10:23:33 -07:00
|
|
|
return "offline";
|
|
|
|
|
|
|
|
|
|
return GetPresenceString(it->second.m_Presence);
|
2013-11-07 12:07:24 -08:00
|
|
|
}
|
|
|
|
|
|
2014-04-12 16:40:36 -07:00
|
|
|
/**
|
|
|
|
|
* Get the current xmpp role of the given nick.
|
|
|
|
|
*/
|
2019-09-12 10:23:33 -07:00
|
|
|
const char* XmppClient::GetRole(const std::string& nick)
|
2014-04-12 16:40:36 -07:00
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
const auto it = m_Impl->m_PlayerMap.find(nick);
|
2019-09-12 10:23:33 -07:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
if (it == m_Impl->m_PlayerMap.end())
|
2019-09-12 10:23:33 -07:00
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
return GetRoleString(it->second.m_Role);
|
2014-04-12 16:40:36 -07:00
|
|
|
}
|
|
|
|
|
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
/**
|
|
|
|
|
* Get the most recent received rating of the given nick.
|
|
|
|
|
* Notice that this doesn't request a rating profile if it hasn't been received yet.
|
|
|
|
|
*/
|
|
|
|
|
std::wstring XmppClient::GetRating(const std::string& nick)
|
|
|
|
|
{
|
2026-03-19 10:36:52 -07:00
|
|
|
const auto it = m_Impl->m_PlayerMap.find(nick);
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
if (it == m_Impl->m_PlayerMap.end())
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
return std::wstring();
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
return wstring_from_utf8(it->second.m_Rating);
|
Rewrite lobby page to use class semantics, add more gamedetails labels, improve performance using batch processing and caching and gain possibility for game creation/player-join/leave events, refs #5387.
Game selection details features:
* Display victory conditions following their sending but missing display
following bffe917914, refs 7b0f6f530c.
* Display the host of the match and the game name in the selected game
details following 61261d14fc, refs D1666.
* Display mods if the mods differ (without having to attempt to join the
game prior) following eca956a513.
Performance features:
* Implement batch message processing in the XmppClient to rebuild GUI
objects only once when receiving backlog or returning from a match.
* Implement Game class to cache gamelist, filter and sorting values, as
they rarely change but are accessed often.
* Cache sprintf objects.
Security fixes:
* Add escapeText in lobby/ to avoid players breaking the lobby for every
participant, supersedes D720, comments by bb.
* Do not hide broadcasted unrecognized chat commands that mods used as
leaking private channels, fixes #5615.
Defect fixes:
* Fix XmppClient.cpp storing unused historic message types resulting in
memory waste and unintentional replay of for instance
disconnect/announcements messages following both e8dfde9ba6/D819 and
6bf74902a7/D2265, refs #3306.
* Fix XmppClient.cpp victoryCondition -> victoryConditions gamesetup.js
change from 6d54ab4c1f/D1240.
* Fix leaderboard/profile page cancel hotkey closing the lobby dialog as
well and removes cancel hotkey note from lobby_panels.xml from
960f2d7c31/D817 since the described issue was fixed by f9b529f2fb/D1701.
* Fix lobby playing menu sound in a running game after having closed the
lobby dialog following introduction in 960f2d7c31/D817.
* Fix GUI on nick change by updating g_Username.
* Update profile panel only with data matching the player requested.
Hack erasure:
* Object semantics make it cheap to add state and cache values, storing
literals in properties while removing globals, adding events while
decoupling components and gaining moddability.
* Erase comments and translation comments stating that this would be
IRC!!, supersedes D1136.
* Introduce Status chat message type to supersede "/special" chat
command + "isSpecial" property from bffe917914 (formerly g_specialKey
e6840f5fca) deluxe hack.
* Introduce System chat message type to supersede system errors
disguising as chat from a mock user called "system".
Code cleanups:
* Move code from XML to JS.
* Move size values from JS to XML, especially following 960f2d7c31/D817
and 7752219cef/D1051.
* Rename "user" to "player".
* Fix lobby/ eslint warnings, refs D2261.
* Remove message.nick emptiness check from 0940db3fc0/D835, since
XEP-0045 dictates that it is non-empty.
* Add translated string for deleted subjects.
* Add TODOs for some evident COList issues, refs #5638.
Differential Revision: https://code.wildfiregames.com/D2412
This was SVN commit r23172.
2019-11-21 05:44:41 -08:00
|
|
|
}
|
|
|
|
|
|
2013-11-07 12:07:24 -08:00
|
|
|
/*****************************************************
|
|
|
|
|
* Utilities *
|
|
|
|
|
*****************************************************/
|
|
|
|
|
|
2021-05-17 08:14:10 -07:00
|
|
|
void XmppClient::SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJIDStr)
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
{
|
2019-09-12 10:23:33 -07:00
|
|
|
DbgXMPP("SendStunEndpointToHost " << hostJIDStr);
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::JID hostJID(hostJIDStr);
|
2026-03-19 10:36:52 -07:00
|
|
|
gloox::Jingle::Session* session = m_Impl->m_sessionManager.createSession(hostJID, m_Impl.get());
|
2024-11-12 12:24:25 -08:00
|
|
|
|
|
|
|
|
gloox::Jingle::ICEUDP::CandidateList candidateList;
|
|
|
|
|
|
|
|
|
|
candidateList.push_back(gloox::Jingle::ICEUDP::Candidate{
|
|
|
|
|
"1", // component_id,
|
|
|
|
|
"1", // foundation
|
|
|
|
|
"0", // candidate_generation
|
|
|
|
|
"1", // candidate_id
|
|
|
|
|
ip,
|
|
|
|
|
"0", // network
|
|
|
|
|
port,
|
|
|
|
|
0, // priority
|
|
|
|
|
"udp",
|
|
|
|
|
"", // base_ip
|
|
|
|
|
0, // base_port
|
|
|
|
|
gloox::Jingle::ICEUDP::ServerReflexive});
|
|
|
|
|
|
|
|
|
|
// sessionInitiate deletes the new Content, and
|
|
|
|
|
// the Plugin destructor inherited by Content frees the ICEUDP plugin.
|
|
|
|
|
|
|
|
|
|
gloox::Jingle::PluginList pluginList;
|
|
|
|
|
pluginList.push_back(new gloox::Jingle::ICEUDP(/*local_pwd*/ "", /*local_ufrag*/ "", candidateList));
|
|
|
|
|
|
|
|
|
|
session->sessionInitiate(new gloox::Jingle::Content(std::string("game-data"), pluginList));
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleSessionAction(gloox::Jingle::Action action, gloox::Jingle::Session* session, const gloox::Jingle::Session::Jingle* jingle)
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
{
|
|
|
|
|
if (action == gloox::Jingle::SessionInitiate)
|
2019-08-16 17:12:19 -07:00
|
|
|
handleSessionInitiation(session, jingle);
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 10:36:52 -07:00
|
|
|
void XmppClient::Impl::handleSessionInitiation(gloox::Jingle::Session*,
|
2025-06-03 23:10:15 -07:00
|
|
|
const gloox::Jingle::Session::Jingle* jingle)
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
{
|
2024-11-12 12:24:25 -08:00
|
|
|
gloox::Jingle::ICEUDP::Candidate candidate{};
|
|
|
|
|
|
|
|
|
|
const gloox::Jingle::Content* content = static_cast<const gloox::Jingle::Content*>(jingle->plugins().front());
|
|
|
|
|
if (content)
|
|
|
|
|
{
|
|
|
|
|
const gloox::Jingle::ICEUDP* iceUDP = static_cast<const gloox::Jingle::ICEUDP*>(content->findPlugin(gloox::Jingle::PluginICEUDP));
|
|
|
|
|
if (iceUDP)
|
|
|
|
|
candidate = iceUDP->candidates().front();
|
|
|
|
|
}
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
|
|
|
|
|
if (candidate.ip.empty())
|
|
|
|
|
{
|
|
|
|
|
LOGERROR("Failed to retrieve Jingle candidate");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 14:56:05 -08:00
|
|
|
if (!g_NetServer)
|
|
|
|
|
{
|
|
|
|
|
LOGERROR("Received STUN connection request, but not hosting currently!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 12:24:25 -08:00
|
|
|
g_NetServer->SendHolePunchingMessage(candidate.ip, candidate.port);
|
STUN + XMPP ICE implementation.
Allows lobby players to host games without having to configure their
router.
Differential Revision: https://code.wildfiregames.com/D364
Fixes #2305
Patch By: fcxSanya.
StunClient based on code by SuperTuxKart, relicensed with approval of
the according authors hilnius, hiker, Auria, deveee, Flakebi, leper,
konstin and KroArtem.
Added rfc5245 (ejabberd) support, a GUI option, refactoring and segfault
fixes by myself.
Tested By: user1, Sandarac, Sestroretsk1714, Vladislav, Grugnas,
javiergodas
Partially Reviewed By: leper, Philip, echotangoecho
This was SVN commit r19703.
2017-05-31 23:33:52 -07:00
|
|
|
}
|