2025-01-12 00:43:01 -08:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-06-07 15:19:05 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-06-07 15:19:05 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-06-07 15:19:05 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-06-07 15:19:05 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "lib/self_test.h"
|
|
|
|
|
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "lib/debug.h"
|
2010-08-10 14:49:33 -07:00
|
|
|
#include "lib/external_libraries/enet.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "lib/file/file_system.h"
|
|
|
|
|
#include "lib/file/vfs/vfs.h"
|
|
|
|
|
#include "lib/path.h"
|
2025-08-12 11:29:24 -07:00
|
|
|
#include "lib/posix/posix_types.h"
|
2010-06-07 15:19:05 -07:00
|
|
|
#include "network/NetClient.h"
|
2016-06-13 09:56:14 -07:00
|
|
|
#include "network/NetMessage.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "network/NetServer.h"
|
2010-06-30 14:41:04 -07:00
|
|
|
#include "ps/CLogger.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "ps/CStr.h"
|
2010-06-07 15:19:05 -07:00
|
|
|
#include "ps/Filesystem.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "ps/Game.h"
|
2010-06-30 14:41:04 -07:00
|
|
|
#include "ps/Loader.h"
|
2010-06-07 15:19:05 -07:00
|
|
|
#include "ps/XML/Xeromyces.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "scriptinterface/Object.h"
|
2010-06-07 15:19:05 -07:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "scriptinterface/ScriptRequest.h"
|
2017-01-23 18:04:50 -08:00
|
|
|
#include "simulation2/system/TurnManager.h"
|
2010-06-07 15:19:05 -07:00
|
|
|
|
2025-07-06 11:15:27 -07:00
|
|
|
#include <SDL_timer.h>
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <js/RootingAPI.h>
|
|
|
|
|
#include <js/TypeDecls.h>
|
|
|
|
|
#include <js/Value.h>
|
2024-09-18 09:17:04 -07:00
|
|
|
#include <optional>
|
2025-07-06 11:15:27 -07:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2024-09-18 09:17:04 -07:00
|
|
|
|
2010-06-07 15:19:05 -07:00
|
|
|
class TestNetComms : public CxxTest::TestSuite
|
|
|
|
|
{
|
2024-09-18 09:17:04 -07:00
|
|
|
std::optional<CXeromycesEngine> xeromycesEngine;
|
|
|
|
|
|
2010-06-07 15:19:05 -07:00
|
|
|
public:
|
|
|
|
|
void setUp()
|
|
|
|
|
{
|
2017-12-10 09:33:03 -08:00
|
|
|
g_VFS = CreateVfs();
|
2021-03-23 05:46:59 -07:00
|
|
|
TS_ASSERT_OK(g_VFS->Mount(L"", DataDir() / "mods" / "public" / "", VFS_MOUNT_MUST_EXIST));
|
|
|
|
|
TS_ASSERT_OK(g_VFS->Mount(L"cache", DataDir() / "_testcache" / "", 0, VFS_MAX_PRIORITY));
|
2024-09-18 09:17:04 -07:00
|
|
|
xeromycesEngine.emplace();
|
2010-06-30 16:40:51 -07:00
|
|
|
|
|
|
|
|
enet_initialize();
|
2010-06-07 15:19:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
|
{
|
2010-06-30 16:40:51 -07:00
|
|
|
enet_deinitialize();
|
|
|
|
|
|
2024-09-18 09:17:04 -07:00
|
|
|
xeromycesEngine.reset();
|
2010-06-07 15:19:05 -07:00
|
|
|
g_VFS.reset();
|
2011-03-23 06:36:20 -07:00
|
|
|
DeleteDirectory(DataDir()/"_testcache");
|
2010-06-07 15:19:05 -07:00
|
|
|
}
|
|
|
|
|
|
2010-06-30 14:41:04 -07:00
|
|
|
bool clients_are_all(const std::vector<CNetClient*>& clients, uint state)
|
2010-06-07 15:19:05 -07:00
|
|
|
{
|
2010-06-30 14:41:04 -07:00
|
|
|
for (size_t j = 0; j < clients.size(); ++j)
|
|
|
|
|
if (clients[j]->GetCurrState() != state)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void connect(CNetServer& server, const std::vector<CNetClient*>& clients)
|
|
|
|
|
{
|
2016-06-13 09:56:14 -07:00
|
|
|
TS_ASSERT(server.SetupConnection(PS_DEFAULT_PORT));
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
for (CNetClient* client: clients)
|
|
|
|
|
{
|
2025-01-12 00:43:01 -08:00
|
|
|
client->SetupServerData("127.0.0.1", PS_DEFAULT_PORT);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
TS_ASSERT(client->SetupConnection(nullptr));
|
|
|
|
|
}
|
2010-06-30 14:41:04 -07:00
|
|
|
|
2010-06-07 15:19:05 -07:00
|
|
|
for (size_t i = 0; ; ++i)
|
|
|
|
|
{
|
2015-02-13 17:45:13 -08:00
|
|
|
// debug_printf(".");
|
2010-06-30 14:41:04 -07:00
|
|
|
for (size_t j = 0; j < clients.size(); ++j)
|
|
|
|
|
clients[j]->Poll();
|
2010-06-07 15:19:05 -07:00
|
|
|
|
2010-10-31 15:00:28 -07:00
|
|
|
if (clients_are_all(clients, NCS_PREGAME))
|
2010-06-07 15:19:05 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (i > 20)
|
|
|
|
|
{
|
|
|
|
|
TS_FAIL("connection timeout");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_Delay(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-31 15:00:28 -07:00
|
|
|
#if 0
|
2010-06-30 14:41:04 -07:00
|
|
|
void disconnect(CNetServer& server, const std::vector<CNetClient*>& clients)
|
2010-06-07 15:19:05 -07:00
|
|
|
{
|
2010-06-30 14:41:04 -07:00
|
|
|
for (size_t i = 0; ; ++i)
|
|
|
|
|
{
|
2015-02-13 17:45:13 -08:00
|
|
|
// debug_printf(".");
|
2010-06-30 14:41:04 -07:00
|
|
|
server.Poll();
|
|
|
|
|
for (size_t j = 0; j < clients.size(); ++j)
|
|
|
|
|
clients[j]->Poll();
|
|
|
|
|
|
|
|
|
|
if (server.GetState() == SERVER_STATE_UNCONNECTED && clients_are_all(clients, NCS_UNCONNECTED))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (i > 20)
|
|
|
|
|
{
|
|
|
|
|
TS_FAIL("disconnection timeout");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_Delay(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-31 15:00:28 -07:00
|
|
|
#endif
|
2010-06-30 14:41:04 -07:00
|
|
|
|
2010-10-31 15:00:28 -07:00
|
|
|
void wait(const std::vector<CNetClient*>& clients, size_t msecs)
|
2010-06-30 14:41:04 -07:00
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < msecs/10; ++i)
|
|
|
|
|
{
|
|
|
|
|
for (size_t j = 0; j < clients.size(); ++j)
|
|
|
|
|
clients[j]->Poll();
|
|
|
|
|
|
|
|
|
|
SDL_Delay(10);
|
|
|
|
|
}
|
2010-06-07 15:19:05 -07:00
|
|
|
}
|
|
|
|
|
|
2024-09-18 10:45:06 -07:00
|
|
|
// just so that cxxtestgen doesn't complain "No tests defined" if all are disabled
|
|
|
|
|
void test_dummy() {}
|
|
|
|
|
|
|
|
|
|
void DISABLED_test_basic()
|
2010-06-07 15:19:05 -07:00
|
|
|
{
|
2010-06-30 14:41:04 -07:00
|
|
|
// This doesn't actually test much, it just runs a very quick multiplayer game
|
|
|
|
|
// and prints a load of debug output so you can see if anything funny's going on
|
|
|
|
|
|
2020-11-14 02:57:50 -08:00
|
|
|
ScriptInterface scriptInterface("Engine", "Test", g_ScriptContext);
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(scriptInterface);
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2010-06-30 14:41:04 -07:00
|
|
|
TestStdoutLogger logger;
|
|
|
|
|
|
|
|
|
|
std::vector<CNetClient*> clients;
|
|
|
|
|
|
2019-08-25 04:02:55 -07:00
|
|
|
CGame client1Game(false);
|
|
|
|
|
CGame client2Game(false);
|
|
|
|
|
CGame client3Game(false);
|
2010-06-30 14:41:04 -07:00
|
|
|
|
2024-12-18 09:50:09 -08:00
|
|
|
CNetServer server{false};
|
2010-06-30 14:41:04 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue attrs(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-07 09:51:44 -07:00
|
|
|
&attrs,
|
|
|
|
|
"mapType", "scenario",
|
|
|
|
|
"map", "maps/scenarios/Saharan Oases",
|
|
|
|
|
"mapPath", "maps/scenarios/",
|
|
|
|
|
"thing", "example");
|
|
|
|
|
|
2021-03-22 03:13:27 -07:00
|
|
|
server.UpdateInitAttributes(&attrs, scriptInterface);
|
2010-06-30 14:41:04 -07:00
|
|
|
|
2021-02-27 09:44:59 -08:00
|
|
|
CNetClient client1(&client1Game);
|
|
|
|
|
CNetClient client2(&client2Game);
|
|
|
|
|
CNetClient client3(&client3Game);
|
2010-06-30 14:41:04 -07:00
|
|
|
|
|
|
|
|
clients.push_back(&client1);
|
|
|
|
|
clients.push_back(&client2);
|
|
|
|
|
clients.push_back(&client3);
|
|
|
|
|
|
|
|
|
|
connect(server, clients);
|
2015-02-13 17:49:34 -08:00
|
|
|
debug_printf("%s", client1.TestReadGuiMessages().c_str());
|
2010-06-30 14:41:04 -07:00
|
|
|
|
|
|
|
|
server.StartGame();
|
|
|
|
|
SDL_Delay(100);
|
|
|
|
|
for (size_t j = 0; j < clients.size(); ++j)
|
|
|
|
|
{
|
|
|
|
|
clients[j]->Poll();
|
|
|
|
|
TS_ASSERT_OK(LDR_NonprogressiveLoad());
|
|
|
|
|
clients[j]->LoadFinished();
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-31 15:00:28 -07:00
|
|
|
wait(clients, 100);
|
2010-06-30 14:41:04 -07:00
|
|
|
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue cmd(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-07 09:51:44 -07:00
|
|
|
&cmd,
|
|
|
|
|
"type", "debug-print",
|
|
|
|
|
"message", "[>>> client1 test sim command]\\n");
|
2010-06-30 14:41:04 -07:00
|
|
|
client1Game.GetTurnManager()->PostCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue cmd(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-07 09:51:44 -07:00
|
|
|
&cmd,
|
|
|
|
|
"type", "debug-print",
|
|
|
|
|
"message", "[>>> client2 test sim command]\\n");
|
2010-06-30 14:41:04 -07:00
|
|
|
client2Game.GetTurnManager()->PostCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-31 15:00:28 -07:00
|
|
|
wait(clients, 100);
|
2010-12-06 11:58:06 -08:00
|
|
|
client1Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client2Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client3Game.GetTurnManager()->Update(1.0f, 1);
|
2010-10-31 15:00:28 -07:00
|
|
|
wait(clients, 100);
|
2010-12-06 11:58:06 -08:00
|
|
|
client1Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client2Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client3Game.GetTurnManager()->Update(1.0f, 1);
|
2010-10-31 15:00:28 -07:00
|
|
|
wait(clients, 100);
|
2010-06-07 15:19:05 -07:00
|
|
|
}
|
2011-10-27 09:46:48 -07:00
|
|
|
|
2024-09-18 10:45:06 -07:00
|
|
|
void DISABLED_test_rejoin()
|
2011-10-27 09:46:48 -07:00
|
|
|
{
|
2020-11-14 02:57:50 -08:00
|
|
|
ScriptInterface scriptInterface("Engine", "Test", g_ScriptContext);
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(scriptInterface);
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2011-10-27 09:46:48 -07:00
|
|
|
TestStdoutLogger logger;
|
|
|
|
|
|
|
|
|
|
std::vector<CNetClient*> clients;
|
|
|
|
|
|
2019-08-25 04:02:55 -07:00
|
|
|
CGame client1Game(false);
|
|
|
|
|
CGame client2Game(false);
|
|
|
|
|
CGame client3Game(false);
|
2011-10-27 09:46:48 -07:00
|
|
|
|
2024-12-18 09:50:09 -08:00
|
|
|
CNetServer server{false};
|
2011-10-27 09:46:48 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue attrs(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-07 09:51:44 -07:00
|
|
|
&attrs,
|
|
|
|
|
"mapType", "scenario",
|
|
|
|
|
"map", "maps/scenarios/Saharan Oases",
|
|
|
|
|
"mapPath", "maps/scenarios/",
|
|
|
|
|
"thing", "example");
|
|
|
|
|
|
2021-03-22 03:13:27 -07:00
|
|
|
server.UpdateInitAttributes(&attrs, scriptInterface);
|
2011-10-27 09:46:48 -07:00
|
|
|
|
2021-02-27 09:44:59 -08:00
|
|
|
CNetClient client1(&client1Game);
|
|
|
|
|
CNetClient client2(&client2Game);
|
|
|
|
|
CNetClient client3(&client3Game);
|
2011-10-27 09:46:48 -07:00
|
|
|
|
|
|
|
|
client1.SetUserName(L"alice");
|
|
|
|
|
client2.SetUserName(L"bob");
|
|
|
|
|
client3.SetUserName(L"charlie");
|
|
|
|
|
|
|
|
|
|
clients.push_back(&client1);
|
|
|
|
|
clients.push_back(&client2);
|
|
|
|
|
clients.push_back(&client3);
|
|
|
|
|
|
|
|
|
|
connect(server, clients);
|
2015-02-13 17:49:34 -08:00
|
|
|
debug_printf("%s", client1.TestReadGuiMessages().c_str());
|
2011-10-27 09:46:48 -07:00
|
|
|
|
|
|
|
|
server.StartGame();
|
|
|
|
|
SDL_Delay(100);
|
|
|
|
|
for (size_t j = 0; j < clients.size(); ++j)
|
|
|
|
|
{
|
|
|
|
|
clients[j]->Poll();
|
|
|
|
|
TS_ASSERT_OK(LDR_NonprogressiveLoad());
|
|
|
|
|
clients[j]->LoadFinished();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wait(clients, 100);
|
|
|
|
|
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue cmd(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-07 09:51:44 -07:00
|
|
|
&cmd,
|
|
|
|
|
"type", "debug-print",
|
|
|
|
|
"message", "[>>> client1 test sim command 1]\\n");
|
|
|
|
|
|
2011-10-27 09:46:48 -07:00
|
|
|
client1Game.GetTurnManager()->PostCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wait(clients, 100);
|
|
|
|
|
client1Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client2Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client3Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
wait(clients, 100);
|
|
|
|
|
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue cmd(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-07 09:51:44 -07:00
|
|
|
&cmd,
|
|
|
|
|
"type", "debug-print",
|
|
|
|
|
"message", "[>>> client1 test sim command 2]\\n");
|
2011-10-27 09:46:48 -07:00
|
|
|
client1Game.GetTurnManager()->PostCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 17:45:13 -08:00
|
|
|
debug_printf("==== Disconnecting client 2\n");
|
2011-10-27 09:46:48 -07:00
|
|
|
|
|
|
|
|
client2.DestroyConnection();
|
|
|
|
|
clients.erase(clients.begin()+1);
|
|
|
|
|
|
2015-02-13 17:45:13 -08:00
|
|
|
debug_printf("==== Connecting client 2B\n");
|
2011-10-27 09:46:48 -07:00
|
|
|
|
2019-08-25 04:02:55 -07:00
|
|
|
CGame client2BGame(false);
|
2021-02-27 09:44:59 -08:00
|
|
|
CNetClient client2B(&client2BGame);
|
2011-10-27 09:46:48 -07:00
|
|
|
client2B.SetUserName(L"bob");
|
|
|
|
|
clients.push_back(&client2B);
|
|
|
|
|
|
2025-01-12 00:43:01 -08:00
|
|
|
client2B.SetupServerData("127.0.0.1", PS_DEFAULT_PORT);
|
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for
anyone to read. This patch consists of 3 parts.
1.) Removing ips and ports from lobby javascript
2.) Removing need of script on the server to attach public ips to game
stanza by asking the host using xmppclient as proxy.
3.) Implementing password protected matches, to deny this information to
not trusted players.
Further description:
Do not send ports and stunip to the bots.
Removed from stanza.
Do not send ip to the lobby.
Removed from mapping gamelist from backend to gui (still on the backend
side, because it is done by script on 0ad server).
Get ip and ports on request when trying to connect.
On the host side, ask stun server what is host's public ip and remember
it.
On the client side, send iq through xmppclient to the hosting player and
ask for ip, port and if Stun is used, then if answer is success,
continue
with connecting, else fail.
Add optional password for matches.
Add password required identifier to the stanza.
Allow host to setup password for the match. Hash it on the host side and
store inside Netserver. If no password is given, matches will behave
as it is not required.
On the client side, if password for the match is required, show
additional window before trying to connect and ask for password, then
hash it
and send with iq request for ip, port and stun.
Server will answer with ip, port and stun only if passwords matches,
else will asnwer with error string.
Some security:
Passwords are hashed before sending, so it is not easy to guess what
users typed. (per wraitii)
Hashes are using different salt as lobby hashing and not using usernames
as salt (as that is not doable), so they are different even typing the
same password as for the lobby account.
Client remembers which user was asked for connection data and iq's id of
request. If answer doesn't match these things, it is ignored. (thnx
user1)
Every request for connection data is logged with hostname of the
requester to the mainlog file (no ips).
If user gets iq to send connection data and is not hosting the match,
will respond with error string "not_server".
If server gets iq::result with connection data, request is ignored.
Differential revision: D3184
Reviewed by: @wraitii
Comments by: @Stan, @bb, @Imarok, @vladislavbelov
Tested in lobby
This was SVN commit r24728.
2021-01-20 10:31:39 -08:00
|
|
|
TS_ASSERT(client2B.SetupConnection(nullptr));
|
2011-10-27 09:46:48 -07:00
|
|
|
|
|
|
|
|
for (size_t i = 0; ; ++i)
|
|
|
|
|
{
|
2015-02-13 17:45:13 -08:00
|
|
|
debug_printf("[%u]\n", client2B.GetCurrState());
|
2011-10-27 09:46:48 -07:00
|
|
|
client2B.Poll();
|
|
|
|
|
if (client2B.GetCurrState() == NCS_PREGAME)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (client2B.GetCurrState() == NCS_UNCONNECTED)
|
|
|
|
|
{
|
|
|
|
|
TS_FAIL("connection rejected");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i > 20)
|
|
|
|
|
{
|
|
|
|
|
TS_FAIL("connection timeout");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_Delay(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wait(clients, 100);
|
|
|
|
|
|
|
|
|
|
client1Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client3Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
wait(clients, 100);
|
|
|
|
|
server.SetTurnLength(100);
|
|
|
|
|
client1Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client3Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
wait(clients, 100);
|
|
|
|
|
|
|
|
|
|
// (This SetTurnLength thing doesn't actually detect errors unless you change
|
2017-01-23 18:04:50 -08:00
|
|
|
// CTurnManager::TurnNeedsFullHash to always return true)
|
2011-10-27 09:46:48 -07:00
|
|
|
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue cmd(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-07 09:51:44 -07:00
|
|
|
&cmd,
|
|
|
|
|
"type", "debug-print",
|
|
|
|
|
"message", "[>>> client1 test sim command 3]\\n");
|
2011-10-27 09:46:48 -07:00
|
|
|
client1Game.GetTurnManager()->PostCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clients[2]->Poll();
|
|
|
|
|
TS_ASSERT_OK(LDR_NonprogressiveLoad());
|
|
|
|
|
clients[2]->LoadFinished();
|
|
|
|
|
|
|
|
|
|
wait(clients, 100);
|
|
|
|
|
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue cmd(rq.cx);
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-07 09:51:44 -07:00
|
|
|
&cmd,
|
|
|
|
|
"type", "debug-print",
|
|
|
|
|
"message", "[>>> client1 test sim command 4]\\n");
|
|
|
|
|
|
2011-10-27 09:46:48 -07:00
|
|
|
client1Game.GetTurnManager()->PostCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 3; ++i)
|
|
|
|
|
{
|
|
|
|
|
client1Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client2BGame.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
client3Game.GetTurnManager()->Update(1.0f, 1);
|
|
|
|
|
wait(clients, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-06-07 15:19:05 -07:00
|
|
|
};
|