1+ using System . Diagnostics . CodeAnalysis ;
2+ using CounterStrikeSharp . API ;
3+ using CounterStrikeSharp . API . Core ;
4+ using CounterStrikeSharp . API . Core . Attributes . Registration ;
5+ using CounterStrikeSharp . API . Modules . Utils ;
6+ using System . Text . Json . Serialization ;
7+ using CounterStrikeSharp . API . Modules . Admin ;
8+ using CounterStrikeSharp . API . Modules . Commands ;
9+ using CounterStrikeSharp . API . Modules . Cvars ;
10+ using CounterStrikeSharp . API . Modules . Entities ;
11+ using CounterStrikeSharp . API . Modules . Memory ;
12+
13+ namespace BasicAdmin ;
14+
15+ internal struct OriginalVec
16+ {
17+ internal Vector Position ;
18+ internal QAngle Rotation ;
19+ internal Vector Velocity ;
20+ }
21+
22+ public class BasicAdmin : BasePlugin , IPluginConfig < BasicAdminConfig >
23+ {
24+ public override string ModuleName => "BasicAdmin" ;
25+ public override string ModuleAuthor => "livevilog" ;
26+ public override string ModuleVersion => "0.1.0" ;
27+
28+ public BasicAdminConfig Config { get ; set ; } = new ( ) ;
29+
30+ private static readonly Dictionary < CCSPlayerController , OriginalVec > OriginalPositions = new ( ) ;
31+
32+
33+ public void OnConfigParsed ( BasicAdminConfig config )
34+ {
35+ this . Config = config ;
36+ }
37+
38+ public override void Load ( bool hotReload )
39+ { }
40+
41+ [ ConsoleCommand ( "css_map" , "Change map." ) ]
42+ [ CommandHelper ( 1 , "<mapname>" ) ]
43+ [ RequiresPermissions ( "@css/changemap" ) ]
44+ public void OnMapCommand ( CCSPlayerController ? caller , CommandInfo info )
45+ {
46+ var map = info . GetArg ( 1 ) ;
47+
48+ if ( ! Server . IsMapValid ( map ) )
49+ {
50+ info . ReplyToCommand ( FormatMessage ( $ "Map { map } not found.") ) ;
51+ return ;
52+ }
53+
54+ Server . PrintToChatAll ( FormatMessage ( $ "Changing map to { map } .") ) ;
55+
56+ AddTimer ( 5f , ( ) =>
57+ {
58+ Server . ExecuteCommand ( $ "changelevel { map } ") ;
59+ } ) ;
60+ }
61+
62+ [ ConsoleCommand ( "css_kick" , "Kicks a player from the server." ) ]
63+ [ CommandHelper ( 1 , "<#userid or name> [reason]" ) ]
64+ [ RequiresPermissions ( "@css/kick" ) ]
65+ public void OnKickCommand ( CCSPlayerController ? caller , CommandInfo info )
66+ {
67+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
68+ {
69+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
70+ return ;
71+ }
72+
73+ var reason = info . GetArg ( 2 ) ;
74+
75+ ServerUtils . KickPlayer ( player ! . PlayerName , reason ) ;
76+ }
77+
78+ [ ConsoleCommand ( "css_slay" , "Slay a player." ) ]
79+ [ CommandHelper ( 1 , "<#userid or name>" ) ]
80+ [ RequiresPermissions ( "@css/slay" ) ]
81+ public void OnSlayCommand ( CCSPlayerController ? caller , CommandInfo info )
82+ {
83+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
84+ {
85+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
86+ return ;
87+ }
88+
89+ player ! . Pawn . Value . CommitSuicide ( false , true ) ;
90+ if ( ! Config . HideActivity )
91+ Server . PrintToChatAll ( $ "{ caller ! . PlayerName } slayed { player ! . PlayerName } .") ;
92+ }
93+
94+ [ ConsoleCommand ( "css_give" , "Give a player an item." ) ]
95+ [ CommandHelper ( 2 , "<#userid or name> <item name>" ) ]
96+ [ RequiresPermissions ( "@css/kick" ) ]
97+ public void OnGiveCommand ( CCSPlayerController ? caller , CommandInfo info )
98+ {
99+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
100+ {
101+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
102+ return ;
103+ }
104+
105+ player ! . GiveNamedItem ( info . GetArg ( 2 ) ) ;
106+
107+ if ( ! Config . HideActivity )
108+ Server . PrintToChatAll ( $ "{ caller ! . PlayerName } gave { player ! . PlayerName } { info . GetArg ( 2 ) } .") ;
109+ }
110+
111+ [ ConsoleCommand ( "css_swap" , "Swap a player." ) ]
112+ [ CommandHelper ( 1 , "<#userid or name>" ) ]
113+ [ RequiresPermissions ( "@css/kick" ) ]
114+ public void OnSwapCommand ( CCSPlayerController ? caller , CommandInfo info )
115+ {
116+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
117+ {
118+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
119+ return ;
120+ }
121+
122+ if ( ( int ) CsTeam . Spectator == player ! . TeamNum )
123+ {
124+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } is a spectator.") ) ;
125+ return ;
126+ }
127+
128+ var isCs = player ! . TeamNum == ( int ) CsTeam . CounterTerrorist ;
129+
130+ player ! . ChangeTeam ( isCs ? CsTeam . Terrorist : CsTeam . CounterTerrorist ) ;
131+
132+ if ( ! Config . HideActivity )
133+ Server . PrintToChatAll ( $ "{ caller ! . PlayerName } swapped { player ! . PlayerName } .") ;
134+ }
135+
136+ [ ConsoleCommand ( "css_spec" , "Change a player to spec." ) ]
137+ [ CommandHelper ( 1 , "<#userid or name>" ) ]
138+ [ RequiresPermissions ( "@css/kick" ) ]
139+ public void OnSpecCommand ( CCSPlayerController ? caller , CommandInfo info )
140+ {
141+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
142+ {
143+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
144+ return ;
145+ }
146+
147+ player ! . ChangeTeam ( CsTeam . Spectator ) ;
148+
149+ if ( ! Config . HideActivity )
150+ Server . PrintToChatAll ( $ "{ caller ! . PlayerName } swapped { player ! . PlayerName } to spec.") ;
151+ }
152+
153+ // [ConsoleCommand("css_respawn", "Respawn a dead player.")]
154+ // [CommandHelper(1, "<#userid or name>")]
155+ // [RequiresPermissions("@css/kick")]
156+ // public void OnRespawnCommand(CCSPlayerController? caller, CommandInfo info)
157+ // {
158+ // if (!ServerUtils.GetTarget(info.GetArg(1), out var player))
159+ // {
160+ // info.ReplyToCommand(FormatMessage($"Target {info.GetArg(1)} not found."));
161+ // return;
162+ // }
163+ //
164+ // info.ReplyToCommand(FormatMessage("Not implemented yet."));
165+ // }
166+
167+ [ ConsoleCommand ( "css_say" , "Say to all players." ) ]
168+ [ CommandHelper ( 1 , "<message>" ) ]
169+ [ RequiresPermissions ( "@css/vote" ) ]
170+ public void OnAdminSayCommand ( CCSPlayerController ? caller , CommandInfo info )
171+ {
172+ Server . PrintToChatAll ( FormatAdminMessage ( info . GetCommandString [ info . GetCommandString . IndexOf ( ' ' ) ..] ) ) ;
173+ }
174+
175+ [ ConsoleCommand ( "css_psay" , "Say to all players." ) ]
176+ [ CommandHelper ( 2 , "<#userid or name> <message>" ) ]
177+ [ RequiresPermissions ( "@css/vote" ) ]
178+ public void OnAdminPrivateSayCommand ( CCSPlayerController ? caller , CommandInfo info )
179+ {
180+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
181+ {
182+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
183+ return ;
184+ }
185+
186+ var range = info . GetArg ( 1 ) . Length + info . GetArg ( 2 ) . Length + 3 ;
187+ var message = info . GetCommandString [ range ..] ;
188+
189+ info . ReplyToCommand ( FormatAdminMessage ( $ "({ player ! . PlayerName } ) { message } ") ) ;
190+ player ! . PrintToChat ( FormatAdminMessage ( $ "({ caller ! . PlayerName } ) { message } ") ) ;
191+ }
192+
193+ [ ConsoleCommand ( "css_csay" , "Say to all players (in center)." ) ]
194+ [ CommandHelper ( 1 , "<message>" ) ]
195+ [ RequiresPermissions ( "@css/vote" ) ]
196+ public void OnAdminCenterSayCommand ( CCSPlayerController ? caller , CommandInfo info )
197+ {
198+ ServerUtils . PrintToCenterAll ( FormatAdminMessage ( info . GetCommandString [ info . GetCommandString . IndexOf ( ' ' ) ..] ) ) ;
199+ }
200+
201+ [ ConsoleCommand ( "css_hsay" , "Say to all players (in hud)." ) ]
202+ [ CommandHelper ( 1 , "<message>" ) ]
203+ [ RequiresPermissions ( "@css/vote" ) ]
204+ public void OnAdminHudSayCommand ( CCSPlayerController ? caller , CommandInfo info )
205+ {
206+ VirtualFunctions . ClientPrintAll (
207+ HudDestination . Alert ,
208+ FormatAdminMessage ( info . GetCommandString [ info . GetCommandString . IndexOf ( ' ' ) ..] ) ,
209+ 0 , 0 , 0 , 0 ) ;
210+ }
211+
212+ [ ConsoleCommand ( "css_extend" , "Respawn a dead player." ) ]
213+ [ CommandHelper ( 1 , "<minutes>" ) ]
214+ [ RequiresPermissions ( "@css/changemap" ) ]
215+ public void OnExtendCommand ( CCSPlayerController ? caller , CommandInfo info )
216+ {
217+ if ( ! int . TryParse ( info . GetArg ( 1 ) , out var time ) )
218+ {
219+ info . ReplyToCommand ( FormatMessage ( $ "Invalid time { info . GetArg ( 1 ) } ") ) ;
220+ return ;
221+ }
222+
223+ var timelimit = ConVar . Find ( "mp_timelimit" ) ;
224+ timelimit ! . SetValue ( timelimit . GetPrimitiveValue < float > ( ) + time ) ;
225+
226+ if ( ! Config . HideActivity )
227+ Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } extended the map.") ) ;
228+ }
229+
230+ [ ConsoleCommand ( "css_rr" , "Restart game." ) ]
231+ [ ConsoleCommand ( "css_restartgame" , "Restart game." ) ]
232+ [ RequiresPermissions ( "@css/changemap" ) ]
233+ public void OnRestartGameCommand ( CCSPlayerController ? caller , CommandInfo info )
234+ {
235+ Server . ExecuteCommand ( "mp_restartgame 1" ) ;
236+
237+ if ( ! Config . HideActivity )
238+ Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } restarted the game.") ) ;
239+ }
240+
241+ [ ConsoleCommand ( "css_bury" , "Bury a player." ) ]
242+ [ CommandHelper ( 1 , "<#userid or name>" ) ]
243+ [ RequiresPermissions ( "@css/changemap" ) ]
244+ public void OnBuryCommand ( CCSPlayerController ? caller , CommandInfo info )
245+ {
246+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) || player ! . Pawn . Value . LifeState != ( int ) LifeState_t . LIFE_ALIVE )
247+ {
248+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
249+ return ;
250+ }
251+
252+ if ( ! OriginalPositions . ContainsKey ( player ! ) )
253+ OriginalPositions [ player ! ] = new OriginalVec ( )
254+ {
255+ Position = player ! . AbsOrigin ! ,
256+ Rotation = player ! . AbsRotation ! ,
257+ Velocity = player ! . AbsVelocity
258+ } ;
259+
260+ var newPos = new Vector ( player ! . Pawn . Value . AbsOrigin ! . X , player ! . Pawn . Value . AbsOrigin ! . Y ,
261+ player ! . Pawn . Value . AbsOrigin ! . Z - 10f ) ;
262+
263+ player ! . Pawn . Value . Teleport ( newPos , player ! . AbsRotation ! , player ! . AbsVelocity ) ;
264+
265+ if ( ! Config . HideActivity )
266+ Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } buried { player ! . PlayerName } .") ) ;
267+ }
268+
269+ [ ConsoleCommand ( "css_unbury" , "Bury a player." ) ]
270+ [ CommandHelper ( 1 , "<#userid or name>" ) ]
271+ [ RequiresPermissions ( "@css/changemap" ) ]
272+ public void OnUnburyCommand ( CCSPlayerController ? caller , CommandInfo info )
273+ {
274+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) || ! OriginalPositions . ContainsKey ( player ! ) )
275+ {
276+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found or is not buried.") ) ;
277+ return ;
278+ }
279+
280+ player ! . Pawn . Value . Teleport ( OriginalPositions [ player ! ] . Position , OriginalPositions [ player ! ] . Rotation , OriginalPositions [ player ! ] . Velocity ) ;
281+
282+ if ( ! Config . HideActivity )
283+ Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } unburied { player ! . PlayerName } .") ) ;
284+
285+ OriginalPositions . Remove ( player ! ) ;
286+ }
287+
288+ [ ConsoleCommand ( "css_disarm" , "Disarm a player." ) ]
289+ [ CommandHelper ( 1 , "<#userid or name>" ) ]
290+ [ RequiresPermissions ( "@css/changemap" ) ]
291+ public void OnDisarmCommand ( CCSPlayerController ? caller , CommandInfo info )
292+ {
293+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) || ! OriginalPositions . ContainsKey ( player ! ) )
294+ {
295+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found or is not buried.") ) ;
296+ return ;
297+ }
298+
299+ foreach ( var weapon in player ! . Pawn . Value . WeaponServices . MyWeapons )
300+ {
301+ weapon . Value . Remove ( ) ;
302+ }
303+
304+ if ( ! Config . HideActivity )
305+ Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } disarmed { player ! . PlayerName } .") ) ;
306+ }
307+
308+ [ ConsoleCommand ( "css_hp" , "Change a player's HP." ) ]
309+ [ CommandHelper ( 2 , "<#userid or name> <health>" ) ]
310+ [ RequiresPermissions ( "@css/slay" ) ]
311+ public void OnHealthCommand ( CCSPlayerController ? caller , CommandInfo info )
312+ {
313+ if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) || int . TryParse ( info . GetArg ( 2 ) , out var health ) )
314+ {
315+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found or is not buried.") ) ;
316+ return ;
317+ }
318+
319+ player ! . Pawn . Value . Health = health ;
320+
321+ if ( ! Config . HideActivity )
322+ Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } changed { player ! . PlayerName } 's health to { health } .") ) ;
323+ }
324+
325+ // [ConsoleCommand("css_vote", "Respawn a dead player.")]
326+ // [CommandHelper(1, "<#userid or name>")]
327+ // // [RequiresPermissions("@css/vote")]
328+ // public void OnVoteCommand(CCSPlayerController? caller, CommandInfo info)
329+ // {
330+ // if (!ServerUtils.GetTarget(info.GetArg(1), out var player))
331+ // {
332+ // info.ReplyToCommand(FormatMessage($"Target {info.GetArg(1)} not found."));
333+ // return;
334+ // }
335+ //
336+ // player!.PlayerPawn.Value.LifeState = (int) LifeState_t.LIFE_ALIVE;;
337+ // }
338+
339+ private static string FormatMessage ( string message ) => $ " { ChatColors . Lime } [BasicAdmin]{ ChatColors . Default } { message } ";
340+ private string FormatAdminMessage ( string message ) => $ " { Config . AdminTag } { message } ";
341+ }
0 commit comments