URL: http://bugs.freeciv.org/Ticket/Display.html?id=39956
Implement part of the bug fix proposal in PR#39579.
server/ruleset.c
load_rulesets()
remove redundant send_rulesets(), usually sent later after game_load(),
instead send only after explicit server/stdinhand.c set_rulesetdir()
In addition, this fixes a bug sending rulesets to game.all_connections
instead of the correct game.est_connections (established).
Now, all rulesets are sent only 2 times. Sending once would be better, but
that requires a packet change with significant redesign and restructuring!
server/savegame.c
game_load()
remove redundant send_ruleset_nations(), sent later with send_rulesets()
Now, nation rulesets are sent only 2 times, as above.
server/srv_main.c
start_game()
remove redundant send_server_settings()
Now, server settings are sent only 3 times. The third time is probably
redundant, but various settings are changing without update packets sent!
Therefore, left the remaining redundancy in place (suitably logged).
Generally, send_server_settings() after send_rulesets() for delta
compression of the redundancy and updates.
Also, the server and client had identically named handle_packet_input()
routines, yet were not the generated packet handler names. Renamed to
avoid confusion with each other, and with packets.def handlers.
client/repodlgs_common.c
calloc instead of malloc
Index: server/srv_main.c
===
--- server/srv_main.c (revision 14148)
+++ server/srv_main.c (working copy)
@@ -976,7 +976,6 @@
set_server_state(S_S_GENERATING_WAITING); /* loaded ??? */
force_end_of_sniff = TRUE;
- send_server_settings(NULL);
/* There's no stateful packet set to client until srv_ready(). */
}
@@ -1073,7 +1072,7 @@
Returns 0 if connection should be closed (because the clients was
rejected). Returns 1 else.
**/
-bool handle_packet_input(struct connection *pconn, void *packet, int type)
+bool server_packet_input(struct connection *pconn, void *packet, int type)
{
struct player *pplayer;
@@ -1502,8 +1501,7 @@
send_player_info(pplayer, NULL);
/* Note this is called even if the player has pressed /start once
- * before. This is a good thing given that no other code supports
- * is_started yet. For instance if a player leaves everyone left
+ * before. For instance, when a player leaves everyone remaining
* might have pressed /start already but the start won't happen
* until someone presses it again. Also you can press start more
* than once to remind other people to start (which is a good thing
@@ -1996,10 +1994,17 @@
set_server_state(S_S_RUNNING);
(void) send_server_info_to_metaserver(META_INFO);
+
+ freelog(LOG_VERBOSE, srv_ready() mostly redundant send_server_settings());
send_server_settings(NULL);
if (game.info.is_new_game) {
-/* Before the player map is allocated (and initiailized)! */
+/* If we're starting a new game, reset the max_players to be the
+ * number of players currently in the game.
+ */
+game.info.max_players = game.info.nplayers;
+
+/* Before the player map is allocated (and initialized)! */
game.fogofwar_old = game.info.fogofwar;
players_iterate(pplayer) {
@@ -2034,15 +2039,7 @@
}
} players_iterate_end;
-assert(game.info.is_new_game); { /* FIXME: inexplicable test */
- /* If we're starting a new game, reset the rules.max_players to be the
- * number of players currently in the game. But when loading a game
- * we don't want to change it. */
- game.info.max_players = game.info.nplayers;
-}
-
/* Set up alliances based on team selections */
-assert(game.info.is_new_game); /* FIXME: inexplicable test */
players_iterate(pplayer) {
players_iterate(pdest) {
if (players_on_same_team(pplayer, pdest)
@@ -2054,7 +2051,8 @@
} players_iterate_end;
} players_iterate_end;
}
-
+
+ /* FIXME: can this be moved? */
players_iterate(pplayer) {
ai_data_analyze_rulesets(pplayer);
} players_iterate_end;
Index: server/srv_main.h
===
--- server/srv_main.h (revision 14148)
+++ server/srv_main.h (working copy)
@@ -61,7 +61,7 @@
bool check_for_game_over(void);
-bool handle_packet_input(struct connection *pconn, void *packet, int type);
+bool server_packet_input(struct connection *pconn, void *packet, int type);
void start_game(void);
void save_game(char *orig_filename, const char *save_reason);
void pick_random_player_name(const struct nation_type *pnation,
Index: server/connecthand.c
===
--- server/connecthand.c(revision 14148)
+++ server/connecthand.c(working copy)
@@ -47,7 +47,7 @@
has started. If