Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2004:
[Freeciv-Dev] (PR#2757) Patch: New metaserver sample civclient/civserver
Home

[Freeciv-Dev] (PR#2757) Patch: New metaserver sample civclient/civserver

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: _vasc@xxxxxxxxxxx.pt_
Subject: [Freeciv-Dev] (PR#2757) Patch: New metaserver sample civclient/civserver implementation
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 4 Oct 2004 15:17:42 -0700
Reply-to: rt@xxxxxxxxxxx

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

here'a a patch that changes the way available players are calculated.
In a nutshell, the metaserver doesn't do it, the server looks at allowtake
and sends the info to the metaserver.

-mike


? server/.meta.c.swp
Index: server/meta.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/meta.c,v
retrieving revision 1.61
diff -u -r1.61 meta.c
--- server/meta.c       4 Oct 2004 04:37:33 -0000       1.61
+++ server/meta.c       4 Oct 2004 22:11:50 -0000
@@ -176,7 +176,7 @@
   static char msg[8192];
   static char str[8192];
   int rest = sizeof(str);
-  int n;
+  int n = 0;
   char *s = str;
   char host[512];
   char state[20];
@@ -253,7 +253,10 @@
       mystrlcpy(s, "dropplrs=1&", rest);
       s = end_of_strn(s, &rest);
     } else {
+      n = 0; /* a counter for players_available */
+
       players_iterate(plr) {
+        bool is_player_available = FALSE;
         char type[15];
         struct connection *pconn = find_conn_by_user(plr->username);
 
@@ -285,7 +288,34 @@
         my_snprintf(s, rest, "plh[]=%s&",
                     pconn ? my_url_encode(pconn->addr) : "");
         s = end_of_strn(s, &rest);
+
+        /* is this player available to take?
+         * TODO: there's some duplication here with 
+         * stdinhand.c:is_allowed_to_take() */
+        if (is_barbarian(plr) && strchr(game.allow_take, 'b')) {
+          is_player_available = TRUE;
+        } else if (!plr->is_alive && strchr(game.allow_take, 'd')) {
+          is_player_available = TRUE;
+        } else if (plr->ai.control
+            && strchr(game.allow_take, (game.is_new_game ? 'A' : 'a'))) {
+          is_player_available = TRUE;
+        } else if (!plr->ai.control
+            && strchr(game.allow_take, (game.is_new_game ? 'H' : 'h'))) {
+          is_player_available = TRUE;
+        }
+
+        if (pconn) {
+          is_player_available = FALSE;
+        }
+
+        if (is_player_available) {
+          n++;
+        }
       } players_iterate_end;
+
+      /* send the number of available players. */
+      my_snprintf(s, rest, "available=%d&", n);
+      s = end_of_strn(s, &rest);
     }
 
     /* send some variables: should be listed in inverted order
@@ -314,6 +344,10 @@
                 my_url_encode("maxplayers"), game.max_players);
     s = end_of_strn(s, &rest);
 
+    my_snprintf(s, rest, "vn[]=%s&vv[]=%s&",
+                my_url_encode("allowtake"), game.allow_take);
+    s = end_of_strn(s, &rest);
+
     my_snprintf(s, rest, "vn[]=%s&vv[]=%d&",
                 my_url_encode("generator"), map.generator);
     s = end_of_strn(s, &rest);

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