-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBan.cs
47 lines (40 loc) · 1.3 KB
/
Ban.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
using BattleBitApi.Api;
namespace BattleBitApi.ConsoleCommands;
public class Ban : ConsoleCommand
{
public Ban() : base(
name: "ban",
description: "Bans a player from the server.",
usage: "ban <steamId> [reason]"
)
{
Action = args =>
{
if (args.Length < 1)
{
Logger.Error("You must provide a player name.");
return;
}
ulong playerSteamId;
try
{
playerSteamId = ulong.Parse(args[0]);
}
catch (Exception)
{
Logger.Error($"Invalid SteamId \"{args[0]}\".");
return;
}
BattleBitPlayer? player = Server.AllPlayers.FirstOrDefault(p => p.SteamID == playerSteamId);
if (player == null)
{
Logger.Error($"Player with SteamId \"{playerSteamId}\" not found.");
return;
}
var reason = args.Length > 1 ? string.Join(" ", args.Skip(1)) : "Banned by admin.";
player.Kick(reason);
Server.ExecuteCommand($"ban {playerSteamId}");
Logger.Info($"Player \"{player.Name}\" banned.");
};
}
}