1
0
forked from mirrors/0ad

461 Commits

Author SHA1 Message Date
phosit 6f82cec51f Use std::unique_ptr for stats-table 2026-04-18 14:38:38 +02:00
phosit b71c1c3e8c Use std::unique_ptr for ENetPeer 2026-04-18 14:38:38 +02:00
phosit e7a583adc0 Use std::unique_ptr for server-session 2026-04-18 14:38:38 +02:00
phosit 0642153abc Use std::unique_ptr for ENetHost 2026-04-18 14:38:38 +02:00
phosit 74255b49c0 Use std::unique_ptr for the server turn manager 2026-04-18 14:38:38 +02:00
phosit 2b1b1dc1e3 Store the server-worker inside the server
This becomes possible by reordering the class definition.
2026-04-18 14:38:38 +02:00
phosit 7758c98e7c Remove IXmppClient.h
This is now possible after 0a455fbe2d.
2026-04-14 19:38:05 +02:00
phosit d5384ad742 FindPublicIP in the CNetServer constructor
When using the lobby, after constructing `CNetServer` the public IP has
to be queried. The consructor knows whether the lobby is used, so do it
in the constructor.
2026-04-11 13:46:34 +02:00
phosit bc17e212bb Launch session at construction of Net*
This way it's statically assured that the session aren't launched
multiple times.
2026-04-11 13:46:33 +02:00
phosit 314e2a58cf Remove UpdateInitAttributes from CNetClient
The init-attributes can only be changed before the worker runs. It isn't
used before the worker runs. This changes it so that it has to be passed
when the server starts.
With this the `m_InitAttributesQueue` can be removed.
2026-04-11 13:45:00 +02:00
phosit 578aea3b09 Remove CNetClient::SetupServerData
It has to be called before `SetupConnection` is called. Now the
server-data is setup during the constructor.
When connecting using the lobby, the data isn't known at construction
time. Then it is done at the start of  `TryToConnectWithSTUN`.
2026-04-11 13:41:43 +02:00
phosit 19c6977872 Request connection-data in the client constructor
This way it doesn't has to be requested manually and it can't be
requested to late.
2026-04-11 13:41:43 +02:00
phosit dbe89d10ae Pass the controllerSecret to the CNet* constructor
It wasn't clear when to call `SetControllerSecret` now it can't be done
wrong. Also the mutex has to be locked less often.
2026-04-11 13:41:23 +02:00
phosit d33fb147bc Pass the game password at construction to Net*
CNetClient and CNetServer are constructed for a single match. The
password of a game can not be changed after creating the match. When the
password is passed to the constructor it's not possible to invoke the
functions in the wrong order and the `ENSURE` can be "checked at
compile-time" so to say.
2026-04-11 13:38:58 +02:00
phosit 040e0b29a2 Initialize members in the class of CNet*
Sometimes the order was wrong.
2026-04-11 13:38:53 +02:00
phosit 6893654cfc Do the gamestate compression in the task-manager
This reduces the stutter when a client joins.
The decompression isn't put on the task manager. As the client would
have to wait for that either way. Also a new polling loop would have to
be introduced.

The compression code is moved to the file transferer so all data send
through it gits compressed.

Refs: #4210
2026-04-09 19:03:46 +02:00
phosit 262c5c037e Use promises to fetch net messages
Refs: #5585
2026-03-13 18:07:56 +01:00
phosit d29890efb0 Split NetSession into two files
Refs: #5212
2026-03-11 21:03:52 +01:00
phosit 789d24aa1c Initialize members net-sessions in the class
With this members of `CNetClientSession` and `CNetServerSession` get
initialized within the class instead of the constructor.
2026-03-11 21:00:05 +01:00
phosit e2dbcea487 Remove INetSession
This was only used in the `CNetFileTransferer`. Only one function is
called. That can also be a `std::function`.
2026-03-05 21:09:14 +01:00
phosit df18e22277 Remove Script::CreateArray
It's better to construct a js-array from a `JS::RootedValueVector`.
Because it is more strongly typed and the index doesn't has to be
specified when appending an element.
Some usages are replaced with `JS::RootedValueArray`.

Fixes: #8702
2026-02-08 19:27:50 +01:00
phosit 13453a3c7b Remove ScriptContext::CreateContext
This function nudges one into using it instead of the constructor. Even
though a `std::shared_ptr` isn't required.
2026-01-24 12:03:05 +01:00
Ralph Sennhauser ba4ef61c15 Use cpp-httplib instead of mongoose
Use cpp-httplib for Profiler2 and RLInterface instead of mongoose.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-01-24 10:45:48 +01:00
phosit 03a5198ed3 Remove g_GUI usage in simulation2/*
This is the last remaining inclusion of a gui file in simulation2/.
2026-01-23 21:05:18 +01:00
phosit cfb742c914 Return the value from GuiPoll 2025-12-17 13:39:17 +01:00
phosit f23dde2f73 Use StructuredClone in m_GuiMessageQueue
The elements have to be cloned either way. Now they don't have to be
traced when they are in the queue.
2025-12-17 13:39:16 +01:00
phosit f03be7b568 Initialize more members of CNetClient
The username and the jid have to be set before the client is connected.
With this commit it's not possible to initialize them to late.
2025-12-14 17:23:05 +01:00
phosit 1917d034fd Introduce a namespace in Loader
All functions had a `LDR_` prefix. The prefix is removed.
Functions and globals which are only used in Loader.cpp are now
contained in an anonymous namespace.
2025-12-13 18:58:17 +01:00
Ralph Sennhauser 4f6d4a91b0 Fix -Wtautological-overlap-compare in stun test
Fix the minimal check for an invalid IP returned.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-11-10 11:41:52 +01:00
Itms 866d6f0527 Add an engine "compatible" version
When a patch version is released, it must declare compatibility with the
previous patch versions of the same main release. This allows players to
keep replaying their games and to keep playing online with users of
other patches of the same main release.

This should have anticipated for dae7a8c394
2025-10-26 09:16:46 +01:00
Itms 50f6da2a13 Use the PYROGENESIS_VERSION macro instead of a global
Reviewed-At: https://gitea.wildfiregames.com/0ad/0ad/pulls/8222
2025-10-26 09:16:44 +01:00
elexis 2ccd10e566 Fix missing returns after disconnect in 95179c5e46.
Patch by @elexis.

The package sent in fa85527baf / #2420 plus this missing return causes the NetServerTurnManager
to be stalled forever if a client succeeds to send this package on disconnect.

In NotifyFinishedClientCommands, Disconnect calls OnDisconnect calls UninitialiseClient calls m_ClientsData.erase,
but then m_ClientsData[client].readyTurn = turn; reinserts the disconnected client, making the turnmanager wait forever for the disconnected client.

refs https://wildfiregames.com/forum/topic/134742-bug-game-incredibly-slowfreeze-at-start-because-because-of-1-player/
2025-10-12 12:39:41 +02:00
elexis 1f58836cf1 Fix NetServerTurnManager hanging if a client passed handshake but not authentication on gamestart.
Fixes #5201.
2025-09-27 10:02:46 +02:00
Itms 9150c20818 Remove ScriptTypes and ScriptExtraHeaders headers
The first header was used to include the SpiderMonkey JS API at once,
with safeguards and preprocessor defines. Nowadays, SpiderMonkey
provides modular headers allowing us to include what we use, refs #8086.

Some defines have to be moved to compiler options but it is apparently
a mistake from the SM developers:
https://bugzilla.mozilla.org/show_bug.cgi?id=1987876
2025-09-14 13:17:18 +02:00
Ralph Sennhauser 2cedb48de2 Remove custom span and use std::span
With C++20 the custom container PS:span, which was a backport of
std::span is no longer needed.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-24 11:09:57 +02:00
Ralph Sennhauser 5b5f678e3f Fix some includes all over the place
Make include-what-you-use happy with some files in source and fix what
needs to be fixed.

Add markers to precompiled.h header includes to avoid
include-what-you-use wanting them to be removed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-14 20:15:30 +02:00
Ralph Sennhauser 3647921bed Fix some includes all over the place
Make include-what-you-use happy with some files in source and fix what
needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-13 19:38:21 +02:00
Ralph Sennhauser 0368a1b391 Make requirements sufficient in StunClient
While std::is_pod is required it is not sufficient so use
std::is_integral as condition which is.

Further replace the static_assert with a requires and use the new endian
support to avoid use preprocessor.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-12 20:45:16 +02:00
Ralph Sennhauser 4a14e382d5 Replace deprecated std::is_pod
std::is_pod is deprecated in C++20 and as such triggers
-Wdeprecated-declarations when built with C++20, "is_standard_layout &&
is_trivial" is the equivalent, so migrate to that.

While at it replace runtime dispatch with compile time and reduce the
required trait for memcpy to what is really needed.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-12 20:45:15 +02:00
phosit eb3f0166f8 Prefer [[maybe_unused]] over UNUSED2
`[[maybe_unused]]` is in the C++ standard.
2025-07-28 13:16:37 +02:00
Ralph Sennhauser 3c1a37985a Fix includes in source/network
Make include-what-you-use happy with files in source/network and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-23 18:18:47 +02:00
phosit 9822a22573 Replace ScriptException::Raise in Engine functions
Now exceptions can be thrown. The function throwing exceptions becomes
cleaner and doesn't require a `ScriptRequest` anymore.
2025-07-08 19:11:49 +02:00
phosit 891908b801 Remove UNUSED
The `UNUSED` macro is used to mark a variable as unused but with a name.
Those usages are replaced with comments so that `UNUSED` can be removed.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-unused
2025-06-26 17:25:05 +02:00
phosit dd26f3a802 Restrict param type of FSM events
Previously the param type was `void*` now the type has to be specified
as template parameter of the `CFsm`.
With this commit some casts can be removed.
2025-06-26 16:42:04 +02:00
Lancelot de Ferrière af32d386b9 Stop running shrinking gcs & simplify GC logic.
Shrinking GCs dump the JITted code, which leads to redundant recompilations, lowers performance, and makes profiling JS more difficult.
They may still happen if the runtime is at risk of OOM.
2025-04-22 17:03:29 +02:00
phosit 1a8757660f Get config values without using return parameters
Many temporaries can be removed.
2025-04-09 12:51:21 +02:00
Vantha 78900842b1 Improve the "UDP port 20595" connection error dialog
Add a unique disconnect reason for timeouts of connection attempts.
Rewrite the displayed error message and provide a link directly to the FAQ entry.
(The old message was very misleading and only brought players on the
wrong track during troubleshooting)
2025-03-13 15:34:20 +01:00
Dunedan 18d7746c84 Fix adding port forwardings using UPnP
The UPnP implementation included a combination of two subtle bugs, which
resulted in failure to create port forwardings every time after the
first one.

When using UPnP, the internet gateway to create the port forwardings at
needs to discovered. As that takes a while, the its root descriptor URL
was supposed to be cached after successful discovery in the user config
in "network.upnprootdescurl". However, instead of caching the root
descriptor URL, the control URL got cached. That caused following
requests to the root descriptor URL to fail, as they ended up at the
control URL instead. As such requests might also fail when the network
topology changed, the code was supposed to fall back to discovering the
internet gateway again when the cached one didn't work. However, due to
the inner workings of miniupnpc the request using the cached root
descriptor URL didn't result in an error, so the new discovery was never
triggered. As the wrong value was persisted in the user config there was
also no way to get out of this situation again.

This commit fixes both of these bugs.

As far as I can tell these bugs existed since the introduction of the
caching of the root descriptor URL in 0ba25e9968, which means creating
port forwardings using UPnP has been broken since Alpha 15.
2025-02-24 08:23:07 +01:00
Dunedan 5696f063f5 Reduce time to discover the internet gateway
When adding a port forwarding via UPnP, pyrogenesis first needs to
discover the internet gateway to create the forwarding at. To do so, it
utilizes miniupnpc to send an SSDP request and waits 10 seconds until it
processes the responses and continues to add the port forwarding.
As that happens asynchronously it means if players hosting games rely on
UPnP for port forwarding and if their pyrogenesis instance doesn't have
the address of their internet gateway cached, it takes more than 10
seconds after starting to host a game, before players can join. However,
waiting for 10 seconds is completely unnecessary, because the internet
gateway responds immediately to the SSDP request. Therefore, this commit
reduces the time to wait for responses from 10 seconds to 2 seconds,
which is the timeout miniupnpc uses internally as well, when discovering
internet gateways.
2025-02-23 04:41:43 +01:00
Dunedan fcd3fc2aa3 Create port forwarding for correct port with UPnP
Up to know the UPnP logic ignored the port a user was hosting a game on
and always added a port forwarding for the default port UDP 20595. This
commit fixes that, so a port forwarding is added for the actual port a
game is hosted on.
2025-02-22 20:26:30 +01:00