diff --git a/Server/Program.cs b/Server/Program.cs index 522ac7b..b58a928 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -212,7 +212,7 @@ CommandHandler.RegisterCommand("tag", args => { } }); -CommandHandler.RegisterCommand("list", _ => $"List: {string.Join("\n\t", server.Clients.Select(x => x.Name))}"); +CommandHandler.RegisterCommand("list", _ => $"List: {string.Join("\n\t", server.Clients.Select(x => $"{x.Name} ({x.Id})"))}"); CommandHandler.RegisterCommand("flip", args => { const string optionUsage = "Valid options: \n\tlist\n\tadd \n\tremove \n\tset \n\tpov "; @@ -263,7 +263,7 @@ CommandHandler.RegisterCommand("flip", args => { }); CommandHandler.RegisterCommand("shine", args => { - const string optionUsage = "Valid options: list, clear"; + const string optionUsage = "Valid options: list, clear, sync"; if (args.Length < 1) return optionUsage; switch (args[0]) { @@ -274,6 +274,9 @@ CommandHandler.RegisterCommand("shine", args => { foreach (ConcurrentBag playerBag in server.Clients.Select(serverClient => (ConcurrentBag) serverClient.Metadata["shineSync"])) playerBag.Clear(); return "Cleared shine bags"; + case "sync" when args.Length == 1: + SyncShineBag(); + return "Synced shine bag automatically"; default: return optionUsage; } diff --git a/Server/Server.cs b/Server/Server.cs index 2d57fcb..64eedd6 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -31,7 +31,7 @@ public class Server { Logger.Warn($"Accepted connection for client {socket.RemoteEndPoint}"); try { - if (Clients.Count == Constants.MaxClients) { + if (Clients.Count == Settings.Instance.Server.MaxPlayers) { Logger.Warn("Turned away client due to max clients"); await socket.DisconnectAsync(false); continue; @@ -182,7 +182,7 @@ public class Server { case ConnectPacket.ConnectionTypes.Reconnecting: { client.Id = header.Id; if (FindExistingClient(header.Id) is { } newClient) { - if (newClient.Connected) throw new Exception($"Tried to join as already connected user {header.Id}"); + // if (newClient.Connected) throw new Exception($"Tried to join as already connected user {header.Id}"); newClient.Socket = client.Socket; client = newClient; } else { @@ -279,7 +279,8 @@ public class Server { } Logger.Info($"Client {socket.RemoteEndPoint} ({client.Name}/{client.Id}) disconnected from the server"); - Clients.Remove(client); + // Clients.Remove(client) + client.Connected = false; try { client.Dispose(); } catch {/*lol*/} diff --git a/Server/Settings.cs b/Server/Settings.cs index 28dd050..1e60ca7 100644 --- a/Server/Settings.cs +++ b/Server/Settings.cs @@ -46,6 +46,7 @@ public class Settings { public class ServerTable { public string Address { get; set; } = IPAddress.Any.ToString(); public ushort Port { get; set; } = 1027; + public byte MaxPlayers { get; set; } = 8; } public class ScenarioTable { diff --git a/Shared/Constants.cs b/Shared/Constants.cs index 1559465..1efa180 100644 --- a/Shared/Constants.cs +++ b/Shared/Constants.cs @@ -6,7 +6,6 @@ using Shared.Packet.Packets; namespace Shared; public static class Constants { - public const int MaxClients = 8; public const int CostumeNameSize = 0x20; // dictionary of packet types to packet