Show why you were disconnected in the main menu; reset-world / reload-save make all players reconnect automatically

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 10:46:45 +02:00
co-authored by Claude Opus 5.5
parent 85fbb8a3ce
commit 08844b18ac
4 changed files with 37 additions and 5 deletions
+24 -2
View File
@@ -138,7 +138,12 @@ public sealed class GameServer
Thread.Sleep(2);
}
foreach (var c in clients.Values) c.Conn.Close("Server shutting down");
foreach (var c in clients.Values)
{
// Grund mitschicken: die Spieler sehen ihn im Hauptmenü
if (c.State == ClientState.Joined) c.Conn.Send(MsgType.Reject, Wire.Build(w => w.Write("The server was shut down.")));
c.Conn.Close("Server shutting down");
}
listener.Stop();
SaveWorld();
if (!offline)
@@ -457,6 +462,22 @@ public sealed class GameServer
}
/// <summary>Chatnachricht vom Server an alle (Absender-ID 0 = "Server").</summary>
/// <summary>
/// Alle Spieler neu verbinden lassen (nach reset-world / reload-save): sie sehen die Meldung, gehen kurz ins Menü
/// und laden dann den neuen Stand. Sonst liefen sie mit der alten Welt weiter.
/// </summary>
void ReconnectAll(string message)
{
int count = 0;
foreach (var c in clients.Values.Where(x => x.State == ClientState.Joined).ToList())
{
c.Conn.Send(MsgType.Reconnect, Wire.Build(w => w.Write(message)));
c.Conn.Close("Reconnect after world change");
count++;
}
if (count > 0) Log($"{count} player(s) will reconnect");
}
string Unban(string id, string by)
{
id = (id ?? "").Trim();
@@ -576,9 +597,10 @@ public sealed class GameServer
world.Reset();
SaveWorld();
Log("World state reset - new players get the plain save game again.");
ReconnectAll("The world is being reset - reconnecting...");
break;
case "reload-save":
LoadSave();
if (LoadSave()) ReconnectAll("The server loaded a new save game - reconnecting...");
break;
case "stop":
case "quit":