0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-25 20:55:18 +00:00

Multiple users on commands

This commit is contained in:
Sanae 2022-05-31 16:02:12 -06:00
parent 74c00aa0f8
commit 774ef20bb4

View file

@ -1,6 +1,7 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Net; using System.Net;
using System.Numerics; using System.Numerics;
using System.Text;
using Server; using Server;
using Shared; using Shared;
using Shared.Packet.Packets; using Shared.Packet.Packets;
@ -141,16 +142,25 @@ server.PacketHandler = (c, p) => {
}; };
CommandHandler.RegisterCommand("rejoin", args => { CommandHandler.RegisterCommand("rejoin", args => {
if (server.Clients.SingleOrDefault(c => c.Connected && args[0] == c.Name) is { } user) { bool moreThanOne = false;
StringBuilder builder = new StringBuilder();
foreach (Client user in server.Clients.Where(c => c.Connected && args.Contains(c.Name))) {
if (moreThanOne) builder.Append(", ");
builder.Append(user.Name);
user.Dispose(); user.Dispose();
return $"Kicked {user.Name}, use \"crash\" if you want to crash the user"; moreThanOne = true;
} }
return "Usage: kick <username>"; return moreThanOne ? $"Caused {builder} to rejoin" : "Usage: rejoin <usernames...>";
}); });
CommandHandler.RegisterCommand("crash", args => { CommandHandler.RegisterCommand("crash", args => {
if (server.Clients.SingleOrDefault(c => c.Connected && args[0] == c.Name) is { } user) { bool moreThanOne = false;
StringBuilder builder = new StringBuilder();
foreach (Client user in server.Clients.Where(c => c.Connected && args.Contains(c.Name))) {
if (moreThanOne) builder.Append(", ");
moreThanOne = true;
builder.Append(user.Name);
Task.Run(async () => { Task.Run(async () => {
await user.Send(new ChangeStagePacket { await user.Send(new ChangeStagePacket {
Id = "$among$us/SubArea", Id = "$among$us/SubArea",
@ -160,14 +170,18 @@ CommandHandler.RegisterCommand("crash", args => {
}); });
user.Dispose(); user.Dispose();
}); });
return $"Crashed {user.Name}";
} }
return "Usage: crash <username>"; return moreThanOne ? $"Crashed {builder}" : "Usage: crash <usernames...>";
}); });
CommandHandler.RegisterCommand("ban", args => { CommandHandler.RegisterCommand("ban", args => {
if (server.Clients.SingleOrDefault(c => c.Connected && args[0] == c.Name) is { } user) { bool moreThanOne = false;
StringBuilder builder = new StringBuilder();
foreach (Client user in server.Clients.Where(c => c.Connected && args.Contains(c.Name))) {
if (moreThanOne) builder.Append(", ");
moreThanOne = true;
builder.Append(user.Name);
Task.Run(async () => { Task.Run(async () => {
await user.Send(new ChangeStagePacket { await user.Send(new ChangeStagePacket {
Id = "$agogus/banned4lyfe", Id = "$agogus/banned4lyfe",
@ -180,9 +194,12 @@ CommandHandler.RegisterCommand("ban", args => {
if (endpoint != null) Settings.Instance.BanList.IpAddresses.Add(endpoint.ToString()); if (endpoint != null) Settings.Instance.BanList.IpAddresses.Add(endpoint.ToString());
user.Dispose(); user.Dispose();
}); });
return $"Crashed {user.Name}";
} }
if (moreThanOne) {
Settings.SaveSettings();
return $"Banned {builder}.";
}
return "Usage: crash <username>"; return "Usage: crash <username>";
}); });