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 => {
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 => {
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<int> playerBag in server.Clients.Select(serverClient => (ConcurrentBag<int>) serverClient.Metadata["shineSync"])) playerBag.Clear();
return "Cleared shine bags";
case "sync" when args.Length == 1:
SyncShineBag();
return "Synced shine bag automatically";
default:
return optionUsage;
}

View file

@ -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*/}

View file

@ -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 {

View file

@ -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