Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4730) new client function city_rename
Home

[Freeciv-Dev] (PR#4730) new client function city_rename

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4730) new client function city_rename
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 31 Jul 2003 14:57:08 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch adds a function city_rename that is a wrapper for 
send_packet_city_request(..., PACKET_CITY_RENAME).  It cuts out lots of 
GUI code and avoids sending unintialized data over the network.

jason

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.20
diff -u -r1.20 citydlg_common.c
--- client/citydlg_common.c     2003/07/31 21:05:36     1.20
+++ client/citydlg_common.c     2003/07/31 21:54:37
@@ -467,3 +467,22 @@
 
   return send_packet_city_request(&aconnection, &packet, ptype);
 }
+
+/**************************************************************************
+  Tell the server to rename the city.  Return the request ID.
+**************************************************************************/
+int city_rename(struct city *pcity, const char *name)
+{
+  struct packet_city_request packet;
+
+  packet.city_id = pcity->id;
+  sz_strlcpy(packet.name, name);
+
+  /* Fill out unused fields. */
+  packet.build_id = -1;
+  packet.is_build_id_unit_id = FALSE;
+  packet.worker_x = packet.worker_y = -1;
+  packet.specialist_from = packet.specialist_to = -1;
+
+  return send_packet_city_request(&aconnection, &packet, PACKET_CITY_RENAME);
+}
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.13
diff -u -r1.13 citydlg_common.h
--- client/citydlg_common.h     2003/07/31 21:05:36     1.13
+++ client/citydlg_common.h     2003/07/31 21:54:37
@@ -58,5 +58,6 @@
 int city_change_specialist(struct city *pcity, enum specialist_type from,
                           enum specialist_type to);
 int city_toggle_worker(struct city *pcity, int city_x, int city_y);
+int city_rename(struct city *pcity, const char *name);
 
 #endif /* FC__CITYDLG_COMMON_H */
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.167
diff -u -r1.167 citydlg.c
--- client/gui-gtk/citydlg.c    2003/07/31 21:05:37     1.167
+++ client/gui-gtk/citydlg.c    2003/07/31 21:54:37
@@ -3303,12 +3303,10 @@
 *****************************************************************/
 static void rename_callback_yes(const char *input, gpointer data)
 {
-  struct city_dialog *pdialog = (struct city_dialog *) data;
-  struct packet_city_request packet;
+  struct city_dialog *pdialog = data;
 
-  packet.city_id = pdialog->pcity->id;
-  sz_strlcpy(packet.name, input);
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_RENAME);
+  city_rename(pdialog->pcity, input);
+
   pdialog->rename_shell = NULL;
 }
 
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.60
diff -u -r1.60 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        2003/07/31 21:05:37     1.60
+++ client/gui-gtk-2.0/citydlg.c        2003/07/31 21:54:37
@@ -2539,13 +2539,10 @@
 *****************************************************************/
 static void rename_callback_yes(GtkWidget * w, gpointer data)
 {
-  struct city_dialog *pdialog = (struct city_dialog *) data;
-  struct packet_city_request packet;
+  struct city_dialog *pdialog = data;
 
   if (pdialog) {
-    packet.city_id = pdialog->pcity->id;
-    sz_strlcpy(packet.name, input_dialog_get_input(w));
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_RENAME);
+    city_rename(pdialog->pcity, input_dialog_get_input(w));
 
     pdialog->rename_shell = NULL;
   }
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.70
diff -u -r1.70 citydlg.c
--- client/gui-mui/citydlg.c    2003/07/31 21:05:37     1.70
+++ client/gui-mui/citydlg.c    2003/07/31 21:54:37
@@ -776,14 +776,13 @@
 /****************************************************************
  Callback for the City Name String
 *****************************************************************/
-static void city_rename(struct city_dialog **ppdialog)
+static void city_rename_callback(struct city_dialog **ppdialog)
 {
   struct city_dialog *pdialog = *ppdialog;
-  struct packet_city_request packet;
+  char *name = (char*)xget(pdialog->name_transparentstring,
+                          MUIA_TransparentString_Contents);
 
-  packet.city_id=pdialog->pcity->id;
-  sz_strlcpy(packet.name, (char*)xget(pdialog->name_transparentstring, 
MUIA_TransparentString_Contents));
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_RENAME);
+  city_rename(pdialog->pcity, name);
 }
 
 /**************************************************************************
@@ -1715,7 +1714,10 @@
 
     if (pdialog->name_transparentstring)
     {
-      DoMethod(pdialog->name_transparentstring, MUIM_Notify, 
MUIA_TransparentString_Acknowledge, MUIV_EveryTime, app, 4, MUIM_CallHook, 
&civstandard_hook, city_rename, pdialog);
+      DoMethod(pdialog->name_transparentstring, MUIM_Notify,
+              MUIA_TransparentString_Acknowledge, MUIV_EveryTime, app, 4,
+              MUIM_CallHook, &civstandard_hook, city_rename_callback,
+              pdialog);
     }
 
     for (i=0;i<6;i++)
Index: client/gui-sdl/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/citydlg.c,v
retrieving revision 1.27
diff -u -r1.27 citydlg.c
--- client/gui-sdl/citydlg.c    2003/07/31 21:05:37     1.27
+++ client/gui-sdl/citydlg.c    2003/07/31 21:54:37
@@ -2115,11 +2115,8 @@
   }
   
   if(strcmp(tmp, pCityDlg->pCity->name)) {
-    struct packet_city_request packet;
-    packet.city_id = pCityDlg->pCity->id;
-    sz_strlcpy(packet.name, tmp);
     SDL_Client_Flags |= CF_CHANGED_CITY_NAME;
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_RENAME);
+    city_rename(pCityDlg->pCity, tmp);
   }
   
   FREE(tmp);
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.56
diff -u -r1.56 citydlg.c
--- client/gui-win32/citydlg.c  2003/07/31 21:05:37     1.56
+++ client/gui-win32/citydlg.c  2003/07/31 21:54:37
@@ -1279,13 +1279,10 @@
 
 static void rename_city_callback(HWND w, void * data)
 {
-  struct city_dialog *pdialog;
-  struct packet_city_request packet;
+  struct city_dialog *pdialog = data;
  
-  if((pdialog=(struct city_dialog *)data)) {
-    packet.city_id=pdialog->pcity->id;
-    sz_strlcpy(packet.name, input_dialog_get_input(w));
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_RENAME);
+  if (pdialog) {
+    city_rename(pdialog->pcity, input_dialog_get_input(w));
   }
  
   input_dialog_destroy(w);
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.99
diff -u -r1.99 citydlg.c
--- client/gui-xaw/citydlg.c    2003/07/31 21:05:37     1.99
+++ client/gui-xaw/citydlg.c    2003/07/31 21:54:37
@@ -1365,13 +1365,10 @@
 static void rename_city_callback(Widget w, XtPointer client_data, 
                                 XtPointer call_data)
 {
-  struct city_dialog *pdialog;
-  struct packet_city_request packet;
+  struct city_dialog *pdialog = client_data;
 
-  if((pdialog=(struct city_dialog *)client_data)) {
-    packet.city_id=pdialog->pcity->id;
-     sz_strlcpy(packet.name, input_dialog_get_input(w));
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_RENAME);
+  if (pdialog) {
+    city_rename(pdialog->pcity, input_dialog_get_input(w));
   }
   input_dialog_destroy(w);
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4730) new client function city_rename, Jason Short <=