From 1b284ff08cfe72f67024ed6433be15613d55f18b Mon Sep 17 00:00:00 2001
From: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Date: Sat, 21 Nov 2026 19:50:24 -0800
Subject: [PATCH] server: Cancel a removed player's meetings

server_remove_player() freed the player and left any diplomacy
meeting it was in. The treaty kept pointing to the freed player, so
the next save read it in treaty_save(), and the other side's client
kept the meeting open; its Cancel meeting button then read the freed
player there too. 

kill_player() and the AI toggles already cancel the meetings.

Cancel them before the player's connections are detached, so both
sides are told.

See RM #2505

Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
---
 server/plrhand.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/server/plrhand.c b/server/plrhand.c
index 87f5e68336..40fd537bc1 100644
--- a/server/plrhand.c
+++ b/server/plrhand.c
@@ -1965,6 +1965,10 @@ void server_remove_player(struct player *pplayer)
     server.nbarbarians--;
   }
 
+  /* Treaties point to the player. Cancel them while the player's own
+   * connections are still attached to hear it. */
+  cancel_all_meetings(pplayer);
+
   /* Don't use conn_list_iterate here because connection_detach() can be
    * recursive and free the next connection pointer. */
   while (conn_list_size(pplayer->connections) > 0) {
-- 
2.55.0

