From bc2ff1a777cdcb6b6fa848f1168778438c4ea410 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 14 May 2022 10:08:55 +0300
Subject: [PATCH 35/35] Add client common treaty list handling

See osdn #44588

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/Makefile.am             |   2 +
 client/clitreaty.c             | 150 ++++++++++++++++
 client/clitreaty.h             |  33 ++++
 client/gui-gtk-3.22/diplodlg.c | 126 +++++++-------
 client/gui-gtk-4.0/diplodlg.c  | 124 +++++++-------
 client/gui-qt/diplodlg.cpp     | 303 +++++++++++++++++----------------
 client/gui-qt/diplodlg.h       |  27 +--
 client/gui-qt/qtg_cxxside.cpp  |   7 +
 client/gui-qt/qtg_cxxside.h    |   9 +
 client/gui-sdl2/diplodlg.c     | 163 +++++++++---------
 client/gui-stub/diplodlg.c     |  23 ++-
 client/gui_interface.c         |  51 ++++++
 client/gui_interface.h         |  10 ++
 client/include/diplodlg_g.h    |  29 ++--
 client/packhand.c              |  44 +++++
 meson.build                    |   1 +
 16 files changed, 727 insertions(+), 375 deletions(-)
 create mode 100644 client/clitreaty.c
 create mode 100644 client/clitreaty.h

diff --git a/client/Makefile.am b/client/Makefile.am
index 98b4e52f1b..cb454c050a 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -100,6 +100,8 @@ freeciv_client_src = $(AUDIO_SDL_FILES) \
 	climap.h	\
 	clinet.c	\
 	clinet.h	\
+	clitreaty.c	\
+	clitreaty.h	\
 	colors_common.c		\
 	colors_common.h		\
 	control.c	\
diff --git a/client/clitreaty.c b/client/clitreaty.c
new file mode 100644
index 0000000000..f2ff3de77f
--- /dev/null
+++ b/client/clitreaty.c
@@ -0,0 +1,150 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Team
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <fc_config.h>
+#endif
+
+/* utility */
+#include "shared.h"
+
+/* common */
+#include "diptreaty.h"
+
+/* client */
+#include "client_main.h"
+#include "diplodlg_g.h"
+
+#include "clitreaty.h"
+
+/**********************************************************************//**
+  Handle new meeting request.
+**************************************************************************/
+void client_init_meeting(int counterpart, int initiated_from)
+{
+  struct Treaty *ptreaty;
+  struct player *we;
+  struct player *they;
+
+  if (!can_client_issue_orders()) {
+    return;
+  }
+
+  we = client_player();
+  they = player_by_number(counterpart);
+  ptreaty = find_treaty(we, they);
+
+  if (ptreaty == NULL) {
+    ptreaty = fc_malloc(sizeof(*ptreaty));
+    init_treaty(ptreaty, we, they);
+    treaty_add(ptreaty);
+  }
+
+  gui_init_meeting(ptreaty, they, player_by_number(initiated_from));
+}
+
+/**********************************************************************//**
+  Handle server information about treaty acceptance.
+**************************************************************************/
+void client_recv_accept_treaty(int counterpart, bool I_accepted,
+                               bool other_accepted)
+{
+  struct Treaty *ptreaty;
+  struct player *we;
+  struct player *they;
+
+  we = client_player();
+  they = player_by_number(counterpart);
+  ptreaty = find_treaty(we, they);
+
+  if (ptreaty == NULL) {
+    return;
+  }
+
+  ptreaty->accept0 = I_accepted;
+  ptreaty->accept1 = other_accepted;
+
+  gui_recv_accept_treaty(ptreaty, they);
+}
+
+/**********************************************************************//**
+  Handle server information about meeting cancellation.
+**************************************************************************/
+void client_recv_cancel_meeting(int counterpart, int initiated_from)
+{
+  struct Treaty *ptreaty;
+  struct player *we;
+  struct player *they;
+
+  we = client_player();
+  they = player_by_number(counterpart);
+  ptreaty = find_treaty(we, they);
+
+  if (ptreaty == NULL) {
+    return;
+  }
+
+  gui_recv_cancel_meeting(ptreaty, they, player_by_number(initiated_from));
+
+  treaty_remove(ptreaty);
+}
+
+/**********************************************************************//**
+  Handle server information about addition of a clause
+**************************************************************************/
+void client_recv_create_clause(int counterpart, int giver,
+                               enum clause_type type, int value)
+{
+  struct Treaty *ptreaty;
+  struct player *we;
+  struct player *they;
+
+  we = client_player();
+  they = player_by_number(counterpart);
+  ptreaty = find_treaty(we, they);
+
+  if (ptreaty == NULL) {
+    return;
+  }
+
+  gui_prepare_clause_updt(ptreaty, they);
+
+  add_clause(ptreaty, player_by_number(giver), type, value);
+
+  gui_recv_create_clause(ptreaty, they);
+}
+
+/**********************************************************************//**
+  Handle server information about removal of a clause
+**************************************************************************/
+void client_recv_remove_clause(int counterpart, int giver,
+                               enum clause_type type, int value)
+{
+  struct Treaty *ptreaty;
+  struct player *we;
+  struct player *they;
+
+  we = client_player();
+  they = player_by_number(counterpart);
+  ptreaty = find_treaty(we, they);
+
+  if (ptreaty == NULL) {
+    return;
+  }
+
+  gui_prepare_clause_updt(ptreaty, they);
+
+  remove_clause(ptreaty, player_by_number(giver), type, value);
+
+  gui_recv_remove_clause(ptreaty, they);
+}
diff --git a/client/clitreaty.h b/client/clitreaty.h
new file mode 100644
index 0000000000..0789f1c141
--- /dev/null
+++ b/client/clitreaty.h
@@ -0,0 +1,33 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__CLITREATY_H
+#define FC__CLITREATY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+void client_init_meeting(int counterpart, int initiated_from);
+void client_recv_accept_treaty(int counterpart, bool I_accepted,
+                               bool other_accepted);
+void client_recv_cancel_meeting(int counterpart, int initiated_from);
+void client_recv_create_clause(int counterpart, int giver,
+                               enum clause_type type, int value);
+void client_recv_remove_clause(int counterpart, int giver,
+                               enum clause_type type, int value);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* FC__CLITREATY_H */
diff --git a/client/gui-gtk-3.22/diplodlg.c b/client/gui-gtk-3.22/diplodlg.c
index 63890e5e13..6a2f909f01 100644
--- a/client/gui-gtk-3.22/diplodlg.c
+++ b/client/gui-gtk-3.22/diplodlg.c
@@ -52,9 +52,9 @@
 #define MAX_NUM_CLAUSES 64
 
 struct Diplomacy_dialog {
-  struct Treaty treaty;
-  struct gui_dialog* dialog;
-  
+  struct Treaty *treaty;
+  struct gui_dialog *dialog;
+
   GtkWidget *menu0;
   GtkWidget *menu1;
 
@@ -65,7 +65,7 @@ struct Diplomacy_dialog {
 };
 
 struct Diplomacy_notebook {
-  struct gui_dialog* dialog;
+  struct gui_dialog *dialog;
   GtkWidget *notebook;
 };
 
@@ -80,11 +80,13 @@ struct Diplomacy_notebook {
 static struct dialog_list *dialog_list;
 static struct Diplomacy_notebook *dipl_main;
 
-static struct Diplomacy_dialog *create_diplomacy_dialog(struct player *plr0, 
-						 struct player *plr1);
+static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty,
+                                                        struct player *plr0,
+                                                        struct player *plr1);
 
-static struct Diplomacy_dialog *find_diplomacy_dialog(int other_player_id);
-static void popup_diplomacy_dialog(int other_player_id, int initiated_from);
+static struct Diplomacy_dialog *find_diplomacy_dialog(struct player *they);
+static void popup_diplomacy_dialog(struct Treaty *ptreaty, struct player *they,
+                                   struct player *initiator);
 static void diplomacy_dialog_map_callback(GtkWidget *w, gpointer data);
 static void diplomacy_dialog_seamap_callback(GtkWidget *w, gpointer data);
 static void diplomacy_dialog_tech_callback(GtkWidget *w, gpointer data);
@@ -109,17 +111,15 @@ static void diplomacy_main_response(struct gui_dialog *dlg, int response,
 /************************************************************************//**
   Server tells us that either party has accepted treaty
 ****************************************************************************/
-void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
-                                    bool other_accepted)
+void gui_recv_accept_treaty(struct Treaty *ptreaty, struct player *they)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(counterpart);
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  pdialog->treaty.accept0 = I_accepted;
-  pdialog->treaty.accept1 = other_accepted;
+  fc_assert(pdialog->treaty == ptreaty);
 
   update_diplomacy_dialog(pdialog);
   gui_dialog_alert(pdialog->dialog);
@@ -128,38 +128,50 @@ void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
 /************************************************************************//**
   Someone is initiating meeting with us.
 ****************************************************************************/
-void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
+void gui_init_meeting(struct Treaty *ptreaty, struct player *they,
+                      struct player *initiator)
 {
-  popup_diplomacy_dialog(counterpart, initiated_from);
+  popup_diplomacy_dialog(ptreaty, they, initiator);
 }
 
 /************************************************************************//**
   Meeting has been cancelled.
 ****************************************************************************/
-void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
+void gui_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they,
+                             struct player *initiator)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(counterpart);
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
+  fc_assert(pdialog->treaty == ptreaty);
+
   close_diplomacy_dialog(pdialog);
 }
 
+/**********************************************************************//**
+  Prepare to clause creation or removal.
+**************************************************************************/
+void gui_prepare_clause_updt(struct Treaty *ptreaty, struct player *they)
+{
+  /* Not needed */
+}
+
 /************************************************************************//**
   Added clause to the meeting
 ****************************************************************************/
-void handle_diplomacy_create_clause(int counterpart, int giver,
-                                    enum clause_type type, int value)
+void gui_recv_create_clause(struct Treaty *ptreaty, struct player *they)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(counterpart);
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  add_clause(&pdialog->treaty, player_by_number(giver), type, value);
+  fc_assert(pdialog->treaty == ptreaty);
+
   update_diplomacy_dialog(pdialog);
   gui_dialog_alert(pdialog->dialog);
 }
@@ -167,16 +179,16 @@ void handle_diplomacy_create_clause(int counterpart, int giver,
 /************************************************************************//**
   Removed clause from meeting.
 ****************************************************************************/
-void handle_diplomacy_remove_clause(int counterpart, int giver,
-                                    enum clause_type type, int value)
+void gui_recv_remove_clause(struct Treaty *ptreaty, struct player *they)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(counterpart);
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  remove_clause(&pdialog->treaty, player_by_number(giver), type, value);
+  fc_assert(pdialog->treaty == ptreaty);
+
   update_diplomacy_dialog(pdialog);
   gui_dialog_alert(pdialog->dialog);
 }
@@ -184,26 +196,22 @@ void handle_diplomacy_remove_clause(int counterpart, int giver,
 /************************************************************************//**
   Popup the dialog 10% inside the main-window 
 ****************************************************************************/
-static void popup_diplomacy_dialog(int other_player_id, int initiated_from)
+static void popup_diplomacy_dialog(struct Treaty *ptreaty, struct player *they,
+                                   struct player *initiator)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(other_player_id);
-
-  if (!can_client_issue_orders()) {
-    return;
-  }
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
-  if (!is_human(client.conn.playing)) {
+  if (!is_human(client_player())) {
     return; /* Don't show if we are not human controlled. */
   }
 
   if (!pdialog) {
-    pdialog = create_diplomacy_dialog(client.conn.playing,
-				      player_by_number(other_player_id));
+    pdialog = create_diplomacy_dialog(ptreaty, client_player(), they);
   }
 
   gui_dialog_present(pdialog->dialog);
   /* We initated the meeting - Make the tab active */
-  if (player_by_number(initiated_from) == client.conn.playing) {
+  if (initiator == client_player()) {
     /* we have to raise the diplomacy meeting tab as well as the selected
      * meeting. */
     fc_assert_ret(dipl_main != NULL);
@@ -244,8 +252,8 @@ static void popup_add_menu(GtkMenuShell *parent, gpointer data)
 
   pdialog = (struct Diplomacy_dialog *) data;
   pgiver = (struct player *) g_object_get_data(G_OBJECT(parent), "plr");
-  pother = (pgiver == pdialog->treaty.plr0
-            ? pdialog->treaty.plr1 : pdialog->treaty.plr0);
+  pother = (pgiver == pdialog->treaty->plr0
+            ? pdialog->treaty->plr1 : pdialog->treaty->plr0);
 
 
   /* Maps. */
@@ -414,7 +422,7 @@ static void popup_add_menu(GtkMenuShell *parent, gpointer data)
 
 
   /* Pacts. */
-  if (pgiver == pdialog->treaty.plr0) {
+  if (pgiver == pdialog->treaty->plr0) {
     enum diplstate_type ds;
 
     ds = player_diplstate_get(pgiver, pother)->type;
@@ -458,10 +466,10 @@ static void row_callback(GtkTreeView *view, GtkTreePath *path,
   index = gtk_tree_path_get_indices(path);
 
   i = 0; 
-  clause_list_iterate(pdialog->treaty.clauses, pclause) {
+  clause_list_iterate(pdialog->treaty->clauses, pclause) {
     if (i == index[0]) {
       dsend_packet_diplomacy_remove_clause_req(&client.conn,
-					       player_number(pdialog->treaty.plr1),
+					       player_number(pdialog->treaty->plr1),
 					       player_number(pclause->from),
 					       pclause->type,
 					       pclause->value);
@@ -549,7 +557,7 @@ static void diplomacy_main_response(struct gui_dialog *dlg, int response,
        * client. Closing the last dialog will also close the main tab.*/
       dsend_packet_diplomacy_cancel_meeting_req(&client.conn,
                                                 player_number(
-                                                  adialog->treaty.plr1));
+                                                  adialog->treaty->plr1));
     } dialog_list_iterate_end;
     break;
   }
@@ -600,7 +608,7 @@ static void diplomacy_response(struct gui_dialog *dlg, int response,
   case GTK_RESPONSE_ACCEPT:         /* Accept treaty. */
     dsend_packet_diplomacy_accept_treaty_req(&client.conn,
                                              player_number(
-                                               pdialog->treaty.plr1));
+                                               pdialog->treaty->plr1));
     break;
 
   default:
@@ -611,7 +619,7 @@ static void diplomacy_response(struct gui_dialog *dlg, int response,
   case RESPONSE_CANCEL_MEETING:     /* Cancel meetings. */
     dsend_packet_diplomacy_cancel_meeting_req(&client.conn,
                                               player_number(
-                                                pdialog->treaty.plr1));
+                                                pdialog->treaty->plr1));
     break;
   }
 }
@@ -619,7 +627,8 @@ static void diplomacy_response(struct gui_dialog *dlg, int response,
 /************************************************************************//**
   Setups diplomacy dialog widgets.
 ****************************************************************************/
-static struct Diplomacy_dialog *create_diplomacy_dialog(struct player *plr0,
+static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty,
+                                                        struct player *plr0,
                                                         struct player *plr1)
 {
   struct Diplomacy_notebook *dipl_dialog;
@@ -638,7 +647,7 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct player *plr0,
   pdialog = fc_malloc(sizeof(*pdialog));
 
   dialog_list_prepend(dialog_list, pdialog);
-  init_treaty(&pdialog->treaty, plr0, plr1);
+  pdialog->treaty = ptreaty;
 
   /* Get main diplomacy tab. */
   dipl_dialog = diplomacy_main_create();
@@ -915,7 +924,7 @@ static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog)
   store = pdialog->store;
 
   gtk_list_store_clear(store);
-  clause_list_iterate(pdialog->treaty.clauses, pclause) {
+  clause_list_iterate(pdialog->treaty->clauses, pclause) {
     char buf[128];
 
     client_diplomacy_clause_string(buf, sizeof(buf), pclause);
@@ -932,10 +941,10 @@ static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog)
 		 	 "Please add some clauses. ---"), -1);
   }
 
-  pixbuf = get_thumb_pixbuf(pdialog->treaty.accept0);
+  pixbuf = get_thumb_pixbuf(pdialog->treaty->accept0);
   gtk_image_set_from_pixbuf(GTK_IMAGE(pdialog->image0), pixbuf);
   g_object_unref(G_OBJECT(pixbuf));
-  pixbuf = get_thumb_pixbuf(pdialog->treaty.accept1);
+  pixbuf = get_thumb_pixbuf(pdialog->treaty->accept1);
   gtk_image_set_from_pixbuf(GTK_IMAGE(pdialog->image1), pixbuf);
   g_object_unref(G_OBJECT(pixbuf));
 }
@@ -1018,7 +1027,7 @@ static void diplomacy_dialog_map_callback(GtkWidget *w, gpointer data)
   pgiver = (struct player *)g_object_get_data(G_OBJECT(w), "plr");
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
+                                           player_number(pdialog->treaty->plr1),
                                            player_number(pgiver), CLAUSE_MAP, 0);
 }
 
@@ -1033,7 +1042,7 @@ static void diplomacy_dialog_seamap_callback(GtkWidget *w, gpointer data)
   pgiver = (struct player *)g_object_get_data(G_OBJECT(w), "plr");
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
+                                           player_number(pdialog->treaty->plr1),
                                            player_number(pgiver), CLAUSE_SEAMAP,
                                            0);
 }
@@ -1047,8 +1056,8 @@ static void diplomacy_dialog_add_pact_clause(GtkWidget *w, gpointer data,
   struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *)data;
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
-                                           player_number(pdialog->treaty.plr0),
+                                           player_number(pdialog->treaty->plr1),
+                                           player_number(pdialog->treaty->plr0),
                                            type, 0);
 }
 
@@ -1086,7 +1095,7 @@ static void diplomacy_dialog_vision_callback(GtkWidget *w, gpointer data)
       (struct player *) g_object_get_data(G_OBJECT(w), "plr");
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
+                                           player_number(pdialog->treaty->plr1),
                                            player_number(pgiver), CLAUSE_VISION,
                                            0);
 }
@@ -1101,7 +1110,7 @@ static void diplomacy_dialog_embassy_callback(GtkWidget *w, gpointer data)
       (struct player *) g_object_get_data(G_OBJECT(w), "plr");
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
+                                           player_number(pdialog->treaty->plr1),
                                            player_number(pgiver), CLAUSE_EMBASSY,
                                            0);
 }
@@ -1134,14 +1143,13 @@ void diplomacy_dialog_done(void)
 /************************************************************************//**
   Find diplomacy dialog between player and other player
 ****************************************************************************/
-static struct Diplomacy_dialog *find_diplomacy_dialog(int other_player_id)
+static struct Diplomacy_dialog *find_diplomacy_dialog(struct player *they)
 {
   struct player *plr0 = client.conn.playing;
-  struct player *plr1 = player_by_number(other_player_id);
 
   dialog_list_iterate(dialog_list, pdialog) {
-    if ((pdialog->treaty.plr0 == plr0 && pdialog->treaty.plr1 == plr1)
-        || (pdialog->treaty.plr0 == plr1 && pdialog->treaty.plr1 == plr0)) {
+    if ((pdialog->treaty->plr0 == plr0 && pdialog->treaty->plr1 == they)
+        || (pdialog->treaty->plr0 == they && pdialog->treaty->plr1 == plr0)) {
       return pdialog;
     }
   } dialog_list_iterate_end;
@@ -1161,7 +1169,7 @@ static void diplo_dialog_returnkey(GtkWidget *w, gpointer data)
   
   if (amount >= 0 && amount <= pgiver->economic.gold) {
     dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              player_number(pgiver),
                                              CLAUSE_GOLD, amount);
   } else {
diff --git a/client/gui-gtk-4.0/diplodlg.c b/client/gui-gtk-4.0/diplodlg.c
index e236a13c39..72cf96d7aa 100644
--- a/client/gui-gtk-4.0/diplodlg.c
+++ b/client/gui-gtk-4.0/diplodlg.c
@@ -52,8 +52,8 @@
 #define MAX_NUM_CLAUSES 64
 
 struct Diplomacy_dialog {
-  struct Treaty treaty;
-  struct gui_dialog* dialog;
+  struct Treaty *treaty;
+  struct gui_dialog *dialog;
 
   GtkWidget *menu0;
   GtkWidget *menu1;
@@ -65,7 +65,7 @@ struct Diplomacy_dialog {
 };
 
 struct Diplomacy_notebook {
-  struct gui_dialog* dialog;
+  struct gui_dialog *dialog;
   GtkWidget *notebook;
 };
 
@@ -80,11 +80,13 @@ struct Diplomacy_notebook {
 static struct dialog_list *dialog_list;
 static struct Diplomacy_notebook *dipl_main;
 
-static struct Diplomacy_dialog *create_diplomacy_dialog(struct player *plr0,
-						 struct player *plr1);
+static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty,
+                                                        struct player *plr0,
+                                                        struct player *plr1);
 
-static struct Diplomacy_dialog *find_diplomacy_dialog(int other_player_id);
-static void popup_diplomacy_dialog(int other_player_id, int initiated_from);
+static struct Diplomacy_dialog *find_diplomacy_dialog(struct player *they);
+static void popup_diplomacy_dialog(struct Treaty *ptreaty, struct player *they,
+                                   struct player *initiator);
 
 #ifdef MENUS_GTK3
 static void diplomacy_dialog_map_callback(GtkWidget *w, gpointer data);
@@ -113,17 +115,15 @@ static void diplomacy_main_response(struct gui_dialog *dlg, int response,
 /************************************************************************//**
   Server tells us that either party has accepted treaty
 ****************************************************************************/
-void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
-                                    bool other_accepted)
+void gui_recv_accept_treaty(struct Treaty *ptreaty, struct player *they)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(counterpart);
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  pdialog->treaty.accept0 = I_accepted;
-  pdialog->treaty.accept1 = other_accepted;
+  fc_assert(pdialog->treaty == ptreaty);
 
   update_diplomacy_dialog(pdialog);
   gui_dialog_alert(pdialog->dialog);
@@ -132,38 +132,50 @@ void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
 /************************************************************************//**
   Someone is initiating meeting with us.
 ****************************************************************************/
-void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
+void gui_init_meeting(struct Treaty *ptreaty, struct player *they,
+                      struct player *initiator)
 {
-  popup_diplomacy_dialog(counterpart, initiated_from);
+  popup_diplomacy_dialog(ptreaty, they, initiator);
 }
 
 /************************************************************************//**
   Meeting has been cancelled.
 ****************************************************************************/
-void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
+void gui_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they,
+                             struct player *initiator)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(counterpart);
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
+  fc_assert(pdialog->treaty == ptreaty);
+
   close_diplomacy_dialog(pdialog);
 }
 
+/**********************************************************************//**
+  Prepare to clause creation or removal.
+**************************************************************************/
+void gui_prepare_clause_updt(struct Treaty *ptreaty, struct player *they)
+{
+  /* Not needed */
+}
+
 /************************************************************************//**
   Added clause to the meeting
 ****************************************************************************/
-void handle_diplomacy_create_clause(int counterpart, int giver,
-                                    enum clause_type type, int value)
+void gui_recv_create_clause(struct Treaty *ptreaty, struct player *they)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(counterpart);
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  add_clause(&pdialog->treaty, player_by_number(giver), type, value);
+  fc_assert(pdialog->treaty == ptreaty);
+
   update_diplomacy_dialog(pdialog);
   gui_dialog_alert(pdialog->dialog);
 }
@@ -171,16 +183,16 @@ void handle_diplomacy_create_clause(int counterpart, int giver,
 /************************************************************************//**
   Removed clause from meeting.
 ****************************************************************************/
-void handle_diplomacy_remove_clause(int counterpart, int giver,
-                                    enum clause_type type, int value)
+void gui_recv_remove_clause(struct Treaty *ptreaty, struct player *they)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(counterpart);
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  remove_clause(&pdialog->treaty, player_by_number(giver), type, value);
+  fc_assert(pdialog->treaty == ptreaty);
+
   update_diplomacy_dialog(pdialog);
   gui_dialog_alert(pdialog->dialog);
 }
@@ -188,26 +200,22 @@ void handle_diplomacy_remove_clause(int counterpart, int giver,
 /************************************************************************//**
   Popup the dialog 10% inside the main-window
 ****************************************************************************/
-static void popup_diplomacy_dialog(int other_player_id, int initiated_from)
+static void popup_diplomacy_dialog(struct Treaty *ptreaty, struct player *they,
+                                   struct player *initiator)
 {
-  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(other_player_id);
-
-  if (!can_client_issue_orders()) {
-    return;
-  }
+  struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
 
-  if (!is_human(client.conn.playing)) {
+  if (!is_human(client_player())) {
     return; /* Don't show if we are not human controlled. */
   }
 
   if (!pdialog) {
-    pdialog = create_diplomacy_dialog(client.conn.playing,
-				      player_by_number(other_player_id));
+    pdialog = create_diplomacy_dialog(ptreaty, client_player(), they);
   }
 
   gui_dialog_present(pdialog->dialog);
   /* We initated the meeting - Make the tab active */
-  if (player_by_number(initiated_from) == client.conn.playing) {
+  if (initiator == client_player()) {
     /* we have to raise the diplomacy meeting tab as well as the selected
      * meeting. */
     fc_assert_ret(dipl_main != NULL);
@@ -249,8 +257,8 @@ static void popup_add_menu(GtkMenuShell *parent, gpointer data)
 
   pdialog = (struct Diplomacy_dialog *) data;
   pgiver = (struct player *) g_object_get_data(G_OBJECT(parent), "plr");
-  pother = (pgiver == pdialog->treaty.plr0
-            ? pdialog->treaty.plr1 : pdialog->treaty.plr0);
+  pother = (pgiver == pdialog->treaty->plr0
+            ? pdialog->treaty->plr1 : pdialog->treaty->plr0);
 
 
   /* Maps. */
@@ -419,7 +427,7 @@ static void popup_add_menu(GtkMenuShell *parent, gpointer data)
 
 
   /* Pacts. */
-  if (pgiver == pdialog->treaty.plr0) {
+  if (pgiver == pdialog->treaty->plr0) {
     enum diplstate_type ds;
 
     ds = player_diplstate_get(pgiver, pother)->type;
@@ -464,10 +472,10 @@ static void row_callback(GtkTreeView *view, GtkTreePath *path,
   index = gtk_tree_path_get_indices(path);
 
   i = 0;
-  clause_list_iterate(pdialog->treaty.clauses, pclause) {
+  clause_list_iterate(pdialog->treaty->clauses, pclause) {
     if (i == index[0]) {
       dsend_packet_diplomacy_remove_clause_req(&client.conn,
-					       player_number(pdialog->treaty.plr1),
+					       player_number(pdialog->treaty->plr1),
 					       player_number(pclause->from),
 					       pclause->type,
 					       pclause->value);
@@ -553,7 +561,7 @@ static void diplomacy_main_response(struct gui_dialog *dlg, int response,
        * client. Closing the last dialog will also close the main tab.*/
       dsend_packet_diplomacy_cancel_meeting_req(&client.conn,
                                                 player_number(
-                                                  adialog->treaty.plr1));
+                                                  adialog->treaty->plr1));
     } dialog_list_iterate_end;
     break;
   }
@@ -604,7 +612,7 @@ static void diplomacy_response(struct gui_dialog *dlg, int response,
   case GTK_RESPONSE_ACCEPT:         /* Accept treaty. */
     dsend_packet_diplomacy_accept_treaty_req(&client.conn,
                                              player_number(
-                                               pdialog->treaty.plr1));
+                                               pdialog->treaty->plr1));
     break;
 
   default:
@@ -615,7 +623,7 @@ static void diplomacy_response(struct gui_dialog *dlg, int response,
   case RESPONSE_CANCEL_MEETING:     /* Cancel meetings. */
     dsend_packet_diplomacy_cancel_meeting_req(&client.conn,
                                               player_number(
-                                                pdialog->treaty.plr1));
+                                                pdialog->treaty->plr1));
     break;
   }
 }
@@ -623,7 +631,8 @@ static void diplomacy_response(struct gui_dialog *dlg, int response,
 /************************************************************************//**
   Setups diplomacy dialog widgets.
 ****************************************************************************/
-static struct Diplomacy_dialog *create_diplomacy_dialog(struct player *plr0,
+static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty,
+                                                        struct player *plr0,
                                                         struct player *plr1)
 {
   struct Diplomacy_notebook *dipl_dialog;
@@ -648,7 +657,7 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct player *plr0,
   pdialog = fc_malloc(sizeof(*pdialog));
 
   dialog_list_prepend(dialog_list, pdialog);
-  init_treaty(&pdialog->treaty, plr0, plr1);
+  pdialog->treaty = ptreaty;
 
   /* Get main diplomacy tab. */
   dipl_dialog = diplomacy_main_create();
@@ -933,7 +942,7 @@ static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog)
   store = pdialog->store;
 
   gtk_list_store_clear(store);
-  clause_list_iterate(pdialog->treaty.clauses, pclause) {
+  clause_list_iterate(pdialog->treaty->clauses, pclause) {
     char buf[128];
 
     client_diplomacy_clause_string(buf, sizeof(buf), pclause);
@@ -950,10 +959,10 @@ static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog)
 		 	 "Please add some clauses. ---"), -1);
   }
 
-  pixbuf = get_thumb_pixbuf(pdialog->treaty.accept0);
+  pixbuf = get_thumb_pixbuf(pdialog->treaty->accept0);
   gtk_image_set_from_pixbuf(GTK_IMAGE(pdialog->image0), pixbuf);
   g_object_unref(G_OBJECT(pixbuf));
-  pixbuf = get_thumb_pixbuf(pdialog->treaty.accept1);
+  pixbuf = get_thumb_pixbuf(pdialog->treaty->accept1);
   gtk_image_set_from_pixbuf(GTK_IMAGE(pdialog->image1), pixbuf);
   g_object_unref(G_OBJECT(pixbuf));
 }
@@ -1037,7 +1046,7 @@ static void diplomacy_dialog_map_callback(GtkWidget *w, gpointer data)
   pgiver = (struct player *)g_object_get_data(G_OBJECT(w), "plr");
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
+                                           player_number(pdialog->treaty->plr1),
                                            player_number(pgiver), CLAUSE_MAP, 0);
 }
 
@@ -1052,7 +1061,7 @@ static void diplomacy_dialog_seamap_callback(GtkWidget *w, gpointer data)
   pgiver = (struct player *)g_object_get_data(G_OBJECT(w), "plr");
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
+                                           player_number(pdialog->treaty->plr1),
                                            player_number(pgiver), CLAUSE_SEAMAP,
                                            0);
 }
@@ -1066,8 +1075,8 @@ static void diplomacy_dialog_add_pact_clause(GtkWidget *w, gpointer data,
   struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *)data;
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
-                                           player_number(pdialog->treaty.plr0),
+                                           player_number(pdialog->treaty->plr1),
+                                           player_number(pdialog->treaty->plr0),
                                            type, 0);
 }
 
@@ -1105,7 +1114,7 @@ static void diplomacy_dialog_vision_callback(GtkWidget *w, gpointer data)
       (struct player *) g_object_get_data(G_OBJECT(w), "plr");
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
+                                           player_number(pdialog->treaty->plr1),
                                            player_number(pgiver), CLAUSE_VISION,
                                            0);
 }
@@ -1120,7 +1129,7 @@ static void diplomacy_dialog_embassy_callback(GtkWidget *w, gpointer data)
       (struct player *) g_object_get_data(G_OBJECT(w), "plr");
 
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(pdialog->treaty.plr1),
+                                           player_number(pdialog->treaty->plr1),
                                            player_number(pgiver), CLAUSE_EMBASSY,
                                            0);
 }
@@ -1154,14 +1163,13 @@ void diplomacy_dialog_done(void)
 /************************************************************************//**
   Find diplomacy dialog between player and other player
 ****************************************************************************/
-static struct Diplomacy_dialog *find_diplomacy_dialog(int other_player_id)
+static struct Diplomacy_dialog *find_diplomacy_dialog(struct player *they)
 {
   struct player *plr0 = client.conn.playing;
-  struct player *plr1 = player_by_number(other_player_id);
 
   dialog_list_iterate(dialog_list, pdialog) {
-    if ((pdialog->treaty.plr0 == plr0 && pdialog->treaty.plr1 == plr1)
-        || (pdialog->treaty.plr0 == plr1 && pdialog->treaty.plr1 == plr0)) {
+    if ((pdialog->treaty->plr0 == plr0 && pdialog->treaty->plr1 == they)
+        || (pdialog->treaty->plr0 == they && pdialog->treaty->plr1 == plr0)) {
       return pdialog;
     }
   } dialog_list_iterate_end;
@@ -1181,7 +1189,7 @@ static void diplo_dialog_returnkey(GtkWidget *w, gpointer data)
 
   if (amount >= 0 && amount <= pgiver->economic.gold) {
     dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              player_number(pgiver),
                                              CLAUSE_GOLD, amount);
   } else {
diff --git a/client/gui-qt/diplodlg.cpp b/client/gui-qt/diplodlg.cpp
index 792d2d0a08..3461694c05 100644
--- a/client/gui-qt/diplodlg.cpp
+++ b/client/gui-qt/diplodlg.cpp
@@ -51,8 +51,10 @@ extern QApplication *qapp;
 /************************************************************************//**
   Constructor for diplomacy widget
 ****************************************************************************/
-diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
+diplo_wdg::diplo_wdg(struct Treaty *ptreaty,
+                     struct player *they, struct player *initiator): QWidget()
 {
+  struct player *we;
   color *colr;
   QString text;
   QString text2;
@@ -77,19 +79,19 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
     get_color(tileset, COLOR_MAPVIEW_CITYTEXT),
     get_color(tileset, COLOR_MAPVIEW_CITYTEXT_DARK)
   };
-  if (counterpart == initiated_from) {
-    initiated_from = client_player_number();
+  if (they == initiator) {
+    we = client_player();
+  } else {
+    we = initiator;
   }
   p1_accept = false;
   p2_accept = false;
-  player1 = initiated_from;
-  player2 = counterpart;
+  plr1 = we;
+  plr2 = they;
   layout = new QGridLayout;
 
-  init_treaty(&treaty, player_by_number(counterpart),
-              player_by_number(initiated_from));
-  state = player_diplstate_get(player_by_number(player1),
-                               player_by_number(player2));
+  treaty = ptreaty;
+  state = player_diplstate_get(we, they);
   text_tooltip = QString(diplstate_type_translated_name(state->type));
   if (state->turns_left > 0) {
     text_tooltip = text_tooltip + " (";
@@ -101,10 +103,10 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
   }
   label3 = new QLabel;
   text = "<b><h3><center>"
-         + QString(nation_plural_for_player(player_by_number(initiated_from)))
+         + QString(nation_plural_for_player(we))
            .toHtmlEscaped()
          + "</center></h3></b>";
-  colr = get_player_color(tileset, player_by_number(initiated_from));
+  colr = get_player_color(tileset, we);
   text = "<style>h3{background-color: "
          + colr->qcolor.name() + ";" + "color: " + color_best_contrast(colr,
              textcolors, ARRAY_SIZE(textcolors))->qcolor.name()
@@ -113,10 +115,10 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
   label3->setMinimumWidth(300);
   label4 = new QLabel;
   text = "<b><h3><center>"
-         + QString(nation_plural_for_player(player_by_number(counterpart)))
+         + QString(nation_plural_for_player(they))
            .toHtmlEscaped()
          + "</center></h3></b></body>";
-  colr = get_player_color(tileset, player_by_number(counterpart));
+  colr = get_player_color(tileset, they);
   text = "<style>h3{background-color: "
          + colr->qcolor.name() + ";" + "color: " + color_best_contrast(colr,
              textcolors, ARRAY_SIZE(textcolors))->qcolor.name()
@@ -128,16 +130,14 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
   plr1_label = new QLabel;
   label = new QLabel;
   sprite = get_nation_flag_sprite(tileset,
-                                  nation_of_player(player_by_number
-                                                   (initiated_from)));
+                                  nation_of_player(we));
   if (sprite != NULL) {
     pix = sprite->pm;
     plr1_label->setPixmap(*pix);
   } else {
     plr1_label->setText("FLAG MISSING");
   }
-  text = ruler_title_for_player(player_by_number(initiated_from),
-                                plr_buf, sizeof(plr_buf));
+  text = ruler_title_for_player(we, plr_buf, sizeof(plr_buf));
   text = "<b><center>" + text.toHtmlEscaped() + "</center></b>";
   label->setText(text);
   plr1_accept = new QLabel;
@@ -146,8 +146,7 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
   layout->addWidget(plr1_accept, 1, 10);
   label2 = new QLabel;
   sprite2 = get_nation_flag_sprite(tileset,
-                                   nation_of_player(player_by_number
-                                                    (counterpart)));
+                                   nation_of_player(they));
   plr2_label = new QLabel;
   if (sprite2 != NULL) {
     pix = sprite2->pm;
@@ -155,8 +154,7 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
   } else {
     plr2_label->setText("FLAG MISSING");
   }
-  text2 = ruler_title_for_player(player_by_number(counterpart),
-                                 plr_buf, sizeof(plr_buf));
+  text2 = ruler_title_for_player(they, plr_buf, sizeof(plr_buf));
   text2 = "<b><center>" + text2.toHtmlEscaped() + "</center></b>";
   label2->setText(text2);
   plr2_accept = new QLabel;
@@ -174,8 +172,8 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
   gold_edit1->setFocusPolicy(Qt::ClickFocus);
   gold_edit2->setFocusPolicy(Qt::ClickFocus);
   if (game.info.trading_gold) {
-    gold_edit2->setMaximum(player_by_number(player1)->economic.gold);
-    gold_edit1->setMaximum(player_by_number(player2)->economic.gold);
+    gold_edit2->setMaximum(we->economic.gold);
+    gold_edit1->setMaximum(they->economic.gold);
   }
   connect(gold_edit1, SIGNAL(valueChanged(int)), SLOT(gold_changed1(int)));
   connect(gold_edit2, SIGNAL(valueChanged(int)), SLOT(gold_changed2(int)));
@@ -221,11 +219,11 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
   layout->addWidget(accept_treaty, 17, 5);
   layout->addWidget(cancel_treaty, 17, 6);
 
-  if (client_player_number() != counterpart) {
+  if (client_player() != they) {
     label4->setToolTip(text_tooltip);
     plr2_label->setToolTip(text_tooltip);
   }
-  if (client_player_number() != initiated_from) {
+  if (client_player() != we) {
     label3->setToolTip(text_tooltip);
     plr1_label->setToolTip(text_tooltip);
   }
@@ -235,7 +233,6 @@ diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
   cancel_treaty->setAutoDefault(true);
   setLayout(layout);
   update_wdg();
-
 }
 
 /************************************************************************//**
@@ -254,10 +251,10 @@ void diplo_wdg::dbl_click(QTableWidgetItem *item)
 
   r = item->row();
   i = 0;
-  clause_list_iterate(treaty.clauses, pclause) {
+  clause_list_iterate(treaty->clauses, pclause) {
     if (i == r) {
       dsend_packet_diplomacy_remove_clause_req(&client.conn,
-                                               player_number(treaty.plr0),
+                                               player_number(treaty->plr1),
                                                player_number(pclause->from),
                                                pclause->type,
                                                pclause->value);
@@ -284,7 +281,8 @@ void diplo_wdg::closeEvent(QCloseEvent *event)
 void diplo_wdg::gold_changed1(int val)
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player2, player2,
+                                           player_number(plr2),
+                                           player_number(plr2),
                                            CLAUSE_GOLD, val);
 }
 
@@ -294,16 +292,17 @@ void diplo_wdg::gold_changed1(int val)
 void diplo_wdg::gold_changed2(int val)
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player2, player1,
+                                           player_number(plr2),
+                                           player_number(plr1),
                                            CLAUSE_GOLD, val);
 }
 
 /************************************************************************//**
   Shows popup menu with available clauses to create
 ****************************************************************************/
-void diplo_wdg::show_menu(int player)
+void diplo_wdg::show_menu(struct player *pplayer)
 {
-  int other_player;
+  struct player *other_player;
   struct player *pgiver, *pother;
   enum diplstate_type ds;
   QAction *all_advancs;
@@ -317,14 +316,14 @@ void diplo_wdg::show_menu(int player)
   QMenu *menu = new QMenu(this);
   int id;
 
-  curr_player = player;
-  if (curr_player == player1) {
-    other_player = player2;
+  curr_player = pplayer;
+  if (curr_player == plr1) {
+    other_player = plr2;
   } else {
-    other_player = player1;
+    other_player = plr1;
   }
-  pgiver = player_by_number(player);
-  pother = player_by_number(other_player);
+  pgiver = pplayer;
+  pother = other_player;
 
   /* Maps */
   map_menu = menu->addMenu(_("Maps"));
@@ -339,6 +338,7 @@ void diplo_wdg::show_menu(int player)
   if (game.info.trading_tech) {
     const struct research *gresearch = research_get(pgiver);
     const struct research *oresearch = research_get(pother);
+
     adv_menu = menu->addMenu(_("Advances"));
     advance_iterate(padvance) {
       Tech_type_id i = advance_number(padvance);
@@ -414,7 +414,7 @@ void diplo_wdg::show_menu(int player)
   }
 
   /* Pacts */
-  if (player_by_number(curr_player) == client_player()) {
+  if (curr_player == client_player()) {
     pacts_menu = menu->addMenu(_("Pacts"));
     ds = player_diplstate_get(pgiver, pother)->type;
     some_action = new QAction(Q_("?diplomatic_state:Cease-fire"), this);
@@ -448,8 +448,9 @@ void diplo_wdg::show_menu(int player)
 void diplo_wdg::give_embassy()
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(treaty.plr0),
-                                           curr_player, CLAUSE_EMBASSY, 0);
+                                           player_number(treaty->plr1),
+                                           player_number(curr_player),
+                                           CLAUSE_EMBASSY, 0);
 }
 
 /************************************************************************//**
@@ -458,8 +459,9 @@ void diplo_wdg::give_embassy()
 void diplo_wdg::give_shared_vision()
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(treaty.plr0),
-                                           curr_player, CLAUSE_VISION, 0);
+                                           player_number(treaty->plr1),
+                                           player_number(curr_player),
+                                           CLAUSE_VISION, 0);
 }
 
 /************************************************************************//**
@@ -468,8 +470,9 @@ void diplo_wdg::give_shared_vision()
 void diplo_wdg::pact_allianze()
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(treaty.plr0),
-                                           curr_player, CLAUSE_ALLIANCE, 0);
+                                           player_number(treaty->plr1),
+                                           player_number(curr_player),
+                                           CLAUSE_ALLIANCE, 0);
 }
 
 /************************************************************************//**
@@ -478,8 +481,9 @@ void diplo_wdg::pact_allianze()
 void diplo_wdg::pact_ceasfire()
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(treaty.plr0),
-                                           curr_player, CLAUSE_CEASEFIRE, 0);
+                                           player_number(treaty->plr1),
+                                           player_number(curr_player),
+                                           CLAUSE_CEASEFIRE, 0);
 }
 
 /************************************************************************//**
@@ -488,8 +492,9 @@ void diplo_wdg::pact_ceasfire()
 void diplo_wdg::pact_peace()
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(treaty.plr0),
-                                           curr_player, CLAUSE_PEACE, 0);
+                                           player_number(treaty->plr1),
+                                           player_number(curr_player),
+                                           CLAUSE_PEACE, 0);
 }
 
 /************************************************************************//**
@@ -498,8 +503,9 @@ void diplo_wdg::pact_peace()
 void diplo_wdg::sea_map_clause()
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(treaty.plr0),
-                                           curr_player, CLAUSE_SEAMAP, 0);
+                                           player_number(treaty->plr1),
+                                           player_number(curr_player),
+                                           CLAUSE_SEAMAP, 0);
 }
 
 /************************************************************************//**
@@ -508,8 +514,9 @@ void diplo_wdg::sea_map_clause()
 void diplo_wdg::world_map_clause()
 {
   dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                           player_number(treaty.plr0),
-                                           curr_player, CLAUSE_MAP, 0);
+                                           player_number(treaty->plr1),
+                                           player_number(curr_player),
+                                           CLAUSE_MAP, 0);
 }
 
 /************************************************************************//**
@@ -517,22 +524,23 @@ void diplo_wdg::world_map_clause()
 ****************************************************************************/
 void diplo_wdg::give_city(int city_num)
 {
-  int giver, dest, other;
+  struct player *giver, *dest, *other;
 
   giver = curr_player;
-  if (curr_player == player1) {
-    dest = player2;
+  if (curr_player == plr1) {
+    dest = plr2;
   } else {
-    dest = player1;
+    dest = plr1;
   }
 
-  if (player_by_number(giver) == client_player()) {
+  if (giver == client_player()) {
     other = dest;
   } else {
     other = giver;
   }
 
-  dsend_packet_diplomacy_create_clause_req(&client.conn, other, giver,
+  dsend_packet_diplomacy_create_clause_req(&client.conn, player_number(other),
+                                           player_number(giver),
                                            CLAUSE_CITY, city_num);
 }
 
@@ -541,22 +549,23 @@ void diplo_wdg::give_city(int city_num)
 ****************************************************************************/
 void diplo_wdg::give_advance(int tech)
 {
-  int giver, dest, other;
+  struct player *giver, *dest, *other;
 
   giver = curr_player;
-  if (curr_player == player1) {
-    dest = player2;
+  if (curr_player == plr1) {
+    dest = plr2;
   } else {
-    dest = player1;
+    dest = plr1;
   }
 
-  if (player_by_number(giver) == client_player()) {
+  if (giver == client_player()) {
     other = dest;
   } else {
     other = giver;
   }
 
-  dsend_packet_diplomacy_create_clause_req(&client.conn, other, giver,
+  dsend_packet_diplomacy_create_clause_req(&client.conn, player_number(other),
+                                           player_number(giver),
                                            CLAUSE_ADVANCE, tech);
 }
 
@@ -565,45 +574,41 @@ void diplo_wdg::give_advance(int tech)
 ****************************************************************************/
 void diplo_wdg::all_advances()
 {
-  int giver, dest, other;
+  struct player *giver, *dest, *other;
   const struct research *dresearch, *gresearch;
 
   giver = curr_player;
-  if (curr_player == player1) {
-    dest = player2;
+  if (curr_player == plr1) {
+    dest = plr2;
   } else {
-    dest = player1;
+    dest = plr1;
   }
 
-  if (player_by_number(giver) == client_player()) {
+  if (giver == client_player()) {
     other = dest;
   } else {
     other = giver;
   }
 
   /* All techs. */
-  struct player *pgiver = player_by_number(giver);
-  struct player *pdest = player_by_number(dest);
-
-  fc_assert_ret(NULL != pgiver);
-  fc_assert_ret(NULL != pdest);
-
-   dresearch = research_get(pdest);
-   gresearch = research_get(pgiver);
-
-   advance_iterate(padvance) {
-     Tech_type_id i = advance_number(padvance);
-
-     if (research_invention_state(gresearch, i) == TECH_KNOWN
-         && research_invention_gettable(dresearch, i,
-                                        game.info.tech_trade_allow_holes)
-         && (research_invention_state(dresearch, i) == TECH_UNKNOWN
-             || research_invention_state(dresearch, i)
-                == TECH_PREREQS_KNOWN)) {
-       dsend_packet_diplomacy_create_clause_req(&client.conn, other, giver,
-                                                CLAUSE_ADVANCE, i);
-     }
-   } advance_iterate_end;
+
+  dresearch = research_get(dest);
+  gresearch = research_get(giver);
+
+  advance_iterate(padvance) {
+    Tech_type_id i = advance_number(padvance);
+
+    if (research_invention_state(gresearch, i) == TECH_KNOWN
+        && research_invention_gettable(dresearch, i,
+                                       game.info.tech_trade_allow_holes)
+        && (research_invention_state(dresearch, i) == TECH_UNKNOWN
+            || research_invention_state(dresearch, i)
+            == TECH_PREREQS_KNOWN)) {
+      dsend_packet_diplomacy_create_clause_req(&client.conn, player_number(other),
+                                               player_number(giver),
+                                               CLAUSE_ADVANCE, i);
+    }
+  } advance_iterate_end;
 }
 
 /************************************************************************//**
@@ -611,7 +616,7 @@ void diplo_wdg::all_advances()
 ****************************************************************************/
 void diplo_wdg::show_menu_p2()
 {
-  show_menu(player2);
+  show_menu(plr2);
 }
 
 /************************************************************************//**
@@ -619,7 +624,7 @@ void diplo_wdg::show_menu_p2()
 ****************************************************************************/
 void diplo_wdg::show_menu_p1()
 {
-  show_menu(player1);
+  show_menu(plr1);
 }
 
 /************************************************************************//**
@@ -653,8 +658,9 @@ void diplo_wdg::update_wdg()
   text_edit->clearContents();
   text_edit->setRowCount(0);
   i = 0;
-  clause_list_iterate(treaty.clauses, pclause) {
+  clause_list_iterate(treaty->clauses, pclause) {
     char buf[128];
+
     client_diplomacy_clause_string(buf, sizeof(buf), pclause);
     text_edit->insertRow(i);
     qitem = new QTableWidgetItem();
@@ -674,7 +680,7 @@ void diplo_wdg::update_wdg()
     text_edit->setItem(0, 0, qitem);
   }
 
-  sprite = get_treaty_thumb_sprite(tileset, treaty.accept0);
+  sprite = get_treaty_thumb_sprite(tileset, treaty->accept1);
   if (sprite != NULL) {
     pix = sprite->pm;
     plr1_accept->setPixmap(*pix);
@@ -682,7 +688,7 @@ void diplo_wdg::update_wdg()
     plr1_accept->setText("PIXMAP MISSING");
   }
 
-  sprite = get_treaty_thumb_sprite(tileset, treaty.accept1);
+  sprite = get_treaty_thumb_sprite(tileset, treaty->accept0);
   if (sprite != NULL) {
     pix = sprite->pm;
     plr2_accept->setPixmap(*pix);
@@ -710,7 +716,7 @@ void diplo_wdg::response_accept()
 {
   restore_pixmap();
   dsend_packet_diplomacy_accept_treaty_req(&client.conn,
-                                           player_number(treaty.plr0));
+                                           player_number(treaty->plr1));
 }
 
 /************************************************************************//**
@@ -720,22 +726,24 @@ void diplo_wdg::response_cancel()
 {
   restore_pixmap();
   dsend_packet_diplomacy_cancel_meeting_req(&client.conn,
-                                            player_number(treaty.plr0));
+                                            player_number(treaty->plr1));
 }
 
 /************************************************************************//**
   Constructor for diplomacy dialog
 ****************************************************************************/
-diplo_dlg::diplo_dlg(int counterpart, int initiated_from): QTabWidget()
+diplo_dlg::diplo_dlg(struct Treaty *ptreaty, struct player *they,
+                     struct player *initiator) : QTabWidget()
 {
-  add_widget(counterpart, initiated_from);
+  add_widget(ptreaty, they, initiator);
   setFocusPolicy(Qt::ClickFocus);
 }
 
 /************************************************************************//**
   Creates new diplomacy widget and adds to diplomacy dialog
 ****************************************************************************/
-void diplo_dlg::add_widget(int counterpart, int initiated_from)
+void diplo_dlg::add_widget(struct Treaty *ptreaty, struct player *they,
+                           struct player *initiator)
 {
   diplo_wdg *dw;
   struct sprite *sprite;
@@ -743,13 +751,12 @@ void diplo_dlg::add_widget(int counterpart, int initiated_from)
   int i;
 
   pix = NULL;
-  dw = new diplo_wdg(counterpart, initiated_from);
-  treaty_list.insert(counterpart, dw);
-  i = addTab(dw, nation_plural_for_player(player_by_number(counterpart)));
+  dw = new diplo_wdg(ptreaty, they, initiator);
+  treaty_list.insert(they, dw);
+  i = addTab(dw, nation_plural_for_player(they));
   dw->set_index(i);
   sprite = get_nation_flag_sprite(tileset,
-                                  nation_of_player(player_by_number
-                                                   (counterpart)));
+                                  nation_of_player(they));
   if (sprite != NULL) {
     pix = sprite->pm;
   }
@@ -761,12 +768,12 @@ void diplo_dlg::add_widget(int counterpart, int initiated_from)
 /************************************************************************//**
   Sets given widget as active in current dialog
 ****************************************************************************/
-void diplo_dlg::make_active(int party)
+void diplo_dlg::make_active(struct player *party)
 {
   QWidget *w;
 
   w = find_widget(party);
-  if (w == NULL) {
+  if (w == nullptr) {
     return;
   }
   setCurrentWidget(w);
@@ -780,7 +787,7 @@ bool diplo_dlg::init(bool raise)
   if (!can_client_issue_orders()) {
     return false;
   }
-  if (!is_human(client.conn.playing)) {
+  if (!is_human(client_player())) {
     return false;
   }
   setAttribute(Qt::WA_DeleteOnClose);
@@ -796,7 +803,7 @@ bool diplo_dlg::init(bool raise)
 ****************************************************************************/
 diplo_dlg::~diplo_dlg()
 {
-  QMapIterator<int, diplo_wdg *>i(treaty_list);
+  QMapIterator<struct player *, diplo_wdg *>i(treaty_list);
   diplo_wdg *dw;
 
   while (i.hasNext()) {
@@ -813,19 +820,19 @@ diplo_dlg::~diplo_dlg()
 /************************************************************************//**
   Finds diplomacy widget in current dialog
 ****************************************************************************/
-diplo_wdg *diplo_dlg::find_widget(int counterpart)
+diplo_wdg *diplo_dlg::find_widget(struct player *they)
 {
-  return treaty_list.value(counterpart);
+  return treaty_list.value(they);
 }
 
 /************************************************************************//**
   Closes given diplomacy widget
 ****************************************************************************/
-void diplo_dlg::close_widget(int counterpart)
+void diplo_dlg::close_widget(struct player *they)
 {
   diplo_wdg *dw;
 
-  dw = treaty_list.take(counterpart);
+  dw = treaty_list.take(they);
   removeTab(dw->get_index());
   dw->deleteLater();
   if (treaty_list.isEmpty()) {
@@ -838,7 +845,7 @@ void diplo_dlg::close_widget(int counterpart)
 ****************************************************************************/
 void diplo_dlg::update_dlg()
 {
-  QMapIterator <int, diplo_wdg *>i(treaty_list);
+  QMapIterator <struct player *, diplo_wdg *>i(treaty_list);
   diplo_wdg *dw;
 
   while (i.hasNext()) {
@@ -852,8 +859,7 @@ void diplo_dlg::update_dlg()
   Update a player's acceptance status of a treaty (traditionally shown
   with the thumbs-up/thumbs-down sprite).
 ****************************************************************************/
-void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
-                                    bool other_accepted)
+void qtg_recv_accept_treaty(struct Treaty *ptreaty, struct player *they)
 {
   int i;
   diplo_dlg *dd;
@@ -867,20 +873,20 @@ void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
   fc_assert(i != -1);
   w = gui()->game_tab_widget->widget(i);
   dd = qobject_cast<diplo_dlg *>(w);
-  dw = dd->find_widget(counterpart);
-  dw->treaty.accept0 = I_accepted;
-  dw->treaty.accept1 = other_accepted;
-  dw->update_wdg();
+  dw = dd->find_widget(they);
 
+  fc_assert(dw->treaty == ptreaty);
+
+  dw->update_wdg();
 }
 
 /************************************************************************//**
   Handle the start of a diplomacy meeting - usually by poping up a
   diplomacy dialog.
 ****************************************************************************/
-void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
+void qtg_init_meeting(struct Treaty *ptreaty, struct player *they,
+                      struct player *initiator)
 {
-
   int i;
   diplo_dlg *dd;
   QPainter p;
@@ -899,8 +905,7 @@ void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
   pix2 = new QPixmap();
   def_pix_del = new QPixmap();
   pix = get_nation_flag_sprite(tileset,
-                                  nation_of_player(player_by_number
-                                                   (counterpart)))->pm;
+                               nation_of_player(they))->pm;
   *pix2 = pix->scaledToWidth(gui()->sw_diplo->width() - 2,
                              Qt::SmoothTransformation);
   if (pix2->height() > gui()->sw_diplo->height()) {
@@ -922,43 +927,50 @@ void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
   gui()->sw_diplo->resize_pixmap(gui()->sw_diplo->width(),
                                  gui()->sw_diplo->height());
   gui()->sw_diplo->set_custom_labels(QString(nation_plural_for_player(
-                                            player_by_number(counterpart))));
+                                                               they)));
   gui()->sw_diplo->update_final_pixmap();
   delete pix2;
   delete def_pix_del;
 
   if (!gui()->is_repo_dlg_open("DDI")) {
-    dd = new diplo_dlg(counterpart, initiated_from);
+    dd = new diplo_dlg(ptreaty, they, initiator);
 
     if (!dd->init(false)) {
       delete dd;
       return;
     }
     dd->update_dlg();
-    dd->make_active(counterpart);
+    dd->make_active(they);
   }
   i = gui()->gimme_index_of("DDI");
   fc_assert(i != -1);
   w = gui()->game_tab_widget->widget(i);
   dd = qobject_cast<diplo_dlg *>(w);
-  fw = dd->find_widget(counterpart);
+  fw = dd->find_widget(they);
   if (fw == NULL) {
-    dd->add_widget(counterpart, initiated_from);
+    dd->add_widget(ptreaty, they, initiator);
     gui()->game_tab_widget->setCurrentIndex(i);
   }
-  dd->make_active(counterpart);
+  dd->make_active(they);
 
   /* Bring it to front if user requested meeting */
-  if (player_by_number(initiated_from) == client.conn.playing) {
+  if (initiator == client_player()) {
     gui()->game_tab_widget->setCurrentIndex(i);
   }
 }
 
+/**********************************************************************//**
+  Prepare to clause creation or removal.
+**************************************************************************/
+void qtg_prepare_clause_updt(struct Treaty *ptreaty, struct player *they)
+{
+  // Not needed
+}
+
 /************************************************************************//**
   Update the diplomacy dialog by adding a clause.
 ****************************************************************************/
-void handle_diplomacy_create_clause(int counterpart, int giver,
-                                    enum clause_type type, int value)
+void qtg_recv_create_clause(struct Treaty *ptreaty, struct player *they)
 {
   int i;
   diplo_dlg *dd;
@@ -966,14 +978,15 @@ void handle_diplomacy_create_clause(int counterpart, int giver,
   QWidget *w;
 
   if (!gui()->is_repo_dlg_open("DDI")) {
+    log_normal("DDI not open");
     return;
   }
   i = gui()->gimme_index_of("DDI");
   fc_assert(i != -1);
   w = gui()->game_tab_widget->widget(i);
   dd = qobject_cast<diplo_dlg *>(w);
-  dw = dd->find_widget(counterpart);
-  add_clause(&dw->treaty, player_by_number(giver), type, value);
+  dw = dd->find_widget(they);
+  fc_assert(dw->treaty == ptreaty);
   dw->update_wdg();
 }
 
@@ -981,7 +994,8 @@ void handle_diplomacy_create_clause(int counterpart, int giver,
   Update the diplomacy dialog when the meeting is canceled (the dialog
   should be closed).
 ****************************************************************************/
-void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
+void qtg_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they,
+                             struct player *initiator)
 {
   int i;
   diplo_dlg *dd;
@@ -994,17 +1008,14 @@ void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
   fc_assert(i != -1);
   w = gui()->game_tab_widget->widget(i);
   dd = qobject_cast<diplo_dlg *>(w);
-  dd->close_widget(counterpart);
-
+  dd->close_widget(they);
 }
 
 /************************************************************************//**
   Update the diplomacy dialog by removing a clause.
 ****************************************************************************/
-void handle_diplomacy_remove_clause(int counterpart, int giver,
-                                    enum clause_type type, int value)
+void qtg_recv_remove_clause(struct Treaty *ptreaty, struct player *they)
 {
-
   int i;
   diplo_dlg *dd;
   diplo_wdg *dw;
@@ -1013,14 +1024,14 @@ void handle_diplomacy_remove_clause(int counterpart, int giver,
   if (!gui()->is_repo_dlg_open("DDI")) {
     return;
   }
+
   i = gui()->gimme_index_of("DDI");
   fc_assert(i != -1);
   w = gui()->game_tab_widget->widget(i);
   dd = qobject_cast<diplo_dlg *>(w);
-  dw = dd->find_widget(counterpart);
-  remove_clause(&dw->treaty, player_by_number(giver), type, value);
+  dw = dd->find_widget(they);
+  fc_assert(dw->treaty == ptreaty);
   dw->update_wdg();
-
 }
 
 /************************************************************************//**
diff --git a/client/gui-qt/diplodlg.h b/client/gui-qt/diplodlg.h
index 128dd67582..1d4e47e9ea 100644
--- a/client/gui-qt/diplodlg.h
+++ b/client/gui-qt/diplodlg.h
@@ -59,12 +59,13 @@ class diplo_wdg: public QWidget
   QTableWidget *text_edit;
 
 public:
-  diplo_wdg(int id, int id2);
+  diplo_wdg(struct Treaty *ptreaty,
+            struct player *they, struct player *initiator);
   ~diplo_wdg();
   void update_wdg();
   void set_index(int ind);
   int get_index();
-  struct Treaty treaty;
+  struct Treaty *treaty;
 
 private slots:
   void all_advances();
@@ -81,7 +82,7 @@ private slots:
   void response_accept();
   void response_cancel();
   void sea_map_clause();
-  void show_menu(int player);
+  void show_menu(struct player *pplayer);
   void show_menu_p1();
   void show_menu_p2();
   void world_map_clause();
@@ -90,10 +91,10 @@ private slots:
 protected:
   void closeEvent(QCloseEvent *event);
 private:
-  int player1;
-  int player2;
+  struct player *plr1;
+  struct player *plr2;
   int active_menu;
-  int curr_player;
+  struct player *curr_player;
   bool p1_accept;
   bool p2_accept;
   int index;
@@ -105,17 +106,19 @@ private:
 class diplo_dlg: public QTabWidget
 {
   Q_OBJECT
-  QMap<int, diplo_wdg *> treaty_list;
+  QMap<struct player *, diplo_wdg *> treaty_list;
 
 public:
-  diplo_dlg(int counterpart, int initiated_from);
+  diplo_dlg(struct Treaty *ptreaty, struct player *they,
+            struct player *initiator);
   ~diplo_dlg();
   void update_dlg();
   bool init(bool raise);
-  diplo_wdg *find_widget(int counterpart);
-  void close_widget(int counterpart);
-  void add_widget(int counterpart, int initiated_from);
-  void make_active(int party);
+  diplo_wdg *find_widget(struct player *they);
+  void close_widget(struct player *they);
+  void add_widget(struct Treaty *ptreaty, struct player *they,
+                  struct player *initiator);
+  void make_active(struct player *party);
 
 private:
   int index;
diff --git a/client/gui-qt/qtg_cxxside.cpp b/client/gui-qt/qtg_cxxside.cpp
index 62518a0193..a94746a826 100644
--- a/client/gui-qt/qtg_cxxside.cpp
+++ b/client/gui-qt/qtg_cxxside.cpp
@@ -112,4 +112,11 @@ void setup_gui_funcs()
   funcs->gui_clear_theme = qtg_gui_clear_theme;
   funcs->get_gui_specific_themes_directories = qtg_get_gui_specific_themes_directories;
   funcs->get_useable_themes_in_directory = qtg_get_useable_themes_in_directory;
+
+  funcs->gui_init_meeting = qtg_init_meeting;
+  funcs->gui_recv_cancel_meeting = qtg_recv_cancel_meeting;
+  funcs->gui_prepare_clause_updt = qtg_prepare_clause_updt;
+  funcs->gui_recv_create_clause = qtg_recv_create_clause;
+  funcs->gui_recv_remove_clause = qtg_recv_remove_clause;
+  funcs->gui_recv_accept_treaty = qtg_recv_accept_treaty;
 }
diff --git a/client/gui-qt/qtg_cxxside.h b/client/gui-qt/qtg_cxxside.h
index eb3a23aaf1..c18982356e 100644
--- a/client/gui-qt/qtg_cxxside.h
+++ b/client/gui-qt/qtg_cxxside.h
@@ -141,4 +141,13 @@ void qtg_gui_clear_theme();
 char **qtg_get_gui_specific_themes_directories(int *count);
 char **qtg_get_useable_themes_in_directory(const char *directory, int *count);
 
+void qtg_init_meeting(struct Treaty *ptreaty, struct player *they,
+                      struct player *initiator);
+void qtg_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they,
+                             struct player *initiator);
+void qtg_prepare_clause_updt(struct Treaty *ptreaty, struct player *they);
+void qtg_recv_create_clause(struct Treaty *ptreaty, struct player *they);
+void qtg_recv_remove_clause(struct Treaty *ptreaty, struct player *they);
+void qtg_recv_accept_treaty(struct Treaty *ptreaty, struct player *they);
+
 #endif /* FC__QTG_CXXSIDE_H */
diff --git a/client/gui-sdl2/diplodlg.c b/client/gui-sdl2/diplodlg.c
index e40ba71f34..a6105ece98 100644
--- a/client/gui-sdl2/diplodlg.c
+++ b/client/gui-sdl2/diplodlg.c
@@ -53,7 +53,7 @@
 #define MAX_NUM_CLAUSES 64
 
 struct diplomacy_dialog {
-  struct Treaty treaty;
+  struct Treaty *treaty;
   struct advanced_dialog *pdialog;
   struct advanced_dialog *pwants;
   struct advanced_dialog *poffers;
@@ -72,9 +72,9 @@ static struct dialog_list *dialog_list;
 static void update_diplomacy_dialog(struct diplomacy_dialog *pdialog);
 static void update_acceptance_icons(struct diplomacy_dialog *pdialog);
 static void update_clauses_list(struct diplomacy_dialog *pdialog);
-static void remove_clause_widget_from_list(int counterpart, int giver,
+static void remove_clause_widget_from_list(struct player *they, struct player *giver,
                                            enum clause_type type, int value);
-static void popdown_diplomacy_dialog(int counterpart);
+static void popdown_diplomacy_dialog(struct player *they);
 static void popdown_diplomacy_dialogs(void);
 static void popdown_sdip_dialog(void);
 
@@ -97,14 +97,13 @@ void diplomacy_dialog_done(void)
 /**********************************************************************//**
   Get diplomacy dialog between client user and other player.
 **************************************************************************/
-static struct diplomacy_dialog *get_diplomacy_dialog(int other_player_id)
+static struct diplomacy_dialog *get_diplomacy_dialog(struct player *they)
 {
-  struct player *plr0 = client.conn.playing;
-  struct player *plr1 = player_by_number(other_player_id);
+  struct player *we = client_player();
 
   dialog_list_iterate(dialog_list, pdialog) {
-    if ((pdialog->treaty.plr0 == plr0 && pdialog->treaty.plr1 == plr1)
-        || (pdialog->treaty.plr0 == plr1 && pdialog->treaty.plr1 == plr0)) {
+    if ((pdialog->treaty->plr0 == we && pdialog->treaty->plr1 == they)
+        || (pdialog->treaty->plr0 == they && pdialog->treaty->plr1 == we)) {
       return pdialog;
     }
   } dialog_list_iterate_end;
@@ -116,17 +115,15 @@ static struct diplomacy_dialog *get_diplomacy_dialog(int other_player_id)
   Update a player's acceptance status of a treaty (traditionally shown
   with the thumbs-up/thumbs-down sprite).
 **************************************************************************/
-void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
-                                    bool other_accepted)
+void gui_recv_accept_treaty(struct Treaty *ptreaty, struct player *they)
 {
-  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(counterpart);
+  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  pdialog->treaty.accept0 = I_accepted;
-  pdialog->treaty.accept1 = other_accepted;
+  fc_assert(pdialog->treaty == ptreaty);
 
   update_acceptance_icons(pdialog);
 }
@@ -135,9 +132,10 @@ void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
   Update the diplomacy dialog when the meeting is canceled (the dialog
   should be closed).
 **************************************************************************/
-void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
+void gui_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they,
+                             struct player *initiator)
 {
-  popdown_diplomacy_dialog(counterpart);
+  popdown_diplomacy_dialog(they);
   flush_dirty();
 }
 
@@ -151,12 +149,12 @@ static int remove_clause_callback(struct widget *pwidget)
   if (PRESSED_EVENT(main_data.event)) {
     struct diplomacy_dialog *pdialog;
 
-    if (!(pdialog = get_diplomacy_dialog(pwidget->data.cont->id1))) {
-      pdialog = get_diplomacy_dialog(pwidget->data.cont->id0);
+    if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
+      pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
     }
 
     dsend_packet_diplomacy_remove_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              pwidget->data.cont->id0,
                                              (enum clause_type) ((pwidget->data.
                                              cont->value >> 16) & 0xFFFF),
@@ -167,25 +165,38 @@ static int remove_clause_callback(struct widget *pwidget)
 }
 
 /**********************************************************************//**
-  Update the diplomacy dialog by adding a clause.
+  Prepare to clause creation or removal.
 **************************************************************************/
-void handle_diplomacy_create_clause(int counterpart, int giver,
-                                    enum clause_type type, int value)
+void gui_prepare_clause_updt(struct Treaty *ptreaty, struct player *they)
 {
-  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(counterpart);
+  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  clause_list_iterate(pdialog->treaty.clauses, pclause) {
-    remove_clause_widget_from_list(player_number(pdialog->treaty.plr1),
-                                   player_number(pclause->from),
+  fc_assert(pdialog->treaty == ptreaty);
+
+  clause_list_iterate(pdialog->treaty->clauses, pclause) {
+    remove_clause_widget_from_list(pdialog->treaty->plr1,
+                                   pclause->from,
                                    pclause->type,
                                    pclause->value);
   } clause_list_iterate_end;
+}
 
-  add_clause(&pdialog->treaty, player_by_number(giver), type, value);
+/**********************************************************************//**
+  Update the diplomacy dialog by adding a clause.
+**************************************************************************/
+void gui_recv_create_clause(struct Treaty *ptreaty, struct player *they)
+{
+  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(they);
+
+  if (!pdialog) {
+    return;
+  }
+
+  fc_assert(pdialog->treaty == ptreaty);
 
   update_clauses_list(pdialog);
   update_acceptance_icons(pdialog);
@@ -194,24 +205,14 @@ void handle_diplomacy_create_clause(int counterpart, int giver,
 /**********************************************************************//**
   Update the diplomacy dialog by removing a clause.
 **************************************************************************/
-void handle_diplomacy_remove_clause(int counterpart, int giver,
-                                    enum clause_type type, int value)
+void gui_recv_remove_clause(struct Treaty *ptreaty, struct player *they)
 {
-  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(counterpart);
+  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(they);
 
   if (!pdialog) {
     return;
   }
 
-  clause_list_iterate(pdialog->treaty.clauses, pclause) {
-    remove_clause_widget_from_list(player_number(pdialog->treaty.plr1),
-                                   player_number(pclause->from),
-                                   pclause->type,
-                                   pclause->value);
-  } clause_list_iterate_end;
-
-  remove_clause(&pdialog->treaty, player_by_number(giver), type, value);
-
   update_clauses_list(pdialog);
   update_acceptance_icons(pdialog);
 }
@@ -255,8 +256,8 @@ static int pact_callback(struct widget *pwidget)
     int clause_type;
     struct diplomacy_dialog *pdialog;
 
-    if (!(pdialog = get_diplomacy_dialog(pwidget->data.cont->id1))) {
-      pdialog = get_diplomacy_dialog(pwidget->data.cont->id0);
+    if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
+      pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
     }
 
     switch (MAX_ID - pwidget->id) {
@@ -272,7 +273,7 @@ static int pact_callback(struct widget *pwidget)
     }
 
     dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              pwidget->data.cont->id0,
                                              clause_type, 0);
   }
@@ -288,12 +289,12 @@ static int vision_callback(struct widget *pwidget)
   if (PRESSED_EVENT(main_data.event)) {
     struct diplomacy_dialog *pdialog;
 
-    if (!(pdialog = get_diplomacy_dialog(pwidget->data.cont->id1))) {
-      pdialog = get_diplomacy_dialog(pwidget->data.cont->id0);
+    if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
+      pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
     }
   
     dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              pwidget->data.cont->id0,
                                              CLAUSE_VISION, 0);
   }
@@ -309,12 +310,12 @@ static int embassy_callback(struct widget *pwidget)
   if (PRESSED_EVENT(main_data.event)) {
     struct diplomacy_dialog *pdialog;
 
-    if (!(pdialog = get_diplomacy_dialog(pwidget->data.cont->id1))) {
-      pdialog = get_diplomacy_dialog(pwidget->data.cont->id0);
+    if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
+      pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
     }
 
     dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              pwidget->data.cont->id0,
                                              CLAUSE_EMBASSY, 0);
   }
@@ -331,8 +332,8 @@ static int maps_callback(struct widget *pwidget)
     int clause_type;
     struct diplomacy_dialog *pdialog;
 
-    if (!(pdialog = get_diplomacy_dialog(pwidget->data.cont->id1))) {
-      pdialog = get_diplomacy_dialog(pwidget->data.cont->id0);
+    if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
+      pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
     }
 
     switch (MAX_ID - pwidget->id) {
@@ -345,7 +346,7 @@ static int maps_callback(struct widget *pwidget)
     }
 
     dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              pwidget->data.cont->id0,
                                              clause_type, 0);
   }
@@ -361,12 +362,12 @@ static int techs_callback(struct widget *pwidget)
   if (PRESSED_EVENT(main_data.event)) {
     struct diplomacy_dialog *pdialog;
 
-    if (!(pdialog = get_diplomacy_dialog(pwidget->data.cont->id1))) {
-      pdialog = get_diplomacy_dialog(pwidget->data.cont->id0);
+    if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
+      pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
     }
 
     dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              pwidget->data.cont->id0,
                                              CLAUSE_ADVANCE,
                                              (MAX_ID - pwidget->id));
@@ -384,8 +385,8 @@ static int gold_callback(struct widget *pwidget)
     int amount;
     struct diplomacy_dialog *pdialog;
 
-    if (!(pdialog = get_diplomacy_dialog(pwidget->data.cont->id1))) {
-      pdialog = get_diplomacy_dialog(pwidget->data.cont->id0);
+    if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
+      pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
     }
 
     if (pwidget->string_utf8->text != NULL) {
@@ -402,7 +403,7 @@ static int gold_callback(struct widget *pwidget)
 
     if (amount > 0) {
       dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                               player_number(pdialog->treaty.plr1),
+                                               player_number(pdialog->treaty->plr1),
                                                pwidget->data.cont->id0,
                                                CLAUSE_GOLD, amount);
       
@@ -429,12 +430,12 @@ static int cities_callback(struct widget *pwidget)
   if (PRESSED_EVENT(main_data.event)) {
     struct diplomacy_dialog *pdialog;
 
-    if (!(pdialog = get_diplomacy_dialog(pwidget->data.cont->id1))) {
-      pdialog = get_diplomacy_dialog(pwidget->data.cont->id0);
+    if (!(pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id1)))) {
+      pdialog = get_diplomacy_dialog(player_by_number(pwidget->data.cont->id0));
     }
 
     dsend_packet_diplomacy_create_clause_req(&client.conn,
-                                             player_number(pdialog->treaty.plr1),
+                                             player_number(pdialog->treaty->plr1),
                                              pwidget->data.cont->id0,
                                              CLAUSE_CITY,
                                              (MAX_ID - pwidget->id));
@@ -827,12 +828,13 @@ static struct advanced_dialog *popup_diplomatic_objects(struct player *pplayer0,
 /**********************************************************************//**
   Open new diplomacy dialog between players.
 **************************************************************************/
-static struct diplomacy_dialog *create_diplomacy_dialog(struct player *plr0, 
+static struct diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty,
+                                                        struct player *plr0,
                                                         struct player *plr1)
 {
   struct diplomacy_dialog *pdialog = fc_calloc(1, sizeof(struct diplomacy_dialog));
 
-  init_treaty(&pdialog->treaty, plr0, plr1);
+  pdialog->treaty = ptreaty;
 
   pdialog->pdialog = fc_calloc(1, sizeof(struct advanced_dialog));
 
@@ -872,8 +874,8 @@ static void update_diplomacy_dialog(struct diplomacy_dialog *pdialog)
                                   pdialog->pdialog->end_widget_list);
     }
 
-    pplayer0 = pdialog->treaty.plr0;
-    pplayer1 = pdialog->treaty.plr1;
+    pplayer0 = pdialog->treaty->plr0;
+    pplayer1 = pdialog->treaty->plr1;
 
     cont->id0 = player_number(pplayer0);
     cont->id1 = player_number(pplayer1);
@@ -1029,7 +1031,7 @@ static void update_acceptance_icons(struct diplomacy_dialog *pdialog)
   /* updates your own acceptance status */
   label = pdialog->pdialog->end_widget_list->prev;
 
-  label->private_data.cbox->state = pdialog->treaty.accept0;
+  label->private_data.cbox->state = pdialog->treaty->accept0;
   if (label->private_data.cbox->state) {
     thm = label->private_data.cbox->true_theme;
   } else {
@@ -1048,7 +1050,7 @@ static void update_acceptance_icons(struct diplomacy_dialog *pdialog)
   /* updates other player's acceptance status */
   label = pdialog->pdialog->end_widget_list->prev->prev;
 
-  label->private_data.cbox->state = pdialog->treaty.accept1;
+  label->private_data.cbox->state = pdialog->treaty->accept1;
   if (label->private_data.cbox->state) {
     thm = label->private_data.cbox->true_theme;
   } else {
@@ -1075,20 +1077,20 @@ static void update_clauses_list(struct diplomacy_dialog *pdialog)
   bool redraw_all, scroll = (pdialog->pdialog->active_widget_list != NULL);
   int len = pdialog->pdialog->scroll->up_left_button->size.w;
 
-  clause_list_iterate(pdialog->treaty.clauses, pclause) {
+  clause_list_iterate(pdialog->treaty->clauses, pclause) {
     client_diplomacy_clause_string(cbuf, sizeof(cbuf), pclause);
 
     pstr = create_utf8_from_char(cbuf, adj_font(12));
     pbuf = create_iconlabel(NULL, pwindow->dst, pstr,
      (WF_FREE_DATA|WF_DRAW_TEXT_LABEL_WITH_SPACE|WF_RESTORE_BACKGROUND));
 
-    if (pclause->from != client.conn.playing) {
+    if (pclause->from != client_player()) {
        pbuf->string_utf8->style |= SF_CENTER_RIGHT;
     }
 
     pbuf->data.cont = fc_calloc(1, sizeof(struct container));
     pbuf->data.cont->id0 = player_number(pclause->from);
-    pbuf->data.cont->id1 = player_number(pdialog->treaty.plr1);
+    pbuf->data.cont->id1 = player_number(pdialog->treaty->plr1);
     pbuf->data.cont->value = ((int)pclause->type << 16) + pclause->value;
 
     pbuf->action = remove_clause_callback;
@@ -1130,25 +1132,26 @@ static void update_clauses_list(struct diplomacy_dialog *pdialog)
 /**********************************************************************//**
   Remove widget related to clause from list of widgets.
 **************************************************************************/
-static void remove_clause_widget_from_list(int counterpart, int giver,
+static void remove_clause_widget_from_list(struct player *they,
+                                           struct player *giver,
                                            enum clause_type type, int value)
 {
   struct widget *buf;
   SDL_Rect src = {0, 0, 0, 0};
   bool scroll = TRUE;
-  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(counterpart);
+  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(they);
 
   /* find widget with clause */
   buf = pdialog->pdialog->end_active_widget_list->next;
 
   do {
     buf = buf->prev;
-  } while (!((buf->data.cont->id0 == giver)
+  } while (!((buf->data.cont->id0 == player_number(giver))
              && (((buf->data.cont->value >> 16) & 0xFFFF) == (int)type)
              && ((buf->data.cont->value & 0xFFFF) == value))
            && (buf != pdialog->pdialog->begin_active_widget_list));
 
-  if (!(buf->data.cont->id0 == giver
+  if (!(buf->data.cont->id0 == player_number(giver)
         && ((buf->data.cont->value >> 16) & 0xFFFF) == (int)type
         && (buf->data.cont->value & 0xFFFF) == value)) {
      return;
@@ -1189,7 +1192,8 @@ static void remove_clause_widget_from_list(int counterpart, int giver,
   Handle the start of a diplomacy meeting - usually by poping up a
   diplomacy dialog.
 **************************************************************************/
-void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
+void gui_init_meeting(struct Treaty *ptreaty, struct player *they,
+                      struct player *initiator)
 {
   struct diplomacy_dialog *pdialog;
 
@@ -1197,13 +1201,12 @@ void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
     return;
   }
 
-  if (!is_human(client.conn.playing)) {
+  if (!is_human(client_player())) {
     return; /* Don't show if we are not under human control. */
   }
 
-  if (!(pdialog = get_diplomacy_dialog(counterpart))) {
-    pdialog = create_diplomacy_dialog(client.conn.playing,
-                                      player_by_number(counterpart));
+  if (!(pdialog = get_diplomacy_dialog(they))) {
+    pdialog = create_diplomacy_dialog(ptreaty, client_player(), they);
   } else {
     /* bring existing dialog to front */
     select_window_group_dialog(pdialog->pdialog->begin_widget_list,
@@ -1216,9 +1219,9 @@ void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
 /**********************************************************************//**
   Close diplomacy dialog between client user and given counterpart.
 **************************************************************************/
-static void popdown_diplomacy_dialog(int counterpart)
+static void popdown_diplomacy_dialog(struct player *they)
 {
-  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(counterpart);
+  struct diplomacy_dialog *pdialog = get_diplomacy_dialog(they);
 
   if (pdialog) {
     popdown_window_group_dialog(pdialog->poffers->begin_widget_list,
@@ -1248,7 +1251,7 @@ static void popdown_diplomacy_dialog(int counterpart)
 static void popdown_diplomacy_dialogs(void)
 {
   dialog_list_iterate(dialog_list, pdialog) {
-    popdown_diplomacy_dialog(player_number(pdialog->treaty.plr1));
+    popdown_diplomacy_dialog(pdialog->treaty->plr1);
   } dialog_list_iterate_end;
 }
 
diff --git a/client/gui-stub/diplodlg.c b/client/gui-stub/diplodlg.c
index 93384a99a4..f63167ecb9 100644
--- a/client/gui-stub/diplodlg.c
+++ b/client/gui-stub/diplodlg.c
@@ -24,8 +24,7 @@
   Update a player's acceptance status of a treaty (traditionally shown
   with the thumbs-up/thumbs-down sprite).
 **************************************************************************/
-void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
-				    bool other_accepted)
+void gui_gui_recv_accept_treaty(struct Treaty *ptreaty, struct player *they)
 {
   /* PORTME */
 }
@@ -34,7 +33,8 @@ void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
   Handle the start of a diplomacy meeting - usually by poping up a
   diplomacy dialog.
 **************************************************************************/
-void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
+void gui_gui_init_meeting(struct Treaty *ptreaty, struct player *they,
+                          struct player *initiator)
 {
   /* PORTME */
 }
@@ -42,8 +42,7 @@ void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
 /**********************************************************************//**
   Update the diplomacy dialog by adding a clause.
 **************************************************************************/
-void handle_diplomacy_create_clause(int counterpart, int giver,
-				    enum clause_type type, int value)
+void gui_gui_recv_create_clause(struct Treaty *ptreaty, struct player *they)
 {
   /* PORTME */
 }
@@ -52,7 +51,8 @@ void handle_diplomacy_create_clause(int counterpart, int giver,
   Update the diplomacy dialog when the meeting is canceled (the dialog
   should be closed).
 **************************************************************************/
-void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
+void gui_gui_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they,
+                                 struct player *initiator)
 {
   /* PORTME */
 }
@@ -60,8 +60,15 @@ void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
 /**********************************************************************//**
   Update the diplomacy dialog by removing a clause.
 **************************************************************************/
-void handle_diplomacy_remove_clause(int counterpart, int giver,
-				    enum clause_type type, int value)
+void gui_gui_recv_remove_clause(struct Treaty *ptreaty, struct player *they)
+{
+  /* PORTME */
+}
+
+/**********************************************************************//**
+  Prepare to clause creation or removal.
+**************************************************************************/
+void gui_gui_prepare_clause_updt(struct Treaty *ptreaty, struct player *they)
 {
   /* PORTME */
 }
diff --git a/client/gui_interface.c b/client/gui_interface.c
index 8ab124abfb..d6b1bc08df 100644
--- a/client/gui_interface.c
+++ b/client/gui_interface.c
@@ -24,6 +24,7 @@
 #include "citydlg_g.h"
 #include "connectdlg_g.h"
 #include "dialogs_g.h"
+#include "diplodlg_g.h"
 #include "editgui_g.h"
 #include "graphics_g.h"
 #include "gui_main_g.h"
@@ -629,3 +630,53 @@ char **get_useable_themes_in_directory(const char *directory, int *count)
 {
   return funcs.get_useable_themes_in_directory(directory, count);
 }
+
+/**********************************************************************//**
+  Call gui_init_meeting callback
+**************************************************************************/
+void gui_init_meeting(struct Treaty *ptreaty, struct player *they,
+                      struct player *initiator)
+{
+  funcs.gui_init_meeting(ptreaty, they, initiator);
+}
+
+/**********************************************************************//**
+  Call gui_recv_cancel_meeting callback
+**************************************************************************/
+void gui_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they,
+                             struct player *initiator)
+{
+  funcs.gui_recv_cancel_meeting(ptreaty, they, initiator);
+}
+
+/**********************************************************************//**
+  Call gui_prepare_clause_updt callback
+**************************************************************************/
+void gui_prepare_clause_updt(struct Treaty *ptreaty, struct player *they)
+{
+  funcs.gui_prepare_clause_updt(ptreaty, they);
+}
+
+/**********************************************************************//**
+  Call gui_recv_create_clause callback
+**************************************************************************/
+void gui_recv_create_clause(struct Treaty *ptreaty, struct player *they)
+{
+  funcs.gui_recv_create_clause(ptreaty, they);
+}
+
+/**********************************************************************//**
+  Call gui_recv_remove_clause callback
+**************************************************************************/
+void gui_recv_remove_clause(struct Treaty *ptreaty, struct player *they)
+{
+  funcs.gui_recv_remove_clause(ptreaty, they);
+}
+
+/**********************************************************************//**
+  Call gui_recv_accept_treaty callback
+**************************************************************************/
+void gui_recv_accept_treaty(struct Treaty *ptreaty, struct player *they)
+{
+  funcs.gui_recv_accept_treaty(ptreaty, they);
+}
diff --git a/client/gui_interface.h b/client/gui_interface.h
index 314006e03b..aad1a477e7 100644
--- a/client/gui_interface.h
+++ b/client/gui_interface.h
@@ -19,6 +19,7 @@ extern "C" {
 #endif /* __cplusplus */
 
 /* common */
+#include "diptreaty.h"
 #include "fc_types.h"
 #include "featured_text.h"
 #include "tile.h"
@@ -143,6 +144,15 @@ struct gui_funcs {
   void (*gui_clear_theme)(void);
   char **(*get_gui_specific_themes_directories)(int *count);
   char **(*get_useable_themes_in_directory)(const char *directory, int *count);
+
+  void (*gui_init_meeting)(struct Treaty *ptreaty, struct player *they,
+                           struct player *initiator);
+  void (*gui_recv_cancel_meeting)(struct Treaty *ptreaty, struct player *they,
+                                  struct player *initiator);
+  void (*gui_prepare_clause_updt)(struct Treaty *ptreaty, struct player *they);
+  void (*gui_recv_create_clause)(struct Treaty *ptreaty, struct player *they);
+  void (*gui_recv_remove_clause)(struct Treaty *ptreaty, struct player *they);
+  void (*gui_recv_accept_treaty)(struct Treaty *ptreaty, struct player *they);
 };
 
 struct gui_funcs *get_gui_funcs(void);
diff --git a/client/include/diplodlg_g.h b/client/include/diplodlg_g.h
index 552f6d6ae1..7f3d18af21 100644
--- a/client/include/diplodlg_g.h
+++ b/client/include/diplodlg_g.h
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -13,23 +13,28 @@
 #ifndef FC__DIPLODLG_G_H
 #define FC__DIPLODLG_G_H
 
+/* utility */
 #include "shared.h"
 
+/* common */
 #include "diptreaty.h"
 
 #include "gui_proto_constructor.h"
 
-GUI_FUNC_PROTO(void, handle_diplomacy_init_meeting,
-               int counterpart, int initiated_from)
-GUI_FUNC_PROTO(void, handle_diplomacy_cancel_meeting,
-               int counterpart, int initiated_from)
-GUI_FUNC_PROTO(void, handle_diplomacy_create_clause, int counterpart, int giver,
-               enum clause_type type, int value)
-GUI_FUNC_PROTO(void, handle_diplomacy_remove_clause, int counterpart, int giver,
-               enum clause_type type, int value)
-GUI_FUNC_PROTO(void, handle_diplomacy_accept_treaty,
-               int counterpart, bool I_accepted,
-               bool other_accepted)
+GUI_FUNC_PROTO(void, gui_init_meeting,
+               struct Treaty *ptreaty, struct player *they,
+               struct player *initiator)
+GUI_FUNC_PROTO(void, gui_recv_cancel_meeting,
+               struct Treaty *ptreaty, struct player *they,
+               struct player *initiator)
+GUI_FUNC_PROTO(void, gui_prepare_clause_updt,
+               struct Treaty *ptreaty, struct player *they)
+GUI_FUNC_PROTO(void, gui_recv_create_clause,
+               struct Treaty *ptreaty, struct player *they)
+GUI_FUNC_PROTO(void, gui_recv_remove_clause,
+               struct Treaty *ptreaty, struct player *they)
+GUI_FUNC_PROTO(void, gui_recv_accept_treaty, struct Treaty *ptreaty,
+               struct player *they)
 
 GUI_FUNC_PROTO(void, close_all_diplomacy_dialogs, void)
 
diff --git a/client/packhand.c b/client/packhand.c
index 65fd41c78e..f8f5cc273a 100644
--- a/client/packhand.c
+++ b/client/packhand.c
@@ -83,6 +83,7 @@
 #include "client_main.h"
 #include "climap.h"
 #include "climisc.h"
+#include "clitreaty.h"
 #include "connectdlg_common.h"
 #include "control.h"
 #include "editor.h"
@@ -5406,3 +5407,46 @@ void handle_play_music(const char *tag)
 {
   play_single_track(tag);
 }
+
+/************************************************************************//**
+  Open meeting
+****************************************************************************/
+void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
+{
+  client_init_meeting(counterpart, initiated_from);
+}
+
+/************************************************************************//**
+  Server tells us that either party has accepted treaty
+****************************************************************************/
+void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted,
+                                    bool other_accepted)
+{
+  client_recv_accept_treaty(counterpart, I_accepted, other_accepted);
+}
+
+/************************************************************************//**
+  Meeting has been cancelled.
+****************************************************************************/
+void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
+{
+  client_recv_cancel_meeting(counterpart, initiated_from);
+}
+
+/************************************************************************//**
+  Add clause to the meeting
+****************************************************************************/
+void handle_diplomacy_create_clause(int counterpart, int giver,
+                                    enum clause_type type, int value)
+{
+  client_recv_create_clause(counterpart, giver, type, value);
+}
+
+/************************************************************************//**
+  Remove clause from meeting.
+****************************************************************************/
+void handle_diplomacy_remove_clause(int counterpart, int giver,
+                                    enum clause_type type, int value)
+{
+  client_recv_remove_clause(counterpart, giver, type, value);
+}
diff --git a/meson.build b/meson.build
index b8aa82217b..06ad423591 100644
--- a/meson.build
+++ b/meson.build
@@ -1455,6 +1455,7 @@ client_common = static_library('fc_client_common',
   'client/climap.c',
   'client/climisc.c',
   'client/clinet.c',
+  'client/clitreaty.c',
   'client/colors_common.c',
   'client/connectdlg_common.c',
   'client/control.c',
-- 
2.35.1