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

Disconnect previous client instead of throwing on new client (rejoins)

This commit is contained in:
Sanae 2022-04-04 14:43:44 -06:00
parent 534a6c9655
commit 1a82666d93
2 changed files with 9 additions and 3 deletions

View file

@ -20,7 +20,7 @@ server.ClientJoined += (c, _) => {
c.Metadata["speedrun"] = false;
foreach (Client client in server.Clients.Where(client => client.Metadata.ContainsKey("lastGamePacket")).ToArray()) {
try {
Task.WaitAll(c.Send((GamePacket) client.Metadata["lastGamePacket"]!, client));
c.Send((GamePacket) client.Metadata["lastGamePacket"]!, client).Wait();
}
catch {
// lol who gives a fuck

View file

@ -180,7 +180,10 @@ public class Server {
case ConnectPacket.ConnectionTypes.FirstConnection: {
firstConn = true;
if (FindExistingClient(header.Id) is { } newClient) {
if (newClient.Connected) throw new Exception($"Tried to join as already connected user {header.Id}");
if (newClient.Connected) {
newClient.Logger.Info($"Disconnecting already connected client {newClient.Socket?.RemoteEndPoint} for {client.Socket?.RemoteEndPoint}");
newClient.Dispose();
}
newClient.Socket = client.Socket;
client = newClient;
}
@ -190,7 +193,10 @@ 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) {
newClient.Logger.Info($"Disconnecting already connected client {newClient.Socket?.RemoteEndPoint} for {client.Socket?.RemoteEndPoint}");
newClient.Dispose();
}
newClient.Socket = client.Socket;
client = newClient;
} else {