Skip to content

Commit 3cfcabe

Browse files
committed
Fix sv_cheats permission, add action
1 parent 58935ba commit 3cfcabe

3 files changed

Lines changed: 145 additions & 33 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: Build & Publish
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
env:
13+
PLUGIN_NAME: PluginName
14+
15+
jobs:
16+
build:
17+
permissions:
18+
contents: write
19+
runs-on: ubuntu-latest
20+
outputs:
21+
buildnumber: ${{ steps.buildnumber.outputs.build_number }}
22+
steps:
23+
- name: Prepare env
24+
shell: bash
25+
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
26+
27+
- uses: actions/checkout@v3
28+
- name: Setup .NET
29+
uses: actions/setup-dotnet@v3
30+
with:
31+
dotnet-version: 7.0.x
32+
33+
- name: Restore dependencies
34+
run: dotnet restore
35+
36+
- name: Build
37+
run: dotnet publish --no-restore
38+
39+
- name: Clean build directory
40+
run: |
41+
mkdir -p addons/counterstrikesharp/plugins/${{PLUGIN_NAME}}
42+
mv BasicAdmin/bin/Debug/net7.0/publish/* addons/counterstrikesharp/plugins/${{PLUGIN_NAME}}
43+
cd addons/counterstrikesharp/plugins/${{PLUGIN_NAME}}
44+
rm CounterStrikeSharp.API.dll McMaster.NETCore.Plugins.dll Microsoft.DotNet.PlatformAbstractions.dll Microsoft.Extensions.DependencyModel.dll ${{PLUGIN_NAME}}.pdb
45+
46+
- uses: actions/upload-artifact@v3
47+
with:
48+
name: css-${{PLUGIN_NAME}}-${{ env.GITHUB_SHA_SHORT }}
49+
path: addons
50+
51+
- name: Generate build number
52+
id: buildnumber
53+
uses: onyxmueller/build-tag-number@v1
54+
with:
55+
token: ${{secrets.github_token}}
56+
57+
publish:
58+
permissions:
59+
contents: write
60+
runs-on: ubuntu-latest
61+
needs: build
62+
steps:
63+
- name: Prepare env
64+
shell: bash
65+
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
66+
67+
- uses: actions/download-artifact@v3
68+
with:
69+
name: css-${{PLUGIN_NAME}}-${{ env.GITHUB_SHA_SHORT }}
70+
path: addons
71+
72+
- name: Prepare zip
73+
run: |
74+
zip -qq -r css-${{PLUGIN_NAME}}-${{ env.GITHUB_SHA_SHORT }}.zip *
75+
76+
- name: Release
77+
uses: softprops/action-gh-release@v1
78+
with:
79+
tag_name: v${{ needs.build.outputs.buildnumber }}
80+
files: |
81+
css-${{PLUGIN_NAME}}-${{ env.GITHUB_SHA_SHORT }}.zip
82+
body: |
83+
${{ github.event.head_commit.message }}

BasicAdmin/BasicAdmin.cs

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
using System.Diagnostics.CodeAnalysis;
2-
using CounterStrikeSharp.API;
1+
using CounterStrikeSharp.API;
32
using CounterStrikeSharp.API.Core;
43
using CounterStrikeSharp.API.Core.Attributes.Registration;
54
using CounterStrikeSharp.API.Modules.Utils;
6-
using System.Text.Json.Serialization;
75
using CounterStrikeSharp.API.Modules.Admin;
86
using CounterStrikeSharp.API.Modules.Commands;
97
using CounterStrikeSharp.API.Modules.Cvars;
10-
using CounterStrikeSharp.API.Modules.Entities;
118
using CounterStrikeSharp.API.Modules.Memory;
129

1310
namespace BasicAdmin;
1411

15-
internal struct OriginalVec
16-
{
17-
internal Vector Position;
18-
internal QAngle Rotation;
19-
internal Vector Velocity;
20-
}
21-
2212
public class BasicAdmin : BasePlugin, IPluginConfig<BasicAdminConfig>
2313
{
2414
public override string ModuleName => "BasicAdmin";
@@ -27,9 +17,6 @@ public class BasicAdmin : BasePlugin, IPluginConfig<BasicAdminConfig>
2717

2818
public BasicAdminConfig Config {get; set;} = new ();
2919

30-
private static readonly Dictionary<CCSPlayerController, OriginalVec> OriginalPositions = new ();
31-
32-
3320
public void OnConfigParsed(BasicAdminConfig config)
3421
{
3522
this.Config = config;
@@ -76,7 +63,7 @@ public void OnKickCommand(CCSPlayerController? caller, CommandInfo info)
7663
ServerUtils.KickPlayer(player!.UserId, reason);
7764

7865
if (!Config.HideActivity)
79-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} kicked {player!.PlayerName}."));
66+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} kicked {player.PlayerName}."));
8067
}
8168

8269
[ConsoleCommand("css_slay", "Slay a player.")]
@@ -93,7 +80,7 @@ public void OnSlayCommand(CCSPlayerController? caller, CommandInfo info)
9380
player!.Pawn.Value.CommitSuicide(false, true);
9481

9582
if (!Config.HideActivity)
96-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} slayed {player!.PlayerName}."));
83+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} slayed {player.PlayerName}."));
9784
}
9885

9986
[ConsoleCommand("css_give", "Give a player an item.")]
@@ -110,7 +97,7 @@ public void OnGiveCommand(CCSPlayerController? caller, CommandInfo info)
11097
player!.GiveNamedItem(info.GetArg(2));
11198

11299
if (!Config.HideActivity)
113-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} gave {player!.PlayerName} {ChatColors.Lime}{info.GetArg(2)}{ChatColors.Default}."));
100+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} gave {player.PlayerName} {ChatColors.Lime}{info.GetArg(2)}{ChatColors.Default}."));
114101
}
115102

116103
[ConsoleCommand("css_swap", "Swap a player.")]
@@ -130,12 +117,12 @@ public void OnSwapCommand(CCSPlayerController? caller, CommandInfo info)
130117
return;
131118
}
132119

133-
var isCs = player!.TeamNum == (int) CsTeam.CounterTerrorist;
120+
var isCs = player.TeamNum == (int) CsTeam.CounterTerrorist;
134121

135-
player!.ChangeTeam(isCs ? CsTeam.Terrorist : CsTeam.CounterTerrorist);
122+
player.ChangeTeam(isCs ? CsTeam.Terrorist : CsTeam.CounterTerrorist);
136123

137124
if (!Config.HideActivity)
138-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} swapped {player!.PlayerName}."));
125+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} swapped {player.PlayerName}."));
139126
}
140127

141128
[ConsoleCommand("css_spec", "Change a player to spec.")]
@@ -152,7 +139,7 @@ public void OnSpecCommand(CCSPlayerController? caller, CommandInfo info)
152139
player!.ChangeTeam(CsTeam.Spectator);
153140

154141
if (!Config.HideActivity)
155-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} moved {player!.PlayerName} to spec."));
142+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} moved {player.PlayerName} to spec."));
156143
}
157144

158145
// [ConsoleCommand("css_respawn", "Respawn a dead player.")]
@@ -195,7 +182,7 @@ public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo in
195182
var message = info.GetCommandString[range..];
196183

197184
info.ReplyToCommand(FormatAdminMessage($"({player!.PlayerName}) {message}"));
198-
player!.PrintToChat(FormatAdminMessage($"({caller!.PlayerName}) {message}"));
185+
player.PrintToChat(FormatAdminMessage($"({caller!.PlayerName}) {message}"));
199186
}
200187

201188
[ConsoleCommand("css_csay", "Say to all players (in center).")]
@@ -257,13 +244,13 @@ public void OnBuryCommand(CCSPlayerController? caller, CommandInfo info)
257244
return;
258245
}
259246

260-
var newPos = new Vector(player!.Pawn.Value.AbsOrigin!.X, player!.Pawn.Value.AbsOrigin!.Y,
261-
player!.Pawn.Value.AbsOrigin!.Z - 10f);
247+
var newPos = new Vector(player.Pawn.Value.AbsOrigin!.X, player.Pawn.Value.AbsOrigin.Y,
248+
player.Pawn.Value.AbsOrigin.Z - 10f);
262249

263-
player!.Pawn.Value.Teleport(newPos, player!.AbsRotation!, player!.AbsVelocity);
250+
player.Pawn.Value.Teleport(newPos, player.AbsRotation!, player.AbsVelocity);
264251

265252
if (!Config.HideActivity)
266-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} buried {player!.PlayerName}."));
253+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} buried {player.PlayerName}."));
267254
}
268255

269256
[ConsoleCommand("css_unbury", "Unbury a player.")]
@@ -277,13 +264,13 @@ public void OnUnburyCommand(CCSPlayerController? caller, CommandInfo info)
277264
return;
278265
}
279266

280-
var newPos = new Vector(player!.Pawn.Value.AbsOrigin!.X, player!.Pawn.Value.AbsOrigin!.Y,
281-
player!.Pawn.Value.AbsOrigin!.Z + 15f);
267+
var newPos = new Vector(player!.Pawn.Value.AbsOrigin!.X, player.Pawn.Value.AbsOrigin.Y,
268+
player.Pawn.Value.AbsOrigin!.Z + 15f);
282269

283-
player!.Pawn.Value.Teleport(newPos, player!.AbsRotation!, player!.AbsVelocity);
270+
player.Pawn.Value.Teleport(newPos, player.AbsRotation!, player.AbsVelocity);
284271

285272
if (!Config.HideActivity)
286-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} unburied {player!.PlayerName}."));
273+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} unburied {player.PlayerName}."));
287274
}
288275

289276
[ConsoleCommand("css_disarm", "Disarm a player.")]
@@ -300,7 +287,7 @@ public void OnDisarmCommand(CCSPlayerController? caller, CommandInfo info)
300287
player!.RemoveWeapons();
301288

302289
if (!Config.HideActivity)
303-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} disarmed {player!.PlayerName}."));
290+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} disarmed {player.PlayerName}."));
304291
}
305292

306293
[ConsoleCommand("css_hp", "Change a player's HP.")]
@@ -317,7 +304,7 @@ public void OnHealthCommand(CCSPlayerController? caller, CommandInfo info)
317304
player!.Pawn.Value.Health = health;
318305

319306
if (!Config.HideActivity)
320-
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} changed {player!.PlayerName}'s health to {health}."));
307+
Server.PrintToChatAll(FormatAdminMessage($"{caller!.PlayerName} changed {player.PlayerName}'s health to {health}."));
321308
}
322309

323310
[ConsoleCommand("css_cvar", "Change a cvar.")]
@@ -333,7 +320,7 @@ public void OnCvarCommand(CCSPlayerController? caller, CommandInfo info)
333320
return;
334321
}
335322

336-
if (cvar.Name.Equals("sv_cheats") && !AdminManager.PlayerHasPermissions(caller, "@css/cvar"))
323+
if (cvar.Name.Equals("sv_cheats") && !AdminManager.PlayerHasPermissions(caller, "@css/cheats"))
337324
{
338325
info.ReplyToCommand(FormatMessage($"You don't have permissions to change \"{info.GetArg(1)}\"."));
339326
return;

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<p style="text-align: center;font-size: 2em;font-weight: bold">
2+
An admin for <a href="https://docs.cssharp.dev" target="_blank">CSSharp</a>
3+
</p>
4+
5+
### Requirements
6+
* CSSharp >= v61
7+
8+
### Available commands
9+
* `css_map`
10+
* requires `@css/changemap` flag
11+
* `css_kick`
12+
* requires `@css/kick` flag
13+
* `css_slay`
14+
* requires `@css/slay` flag
15+
* `css_give`
16+
* requires `@css/cvar` flag
17+
* `css_swap`
18+
* requires `@css/kick` flag
19+
* `css_spec`
20+
* requires `@css/kick` flag
21+
* `css_say`
22+
* requires `@css/chat` flag
23+
* `css_psay`
24+
* requires `@css/chat` flag
25+
* `css_csay`
26+
* requires `@css/chat` flag
27+
* `css_hsay`
28+
* requires `@css/chat` flag
29+
* `css_extend`
30+
* requires `@css/changemap` flag
31+
* `css_restartgame`
32+
* `css_rr` (alias)
33+
* requires `@css/changemap` flag
34+
* `css_bury`/`css_unbury`
35+
* requires `@css/ban` flag
36+
* `css_disarm`
37+
* requires `@css/ban` flag
38+
* `css_hp`
39+
* requires `@css/slay` flag
40+
* `css_cvar`
41+
* requires `@css/cvar` flag
42+
* `sv_cheats` reqyutes

0 commit comments

Comments
 (0)