2024-08-10 07:08:31 +02:00
|
|
|
/* Copyright (C) 2024 Wildfire Games.
|
2023-12-03 01:30:12 +01:00
|
|
|
* This file is part of 0 A.D.
|
2013-11-07 21:07:24 +01:00
|
|
|
*
|
2023-12-03 01:30:12 +01:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2013-11-07 21:07:24 +01: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-03 01:30:12 +01:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2013-11-07 21:07:24 +01: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-03 01:30:12 +01:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2013-11-07 21:07:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
2018-08-24 13:29:38 +02:00
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
#include "XmppClient.h"
|
|
|
|
#include "StanzaExtensions.h"
|
|
|
|
|
2014-11-13 02:26:36 +01:00
|
|
|
#include "i18n/L10n.h"
|
2013-11-10 00:26:17 +01:00
|
|
|
#include "lib/utf8.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-06-01 08:33:52 +02:00
|
|
|
#include "network/NetServer.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 19:31:39 +01:00
|
|
|
#include "network/NetClient.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-06-01 08:33:52 +02:00
|
|
|
#include "network/StunClient.h"
|
2013-11-07 21:07:24 +01:00
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#include "ps/ConfigDB.h"
|
2021-05-09 14:51:32 +02:00
|
|
|
#include "ps/GUID.h"
|
2015-08-02 01:03:13 +02:00
|
|
|
#include "ps/Pyrogenesis.h"
|
2014-11-13 02:26:36 +01:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2021-05-10 13:51:32 +02:00
|
|
|
#include "scriptinterface/StructuredClone.h"
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2020-12-09 15:39:14 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
//debug
|
|
|
|
#if 1
|
|
|
|
#define DbgXMPP(x)
|
|
|
|
#else
|
|
|
|
#define DbgXMPP(x) std::cout << x << std::endl;
|
|
|
|
|
|
|
|
static std::string tag_xml(const glooxwrapper::IQ& iq)
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
glooxwrapper::Tag* tag = iq.tag();
|
|
|
|
ret = tag->xml().to_string();
|
|
|
|
glooxwrapper::Tag::free(tag);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static std::string tag_name(const glooxwrapper::IQ& iq)
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
glooxwrapper::Tag* tag = iq.tag();
|
|
|
|
ret = tag->name().to_string();
|
|
|
|
glooxwrapper::Tag::free(tag);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-06 07:14:20 +02:00
|
|
|
IXmppClient* IXmppClient::create(const ScriptInterface* scriptInterface, const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize,bool regOpt)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2019-09-06 07:14:20 +02:00
|
|
|
return new XmppClient(scriptInterface, sUsername, sPassword, sRoom, sNick, historyRequestSize, regOpt);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-26 06:39:55 +01:00
|
|
|
* Construct the XMPP client.
|
|
|
|
*
|
2019-09-06 07:14:20 +02:00
|
|
|
* @param scriptInterface - ScriptInterface to be used for storing GUI messages.
|
|
|
|
* Can be left blank for non-visual applications.
|
2014-01-26 06:39:55 +01: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 21:07:24 +01:00
|
|
|
*/
|
2019-09-06 07:14:20 +02:00
|
|
|
XmppClient::XmppClient(const ScriptInterface* scriptInterface, const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize, bool regOpt)
|
2019-09-09 22:50:17 +02:00
|
|
|
: m_ScriptInterface(scriptInterface),
|
|
|
|
m_client(nullptr),
|
|
|
|
m_mucRoom(nullptr),
|
|
|
|
m_registration(nullptr),
|
|
|
|
m_username(sUsername),
|
|
|
|
m_password(sPassword),
|
|
|
|
m_room(sRoom),
|
|
|
|
m_nick(sNick),
|
|
|
|
m_initialLoadComplete(false),
|
|
|
|
m_isConnected(false),
|
|
|
|
m_sessionManager(nullptr),
|
|
|
|
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 19:31:39 +01:00
|
|
|
m_PlayerMapUpdate(false),
|
|
|
|
m_connectionDataJid(),
|
|
|
|
m_connectionDataIqId()
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2019-09-06 07:14:20 +02:00
|
|
|
if (m_ScriptInterface)
|
2020-11-18 15:39:04 +01:00
|
|
|
JS_AddExtraGCRootsTracer(m_ScriptInterface->GetGeneralJSContext(), XmppClient::Trace, this);
|
2019-09-06 07:14:20 +02:00
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
// Read lobby configuration from default.cfg
|
|
|
|
std::string sXpartamupp;
|
2018-04-14 14:50:54 +02:00
|
|
|
std::string sEchelon;
|
2018-03-12 01:23:40 +01:00
|
|
|
CFG_GET_VAL("lobby.server", m_server);
|
2014-11-18 00:29:49 +01:00
|
|
|
CFG_GET_VAL("lobby.xpartamupp", sXpartamupp);
|
2018-04-14 14:50:54 +02:00
|
|
|
CFG_GET_VAL("lobby.echelon", sEchelon);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2018-03-12 01:23:40 +01:00
|
|
|
m_xpartamuppId = sXpartamupp + "@" + m_server + "/CC";
|
2018-04-14 14:50:54 +02:00
|
|
|
m_echelonId = sEchelon + "@" + m_server + "/CC";
|
2023-12-03 01:30:12 +01:00
|
|
|
// Generate a unique, unpredictable resource to allow multiple 0 A.D. instances to connect to the lobby.
|
2021-05-09 14:51:32 +02:00
|
|
|
glooxwrapper::JID clientJid(sUsername + "@" + m_server + "/0ad-" + ps_generate_guid());
|
2018-03-12 01:23:40 +01:00
|
|
|
glooxwrapper::JID roomJid(m_room + "@conference." + m_server + "/" + sNick);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
// If we are connecting, use the full jid and a password
|
|
|
|
// If we are registering, only use the server name
|
2015-06-19 19:25:28 +02:00
|
|
|
if (!regOpt)
|
2013-11-07 21:07:24 +01:00
|
|
|
m_client = new glooxwrapper::Client(clientJid, sPassword);
|
|
|
|
else
|
2018-03-12 01:23:40 +01:00
|
|
|
m_client = new glooxwrapper::Client(m_server);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2018-08-24 13:29:38 +02: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.
|
2018-11-27 15:41:44 +01:00
|
|
|
bool tls = true;
|
|
|
|
CFG_GET_VAL("lobby.tls", tls);
|
|
|
|
m_client->setTls(tls ? gloox::TLSRequired : gloox::TLSDisabled);
|
2013-11-07 21:07:24 +01: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;
|
|
|
|
m_client->setSASLMechanisms(mechs);
|
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
m_client->registerConnectionListener(this);
|
2013-11-07 21:07:24 +01:00
|
|
|
m_client->setPresence(gloox::Presence::Available, -1);
|
2015-08-02 01:03:13 +02:00
|
|
|
m_client->disco()->setVersion("Pyrogenesis", engine_version);
|
2014-09-20 17:35:26 +02:00
|
|
|
m_client->disco()->setIdentity("client", "bot");
|
2013-11-07 21:07:24 +01:00
|
|
|
m_client->setCompression(false);
|
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
m_client->registerStanzaExtension(new GameListQuery());
|
2015-06-19 19:25:28 +02:00
|
|
|
m_client->registerIqHandler(this, EXTGAMELISTQUERY);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
m_client->registerStanzaExtension(new BoardListQuery());
|
2015-06-19 19:25:28 +02:00
|
|
|
m_client->registerIqHandler(this, EXTBOARDLISTQUERY);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
m_client->registerStanzaExtension(new ProfileQuery());
|
2015-06-19 19:25:28 +02:00
|
|
|
m_client->registerIqHandler(this, EXTPROFILEQUERY);
|
2014-09-20 17:35:26 +02:00
|
|
|
|
2018-03-12 01:23:40 +01:00
|
|
|
m_client->registerStanzaExtension(new LobbyAuth());
|
|
|
|
m_client->registerIqHandler(this, EXTLOBBYAUTH);
|
|
|
|
|
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 19:31:39 +01:00
|
|
|
m_client->registerStanzaExtension(new ConnectionData());
|
|
|
|
m_client->registerIqHandler(this, EXTCONNECTIONDATA);
|
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
m_client->registerMessageHandler(this);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
// Uncomment to see the raw stanzas
|
2013-12-28 04:34:40 +01:00
|
|
|
//m_client->getWrapped()->logInstance().registerLogHandler( gloox::LogLevelDebug, gloox::LogAreaAll, this );
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
if (!regOpt)
|
|
|
|
{
|
|
|
|
// Create a Multi User Chat Room
|
|
|
|
m_mucRoom = new glooxwrapper::MUCRoom(m_client, roomJid, this, 0);
|
2014-01-26 06:39:55 +01:00
|
|
|
// Get room history.
|
|
|
|
m_mucRoom->setRequestHistory(historyRequestSize, gloox::MUCRoom::HistoryMaxStanzas);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Registration
|
|
|
|
m_registration = new glooxwrapper::Registration(m_client);
|
|
|
|
m_registration->registerRegistrationHandler(this);
|
|
|
|
}
|
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-06-01 08:33:52 +02:00
|
|
|
|
|
|
|
m_sessionManager = new glooxwrapper::SessionManager(m_client, this);
|
|
|
|
// Register plugins to allow gloox parse them in incoming sessions
|
|
|
|
m_sessionManager->registerPlugins();
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the xmpp client
|
|
|
|
*/
|
|
|
|
XmppClient::~XmppClient()
|
|
|
|
{
|
|
|
|
DbgXMPP("XmppClient destroyed");
|
|
|
|
delete m_registration;
|
|
|
|
delete m_mucRoom;
|
2019-07-19 21:46:48 +02:00
|
|
|
delete m_sessionManager;
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
// Workaround for memory leak in gloox 1.0/1.0.1
|
|
|
|
m_client->removePresenceExtension(gloox::ExtCaps);
|
|
|
|
|
|
|
|
delete m_client;
|
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : m_GameList)
|
|
|
|
glooxwrapper::Tag::free(t);
|
|
|
|
for (const glooxwrapper::Tag* const& t : m_BoardList)
|
|
|
|
glooxwrapper::Tag::free(t);
|
|
|
|
for (const glooxwrapper::Tag* const& t : m_Profile)
|
|
|
|
glooxwrapper::Tag::free(t);
|
2019-09-06 07:14:20 +02:00
|
|
|
|
|
|
|
if (m_ScriptInterface)
|
2020-11-18 15:39:04 +01:00
|
|
|
JS_RemoveExtraGCRootsTracer(m_ScriptInterface->GetGeneralJSContext(), XmppClient::Trace, this);
|
2019-09-06 07:14:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void XmppClient::TraceMember(JSTracer* trc)
|
|
|
|
{
|
|
|
|
for (JS::Heap<JS::Value>& guiMessage : m_GuiMessageQueue)
|
2020-11-12 09:04:24 +01:00
|
|
|
JS::TraceEdge(trc, &guiMessage, "m_GuiMessageQueue");
|
2019-09-06 07:14:20 +02:00
|
|
|
|
|
|
|
for (JS::Heap<JS::Value>& guiMessage : m_HistoricGuiMessages)
|
2020-11-12 09:04:24 +01:00
|
|
|
JS::TraceEdge(trc, &guiMessage, "m_HistoricGuiMessages");
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Network
|
|
|
|
void XmppClient::connect()
|
|
|
|
{
|
2015-08-30 14:56:48 +02:00
|
|
|
m_initialLoadComplete = false;
|
2013-11-07 21:07:24 +01:00
|
|
|
m_client->connect(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XmppClient::disconnect()
|
|
|
|
{
|
|
|
|
m_client->disconnect();
|
|
|
|
}
|
|
|
|
|
2018-01-15 05:30:33 +01:00
|
|
|
bool XmppClient::isConnected()
|
|
|
|
{
|
|
|
|
return m_isConnected;
|
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
void XmppClient::recv()
|
|
|
|
{
|
|
|
|
m_client->recv(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log (debug) Handler
|
|
|
|
*/
|
|
|
|
void XmppClient::handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message)
|
|
|
|
{
|
|
|
|
std::cout << "log: level: " << level << ", area: " << area << ", message: " << message << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* Connection handlers *
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle connection
|
|
|
|
*/
|
|
|
|
void XmppClient::onConnect()
|
|
|
|
{
|
|
|
|
if (m_mucRoom)
|
|
|
|
{
|
2018-01-15 05:30:33 +01:00
|
|
|
m_isConnected = true;
|
2019-09-06 07:14:20 +02:00
|
|
|
CreateGUIMessage("system", "connected", std::time(nullptr));
|
2013-11-07 21:07:24 +01:00
|
|
|
m_mucRoom->join();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_registration)
|
|
|
|
m_registration->fetchRegistrationFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle disconnection
|
|
|
|
*/
|
|
|
|
void XmppClient::onDisconnect(gloox::ConnectionError error)
|
|
|
|
{
|
|
|
|
// 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.
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : m_GameList)
|
|
|
|
glooxwrapper::Tag::free(t);
|
|
|
|
for (const glooxwrapper::Tag* const& t : m_BoardList)
|
|
|
|
glooxwrapper::Tag::free(t);
|
|
|
|
for (const glooxwrapper::Tag* const& t : m_Profile)
|
|
|
|
glooxwrapper::Tag::free(t);
|
2018-01-15 05:30:33 +01:00
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
m_BoardList.clear();
|
|
|
|
m_GameList.clear();
|
|
|
|
m_PlayerMap.clear();
|
2019-09-11 13:51:34 +02:00
|
|
|
m_PlayerMapUpdate = true;
|
2014-09-20 17:35:26 +02:00
|
|
|
m_Profile.clear();
|
2017-08-29 18:04:45 +02:00
|
|
|
m_HistoricGuiMessages.clear();
|
2018-01-15 05:30:33 +01:00
|
|
|
m_isConnected = false;
|
2020-01-02 23:14:14 +01:00
|
|
|
m_initialLoadComplete = false;
|
2019-09-11 13:51:34 +02:00
|
|
|
|
2019-09-09 23:26:58 +02:00
|
|
|
CreateGUIMessage(
|
|
|
|
"system",
|
|
|
|
"disconnected",
|
|
|
|
std::time(nullptr),
|
2019-09-12 19:23:33 +02:00
|
|
|
"reason", error,
|
|
|
|
"certificate_status", m_certStatus);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-24 13:29:38 +02:00
|
|
|
* Handle TLS connection.
|
2013-11-07 21:07:24 +01:00
|
|
|
*/
|
|
|
|
bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info)
|
|
|
|
{
|
|
|
|
DbgXMPP("onTLSConnect");
|
|
|
|
DbgXMPP(
|
|
|
|
"status: " << info.status <<
|
|
|
|
"\nissuer: " << info.issuer <<
|
|
|
|
"\npeer: " << info.server <<
|
|
|
|
"\nprotocol: " << info.protocol <<
|
|
|
|
"\nmac: " << info.mac <<
|
|
|
|
"\ncipher: " << info.cipher <<
|
|
|
|
"\ncompression: " << info.compression );
|
2018-08-24 13:29:38 +02:00
|
|
|
|
2018-10-09 19:50:08 +02:00
|
|
|
m_certStatus = static_cast<gloox::CertStatus>(info.status);
|
|
|
|
|
2018-08-24 13:29:38 +02:00
|
|
|
// Optionally accept invalid certificates, see require_tls option.
|
|
|
|
bool verify_certificate = true;
|
|
|
|
CFG_GET_VAL("lobby.verify_certificate", verify_certificate);
|
|
|
|
|
|
|
|
return info.status == gloox::CertOk || !verify_certificate;
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle MUC room errors
|
|
|
|
*/
|
2019-09-13 17:24:44 +02:00
|
|
|
void XmppClient::handleMUCError(glooxwrapper::MUCRoom& UNUSED(room), gloox::StanzaError err)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2019-09-13 17:24:44 +02:00
|
|
|
DbgXMPP("MUC Error " << ": " << StanzaErrorToString(err));
|
2019-09-12 19:23:33 +02:00
|
|
|
CreateGUIMessage("system", "error", std::time(nullptr), "text", err);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* Requests to server *
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request the leaderboard data from the server.
|
|
|
|
*/
|
|
|
|
void XmppClient::SendIqGetBoardList()
|
|
|
|
{
|
2018-04-14 14:50:54 +02:00
|
|
|
glooxwrapper::JID echelonJid(m_echelonId);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
// Send IQ
|
2014-01-24 00:13:13 +01:00
|
|
|
BoardListQuery* b = new BoardListQuery();
|
|
|
|
b->m_Command = "getleaderboard";
|
2018-04-14 14:50:54 +02:00
|
|
|
glooxwrapper::IQ iq(gloox::IQ::Get, echelonJid, m_client->getID());
|
2014-01-24 00:13:13 +01:00
|
|
|
iq.addExtension(b);
|
2013-11-07 21:07:24 +01:00
|
|
|
DbgXMPP("SendIqGetBoardList [" << tag_xml(iq) << "]");
|
|
|
|
m_client->send(iq);
|
|
|
|
}
|
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
/**
|
|
|
|
* Request the profile data from the server.
|
|
|
|
*/
|
|
|
|
void XmppClient::SendIqGetProfile(const std::string& player)
|
|
|
|
{
|
2018-04-14 14:50:54 +02:00
|
|
|
glooxwrapper::JID echelonJid(m_echelonId);
|
2014-09-20 17:35:26 +02:00
|
|
|
|
|
|
|
// Send IQ
|
|
|
|
ProfileQuery* b = new ProfileQuery();
|
|
|
|
b->m_Command = player;
|
2018-04-14 14:50:54 +02:00
|
|
|
glooxwrapper::IQ iq(gloox::IQ::Get, echelonJid, m_client->getID());
|
2014-09-20 17:35:26 +02:00
|
|
|
iq.addExtension(b);
|
|
|
|
DbgXMPP("SendIqGetProfile [" << tag_xml(iq) << "]");
|
|
|
|
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 19:31:39 +01:00
|
|
|
/**
|
|
|
|
* Request the Connection data (ip, port...) from the server.
|
|
|
|
*/
|
2021-05-18 16:47:36 +02: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 19:31:39 +01:00
|
|
|
{
|
|
|
|
glooxwrapper::JID targetJID(jid);
|
|
|
|
|
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
|
|
|
connectionData->m_Password = password;
|
2021-05-18 16:47:36 +02:00
|
|
|
connectionData->m_ClientSalt = clientSalt;
|
2021-05-16 17:34:38 +02:00
|
|
|
connectionData->m_IsLocalIP = localIP ? "1" : "0";
|
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 19:31:39 +01:00
|
|
|
glooxwrapper::IQ iq(gloox::IQ::Get, targetJID, m_client->getID());
|
|
|
|
iq.addExtension(connectionData);
|
2021-01-20 20:54:16 +01:00
|
|
|
m_connectionDataJid = iq.from().full();
|
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 19:31:39 +01:00
|
|
|
m_connectionDataIqId = iq.id().to_string();
|
|
|
|
DbgXMPP("SendIqGetConnectionData [" << tag_xml(iq) << "]");
|
|
|
|
m_client->send(iq);
|
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
/**
|
|
|
|
* Send game report containing numerous game properties to the server.
|
|
|
|
*
|
|
|
|
* @param data A JS array of game statistics
|
|
|
|
*/
|
2021-05-13 19:23:52 +02:00
|
|
|
void XmppClient::SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2018-04-14 14:50:54 +02:00
|
|
|
glooxwrapper::JID echelonJid(m_echelonId);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
// Setup some base stanza attributes
|
|
|
|
GameReport* game = new GameReport();
|
|
|
|
glooxwrapper::Tag* report = glooxwrapper::Tag::allocate("game");
|
|
|
|
|
|
|
|
// Iterate through all the properties reported and add them to the stanza.
|
|
|
|
std::vector<std::string> properties;
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::EnumeratePropertyNames(rq, data, true, properties);
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const std::string& p : properties)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2013-11-10 00:26:17 +01:00
|
|
|
std::wstring value;
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::GetProperty(rq, data, p.c_str(), value);
|
2015-06-19 19:25:28 +02:00
|
|
|
report->addAttribute(p, utf8_from_wstring(value));
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add stanza to IQ
|
2015-06-19 19:25:28 +02:00
|
|
|
game->m_GameReport.emplace_back(report);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
// Send IQ
|
2018-04-14 14:50:54 +02:00
|
|
|
glooxwrapper::IQ iq(gloox::IQ::Set, echelonJid, m_client->getID());
|
2013-11-07 21:07:24 +01:00
|
|
|
iq.addExtension(game);
|
|
|
|
DbgXMPP("SendGameReport [" << tag_xml(iq) << "]");
|
|
|
|
m_client->send(iq);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a request to register a game to the server.
|
|
|
|
*
|
|
|
|
* @param data A JS array of game attributes
|
|
|
|
*/
|
2021-05-13 19:23:52 +02:00
|
|
|
void XmppClient::SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue data)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
|
|
|
glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
|
|
|
|
|
|
|
|
// Setup some base stanza attributes
|
2021-05-09 14:51:32 +02:00
|
|
|
std::unique_ptr<GameListQuery> g = std::make_unique<GameListQuery>();
|
2013-11-07 21:07:24 +01:00
|
|
|
g->m_Command = "register";
|
|
|
|
glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game");
|
|
|
|
|
|
|
|
// Iterate through all the properties reported and add them to the stanza.
|
|
|
|
std::vector<std::string> properties;
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::EnumeratePropertyNames(rq, data, true, properties);
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const std::string& p : properties)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2021-05-09 14:51:32 +02:00
|
|
|
std::string value;
|
2021-05-13 19:23:52 +02:00
|
|
|
if (!Script::GetProperty(rq, data, p.c_str(), value))
|
2021-05-09 14:51:32 +02:00
|
|
|
{
|
|
|
|
LOGERROR("Could not parse attribute '%s' as string.", p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
game->addAttribute(p, value);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
2021-05-09 14:51:32 +02: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 21:07:24 +01:00
|
|
|
// Push the stanza onto the IQ
|
2015-06-19 19:25:28 +02:00
|
|
|
g->m_GameList.emplace_back(game);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
// Send IQ
|
2017-10-21 16:11:25 +02:00
|
|
|
glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
2021-05-09 14:51:32 +02:00
|
|
|
iq.addExtension(g.release());
|
2013-11-07 21:07:24 +01:00
|
|
|
DbgXMPP("SendIqRegisterGame [" << tag_xml(iq) << "]");
|
|
|
|
m_client->send(iq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a request to unregister a game to the server.
|
|
|
|
*/
|
|
|
|
void XmppClient::SendIqUnregisterGame()
|
|
|
|
{
|
|
|
|
glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
|
|
|
|
|
|
|
|
// Send IQ
|
|
|
|
GameListQuery* g = new GameListQuery();
|
|
|
|
g->m_Command = "unregister";
|
2015-06-19 19:25:28 +02:00
|
|
|
g->m_GameList.emplace_back(glooxwrapper::Tag::allocate("game"));
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2017-10-21 16:11:25 +02:00
|
|
|
glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
2015-06-19 19:25:28 +02:00
|
|
|
iq.addExtension(g);
|
2013-11-07 21:07:24 +01:00
|
|
|
DbgXMPP("SendIqUnregisterGame [" << tag_xml(iq) << "]");
|
2015-06-19 19:25:28 +02:00
|
|
|
m_client->send(iq);
|
2013-11-07 21:07:24 +01: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)
|
|
|
|
{
|
|
|
|
glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
|
|
|
|
|
|
|
|
// Send IQ
|
|
|
|
GameListQuery* g = new GameListQuery();
|
|
|
|
g->m_Command = "changestate";
|
|
|
|
glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game");
|
|
|
|
game->addAttribute("nbp", nbp);
|
|
|
|
game->addAttribute("players", players);
|
2015-06-19 19:25:28 +02:00
|
|
|
g->m_GameList.emplace_back(game);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2017-10-21 16:11:25 +02:00
|
|
|
glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
2015-06-19 19:25:28 +02:00
|
|
|
iq.addExtension(g);
|
2013-11-07 21:07:24 +01:00
|
|
|
DbgXMPP("SendIqChangeStateGame [" << tag_xml(iq) << "]");
|
|
|
|
m_client->send(iq);
|
|
|
|
}
|
|
|
|
|
2018-03-12 01:23:40 +01: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;
|
|
|
|
|
2021-05-09 14:51:32 +02:00
|
|
|
glooxwrapper::JID clientJid(to);
|
2018-03-12 01:23:40 +01:00
|
|
|
glooxwrapper::IQ iq(gloox::IQ::Set, clientJid, m_client->getID());
|
|
|
|
iq.addExtension(auth);
|
|
|
|
DbgXMPP("SendIqLobbyAuth [" << tag_xml(iq) << "]");
|
|
|
|
m_client->send(iq);
|
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
/*****************************************************
|
|
|
|
* Account registration *
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
void XmppClient::handleRegistrationFields(const glooxwrapper::JID&, int fields, glooxwrapper::string)
|
|
|
|
{
|
|
|
|
glooxwrapper::RegistrationFields vals;
|
|
|
|
vals.username = m_username;
|
|
|
|
vals.password = m_password;
|
|
|
|
m_registration->createAccount(fields, vals);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XmppClient::handleRegistrationResult(const glooxwrapper::JID&, gloox::RegistrationResult result)
|
|
|
|
{
|
|
|
|
if (result == gloox::RegistrationSuccess)
|
2019-09-06 07:14:20 +02:00
|
|
|
CreateGUIMessage("system", "registered", std::time(nullptr));
|
2013-11-07 21:07:24 +01:00
|
|
|
else
|
2019-09-12 19:23:33 +02:00
|
|
|
CreateGUIMessage("system", "error", std::time(nullptr), "text", result);
|
2017-08-28 19:47:43 +02:00
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void XmppClient::handleAlreadyRegistered(const glooxwrapper::JID&)
|
|
|
|
{
|
|
|
|
DbgXMPP("the account already exists");
|
|
|
|
}
|
|
|
|
|
|
|
|
void XmppClient::handleDataForm(const glooxwrapper::JID&, const glooxwrapper::DataForm&)
|
|
|
|
{
|
|
|
|
DbgXMPP("dataForm received");
|
|
|
|
}
|
|
|
|
|
|
|
|
void XmppClient::handleOOB(const glooxwrapper::JID&, const glooxwrapper::OOB&)
|
|
|
|
{
|
|
|
|
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 19:23:52 +02:00
|
|
|
JS::Value XmppClient::GUIGetPlayerList(const ScriptRequest& rq)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2021-03-02 21:01:14 +01:00
|
|
|
JS::RootedValue ret(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateArray(rq, &ret);
|
2019-07-22 21:35:14 +02:00
|
|
|
int j = 0;
|
2014-01-26 05:25:35 +01:00
|
|
|
|
2020-12-31 15:27:02 +01:00
|
|
|
for (const std::pair<const glooxwrapper::string, SPlayer>& p : m_PlayerMap)
|
2014-01-26 05:25:35 +01:00
|
|
|
{
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue player(rq.cx);
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(
|
2020-11-13 14:18:22 +01:00
|
|
|
rq,
|
2019-07-22 21:35:14 +02:00
|
|
|
&player,
|
2019-09-12 19:23:33 +02:00
|
|
|
"name", p.first,
|
|
|
|
"presence", p.second.m_Presence,
|
|
|
|
"rating", p.second.m_Rating,
|
|
|
|
"role", p.second.m_Role);
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetPropertyInt(rq, ret, j++, player);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
2021-03-02 21:01:14 +01:00
|
|
|
return ret;
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle requests from the GUI for the list of all active games.
|
|
|
|
*
|
|
|
|
* @return A JS array containing all known games
|
|
|
|
*/
|
2021-05-13 19:23:52 +02:00
|
|
|
JS::Value XmppClient::GUIGetGameList(const ScriptRequest& rq)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2021-03-02 21:01:14 +01:00
|
|
|
JS::RootedValue ret(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateArray(rq, &ret);
|
2019-07-22 21:35:14 +02:00
|
|
|
int j = 0;
|
|
|
|
|
2021-05-09 14:51:32 +02:00
|
|
|
const char* stats[] = { "name", "hostUsername", "hostJID", "state", "hasPassword",
|
2018-02-21 18:27:33 +01: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 14:44:41 +01:00
|
|
|
"victoryConditions", "startTime", "mods" };
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for(const glooxwrapper::Tag* const& t : m_GameList)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue game(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(rq, &game);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(stats); ++i)
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, game, stats[i], t->findAttribute(stats[i]));
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetPropertyInt(rq, ret, j++, game);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
2021-03-02 21:01:14 +01:00
|
|
|
return ret;
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle requests from the GUI for leaderboard data.
|
|
|
|
*
|
|
|
|
* @return A JS array containing all known leaderboard data
|
|
|
|
*/
|
2021-05-13 19:23:52 +02:00
|
|
|
JS::Value XmppClient::GUIGetBoardList(const ScriptRequest& rq)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2021-03-02 21:01:14 +01:00
|
|
|
JS::RootedValue ret(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateArray(rq, &ret);
|
2019-07-22 21:35:14 +02:00
|
|
|
int j = 0;
|
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
const char* attributes[] = { "name", "rank", "rating" };
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for(const glooxwrapper::Tag* const& t : m_BoardList)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue board(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(rq, &board);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(attributes); ++i)
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, board, attributes[i], t->findAttribute(attributes[i]));
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetPropertyInt(rq, ret, j++, board);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
2021-03-02 21:01:14 +01:00
|
|
|
return ret;
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
/**
|
|
|
|
* Handle requests from the GUI for profile data.
|
|
|
|
*
|
|
|
|
* @return A JS array containing the specific user's profile data
|
|
|
|
*/
|
2021-05-13 19:23:52 +02:00
|
|
|
JS::Value XmppClient::GUIGetProfile(const ScriptRequest& rq)
|
2014-09-20 17:35:26 +02:00
|
|
|
{
|
2021-03-02 21:01:14 +01:00
|
|
|
JS::RootedValue ret(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateArray(rq, &ret);
|
2019-07-22 21:35:14 +02:00
|
|
|
int j = 0;
|
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
const char* stats[] = { "player", "rating", "totalGamesPlayed", "highestRating", "wins", "losses", "rank" };
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : m_Profile)
|
2014-09-20 17:35:26 +02:00
|
|
|
{
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue profile(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(rq, &profile);
|
2014-09-20 17:35:26 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(stats); ++i)
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, profile, stats[i], t->findAttribute(stats[i]));
|
2014-09-20 17:35:26 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetPropertyInt(rq, ret, j++, profile);
|
2014-09-20 17:35:26 +02:00
|
|
|
}
|
2021-03-02 21:01:14 +01:00
|
|
|
return ret;
|
2014-09-20 17:35:26 +02:00
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
/*****************************************************
|
|
|
|
* Message interfaces *
|
|
|
|
*****************************************************/
|
|
|
|
|
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 19:29:17 +01:00
|
|
|
void SetGUIMessageProperty(const ScriptRequest& UNUSED(rq), JS::HandleObject UNUSED(messageObj))
|
2017-08-28 19:47:43 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-06 07:14:20 +02: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 19:29:17 +01:00
|
|
|
void SetGUIMessageProperty(const ScriptRequest& rq, JS::HandleObject messageObj, const std::string& propertyName, const T& propertyValue, Args const&... args)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue scriptPropertyValue(rq.cx);
|
2021-05-13 11:43:33 +02:00
|
|
|
Script::ToJSVal(rq, &scriptPropertyValue, propertyValue);
|
2020-11-13 14:18:22 +01:00
|
|
|
JS_DefineProperty(rq.cx, messageObj, propertyName.c_str(), scriptPropertyValue, JSPROP_ENUMERATE);
|
|
|
|
SetGUIMessageProperty(rq, messageObj, args...);
|
2019-09-06 07:14:20 +02:00
|
|
|
}
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2019-09-06 07:14:20 +02:00
|
|
|
template<typename... Args>
|
|
|
|
void XmppClient::CreateGUIMessage(
|
|
|
|
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 19:29:17 +01:00
|
|
|
ScriptRequest rq(m_ScriptInterface);
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue message(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(
|
2020-11-13 14:18:22 +01:00
|
|
|
rq,
|
2019-09-11 12:15:13 +02:00
|
|
|
&message,
|
|
|
|
"type", type,
|
|
|
|
"level", level,
|
|
|
|
"historic", false,
|
|
|
|
"time", static_cast<double>(time));
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject messageObj(rq.cx, message.toObjectOrNull());
|
|
|
|
SetGUIMessageProperty(rq, messageObj, args...);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::FreezeObject(rq, message, true);
|
2019-09-06 07:14:20 +02:00
|
|
|
m_GuiMessageQueue.push_back(JS::Heap<JS::Value>(message));
|
2017-08-29 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 13:51:34 +02:00
|
|
|
bool XmppClient::GuiPollHasPlayerListUpdate()
|
2019-09-06 04:53:22 +02: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 14:44:41 +01:00
|
|
|
// The initial playerlist will be received in multiple messages
|
|
|
|
// Only inform the GUI after all of these playerlist fragments were received.
|
|
|
|
if (!m_initialLoadComplete)
|
|
|
|
return false;
|
|
|
|
|
2019-09-11 13:51:34 +02:00
|
|
|
bool hasUpdate = m_PlayerMapUpdate;
|
|
|
|
m_PlayerMapUpdate = false;
|
2019-09-06 04:53:22 +02:00
|
|
|
return hasUpdate;
|
|
|
|
}
|
|
|
|
|
2021-05-10 13:51:32 +02:00
|
|
|
JS::Value XmppClient::GuiPollNewMessages(const ScriptInterface& guiInterface)
|
2017-08-29 18:04:45 +02:00
|
|
|
{
|
2020-01-02 23:14:14 +01:00
|
|
|
if ((m_isConnected && !m_initialLoadComplete) || m_GuiMessageQueue.empty())
|
2017-08-29 18:04:45 +02:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
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 19:29:17 +01:00
|
|
|
ScriptRequest rq(m_ScriptInterface);
|
2019-09-06 07:14:20 +02: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 14:44:41 +01:00
|
|
|
// Optimize for batch message processing that is more
|
|
|
|
// performance demanding than processing a lone message.
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue messages(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateArray(rq, &messages);
|
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 14:44:41 +01:00
|
|
|
|
|
|
|
int j = 0;
|
2017-08-29 18:04:45 +02: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 14:44:41 +01:00
|
|
|
for (const JS::Heap<JS::Value>& message : m_GuiMessageQueue)
|
2019-09-06 07:14:20 +02:00
|
|
|
{
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetPropertyInt(rq, messages, j++, 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 14:44:41 +01:00
|
|
|
|
|
|
|
// Store historic chat messages.
|
|
|
|
// Only store relevant messages to minimize memory footprint.
|
2020-11-13 14:18:22 +01: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 14:44:41 +01:00
|
|
|
std::string type;
|
2021-05-13 19:23:52 +02: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 14:44:41 +01:00
|
|
|
if (type != "chat")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::string level;
|
2021-05-13 19:23:52 +02: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 14:44:41 +01:00
|
|
|
if (level != "room-message" && level != "private-message")
|
|
|
|
continue;
|
|
|
|
|
2021-05-10 13:51:32 +02: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 14:44:41 +01:00
|
|
|
{
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetProperty(rq, historicMessage, "historic", true);
|
|
|
|
Script::FreezeObject(rq, historicMessage, 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 14:44:41 +01:00
|
|
|
m_HistoricGuiMessages.push_back(JS::Heap<JS::Value>(historicMessage));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LOGERROR("Could not clone historic lobby GUI message!");
|
2019-09-06 07:14:20 +02: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 14:44:41 +01:00
|
|
|
m_GuiMessageQueue.clear();
|
2020-10-31 11:13:33 +01:00
|
|
|
|
|
|
|
// Copy the messages over to the caller script interface.
|
2021-05-10 13:51:32 +02:00
|
|
|
return Script::CloneValueFromOtherCompartment(guiInterface, *m_ScriptInterface, messages);
|
2017-08-29 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 13:51:32 +02:00
|
|
|
JS::Value XmppClient::GuiPollHistoricMessages(const ScriptInterface& guiInterface)
|
2017-08-29 18:04:45 +02: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 14:44:41 +01:00
|
|
|
if (m_HistoricGuiMessages.empty())
|
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
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 19:29:17 +01:00
|
|
|
ScriptRequest rq(m_ScriptInterface);
|
2017-08-29 18:04:45 +02:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue messages(rq.cx);
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateArray(rq, &messages);
|
2019-07-22 21:35:14 +02:00
|
|
|
|
|
|
|
int j = 0;
|
2019-09-06 07:14:20 +02:00
|
|
|
for (const JS::Heap<JS::Value>& message : m_HistoricGuiMessages)
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::SetPropertyInt(rq, messages, j++, message);
|
2019-09-06 07:14:20 +02:00
|
|
|
|
2020-10-31 11:13:33 +01:00
|
|
|
// Copy the messages over to the caller script interface.
|
2021-05-10 13:51:32 +02:00
|
|
|
return Script::CloneValueFromOtherCompartment(guiInterface, *m_ScriptInterface, messages);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a standard MUC textual message.
|
|
|
|
*/
|
|
|
|
void XmppClient::SendMUCMessage(const std::string& message)
|
|
|
|
{
|
|
|
|
m_mucRoom->send(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-31 18:08:23 +01:00
|
|
|
* Handle a room message.
|
2013-11-07 21:07:24 +01:00
|
|
|
*/
|
2019-09-13 17:24:44 +02:00
|
|
|
void XmppClient::handleMUCMessage(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::Message& msg, bool priv)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
|
|
|
DbgXMPP(msg.from().resource() << " said " << msg.body());
|
|
|
|
|
2017-08-28 19:47:43 +02:00
|
|
|
CreateGUIMessage(
|
|
|
|
"chat",
|
|
|
|
priv ? "private-message" : "room-message",
|
2019-09-06 07:14:20 +02:00
|
|
|
ComputeTimestamp(msg),
|
2019-09-12 19:23:33 +02:00
|
|
|
"from", msg.from().resource(),
|
|
|
|
"text", msg.body());
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-31 18:08:23 +01:00
|
|
|
* Handle a private message.
|
2013-11-07 21:07:24 +01:00
|
|
|
*/
|
2017-08-28 19:47:43 +02:00
|
|
|
void XmppClient::handleMessage(const glooxwrapper::Message& msg, glooxwrapper::MessageSession*)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
|
|
|
DbgXMPP("type " << msg.subtype() << ", subject " << msg.subject()
|
|
|
|
<< ", message " << msg.body() << ", thread id " << msg.thread());
|
|
|
|
|
2017-08-28 19:47:43 +02:00
|
|
|
CreateGUIMessage(
|
|
|
|
"chat",
|
2024-08-10 07:08:31 +02:00
|
|
|
msg.subtype() == gloox::Message::MessageType::Headline ? "headline" : "private-message",
|
2019-09-06 07:14:20 +02:00
|
|
|
ComputeTimestamp(msg),
|
2019-09-12 19:23:33 +02:00
|
|
|
"from", msg.from().resource(),
|
2024-08-10 07:08:31 +02:00
|
|
|
"subject", msg.subject(),
|
2019-09-12 19:23:33 +02:00
|
|
|
"text", msg.body());
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle portions of messages containing custom stanza extensions.
|
|
|
|
*/
|
|
|
|
bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|
|
|
{
|
|
|
|
DbgXMPP("handleIq [" << tag_xml(iq) << "]");
|
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
if (iq.subtype() == gloox::IQ::Result)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2015-06-19 19:25:28 +02: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 19:31:39 +01:00
|
|
|
const ConnectionData* cd = iq.findExtension<ConnectionData>(EXTCONNECTIONDATA);
|
|
|
|
if (cd)
|
|
|
|
{
|
|
|
|
if (g_NetServer || !g_NetClient)
|
|
|
|
return true;
|
|
|
|
|
2021-01-20 20:54:16 +01: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 19:31:39 +01:00
|
|
|
return true;
|
2021-01-20 20:54:16 +01: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 19:31:39 +01:00
|
|
|
|
2021-01-20 20:54:16 +01:00
|
|
|
if (!m_connectionDataIqId.empty() && m_connectionDataIqId.compare(iq.id().to_string()) != 0) {
|
2021-05-09 14:51:32 +02: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 19:31:39 +01:00
|
|
|
return true;
|
2021-01-20 20:54:16 +01: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 19:31:39 +01:00
|
|
|
|
|
|
|
if (!cd->m_Error.empty())
|
|
|
|
{
|
|
|
|
g_NetClient->HandleGetServerDataFailed(cd->m_Error.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_NetClient->SetupServerData(cd->m_Ip.to_string(), stoi(cd->m_Port.to_string()), !cd->m_UseSTUN.empty());
|
2021-05-22 10:34:00 +02:00
|
|
|
g_NetClient->TryToConnect(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 19:31:39 +01:00
|
|
|
}
|
2015-06-19 19:25:28 +02:00
|
|
|
if (gq)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2024-08-13 06:59:38 +02:00
|
|
|
if (iq.from().full() != m_xpartamuppId)
|
|
|
|
{
|
|
|
|
LOGWARNING("XmppClient: Received game list response from unexpected sender: %s", iq.from().full());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gq->m_Command == "register" && g_NetServer && !g_NetServer->GetUseSTUN())
|
2021-02-08 16:47:34 +01:00
|
|
|
{
|
|
|
|
if (gq->m_GameList.empty())
|
|
|
|
{
|
|
|
|
LOGWARNING("XmppClient: Received empty game list in response to Game Register");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
std::string publicIP = gq->m_GameList.front()->findAttribute("ip").to_string();
|
|
|
|
if (publicIP.empty())
|
|
|
|
{
|
|
|
|
LOGWARNING("XmppClient: Received game with no IP in response to Game Register");
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-17 17:14:10 +02:00
|
|
|
g_NetServer->SetConnectionData(publicIP, g_NetServer->GetPublicPort());
|
2021-02-08 16:47:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : m_GameList)
|
|
|
|
glooxwrapper::Tag::free(t);
|
2013-11-07 21:07:24 +01:00
|
|
|
m_GameList.clear();
|
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : gq->m_GameList)
|
|
|
|
m_GameList.emplace_back(t->clone());
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2019-09-06 07:14:20 +02:00
|
|
|
CreateGUIMessage("game", "gamelist", std::time(nullptr));
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
2015-06-19 19:25:28 +02:00
|
|
|
if (bq)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2024-08-13 06:59:38 +02:00
|
|
|
if (iq.from().full() != m_echelonId)
|
|
|
|
{
|
|
|
|
LOGWARNING("XmppClient: Received board list response from unexpected sender: %s", iq.from().full());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-24 00:13:13 +01:00
|
|
|
if (bq->m_Command == "boardlist")
|
|
|
|
{
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : m_BoardList)
|
|
|
|
glooxwrapper::Tag::free(t);
|
2014-01-24 00:13:13 +01:00
|
|
|
m_BoardList.clear();
|
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : bq->m_StanzaBoardList)
|
|
|
|
m_BoardList.emplace_back(t->clone());
|
2014-01-24 00:13:13 +01:00
|
|
|
|
2019-09-06 07:14:20 +02:00
|
|
|
CreateGUIMessage("game", "leaderboard", std::time(nullptr));
|
2014-01-24 00:13:13 +01:00
|
|
|
}
|
|
|
|
else if (bq->m_Command == "ratinglist")
|
|
|
|
{
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : bq->m_StanzaBoardList)
|
2014-01-26 20:01:21 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
const PlayerMap::iterator it = m_PlayerMap.find(t->findAttribute("name"));
|
|
|
|
if (it != m_PlayerMap.end())
|
2019-09-11 13:51:34 +02:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
it->second.m_Rating = t->findAttribute("rating");
|
2019-09-11 13:51:34 +02:00
|
|
|
m_PlayerMapUpdate = true;
|
|
|
|
}
|
2014-01-26 20:01:21 +01:00
|
|
|
}
|
2019-09-06 07:14:20 +02:00
|
|
|
CreateGUIMessage("game", "ratinglist", std::time(nullptr));
|
2014-01-24 00:13:13 +01:00
|
|
|
}
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
2014-09-20 17:35:26 +02:00
|
|
|
if (pq)
|
|
|
|
{
|
2024-08-13 06:59:38 +02:00
|
|
|
if (iq.from().full() != m_echelonId)
|
|
|
|
{
|
|
|
|
LOGWARNING("XmppClient: Received profile response from unexpected sender: %s", iq.from().full());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : m_Profile)
|
|
|
|
glooxwrapper::Tag::free(t);
|
2014-09-20 17:35:26 +02:00
|
|
|
m_Profile.clear();
|
|
|
|
|
2015-06-19 19:25:28 +02:00
|
|
|
for (const glooxwrapper::Tag* const& t : pq->m_StanzaProfile)
|
|
|
|
m_Profile.emplace_back(t->clone());
|
2014-09-20 17:35:26 +02:00
|
|
|
|
2019-09-06 07:14:20 +02:00
|
|
|
CreateGUIMessage("game", "profile", std::time(nullptr));
|
2014-09-20 17:35:26 +02:00
|
|
|
}
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
2018-03-12 01:23:40 +01:00
|
|
|
else if (iq.subtype() == gloox::IQ::Set)
|
|
|
|
{
|
|
|
|
const LobbyAuth* lobbyAuth = iq.findExtension<LobbyAuth>(EXTLOBBYAUTH);
|
|
|
|
if (lobbyAuth)
|
|
|
|
{
|
|
|
|
LOGMESSAGE("XmppClient: Received lobby auth: %s from %s", lobbyAuth->m_Token.to_string(), iq.from().username());
|
|
|
|
|
|
|
|
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
|
|
|
m_client->send(response);
|
|
|
|
|
|
|
|
if (g_NetServer)
|
|
|
|
g_NetServer->OnLobbyAuth(iq.from().username(), lobbyAuth->m_Token.to_string());
|
2018-11-07 23:56:05 +01:00
|
|
|
else
|
2021-05-09 14:51:32 +02:00
|
|
|
LOGMESSAGE("Received lobby authentication request, but not hosting currently!");
|
2018-03-12 01:23:40 +01: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 19:31:39 +01:00
|
|
|
else if (iq.subtype() == gloox::IQ::Get)
|
|
|
|
{
|
|
|
|
const ConnectionData* cd = iq.findExtension<ConnectionData>(EXTCONNECTIONDATA);
|
|
|
|
if (cd)
|
|
|
|
{
|
2021-03-10 17:50:15 +01: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 19:31:39 +01:00
|
|
|
if (!g_NetServer)
|
|
|
|
{
|
|
|
|
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
|
|
|
connectionData->m_Error = "not_server";
|
|
|
|
|
|
|
|
response.addExtension(connectionData);
|
|
|
|
|
|
|
|
m_client->send(response);
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-26 21:20:48 +01:00
|
|
|
if (g_NetServer->IsBanned(iq.from().username()))
|
|
|
|
{
|
|
|
|
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
|
|
|
connectionData->m_Error = "banned";
|
|
|
|
|
|
|
|
response.addExtension(connectionData);
|
|
|
|
|
|
|
|
m_client->send(response);
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-18 16:47:36 +02:00
|
|
|
if (!g_NetServer->CheckPasswordAndIncrement(iq.from().username(), cd->m_Password.to_string(), cd->m_ClientSalt.to_string()))
|
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 19:31:39 +01:00
|
|
|
{
|
|
|
|
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
|
|
|
connectionData->m_Error = "invalid_password";
|
|
|
|
|
|
|
|
response.addExtension(connectionData);
|
|
|
|
|
|
|
|
m_client->send(response);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
|
|
|
ConnectionData* connectionData = new ConnectionData();
|
2021-05-16 17:34:38 +02:00
|
|
|
|
|
|
|
if (cd->m_IsLocalIP.to_string() == "0")
|
|
|
|
{
|
|
|
|
connectionData->m_Ip = g_NetServer->GetPublicIp();
|
|
|
|
connectionData->m_Port = std::to_string(g_NetServer->GetPublicPort());
|
|
|
|
connectionData->m_UseSTUN = g_NetServer->GetUseSTUN() ? "true" : "";
|
2021-05-22 10:34:00 +02:00
|
|
|
connectionData->m_IsLocalIP = "";
|
2021-05-16 17:34:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CStr ip;
|
|
|
|
if (StunClient::FindLocalIP(ip))
|
|
|
|
{
|
|
|
|
connectionData->m_Ip = ip;
|
|
|
|
connectionData->m_Port = std::to_string(g_NetServer->GetLocalPort());
|
|
|
|
connectionData->m_UseSTUN = "";
|
2021-05-22 10:34:00 +02:00
|
|
|
connectionData->m_IsLocalIP = "true";
|
2021-05-16 17:34:38 +02: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 19:31:39 +01:00
|
|
|
|
|
|
|
response.addExtension(connectionData);
|
|
|
|
|
|
|
|
m_client->send(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-09-20 17:35:26 +02:00
|
|
|
else if (iq.subtype() == gloox::IQ::Error)
|
2019-09-12 19:23:33 +02:00
|
|
|
CreateGUIMessage("system", "error", std::time(nullptr), "text", iq.error_error());
|
2013-11-07 21:07:24 +01:00
|
|
|
else
|
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
CreateGUIMessage("system", "error", std::time(nullptr), "text", wstring_from_utf8(g_L10n.Translate("unknown subtype (see logs)")));
|
2017-08-28 19:47:43 +02:00
|
|
|
LOGMESSAGE("unknown subtype '%s'", tag_name(iq).c_str());
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
2019-09-12 19:23:33 +02:00
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update local data when a user changes presence.
|
|
|
|
*/
|
2019-09-13 17:24:44 +02:00
|
|
|
void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::MUCRoomParticipant participant, const glooxwrapper::Presence& presence)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
const glooxwrapper::string& nick = participant.nick->resource();
|
2017-05-05 03:13:12 +02:00
|
|
|
|
2019-09-12 19:23:33 +02:00
|
|
|
if (presence.presence() == gloox::Presence::Unavailable)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
|
|
|
if (!participant.newNick.empty() && (participant.flags & (gloox::UserNickChanged | gloox::UserSelf)))
|
|
|
|
{
|
|
|
|
// we have a nick change
|
2019-09-12 19:23:33 +02: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 12:16:46 +01:00
|
|
|
}
|
|
|
|
else if (participant.flags & gloox::UserKicked)
|
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
DbgXMPP(nick << " was kicked. Reason: " << participant.reason);
|
|
|
|
CreateGUIMessage(
|
|
|
|
"chat",
|
|
|
|
"kicked",
|
|
|
|
std::time(nullptr),
|
|
|
|
"nick", nick,
|
|
|
|
"reason", participant.reason);
|
2017-02-28 12:16:46 +01:00
|
|
|
}
|
|
|
|
else if (participant.flags & gloox::UserBanned)
|
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
DbgXMPP(nick << " was banned. Reason: " << participant.reason);
|
|
|
|
CreateGUIMessage(
|
|
|
|
"chat",
|
|
|
|
"banned",
|
|
|
|
std::time(nullptr),
|
|
|
|
"nick", nick,
|
|
|
|
"reason", participant.reason);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
else
|
2017-02-28 12:16:46 +01:00
|
|
|
{
|
2017-07-31 18:33:14 +02:00
|
|
|
DbgXMPP(nick << " left the room (flags " << participant.flags << ")");
|
2019-09-12 19:23:33 +02:00
|
|
|
CreateGUIMessage(
|
|
|
|
"chat",
|
|
|
|
"leave",
|
|
|
|
std::time(nullptr),
|
|
|
|
"nick", nick);
|
2017-02-28 12:16:46 +01:00
|
|
|
}
|
2013-11-07 21:07:24 +01:00
|
|
|
m_PlayerMap.erase(nick);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
const PlayerMap::iterator it = m_PlayerMap.find(nick);
|
|
|
|
|
2019-04-07 18:06:10 +02:00
|
|
|
/* During the initialization process, we receive join messages for everyone
|
2015-08-30 14:56:48 +02: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 19:23:33 +02:00
|
|
|
if (m_mucRoom->nick() == nick)
|
2015-08-30 14:56:48 +02:00
|
|
|
m_initialLoadComplete = true;
|
|
|
|
}
|
2019-09-12 19:23:33 +02: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,
|
|
|
|
"newrole", participant.role);
|
|
|
|
}
|
2013-11-07 21:07:24 +01:00
|
|
|
else
|
2019-09-11 13:51:34 +02:00
|
|
|
{
|
2019-09-06 04:53:22 +02: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 13:51:34 +02:00
|
|
|
}
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2019-09-12 19:23:33 +02: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 21:07:24 +01:00
|
|
|
}
|
2019-09-11 13:51:34 +02:00
|
|
|
|
|
|
|
m_PlayerMapUpdate = true;
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
2014-01-24 19:20:15 +01:00
|
|
|
/**
|
|
|
|
* Update local cache when subject changes.
|
|
|
|
*/
|
2019-09-13 17:24:44 +02:00
|
|
|
void XmppClient::handleMUCSubject(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::string& nick, const glooxwrapper::string& subject)
|
2014-01-24 19:20:15 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
m_Subject = wstring_from_utf8(subject.to_string());
|
|
|
|
|
|
|
|
CreateGUIMessage(
|
|
|
|
"chat",
|
|
|
|
"subject",
|
|
|
|
std::time(nullptr),
|
|
|
|
"nick", nick,
|
|
|
|
"subject", m_Subject);
|
2014-01-24 19:20:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current subject.
|
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
const std::wstring& XmppClient::GetSubject()
|
2014-01-24 19:20:15 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
return m_Subject;
|
2014-01-24 19:20:15 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
/**
|
|
|
|
* Request nick change, real change via mucRoomHandler.
|
|
|
|
*
|
|
|
|
* @param nick Desired nickname
|
|
|
|
*/
|
|
|
|
void XmppClient::SetNick(const std::string& nick)
|
|
|
|
{
|
|
|
|
m_mucRoom->setNick(nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current nickname.
|
|
|
|
*/
|
2021-05-09 14:51:32 +02:00
|
|
|
std::string XmppClient::GetNick() const
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2021-03-02 21:01:14 +01:00
|
|
|
return m_mucRoom->nick().to_string();
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
2021-05-09 14:51:32 +02:00
|
|
|
std::string XmppClient::GetJID() const
|
|
|
|
{
|
|
|
|
return m_client->getJID().to_string();
|
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01: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)
|
|
|
|
{
|
|
|
|
m_mucRoom->kick(nick, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
m_mucRoom->ban(nick, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the xmpp presence of the client.
|
|
|
|
*
|
|
|
|
* @param presence A string containing the desired presence
|
|
|
|
*/
|
|
|
|
void XmppClient::SetPresence(const std::string& presence)
|
|
|
|
{
|
|
|
|
#define IF(x,y) if (presence == x) m_mucRoom->setPresence(gloox::Presence::y)
|
|
|
|
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 21:36:24 +01:00
|
|
|
else LOGERROR("Unknown presence '%s'", presence.c_str());
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current xmpp presence of the given nick.
|
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
const char* XmppClient::GetPresence(const std::string& nick)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
const PlayerMap::iterator it = m_PlayerMap.find(nick);
|
|
|
|
|
|
|
|
if (it == m_PlayerMap.end())
|
|
|
|
return "offline";
|
|
|
|
|
|
|
|
return GetPresenceString(it->second.m_Presence);
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
2014-04-13 01:40:36 +02:00
|
|
|
/**
|
|
|
|
* Get the current xmpp role of the given nick.
|
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
const char* XmppClient::GetRole(const std::string& nick)
|
2014-04-13 01:40:36 +02:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
const PlayerMap::iterator it = m_PlayerMap.find(nick);
|
|
|
|
|
|
|
|
if (it == m_PlayerMap.end())
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return GetRoleString(it->second.m_Role);
|
2014-04-13 01:40:36 +02: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 14:44:41 +01: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)
|
|
|
|
{
|
|
|
|
const PlayerMap::iterator it = m_PlayerMap.find(nick);
|
|
|
|
|
|
|
|
if (it == m_PlayerMap.end())
|
|
|
|
return std::wstring();
|
|
|
|
|
|
|
|
return wstring_from_utf8(it->second.m_Rating.to_string());
|
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
/*****************************************************
|
|
|
|
* Utilities *
|
|
|
|
*****************************************************/
|
|
|
|
|
2017-06-18 20:48:18 +02:00
|
|
|
/**
|
2017-08-24 22:57:21 +02: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.
|
2017-06-18 20:48:18 +02:00
|
|
|
*
|
|
|
|
* @returns Seconds since the epoch.
|
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
std::time_t XmppClient::ComputeTimestamp(const glooxwrapper::Message& msg)
|
2017-06-18 20:48:18 +02:00
|
|
|
{
|
|
|
|
// Only historic messages contain a timestamp!
|
|
|
|
if (!msg.when())
|
|
|
|
return std::time(nullptr);
|
|
|
|
|
2017-08-24 22:57:21 +02:00
|
|
|
// The locale is irrelevant, because the XMPP date format doesn't contain written month names
|
2018-01-06 17:09:10 +01:00
|
|
|
for (const std::string& format : std::vector<std::string>{ "Y-M-d'T'H:m:sZ", "Y-M-d'T'H:m:s.SZ" })
|
|
|
|
{
|
2018-04-10 20:13:32 +02:00
|
|
|
UDate dateTime = g_L10n.ParseDateTime(msg.when()->stamp().to_string(), format, icu::Locale::getUS());
|
2018-01-06 17:09:10 +01:00
|
|
|
if (dateTime)
|
|
|
|
return dateTime / 1000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::time(nullptr);
|
2017-06-18 20:48:18 +02:00
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
/**
|
2019-09-12 19:23:33 +02:00
|
|
|
* Convert a gloox presence type to an untranslated string literal to be used as an identifier by the scripts.
|
2013-11-07 21:07:24 +01:00
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
const char* XmppClient::GetPresenceString(const gloox::Presence::PresenceType presenceType)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
switch (presenceType)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
#define CASE(X,Y) case gloox::Presence::X: return Y
|
2013-11-07 21:07:24 +01:00
|
|
|
CASE(Available, "available");
|
|
|
|
CASE(Chat, "chat");
|
|
|
|
CASE(Away, "away");
|
|
|
|
CASE(DND, "playing");
|
2015-12-02 15:41:32 +01:00
|
|
|
CASE(XA, "away");
|
2013-11-07 21:07:24 +01:00
|
|
|
CASE(Unavailable, "offline");
|
|
|
|
CASE(Probe, "probe");
|
|
|
|
CASE(Error, "error");
|
|
|
|
CASE(Invalid, "invalid");
|
|
|
|
default:
|
2019-09-12 19:23:33 +02:00
|
|
|
LOGERROR("Unknown presence type '%d'", static_cast<int>(presenceType));
|
|
|
|
return "";
|
2013-11-07 21:07:24 +01:00
|
|
|
#undef CASE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 16:46:19 +01:00
|
|
|
/**
|
2019-09-12 19:23:33 +02:00
|
|
|
* Convert a gloox role type to an untranslated string literal to be used as an identifier by the scripts.
|
2014-01-30 16:46:19 +01:00
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
const char* XmppClient::GetRoleString(const gloox::MUCRoomRole role)
|
2014-01-30 16:46:19 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
switch (role)
|
2014-01-30 16:46:19 +01:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
#define CASE(X, Y) case gloox::X: return Y
|
2014-01-30 16:46:19 +01:00
|
|
|
CASE(RoleNone, "none");
|
|
|
|
CASE(RoleVisitor, "visitor");
|
|
|
|
CASE(RoleParticipant, "participant");
|
|
|
|
CASE(RoleModerator, "moderator");
|
|
|
|
CASE(RoleInvalid, "invalid");
|
|
|
|
default:
|
2019-09-12 19:23:33 +02:00
|
|
|
LOGERROR("Unknown role type '%d'", static_cast<int>(role));
|
|
|
|
return "";
|
2014-01-30 16:46:19 +01:00
|
|
|
#undef CASE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 19:50:08 +02:00
|
|
|
/**
|
|
|
|
* Translates a gloox certificate error codes, i.e. gloox certificate statuses except CertOk.
|
|
|
|
* Keep in sync with specifications.
|
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
std::string XmppClient::CertificateErrorToString(gloox::CertStatus status)
|
2018-10-09 19:50:08 +02:00
|
|
|
{
|
|
|
|
std::map<gloox::CertStatus, std::string> certificateErrorStrings = {
|
2019-09-09 16:33:30 +02:00
|
|
|
{ gloox::CertInvalid, g_L10n.Translate("The certificate is not trusted.") },
|
|
|
|
{ gloox::CertSignerUnknown, g_L10n.Translate("The certificate hasn't got a known issuer.") },
|
|
|
|
{ gloox::CertRevoked, g_L10n.Translate("The certificate has been revoked.") },
|
|
|
|
{ gloox::CertExpired, g_L10n.Translate("The certificate has expired.") },
|
2020-05-21 12:15:26 +02:00
|
|
|
{ gloox::CertNotActive, g_L10n.Translate("The certificate is not yet active.") },
|
2019-09-09 16:33:30 +02:00
|
|
|
{ gloox::CertWrongPeer, g_L10n.Translate("The certificate has not been issued for the peer connected to.") },
|
|
|
|
{ gloox::CertSignerNotCa, g_L10n.Translate("The certificate signer is not a certificate authority.") }
|
2018-10-09 19:50:08 +02:00
|
|
|
};
|
|
|
|
|
2019-09-09 23:26:58 +02:00
|
|
|
std::string result;
|
2018-10-09 19:50:08 +02:00
|
|
|
|
|
|
|
for (std::map<gloox::CertStatus, std::string>::iterator it = certificateErrorStrings.begin(); it != certificateErrorStrings.end(); ++it)
|
|
|
|
if (status & it->first)
|
|
|
|
result += "\n" + it->second;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
/**
|
|
|
|
* Convert a gloox stanza error type to string.
|
2016-01-01 19:38:50 +01:00
|
|
|
* Keep in sync with Gloox documentation
|
2013-11-07 21:07:24 +01:00
|
|
|
*
|
|
|
|
* @param err Error to be converted
|
|
|
|
* @return Converted error string
|
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
std::string XmppClient::StanzaErrorToString(gloox::StanzaError err)
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
|
|
|
#define CASE(X, Y) case gloox::X: return Y
|
2016-01-01 19:38:50 +01:00
|
|
|
#define DEBUG_CASE(X, Y) case gloox::X: return g_L10n.Translate("Error") + " (" + Y + ")"
|
2013-11-07 21:07:24 +01:00
|
|
|
switch (err)
|
|
|
|
{
|
2016-01-01 19:38:50 +01:00
|
|
|
CASE(StanzaErrorUndefined, g_L10n.Translate("No error"));
|
2017-10-29 00:34:57 +02:00
|
|
|
DEBUG_CASE(StanzaErrorBadRequest, "Server received malformed XML");
|
2016-01-01 19:38:50 +01:00
|
|
|
CASE(StanzaErrorConflict, g_L10n.Translate("Player already logged in"));
|
|
|
|
DEBUG_CASE(StanzaErrorFeatureNotImplemented, "Server does not implement requested feature");
|
2014-11-13 02:26:36 +01:00
|
|
|
CASE(StanzaErrorForbidden, g_L10n.Translate("Forbidden"));
|
2016-01-01 19:38:50 +01:00
|
|
|
DEBUG_CASE(StanzaErrorGone, "Unable to find message receipiant");
|
2014-11-13 02:26:36 +01:00
|
|
|
CASE(StanzaErrorInternalServerError, g_L10n.Translate("Internal server error"));
|
2016-01-01 19:38:50 +01:00
|
|
|
DEBUG_CASE(StanzaErrorItemNotFound, "Message receipiant does not exist");
|
|
|
|
DEBUG_CASE(StanzaErrorJidMalformed, "JID (XMPP address) malformed");
|
|
|
|
DEBUG_CASE(StanzaErrorNotAcceptable, "Receipiant refused message. Possible policy issue");
|
2014-11-13 02:26:36 +01:00
|
|
|
CASE(StanzaErrorNotAllowed, g_L10n.Translate("Not allowed"));
|
|
|
|
CASE(StanzaErrorNotAuthorized, g_L10n.Translate("Not authorized"));
|
2016-01-01 19:38:50 +01:00
|
|
|
DEBUG_CASE(StanzaErrorNotModified, "Requested item has not changed since last request");
|
|
|
|
DEBUG_CASE(StanzaErrorPaymentRequired, "This server requires payment");
|
|
|
|
CASE(StanzaErrorRecipientUnavailable, g_L10n.Translate("Recipient temporarily unavailable"));
|
|
|
|
DEBUG_CASE(StanzaErrorRedirect, "Request redirected");
|
2014-11-13 02:26:36 +01:00
|
|
|
CASE(StanzaErrorRegistrationRequired, g_L10n.Translate("Registration required"));
|
2016-01-01 19:38:50 +01:00
|
|
|
DEBUG_CASE(StanzaErrorRemoteServerNotFound, "Remote server not found");
|
|
|
|
DEBUG_CASE(StanzaErrorRemoteServerTimeout, "Remote server timed out");
|
|
|
|
DEBUG_CASE(StanzaErrorResourceConstraint, "The recipient is unable to process the message due to resource constraints");
|
2014-11-13 02:26:36 +01:00
|
|
|
CASE(StanzaErrorServiceUnavailable, g_L10n.Translate("Service unavailable"));
|
2016-01-01 19:38:50 +01:00
|
|
|
DEBUG_CASE(StanzaErrorSubscribtionRequired, "Service requires subscription");
|
|
|
|
DEBUG_CASE(StanzaErrorUnexpectedRequest, "Attempt to send from invalid stanza address");
|
|
|
|
DEBUG_CASE(StanzaErrorUnknownSender, "Invalid 'from' address");
|
2013-11-07 21:07:24 +01:00
|
|
|
default:
|
2016-01-01 19:38:50 +01:00
|
|
|
return g_L10n.Translate("Unknown error");
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
2016-01-01 19:38:50 +01:00
|
|
|
#undef DEBUG_CASE
|
2013-11-07 21:07:24 +01:00
|
|
|
#undef CASE
|
|
|
|
}
|
2016-01-01 18:18:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a gloox connection error enum to string
|
|
|
|
* Keep in sync with Gloox documentation
|
2016-11-23 14:02:58 +01:00
|
|
|
*
|
2016-01-01 18:18:17 +01:00
|
|
|
* @param err Error to be converted
|
|
|
|
* @return Converted error string
|
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
std::string XmppClient::ConnectionErrorToString(gloox::ConnectionError err)
|
2016-01-01 18:18:17 +01:00
|
|
|
{
|
|
|
|
#define CASE(X, Y) case gloox::X: return Y
|
2016-01-01 19:38:50 +01:00
|
|
|
#define DEBUG_CASE(X, Y) case gloox::X: return g_L10n.Translate("Error") + " (" + Y + ")"
|
2016-01-01 18:18:17 +01:00
|
|
|
switch (err)
|
|
|
|
{
|
|
|
|
CASE(ConnNoError, g_L10n.Translate("No error"));
|
|
|
|
CASE(ConnStreamError, g_L10n.Translate("Stream error"));
|
|
|
|
CASE(ConnStreamVersionError, g_L10n.Translate("The incoming stream version is unsupported"));
|
|
|
|
CASE(ConnStreamClosed, g_L10n.Translate("The stream has been closed by the server"));
|
2016-01-01 19:38:50 +01:00
|
|
|
DEBUG_CASE(ConnProxyAuthRequired, "The HTTP/SOCKS5 proxy requires authentication");
|
|
|
|
DEBUG_CASE(ConnProxyAuthFailed, "HTTP/SOCKS5 proxy authentication failed");
|
|
|
|
DEBUG_CASE(ConnProxyNoSupportedAuth, "The HTTP/SOCKS5 proxy requires an unsupported authentication mechanism");
|
2017-10-29 00:34:57 +02:00
|
|
|
CASE(ConnIoError, g_L10n.Translate("An I/O error occurred"));
|
|
|
|
DEBUG_CASE(ConnParseError, "An XML parse error occurred");
|
2016-01-01 18:18:17 +01:00
|
|
|
CASE(ConnConnectionRefused, g_L10n.Translate("The connection was refused by the server"));
|
|
|
|
CASE(ConnDnsError, g_L10n.Translate("Resolving the server's hostname failed"));
|
|
|
|
CASE(ConnOutOfMemory, g_L10n.Translate("This system is out of memory"));
|
2016-01-01 19:38:50 +01:00
|
|
|
DEBUG_CASE(ConnNoSupportedAuth, "The authentication mechanisms the server offered are not supported or no authentication mechanisms were available");
|
2019-09-09 23:26:58 +02:00
|
|
|
CASE(ConnTlsFailed, g_L10n.Translate("The server's certificate could not be verified or the TLS handshake did not complete successfully"));
|
2016-01-04 18:05:43 +01:00
|
|
|
CASE(ConnTlsNotAvailable, g_L10n.Translate("The server did not offer required TLS encryption"));
|
2016-01-01 19:38:50 +01:00
|
|
|
DEBUG_CASE(ConnCompressionFailed, "Negotiation/initializing compression failed");
|
2016-01-01 18:18:17 +01:00
|
|
|
CASE(ConnAuthenticationFailed, g_L10n.Translate("Authentication failed. Incorrect password or account does not exist"));
|
|
|
|
CASE(ConnUserDisconnected, g_L10n.Translate("The user or system requested a disconnect"));
|
|
|
|
CASE(ConnNotConnected, g_L10n.Translate("There is no active connection"));
|
|
|
|
default:
|
2016-01-01 19:38:50 +01:00
|
|
|
return g_L10n.Translate("Unknown error");
|
|
|
|
}
|
|
|
|
#undef DEBUG_CASE
|
|
|
|
#undef CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a gloox registration result enum to string
|
|
|
|
* Keep in sync with Gloox documentation
|
2016-11-23 14:02:58 +01:00
|
|
|
*
|
2016-01-01 19:38:50 +01:00
|
|
|
* @param err Enum to be converted
|
|
|
|
* @return Converted string
|
|
|
|
*/
|
2019-09-12 19:23:33 +02:00
|
|
|
std::string XmppClient::RegistrationResultToString(gloox::RegistrationResult res)
|
2016-01-01 19:38:50 +01:00
|
|
|
{
|
|
|
|
#define CASE(X, Y) case gloox::X: return Y
|
|
|
|
#define DEBUG_CASE(X, Y) case gloox::X: return g_L10n.Translate("Error") + " (" + Y + ")"
|
|
|
|
switch (res)
|
|
|
|
{
|
2018-01-07 01:10:14 +01:00
|
|
|
CASE(RegistrationSuccess, g_L10n.Translate("Your account has been successfully registered"));
|
2016-01-04 18:58:28 +01:00
|
|
|
CASE(RegistrationNotAcceptable, g_L10n.Translate("Not all necessary information provided"));
|
|
|
|
CASE(RegistrationConflict, g_L10n.Translate("Username already exists"));
|
2016-01-04 18:05:39 +01:00
|
|
|
DEBUG_CASE(RegistrationNotAuthorized, "Account removal timeout or insufficiently secure channel for password change");
|
2017-10-29 00:34:57 +02:00
|
|
|
DEBUG_CASE(RegistrationBadRequest, "Server received an incomplete request");
|
2017-05-14 05:18:21 +02:00
|
|
|
DEBUG_CASE(RegistrationForbidden, "Registration forbidden");
|
2016-01-04 18:05:39 +01:00
|
|
|
DEBUG_CASE(RegistrationRequired, "Account cannot be removed as it does not exist");
|
|
|
|
DEBUG_CASE(RegistrationUnexpectedRequest, "This client is unregistered with the server");
|
|
|
|
DEBUG_CASE(RegistrationNotAllowed, "Server does not permit password changes");
|
|
|
|
default:
|
2017-02-07 16:05:26 +01:00
|
|
|
return "";
|
2016-01-01 18:18:17 +01:00
|
|
|
}
|
2016-01-01 19:38:50 +01:00
|
|
|
#undef DEBUG_CASE
|
2016-01-01 18:18:17 +01:00
|
|
|
#undef CASE
|
|
|
|
}
|
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-06-01 08:33:52 +02:00
|
|
|
|
2021-05-17 17:14:10 +02: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-06-01 08:33:52 +02:00
|
|
|
{
|
2019-09-12 19:23:33 +02:00
|
|
|
DbgXMPP("SendStunEndpointToHost " << 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-06-01 08:33:52 +02:00
|
|
|
glooxwrapper::JID hostJID(hostJIDStr);
|
|
|
|
glooxwrapper::Jingle::Session session = m_sessionManager->createSession(hostJID);
|
2021-05-17 17:14:10 +02:00
|
|
|
session.sessionInitiate(ip.c_str(), 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-06-01 08:33:52 +02:00
|
|
|
}
|
|
|
|
|
2019-08-17 02:12:19 +02:00
|
|
|
void XmppClient::handleSessionAction(gloox::Jingle::Action action, glooxwrapper::Jingle::Session& session, const glooxwrapper::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-06-01 08:33:52 +02:00
|
|
|
{
|
|
|
|
if (action == gloox::Jingle::SessionInitiate)
|
2019-08-17 02:12:19 +02: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-06-01 08:33:52 +02:00
|
|
|
}
|
|
|
|
|
2019-08-17 02:12:19 +02:00
|
|
|
void XmppClient::handleSessionInitiation(glooxwrapper::Jingle::Session& UNUSED(session), const glooxwrapper::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-06-01 08:33:52 +02:00
|
|
|
{
|
2019-08-17 02:12:19 +02:00
|
|
|
glooxwrapper::Jingle::ICEUDP::Candidate candidate = jingle.getCandidate();
|
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-06-01 08:33:52 +02:00
|
|
|
|
|
|
|
if (candidate.ip.empty())
|
|
|
|
{
|
|
|
|
LOGERROR("Failed to retrieve Jingle candidate");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-07 23:56:05 +01:00
|
|
|
if (!g_NetServer)
|
|
|
|
{
|
|
|
|
LOGERROR("Received STUN connection request, but not hosting currently!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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-06-01 08:33:52 +02:00
|
|
|
g_NetServer->SendHolePunchingMessage(candidate.ip.to_string(), candidate.port);
|
|
|
|
}
|