<URL: http://bugs.freeciv.org/Ticket/Display.html?id=37433 >

 I don't like how libcivcommon access is_server from libcivserver and
libcivclient. This patch moves actual variable to common and
introduces functions to set and get it.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/civclient.c freeciv/client/civclient.c
--- freeciv/client/civclient.c	2007-01-27 20:10:48.000000000 +0200
+++ freeciv/client/civclient.c	2007-03-03 19:42:18.000000000 +0200
@@ -73,10 +73,6 @@
 
 #include "civclient.h"
 
-/* this is used in strange places, and is 'extern'd where
-   needed (hence, it is not 'extern'd in civclient.h) */
-bool is_server = FALSE;
-
 char *logfile = NULL;
 char *scriptfile = NULL;
 static char tileset_name[512] = "\0";
@@ -181,6 +177,8 @@
 # endif
 #endif
 
+  i_am_client(); /* Tell to libcivcommon that we are client */
+
   init_nls();
   audio_init();
   init_character_encodings(gui_character_encoding, gui_use_transliteration);
diff -Nurd -X.diff_ignore freeciv/common/game.c freeciv/common/game.c
--- freeciv/common/game.c	2007-02-11 15:41:19.000000000 +0200
+++ freeciv/common/game.c	2007-03-03 19:45:07.000000000 +0200
@@ -67,6 +67,33 @@
 };
 */
 
+bool am_i_server = FALSE;
+
+
+/**************************************************************************
+  Is program type server?
+**************************************************************************/
+bool is_server(void)
+{
+  return am_i_server;
+}
+
+/**************************************************************************
+  Set program type to server.
+**************************************************************************/
+void i_am_server(void)
+{
+  am_i_server = TRUE;
+}
+
+/**************************************************************************
+  Set program type to client.
+**************************************************************************/
+void i_am_client(void)
+{
+  am_i_server = FALSE;
+}
+
 /**************************************************************************
 Count the # of thousand citizen in a civilisation.
 **************************************************************************/
diff -Nurd -X.diff_ignore freeciv/common/game.h freeciv/common/game.h
--- freeciv/common/game.h	2007-02-26 14:16:16.000000000 +0200
+++ freeciv/common/game.h	2007-03-03 19:45:08.000000000 +0200
@@ -121,6 +121,10 @@
   } callbacks;
 };
 
+bool is_server(void);
+void i_am_server(void);
+void i_am_client(void);
+
 void game_init(void);
 void game_map_init(void);
 void game_free(void);
@@ -152,7 +156,6 @@
 const char *population_to_text(int thousand_citizen);
 
 extern struct civ_game game;
-extern bool is_server;
 
 bool setting_class_is_changeable(enum sset_class class);
 
diff -Nurd -X.diff_ignore freeciv/common/map.c freeciv/common/map.c
--- freeciv/common/map.c	2007-02-12 15:27:43.000000000 +0200
+++ freeciv/common/map.c	2007-03-03 19:45:37.000000000 +0200
@@ -705,7 +705,7 @@
 {
   const int maxcost = 72; /* Arbitrary. */
 
-  assert(!is_server
+  assert(!is_server()
 	 || (tile0->terrain != T_UNKNOWN && tile1->terrain != T_UNKNOWN));
 
   /* A ship can take the step if:
diff -Nurd -X.diff_ignore freeciv/common/unit.c freeciv/common/unit.c
--- freeciv/common/unit.c	2007-03-02 18:29:07.000000000 +0200
+++ freeciv/common/unit.c	2007-03-03 19:43:27.000000000 +0200
@@ -1163,7 +1163,7 @@
       return FALSE;
     }
     
-    if (!is_server) {
+    if (!is_server()) {
       struct city *pcity = is_non_allied_city_tile(ptile, pplayer);
 
       if (pcity 
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-03-03 17:23:31.000000000 +0200
+++ freeciv/server/srv_main.c	2007-03-03 19:36:44.000000000 +0200
@@ -114,11 +114,6 @@
 static void announce_player(struct player *pplayer);
 static void srv_loop(void);
 
-
-/* this is used in strange places, and is 'extern'd where
-   needed (hence, it is not 'extern'd in srv_main.h) */
-bool is_server = TRUE;
-
 /* command-line arguments to server */
 struct server_arguments srvarg;
 
@@ -162,6 +157,8 @@
 **************************************************************************/
 void srv_init(void)
 {
+  i_am_server(); /* Tell to libcivcommon that we are server */
+
   /* NLS init */
   init_nls();
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to