Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] Re: (PR#8745) Bug: conndlg and scenarios
Home

[Freeciv-Dev] Re: (PR#8745) Bug: conndlg and scenarios

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#8745) Bug: conndlg and scenarios
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 5 Sep 2004 08:20:38 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8745 >

here's a second version of the patch. single_playerlist_reply is replaced
with packet_game_load.

-mike

diff -Nur -Xcvs/diff_ignore snap/client/gui-gtk/connectdlg.c 
snap-scen/client/gui-gtk/connectdlg.c
--- snap/client/gui-gtk/connectdlg.c    2004-04-09 22:43:58.000000000 -0500
+++ snap-scen/client/gui-gtk/connectdlg.c       2004-09-05 09:42:42.304646184 
-0500
@@ -350,11 +350,10 @@
 }
 
 /**************************************************************************
-  this regenerates the player information from a game on the server.
+  this regenerates the player information from a loaded game on the server.
   currently a stub. TODO
 **************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
-                                    *packet)
+void handle_game_load(struct packet_game_load *packet)
 { 
   /* PORTME */
 }
diff -Nur -Xcvs/diff_ignore snap/client/gui-gtk-2.0/connectdlg.c 
snap-scen/client/gui-gtk-2.0/connectdlg.c
--- snap/client/gui-gtk-2.0/connectdlg.c        2004-08-28 10:38:51.000000000 
-0500
+++ snap-scen/client/gui-gtk-2.0/connectdlg.c   2004-09-05 10:17:43.337501280 
-0500
@@ -445,10 +445,9 @@
 }
 
 /**************************************************************************
-  this regenerates the player information from a game on the server.
+  this regenerates the player information from a loaded game on the server.
 **************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply 
-                                    *packet)
+void handle_game_load(struct packet_game_load *packet)
 {
   int i;
 
@@ -458,12 +457,8 @@
 
   gtk_list_store_clear(storesaved);
 
-  if (packet->nplayers != 0) {
-    game.nplayers = packet->nplayers;
-  }
-
   /* we couldn't load the savegame, we could have gotten the name wrong, etc */
-  if (packet->nplayers == 0
+  if (!packet->load_successful
       || strcmp(current_filename, packet->load_filename) != 0) {
     gtk_window_set_title(GTK_WINDOW(dialog), _("Couldn't load the savegame"));
     return;
@@ -474,6 +469,7 @@
     gtk_window_set_title(GTK_WINDOW(dialog), ++buf);
   }
 
+  game.nplayers = packet->nplayers;
 
   for (i = 0; i < packet->nplayers; i++) {
     GtkTreeIter iter;
@@ -486,10 +482,30 @@
                        3, packet->is_alive[i] ? _("Alive") : _("Dead"),
                        4, packet->is_ai[i] ? _("AI") : _("Human"), -1);
 
-    /* set flag. */
-    flag = get_flag(packet->nation_flag[i]);
-    gtk_list_store_set(storesaved, &iter, 1, flag, -1);
-    g_object_unref(flag);
+    /* set flag if we've got one to set. */
+    if (strcmp(packet->nation_flag[i], "") != 0) {
+      flag = get_flag(packet->nation_flag[i]);
+      gtk_list_store_set(storesaved, &iter, 1, flag, -1);
+      g_object_unref(flag);
+    }
+  }
+
+  /* if nplayers is zero, we suppose it's a scenario */
+  if (packet->load_successful && packet->nplayers == 0) {
+    GtkTreeIter iter;
+    char message[MAX_LEN_MSG];
+
+    my_snprintf(message, sizeof(message), "/create %s", user_name);
+    send_chat(message);
+    my_snprintf(message, sizeof(message), "/ai %s", user_name);
+    send_chat(message);
+
+    /* create a false entry */
+    gtk_list_store_append(storesaved, &iter);
+    gtk_list_store_set(storesaved, &iter,
+                       0, user_name,
+                       3, _("Alive"),
+                       4, _("Human"), -1);
   }
 }
 
@@ -520,7 +536,6 @@
 
       my_snprintf(message, sizeof(message), "/load %s", current_filename);
       send_chat(message);
-      send_packet_single_playerlist_req(&aconnection);
     }
   }
 
diff -Nur -Xcvs/diff_ignore snap/client/gui-sdl/connectdlg.c 
snap-scen/client/gui-sdl/connectdlg.c
--- snap/client/gui-sdl/connectdlg.c    2004-04-09 22:43:58.000000000 -0500
+++ snap-scen/client/gui-sdl/connectdlg.c       2004-09-05 09:43:51.812045956 
-0500
@@ -81,10 +81,9 @@
 }
 
 /**************************************************************************
- provide a packet handler for packet_single_playerlist_reply 
+ provide a packet handler for packet_game_load
 **************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
-                                    *packet)
+void handle_game_load(struct packet_game_load *packet)
 { 
   /* PORTME */
 }
diff -Nur -Xcvs/diff_ignore snap/client/gui-stub/connectdlg.c 
snap-scen/client/gui-stub/connectdlg.c
--- snap/client/gui-stub/connectdlg.c   2004-04-09 22:43:58.000000000 -0500
+++ snap-scen/client/gui-stub/connectdlg.c      2004-09-05 09:42:03.851829980 
-0500
@@ -85,10 +85,9 @@
 }
 
 /**************************************************************************
- provide a packet handler for packet_single_playerlist_reply 
+ provide a packet handler for packet_game_load
 **************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
-                                    *packet)
+void handle_game_load(struct packet_game_load *packet)
 { 
   /* PORTME */
 }
diff -Nur -Xcvs/diff_ignore snap/client/gui-win32/connectdlg.c 
snap-scen/client/gui-win32/connectdlg.c
--- snap/client/gui-win32/connectdlg.c  2004-08-21 13:07:46.000000000 -0500
+++ snap-scen/client/gui-win32/connectdlg.c     2004-09-05 09:43:10.046020733 
-0500
@@ -105,8 +105,7 @@
 /**************************************************************************
  PORTME 
 **************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
-                                    *packet)
+void handle_game_load(struct packet_game_load *packet)
 { 
 }
 
diff -Nur -Xcvs/diff_ignore snap/client/gui-xaw/connectdlg.c 
snap-scen/client/gui-xaw/connectdlg.c
--- snap/client/gui-xaw/connectdlg.c    2004-04-09 22:43:58.000000000 -0500
+++ snap-scen/client/gui-xaw/connectdlg.c       2004-09-05 09:44:29.100140791 
-0500
@@ -235,11 +235,10 @@
 }
 
 /**************************************************************************
-  this regenerates the player information from a game on the server.
+  this regenerates the player information from a loaded game on the server.
   currently a stub. TODO
 **************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
-                                    *packet)
+void handle_game_load(struct packet_game_load *packet)
 { 
   /* PORTME */
 }
diff -Nur -Xcvs/diff_ignore snap/common/capstr.c snap-scen/common/capstr.c
--- snap/common/capstr.c        2004-09-05 09:17:04.000000000 -0500
+++ snap-scen/common/capstr.c   2004-09-05 09:33:28.901816452 -0500
@@ -73,7 +73,7 @@
  * are not directly related to the capability strings discussed here.)
  */
 
-#define CAPABILITY "+Freeciv.Devel.2004.Sep.2"
+#define CAPABILITY "+Freeciv.Devel.2004.Sep.2 +load_packet"
 
 void init_our_capability(void)
 {
diff -Nur -Xcvs/diff_ignore snap/common/packets.def snap-scen/common/packets.def
--- snap/common/packets.def     2004-09-05 09:17:04.000000000 -0500
+++ snap-scen/common/packets.def        2004-09-05 09:36:07.863859843 -0500
@@ -1259,10 +1259,8 @@
  BOOL you_have_hack;
 end
 
-PACKET_SINGLE_PLAYERLIST_REQ=110;cs,handle-per-conn,no-handle
-end
-
-PACKET_SINGLE_PLAYERLIST_REPLY=111;sc
+PACKET_GAME_LOAD=111;sc,handle-via-packet,lsend
+  BOOL load_successful;
   UINT8 nplayers;
   STRING load_filename[MAX_LEN_PACKET];
   STRING name[MAX_NUM_PLAYERS:nplayers][MAX_LEN_NAME]; 
diff -Nur -Xcvs/diff_ignore snap/server/plrhand.c snap-scen/server/plrhand.c
--- snap/server/plrhand.c       2004-08-28 10:38:55.000000000 -0500
+++ snap-scen/server/plrhand.c  2004-09-05 09:52:25.444399452 -0500
@@ -2095,41 +2095,3 @@
 
   send_player_info(pplayer, NULL);
 }
-
-/************************************************************************** 
- we should only send this packet to a client starting up in cmdlevel hack.
- for now, there's no better place for this to go.
-**************************************************************************/
-void handle_single_playerlist_req(struct connection *pconn)
-{
-  int i;
-  struct packet_single_playerlist_reply packet;
-
-  packet.nplayers = game.nplayers;
-
-  sz_strlcpy(packet.load_filename, srvarg.load_filename);
-
-  for (i = 0; i < game.nplayers; i++) {
-    struct player *pplayer = &game.players[i];
-
-    if (game.nation_count && is_barbarian(pplayer)){
-      packet.nplayers--;
-      continue;
-    }
-
-    sz_strlcpy(packet.name[i], pplayer->name);
-    sz_strlcpy(packet.username[i], pplayer->username);
-    if (game.nation_count) {
-      sz_strlcpy(packet.nation_name[i], get_nation_name(pplayer->nation));
-      sz_strlcpy(packet.nation_flag[i],
-                 get_nation_by_plr(pplayer)->flag_graphic_str);
-    } else { /* No nations picked */
-      sz_strlcpy(packet.nation_name[i], "");
-      sz_strlcpy(packet.nation_flag[i], "");
-    }
-    packet.is_alive[i] = pplayer->is_alive;
-    packet.is_ai[i] = pplayer->ai.control;
-  }
-
-  send_packet_single_playerlist_reply(pconn, &packet);
-}
diff -Nur -Xcvs/diff_ignore snap/server/plrhand.h snap-scen/server/plrhand.h
--- snap/server/plrhand.h       2004-09-05 09:17:10.000000000 -0500
+++ snap-scen/server/plrhand.h  2004-09-05 09:52:33.835399705 -0500
@@ -98,6 +98,4 @@
 bool civil_war_triggered(struct player *pplayer);
 void civil_war(struct player *pplayer);
 
-void handle_single_playerlist_req(struct connection *pconn);
-
 #endif  /* FC__PLRHAND_H */
diff -Nur -Xcvs/diff_ignore snap/server/srv_main.c snap-scen/server/srv_main.c
--- snap/server/srv_main.c      2004-09-05 09:17:10.000000000 -0500
+++ snap-scen/server/srv_main.c 2004-09-05 09:58:23.372097287 -0500
@@ -924,11 +924,6 @@
     return TRUE;
   }
 
-  if (type == PACKET_SINGLE_PLAYERLIST_REQ) {
-    handle_single_playerlist_req(pconn);
-    return TRUE;
-  }
-
   pplayer = pconn->player;
 
   if(!pplayer) {
diff -Nur -Xcvs/diff_ignore snap/server/stdinhand.c snap-scen/server/stdinhand.c
--- snap/server/stdinhand.c     2004-09-05 09:17:10.000000000 -0500
+++ snap-scen/server/stdinhand.c        2004-09-05 10:05:09.195379024 -0500
@@ -37,6 +37,7 @@
 #include "log.h"
 #include "map.h"
 #include "mem.h"
+#include "packets.h"
 #include "player.h"
 #include "registry.h"
 #include "shared.h"            /* fc__attribute, bool type, etc. */
@@ -797,7 +798,6 @@
     return FALSE;
   }       
 
-
   if ((pplayer=find_player_by_name(arg))) {
     cmd_reply(CMD_CREATE, caller, C_BOUNCE,
              _("A player already exists by that name."));
@@ -2929,6 +2929,49 @@
 }
 
 /**************************************************************************
+  helper function for load_command(). Sends a load_game packet to all
+  connections.
+**************************************************************************/
+static void send_packet_load_game(bool load_successful)
+{
+  int i;
+  struct packet_game_load packet;
+
+  sz_strlcpy(packet.load_filename, srvarg.load_filename);
+  packet.load_successful = load_successful;
+
+  if (load_successful) {
+    packet.nplayers = game.nplayers;
+
+    for (i = 0; i < game.nplayers; i++) {
+      struct player *pplayer = &game.players[i];
+
+      if (game.nation_count && is_barbarian(pplayer)){
+        packet.nplayers--;
+        continue;
+      }
+
+      sz_strlcpy(packet.name[i], pplayer->name);
+      sz_strlcpy(packet.username[i], pplayer->username);
+      if (game.nation_count) {
+        sz_strlcpy(packet.nation_name[i], get_nation_name(pplayer->nation));
+        sz_strlcpy(packet.nation_flag[i],
+                 get_nation_by_plr(pplayer)->flag_graphic_str);
+      } else { /* No nations picked */
+        sz_strlcpy(packet.nation_name[i], "");
+        sz_strlcpy(packet.nation_flag[i], "");
+      }
+      packet.is_alive[i] = pplayer->is_alive;
+      packet.is_ai[i] = pplayer->ai.control;
+    }
+  } else {
+    packet.nplayers = 0;
+  }
+
+  lsend_packet_game_load(&game.est_connections, &packet);
+}
+
+/**************************************************************************
   ...
 **************************************************************************/
 bool load_command(struct connection *caller, char *arg, bool check)
@@ -2938,12 +2981,14 @@
 
   if (!arg || arg[0] == '\0') {
     cmd_reply(CMD_LOAD, caller, C_FAIL, _("Usage: load <filename>"));
+    send_packet_load_game(FALSE);
     return FALSE;
   }
 
   if (server_state != PRE_GAME_STATE) {
     cmd_reply(CMD_LOAD, caller, C_FAIL, _("Can't load a game while another "
                                           "is running."));
+    send_packet_load_game(FALSE);
     return FALSE;
   }
 
@@ -2951,6 +2996,7 @@
 
   if (!section_file_load_nodup(&file, arg)) {
     cmd_reply(CMD_LOAD, caller, C_FAIL, _("Couldn't load savefile: %s"), arg);
+    send_packet_load_game(FALSE);
     return FALSE;
   }
 
@@ -2978,6 +3024,9 @@
 
   sanity_check();
 
+  /* everything seemed to load ok, spread the good news. */
+  send_packet_load_game(TRUE);
+
   /* attach connections to players. currently, this applies only 
    * to connections that have the correct username. Any attachments
    * made before the game load are unattached. */

[Prev in Thread] Current Thread [Next in Thread]