1- using System . Text ;
2- using CounterStrikeSharp . API . Core ;
1+ using CounterStrikeSharp . API . Core ;
32using CounterStrikeSharp . API . Core . Attributes ;
43using CounterStrikeSharp . API . Core . Attributes . Registration ;
5- using CounterStrikeSharp . API . Modules . Utils ;
6- using System . Net . Http ;
7- using System . Threading . Tasks ;
84using Newtonsoft . Json . Linq ;
95using CounterStrikeSharp . API ;
106
@@ -19,10 +15,12 @@ public class SteamUserInfo
1915 public int CSGOPlaytime { get ; set ; }
2016 public bool IsPrivate { get ; set ; }
2117 public bool HasPrime { get ; set ; }
18+ public bool IsTradeBanned { get ; set ; }
19+ public bool IsGameBanned { get ; set ; }
2220 }
2321
2422 public override string ModuleName => "Steam Restrict" ;
25- public override string ModuleVersion => "1.0 .0" ;
23+ public override string ModuleVersion => "1.1 .0" ;
2624 public override string ModuleAuthor => "K4ryuu" ;
2725
2826 public override void Load ( bool hotReload )
@@ -103,6 +101,32 @@ private async Task<SteamUserInfo> FetchSteamUserInfo(CCSPlayerController player)
103101 {
104102 Server . ExecuteCommand ( $ "kickid { player . UserId } \" You have been kicked for not meeting the minimum requirements.\" ") ;
105103 }
104+
105+ string tradeBanUrl = $ "https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key={ steamWebAPIKey } &steamids={ steamId } ";
106+ HttpResponseMessage tradeBanResponse = await httpClient . GetAsync ( tradeBanUrl ) ;
107+
108+ if ( tradeBanResponse . IsSuccessStatusCode )
109+ {
110+ string tradeBanJson = await tradeBanResponse . Content . ReadAsStringAsync ( ) ;
111+ ParseTradeBanStatus ( tradeBanJson , userInfo ) ;
112+ }
113+ else
114+ {
115+ userInfo . IsTradeBanned = false ;
116+ }
117+
118+ string gameBanUrl = $ "https://api.steampowered.com/ISteamUser/GetUserGameBan/v1/?key={ steamWebAPIKey } &steamids={ steamId } ";
119+ HttpResponseMessage gameBanResponse = await httpClient . GetAsync ( gameBanUrl ) ;
120+
121+ if ( gameBanResponse . IsSuccessStatusCode )
122+ {
123+ string gameBanJson = await gameBanResponse . Content . ReadAsStringAsync ( ) ;
124+ ParseGameBanStatus ( gameBanJson , userInfo ) ;
125+ }
126+ else
127+ {
128+ userInfo . IsGameBanned = false ;
129+ }
106130 }
107131
108132 return userInfo ;
@@ -134,6 +158,16 @@ private bool IsRestrictionViolated(SteamUserInfo userInfo)
134158 isViolated = true ;
135159 }
136160
161+ if ( CFG . config . BlockTradeBanned && userInfo . IsTradeBanned )
162+ {
163+ isViolated = true ;
164+ }
165+
166+ if ( CFG . config . BlockGameBanned && userInfo . IsGameBanned )
167+ {
168+ isViolated = true ;
169+ }
170+
137171 return isViolated ;
138172 }
139173
@@ -202,5 +236,43 @@ private void ParseSteamUserInfo(string json, SteamUserInfo userInfo)
202236 Console . WriteLine ( $ "Error parsing Steam user info: { ex . Message } ") ;
203237 }
204238 }
239+
240+ private void ParseTradeBanStatus ( string json , SteamUserInfo userInfo )
241+ {
242+ try
243+ {
244+ JObject data = JObject . Parse ( json ) ;
245+ JArray playerBans = ( data [ "players" ] as JArray ) ! ;
246+
247+ if ( playerBans != null && playerBans . Count > 0 )
248+ {
249+ var playerBan = playerBans [ 0 ] ;
250+ userInfo . IsTradeBanned = ( bool ) playerBan [ "CommunityBanned" ] ! ;
251+ }
252+ }
253+ catch ( Exception ex )
254+ {
255+ Console . WriteLine ( $ "Error parsing trade ban status: { ex . Message } ") ;
256+ }
257+ }
258+
259+ private void ParseGameBanStatus ( string json , SteamUserInfo userInfo )
260+ {
261+ try
262+ {
263+ JObject data = JObject . Parse ( json ) ;
264+ JArray userGameBans = ( data [ "players" ] as JArray ) ! ;
265+
266+ if ( userGameBans != null && userGameBans . Count > 0 )
267+ {
268+ var userGameBan = userGameBans [ 0 ] ;
269+ userInfo . IsGameBanned = ( bool ) userGameBan [ "IsGameBanned" ] ! ;
270+ }
271+ }
272+ catch ( Exception ex )
273+ {
274+ Console . WriteLine ( $ "Error parsing game ban status: { ex . Message } ") ;
275+ }
276+ }
205277 }
206278}
0 commit comments