Disconnect previous client instead of throwing on new client (rejoins)
This commit is contained in:
parent
534a6c9655
commit
1a82666d93
|
@ -20,7 +20,7 @@ server.ClientJoined += (c, _) => {
|
||||||
c.Metadata["speedrun"] = false;
|
c.Metadata["speedrun"] = false;
|
||||||
foreach (Client client in server.Clients.Where(client => client.Metadata.ContainsKey("lastGamePacket")).ToArray()) {
|
foreach (Client client in server.Clients.Where(client => client.Metadata.ContainsKey("lastGamePacket")).ToArray()) {
|
||||||
try {
|
try {
|
||||||
Task.WaitAll(c.Send((GamePacket) client.Metadata["lastGamePacket"]!, client));
|
c.Send((GamePacket) client.Metadata["lastGamePacket"]!, client).Wait();
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
// lol who gives a fuck
|
// lol who gives a fuck
|
||||||
|
|
|
@ -180,7 +180,10 @@ public class Server {
|
||||||
case ConnectPacket.ConnectionTypes.FirstConnection: {
|
case ConnectPacket.ConnectionTypes.FirstConnection: {
|
||||||
firstConn = true;
|
firstConn = true;
|
||||||
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) {
|
||||||
|
newClient.Logger.Info($"Disconnecting already connected client {newClient.Socket?.RemoteEndPoint} for {client.Socket?.RemoteEndPoint}");
|
||||||
|
newClient.Dispose();
|
||||||
|
}
|
||||||
newClient.Socket = client.Socket;
|
newClient.Socket = client.Socket;
|
||||||
client = newClient;
|
client = newClient;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +193,10 @@ 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) {
|
||||||
|
newClient.Logger.Info($"Disconnecting already connected client {newClient.Socket?.RemoteEndPoint} for {client.Socket?.RemoteEndPoint}");
|
||||||
|
newClient.Dispose();
|
||||||
|
}
|
||||||
newClient.Socket = client.Socket;
|
newClient.Socket = client.Socket;
|
||||||
client = newClient;
|
client = newClient;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue