[Freeciv-Dev] Server patch: Background mode, report dead players
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I've patched the server to accept (undocumented) option -b or
--background. If
called like that, it will
a) Not read stdin
b) Set cmdlevel ctrl
c) Exit if last players disconnects.
This is used by my new client which runs the server for single player
games.
Also, the server reports whether a player is dead or alive in the
metaserver
info. The metaserver in turn only proposes live players in the Join As
field.
That version is already up.
One thing about the server tho: I suggest a one-line /list format for
players that only 1 person is connected to. /list is important during
startup.
Patches for the client will by much larger, can I get CVS write access
maybe?
A rollback is always possible.
-Urban (Zop) 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/16 18:38:57
@@ -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)
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/16 18:38:58
@@ -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.58
diff -u -r1.58 sernet.c
--- sernet.c 2000/09/11 06:49:34 1.58
+++ sernet.c 2000/09/16 18:39:00
@@ -262,7 +262,8 @@
MY_FD_ZERO(&readfs);
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);
@@ -335,7 +336,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.20
diff -u -r1.20 srv_main.c
--- srv_main.c 2000/09/06 21:41:19 1.20
+++ srv_main.c 2000/09/16 18:39:10
@@ -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) {
@@ -1694,6 +1697,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/16 18:39:10
@@ -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);
- [Freeciv-Dev] Server patch: Background mode, report dead players,
Urban Mueller <=
|
|