43 Commits

Author SHA1 Message Date
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
Amos
d909878624 Optimizations 2022-06-08 14:03:04 +02:00
Kawe Mazidjatari
326b751934 Light optimizations 2022-06-07 13:46:18 +02:00
Kawe Mazidjatari
61c7dbf5c1 Fix memory leaks 2022-05-28 23:05:10 +02:00
Kawe Mazidjatari
0549134133 Fix netconsole bug 2022-05-07 03:52:33 +02:00
Kawe Mazidjatari
57e6dc4280 Improve RCON system
* Buffers are now send properly from the game client and netconsole client (running scripts and executing command's/convar's now work properly).
* Removed 'PASS' string check on server and only rely on 'SERVERDATA_REQUEST_AUTH' enum for auth queries (should make heavy abuse even harder).
2022-05-07 03:06:19 +02:00
Amos
cf92d64a27 Use unicode character set instead of multi-byte 2022-03-04 16:06:36 +01:00
Amos
23f37bfa50 RCON QOL improvements 2022-02-24 16:44:33 +01:00
Amos
10174a6206 Initial game client RCON implementation 2022-02-14 23:16:24 +01:00
Amos
04be5e0e64 Use WSA error codes for startup/shutdown 2022-02-14 02:33:13 +01:00
Amos
a5b3b2dea4 Update comment blocks 2022-02-13 15:16:09 +01:00
Amos
9c8644e645 Implement stream serialization/deserialization in RCON server and client 2022-02-13 15:10:38 +01:00
Amos
ad65ff1f63 Small change 2022-02-09 21:29:34 +01:00
Amos
a5da2e81bf RCON improvements (see description)
** SERVER **
* Close redundant connections if max sockets have been reached.
* Ban if client keeps spamming without authing first (ignoring message).
* Check for whitelisted address before issuing bans (whitelisted address in ConVar 'sv_rcon_whitelist_address' will never get banned or get its connection terminated.
* Transmit SQVM and DevMsg logs over the wire to the net console.

** NETCON **
* IPv6 support.
* Close connection properly after FIN request.
* Prompt user to reconnect after connection has been terminated instead of closing the application.
* Add proper quit command.

** SDKLAUNCHER **
* Rename to 'launcher.exe' to describe its purpose better. Our logo gets printed nice and large on the console during startup.

** SDK **
* Cleanup.
2022-02-08 16:32:00 +01:00
Amos
7fff22ccec Slight cleanup 2022-02-06 17:27:47 +01:00
Amos
bba0120e88 Fix small bug in netconsole
Changed member params but forgot to change thread invocation params
2022-02-06 17:07:27 +01:00
Amos
c187bed4c5 RCON implementation (see description)
* Fully rewritten protocol agnostic CNetAdr class
* Fully rebuilded legacy CNetAdr class
* Fully rebuilded dual-stack CSocketCreator class
* New project "netconsole" added (lightweight netconsole for RCON)

RCON is still work in progress
2022-02-06 16:48:52 +01:00