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

The user management update

This commit is contained in:
Sanae 2022-05-31 15:48:57 -06:00
parent d898f4754b
commit 74c00aa0f8
2 changed files with 59 additions and 2 deletions

View file

@ -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 <username>";
});
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 <username>";
});
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 <username>";
});
CommandHandler.RegisterCommand("send", args => {
const string optionUsage = "Usage: send <stage> <id> <scenario[0..255]> <player/*>";
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})"))}");

View file

@ -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<Guid> Players { get; set; } = new List<Guid>();
public bool Enabled { get; set; } = false;
public List<Guid> Players { get; set; } = new List<Guid>();
}
public class BannedPlayers {
public bool Enabled { get; set; } = false;
public List<Guid> Players { get; set; } = new List<Guid>();
public List<string> IpAddresses { get; set; } = new List<string>();
}
public class FlipTable {
public List<Guid> Players { get; set; } = new List<Guid>();
public bool Enabled { get; set; } = true;
public List<Guid> Players { get; set; } = new List<Guid>();
public FlipOptions Pov { get; set; } = FlipOptions.Both;
}
}