Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] PATCH: noninteractive server mode, dead player report
Home

[Freeciv-Dev] PATCH: noninteractive server mode, dead player report

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] PATCH: noninteractive server mode, dead player report
From: mueller <mueller@xxxxxxxx>
Date: Sat, 23 Sep 2000 21:34:55 +0200

(Slightly modified repost)

This patch implements an option -b for the civserver which prevents the
server
from reading from stdin. Also makes the server report to metaserver
whether a 
player is dead or alive.
Index: civserver.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/civserver.c,v
retrieving revision 1.199
diff -u -r1.199 civserver.c
--- civserver.c 2000/09/01 06:23:06     1.199
+++ civserver.c 2000/09/23 19:27:07
@@ -73,6 +73,9 @@
     else if (is_option("--help", argv[inx])) {
       showhelp = 1;
       break;
+    } else if (is_option("--background", argv[inx])) {
+      srvarg.background = 1;
+      break;
     } else if ((option = get_option("--log", argv, &inx, argc)) != NULL)
       srvarg.log_filename = option;
     else if ((option = get_option("--gamelog", argv, &inx, argc)) != NULL)
@@ -129,6 +132,7 @@
     fprintf(stderr, _("  -m, --meta\t\tSend info to metaserver\n"));
     fprintf(stderr, _("  -M, --Metaserver ADDR\tSet ADDR as metaserver 
address\n"));
     fprintf(stderr, _("  -s, --server HOST\tList this server as host HOST\n"));
+    fprintf(stderr, _("  -b, --background\tStart noninteractively, enable 
client cmds\n"));
 #ifdef DEBUG
     fprintf(stderr, _("  -d, --debug NUM\tSet debug log level (0 to 4,"
                      " or 4:file1,min,max:...)\n"));
Index: meta.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/meta.c,v
retrieving revision 1.36
diff -u -r1.36 meta.c
--- meta.c      2000/08/22 08:55:02     1.36
+++ meta.c      2000/09/23 19:27:07
@@ -373,8 +373,8 @@
       /* Fixme: how should metaserver handle multi-connects?
        * Uses player_addr_hack() for now.
        */
-      cat_snprintf(info, sizeof(info), "%2d   %-20s %s\n", i, pplayer->name,
-                  player_addr_hack(pplayer));
+      cat_snprintf(info, sizeof(info), "%2d   %-20s %s %s\n", i, pplayer->name,
+                  player_addr_hack(pplayer), pplayer->is_alive?"":"(dead)");
     }
   }
 
Index: sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.60
diff -u -r1.60 sernet.c
--- sernet.c    2000/09/18 22:39:18     1.60
+++ sernet.c    2000/09/23 19:27:08
@@ -331,7 +331,8 @@
     MY_FD_ZERO(&writefs);
     MY_FD_ZERO(&exceptfs);
 #ifndef SOCKET_ZERO_ISNT_STDIN
-    FD_SET(0, &readfs);        
+    if (!srvarg.background)
+      FD_SET(0, &readfs);      
 #endif
     FD_SET(sock, &readfs);
     FD_SET(sock, &exceptfs);
@@ -408,7 +409,7 @@
 #else  /* !HAVE_LIBREADLINE */
       int didget;
       char buf[BUF_SIZE+1];
-      
+
       if((didget=read(0, buf, BUF_SIZE))==-1) {
        freelog(LOG_FATAL, "read from stdin failed");
        exit(1);
Index: srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.21
diff -u -r1.21 srv_main.c
--- srv_main.c  2000/09/18 20:36:16     1.21
+++ srv_main.c  2000/09/23 19:27:09
@@ -220,6 +220,9 @@
   if (srvarg.script_filename)
     read_init_script(srvarg.script_filename);
 
+  if (srvarg.background)
+    handle_stdin_input((struct connection *)NULL, "cmdlevel ctrl");
+
   /* load a saved game */
   
   if(srvarg.load_filename) {
@@ -1703,6 +1706,19 @@
       toggle_ai_player_direct(NULL, pplayer);
     }
     check_for_full_turn_done();
+  }
+
+  if (srvarg.background) {
+    int i, humans=0;
+    for(i=0; i<game.nplayers; i++) {
+      struct player *pplayer = &game.players[i];
+      if (conn_list_size(&pplayer->connections))
+        humans++;
+    }
+    if (humans==0) {
+      close_connections_and_socket();
+      exit(0);
+    }
   }
 }
 
Index: srv_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.h,v
retrieving revision 1.3
diff -u -r1.3 srv_main.h
--- srv_main.h  2000/08/22 08:53:20     1.3
+++ srv_main.h  2000/09/23 19:27:09
@@ -36,6 +36,7 @@
   char *script_filename;
   /* server name for metaserver to use for us */
   char metaserver_servername[64];
+  int  background;
 };
 
 void srv_init(void);

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