forked from RedBigz/Citruslib-FixedUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandRegistry.cs
More file actions
420 lines (386 loc) · 21.2 KB
/
CommandRegistry.cs
File metadata and controls
420 lines (386 loc) · 21.2 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
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
420
using Landfall.Network;
using UnityEngine;
using WobbleBridge.Utils;
namespace WobbleBridge
{
public static class CommandRegistry
{
public static void Register()
{
RegisterTeamCommands();
RegisterTeleportCommands();
RegisterPlayerInfoCommands();
RegisterAdminCommands();
RegisterItemCommands();
RegisterMiscCommands();
}
// ─── Team ────────────────────────────────────────────────────────────────
private static void RegisterTeamCommands()
{
Wobble.AddCommand("team", delegate (string[] prms, TABGPlayerServer player)
{
switch (prms[0])
{
case "get":
if (prms.Length != 2)
{
Wobble.SelfParrot(player, "team get <name>");
return;
}
if (!Wobble.PlayerChatSearch(prms[1], out TABGPlayerServer getTarget))
{
Wobble.SelfParrot(player, getTarget != null
? "multiple results for: " + prms[1]
: "no results for: " + prms[1]);
return;
}
Wobble.SelfParrot(player, "groupIndex for player " + getTarget.PlayerName + " is:" + getTarget.GroupIndex);
break;
case "set":
if (prms.Length != 3)
{
Wobble.SelfParrot(player, "team set <name> <index>");
return;
}
if (!Wobble.PlayerChatSearch(prms[1], out TABGPlayerServer setTarget))
{
Wobble.SelfParrot(player, setTarget != null
? "multiple results for: " + prms[1]
: "no results for: " + prms[1]);
return;
}
if (!byte.TryParse(prms[2], out byte ind))
{
Wobble.SelfParrot(player, "could not parse group index: " + prms[2]);
return;
}
Wobble.SetTeam(setTarget, ind);
Wobble.SelfParrot(player, "set player " + setTarget.PlayerName + " to team " + prms[2]);
break;
default:
Wobble.SelfParrot(player, "unknown parameter: " + prms[0]);
break;
}
},
"Wobble Lib", "Changes or queries a player's team", "<get|set> <player> [index](if setting)", 2);
}
// ─── Teleport ────────────────────────────────────────────────────────────
private static void RegisterTeleportCommands()
{
Wobble.AddCommand("goto", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 1) { Wobble.SelfParrot(player, "goto <name>"); return; }
if (!Wobble.PlayerChatSearch(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
Wobble.log.Log($"taking player {player.PlayerName} to {find.PlayerName}");
Wobble.Teleport(player, find.PlayerPosition);
},
"Wobble Lib", "Brings the command user to the specified player", "<player>", 2);
Wobble.AddCommand("bring", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 1) { Wobble.SelfParrot(player, "bring <name>"); return; }
if (!Wobble.PlayerChatSearch(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
Wobble.log.Log($"taking player {find.PlayerName} to {player.PlayerName}");
Wobble.Teleport(find, player.PlayerPosition);
},
"Wobble Lib", "Brings a player to the command user", "<player>", 2);
Wobble.AddCommand("send", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 2) { Wobble.SelfParrot(player, "send <name> <name>"); return; }
if (!Wobble.PlayerChatSearch(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
if (!Wobble.PlayerChatSearch(prms[1], out TABGPlayerServer find2))
{
Wobble.SelfParrot(player, find2 != null ? "multiple results for: " + prms[1] : "no results for: " + prms[1]);
return;
}
Wobble.log.Log($"taking player {find.PlayerName} to {find2.PlayerName}");
Wobble.Teleport(find, find2.PlayerPosition);
},
"Wobble Lib", "Sends the first player to the second player", "<player> <player>", 2);
Wobble.AddCommand("goto_pos", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 3) { Wobble.SelfParrot(player, "goto_pos <x> <y> <z>"); return; }
if (!(float.TryParse(prms[0], out float x) & float.TryParse(prms[1], out float y) & float.TryParse(prms[2], out float z)))
{
Wobble.SelfParrot(player, "there was an issue parsing the coordinates you provided!");
return;
}
Wobble.log.Log($"taking player {player.PlayerName} to {x},{y},{z}");
Wobble.Teleport(player, new Vector3(x, y, z));
},
"Wobble Lib", "teleports the player to the specified coordinates", "(x) (y) (z)", 2);
Wobble.AddCommand("send_pos", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 4) { Wobble.SelfParrot(player, "send_pos <name/id> <x> <y> <z>"); return; }
if (!Wobble.PlayerChatSearch(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
if (!(float.TryParse(prms[1], out float x) & float.TryParse(prms[2], out float y) & float.TryParse(prms[3], out float z)))
{
Wobble.SelfParrot(player, "there was an issue parsing the coordinates you provided!");
return;
}
Wobble.log.Log($"taking player {find.PlayerName} to {x},{y},{z}");
Wobble.Teleport(find, new Vector3(x, y, z));
},
"Wobble Lib", "teleports the specified player to the specified coordinates", "<name> (x) (y) (z)", 2);
}
// ─── Player Info ─────────────────────────────────────────────────────────
private static void RegisterPlayerInfoCommands()
{
Wobble.AddCommand("get_pos", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length > 1) { Wobble.SelfParrot(player, "get_pos <name(optional)>"); return; }
TABGPlayerServer find = player;
if (prms.Length == 1)
{
if (!Wobble.PlayerChatSearch(prms[0], out find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
}
string msg = $"player {find.PlayerName} is located at {find.PlayerPosition}";
Wobble.SelfParrot(player, msg);
Wobble.log.Log(msg);
},
"Wobble Lib", "queries a player's position", "<name>(optional)", 1);
Wobble.AddCommand("id", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 1) { Wobble.SelfParrot(player, "id <name>"); return; }
if (!Wobble.PlayerWithName(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
string message = $"id for {find.PlayerName} is {find.PlayerIndex}";
Wobble.SelfParrot(player, message);
Wobble.log.Log(message);
},
"Wobble Lib", "Gets the ID of a player with the given name.", "<name>");
Wobble.AddCommand("name", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 1) { Wobble.SelfParrot(player, "name <id>"); return; }
if (!byte.TryParse(prms[0], out byte ind)) { Wobble.SelfParrot(player, "name <id>"); return; }
if (!Wobble.PlayerWithIndex(ind, out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
string message = $"name for {find.PlayerIndex} is {find.PlayerName}";
Wobble.SelfParrot(player, message);
Wobble.log.Log(message);
},
"Wobble Lib", "Gets the NAME of a player with the given byte playerindex.", "[id]");
Wobble.AddCommand("epic", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 1) { Wobble.SelfParrot(player, "epic <name>"); return; }
if (!Wobble.PlayerChatSearch(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
string message = $"epicid for {find.PlayerName} is {find.EpicUserName}";
Wobble.SelfParrot(player, message);
Wobble.log.Log(message);
},
"Wobble Lib", "Gets the epic id of a player with the given name or index", "<name>");
}
// ─── Admin ───────────────────────────────────────────────────────────────
private static void RegisterAdminCommands()
{
Wobble.AddCommand("perm-get", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 1) { Wobble.SelfParrot(player, "perm-get <name>"); return; }
if (!Wobble.PlayerChatSearch(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
if (Wobble.permList == null) { Wobble.log.Log("Perm list doesn't exist!"); return; }
PermList.PermPlayer ply = Wobble.permList.players.Find(p => p.epic == (string)find.EpicUserName);
int perm = ply?.permlevel ?? 1;
string text = $"{find.PlayerName} has perm level {perm}";
Wobble.log.Log(text);
Wobble.SelfParrot(player, text);
},
"Wobble Lib", "Gets the permission status of the player", "<player>", 1);
Wobble.AddCommand("perm-set", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length != 2) { Wobble.SelfParrot(player, "perm-set <name> [level]"); return; }
if (!Wobble.PlayerChatSearch(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
if (Wobble.permList == null)
{
Wobble.SelfParrot(player, "the permlist doesnt exist somehow??");
Wobble.log.Log("Perm list doesn't exist!");
return;
}
// Bugfix: war prms[2], muss prms[1] sein
if (!int.TryParse(prms[1], out int perm))
{
Wobble.SelfParrot(player, $"Invalid integer {prms[1]}");
Wobble.log.Log($"Invalid integer {prms[1]}");
return;
}
PermList.PermPlayer ply = Wobble.permList.players.Find(p => p.epic == (string)find.EpicUserName);
if (ply != null)
{
ply.permlevel = perm;
}
else
{
Wobble.permList.players.Add(new PermList.PermPlayer
{
name = find.PlayerName,
epic = find.EpicUserName,
permlevel = perm
});
}
Wobble.WriteNewPermList();
},
"Wobble Lib", "SETS the permission status of the player!", "<player>", 4);
Wobble.AddCommand("reloadweps", delegate (string[] prms, TABGPlayerServer player)
{
WeaponPatchManager.ReloadConfig();
Wobble.SelfParrot(player, "Weapon patches reloaded!");
},
"Wobble Lib", "Reloads weapon damage multipliers from json", "", 1);
}
// ─── Items ───────────────────────────────────────────────────────────────
private static void RegisterItemCommands()
{
Wobble.AddCommand("give", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length < 1 || prms.Length > 2) { Wobble.SelfParrot(player, "give <itemID> <amount>"); return; }
int amt = 1;
if (prms.Length == 2 && !int.TryParse(prms[1], out amt)) { Wobble.SelfParrot(player, "invalid amount"); return; }
if (!ItemHelper.TryParseItemId(prms[0], out int typ)) { Wobble.SelfParrot(player, "invalid item (use ID or Item enum name)"); return; }
LootPack lp = new LootPack();
lp.AddLoot(typ, amt);
Wobble.GiveLoot(player, lp);
},
"Wobble Lib", "gives the user an item with an optional amount", "[id|ItemName] [amount(optional)]", 2);
Wobble.AddCommand("gift", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length < 2 || prms.Length > 3) { Wobble.SelfParrot(player, "gift <player> <itemID> <amount>"); return; }
if (!Wobble.PlayerChatSearch(prms[0], out TABGPlayerServer find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
int amt = 1;
if (prms.Length == 3 && !int.TryParse(prms[2], out amt)) { Wobble.SelfParrot(player, "invalid amount"); return; }
if (!ItemHelper.TryParseItemId(prms[1], out int typ)) { Wobble.SelfParrot(player, "invalid item (use ID or Item enum name)"); return; }
LootPack lp = new LootPack();
lp.AddLoot(typ, amt);
Wobble.GiveLoot(find, lp);
},
"Wobble Lib", "gives the target player an item with an optional amount", "<player> [id|ItemName] [amount(optional)]", 2);
}
// ─── Misc ────────────────────────────────────────────────────────────────
private static void RegisterMiscCommands()
{
Wobble.AddCommand("broadcast", delegate (string[] prms, TABGPlayerServer player)
{
if (prms == null || prms.Length == 0) { Wobble.SelfParrot(player, "broadcast <message>"); return; }
string msg = "[SERVER] " + string.Join(" ", prms);
foreach (TABGPlayerServer pl in Wobble.World.GameRoomReference.Players)
{
if (pl != null) Wobble.SelfParrot(pl, msg);
}
},
"Wobble Lib", "Sends a message to all players in the game", "<message>", 3);
Wobble.AddCommand("kill", delegate (string[] prms, TABGPlayerServer player)
{
if (prms.Length > 1) { Wobble.SelfParrot(player, "kill <name(optional)>"); return; }
TABGPlayerServer find = player;
if (prms.Length == 1)
{
if (!Wobble.PlayerChatSearch(prms[0], out find))
{
Wobble.SelfParrot(player, find != null ? "multiple results for: " + prms[0] : "no results for: " + prms[0]);
return;
}
}
string msg = $"killing player {find.PlayerName}";
Wobble.KillPlayer(find);
Wobble.SelfParrot(player, msg);
Wobble.log.Log(msg);
},
"Wobble Lib", "kills a player. if no player is specified it kills the user...!", "<name>(optional)", 1);
Wobble.AddCommand("start", delegate (string[] prms, TABGPlayerServer player)
{
float time = 30;
if (prms.Length > 0)
{
if (prms.Length != 1) { Wobble.SelfParrot(player, "start <time(optional)>"); return; }
if (!float.TryParse(prms[0], out time)) { Wobble.SelfParrot(player, "invalid time: " + prms[0]); return; }
}
Wobble.World.GameRoomReference.StartCountDown(time);
},
"Wobble Lib", "Starts the countdown timer", "[time]", 1);
Wobble.AddCommand("list", delegate (string[] prms, TABGPlayerServer player)
{
string players = "PLAYERS:";
foreach (TABGPlayerServer pl in Wobble.World.GameRoomReference.Players)
players += $"\n{pl.PlayerName} ind:{pl.PlayerIndex} team:{pl.GroupIndex} (original team is {(byte)(Wobble.players.Find(p => p.player.PlayerIndex == pl.PlayerIndex).data["originalTeam"])}) epic:{pl.EpicUserName}";
string playerRefs = "PLAYERREFS:";
foreach (PlayerRef pl in Wobble.players)
playerRefs += $"\n{pl.player.PlayerName} ind:{pl.player.PlayerIndex} team:{pl.player.GroupIndex}";
string teams = "TEAM REFS:\n";
string teamsLite = "";
foreach (PlayerTeam team in Wobble.teams)
{
if (team.players.Count > 0)
{
teams += $"Team {team.groupIndex} : ";
teamsLite += $"Team {team.groupIndex} : ";
foreach (PlayerRef p in team.players) { teams += p.player.PlayerName + ", "; teamsLite += p.player.PlayerName + ", "; }
teams += "\n"; teamsLite += "\n";
}
else teams += $"Team {team.groupIndex} : (no players)\n";
}
string req = prms.Length != 0 ? prms[0] : "all";
string result;
switch (req)
{
case "teams": case "team": case "t":
result = "TEAMS LIST INFO\n" + teams;
Wobble.SelfParrot(player, teamsLite);
break;
case "players": case "player": case "p":
result = "PLAYERS LIST INFO\n" + players;
Wobble.SelfParrot(player, players);
break;
case "playerrefs":
result = "PLAYERREFS LIST INFO\n" + playerRefs;
Wobble.SelfParrot(player, playerRefs);
break;
default:
result = "ALL LIST INFO\n" + players + "\n" + teams + "\n" + playerRefs;
Wobble.SelfParrot(player, "lists posted to console.");
break;
}
Wobble.log.Log(result);
},
"Wobble Lib", "lists different things in the console.", "<teams|players|playerrefs|all>", 2);
}
}
}