202 Commits

Author SHA1 Message Date
Kawe Mazidjatari
0936f60c85 Engine: add newly reversed fields to CClient class 2024-04-12 20:34:46 +02:00
Kawe Mazidjatari
e909df9ec8 Engine: light cleanup to CL_MoveEx()
Make *chan and commandTick const.
2024-04-12 20:33:36 +02:00
Kawe Mazidjatari
2ca3baa77d UserCmd: limit command backlog to prevent exploitation
Implement UserCmd command backlog limiting (the new convar 'sv_maxUserCmdProcessTicks' dictates how many ticks can be processed per second). Defaulted to 10, which is (default tick interval (0.05) * default cvar val (10) = 0.5ms window), which is equal to the default of cvar 'sv_maxunlag'.

Before this patch, you could stuff several seconds worth of usercmd's in one second and achieve speed hacking.
2024-04-12 01:51:11 +02:00
Kawe Mazidjatari
b699fe431e RTech: use more consistent type names
Force consistency between type names (follow scheme used in tier0 and rtech_game export symbols).
2024-04-11 02:19:36 +02:00
Kawe Mazidjatari
e639cb3f5f RTech: rename pak defines
More correct and consistent naming.
2024-04-11 01:42:55 +02:00
Kawe Mazidjatari
b019307947 Engine: initiate rcon connection from address change callback
A more user friendly approach.
2024-04-10 16:23:48 +02:00
Kawe Mazidjatari
e5199d8253 Engine: use tier2 random generator for netkey
Limit usage to only 1 algorithm provider.
2024-04-10 15:29:51 +02:00
Kawe Mazidjatari
ee39e0b014 Tier2: move random generator from tier0 to tier2
Moved into cryptutils.cpp.
2024-04-10 15:28:47 +02:00
Kawe Mazidjatari
ec14bf70de Engine: move rcon_password entirely to server
The client doesn't need this convar, client only needs cl_rcon_address.
2024-04-10 15:15:27 +02:00
Kawe Mazidjatari
f8dd1fe88c Engine: implement encryption for RCON protocol
RCON lacked encryption, added AES-CTR encryption on RCON frames. Slightly adjusted protocol to take this into account (sending nonces, encrypted data itself, etc).
2024-04-10 14:08:52 +02:00
Kawe Mazidjatari
801c3cee79 Engine: remove extraneous include 2024-04-03 01:04:13 +02:00
Kawe Mazidjatari
3c5a1a1203 Engine: flip order of checks
Check for cvar or state first before checking the current thread. The cvar/state check is slightly cheaper.
2024-04-01 01:06:32 +02:00
Kawe Mazidjatari
f5fcf8bd7a Engine: rcon code readability improvement
Remove the else statement since it will always be else there.
2024-04-01 01:04:27 +02:00
Kawe Mazidjatari
ff9261b773 Engine: fix string bug, extraneous copy
request.requestmsg() returns a reference but we assign the reference to a char*. Removed the c_str() call.
2024-04-01 01:02:59 +02:00
Kawe Mazidjatari
83b1f43dbc Engine: properly deal with server frame thread commands/convars
Marked convars/concommands as FCVAR_SERVER_FRAME_THREAD and removed main thread dispatching code and comments that are no longer in effect. In the RCONServer execute handler, a ThreadJoinServerJob() is placed if the commandbase is flagged FCVAR_SERVER_FRAME_THREAD since RCON dispatches the command, or sets the convar directly.
2024-04-01 01:02:02 +02:00
Kawe Mazidjatari
276289966c Engine: reimplement netmsg debuggers
Reimplement logic for cvars: "net_showmsg", "net_blockmsg", "net_showpeaks".
2024-03-31 16:13:04 +02:00
Kawe Mazidjatari
b7e61e4088 Engine: add functions for getting build/platform strings 2024-03-31 16:13:04 +02:00
Kawe Mazidjatari
c4a0c0d6c8 RTech: finalize decouple of websocket system + improvements
The WebSocket system is now fully split up. The global network module initialization is moved to DLL init so the websocket class could be used for anything. The LiveAPI system now also mostly runs in the server frame thread, the convar change callbacks still need to be latched to the server frame thread however.
2024-03-31 16:13:03 +02:00
Kawe Mazidjatari
2d084db3a3 LiveAPI: initial WebSocket implementation
Working WebSocket implementation (foundation for game LiveAPI).
2024-03-25 01:26:33 +01:00
Kawe Mazidjatari
d302be7b4d Cleanup/add some comments 2024-03-16 01:30:44 +01:00
Kawe Mazidjatari
fd3a805316 Engine: datablock sender cleanup
Mark cvar net_compressDataBlockLzAcceleration static.
2024-03-14 02:31:09 +01:00
Kawe Mazidjatari
6f962a8e2b Engine: server bulk ban check bug fixes
If the code was ran in the main thread, it would never fire the actual check logic. This patch changed the code so it would always fire from the start of the frame. Also fixed a memory leak that occurred when passing in an external banned list to SV_CheckClientsForBan (previously, 'SV_CheckForBan'); the code always allocated a new banned list, but only freed it if no external banned list was provided. This patch changed the code so it only allocates it if no external one is provided.
2024-03-10 02:13:15 +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
535a212fc4 Engine: fix return value for game wndproc
Should return LRESULT, not int.
2024-03-03 14:44:25 +01:00
Kawe Mazidjatari
06b2226bbc ImGui: make config singleton static
Avoid indirection, also deduplicate common style var assignments.
2024-02-29 22:31:43 +01:00
Kawe Mazidjatari
8f09ac1b86 ImGui: cleanup and improvement to surface implementation
* Properly run fade in-out animations
* Make common methods/members shared
* Remove extraneous SDK thread
2024-02-29 13:18:18 +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
3e3bc79adf ImguiSystem: properly implement ImGui and fix several bugs
Moved implementation to dedicated class 'CImguiSystem' with the following changes:

* Added mutex for ImGui_ImplWin32_WndProcHandler(), the window proc is ran from a different thread than CImguiSystem::SampleFrame() is being called from. Needs a mutex as both functions interact with the input queue list.

* Added init stages for debugging and preventing the system from running certain parts of the code if a certain stage hasn't been reached yet.

* NULL out ImGuiContext::ConfigNavWindowingKeyNext , we don't need any nav window shortcuts as users don't need then in-game, and it also interferes with certain key binds some users have.

* CImguiSystem::SampleFrame() (previously ImguiSystem_SampleFrame()), is now being called from CMaterialSystem::SwapBuffers(), as that function is called from the main thread while also getting updated during level loads/etc, so instead of switching between 2 static buffers for as long as the levels are being loaded, we imgui updates properly too and directly swap afterwards.

* Removed hack in CGame::WindowProc() where we would only run windowproc if we aren't shutting the game down. This was needed as there was a chance of a crash at some rare cases, but this was simply due to a missing mutex which has been addressed and fixed as of this commit.

* Lock mutex during init and shutdown.
2024-02-27 17:43:18 +01:00
Kawe Mazidjatari
0a3da6edcc Update sdk_dll.cpp
Mark 'sdk_fixedframe_tickinterval' FCVAR_ACCESSIBLE_FROM_THREADS.
2024-02-25 23:54:34 +01:00
Kawe Mazidjatari
940cbe6430 ImGui: move initialization code to DX hook setups
Also removed unused global declaration 'g_bImGuiInitialized'.
2024-02-25 21:15:37 +01:00
Kawe Mazidjatari
e967cb374b Engine: render ImGui in main thread and fix many threading bugs
ImGui drawing code now takes place in the main thread, a snapshot of the render data is created in CMaterialSystem::SwapBuffers(), and is being rendered in the render thread right before SpinPresent().

The reason why this was necessary, is because ConVar::GetString() isn't thread safe if its not marked FCVAR_MATERIAL_SYSTEM_THREAD or FCVAR_ACCESSIBLE_FROM_THREADS, and we used it for the console suggestions window, which iterates over every ConVar, accessible from threads or not.

This is overall also a better code architecture.

This change also forced changes in the ImGui server browser window, which contained a bunch of threading bugs too.

Engine changes:
- g_pCVar is no longer exported, as this wasn't necessary in the end.
- g_ThreadMainThreadID and g_ThreadServerFrameThreadID are now exported from the game executable, as these are required as soon as the DLL is loaded.
2024-02-25 20:12:56 +01:00
Kawe Mazidjatari
a1e4500b98 Engine: reject connection is session ID hashing failed
If hashing failed, the other checks will fail regardless, return out early.
2024-02-25 19:57:45 +01:00
Kawe Mazidjatari
4ce38ba725 Engine: close RCON socket on password hashing failure
Must also be closed here
2024-02-25 19:56:58 +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
02087fef5e Engine: reduce reason buffer stack size
64 chars will cover all reasons returned by l8w8jwt_get_validation_result_desc.
2024-02-22 14:56:20 +01:00
Kawe Mazidjatari
79f8b46d62 RTech: major cleanup of pak globals and improvement
Add missing types to fully mapped out PakGlobals_s struct, which is a 13MiB+ structure! This covers the vast majority of the pakfile system which is why we had to change a bunch of stuff for this patch. This patch also comes with:

- Reversed 'JobFifoLock_s' structure
- Reversed 'PakTracker_s' structure
- Reversed 'PakAssetTracker_s' structure

Many globals have been dropped as they were covered by the large PakGlobals_s singleton.

The pak decoder logic has been changed up as well, we now use a decode mode enumerant which will make it easier to add in more decoders for the pak files in the future.
2024-02-22 02:09:28 +01:00
Kawe Mazidjatari
acbe43a210 Engine: fix RCON bugs and improve security
- Upgraded hashing algorithm to SHA-512, and store the raw hash instead of a string copy, which is way cheaper to compute and compare.
- Only ever close sockets once in CRConServer::SetPassword().
- Made the game server & game client RCON singletons static.
- Added calls to gracefully shutdown RCON server and RCON client on Engine/SDK shutdown.
- Added more prints so RCON user knows when its shutdown, or when their password change is in effect, etc.
- Fixed bug where we could tokenize an empty string when we dispatch a console command.
2024-02-22 01:55:08 +01:00
Kawe Mazidjatari
6afb5fe593 Engine: improve CClient::Authenticate performance
- Removed 2 std::string copy constructions
- Removed 32 sprintf calls per token auth request.
- Fixed a bug where we format the NucleusID as s64 instead of u64.
- Added additional hardening for when token/sessionId stitching fails, this will now always reject the connection.
- Improved the macro to make sure we always free the JWT claims if it has been allocated.
2024-02-22 00:59:00 +01:00
Kawe Mazidjatari
bc5e14643c Engine: print COM_ExplainDisconnection() text as CLIENT
Only used on the client, print it as client.
2024-02-21 01:18:43 +01:00
Kawe Mazidjatari
77c8e3a994 Engine: remove deprecated cvar 'cl_move_use_dt'
No longer used, the vftable call made when this was false is stubbed and thus will cause movement to bug when unset; removed.
2024-02-21 01:17:48 +01:00
Kawe Mazidjatari
4ae9852291 Engine: cleanup data block sender/receiver and add types
* Move member vars to correct place, to match it with the engine.
* Added out-of-band network message ID's for the R5 engine.

Also implemented 'ServerDataBlockSender::SendDataBlock()' and 'ClientDataBlockReceiver::AcknowledgeTransmission()'. NOTE that these are currently not tested, and also not in use! The code uses the version stored in the vftable which is what the engine itself provides. These have been implemented for reference only. If they need to be used, they need to be thoroughly tested first!
2024-02-21 01:16:10 +01:00
Kawe Mazidjatari
0fbbae3732 Engine: fix bug regarding packet compression override
Only encrypt and decrypt packets if the initial argument tells it to do so. Some connectionless packets aren't supposed to be encrypted
2024-02-19 21:24:01 +01:00
Kawe Mazidjatari
155c221a70 Engine: rebuild CClientState::ProcessCreateStringTable()
Rebuild CClientState::ProcessCreateStringTable() and add notes for multiple 'potential' exploit vectors that are currently in place. Also add wrappers for compressing/decompressing net packets.
2024-02-19 21:24:00 +01:00
Kawe Mazidjatari
802e1f42eb Engine: partial rebuild for data block sender/receiver
This patch partially rebuilds the data block sender/receiver. The receiver leaks memory if the sender sends a bogus LZ4 packet, it would allocate memory to copy the encoded data into, from which it would decode it to the scratch buffer, but it would never deallocate this temporary buffer is the LZ4 decoder failed. This has been fixed. The second reason to rebuild these was to look into potential compression optimization. The data block rebuild now also features the latest LZ4 codec.
2024-02-19 21:24:00 +01:00
Kawe Mazidjatari
976f1ab5ae Engine: fix netchan bugs and add SendData()
Fixed bug in CNetChan::SendNetMsg() where the return value of INetMessage::WriteToBuffer() was not checked, nor did we return if the stream we added the message in was overflowed. If the function gets to the stage of writing the msg in the buffer, we need to return true only if we didn't overflow AND if the msg was successfully written. Also added a method for sending bitbuf data into stream of choice.
2024-02-19 21:24:00 +01:00
Kawe Mazidjatari
b3cd76aa70 Engine: fix bug in networking code caused by incorrect constants
Mixed MAX_BACKUP_COMMANDS with MAX_NEW_COMMANDS, added proper (confirmed) defines. Also fixed MAX_BACKUP_COMMANDS_PROCESS, which was 60 but was supposed to be 64, so we were 4 backup commands short in CPlayer::ProcessUsercmds().
2024-02-19 21:22:24 +01:00
Kawe Mazidjatari
92dd860079 Engine: fix bug causing level assets to not load properly
The level has changed when strcmp returns a non-null value.
2024-02-06 15:37:50 +01:00
Kawe Mazidjatari
340dcfd4bd Engine: remove unused variable
No longer used as of commit b29be00d.
2024-02-06 14:51:47 +01:00
Kawe Mazidjatari
b29be00d82 Engine: revert server tick msg rebuild to old behavior
Only update statistics, this code was mainly added for testing, but testing revealed no additional performance or smoothness improvements, even during >6 hour sessions. The clock drift already gets corrected each frame from Host_RunFrame(). Only update statistics to update CPU and frame times on the client's debug panels if enabled.
2024-02-06 14:42:36 +01:00