66 Commits

Author SHA1 Message Date
Kawe Mazidjatari
aa6a5dcb6e NetCon: rename to 'netcon'; remove platform suffix
Netcon is no longer 32bits. Previously it was made 32bits to maximize system compatibility, but this was unfortunately too hard to maintain after the migration to CMake, it was also no longer worth it as the tool never got used on 32bit platforms. Renamed to avoid confusion.
2024-06-01 11:49:15 +02:00
Kawe Mazidjatari
e7d3e8d23d NetConsole: log header/version as soon as possible
Logged right after console and terminal is initialized.
2024-06-01 11:43:11 +02:00
Kawe Mazidjatari
29ff073ae3 NetConsole: fix command line bug
Recently, encryption was implemented in the RCON system, but the command line initialization code wasn't adapted to this new logic. Code has now been adapted.
2024-06-01 11:43:10 +02:00
Kawe Mazidjatari
b26ed2f746 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-06-01 11:24:47 +02:00
Kawe Mazidjatari
001a8db684 NetConsole: fix undefined symbol
CheckCPUforSSE2() was removed in commit 504d042e6095b24e125c7d38549db860b2d15a67, but NetConsole still needs to check for it.
2024-06-01 11:16:47 +02:00
Kawe Mazidjatari
869741b3b3 Netconsole: fix race condition caused by misplaced mutex
Mutex should be locked before IsConnected(), as IsConnected() accesses CSocketCreator which checks a vector (not thread safe), lock the mutex in the correct place.
2024-04-05 18:13:31 +02:00
Kawe Mazidjatari
cb8f0902a4 Netconsole: don't process empty input strings
Caught by assert in CUtlBuffer ctor when tokenizing the input.
2024-04-05 17:46:55 +02:00
Kawe Mazidjatari
3c10bf0e8d Netconsole: refactor & improvements
* Fix multiple issues related to threading, such as not locking the mutex when using thread-unsafe members or methods.
* Netconsole now logs its output to a file on the disk.
* Properly handle close events, to allow netconsole to shutdown properly, so stuff like log buffers could flush properly. Input is now ran in a separate thread so main thread could check if we need to shutdown, and do so if needed. This was needed as previously input was ran in the main thread and the issue is that its blocking until an input is given.
2024-04-05 17:46:55 +02:00
Kawe Mazidjatari
abbed191c2 Tools: check CPU for SSE2
SSE and SSE2 instructions are being used, check for them instead of crashing somewhere in the program.
2024-04-05 17:46:52 +02:00
Kawe Mazidjatari
b2ce189ba1 Tools: rename NETCONSOLE define to _TOOLS
Rename since this would actually be used for all tools. Also moved 'plat_time.cpp' to tier0 so anything could compile it.
2024-04-05 17:35:10 +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
Kawe Mazidjatari
f2783ae93f Make use of 'CConnectedNetConsoleData::m_bInputOnly' properly
This member was in the class when RCON was added to the r5sdk, but it was never utilized. Now, each netconsole can toggle whether they are input only or not, the server only sends logs to netconsoles that are not input only. This patch also contains a fix in which the listen server sends logs to the client of its own process, causing an infinite recursive call to DevMsg.
2023-08-04 17:28:01 +02:00
Kawe Mazidjatari
3a19ac0c24 Add a note 2023-08-04 15:39:40 +02:00
Kawe Mazidjatari
461fb48575 More reliable way of enablin ansi colors on netconsole
Compare arguments individually instead of performing a scan over the whole command line string.
2023-08-04 15:36:40 +02:00
Kawe Mazidjatari
e7420a26af Properly tokenize netconsole input
Use the command tokenizer class.
2023-08-04 15:35:20 +02:00
Kawe Mazidjatari
f6d2628937 Cleanup proto structure
Removed unused/extraneous enumerants.
2023-08-04 11:20:24 +02:00
Kawe Mazidjatari
ddfe027677 Pass by reference
CConnectedNetConsoleData was allocated and deallocated manually, but std::vector is able to do it on its own. The vector type has been swapped out with CUtlVector as this removed the need of having to cast size types to a 32bit int to make it more compatible with the other sdk/engine types without throwing compiler warnings.
2023-08-04 10:48:22 +02:00
Kawe Mazidjatari
9e6b0e567f Port everything to CCommandLine
Before, we had to do a hack of capturing the command line using GetCommandLineA, and then checking if a certain argument is present. This was required due to how early the GameSDK dll was loaded (the g_CmdLine object was far from initialized in the engine). Due to the loader refactor, the commandline can be used directly after creation in the game's entry point (which is the time the SDK is getting loaded). Therefore, no copies of the command line are required anymore.
This commit contains the following changes:

- Correctly ordered the initialization, and deinitialization of systems (first init = last shutdown).
- Factored out command line string copy in favor of game's implementation.
- Factored the R5Reloaded emblem print into its own function.
- Removed 'SpdLog_PostInit()', we can now directly call DevMsg() once SpdLog_Init() has been called, the logger callback sink deals with the formatting of the output.
- Fixed a bug where the logger did not print the correct color for 'SYSTEM_WARNING' and 'SYSTEM_ERROR' in the external console.
- Fixed a bug where the command line did not work when the game wasn't launched with the '-launcher' parameter.
- Logs now equally appear on the external, and in-game console windows.
2023-07-01 01:20:47 +02:00
Kawe Mazidjatari
884decd090 Set default debugger parameters
The debugger can now be immediately invoked on all runtime projects after generating the solution without having to set anything up.
2023-06-24 15:46:56 +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
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
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
b57eb0c0c3 Set runtime directories for projects
Adjust the runtime directories, so they are identical to pre-cmake port.
2023-05-14 01:27:51 +02:00
Kawe Mazidjatari
08384346bf Setup log callback sink for netconsole 2023-05-13 14:04:13 +02:00
Kawe Mazidjatari
84c43cffa8 Properly setup netconsole CMakeLists 2023-05-13 14:02:47 +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
359820615f Move low level code to tier0/tier1
Moved to tier0/tier1 so it could be compiled into a static library in the future.
2023-05-06 22:59:01 +02:00
Kawe Mazidjatari
be61c93c85 RCON system improvements
* Added more error handling throughout code.
* Marked function parameters 'const' where possible.
* Updated comments.
2023-04-22 16:02:54 +02:00
Kawe Mazidjatari
8aed88a0b5 Make it easier to distinguish netconsole logs from rcon logs
Log net console timestamps with parentheses, and rcon logs with brackets. This makes it much easier to determine who the owner of the log is.
2023-04-19 02:05:58 +02:00
Kawe Mazidjatari
179bd31ee6 Initial large refactor of the RCON implementation
* Decoding and encoding is done into a single buffer, from raw buffers to avoid extraneous copies.
* Added base class holding all core logic for encoding, decoding, receiving and processing of the RCON protocol. This code was initially identical between all implementations of RCON, deduplicating this avoids bugs.
* Added more sophisticated error handling, stop right away when decoding for example fails.
* Added ability to have more than one active authenticated net console on the server. Controlled by cvar 'sv_rcon_maxconnections' (default 1).
* Max packet size for accepted, but not authenticated sockets is now controled by cvar 'sv_rcon_maxpacketsize' (default 1024).
2023-04-19 01:35:31 +02:00
Kawe Mazidjatari
b5b379fff9 Determine net console frame tick rate using an interval 2023-04-16 15:49:07 +02:00
Kawe Mazidjatari
bd1bec3cfe Several RCON bug fixes and improvements
* Fixed uncontrolled format specifier in 'NetMsg' call on the RCON client.
* Removed extraneous call to 'PrintPercentageEscape'.
* Compare, and disable RCON logs if user attempts to connect to listen server's RCON.
2023-04-16 12:05:39 +02:00
Kawe Mazidjatari
9287f00841 Fixed performance bug in standalone netconsole
When unconnected, the frame loop would run as fast as it could. Moved thread sleeper at the bottom in the outer scope of the function to prevent this behavior in all cases.
2023-04-16 01:00:07 +02:00
Kawe Mazidjatari
cf610b7d6b Light improvements to client side RCON system 2023-04-16 00:22:21 +02:00
Kawe Mazidjatari
a857403b9e Fix type conversion warning in netconsole tool 2023-04-03 14:51:18 +02:00
Kawe Mazidjatari
5aea2f4261 RCON system upgrade
RCON upgrade with additional logging system improvements:
* Netconsole's can now log received messages in color, even when the RCON server has ANSI colors disabled; logs are fully composed locally.
* RCON server now also sends the log type over the wire, along with the (already existing) context.
* SDK logging code is now shared with the standalone netconsole application.
* Improved logging readability for the standalone netconsole application.
2023-03-27 02:01:48 +02:00
Kawe Mazidjatari
793fcd62f2 End of logger refactor
Changed all loggers to use the internal 'CoreMsg/CoreMsgV' functions. Significantly reduced duplicate code and CPU time. Code is also much more robust.

* Code now only acquires mutex lock when the actual logging part takes place.
* Code now only checks and strip ANSI rows if its enabled to begin with.
* Code now supports setting log levels, which ultimately could be tweaked with a cvar.
* Changed logger and file names to be more readable.

TODO:
* The RCON protocol has to be modified to accommodate these changes.
2023-03-26 16:09:05 +02:00
Kawe Mazidjatari
8ed5a3a695 Connect RCON to localhost by machine name
Connect to local host using machine name when ip is set to 'localhost'.
2023-01-29 17:12:33 +01:00
Kawe Mazidjatari
b98eee0268 RCON system refactor and improvements
* Use game's CNetAdr RCON and socket creator.
* Add support for constructing host from [ip]:port format in the netconsole client.
* Pass 'netadr_t' parameter by reference to 'CSocketCreator::OnSocketAccepted'.
2023-01-29 15:24:24 +01:00
Kawe Mazidjatari
4b1c5dd5a3 RCON system light refactor
* Used 'htonl'/'ntohl' for constructing the length prefix.
* Used static socket/address members instead of pointers.
* Used const qualifier where possible.
* Changed length prefix field type to 'u_long'.
* Removed extraneous include.
* Properly escaped percentage characters on the RCON game client for the ImGui console.
2022-11-14 21:00:41 +01:00
Kawe Mazidjatari
656b0be3ec Improve threading (work in progress)
* Only run '_DownloadPlaylists_f()' in the main thread, schedule for next frame if we aren't in the main thread. (this should fix crash cases related to disconnecting from the game).

* Locked read/write to CBrowser members (thread for obtaining the server list is detached, but once the 'slow' post operation in this thread is complete, mutex lock is acquired (locking the render thread if the browser is active) to set the string members of CBrowser, this operation is very fast as we only set the string and the color after the http post operation (this never caused a crash, but the behavior without any lock mechanism is technically undefined regardless).

* Obtain the host name dynamically from the ConVar 'pylon_matchmaking_hostname' (atomic operation). Initial approach was deleting the whole master server pointer just to construct a new httpclient object..
2022-08-27 18:57:56 +02:00
Kawe Mazidjatari
619ac76452 Implement client rcon send log request
If 'cl_rcon_request_sendlogs' is set, the netconsole will request the server to send console logs to the rcon client after successful auth.
2022-08-17 11:50:40 +02:00
Kawe Mazidjatari
3c3da82154 Additional code improvements
* Removed some unused signatures.
* Named 2 CBaseFileSystem methods, and applied them to 'MOD_ProcessPakQueue()'.
* Renamed 'qword_1671061C8' to 'g_pMTVFTaskItem'.
* Renamed 'g_pMapVPKCache' to 'g_szMTVFItemName'.
* Only set first byte to 0 in 'g_szMTVFItemName' (actual size is 0x100, not 0x40).
2022-08-16 21:42:57 +02:00
Kawe Mazidjatari
88b3336758 Many small code improvements and optimizations
* Use c++ methods as much as possible.
* Use enum types for accessing NavMesh objects from array.
* Use size_t for for loops when testing against size types.
* Don't compute strlen twice of more on the same string.
* Don't use unnecessary c string casts if there is a method with a std::string overload.
* Don't create string objects from string pointers if we could use them directly.
* Don't initialize RCON password twice on each change, and don't set if the new password equals the old.
2022-08-11 11:07:45 +02:00
Kawe Mazidjatari
329621c6ad Move all public headers into root of 'public' 2022-08-09 17:18:07 +02:00
Kawe Mazidjatari
9ba5e63ada Add max size bounds for PayLoadLen when setting size of m_RecvBuffer
Should technically never fail, but in case it does it won't crash the application.
2022-08-03 18:41:25 +02:00
Kawe Mazidjatari
5bd6432862 Additional RCON system cleanup 2022-08-03 09:32:48 +02:00
Kawe Mazidjatari
9775fc4bba RCON system overhaul
* Implemented robust length-prefix framing logic for non-blocking sockets (previously used character sequences to determine length, but you cannot use character sequences on protocol buffers as its binary data. This logic should fix all problems regarding some commands not getting networked properly to the server and stuff not getting printed on the client).
* Increased buffer size to std::vector::max_size when netconsole is authenticated (MAX_NETCONSOLE_INPUT_LEN still remains enforced on accepted but not authenticated connections to prevent attackers from crashing the server).
* Process max 1024 bytes each recv buffer iteration.
* Additional optimizations and cleanup.
2022-08-02 23:58:43 +02:00
Kawe Mazidjatari
5795d15c83 Netconsole and ConVar improvements
Implemented StringSplit() (split string with a delimiter, and stop splitting after either the last delimiter has been reached, or nMax, so when nMax is 2, then 'SET mat_sky_color 255 255 0 255' gets split into: "SET" "mat_sky_color" "255 255 0 255").

Netconsole now sends ConVar's/ConCommands and values separately with use of StringSplit.

ConVar now uses internal ChangeStringValue (this runs the callback).
2022-07-31 17:07:35 +02:00