Index: server/srv_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v retrieving revision 1.88 diff -u -r1.88 srv_main.c --- server/srv_main.c 2002/08/06 22:27:03 1.88 +++ server/srv_main.c 2002/08/08 14:04:31 @@ -95,7 +95,6 @@ #include "srv_main.h" - static void begin_turn(void); static void before_end_year(void); static void end_turn(void); @@ -116,7 +115,6 @@ static void send_select_nation(struct player *pplayer); static void check_for_full_turn_done(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; @@ -134,6 +132,8 @@ */ bool force_end_of_sniff; +/* set this to TRUE to quit program on game over */ +bool server_quit_flag = FALSE; /* The next three variables make selecting nations for AI players cleaner */ static int *nations_avail; @@ -1746,73 +1746,21 @@ } /************************************************************************** -Server initialization. + Server loop **************************************************************************/ -void srv_main(void) +void srv_loop(void) { int i; - /* make sure it's initialized */ - if (!has_been_srv_init) { - srv_init(); - } - - my_init_network(); - - con_log_init(srvarg.log_filename, srvarg.loglevel); - gamelog_init(srvarg.gamelog_filename); - gamelog_set_level(GAMELOG_FULL); - gamelog(GAMELOG_NORMAL, _("Starting new log")); - -#ifdef GENERATING_MAC /* mac beta notice */ - con_puts(C_COMMENT, ""); - con_puts(C_COMMENT, "This is an alpha/beta version of MacFreeciv."); - con_puts(C_COMMENT, "Visit http://www.geocities.com/SiliconValley/Orchard/8738/MFC/index.html"); - con_puts(C_COMMENT, "for new versions of this project and information about it."); - con_puts(C_COMMENT, ""); -#endif -#if IS_BETA_VERSION - con_puts(C_COMMENT, ""); - con_puts(C_COMMENT, beta_message()); - con_puts(C_COMMENT, ""); -#endif - - con_flush(); - - init_our_capability(); - game_init(); - - /* load a saved game */ - - if (srvarg.load_filename) { - load_command(NULL, srvarg.load_filename); - } - - /* init network */ - init_connections(); - server_open_socket(); - - if(!(srvarg.metaserver_no_send)) { - freelog(LOG_NORMAL, _("Sending info to metaserver [%s]"), - meta_addr_port()); - server_open_udp(); /* open socket for meta server */ - } - - (void) send_server_info_to_metaserver(TRUE, FALSE); - /* accept new players, wait for serverop to start..*/ server_state=PRE_GAME_STATE; - /* load a script file */ - if (srvarg.script_filename - && !read_init_script(NULL, srvarg.script_filename)) { - exit(EXIT_FAILURE); - } - freelog(LOG_NORMAL, _("Now accepting new client connections.")); while(server_state==PRE_GAME_STATE) sniff_packets(); /* Accepting commands. */ + if (server_quit_flag) { return; } + (void) send_server_info_to_metaserver(TRUE, FALSE); if(game.is_new_game) { @@ -1958,20 +1906,77 @@ /*** Where the action is. ***/ main_loop(); +} - send_game_state(&game.est_connections, CLIENT_GAME_OVER_STATE); +/************************************************************************** +Server initialization. +**************************************************************************/ +void srv_main(void) +{ + /* make sure it's initialized */ + if (!has_been_srv_init) { + srv_init(); + } + my_init_network(); - report_scores(TRUE); - show_map_to_all(); - notify_player(NULL, _("Game: The game is over...")); - gamelog(GAMELOG_NORMAL, _("The game is over!")); - if (game.save_nturns > 0) save_game_auto(); + con_log_init(srvarg.log_filename, srvarg.loglevel); + gamelog_init(srvarg.gamelog_filename); + gamelog_set_level(GAMELOG_FULL); + gamelog(GAMELOG_NORMAL, _("Starting new log")); + +#if IS_BETA_VERSION + con_puts(C_COMMENT, ""); + con_puts(C_COMMENT, beta_message()); + con_puts(C_COMMENT, ""); +#endif + + con_flush(); + init_our_capability(); + game_init(); - while (server_state == GAME_OVER_STATE) { - force_end_of_sniff = FALSE; - sniff_packets(); + /* load a saved game */ + if (srvarg.load_filename) { + load_command(NULL, srvarg.load_filename); + } + + /* init network */ + init_connections(); + server_open_socket(); + + if(!(srvarg.metaserver_no_send)) { + freelog(LOG_NORMAL, _("Sending info to metaserver [%s]"), + meta_addr_port()); + server_open_udp(); /* open socket for meta server */ } + (void) send_server_info_to_metaserver(TRUE, FALSE); + + /* load a script file */ + if (srvarg.script_filename + && !read_init_script(NULL, srvarg.script_filename)) { + exit(EXIT_FAILURE); + } + + /* Run server loop */ + while (TRUE) { + srv_loop(); + if (server_quit_flag) { break; } /* quit from pregame */ + + report_scores(TRUE); + show_map_to_all(); + notify_player(NULL, _("Game: The game is over...")); + gamelog(GAMELOG_NORMAL, _("The game is over!")); + if (game.save_nturns > 0) { save_game_auto(); } + + game_free(); + game_init(); + + game.is_new_game = TRUE; + server_state=PRE_GAME_STATE; + send_game_state(&game.est_connections, CLIENT_PRE_GAME_STATE); + } + + send_game_state(&game.est_connections, CLIENT_GAME_OVER_STATE); + close_connections_and_socket(); - game_free(); } Index: server/srv_main.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/srv_main.h,v retrieving revision 1.11 diff -u -r1.11 srv_main.h --- server/srv_main.h 2002/05/25 17:44:09 1.11 +++ server/srv_main.h 2002/08/08 14:04:31 @@ -62,4 +62,6 @@ extern bool force_end_of_sniff; +extern bool server_quit_flag; + #endif /* FC__SRV_MAIN_H */ Index: server/stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.240 diff -u -r1.240 stdinhand.c --- server/stdinhand.c 2002/08/07 21:38:05 1.240 +++ server/stdinhand.c 2002/08/08 14:04:32 @@ -1014,7 +1014,8 @@ }, {"quit", ALLOW_HACK, "quit", - N_("Quit the game and shutdown the server."), NULL + N_("In pregame: Quit the game and shutdown the server. " + "During game: Stop the game and return to pregame."), NULL }, {"cut", ALLOW_CTRL, /* TRANS: translate text between <> only */ @@ -3333,13 +3334,20 @@ } /************************************************************************** -... + Jump back to pregame from run game state, or quit game from pregame **************************************************************************/ void quit_game(struct connection *caller) { - cmd_reply(CMD_QUIT, caller, C_OK, _("Goodbye.")); - close_connections_and_socket(); - exit(EXIT_SUCCESS); + if (server_state == PRE_GAME_STATE) { + con_write(C_OK, "Goodbye!"); + server_state = RUN_GAME_STATE; /* exit loop */ + server_quit_flag = TRUE; /* then quit */ + force_end_of_sniff = TRUE; + } else if (server_state == RUN_GAME_STATE) { + con_write(C_OK, "Returning to pregame state"); + server_state = PRE_GAME_STATE; /* just exit loop */ + force_end_of_sniff = TRUE; + } } /**************************************************************************