0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-22 03:05:16 +00:00

Various useful changes

This commit is contained in:
Sanae 2022-03-15 14:44:46 -06:00
parent cc67ac9ced
commit 8d11623ada
4 changed files with 10 additions and 6 deletions

View file

@ -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 => { CommandHandler.RegisterCommand("flip", args => {
const string optionUsage = "Valid options: \n\tlist\n\tadd <user id>\n\tremove <user id>\n\tset <true/false>\n\tpov <both/self/others>"; const string optionUsage = "Valid options: \n\tlist\n\tadd <user id>\n\tremove <user id>\n\tset <true/false>\n\tpov <both/self/others>";
@ -263,7 +263,7 @@ CommandHandler.RegisterCommand("flip", args => {
}); });
CommandHandler.RegisterCommand("shine", args => { CommandHandler.RegisterCommand("shine", args => {
const string optionUsage = "Valid options: list, clear"; const string optionUsage = "Valid options: list, clear, sync";
if (args.Length < 1) if (args.Length < 1)
return optionUsage; return optionUsage;
switch (args[0]) { switch (args[0]) {
@ -274,6 +274,9 @@ CommandHandler.RegisterCommand("shine", args => {
foreach (ConcurrentBag<int> playerBag in server.Clients.Select(serverClient => (ConcurrentBag<int>) serverClient.Metadata["shineSync"])) playerBag.Clear(); foreach (ConcurrentBag<int> playerBag in server.Clients.Select(serverClient => (ConcurrentBag<int>) serverClient.Metadata["shineSync"])) playerBag.Clear();
return "Cleared shine bags"; return "Cleared shine bags";
case "sync" when args.Length == 1:
SyncShineBag();
return "Synced shine bag automatically";
default: default:
return optionUsage; return optionUsage;
} }

View file

@ -31,7 +31,7 @@ public class Server {
Logger.Warn($"Accepted connection for client {socket.RemoteEndPoint}"); Logger.Warn($"Accepted connection for client {socket.RemoteEndPoint}");
try { try {
if (Clients.Count == Constants.MaxClients) { if (Clients.Count == Settings.Instance.Server.MaxPlayers) {
Logger.Warn("Turned away client due to max clients"); Logger.Warn("Turned away client due to max clients");
await socket.DisconnectAsync(false); await socket.DisconnectAsync(false);
continue; continue;
@ -182,7 +182,7 @@ public class Server {
case ConnectPacket.ConnectionTypes.Reconnecting: { case ConnectPacket.ConnectionTypes.Reconnecting: {
client.Id = header.Id; client.Id = header.Id;
if (FindExistingClient(header.Id) is { } newClient) { 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; newClient.Socket = client.Socket;
client = newClient; client = newClient;
} else { } else {
@ -279,7 +279,8 @@ public class Server {
} }
Logger.Info($"Client {socket.RemoteEndPoint} ({client.Name}/{client.Id}) disconnected from the server"); Logger.Info($"Client {socket.RemoteEndPoint} ({client.Name}/{client.Id}) disconnected from the server");
Clients.Remove(client); // Clients.Remove(client)
client.Connected = false;
try { try {
client.Dispose(); client.Dispose();
} catch {/*lol*/} } catch {/*lol*/}

View file

@ -46,6 +46,7 @@ public class Settings {
public class ServerTable { public class ServerTable {
public string Address { get; set; } = IPAddress.Any.ToString(); public string Address { get; set; } = IPAddress.Any.ToString();
public ushort Port { get; set; } = 1027; public ushort Port { get; set; } = 1027;
public byte MaxPlayers { get; set; } = 8;
} }
public class ScenarioTable { public class ScenarioTable {

View file

@ -6,7 +6,6 @@ using Shared.Packet.Packets;
namespace Shared; namespace Shared;
public static class Constants { public static class Constants {
public const int MaxClients = 8;
public const int CostumeNameSize = 0x20; public const int CostumeNameSize = 0x20;
// dictionary of packet types to packet // dictionary of packet types to packet