2020-01-01 22:49:13 +01:00
|
|
|
/* Copyright (C) 2020 Wildfire Games.
|
2013-11-16 19:38:40 +01:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "JSInterface_Lobby.h"
|
|
|
|
|
2019-09-06 07:14:20 +02:00
|
|
|
#include "gui/GUIManager.h"
|
2013-11-16 19:38:40 +01:00
|
|
|
#include "lib/utf8.h"
|
|
|
|
#include "lobby/IXmppClient.h"
|
2018-08-25 16:34:30 +02:00
|
|
|
#include "network/NetServer.h"
|
|
|
|
#include "ps/CLogger.h"
|
2018-08-23 19:13:22 +02:00
|
|
|
#include "ps/CStr.h"
|
2018-08-08 14:59:05 +02:00
|
|
|
#include "ps/Util.h"
|
2014-11-16 03:10:24 +01:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2018-04-08 23:41:31 +02:00
|
|
|
|
2014-01-17 21:14:41 +01:00
|
|
|
#include "third_party/encryption/pkcs5_pbkdf2.h"
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2018-08-25 16:34:30 +02:00
|
|
|
#include <string>
|
|
|
|
|
2017-08-24 02:32:42 +02:00
|
|
|
void JSI_Lobby::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
|
2014-11-16 03:10:24 +01:00
|
|
|
{
|
|
|
|
// Lobby functions
|
|
|
|
scriptInterface.RegisterFunction<bool, &JSI_Lobby::HasXmppClient>("HasXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, bool, &JSI_Lobby::SetRankedGame>("SetRankedGame");
|
|
|
|
#if CONFIG2_LOBBY // Allow the lobby to be disabled
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, std::wstring, std::wstring, int, &JSI_Lobby::StartXmppClient>("StartXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::StartRegisterXmppClient>("StartRegisterXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::StopXmppClient>("StopXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::ConnectXmppClient>("ConnectXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::DisconnectXmppClient>("DisconnectXmppClient");
|
2018-01-15 05:30:33 +01:00
|
|
|
scriptInterface.RegisterFunction<bool, &JSI_Lobby::IsXmppClientConnected>("IsXmppClientConnected");
|
2014-11-16 03:10:24 +01:00
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendGetBoardList>("SendGetBoardList");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::SendGetProfile>("SendGetProfile");
|
2015-01-24 15:46:52 +01:00
|
|
|
scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendRegisterGame>("SendRegisterGame");
|
|
|
|
scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendGameReport>("SendGameReport");
|
2014-11-16 03:10:24 +01:00
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendUnregisterGame>("SendUnregisterGame");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame");
|
2015-01-24 15:46:52 +01:00
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetPlayerList>("GetPlayerList");
|
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetGameList>("GetGameList");
|
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetBoardList>("GetBoardList");
|
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetProfile>("GetProfile");
|
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
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::LobbyGuiPollNewMessages>("LobbyGuiPollNewMessages");
|
2017-08-29 18:04:45 +02:00
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::LobbyGuiPollHistoricMessages>("LobbyGuiPollHistoricMessages");
|
2019-09-11 13:51:34 +02:00
|
|
|
scriptInterface.RegisterFunction<bool, &JSI_Lobby::LobbyGuiPollHasPlayerListUpdate>("LobbyGuiPollHasPlayerListUpdate");
|
2014-11-16 03:10:24 +01:00
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySendMessage>("LobbySendMessage");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySetPlayerPresence>("LobbySetPlayerPresence");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySetNick>("LobbySetNick");
|
|
|
|
scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetNick>("LobbyGetNick");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyKick>("LobbyKick");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyBan>("LobbyBan");
|
2019-09-12 19:23:33 +02:00
|
|
|
scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerPresence>("LobbyGetPlayerPresence");
|
|
|
|
scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerRole>("LobbyGetPlayerRole");
|
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
|
|
|
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerRating>("LobbyGetPlayerRating");
|
2014-11-16 03:10:24 +01:00
|
|
|
scriptInterface.RegisterFunction<std::wstring, std::wstring, std::wstring, &JSI_Lobby::EncryptPassword>("EncryptPassword");
|
|
|
|
scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetRoomSubject>("LobbyGetRoomSubject");
|
|
|
|
#endif // CONFIG2_LOBBY
|
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
bool JSI_Lobby::HasXmppClient(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
2017-02-28 12:16:46 +01:00
|
|
|
return g_XmppClient;
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::SetRankedGame(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), bool isRanked)
|
2014-04-16 08:03:49 +02:00
|
|
|
{
|
|
|
|
g_rankedGame = isRanked;
|
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
#if CONFIG2_LOBBY
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::StartXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& username, const std::wstring& password, const std::wstring& room, const std::wstring& nick, int historyRequestSize)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
2020-01-01 22:49:13 +01:00
|
|
|
if (g_XmppClient)
|
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call StartXmppClient with an already initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_XmppClient =
|
|
|
|
IXmppClient::create(
|
|
|
|
g_GUI->GetScriptInterface().get(),
|
|
|
|
utf8_from_wstring(username),
|
|
|
|
utf8_from_wstring(password),
|
|
|
|
utf8_from_wstring(room),
|
|
|
|
utf8_from_wstring(nick),
|
|
|
|
historyRequestSize);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
|
|
|
g_rankedGame = true;
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::StartRegisterXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& username, const std::wstring& password)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
2020-01-01 22:49:13 +01:00
|
|
|
if (g_XmppClient)
|
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call StartRegisterXmppClient with an already initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2020-01-01 22:49:13 +01:00
|
|
|
g_XmppClient =
|
|
|
|
IXmppClient::create(
|
|
|
|
g_GUI->GetScriptInterface().get(),
|
|
|
|
utf8_from_wstring(username),
|
|
|
|
utf8_from_wstring(password),
|
|
|
|
std::string(),
|
|
|
|
std::string(),
|
|
|
|
0,
|
|
|
|
true);
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::StopXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call StopXmppClient without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
SAFE_DELETE(g_XmppClient);
|
|
|
|
g_rankedGame = false;
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::ConnectXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call ConnectXmppClient without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
g_XmppClient->connect();
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::DisconnectXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call DisconnectXmppClient without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
g_XmppClient->disconnect();
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
bool JSI_Lobby::IsXmppClientConnected(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2018-01-15 05:30:33 +01:00
|
|
|
{
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call IsXmppClientConnected without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-15 05:30:33 +01:00
|
|
|
return g_XmppClient->isConnected();
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::SendGetBoardList(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call SendGetBoardList without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
g_XmppClient->SendIqGetBoardList();
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::SendGetProfile(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& player)
|
2014-09-20 17:35:26 +02:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call SendGetProfile without an initialized XmppClient!");
|
2014-09-20 17:35:26 +02:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
g_XmppClient->SendIqGetProfile(utf8_from_wstring(player));
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::SendGameReport(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue data)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call SendGameReport without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
g_XmppClient->SendIqGameReport(*(pCmptPrivate->pScriptInterface), data);
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::SendRegisterGame(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue data)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call SendRegisterGame without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2014-01-04 11:14:53 +01:00
|
|
|
|
2018-08-25 16:34:30 +02:00
|
|
|
// Prevent JS mods to register matches in the lobby that were started with lobby authentication disabled
|
|
|
|
if (!g_NetServer || !g_NetServer->UseLobbyAuth())
|
|
|
|
{
|
|
|
|
LOGERROR("Registering games in the lobby requires lobby authentication to be enabled!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
g_XmppClient->SendIqRegisterGame(*(pCmptPrivate->pScriptInterface), data);
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::SendUnregisterGame(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call SendUnregisterGame without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
g_XmppClient->SendIqUnregisterGame();
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::SendChangeStateGame(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nbp, const std::wstring& players)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call SendChangeStateGame without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players));
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
JS::Value JSI_Lobby::GetPlayerList(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
2016-11-23 15:09:58 +01:00
|
|
|
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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
|
|
|
ScriptException::Raise(rq, "Cannot call GetPlayerList without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue playerList(rq.cx);
|
2020-11-13 17:44:15 +01:00
|
|
|
g_XmppClient->GUIGetPlayerList(*(pCmptPrivate->pScriptInterface), &playerList);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
return playerList;
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
JS::Value JSI_Lobby::GetGameList(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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
|
|
|
ScriptException::Raise(rq, "Cannot call GetGameList without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue gameList(rq.cx);
|
2020-11-13 17:44:15 +01:00
|
|
|
g_XmppClient->GUIGetGameList(*(pCmptPrivate->pScriptInterface), &gameList);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
return gameList;
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
JS::Value JSI_Lobby::GetBoardList(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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
|
|
|
ScriptException::Raise(rq, "Cannot call GetBoardList without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue boardList(rq.cx);
|
2020-11-13 17:44:15 +01:00
|
|
|
g_XmppClient->GUIGetBoardList(*(pCmptPrivate->pScriptInterface), &boardList);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
return boardList;
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
JS::Value JSI_Lobby::GetProfile(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2014-09-20 17:35:26 +02:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
2014-09-20 17:35:26 +02:00
|
|
|
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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
|
|
|
ScriptException::Raise(rq, "Cannot call GetProfile without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue profileFetch(rq.cx);
|
2020-11-13 17:44:15 +01:00
|
|
|
g_XmppClient->GUIGetProfile(*(pCmptPrivate->pScriptInterface), &profileFetch);
|
2015-01-24 15:46:52 +01:00
|
|
|
|
|
|
|
return profileFetch;
|
2014-09-20 17:35:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
bool JSI_Lobby::LobbyGuiPollHasPlayerListUpdate(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2019-09-06 04:53:22 +02:00
|
|
|
{
|
2020-01-01 22:49:13 +01:00
|
|
|
if (!g_XmppClient)
|
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyGuiPollHasPlayerListUpdate without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_XmppClient->GuiPollHasPlayerListUpdate();
|
2019-09-06 04:53:22 +02:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
JS::Value JSI_Lobby::LobbyGuiPollNewMessages(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2015-01-24 15:46:52 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
return g_XmppClient->GuiPollNewMessages(*(pCmptPrivate->pScriptInterface));
|
2017-08-29 18:04:45 +02:00
|
|
|
}
|
2016-11-23 15:09:58 +01:00
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
JS::Value JSI_Lobby::LobbyGuiPollHistoricMessages(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2017-08-29 18:04:45 +02:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyGuiPollHistoricMessages without an initialized XmppClient!");
|
2017-08-29 18:04:45 +02:00
|
|
|
return JS::UndefinedValue();
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
return g_XmppClient->GuiPollHistoricMessages(*(pCmptPrivate->pScriptInterface));
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::LobbySendMessage(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& message)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbySendMessage without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2016-11-23 15:09:58 +01:00
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
g_XmppClient->SendMUCMessage(utf8_from_wstring(message));
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::LobbySetPlayerPresence(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& presence)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbySetPlayerPresence without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
|
|
|
g_XmppClient->SetPresence(utf8_from_wstring(presence));
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::LobbySetNick(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nick)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbySetNick without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
|
|
|
g_XmppClient->SetNick(utf8_from_wstring(nick));
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
std::wstring JSI_Lobby::LobbyGetNick(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyGetNick without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return std::wstring();
|
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
|
|
|
std::string nick;
|
|
|
|
g_XmppClient->GetNick(nick);
|
|
|
|
return wstring_from_utf8(nick);
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::LobbyKick(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nick, const std::wstring& reason)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyKick without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
|
|
|
g_XmppClient->kick(utf8_from_wstring(nick), utf8_from_wstring(reason));
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
void JSI_Lobby::LobbyBan(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nick, const std::wstring& reason)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyBan without an initialized XmppClient!");
|
2013-11-16 19:38:40 +01:00
|
|
|
return;
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
|
|
|
g_XmppClient->ban(utf8_from_wstring(nick), utf8_from_wstring(reason));
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
const char* JSI_Lobby::LobbyGetPlayerPresence(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nickname)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyGetPlayerPresence without an initialized XmppClient!");
|
2019-09-12 19:23:33 +02:00
|
|
|
return "";
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2019-09-12 19:23:33 +02:00
|
|
|
return g_XmppClient->GetPresence(utf8_from_wstring(nickname));
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
const char* JSI_Lobby::LobbyGetPlayerRole(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nickname)
|
2014-04-13 01:40:36 +02:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyGetPlayerRole without an initialized XmppClient!");
|
2019-09-12 19:23:33 +02:00
|
|
|
return "";
|
2020-01-01 22:49:13 +01:00
|
|
|
}
|
2014-04-13 01:40:36 +02:00
|
|
|
|
2019-09-12 19:23:33 +02:00
|
|
|
return g_XmppClient->GetRole(utf8_from_wstring(nickname));
|
2014-04-13 01:40:36 +02:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
std::wstring JSI_Lobby::LobbyGetPlayerRating(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nickname)
|
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 (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyGetPlayerRating without an initialized XmppClient!");
|
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
|
|
|
return std::wstring();
|
2020-01-01 22:49:13 +01: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
|
|
|
|
|
|
|
return g_XmppClient->GetRating(utf8_from_wstring(nickname));
|
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
// Non-public secure PBKDF2 hash function with salting and 1,337 iterations
|
2018-04-08 23:41:31 +02:00
|
|
|
//
|
|
|
|
// TODO: We should use libsodium's crypto_pwhash instead of this. The first reason is that
|
|
|
|
// libsodium doesn't propose a bare PBKDF2 hash in its API and it's too bad to rely on custom
|
|
|
|
// code when we have a fully-fledged library available; the second reason is that Argon2 (the
|
|
|
|
// default algorithm for crypto_pwhash) is better than what we use (and it's the default one
|
|
|
|
// in the lib for a reason).
|
|
|
|
// However changing the hashing method should be planned carefully, by trying to login with a
|
|
|
|
// password hashed the old way, and, if successful, updating the password in the database using
|
|
|
|
// the new hashing method. Dropping the old hashing code can only be done either by giving users
|
|
|
|
// a way to reset their password, or by keeping track of successful password updates and dropping
|
|
|
|
// old unused accounts after some time.
|
2013-11-16 19:38:40 +01:00
|
|
|
std::string JSI_Lobby::EncryptPassword(const std::string& password, const std::string& username)
|
|
|
|
{
|
2018-04-08 23:41:31 +02:00
|
|
|
ENSURE(sodium_init() >= 0);
|
|
|
|
|
|
|
|
const int DIGESTSIZE = crypto_hash_sha256_BYTES;
|
2013-11-16 19:38:40 +01:00
|
|
|
const int ITERATIONS = 1337;
|
|
|
|
|
2018-04-08 23:41:31 +02:00
|
|
|
cassert(DIGESTSIZE == 32);
|
|
|
|
|
2013-12-14 17:22:48 +01:00
|
|
|
static const unsigned char salt_base[DIGESTSIZE] = {
|
2013-11-16 19:38:40 +01:00
|
|
|
244, 243, 249, 244, 32, 33, 34, 35, 10, 11, 12, 13, 14, 15, 16, 17,
|
|
|
|
18, 19, 20, 32, 33, 244, 224, 127, 129, 130, 140, 153, 133, 123, 234, 123 };
|
|
|
|
|
|
|
|
// initialize the salt buffer
|
2013-12-14 17:22:48 +01:00
|
|
|
unsigned char salt_buffer[DIGESTSIZE] = {0};
|
2018-04-08 23:41:31 +02:00
|
|
|
crypto_hash_sha256_state state;
|
|
|
|
crypto_hash_sha256_init(&state);
|
|
|
|
|
|
|
|
crypto_hash_sha256_update(&state, salt_base, sizeof(salt_base));
|
|
|
|
crypto_hash_sha256_update(&state, (unsigned char*)username.c_str(), username.length());
|
|
|
|
|
|
|
|
crypto_hash_sha256_final(&state, salt_buffer);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
|
|
|
// PBKDF2 to create the buffer
|
2013-12-14 17:22:48 +01:00
|
|
|
unsigned char encrypted[DIGESTSIZE];
|
|
|
|
pbkdf2(encrypted, (unsigned char*)password.c_str(), password.length(), salt_buffer, DIGESTSIZE, ITERATIONS);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2018-08-23 19:13:22 +02:00
|
|
|
return CStr(Hexify(encrypted, DIGESTSIZE)).UpperCase();
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
std::wstring JSI_Lobby::EncryptPassword(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::wstring& pass, const std::wstring& user)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
return wstring_from_utf8(JSI_Lobby::EncryptPassword(utf8_from_wstring(pass), utf8_from_wstring(user)));
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:44:15 +01:00
|
|
|
std::wstring JSI_Lobby::LobbyGetRoomSubject(ScriptInterface::CmptPrivate* pCmptPrivate)
|
2014-01-24 19:20:15 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2020-01-01 22:49:13 +01:00
|
|
|
{
|
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(pCmptPrivate->pScriptInterface);
|
|
|
|
ScriptException::Raise(rq, "Cannot call LobbyGetRoomSubject without an initialized XmppClient!");
|
2020-01-01 22:49:13 +01:00
|
|
|
return std::wstring();
|
|
|
|
}
|
2014-01-24 19:20:15 +01:00
|
|
|
|
2019-09-12 19:23:33 +02:00
|
|
|
return g_XmppClient->GetSubject();
|
2014-01-24 19:20:15 +01:00
|
|
|
}
|
|
|
|
|
2013-12-14 17:22:48 +01:00
|
|
|
#endif
|