127 Commits

Author SHA1 Message Date
Kawe Mazidjatari
32c2c903e5 Pylon: mark convars 'FCVAR_ACCESSIBLE_FROM_THREADS' 2024-04-05 18:19:39 +02:00
Kawe Mazidjatari
609d705a0c 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-04-05 18:13:32 +02:00
Kawe Mazidjatari
d6b14fa12c 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-04-05 18:13:31 +02:00
Kawe Mazidjatari
f0907ca9f1 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-04-05 17:56:52 +02:00
Kawe Mazidjatari
dbec4be848 NetworkSystem: rename NetGameServer_t member vars 2024-04-05 17:52:58 +02:00
Kawe Mazidjatari
e8be704276 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-04-05 17:52:57 +02:00
Kawe Mazidjatari
fcf3a09418 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-04-05 17:52:57 +02:00
Kawe Mazidjatari
4662995f2e 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-04-05 17:52:57 +02:00
Kawe Mazidjatari
ee82d5d8e0 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-04-05 17:42:05 +02:00
Kawe Mazidjatari
bd230506fb Pylon: fix bulkCheck request body
Array should be in "players".
2024-04-05 17:29:12 +02:00
Kawe Mazidjatari
52b84fc3b7 Pylon: fix typo 2024-04-05 17:19:31 +02:00
Kawe Mazidjatari
fa76747baa Show a more detailed error if the EULA request failed 2024-04-05 16:34:29 +02:00
Kawe Mazidjatari
2fe902061e Don't check for accepted EULA versions if this is a dedicated server 2024-04-05 16:34:28 +02:00
Kawe Mazidjatari
b37a3bdeba Add comments on newly added code 2024-04-05 16:28:59 +02:00
Kawe Mazidjatari
22c82d6f1d 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.
2024-04-05 16:26:18 +02:00
Kawe Mazidjatari
0eaa226dce 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
2024-04-05 16:24:46 +02:00
Kawe Mazidjatari
909977452e 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.
2024-04-05 16:24:45 +02:00
Kawe Mazidjatari
b3e768190c 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.
2024-04-05 16:21:45 +02:00
Kawe Mazidjatari
1d41b23abb Make sure language is never NULL
* Initialize CPylon::m_Language to "english".
* Make sure cvar change callback is always setting values instead of returning out early.
2023-09-16 00:45:11 +02:00
Kawe Mazidjatari
f0bbc7dbf0 Change logging context
Should be engine.
2023-09-07 22:46:12 +02:00
O-Robotic
51dd17ad2a Validate json root is an object before trying to retrieve members from it. 2023-09-07 20:32:09 +01:00
Kawe Mazidjatari
b85003a9ac Replace JSON library with RapidJSON
Less copies and overall CPU time parsing/constructing JSON's as we are mostly still using string pointers rather than STL string container.
2023-09-07 11:17:05 +02:00
Kawe Mazidjatari
cb1a69e82a Ban system refactor
Use CUtlVector, and remove every copy caused by passing vectors by value. CUtlVector does not support copying. Also removed all extraneous std::string copies caused by calling itoa instead of std::to_string, or std::stoll, etc. All features have been tested and work as designed.
2023-08-31 00:16:25 +02:00
Kawe Mazidjatari
71b0781715 Utilize 'DevMsg()' for uncertain builds only
Only uncertain builds will contain DevMsg()/DevWarning() prints. For retail, Msg() and Warning() should be used instead.
2023-08-21 19:12:29 +02:00
rexx
1c179434d3 fix dedi compile
sets pylon language in a cvar change callback instead of accessing directly, as networksystem does not have a DEDICATED define
2023-08-17 20:22:28 +01:00
rexx
356f0ce7c0 send language to MS 2023-08-17 20:02:42 +01:00
Kawe Mazidjatari
5f64cd83d8 Fix FileSystem size integer truncation
The implementation in the engine always took/returned signed 64bit size types, but I made a mistake when reversing the virtual function table. All types have been changed to what they should be (mostly signed 64bit, very few unsigned), and usage in-SDK has been adjusted accordingly.
2023-08-09 14:43:54 +02:00
Kawe Mazidjatari
9e9d3342b3 CURL tools improvement
- Added wrapper for downloading files.
- Moved many function arguments to dedicated parameters structure.
2023-07-28 14:47:20 +02:00
Kawe Mazidjatari
31d92b439f Move cvars from curlutils.cpp
Move it elsewhere so this code can be shared among tools that don't feature the ConVar class.
2023-07-26 16:52:49 +02:00
Kawe Mazidjatari
54536a2652 Parameterize changelevel or map in CServerListManager::LaunchServer()
Parameterized; whether or not to drop all clients (map = drop, changelevel = keep).
2023-07-19 02:21:58 +02:00
Kawe Mazidjatari
6cecc3297e Move KeepAlive function to HostState
Only used in HostState, moved to HostState with static linkage.
2023-07-19 02:19:43 +02:00
Kawe Mazidjatari
7455d4da2d CPylon: add getters and setters for error/token fields 2023-07-19 02:17:28 +02:00
Amos
ccdfed1c19 Use CServer's 'GetClient'
Use the CServer's 'GetClient' method for obtaining clients by index.
2023-07-12 08:56:17 +02:00
Kawe Mazidjatari
ef69611435 Replace memalloc calls throughout entire SDK
Global 'direct' usage of 'MemAllocSingleton()' has been jettisoned. Where possible, smart pointers were used instead. During the refactor, the following bugs were addressed and fixed:
- The virtual destructor of 'CCVarIteratorInternal' was NOT called on destruction.
- Class function 'KeyValues::MakeCopy' did NOT calculate the buffer size of the wide string correctly, the original calculation was 'len+1*sizeof(wchar_t)', but should've been '(len+1)*sizeof(wchar_t)'.

Some other code changes include:
- Tier0 include 'memstd.h' has been moved above all thirdparty includes, to make sure the memalloc functions get shadowed with ours in third party libraries as well.
- RPak file paths string literals are now defines.
- 'DestroyOverlay' has been refactored to match the assembly of the game.
2023-06-26 22:34:24 +02:00
Amos
b13cc071a9 Improve ban commands
The ban commands have the 'sv_' prefix removed. CBaseEntity::InputKill expects 'kickid' to be present, it uses this to kick the player once the entity has been destroyed. Not doing so could lead into a crash or other undesired behavior.
2023-06-22 09:09:38 +02:00
Amos
ac4ab6aa1a Add reason parameter to kick/ban commands
Reason parameters are optional. For scripts, to use the default message, pass in an empty string. The function for the script system should be centralized soon to avoid more duplicate code.
2023-06-20 08:44:03 +02:00
Kawe Mazidjatari
3f8baf6f68 Allow setting compile options for specific targets
Previously, it was all controlled from the global init (applied to all projects), but some projects need different options. With these changes, you can disable the common options applied in the 'add_module' macro, and set your own if desired.
2023-06-17 00:45:27 +02:00
Kawe Mazidjatari
e891d74656 Fix cURL error logging for dedicated
Since this file no longer gets build along with the DLL project, but as a static lib instead, the 'DEDICATED' define no longer worked, and therefore this became broken after the CMake port. The 'CURLHandleError' helper function now takes a bool determining whether or not to log the error, and the caller disables it for dedicated (dedicated should only log the error once, this happens from within the caller class).
2023-06-02 00:05:23 +02:00
Kawe Mazidjatari
9f44bcc818 Treat compiler warnings as errors
Treat them as errors globally. Most of the time a warning is a bug, or problem in code that could be solved in a different (better) manner. Thirdparty code have this disabled. The warnings as errors option can be globally disabled through the CMake GUI, but this is not recommended.
2023-05-15 09:44:26 +02:00
Kawe Mazidjatari
0138ac025f Fix bug when trying to print the host token
Should return ptr to string (caught from compiler warnings).
2023-05-15 00:54:33 +02:00
Kawe Mazidjatari
6a86ae2606 Cleanup CMakeLists files
Light cleanup in CMakeLists files. Split protocols and improve filter names.
2023-05-14 17:36:08 +02:00
Kawe Mazidjatari
8dbc2024c6 CMake code improvements
Use the 'add_module' macro to add modules without creating duplicate code. This macro also takes a reuse PCH as parameter, so modules that need a precompiled header, could reuse those from different targets that compile them. This commit also restructures the group order of the generated solution files for easier code navigation.
2023-05-13 00:14:53 +02:00
Kawe Mazidjatari
f120354e96 Initial port to CMake
* All libraries have been isolated from each other, and build into separate artifacts.
* Project has been restructured to support isolating libraries.
* CCrashHandler now calls a callback on crash (setup from core/dllmain.cpp, this can be setup in any way for any project. This callback is getting called when the apllication crashes. Useful for flushing buffers before closing handles to logging files for example).
* Tier0 'CoreMsgV' function now calls a callback sink, which could be set by the user (currently setup to the SDK's internal logger in core/dllmain.cpp).

TODO:
* Add a batch file to autogenerate all projects.
* Add support for dedicated server.
* Add support for client dll.

Bugs:
* Game crashes on the title screen after the UI script compiler has finished (root cause unknown).
* Curl error messages are getting logged twice for the dedicated server due to the removal of all "DEDICATED" preprocessor directives to support isolating projects. This has to be fixed properly!
2023-05-10 00:05:38 +02:00
Kawe Mazidjatari
f319fc0846 Use server global variables for client loops
Use server global variables for determining the num clients to loop over. This is cheaper and better than always looping over MAX_PLAYERS.
2023-04-30 01:50:38 +02:00
Kawe Mazidjatari
2748c61fe2 Put json value getters in try catch
Put 'nlohmann::json::value' operations in try catch, as these could raise an exception.
2023-04-29 14:58:46 +02:00
Kawe Mazidjatari
145bc3797f Only check token field if the server is hidden 2023-04-29 13:15:18 +02:00
Kawe Mazidjatari
3ea49766c6 Light banning code improvements
* Removed extraneous std::string constructors (everything using the bansystem used raw char pointers).
* Improved logging and function comments.
2023-04-29 12:15:51 +02:00
Kawe Mazidjatari
ab9d36e0d8 Send client's persona name to the master server
Will be used on the master server for additional checking.
2023-04-29 00:05:47 +02:00
Kawe Mazidjatari
48bc69b028 Initial implementation of bulk ban checking
Initial implementation of the bulk ban check system. This implementation takes a snapshot of the currently connected clients, sends it up to the master server, and the master server returns anything within this list that is marked 'banned'. The server would then kick the player from the server. This commit also removes the global banned list cache, as the bulk checking system offers a lot more freedom regarding banning specific players and have it sync across all available servers.
2023-04-28 23:47:58 +02:00
Kawe Mazidjatari
fcc4b410f3 Improve formatting in pylon code 2023-04-26 23:31:16 +02:00