34 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
94d30b759d Fix potential security flaws caused by uncontrolled format strings
Make sure format strings are string literals to avoid an uncontrolled format string situation.
2023-04-08 20:13:06 +02:00
Kawe Mazidjatari
53c693f6e1 Avoid creating a unnecessary copy
Avoid copying the string out of the vector.
2023-04-03 11:21:31 +02:00
Kawe Mazidjatari
e1f0e72af4 /W4: Fix type demotion warnings
Explicitly demote to 'int' to suppress pesky compiler warnings.
2023-04-02 16:03:01 +02:00
Kawe Mazidjatari
03bc4e71c4 Ban system improvements
* Refactored code; kick & ban now share the same function.
* Kick & ban will now log a confirmation to the console.
* Players in refused list will no longer get banned, this was initially performed to keep load off the master server, but this turned out to be excessive. It also caused the side effect of having players banned even if their bans have been removed from the master server.
2023-02-23 23:55:55 +01:00
rexx
9d2ffa6e26
bansystem: fix incorrect allocation size causing OOB memory write 2023-01-14 15:35:46 +00:00
Kawe Mazidjatari
277e05b2b8 Improve logging throughout SDK
Used proper enum for context. The low level tier1 stuff should print in COMMON.
Also added newlines where missing, the logging system will undergo a change where a newline will only be appended if we are logging in the same context without a newline.
2022-11-25 23:03:56 +01:00
Kawe Mazidjatari
793c2e8e50 Rename 'Reputation_t' enumerant 2022-09-20 02:04:25 +02:00
Kawe Mazidjatari
58cadb529b 'Bad behaving player' systems improvement
* Use 'CClient::Disconnect(..)' for all kicks and bans (this automatically clears the entire CClient slot, and removes the net channel).
* Only force disconnect when 'CNetChan::m_nSignonState' has a value that is not NULL.
* Clear the ServerPlayer slot on 'CClient::Disconnect(..)' and 'CClient::Connect(..)'.
* Only kick player for NetChannel overflow when value exceeds processing budget (not equals).
2022-09-19 01:28:43 +02:00
Kawe Mazidjatari
fdd74aa622 Implement net message processing budget
Implement net message process budget (channel gets removed if value is exceeded).
Use 'net_processLimit' to enable the implementation on the server. It will get enabled by default after testing and some cleanup. This helps against people trying to slow the server down by spamming net messages with a higher rate, e.g. using 'bind "mousewheel_up" "status"'.
2022-09-18 23:19:50 +02:00
Kawe Mazidjatari
a68f55dac0 Move unban logic to CBanSystem and expose to Squirrel
New unban function in SERVER context 'UnbanPlayer(string criteria)'.
2022-09-16 00:51:35 +02:00
Kawe Mazidjatari
9c9843a0fc Centralize kick/ban wrappers to CBanSystem and add new server functions for kicking/banning players 2022-09-15 23:13:37 +02:00
Kawe Mazidjatari
729475c74c Light cleanup
Use NO_ERROR instead of NULL for error code parameter passed to Error(..).
2022-09-14 01:14:51 +02:00
Kawe Mazidjatari
3d6d6644bd Logging bug fix and error handling improvements
* Replaced the boolean 'fatal' parameter with a error code parameter, anything non-null will prompt a message (fatal) and terminate the process with given error code.
* Fixed bug where the global ostreamsink for spdlog did NOT get cleared in 'SQVM_PrintFunc' when cvar 'sq_showvmoutput' was < 3. Moved to global scope.
* Added error message for when detouring the process has failed, with the error code.
* Only call 'Plat_GetProcessUpTime()' once per log, (improves performance and fixes bug where the error message box would show a different time stamp than what is logged into the console or file).
* All TIER0 loggers only log to notify and console when the SDK engine has fully initialized and detoured all functions.
2022-09-14 00:39:38 +02:00
Kawe Mazidjatari
34a06147d7 Fix spelling errors
Overall spelling improvements and cleanup..
2022-09-09 19:47:31 +02:00
Kawe Mazidjatari
dea5f166db Use internal file system to load/save banned list.
'banlist.json' is now read from all searchpaths.
'banned.json' is only written to "PLATFORM".
2022-09-01 01:07:16 +02:00
Kawe Mazidjatari
d9709cfb1e Flip order of assignment 2022-08-31 18:20:11 +02:00
Kawe Mazidjatari
1285d15623 Ban system and authentication improvements
* Fixed bug where multiple of the same entries get added to the global ban/refuse list.
* Fixed bug where we still use the client instance after deleting it in 'CBanSystem::BanListCheck()'.
* Load banlist at a later state (not at construction of class), this is needed for a future change of adapting the 'business' code to feature the game's FileSystem.
* CServer cleanup.
* More detailed ban messages (banned, added to refused list, removed from slot, etc..).
* Use localization key for banned message ("#Valve_Reject_Banned").
* Add const qualifiers to all CPylon methods.

Note:
* This commit requires changes on the master server, these changes are already performed, however the new master server isn't live yet until we publish the new release.
2022-08-30 12:07:09 +02:00
Kawe Mazidjatari
71c5ff2416 Clear banlist if valid if we attempt to load it
When we 'reload' the banlist, and have a valid file, none of the current bans in the vector will get overwritten. We clear the entire vector if valid, and rebuild it if the file is valid. if no file is found, or if access to file is denied, we assume the server operator wants all bans dropped.
2022-08-29 17:03:14 +02:00
Kawe Mazidjatari
afad5b92ec Rename 'OriginID' to 'NucleusID'
Nucleus ID is the official internal term for the platform user id used by the OriginSDK.
2022-08-29 15:59:12 +02:00
Kawe Mazidjatari
38c94eda27 Banlist writing optimizations
* Only write if there is something to write.
* Don't write each iteration, write after the loops are finished.
2022-08-28 00:11:33 +02:00
Kawe Mazidjatari
532b4125d5 More thread safety improvements
* Run 'CHostState::Think()' in the main thread.
* Construct 'NetGameServer_t' objects in main thread before dispatching (TODO: browser).
* Dispatch the call to 'CBanSystem::AddConnectionRefuse' from 'SV_IsClientBanned' to the main thread if we aren't main.
* Return bool for CBanSystem::AddEntry and CBanSystem::DeleteEntry for future optimizations (next commit).
2022-08-27 23:45:58 +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
cdfc557452 CBanSystem optimizations
Pass by constant reference, const qualifiers, size_t loop iterators instead of implicit cast to int, extraneous cast to c-string, etc..
2022-08-09 17:57:43 +02:00
Kawe Mazidjatari
efd92f8ebc Move 'bansystem' from 'public' to 'networksystem' 2022-08-09 17:34:10 +02:00