6
6
7
7
using System . Text . Json . Serialization ;
8
8
using Microsoft . Extensions . Logging ;
9
+ using Steamworks ;
10
+ using CounterStrikeSharp . API . Modules . Cvars ;
9
11
10
12
namespace KitsuneSteamRestrict ;
11
13
12
14
public class PluginConfig : BasePluginConfig
13
15
{
16
+ [ JsonPropertyName ( "LogProfileInformations" ) ]
17
+ public bool LogProfileInformations { get ; set ; } = true ;
18
+
14
19
[ JsonPropertyName ( "SteamWebAPI" ) ]
15
20
public string SteamWebAPI { get ; set ; } = "" ;
16
21
@@ -54,7 +59,7 @@ public class PluginConfig : BasePluginConfig
54
59
public DatabaseSettings DatabaseSettings { get ; set ; } = new DatabaseSettings ( ) ;
55
60
56
61
[ JsonPropertyName ( "ConfigVersion" ) ]
57
- public override int Version { get ; set ; } = 2 ;
62
+ public override int Version { get ; set ; } = 3 ;
58
63
}
59
64
60
65
public sealed class DatabaseSettings
@@ -88,7 +93,7 @@ public sealed class DatabaseSettings
88
93
public class SteamRestrictPlugin : BasePlugin , IPluginConfig < PluginConfig >
89
94
{
90
95
public override string ModuleName => "Steam Restrict" ;
91
- public override string ModuleVersion => "1.3.1 " ;
96
+ public override string ModuleVersion => "1.3.2 " ;
92
97
public override string ModuleAuthor => "K4ryuu, Cruze @ KitsuneLab" ;
93
98
public override string ModuleDescription => "Restrict certain players from connecting to your server." ;
94
99
@@ -120,7 +125,7 @@ public override void Load(bool hotReload)
120
125
if ( ! IsDatabaseConfigDefault ( ) )
121
126
{
122
127
var databaseService = new DatabaseService ( Config . DatabaseSettings ) ;
123
- _ = databaseService . EnsureTablesExistAsync ( ) ;
128
+ Task . Run ( databaseService . EnsureTablesExistAsync ) ;
124
129
}
125
130
126
131
RegisterListener < Listeners . OnGameServerSteamAPIActivated > ( ( ) => { g_bSteamAPIActivated = true ; } ) ;
@@ -198,44 +203,63 @@ private void OnPlayerConnectFull(CCSPlayerController player)
198
203
199
204
private void CheckUserViolations ( nint handle , ulong authorizedSteamID )
200
205
{
201
- SteamService steamService = new SteamService ( this ) ;
202
- steamService . FetchSteamUserInfo ( handle , authorizedSteamID ) ;
206
+ CSteamID cSteamID = new CSteamID ( authorizedSteamID ) ;
203
207
204
- SteamUserInfo ? userInfo = steamService . UserInfo ;
208
+ SteamUserInfo UserInfo = new SteamUserInfo
209
+ {
210
+ HasPrime = SteamGameServer . UserHasLicenseForApp ( cSteamID , ( AppId_t ) 624820 ) == EUserHasLicenseForAppResult . k_EUserHasLicenseResultHasLicense
211
+ || SteamGameServer . UserHasLicenseForApp ( cSteamID , ( AppId_t ) 54029 ) == EUserHasLicenseForAppResult . k_EUserHasLicenseResultHasLicense ,
212
+ CS2Level = new CCSPlayerController_InventoryServices ( handle ) . PersonaDataPublicLevel
213
+ } ;
205
214
206
- CCSPlayerController ? player = Utilities . GetPlayerFromSteamId ( authorizedSteamID ) ;
215
+ SteamService steamService = new SteamService ( this , UserInfo ) ;
207
216
208
- if ( player ? . IsValid == true && userInfo != null )
217
+ Task . Run ( async ( ) =>
209
218
{
210
- Logger . LogInformation ( $ "{ player . PlayerName } info:") ;
211
- Logger . LogInformation ( $ "CS2Playtime: { userInfo . CS2Playtime } ") ;
212
- Logger . LogInformation ( $ "CS2Level: { userInfo . CS2Level } ") ;
213
- Logger . LogInformation ( $ "SteamLevel: { userInfo . SteamLevel } ") ;
214
- if ( ( DateTime . Now - userInfo . SteamAccountAge ) . TotalSeconds > 30 )
215
- Logger . LogInformation ( $ "Steam Account Creation Date: { userInfo . SteamAccountAge : dd-MM-yyyy} ") ;
216
- else
217
- Logger . LogInformation ( $ "Steam Account Creation Date: N/A") ;
218
- Logger . LogInformation ( $ "HasPrime: { userInfo . HasPrime } ") ;
219
- Logger . LogInformation ( $ "HasPrivateProfile: { userInfo . IsPrivate } ") ;
220
- Logger . LogInformation ( $ "IsTradeBanned: { userInfo . IsTradeBanned } ") ;
221
- Logger . LogInformation ( $ "IsGameBanned: { userInfo . IsGameBanned } ") ;
222
- Logger . LogInformation ( $ "IsInSteamGroup: { userInfo . IsInSteamGroup } ") ;
223
-
224
- if ( IsRestrictionViolated ( player , userInfo ) )
225
- {
226
- Server . ExecuteCommand ( $ "kickid { player . UserId } \" You have been kicked for not meeting the minimum requirements.\" ") ;
227
- }
228
- else if ( ! IsDatabaseConfigDefault ( ) )
219
+ await steamService . FetchSteamUserInfo ( authorizedSteamID . ToString ( ) ) ;
220
+
221
+ SteamUserInfo ? userInfo = steamService . UserInfo ;
222
+
223
+ Server . NextWorldUpdate ( ( ) =>
229
224
{
230
- ulong steamID = player . AuthorizedSteamID ? . SteamId64 ?? 0 ;
225
+ CCSPlayerController ? player = Utilities . GetPlayerFromSteamId ( authorizedSteamID ) ;
231
226
232
- if ( steamID != 0 )
227
+ if ( player ? . IsValid == true && userInfo != null )
233
228
{
234
- var databaseService = new DatabaseService ( Config . DatabaseSettings ) ;
235
- Task . Run ( async ( ) => await databaseService . AddAllowedUserAsync ( steamID , Config . DatabaseSettings . TablePurgeDays ) ) ;
229
+ if ( Config . LogProfileInformations )
230
+ {
231
+ Logger . LogInformation ( $ "{ player . PlayerName } info:") ;
232
+ Logger . LogInformation ( $ "CS2Playtime: { userInfo . CS2Playtime } ") ;
233
+ Logger . LogInformation ( $ "CS2Level: { userInfo . CS2Level } ") ;
234
+ Logger . LogInformation ( $ "SteamLevel: { userInfo . SteamLevel } ") ;
235
+ if ( ( DateTime . Now - userInfo . SteamAccountAge ) . TotalSeconds > 30 )
236
+ Logger . LogInformation ( $ "Steam Account Creation Date: { userInfo . SteamAccountAge : dd-MM-yyyy} ({ ( int ) ( DateTime . Now - userInfo . SteamAccountAge ) . TotalDays } days ago)") ;
237
+ else
238
+ Logger . LogInformation ( $ "Steam Account Creation Date: N/A") ;
239
+ Logger . LogInformation ( $ "HasPrime: { userInfo . HasPrime } ") ;
240
+ Logger . LogInformation ( $ "HasPrivateProfile: { userInfo . IsPrivate } ") ;
241
+ Logger . LogInformation ( $ "IsTradeBanned: { userInfo . IsTradeBanned } ") ;
242
+ Logger . LogInformation ( $ "IsGameBanned: { userInfo . IsGameBanned } ") ;
243
+ Logger . LogInformation ( $ "IsInSteamGroup: { userInfo . IsInSteamGroup } ") ;
244
+ }
245
+
246
+ if ( IsRestrictionViolated ( player , userInfo ) )
247
+ {
248
+ Server . ExecuteCommand ( $ "kickid { player . UserId } \" You have been kicked for not meeting the minimum requirements.\" ") ;
249
+ }
250
+ else if ( ! IsDatabaseConfigDefault ( ) )
251
+ {
252
+ ulong steamID = player . AuthorizedSteamID ? . SteamId64 ?? 0 ;
253
+
254
+ if ( steamID != 0 )
255
+ {
256
+ var databaseService = new DatabaseService ( Config . DatabaseSettings ) ;
257
+ Task . Run ( async ( ) => await databaseService . AddAllowedUserAsync ( steamID , Config . DatabaseSettings . TablePurgeDays ) ) ;
258
+ }
259
+ }
236
260
}
237
- }
238
- }
261
+ } ) ;
262
+ } ) ;
239
263
}
240
264
241
265
private bool IsRestrictionViolated ( CCSPlayerController player , SteamUserInfo userInfo )
@@ -245,25 +269,50 @@ private bool IsRestrictionViolated(CCSPlayerController player, SteamUserInfo use
245
269
246
270
BypassConfig bypassConfig = _bypassConfig ?? new BypassConfig ( ) ;
247
271
PlayerBypassConfig ? playerBypassConfig = bypassConfig . GetPlayerConfig ( player . AuthorizedSteamID ? . SteamId64 ?? 0 ) ;
248
-
249
272
bool isPrime = userInfo . HasPrime ;
250
- var configChecks = new [ ]
273
+
274
+ if ( isPrime )
251
275
{
252
- ( isPrime && ( playerBypassConfig ? . BypassMinimumCS2Level ?? false ) , Config . MinimumCS2LevelPrime , userInfo . CS2Level ) ,
253
- ( ! isPrime && ( playerBypassConfig ? . BypassMinimumCS2Level ?? false ) , Config . MinimumCS2LevelNonPrime , userInfo . CS2Level ) ,
254
- ( isPrime && ( playerBypassConfig ? . BypassMinimumHours ?? false ) , Config . MinimumHourPrime , userInfo . CS2Playtime ) ,
255
- ( ! isPrime && ( playerBypassConfig ? . BypassMinimumHours ?? false ) , Config . MinimumHourNonPrime , userInfo . CS2Playtime ) ,
256
- ( isPrime && ( playerBypassConfig ? . BypassMinimumLevel ?? false ) , Config . MinimumLevelPrime , userInfo . SteamLevel ) ,
257
- ( ! isPrime && ( playerBypassConfig ? . BypassMinimumLevel ?? false ) , Config . MinimumLevelNonPrime , userInfo . SteamLevel ) ,
258
- ( playerBypassConfig ? . BypassMinimumSteamAccountAge ?? false , Config . MinimumSteamAccountAgeInDays , ( DateTime . Now - userInfo . SteamAccountAge ) . TotalDays ) ,
259
- ( Config . BlockPrivateProfile && ( playerBypassConfig ? . BypassPrivateProfile ?? false ) , 1 , userInfo . IsPrivate ? 0 : 1 ) ,
260
- ( Config . BlockTradeBanned && ( playerBypassConfig ? . BypassTradeBanned ?? false ) , 1 , userInfo . IsTradeBanned ? 0 : 1 ) ,
261
- ( Config . BlockGameBanned && ( playerBypassConfig ? . BypassGameBanned ?? false ) , 1 , userInfo . IsGameBanned ? 0 : 1 ) ,
262
- ( ! string . IsNullOrEmpty ( Config . SteamGroupID ) && ( playerBypassConfig ? . BypassSteamGroupCheck ?? false ) , 1 , userInfo . IsInSteamGroup ? 1 : 0 ) ,
263
- ( Config . BlockVACBanned && ( playerBypassConfig ? . BypassVACBanned ?? false ) , 1 , userInfo . IsVACBanned ? 0 : 1 ) ,
264
- } ;
276
+ if ( ! ( playerBypassConfig ? . BypassMinimumCS2Level ?? false ) && Config . MinimumCS2LevelPrime != - 1 && userInfo . CS2Level < Config . MinimumCS2LevelPrime )
277
+ return true ;
278
+
279
+ if ( ! ( playerBypassConfig ? . BypassMinimumHours ?? false ) && Config . MinimumHourPrime != - 1 && userInfo . CS2Playtime < Config . MinimumHourPrime )
280
+ return true ;
281
+
282
+ if ( ! ( playerBypassConfig ? . BypassMinimumLevel ?? false ) && Config . MinimumLevelPrime != - 1 && userInfo . SteamLevel < Config . MinimumLevelPrime )
283
+ return true ;
284
+ }
285
+ else
286
+ {
287
+ if ( ! ( playerBypassConfig ? . BypassMinimumCS2Level ?? false ) && Config . MinimumCS2LevelNonPrime != - 1 && userInfo . CS2Level < Config . MinimumCS2LevelNonPrime )
288
+ return true ;
289
+
290
+ if ( ! ( playerBypassConfig ? . BypassMinimumHours ?? false ) && Config . MinimumHourNonPrime != - 1 && userInfo . CS2Playtime < Config . MinimumHourNonPrime )
291
+ return true ;
292
+
293
+ if ( ! ( playerBypassConfig ? . BypassMinimumLevel ?? false ) && Config . MinimumLevelNonPrime != - 1 && userInfo . SteamLevel < Config . MinimumLevelNonPrime )
294
+ return true ;
295
+ }
296
+
297
+ if ( ! ( playerBypassConfig ? . BypassMinimumSteamAccountAge ?? false ) && Config . MinimumSteamAccountAgeInDays != - 1 && ( DateTime . Now - userInfo . SteamAccountAge ) . TotalDays < Config . MinimumSteamAccountAgeInDays )
298
+ return true ;
299
+
300
+ if ( Config . BlockPrivateProfile && ! ( playerBypassConfig ? . BypassPrivateProfile ?? false ) && userInfo . IsPrivate )
301
+ return true ;
302
+
303
+ if ( Config . BlockTradeBanned && ! ( playerBypassConfig ? . BypassTradeBanned ?? false ) && userInfo . IsTradeBanned )
304
+ return true ;
305
+
306
+ if ( Config . BlockGameBanned && ! ( playerBypassConfig ? . BypassGameBanned ?? false ) && userInfo . IsGameBanned )
307
+ return true ;
308
+
309
+ if ( ! string . IsNullOrEmpty ( Config . SteamGroupID ) && ! ( playerBypassConfig ? . BypassSteamGroupCheck ?? false ) && ! userInfo . IsInSteamGroup )
310
+ return true ;
311
+
312
+ if ( Config . BlockVACBanned && ! ( playerBypassConfig ? . BypassVACBanned ?? false ) && userInfo . IsVACBanned )
313
+ return true ;
265
314
266
- return configChecks . Any ( check => check . Item1 && check . Item2 != - 1 && check . Item3 < check . Item2 ) ;
315
+ return false ;
267
316
}
268
317
269
318
public bool IsDatabaseConfigDefault ( )
0 commit comments