forked from shobhit-pathak/MatchZy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsoleCommands.cs
419 lines (380 loc) · 19.3 KB
/
ConsoleCommands.cs
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Events;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Timers;
namespace MatchZy
{
public partial class MatchZy
{
[ConsoleCommand("css_whitelist", "Toggles Whitelisting of players")]
public void OnWLCommand(CCSPlayerController? player, CommandInfo? command) {
if (IsPlayerAdmin(player, "css_whitelist", "@css/config")) {
isWhitelistRequired = !isWhitelistRequired;
string WLStatus = isWhitelistRequired ? "Enabled" : "Disabled";
if (player == null) {
ReplyToUserCommand(player, $"Whitelist is now {WLStatus}!");
} else {
player.PrintToChat($"{chatPrefix} Whitelist is now {ChatColors.Green}{WLStatus}{ChatColors.Default}!");
}
} else {
SendPlayerNotAdminMessage(player);
}
}
[ConsoleCommand("css_save_nades_as_global", "Toggles Global Lineups for players")]
public void OnSaveNadesAsGlobalCommand(CCSPlayerController? player, CommandInfo? command) {
if (IsPlayerAdmin(player, "css_save_nades_as_global", "@css/config")) {
isSaveNadesAsGlobalEnabled = !isSaveNadesAsGlobalEnabled;
string GlobalNadesStatus = isSaveNadesAsGlobalEnabled ? "Enabled" : "Disabled";
if (player == null) {
ReplyToUserCommand(player, $"Saving/Loading Lineups Globally is now {GlobalNadesStatus}!");
} else {
player.PrintToChat($"{chatPrefix} Saving/Loading Lineups Globally is now {ChatColors.Green}{GlobalNadesStatus}{ChatColors.Default}!");
}
} else {
SendPlayerNotAdminMessage(player);
}
}
[ConsoleCommand("css_ready", "Marks the player ready")]
public void OnPlayerReady(CCSPlayerController? player, CommandInfo? command) {
if (player == null) return;
Log($"[!ready command] Sent by: {player.UserId}, connectedPlayers: {connectedPlayers}");
if (readyAvailable && !matchStarted) {
if (player.UserId.HasValue) {
if (!playerReadyStatus.ContainsKey(player.UserId.Value)) {
playerReadyStatus[player.UserId.Value] = false;
}
if (playerReadyStatus[player.UserId.Value]) {
player.PrintToChat($"{chatPrefix} You are already ready!");
} else {
playerReadyStatus[player.UserId.Value] = true;
player.PrintToChat($"{chatPrefix} You have been marked ready!");
}
CheckLiveRequired();
HandleClanTags();
}
}
}
[ConsoleCommand("css_unready", "Marks the player unready")]
public void OnPlayerUnReady(CCSPlayerController? player, CommandInfo? command) {
if (player == null) return;
Log($"[!unready command] {player.UserId}");
if (readyAvailable && !matchStarted) {
if (player.UserId.HasValue) {
if (!playerReadyStatus.ContainsKey(player.UserId.Value)) {
playerReadyStatus[player.UserId.Value] = false;
}
if (!playerReadyStatus[player.UserId.Value]) {
player.PrintToChat($"{chatPrefix} You are already unready!");
} else {
playerReadyStatus[player.UserId.Value] = false;
player.PrintToChat($"{chatPrefix} You have been marked unready!");
}
HandleClanTags();
}
}
}
[ConsoleCommand("css_stay", "Stays after knife round")]
public void OnTeamStay(CCSPlayerController? player, CommandInfo? command) {
if (player == null) return;
Log($"[!stay command] {player.UserId}, TeamNum: {player.TeamNum}, knifeWinner: {knifeWinner}, isSideSelectionPhase: {isSideSelectionPhase}");
if (isSideSelectionPhase) {
if (player.TeamNum == knifeWinner) {
Server.PrintToChatAll($"{chatPrefix} {ChatColors.Green}{knifeWinnerName}{ChatColors.Default} has decided to stay!");
StartLive();
}
}
}
[ConsoleCommand("css_switch", "Switch after knife round")]
public void OnTeamSwitch(CCSPlayerController? player, CommandInfo? command) {
if (player == null) return;
Log($"[!switch command] {player.UserId}, TeamNum: {player.TeamNum}, knifeWinner: {knifeWinner}, isSideSelectionPhase: {isSideSelectionPhase}");
if (isSideSelectionPhase) {
if (player.TeamNum == knifeWinner) {
Server.ExecuteCommand("mp_swapteams;");
SwapSidesInTeamData(true);
Server.PrintToChatAll($"{chatPrefix} {ChatColors.Green}{knifeWinnerName}{ChatColors.Default} has decided to switch!");
StartLive();
}
}
}
[ConsoleCommand("css_tech", "Pause the match")]
public void OnTechCommand(CCSPlayerController? player, CommandInfo? command) {
PauseMatch(player, command);
}
[ConsoleCommand("css_pause", "Pause the match")]
public void OnPauseCommand(CCSPlayerController? player, CommandInfo? command) {
if (isPauseCommandForTactical)
{
OnTacCommand(player, command);
}
else
{
PauseMatch(player, command);
}
}
[ConsoleCommand("css_fp", "Pause the matchas an admin")]
[ConsoleCommand("css_forcepause", "Pause the match as an admin")]
public void OnForcePauseCommand(CCSPlayerController? player, CommandInfo? command) {
ForcePauseMatch(player, command);
}
[ConsoleCommand("css_fup", "Pause the matchas an admin")]
[ConsoleCommand("css_forceunpause", "Pause the match as an admin")]
public void OnForceUnpauseCommand(CCSPlayerController? player, CommandInfo? command) {
ForceUnpauseMatch(player, command);
}
[ConsoleCommand("css_unpause", "Unpause the match")]
public void OnUnpauseCommand(CCSPlayerController? player, CommandInfo? command) {
if (isMatchLive && isPaused) {
var pauseTeamName = unpauseData["pauseTeam"];
if ((string)pauseTeamName == "Admin") {
player?.PrintToChat($"{chatPrefix} Match has been paused by an admin, hence it can be unpaused by an admin only.");
return;
}
string unpauseTeamName = "Admin";
string remainingUnpauseTeam = "Admin";
if (player?.TeamNum == 2) {
unpauseTeamName = reverseTeamSides["TERRORIST"].teamName;
remainingUnpauseTeam = reverseTeamSides["CT"].teamName;
if (!(bool)unpauseData["t"]) {
unpauseData["t"] = true;
}
} else if (player?.TeamNum == 3) {
unpauseTeamName = reverseTeamSides["CT"].teamName;
remainingUnpauseTeam = reverseTeamSides["TERRORIST"].teamName;
if (!(bool)unpauseData["ct"]) {
unpauseData["ct"] = true;
}
} else {
return;
}
if ((bool)unpauseData["t"] && (bool)unpauseData["ct"]) {
Server.PrintToChatAll($"{chatPrefix} Both teams has unpaused the match, resuming the match!");
Server.ExecuteCommand("mp_unpause_match;");
isPaused = false;
unpauseData["ct"] = false;
unpauseData["t"] = false;
} else if (unpauseTeamName == "Admin") {
Server.PrintToChatAll($"{chatPrefix} {ChatColors.Green}{unpauseTeamName}{ChatColors.Default} has unpaused the match, resuming the match!");
Server.ExecuteCommand("mp_unpause_match;");
isPaused = false;
unpauseData["ct"] = false;
unpauseData["t"] = false;
} else {
Server.PrintToChatAll($"{chatPrefix} {ChatColors.Green}{unpauseTeamName}{ChatColors.Default} wants to unpause the match. {ChatColors.Green}{remainingUnpauseTeam}{ChatColors.Default}, please write !unpause to confirm.");
}
if (!isPaused && pausedStateTimer != null) {
pausedStateTimer.Kill();
pausedStateTimer = null;
}
}
}
[ConsoleCommand("css_tac", "Starts a tactical timeout for the requested team")]
public void OnTacCommand(CCSPlayerController? player, CommandInfo? command) {
if (player == null) return;
if (matchStarted && isMatchLive) {
Log($"[.tac command sent via chat] Sent by: {player.UserId}, connectedPlayers: {connectedPlayers}");
if (isPaused)
{
ReplyToUserCommand(player, "Match is already paused, cannot start a tactical timeout!");
return;
}
if (player.TeamNum == 2) {
Server.ExecuteCommand("timeout_terrorist_start");
} else if (player.TeamNum == 3) {
Server.ExecuteCommand("timeout_ct_start");
}
}
}
[ConsoleCommand("css_roundknife", "Toggles knife round for the match")]
[ConsoleCommand("css_rk", "Toggles knife round for the match")]
public void OnKifeCommand(CCSPlayerController? player, CommandInfo? command) {
if (IsPlayerAdmin(player, "css_roundknife", "@css/config")) {
isKnifeRequired = !isKnifeRequired;
string knifeStatus = isKnifeRequired ? "Enabled" : "Disabled";
if (player == null) {
ReplyToUserCommand(player, $"Knife round is now {knifeStatus}!");
} else {
player.PrintToChat($"{chatPrefix} Knife round is now {ChatColors.Green}{knifeStatus}{ChatColors.Default}!");
}
} else {
SendPlayerNotAdminMessage(player);
}
}
[ConsoleCommand("css_readyrequired", "Sets number of ready players required to start the match")]
public void OnReadyRequiredCommand(CCSPlayerController? player, CommandInfo command) {
if (IsPlayerAdmin(player, "css_readyrequired", "@css/config")) {
if (command.ArgCount >= 2) {
string commandArg = command.ArgByIndex(1);
HandleReadyRequiredCommand(player, commandArg);
}
else {
string minimumReadyRequiredFormatted = (player == null) ? $"{minimumReadyRequired}" : $"{ChatColors.Green}{minimumReadyRequired}{ChatColors.Default}";
ReplyToUserCommand(player, $"Current Ready Required: {minimumReadyRequiredFormatted} .Usage: !readyrequired <number_of_ready_players_required>");
}
} else {
SendPlayerNotAdminMessage(player);
}
}
[ConsoleCommand("css_settings", "Shows the current match configuration/settings")]
public void OnMatchSettingsCommand(CCSPlayerController? player, CommandInfo? command) {
if (player == null) return;
if (IsPlayerAdmin(player, "css_settings", "@css/config")) {
string knifeStatus = isKnifeRequired ? "Enabled" : "Disabled";
string playoutStatus = isPlayOutEnabled ? "Enabled" : "Disabled";
player.PrintToChat($"{chatPrefix} Current Settings:");
player.PrintToChat($"{chatPrefix} Knife: {ChatColors.Green}{knifeStatus}{ChatColors.Default}");
player.PrintToChat($"{chatPrefix} Minimum Ready Required: {ChatColors.Green}{minimumReadyRequired}{ChatColors.Default}");
player.PrintToChat($"{chatPrefix} Playout: {ChatColors.Green}{playoutStatus}{ChatColors.Default}");
} else {
SendPlayerNotAdminMessage(player);
}
}
[ConsoleCommand("css_restart", "Restarts the match")]
public void OnRestartMatchCommand(CCSPlayerController? player, CommandInfo? command) {
if (IsPlayerAdmin(player, "css_restart", "@css/config")) {
if (!isPractice) {
ResetMatch();
} else {
ReplyToUserCommand(player, "Practice mode is active, cannot restart the match.");
}
} else {
SendPlayerNotAdminMessage(player);
}
}
[ConsoleCommand("css_map", "Changes the map using changelevel")]
public void OnChangeMapCommand(CCSPlayerController? player, CommandInfo command) {
if (player == null) return;
var mapName = command.ArgByIndex(1);
HandleMapChangeCommand(player, mapName);
}
[ConsoleCommand("css_rmap", "Reloads the current map")]
private void OnMapReloadCommand(CCSPlayerController? player, CommandInfo? command) {
if (player == null) return;
if (!IsPlayerAdmin(player)) {
SendPlayerNotAdminMessage(player);
return;
}
string currentMapName = Server.MapName;
if (long.TryParse(currentMapName, out _)) { // Check if mapName is a long for workshop map ids
Server.ExecuteCommand($"host_workshop_map \"{currentMapName}\"");
} else if (Server.IsMapValid(currentMapName)) {
Server.ExecuteCommand($"changelevel \"{currentMapName}\"");
} else {
player.PrintToChat($"{chatPrefix} Invalid map name!");
}
}
[ConsoleCommand("css_start", "Force starts the match")]
public void OnStartCommand(CCSPlayerController? player, CommandInfo? command) {
if (player == null) return;
if (IsPlayerAdmin(player, "css_start", "@css/config")) {
if (isPractice) {
ReplyToUserCommand(player, "Cannot start a match while in practice mode. Please use .exitprac command to exit practice mode first!");
return;
}
if (matchStarted) {
player.PrintToChat($"{chatPrefix} Start command cannot be used if match is already started! If you want to unpause, please use .unpause");
} else {
Server.PrintToChatAll($"{chatPrefix} {ChatColors.Green}Admin{ChatColors.Default} has started the game!");
HandleMatchStart();
}
} else {
SendPlayerNotAdminMessage(player);
}
}
[ConsoleCommand("css_asay", "Say as an admin")]
public void OnAdminSay(CCSPlayerController? player, CommandInfo? command) {
if (command == null) return;
if (player == null) {
Server.PrintToChatAll($"{adminChatPrefix} {command.ArgString}");
return;
}
if (!IsPlayerAdmin(player, "css_asay", "@css/chat")) {
SendPlayerNotAdminMessage(player);
return;
}
string message = "";
for (int i = 1; i < command.ArgCount; i++) {
message += command.ArgByIndex(i) + " ";
}
Server.PrintToChatAll($"{adminChatPrefix} {message}");
}
[ConsoleCommand("reload_admins", "Reload admins of MatchZy")]
public void OnReloadAdmins(CCSPlayerController? player, CommandInfo? command) {
if (IsPlayerAdmin(player, "reload_admins", "@css/config")) {
LoadAdmins();
UpdatePlayersMap();
} else {
SendPlayerNotAdminMessage(player);
}
}
[ConsoleCommand("css_match", "Starts match mode")]
public void OnMatchCommand(CCSPlayerController? player, CommandInfo? command)
{
if (!IsPlayerAdmin(player, "css_match", "@css/map", "@custom/prac")) {
SendPlayerNotAdminMessage(player);
return;
}
if (matchStarted) {
ReplyToUserCommand(player, "MatchZy is already in match mode!");
return;
}
StartMatchMode();
}
[ConsoleCommand("css_exitprac", "Starts match mode")]
public void OnExitPracCommand(CCSPlayerController? player, CommandInfo? command)
{
if (!IsPlayerAdmin(player, "css_exitprac", "@css/map", "@custom/prac")) {
SendPlayerNotAdminMessage(player);
return;
}
if (matchStarted) {
ReplyToUserCommand(player, "MatchZy is already in match mode!");
return;
}
StartMatchMode();
}
[ConsoleCommand("css_rcon", "Triggers provided command on the server")]
public void OnRconCommand(CCSPlayerController? player, CommandInfo command)
{
if (!IsPlayerAdmin(player, "css_rcon", "@css/rcon")) {
SendPlayerNotAdminMessage(player);
return;
}
Server.ExecuteCommand(command.ArgString);
ReplyToUserCommand(player, "Command sent successfully!");
}
[ConsoleCommand("css_help", "Triggers provided command on the server")]
public void OnHelpCommand(CCSPlayerController? player, CommandInfo? command)
{
SendAvailableCommandsMessage(player);
}
[ConsoleCommand("css_playout", "Toggles playout (Playing of max rounds)")]
public void OnPlayoutCommand(CCSPlayerController? player, CommandInfo? command) {
if (IsPlayerAdmin(player, "css_playout", "@css/config")) {
isPlayOutEnabled = !isPlayOutEnabled;
string playoutStatus = isPlayOutEnabled? "Enabled" : "Disabled";
if (player == null) {
ReplyToUserCommand(player, $"Playout is now {playoutStatus}!");
} else {
player.PrintToChat($"{chatPrefix} Playout is now {ChatColors.Green}{playoutStatus}{ChatColors.Default}!");
}
if (isPlayOutEnabled) {
Server.ExecuteCommand("mp_match_can_clinch false");
} else {
Server.ExecuteCommand("mp_match_can_clinch true");
}
} else {
SendPlayerNotAdminMessage(player);
}
}
}
}