45 Commits

Author SHA1 Message Date
Kawe Mazidjatari
73b517600d NetworkSystem: use cached string lengths where possible
Avoid doing internal strlen() when length is already known.
2025-02-07 21:48:50 +01:00
Kawe Mazidjatari
fde639e167 NetworkSystem: optimize server list construction
Use emplace_back to construct in place, and transfer ownership of allocated memory.
2025-02-07 21:42:44 +01:00
Kawe Mazidjatari
bb566cd1fd NetworkSystem: use cached string lengths where possible
No need to do another strlen internally in rapidjson's value wrapper. We already know its length.
2025-02-07 21:40:33 +01:00
Kawe Mazidjatari
e27fc72e25 NetworkSystem: update function documentation 2025-02-07 21:39:22 +01:00
Kawe Mazidjatari
18e71086b6 Tier2: strong optimizations for JSON tools
- Fetch field name strlen at compile time using rapidjson's string refs.
- Use from_chars to do string to number conversions which isn't locale aware, for maximum speed.
2025-02-07 21:38:03 +01:00
Kawe Mazidjatari
a5bd66513a NetworkSystem: fix network address comparisons
Network addresses should always be stored as base only (without their port numbers), since all additional data can change on reconnects which will make comparisons impossible.
2025-01-26 11:53:39 +01:00
Kawe Mazidjatari
5584c2a87f NetworkSystem: fix incorrect function parameter
nRead was incorrectly placed, it should've been in the parse call. This is used to process the string buffer at once since we already know the size of the string buffer.
2025-01-26 11:48:21 +01:00
Kawe Mazidjatari
de4a3d294c NetworkSystem: provide buffer size to RapidJSON parser
We already know the buffer size, this avoids having to recalculate it in the parser.
2025-01-13 15:51:07 +01:00
Kawe Mazidjatari
551840e6a3 NetworkSystem: fix bug when checking for pending map change
We need to check if it has a string before calling Playlists_Parse(), because if it has it will be emptied so the check afterwards won't work.
2024-12-05 23:38:53 +01:00
Kawe Mazidjatari
3d8d0b37a6 NetworkSystem: remove default assignments for map and playlist
No longer needed as of commit 3209af9a6c2509e5e6969199f5d9913b0ddb6ed0. These defaults were for the server browser but this code has now been moved over properly.
2024-12-05 15:55:36 +01:00
Kawe Mazidjatari
3209af9a6c Engine: large server host code refactor
This code was written at the start of the project before much of the engine was reverse engineered. There were some design problems where core server functions were shared with UI script.

A second problem was that not everything was properly synced between another; CServerHostManager held its own instance of the server name and server description, while the engine has actual convars to store these. So scripters weren't able to get the server name and server description if the server was a listen server and launched through the title screen.

The CServerHostManager class has been reworked to not keep a second instance, and the script functions for creating the servers have been reworked to always store the name and description in aforementioned convars.

Also moved the CreateServer and DestroyServer function to the UI namespace of scripts, and it is now only registered in UI context. The server should use GameRules_ChangeMap() to switch levels instead.

UI script also no longer registers core server functions, this was a design mistake and has been fully factored out in this patch.

The server script function 'SetClassVarSynced' has also been deprecated and removed, since calling this sends a netmsg to all connected clients, and running this once will not apply the new class var values to clients connecting afterwards. This should be managed through player.SetClassVar in the connect codecallbacks in scripts.
2024-12-05 15:53:40 +01:00
Kawe Mazidjatari
8237f2b1f3 BanSystem: use automatic JSON type classification
New feature as of commit 138600a3a6dafeae3d441e6a3c74b865ea88f1d3.
2024-11-29 14:51:30 +01:00
Kawe Mazidjatari
163f38c87d NetworkSystem: use automatic JSON type classification
New feature as of commit 138600a3a6dafeae3d441e6a3c74b865ea88f1d3.
2024-11-29 14:50:51 +01:00
Kawe Mazidjatari
4aee1e707c CPylon: fix bug in GetServerByToken
Field name and field type were incorrectly set, GetServerByToken only returns 1 server and is always an object but it was always treated as an array of servers. Fixed field name and field type.
2024-11-12 00:14:08 +01:00
Kawe Mazidjatari
a809b1f262 Server: remove exraneous client pointer check
CServer::GetClient() will never return NULL as it returns address of client in array. Removed extraneous checks as its misleading, and added const where possible.
2024-11-11 17:47:36 +01:00
Kawe Mazidjatari
50b4c559c6 Pylon: light cleanup of GetBannedList
Logic remains unchanged, just unscoped the iteration code by inverting the check for whether the array is empty.
2024-11-11 00:14:25 +01:00
O-Robotic
cce4429606 Pylon: Fix incorrect return value in GetBannedList
GetBannedList was returning true even when no players were pushed to the banlist causing excessive thread creation in the bulk check system.
2024-11-10 17:00:23 +00:00
Kawe Mazidjatari
bca3a595e5 Pylon: enforce consistency in schema 2024-11-09 14:05:41 +01:00
Kawe Mazidjatari
a702323181 Pylon: add option to fully disable matchmaking server connection
Fully disable the system if pylon_matchmaking_enabled is false.
2024-11-09 01:19:23 +01:00
Kawe Mazidjatari
6de498e7ba Common: make IsEULAUpToDate globally accessible
Will be used for crash reporting as well.
2024-10-06 11:50:31 +02:00
Kawe Mazidjatari
044528b9b1 Game: properly load shared global vars for game dll's
Properly load it from CServerGameDLL::DLLInit (and new in this commit, the client's shared globals from CHLClient::Init), this way we can also avoid the double dereference which improves performance. Also performed an architectural change where anything outside Game DLL code uses the shared interface pointer instead of the objects directly.
2024-07-31 22:18:33 +02:00
Kawe Mazidjatari
61856106f0 NetworkSystem: fix regression in eula schema
During port to new performant JSON utils system in commit a5e05d3996ae95876fcac09affeaa043a768e749, the typo was made causing EULA not to display during tests. Fix field name typo.
2024-06-11 16:42:59 +02:00
Kawe Mazidjatari
a5e05d3996 NetworkSystem: significant performance improvements
Now uses new JSON member lookup utilities implemented in commit f6e93ee457876ce869ce04067fe9344ff81083ca. All lookups (typically 3 per member) have been reduced to 1 by caching and reusing all value pointers or iterators. Also added error strings for 2 missing error cases in CPylon::GetEULA(), previously it would only set the error string during fetch error, but not when the data is missing or the schema is incorrect.
2024-06-11 10:16:16 +02:00
Kawe Mazidjatari
57dc081d4a Pylon: rename field "playerCount" to "numPlayers"
Force consistency between code structure.
2024-03-16 11:55:20 +01:00
Kawe Mazidjatari
63237361e9 NetworkSystem: fix numerous issues
This patch splits host logic from CServerListManager. CServerListManager is actually meant for the client to manage the server list to which the client could connect to. The hosting logic has been moved to the new CServerHostManager class.

Previously, we stored all the hosting details in CServerListManager, with connection criteria in CPylon, this data has been moved over to CServerHostManager as well.

Previously, we also needed a mutex to access the server host data, function HostState_KeepAlive() has been refactored to the point this mutex is no longer necessary as the only threaded process is the actual request, the rest is being applied in the main thread. We also now only construct a NetGameServer_t struct if we actually plan to host.

Access to CPylon::m_Language is now also protected by a mutex, as the change callback of cvar 'language' and the threaded method 'CPylon::QueryServer()' are competing for access.
2024-03-10 01:57:04 +01:00
Kawe Mazidjatari
420cb7a68d Engine: make task queue singleton static
Compile it as static object & renamed to more correct names. Also made the integral type for frame delay an unsigned int instead
2024-02-28 00:43:57 +01:00
Kawe Mazidjatari
006bec08f6 Pylon: mark convars 'FCVAR_ACCESSIBLE_FROM_THREADS' 2024-02-25 23:56:49 +01:00
Kawe Mazidjatari
6828901815 Tier1: static construction of ConVar objects during link time
Fully implemented ConVar class so we could statically construct all SDK convars, this avoids a level of indirection, and allows for creating ConVar's everywhere in the project.

This patch also removed the settings tab of the ImGui server browser, as it has threading issues, while it technically never caused a crash yet, it has been removed as there was no point keeping it vs the work required to make it thread save (it only managed 2 convars which are perfectly manageable through cfg's or the in-game console).

Also temporarily disabled the creation of ConVar's in the mod system due to a memory leak, we would allocate and register a convar based on details parsed out of a mod file definition, but never unregister and free it.
2024-02-24 02:15:09 +01:00
Kawe Mazidjatari
3d36c87b08 Statically construct all ConCommand
Properly implement the ConCommandBase and ConCommand classes so we could statically construct all ConCommand objects in the global scope of each translation unit, this way we don't need to put them in a global file and deal with preprocessor directives to compile then in/out for certain projects.
2024-02-23 00:12:06 +01:00
Kawe Mazidjatari
ed5721eaa0 BanSystem: refactor & fix bugs
* Make sure we read the banlist from platform as well, just like how we write to it.
* Use strtoull() instead of atoll() for nucleus id values, nucleus id is unsigned so we must convert to unsigned.
* Remove extraneous try catches, these were previously used for integral type conversions that threw exceptions, but the current ones do not throw so the try catch is unnecessary.
2024-02-04 12:55:56 +01:00
Kawe Mazidjatari
39d16fa4d7 NetworkSystem: rename NetGameServer_t member vars 2024-01-29 23:00:15 +01:00
Kawe Mazidjatari
8911bfa81a GameUI: cleanup and fix race condition
* Use CThreadFastMutex instead
* Rename ISurface to IDebugSurface to prevent a potential name collision with VGUI's ISurface iface if we ever add it
* Fix race condition when setting CPylon::m_HostIP from materialsystem thread, this has been dispatched to the main thread
* Marked 'pylon_matchmaking_hostname' FCVAR_MATERIAL_SYSTEM_THREAD as we use it in the server browser panel.
2024-01-21 23:06:26 +01:00
Kawe Mazidjatari
1361bfb172 Make singletons use static memory
Avoid heap memory allocation and a level of indirection. This allows the compiler to optimize the program even more. No logic has been changed in this patch.
2024-01-21 21:29:23 +01:00
Kawe Mazidjatari
c9b80a70cd Playlists: fix resource/memory leak
Remove workaround that was implemented to counter a crash during the beginning of this project, this issue was long solved but the workaround was never removed. Clearing the last precached VPK name prevents the engine from helping other threads to properly unload existing handles, if at all.
2024-01-21 20:24:44 +01:00
Kawe Mazidjatari
cd82e22ea3 Tier1: move KeyValues class to Tier1
The KeyValues class belongs here. Also reimplemented most loading methods for KeyValues, and adjusted the VPK building code to account for it. Pointers to the engine's implementation of KeyValues have been moved to a separate header ('keyvalues_iface.h'), as this allows external tools code to utilize the standalone KeyValues class implementation. Playlist utilities are completely separated from the KeyValues header; these have nothing to do with KeyValues other than manipulating a global KeyValues object for the playlists, and thus have been named as such and moved to rtech/playlists.
2024-01-12 00:52:07 +01:00
Kawe Mazidjatari
dda8c1255d Pylon: fix bulkCheck request body
Array should be in "players".
2024-01-07 15:24:40 +01:00
Kawe Mazidjatari
18235b43f3 Pylon: fix typo 2024-01-01 16:46:16 +01:00
Kawe Mazidjatari
193cc9b19b Show a more detailed error if the EULA request failed 2023-10-25 23:29:37 +02:00
Kawe Mazidjatari
dbedacebbf Don't check for accepted EULA versions if this is a dedicated server 2023-10-21 19:16:52 +02:00
Kawe Mazidjatari
bbe163f58c Add comments on newly added code 2023-10-20 19:30:07 +02:00
Kawe Mazidjatari
234dc312fe EULA dialog implementation
Display the EULA (fetched from masterserver), which the end user MUST accept before they can make use of the multiplayer features of R5Reloaded. NOTE: user doesn't need to agree to this to use the listenserver.
2023-10-20 19:16:33 +02:00
Kawe Mazidjatari
b9a24b30af Change JSON field types send to master server
They were all strings; changed them to what made most sense for each field type. Changes:
"hidden": string -> bool
"port": string -> int
"checksum": string -> uint
"playerCount": string -> int
"maxPlayers": string -> int
2023-10-15 10:47:19 +02:00
Kawe Mazidjatari
59fab7ac93 Client token authentication implementation
The game internally obtains a auth token from Origin. On connect to a gameserver, it will send it to the masterserver. The master server will create a JWT token and send this back to the client. The client stores this token in 3 userinfo cvars (token, sig1, sig2). the sig1 and sig2 cvars are there to compensate for the truncation caused by sending the cvar, as each cvar string length could be up to 255 (byte max). The server verifies this token (the signature, timestamp, expiry); if they are valid, the has successfully authenticated and will connect.
2023-10-15 10:40:46 +02:00
Kawe Mazidjatari
c3e11b4283 Pylon: fix use after free
The member must contain a copy of the string, pointing it to the buffer used by the language cvar results in undefined behavior. Several cases were the string pointed to random data were reported.
2023-10-08 16:37:10 +02:00
Kawe Mazidjatari
fd3e227a86 Align folder structure with p4 2023-09-19 22:13:22 +02:00