diff --git a/Server/Program.cs b/Server/Program.cs index d7e1909..b0083c9 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Net; using System.Numerics; using Server; using Shared; @@ -139,6 +140,52 @@ server.PacketHandler = (c, p) => { return true; }; +CommandHandler.RegisterCommand("rejoin", args => { + if (server.Clients.SingleOrDefault(c => c.Connected && args[0] == c.Name) is { } user) { + user.Dispose(); + return $"Kicked {user.Name}, use \"crash\" if you want to crash the user"; + } + + return "Usage: kick "; +}); + +CommandHandler.RegisterCommand("crash", args => { + if (server.Clients.SingleOrDefault(c => c.Connected && args[0] == c.Name) is { } user) { + Task.Run(async () => { + await user.Send(new ChangeStagePacket { + Id = "$among$us/SubArea", + Stage = "$agogusStage", + Scenario = 21, + SubScenarioType = 69 // invalid id + }); + user.Dispose(); + }); + return $"Crashed {user.Name}"; + } + + return "Usage: crash "; +}); + +CommandHandler.RegisterCommand("ban", args => { + if (server.Clients.SingleOrDefault(c => c.Connected && args[0] == c.Name) is { } user) { + Task.Run(async () => { + await user.Send(new ChangeStagePacket { + Id = "$agogus/banned4lyfe", + Stage = "$ejected", + Scenario = 69, + SubScenarioType = 21 // invalid id + }); + IPEndPoint? endpoint = (IPEndPoint?) user.Socket?.RemoteEndPoint; + Settings.Instance.BanList.Players.Add(user.Id); + if (endpoint != null) Settings.Instance.BanList.IpAddresses.Add(endpoint.ToString()); + user.Dispose(); + }); + return $"Crashed {user.Name}"; + } + + return "Usage: crash "; +}); + CommandHandler.RegisterCommand("send", args => { const string optionUsage = "Usage: send "; if (args.Length < 4) @@ -291,6 +338,9 @@ CommandHandler.RegisterCommand("maxplayers", args => { if (!ushort.TryParse(args[0], out ushort maxPlayers)) return optionUsage; Settings.Instance.Server.MaxPlayers = maxPlayers; Settings.SaveSettings(); + foreach (Client client in server.Clients) + client.Dispose(); // reconnect all players + return $"Saved and set max players to {maxPlayers}"; }); CommandHandler.RegisterCommand("list", _ => $"List: {string.Join("\n\t", server.Clients.Where(x => x.Connected).Select(x => $"{x.Name} ({x.Id})"))}"); diff --git a/Server/Settings.cs b/Server/Settings.cs index 3d32fff..86ad88e 100644 --- a/Server/Settings.cs +++ b/Server/Settings.cs @@ -42,6 +42,7 @@ public class Settings { public ServerTable Server { get; set; } = new ServerTable(); public FlipTable Flip { get; set; } = new FlipTable(); public ScenarioTable Scenario { get; set; } = new ScenarioTable(); + public BannedPlayers BanList { get; set; } = new BannedPlayers(); public class ServerTable { public string Address { get; set; } = IPAddress.Any.ToString(); @@ -54,13 +55,19 @@ public class Settings { } public class HiddenPlayers { - public List Players { get; set; } = new List(); public bool Enabled { get; set; } = false; + public List Players { get; set; } = new List(); + } + + public class BannedPlayers { + public bool Enabled { get; set; } = false; + public List Players { get; set; } = new List(); + public List IpAddresses { get; set; } = new List(); } public class FlipTable { - public List Players { get; set; } = new List(); public bool Enabled { get; set; } = true; + public List Players { get; set; } = new List(); public FlipOptions Pov { get; set; } = FlipOptions.Both; } } \ No newline at end of file