Skip to content

Commit 74340e0

Browse files
authored
Merge pull request #5 from HerrMagiic/dev
Permissions + Server Commands
2 parents a9daf35 + b96d2ea commit 74340e0

File tree

6 files changed

+114
-58
lines changed

6 files changed

+114
-58
lines changed

CustomCommands/Commands.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
2727
"sv_cheats 1",
2828
"sv_falldamage_scale 0",
2929
"sv_party_mode 1",
30-
"mp_freezetime 2.5",
31-
"mp_round_restart_delay 2.5",
30+
"mp_freezetime 1",
31+
"mp_round_restart_delay 2",
3232
"cl_ragdoll_gravity 0",
3333
"sv_accelerate 10",
3434
"sv_airaccelerate 1400",
35-
"sv_gravity 800.0"
35+
"sv_gravity 800.0",
36+
"say hello"
3637
],
3738
"Permission": {
38-
"ReguiresPermissionOr": false,
39+
"ReguiresAllPermissions": false,
3940
"PermissionList": [
4041
"@css/cvar",
4142
"@custom/permission",

CustomCommands/CustomCommands.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using CounterStrikeSharp.API;
22
using CounterStrikeSharp.API.Core;
33
using CounterStrikeSharp.API.Core.Attributes;
4-
using CounterStrikeSharp.API.Core.Attributes.Registration;
54
using CustomCommands.Model;
65
using Microsoft.Extensions.Logging;
76
using System.Text.Json;

CustomCommands/Functions.cs

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CounterStrikeSharp.API;
22
using CounterStrikeSharp.API.Core;
33
using CounterStrikeSharp.API.Modules.Admin;
4+
using CounterStrikeSharp.API.Modules.Entities.Constants;
45
using CustomCommands.Model;
56

67
namespace CustomCommands;
@@ -27,6 +28,7 @@ private void RegisterListeners()
2728

2829
});
2930
}
31+
3032
private void AddCommands(Commands com)
3133
{
3234
string[] aliases = com.Command.Split(',');
@@ -36,13 +38,40 @@ private void AddCommands(Commands com)
3638
AddCommand(aliases[i], com.Description, (player, info) =>
3739
{
3840
if (player == null) return;
39-
RequiresPermissions(player, com.Permissions);
41+
42+
if (com.Permission.PermissionList.Count >= 1)
43+
if (!RequiresPermissions(player, com.Permission))
44+
return;
45+
4046
TriggerMessage(player, com);
4147
ExecuteServerCommands(com);
4248
});
4349
}
4450
}
4551

52+
private bool RequiresPermissions(CCSPlayerController player, Permission permissions)
53+
{
54+
if (!permissions.ReguiresAllPermissions)
55+
{
56+
foreach (var permission in permissions.PermissionList)
57+
{
58+
if (AdminManager.PlayerHasPermissions(player, new string[]{permission}))
59+
return true;
60+
}
61+
PrintToChat(Receiver.Client, player, "You don't have the required permissions to execute this command");
62+
return false;
63+
}
64+
else
65+
{
66+
if (!AdminManager.PlayerHasPermissions(player, permissions.PermissionList.ToArray()))
67+
{
68+
PrintToChat(Receiver.Client, player, "You don't have the required permissions to execute this command");
69+
return false;
70+
}
71+
return true;
72+
}
73+
}
74+
4675
private void ExecuteServerCommands(Commands cmd)
4776
{
4877
if (cmd.ServerCommands.Count == 0) return;

CustomCommands/Model/CenterElement.cs

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
using CounterStrikeSharp.API;
2-
using CounterStrikeSharp.API.Core;
3-
using CounterStrikeSharp.API.Core.Attributes;
4-
using CounterStrikeSharp.API.Core.Attributes.Registration;
5-
using CustomCommands.Model;
6-
using Microsoft.Extensions.Logging;
7-
using System.Text.Json;
81

92
namespace CustomCommands.Model;
103
public class CenterClientElement

CustomCommands/Model/CommandsConfig.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ public class Commands
99
public CenterElement CenterMessage { get; set; } = new();
1010
public required Sender PrintTo { get; set; } = Sender.ClientChat;
1111
public List<string> ServerCommands { get; set; } = new();
12-
public PermissionsElement Permissions { get; set; } = new();
12+
public Permission Permission { get; set; } = new();
1313
}
14-
public class PermissionsElement
14+
public class Permission
1515
{
16-
public bool ReguiresPermissionOr { get; set; } = false;
16+
public bool ReguiresAllPermissions { get; set; } = false;
1717
public List<string> PermissionList { get; set; } = new();
1818
}
1919
public class CenterElement

README.md

+76-42
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
## Custom Commands Plugin
1+
# Custom Commands Plugin Readme
22

3-
Create your custom commands in ./plugins/CustomCommands/Commands.json
3+
## Overview
44

5-
#### Example
5+
The Custom Commands Plugin allows you to create and customize commands for your server. These commands can display messages, perform server-side actions, and more. The configuration for these commands is stored in the `Commands.json` file located in the `./plugins/CustomCommands/` directory.
6+
7+
## Example Configuration
68

79
```json
810
[
911
{
1012
"Title": "Discord",
1113
"Command": "discord",
1214
"Message": "{PREFIX}{GREEN}Discord: \n <link>",
13-
"CenterMessage": "",
14-
"CenterMessageTime": 1,
15-
"PrintTo": 0,
1615
"Description": "Command for Discord"
1716
},
1817
{
@@ -23,54 +22,89 @@ Create your custom commands in ./plugins/CustomCommands/Commands.json
2322
"CenterMessageTime": 2,
2423
"PrintTo": 7,
2524
"Description": "Command for SteamGroup"
25+
},
26+
{
27+
"Title": "Enable Surf",
28+
"Command": "surf",
29+
"Message": "Surf is now enabled",
30+
"PrintTo": 0,
31+
"Description": "Command for enabling Surf gamemode",
32+
"ServerCommands": [
33+
"sv_cheats 1",
34+
"sv_falldamage_scale 0",
35+
"sv_party_mode 1",
36+
"mp_freezetime 2.5",
37+
"mp_round_restart_delay 2.5",
38+
"cl_ragdoll_gravity 0",
39+
"sv_accelerate 10",
40+
"sv_airaccelerate 1400",
41+
"sv_gravity 800.0"
42+
],
43+
"Permission": {
44+
"RequiresPermissionOr": false,
45+
"PermissionList": [
46+
"@css/cvar",
47+
"@custom/permission",
48+
"#css/simple-admin"
49+
]
50+
}
2651
}
2752
]
2853
```
2954

30-
**Title**: Just the title for your
55+
## Configuration Details
56+
57+
### Title
58+
59+
Just the title for your command. Can be anything or empty.
60+
61+
### Command
62+
63+
Specify the commands as a string, e.g., "discord" or "steam,steamgroup,group". Players can use `!discord` or `/discord` in the chat or css_discord in the console.
64+
65+
### Message
66+
67+
The message you want to send. You can use color codes like {GREEN} for green text.
68+
69+
### CenterMessage
70+
71+
The center message. For special formating use HTML
72+
73+
### PrintTo
74+
75+
Specifies where the message should be shown:
76+
77+
- **0**: Client Chat
78+
- **1**: All Chat
79+
- **2**: Client Center
80+
- **3**: All Center
81+
- **4**: Client Chat & Client Center
82+
- **5**: Client Chat & All Center
83+
- **6**: All Chat & Client Center
84+
- **7**: All Chat & All Center
85+
86+
### Description
3187

32-
**Command:** just type the name. !`<command>` and /`<command>` will work normally
88+
A description of what the command does. This will be shown when do css_help
3389

34-
**Message**: The message you want to send.
90+
### ServerCommands
3591

36-
Colors:
92+
An array of server commands to be executed when the command is triggered. Useful for actions like enabling specific game modes.
3793

38-
* {DEFAULT}
39-
* {RED}
40-
* {LIGHTPURPLE}
41-
* {GREEN}
42-
* {LIME}
43-
* {LIGHTGREEN}
44-
* {LIGHTRED}
45-
* {GRAY}
46-
* {LIGHTOLIVE}
47-
* {OLIVE}
48-
* {LIGHTBLUE}
49-
* {BLUE}
50-
* {PURPLE}
51-
* {GRAYBLUE}
94+
### Permission
5295

53-
**CenterMessage**: The Center Message. HTML works as well.
96+
Defines if the command requires specific permissions to execute:
5497

55-
**PrintTo**: Where the message should be shown
98+
- **ReguiresAllPermissions**
99+
- Set to true = The player needs all permissions in PermissionsList
100+
- Set to false = The player only needs one of the permissions in PermissionsList
101+
- **PermissionList**: A list of permission flags or groups required to execute the command. [More Explenation](https://docs.cssharp.dev/docs/admin-framework/defining-admins.html)
56102

57-
| Desc | Nr |
58-
| --------------------------- | -- |
59-
| Client Chat | 0 |
60-
| All Chat | 1 |
61-
| Client Center | 2 |
62-
| All Center | 3 |
63-
| Client Chat & Client Center | 4 |
64-
| Client Chat & All Center | 5 |
65-
| All Chat & Client Center | 6 |
66-
| All Chat & All Center | 7 |
103+
### Colorlist
67104

68-
**Description**: What the Description for the command should be
105+
{DEFAULT}, {RED}, {LIGHTPURPLE}, {GREEN}, {LIME},
106+
{LIGHTGREEN}, {LIGHTRED}, {GRAY}, {LIGHTOLIVE},
107+
{OLIVE}, {LIGHTBLUE}, {BLUE}, {PURPLE}, {GRAYBLUE}
69108

70109

71-
## Roadmap
72110

73-
* [ ] Send Server Commands
74-
* [ ] Set permissions
75-
* [ ] On Off toggle
76-
* [ ] Allow Args

0 commit comments

Comments
 (0)