forked from RainOrigami/BattleBitBaseModules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModeratorTools.cs
More file actions
232 lines (195 loc) · 7.84 KB
/
Copy pathModeratorTools.cs
File metadata and controls
232 lines (195 loc) · 7.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
using BattleBitAPI.Common;
using BBRAPIModules;
using Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BattleBitBaseModules;
[RequireModule(typeof(CommandHandler))]
public class ModeratorTools : BattleBitModule
{
[ModuleReference]
public CommandHandler CommandHandler { get; set; }
public override void OnModulesLoaded()
{
this.CommandHandler.Register(this);
}
[CommandCallback("Say", Description = "Prints a message to all players", AllowedRoles = Roles.Moderator)]
public void Say(RunnerPlayer commandSource, string message)
{
this.Server.SayToAllChat(message);
}
[CommandCallback("AnnounceShort", Description = "Prints a short announce to all players", AllowedRoles = Roles.Moderator)]
public void AnnounceShort(RunnerPlayer commandSource, string message)
{
this.Server.AnnounceShort(message);
}
[CommandCallback("AnnounceLong", Description = "Prints a long announce to all players", AllowedRoles = Roles.Moderator)]
public void AnnounceLong(RunnerPlayer commandSource, string message)
{
this.Server.AnnounceLong(message);
}
[CommandCallback("Message", Description = "Messages a specific player", AllowedRoles = Roles.Moderator)]
public void Message(RunnerPlayer commandSource, RunnerPlayer target, string message, float? timeout = null)
{
if (timeout.HasValue)
{
target.Message(message, timeout.Value);
}
else
{
target.Message(message);
}
commandSource.Message($"Message sent to {target.Name}", 10);
}
[CommandCallback("Clear", Description = "Clears the chat", AllowedRoles = Roles.Moderator)]
public void Clear(RunnerPlayer commandSource)
{
this.Server.SayToAllChat("".PadLeft(30, '\n') + "<size=0%>Chat cleared");
}
[CommandCallback("Kick", Description = "Kicks a player", AllowedRoles = Roles.Moderator)]
public void Kick(RunnerPlayer commandSource, RunnerPlayer target, string? reason = null)
{
target.Kick(reason ?? string.Empty);
commandSource.Message($"Player {target.Name} kicked", 10);
}
[CommandCallback("Ban", Description = "Bans a player", AllowedRoles = Roles.Moderator)]
public void Ban(RunnerPlayer commandSource, RunnerPlayer target)
{
this.Server.ExecuteCommand($"ban {target.SteamID}");
target.Kick();
commandSource.Message($"Player {target.Name} banned", 10);
}
[CommandCallback("Kill", Description = "Kills a player", AllowedRoles = Roles.Moderator)]
public void Kill(RunnerPlayer commandSource, RunnerPlayer target)
{
target.Kill();
commandSource.Message($"Player {target.Name} killed", 10);
}
[CommandCallback("Gag", Description = "Gags a player", AllowedRoles = Roles.Moderator)]
public void Gag(RunnerPlayer commandSource, RunnerPlayer target)
{
if (this.gaggedPlayers.Contains(target.SteamID))
{
commandSource.Message($"Player {target.Name} is already gagged");
return;
}
this.gaggedPlayers.Add(target.SteamID);
commandSource.Message($"Player {target.Name} gagged", 10);
}
[CommandCallback("Ungag", Description = "Ungags a player", AllowedRoles = Roles.Moderator)]
public void Ungag(RunnerPlayer commandSource, RunnerPlayer target)
{
if (!this.gaggedPlayers.Contains(target.SteamID))
{
commandSource.Message($"Player {target.Name} is not gagged");
return;
}
this.gaggedPlayers.Remove(target.SteamID);
commandSource.Message($"Player {target.Name} ungagged", 10);
}
[CommandCallback("Mute", Description = "Mutes a player", AllowedRoles = Roles.Moderator)]
public void Mute(RunnerPlayer commandSource, RunnerPlayer target)
{
if (target.Modifications.IsVoiceChatMuted)
{
commandSource.Message($"Player {target.Name} is already muted");
return;
}
target.Modifications.IsVoiceChatMuted = true;
commandSource.Message($"Player {target.Name} muted", 10);
}
[CommandCallback("Unmute", Description = "Unmutes a player", AllowedRoles = Roles.Moderator)]
public void Unmute(RunnerPlayer commandSource, RunnerPlayer target)
{
if (!target.Modifications.IsVoiceChatMuted)
{
commandSource.Message($"Player {target.Name} is not muted");
return;
}
target.Modifications.IsVoiceChatMuted = false;
commandSource.Message($"Player {target.Name} unmuted", 10);
}
[CommandCallback("Silence", Description = "Mutes and gags a player", AllowedRoles = Roles.Moderator)]
public void Silence(RunnerPlayer commandSource, RunnerPlayer target)
{
Mute(commandSource, target);
Gag(commandSource, target);
commandSource.Message($"Player {target.Name} silenced", 10);
}
[CommandCallback("Unsilence", Description = "Unmutes and ungags a player", AllowedRoles = Roles.Moderator)]
public void Unsilence(RunnerPlayer commandSource, RunnerPlayer target)
{
Unmute(commandSource, target);
Ungag(commandSource, target);
commandSource.Message($"Player {target.Name} unsilenced", 10);
}
[CommandCallback("LockSpawn", Description = "Prevents a player or all players from spawning", AllowedRoles = Roles.Moderator)]
public void LockSpawn(RunnerPlayer commandSource, RunnerPlayer? target = null)
{
if (target == null)
{
this.globalSpawnLock = true;
foreach (RunnerPlayer player in this.Server.AllPlayers)
{
player.Modifications.CanDeploy = false;
}
commandSource.Message("Spawn globally locked", 10);
}
else
{
if (this.lockedSpawns.Contains(target.SteamID))
{
commandSource.Message($"Spawn already locked for {target.Name}", 10);
return;
}
target.Modifications.CanDeploy = false;
this.lockedSpawns.Add(target.SteamID);
commandSource.Message($"Spawn locked for {target.Name}", 10);
}
}
[CommandCallback("UnlockSpawn", Description = "Allows a player or all players to spawn", AllowedRoles = Roles.Moderator)]
public void UnlockSpawn(RunnerPlayer commandSource, RunnerPlayer? target = null)
{
if (target == null)
{
this.globalSpawnLock = false;
foreach (RunnerPlayer player in this.Server.AllPlayers)
{
player.Modifications.CanDeploy = true;
}
commandSource.Message("Spawn globally unlocked", 10);
}
else
{
if (!this.lockedSpawns.Contains(target.SteamID))
{
commandSource.Message($"Spawn already unlocked for {target.Name}", 10);
return;
}
this.lockedSpawns.Remove(target.SteamID);
commandSource.Message($"Spawn unlocked for {target.Name}", 10);
}
}
private List<ulong> gaggedPlayers = new();
private List<ulong> lockedSpawns = new();
private bool globalSpawnLock = false;
public override Task<bool> OnPlayerTypedMessage(RunnerPlayer player, ChatChannel channel, string msg)
{
if (this.gaggedPlayers.Contains(player.SteamID))
{
return Task.FromResult(false);
}
return Task.FromResult(true);
}
public override Task<OnPlayerSpawnArguments?> OnPlayerSpawning(RunnerPlayer player, OnPlayerSpawnArguments request)
{
if (this.globalSpawnLock || this.lockedSpawns.Contains(player.SteamID))
{
return Task.FromResult<OnPlayerSpawnArguments?>(null);
}
return Task.FromResult(request as OnPlayerSpawnArguments?);
}
}