--- freeciv-1.7.2.stock/server/stdinhand.c Tue Dec 22 09:16:59 1998 +++ freeciv-1.7.2/server/stdinhand.c Tue Feb 9 18:28:36 1999 @@ -31,7 +31,6 @@ extern char metaserver_info_line[256]; void cut_player_connection(char *playername); -void quit_game(void); void show_help(void); void show_players(void); @@ -236,6 +239,9 @@ { static int first=1; + if(is_daemon) + return; + if (first) printf("\nGet a list of the available commands with 'h'.\n"); @@ -620,6 +626,9 @@ char command[512], arg[512], *cptr_s, *cptr_d; int i; + if(is_daemon) + return; + /* Is it a comment or a blank line? */ /* line is comment if the first non-whitespace character is '#': */ for(cptr_s=str; *cptr_s && isspace(*cptr_s); cptr_s++); @@ -666,8 +675,10 @@ set_ai_level(arg, 5); else if (!strcmp("hard", command)) set_ai_level(arg, 7); - else if(!strcmp("q", command)) - quit_game(); + else if(!strcmp("q", command)) { + quit_game(); + exit(1); + } else if(!strcmp("c", command)) cut_player_connection(arg); else if (!strcmp("show",command)) @@ -676,6 +687,12 @@ explain_option(arg); else if (!strcmp("set", command)) set_command(arg); + else if(!strcmp("daemon", command)) { + if(server_state==RUN_GAME_STATE) + become_daemon(arg); + else + printf("Sorry, you have to at least start the game before the process can become a daemon.\n"); + } else if(!strcmp("score", command)) { if(server_state==RUN_GAME_STATE) show_ending(); @@ -727,47 +744,31 @@ /************************************************************************** ... **************************************************************************/ -void quit_game(void) -{ - int i; - struct packet_generic_message gen_packet; - gen_packet.message[0]='\0'; - - for(i=0; i #include #include +#include #include +#include +#include +#include #ifdef __EMX__ #include @@ -72,6 +76,7 @@ void ai_start_turn(void); int is_game_over(); void read_init_script(char *script_filename); +void deadly_signal(int sig); extern struct connection connections[]; @@ -109,18 +114,22 @@ int rand_init=0; +int is_daemon=0; + /************************************************************************** ... **************************************************************************/ int main(int argc, char *argv[]) { - int h=0, v=0, n=0; + int h=0, v=0, n=0, do_daemon=0; char *log_filename=NULL; char *load_filename=NULL; char *script_filename=NULL; int i; int save_counter=0; int log_level=LOG_NORMAL; + struct packet_generic_message gen_packet; + struct sigaction act; strcpy(metaserver_info_line, DEFAULT_META_SERVER_INFO_STRING); @@ -192,6 +201,17 @@ else if(!strcmp("-v", argv[i]) || !strcmp("--version", argv[i])) { v=1; } + else if(!strcmp("-b", argv[i]) || !strcmp("--background", argv[i])) { + if(++i>=argc) { + fprintf(stderr, "Error: no game file specified for daemon mode\n"); + h=1; + break; + } + load_filename=argv[i]; + do_daemon=1; + if(++i