mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-22 03:05:16 +00:00
ignore & crash instead of disconnect clients after reaching the MaxPlayers limit
Otherwise they'll enter an endless disconnect-reconnnect loop spamming the server with new TCP connections.
This commit is contained in:
parent
082e480b1e
commit
4de654b6e4
1 changed files with 10 additions and 5 deletions
|
@ -197,6 +197,11 @@ public class Server {
|
||||||
client.Ignored = true;
|
client.Ignored = true;
|
||||||
client.Banned = true;
|
client.Banned = true;
|
||||||
}
|
}
|
||||||
|
// is the server full?
|
||||||
|
else if (Clients.Count(x => x.Connected) >= Settings.Instance.Server.MaxPlayers) {
|
||||||
|
client.Logger.Error($"Ignoring player {client.Name} ({client.Id}/{remote}) as server reached max players of {Settings.Instance.Server.MaxPlayers}");
|
||||||
|
client.Ignored = true;
|
||||||
|
}
|
||||||
|
|
||||||
// send server init (required to crash ignored players later)
|
// send server init (required to crash ignored players later)
|
||||||
await client.Send(new InitPacket {
|
await client.Send(new InitPacket {
|
||||||
|
@ -213,11 +218,12 @@ public class Server {
|
||||||
|
|
||||||
// add client to the set of connected players
|
// add client to the set of connected players
|
||||||
lock (Clients) {
|
lock (Clients) {
|
||||||
// is the server full?
|
// is the server full? (check again, to prevent race conditions)
|
||||||
if (Clients.Count(x => x.Connected) == Settings.Instance.Server.MaxPlayers) {
|
if (Clients.Count(x => x.Connected) >= Settings.Instance.Server.MaxPlayers) {
|
||||||
client.Logger.Error($"Turned away as server is at max clients");
|
client.Logger.Error($"Ignoring player {client.Name} ({client.Id}/{remote}) as server reached max players of {Settings.Instance.Server.MaxPlayers}");
|
||||||
|
client.Ignored = true;
|
||||||
memory.Dispose();
|
memory.Dispose();
|
||||||
goto disconnect;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// detect and handle reconnections
|
// detect and handle reconnections
|
||||||
|
@ -354,7 +360,6 @@ public class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
// client disconnected
|
// client disconnected
|
||||||
disconnect:
|
|
||||||
if (client.Name != "Unknown User" && client.Id != Guid.Parse("00000000-0000-0000-0000-000000000000")) {
|
if (client.Name != "Unknown User" && client.Id != Guid.Parse("00000000-0000-0000-0000-000000000000")) {
|
||||||
Logger.Info($"Client {remote} ({client.Name}/{client.Id}) disconnected from the server");
|
Logger.Info($"Client {remote} ({client.Name}/{client.Id}) disconnected from the server");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue