Server closes connections gracefully so kick/ban/reset/shutdown messages arrive; status dot and HUD yellow until really connected (also while reconnecting)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 10:59:50 +02:00
co-authored by Claude Opus 5.5
parent 0ae4dae28d
commit bdaedcc1e8
2 changed files with 26 additions and 5 deletions
+22 -2
View File
@@ -860,6 +860,23 @@ namespace MSCO
public string DisconnectNotice { get; private set; }
public void ClearDisconnectNotice() { DisconnectNotice = null; }
public bool IsReconnecting { get { return reconnectMessage != null && session == null; } }
bool worldSynced; // Server: Weltzustand angewendet
/// <summary>
/// Wirklich verbunden (grüner Punkt): Host sobald die Sitzung läuft; auf einem Server erst, wenn man im Spiel ist
/// und der Weltzustand angewendet wurde; bei P2P als Client, wenn man im Spiel ist. Vorher gelb.
/// </summary>
public bool IsFullyConnected
{
get
{
if (session == null) return false;
if (session.IsHost) return true;
if (!handshakeDone || !MenuHelper.InGame) return false;
return !dedicated || worldSynced;
}
}
public string ReconnectMessage { get { return reconnectMessage; } }
/// <summary>Technische Gründe in verständliche Sätze übersetzen.</summary>
@@ -893,6 +910,7 @@ namespace MSCO
if (session != null && session.IsSteam) steam.Leave();
session = null;
handshakeDone = false;
worldSynced = false;
pingMs = -1f;
teleportToHost = false;
dedicated = false;
@@ -1333,6 +1351,7 @@ namespace MSCO
doorSync.Reset();
FsmSync.Reset();
readySent = false;
worldSynced = false;
if (session != null) SetStatus(session.IsHost ? "Hosting" : "Connected");
}
else if (MenuHelper.InMenu)
@@ -1597,6 +1616,7 @@ namespace MSCO
if (objects.ApplySnapshotPose(p.Key, p.Value.Position, p.Value.Rotation)) applied++;
if (spawned > 0) MscoLog.Info(spawned + " spawned item(s) restored");
worldSynced = true;
MscoLog.Info("[MSCO] World synced: " + applied + "/" + objectCount + " objects, " + eventCount + " part/bolt actions");
SetStatus("Connected");
}
@@ -1729,13 +1749,13 @@ namespace MSCO
void DrawHud()
{
// Statuszeile oben in der Mitte (links oben ist die Spielanzeige)
string state = IsPeerReady ? "CONNECTED" : "WAITING";
string state = IsFullyConnected ? "CONNECTED" : IsPeerReady ? "SYNCING..." : "WAITING";
string text = "MSCO • " + state + " • " + (dedicated ? "Server" : IsHost ? "Host" : "Client") + " • " +
players.Count + " player(s) • " + objects.Count + " synced objects";
var rect = new Rect((Screen.width - 520) / 2f, 6, 520, 24);
if (hudBox == null) hudBox = UiTheme.Panel9(new Color(0.06f, 0.06f, 0.07f, 0.85f), 8);
GUI.Box(rect, GUIContent.none, hudBox);
hudStyle.normal.textColor = IsPeerReady ? new Color(0.24f, 0.84f, 0.55f) : new Color(0.95f, 0.76f, 0.11f);
hudStyle.normal.textColor = IsFullyConnected ? new Color(0.24f, 0.84f, 0.55f) : new Color(0.95f, 0.76f, 0.11f);
GUI.Label(rect, text, hudStyle);
DrawNameTags();