From 6fffbfd241bda75e0167e06965b1d9a6c77b9746 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 25 Dec 2023 20:23:12 +0200 Subject: [PATCH 1/3] Update to Freeciv server freeciv/freeciv@e8beaa91d5 Signed-off-by: Marko Lindqvist --- .../src/main/webapp/javascript/unittype.js | 1 + freeciv/apply_patches.sh | 18 +- ...ions-before-setting-turn-number-to-1.patch | 69 --- ...-for-terminating-NULL-on-astr_buffer.patch | 36 -- .../0005-Meson-Define-SIZEOF_INT.patch | 43 -- .../0039-Improve-report.c-coding-style.patch | 449 ------------------ freeciv/version.txt | 4 +- 7 files changed, 4 insertions(+), 616 deletions(-) delete mode 100644 freeciv/patches/backports/0002-Pick-random-nations-before-setting-turn-number-to-1.patch delete mode 100644 freeciv/patches/backports/0003-Reserve-space-for-terminating-NULL-on-astr_buffer.patch delete mode 100644 freeciv/patches/backports/0005-Meson-Define-SIZEOF_INT.patch delete mode 100644 freeciv/patches/backports/0039-Improve-report.c-coding-style.patch diff --git a/freeciv-web/src/main/webapp/javascript/unittype.js b/freeciv-web/src/main/webapp/javascript/unittype.js index 018f4908a..ce0caa29d 100644 --- a/freeciv-web/src/main/webapp/javascript/unittype.js +++ b/freeciv-web/src/main/webapp/javascript/unittype.js @@ -39,6 +39,7 @@ var UCF_KILLCITIZEN = 10; var UCF_HUT_FRIGHTEN = 11; var UTYF_FLAGLESS = 30; +var UTYF_PROVIDES_RANSOM = 31; /**********************************************************************//** Return true iff units of the given type can do the specified generalized diff --git a/freeciv/apply_patches.sh b/freeciv/apply_patches.sh index f58f365e4..e29e10b94 100755 --- a/freeciv/apply_patches.sh +++ b/freeciv/apply_patches.sh @@ -2,22 +2,10 @@ # Freeciv server version upgrade notes (backports) # ------------------------------------------------ -# osdn #????? or RM #? is a ticket in freeciv.org tracker: +# osdn #????? or RM #?? is a ticket in freeciv.org tracker: # https://osdn.net/projects/freeciv/ticket/????? # https://redmine.freeciv.org/issues/?? # -# 0039-Improve-report.c-coding-style.patch -# Baseline for scorelog_filenames.patch -# osdn #48949 -# 0002-Pick-random-nations-before-setting-turn-number-to-1.patch -# Assert fix -# ????? -# 0003-Reserve-space-for-terminating-NULL-on-astr_buffer.patch -# String handling / datafile loading fix -# ????? -# 0005-Meson-Define-SIZEOF_INT.patch -# Fix to meson based build -# RM #7 # 0029-Meson-Search-mwand-by-MagickWand-6.Q16HDRI.pc.patch # MagickWand configure time fix on latest Debian/Ubuntu # RM #32 @@ -52,10 +40,6 @@ declare -a GIT_PATCHLIST=( ) declare -a PATCHLIST=( - "backports/0039-Improve-report.c-coding-style" - "backports/0002-Pick-random-nations-before-setting-turn-number-to-1" - "backports/0003-Reserve-space-for-terminating-NULL-on-astr_buffer" - "backports/0005-Meson-Define-SIZEOF_INT" "backports/0029-Meson-Search-mwand-by-MagickWand-6.Q16HDRI.pc" "backports/0027-worklist_item_postpone_req_vec-Add-break-for-VUT_PLA" "backports/0029-universal_value_initial-Fix-switch-case-fall-through" diff --git a/freeciv/patches/backports/0002-Pick-random-nations-before-setting-turn-number-to-1.patch b/freeciv/patches/backports/0002-Pick-random-nations-before-setting-turn-number-to-1.patch deleted file mode 100644 index 6f51aec82..000000000 --- a/freeciv/patches/backports/0002-Pick-random-nations-before-setting-turn-number-to-1.patch +++ /dev/null @@ -1,69 +0,0 @@ -From c78cd45b08561c79fe805ea63432be160a2f2e1c Mon Sep 17 00:00:00 2001 -From: Marko Lindqvist -Date: Wed, 15 Nov 2023 07:55:06 +0200 -Subject: [PATCH 2/2] Pick random nations before setting turn number to 1 - -The consequences of having nations unassigned at turn 1 -included failed asserts. - -Reported by gatorized - -https://forum.freeciv.org/f/viewtopic.php?t=94637 - -Signed-off-by: Marko Lindqvist ---- - server/plrhand.c | 2 +- - server/srv_main.c | 11 ++++++----- - 2 files changed, 7 insertions(+), 6 deletions(-) - -diff --git a/server/plrhand.c b/server/plrhand.c -index 98aff46cbf..76b91d346b 100644 ---- a/server/plrhand.c -+++ b/server/plrhand.c -@@ -1385,7 +1385,7 @@ static void package_player_info(struct player *plr, - packet->color_green = preferred->g; - packet->color_blue = preferred->b; - } else { -- fc_assert(game.info.turn < 1); -+ fc_assert(game.info.turn < 1); /* Game has not yet started */ - packet->color_valid = FALSE; - /* Client shouldn't use these dummy values */ - packet->color_red = 0; -diff --git a/server/srv_main.c b/server/srv_main.c -index a704497d03..9eae8cc5ae 100644 ---- a/server/srv_main.c -+++ b/server/srv_main.c -@@ -2317,7 +2317,7 @@ void update_nations_with_startpos(void) - } - - /**********************************************************************//** -- Handles a pick-nation packet from the client. These packets are -+ Handles a pick-nation packet from the client. These packets are - handled by connection because ctrl users may edit anyone's nation in - pregame, and editing is possible during a running game. - **************************************************************************/ -@@ -3199,16 +3199,17 @@ static void srv_ready(void) - #endif - - if (game.info.is_new_game) { -- game.info.turn++; /* pregame T0 -> game T1 */ -- fc_assert(game.info.turn == 1); -- game.info.year = game.server.start_year; - /* Must come before assign_player_colors() */ - generate_players(); - final_ruleset_adjustments(); -+ -+ game.info.turn++; /* Pregame T0 -> game T1 */ -+ fc_assert(game.info.turn == 1); -+ game.info.year = game.server.start_year; - } - - /* If we have a tile map, and MAPGEN_SCENARIO == map.server.generator, -- * call map_fractal_generate anyway to make the specials, huts and -+ * call map_fractal_generate() anyway to make the specials, huts and - * continent numbers. */ - if (map_is_empty() - || (MAPGEN_SCENARIO == wld.map.server.generator --- -2.42.0 - diff --git a/freeciv/patches/backports/0003-Reserve-space-for-terminating-NULL-on-astr_buffer.patch b/freeciv/patches/backports/0003-Reserve-space-for-terminating-NULL-on-astr_buffer.patch deleted file mode 100644 index bcea2842a..000000000 --- a/freeciv/patches/backports/0003-Reserve-space-for-terminating-NULL-on-astr_buffer.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 2d26bcf2fab7d90921be4932bf047d04e58502f7 Mon Sep 17 00:00:00 2001 -From: Marko Lindqvist -Date: Mon, 27 Nov 2023 01:29:52 +0200 -Subject: [PATCH 3/3] Reserve space for terminating NULL on astr_buffer - -Growing the buffer was always considered a failure, -as it was one byte too small even after giving out -the requested size. - -Reported by Giacomo Mulas - -Debian Bug#1056916 - -Signed-off-by: Marko Lindqvist < ---- - utility/astring.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/utility/astring.c b/utility/astring.c -index 02d775d3bd..ffdb77c1ea 100644 ---- a/utility/astring.c -+++ b/utility/astring.c -@@ -228,8 +228,8 @@ static inline void astr_vadd_at(struct astring *astr, size_t at, - va_copy(copy, ap); - - req_len = fc_vsnprintf(buffer, buffer_size, format, ap); -- if (req_len > buffer_size) { -- buffer = astr_buffer_grow(req_len, &buffer_size); -+ if (req_len + 1 > buffer_size) { -+ buffer = astr_buffer_grow(req_len + 1, &buffer_size); - /* Even if buffer is *still* too small, we fill what we can */ - req_len = fc_vsnprintf(buffer, buffer_size, format, copy); - if (req_len > buffer_size) { --- -2.42.0 - diff --git a/freeciv/patches/backports/0005-Meson-Define-SIZEOF_INT.patch b/freeciv/patches/backports/0005-Meson-Define-SIZEOF_INT.patch deleted file mode 100644 index 94639c231..000000000 --- a/freeciv/patches/backports/0005-Meson-Define-SIZEOF_INT.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 0e5a1f3ea059aaada4740719323ac778b898c06f Mon Sep 17 00:00:00 2001 -From: Marko Lindqvist -Date: Tue, 28 Nov 2023 12:03:27 +0200 -Subject: [PATCH 5/7] Meson: Define SIZEOF_INT - -See RM #7 - -Signed-off-by: Marko Lindqvist ---- - gen_headers/meson_fc_config.h.in | 3 +++ - meson.build | 2 ++ - 2 files changed, 5 insertions(+) - -diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in -index 315d330942..5fde52f32a 100644 ---- a/gen_headers/meson_fc_config.h.in -+++ b/gen_headers/meson_fc_config.h.in -@@ -43,6 +43,9 @@ - /* Processor stores words with the most significant byte first */ - #mesondefine WORDS_BIGENDIAN - -+/* Size of int type */ -+#mesondefine SIZEOF_INT -+ - /* Database backend available */ - #mesondefine HAVE_FCDB - -diff --git a/meson.build b/meson.build -index cfed0f9e08..d7861e1b37 100644 ---- a/meson.build -+++ b/meson.build -@@ -145,6 +145,8 @@ if host_machine.endian() == 'big' - priv_conf_data.set('WORDS_BIGENDIAN', 1) - endif - -+priv_conf_data.set('SIZEOF_INT', c_compiler.sizeof('int')) -+ - if get_option('debug') - priv_conf_data.set('FREECIV_DEBUG', 1) - pub_conf_data.set('FREECIV_DEBUG', 1) --- -2.42.0 - diff --git a/freeciv/patches/backports/0039-Improve-report.c-coding-style.patch b/freeciv/patches/backports/0039-Improve-report.c-coding-style.patch deleted file mode 100644 index 5f4770c28..000000000 --- a/freeciv/patches/backports/0039-Improve-report.c-coding-style.patch +++ /dev/null @@ -1,449 +0,0 @@ -From 0d5cdeb7aa55979cfc53c7a1e8345cb007cb309d Mon Sep 17 00:00:00 2001 -From: Marko Lindqvist -Date: Sun, 5 Nov 2023 23:13:27 +0200 -Subject: [PATCH 39/39] Improve report.c coding style - -See osdn #48949 - -Signed-off-by: Marko Lindqvist ---- - server/report.c | 147 ++++++++++++++++++++++++------------------------ - 1 file changed, 74 insertions(+), 73 deletions(-) - -diff --git a/server/report.c b/server/report.c -index e06fe0f813..34879233e2 100644 ---- a/server/report.c -+++ b/server/report.c -@@ -66,7 +66,7 @@ struct logging_civ_score { - * the end of previous turn in the beginning to turn 0. */ - struct history_report latest_history_report = { -2 }; - --static struct logging_civ_score *score_log = NULL; -+static struct logging_civ_score *score_log = nullptr; - - static void plrdata_slot_init(struct plrdata_slot *plrdata, - const char *name); -@@ -87,10 +87,10 @@ enum historian_type { - HISTORIAN_HAPPIEST = 3, - HISTORIAN_LARGEST = 4}; - --#define HISTORIAN_FIRST HISTORIAN_RICHEST --#define HISTORIAN_LAST HISTORIAN_LARGEST -+#define HISTORIAN_FIRST HISTORIAN_RICHEST -+#define HISTORIAN_LAST HISTORIAN_LARGEST - --static const char *historian_message[]={ -+static const char *historian_message[] = { - /* TRANS: year reports ... */ - N_("%s %s reports on the RICHEST Civilizations in the World."), - /* TRANS: year reports ... */ -@@ -103,7 +103,7 @@ static const char *historian_message[]={ - N_("%s %s reports on the LARGEST Civilizations in the World.") - }; - --static const char *historian_name[]={ -+static const char *historian_name[] = { - /* TRANS: [year] [reports ...] */ - N_("Herodotus"), - /* TRANS: [year] [reports ...] */ -@@ -193,7 +193,7 @@ static struct dem_col { - char key; - } coltable[] = {{'q'}, {'r'}, {'b'}}; /* Corresponds to dem_flag enum */ - --/* prime number of entries makes for better scaling */ -+/* Prime number of entries makes for better scaling */ - static const char *ranking[] = { - /* TRANS: <#>: The Poles */ - N_("%2d: The Supreme %s"), -@@ -233,7 +233,7 @@ static const char *ranking[] = { - static int secompare(const void *a, const void *b) - { - return (((const struct player_score_entry *)b)->value - -- ((const struct player_score_entry *)a)->value); -+ ((const struct player_score_entry *)a)->value); - } - - /**********************************************************************//** -@@ -250,45 +250,45 @@ static void historian_generic(struct history_report *report, - if (GOOD_PLAYER(pplayer)) { - switch (which_news) { - case HISTORIAN_RICHEST: -- size[j].value = pplayer->economic.gold; -- break; -+ size[j].value = pplayer->economic.gold; -+ break; - case HISTORIAN_ADVANCED: -- size[j].value -- = pplayer->score.techs + research_get(pplayer)->future_tech; -- break; -+ size[j].value -+ = pplayer->score.techs + research_get(pplayer)->future_tech; -+ break; - case HISTORIAN_MILITARY: -- size[j].value = pplayer->score.units; -- break; -- case HISTORIAN_HAPPIEST: -- size[j].value = -- (((pplayer->score.happy - pplayer->score.unhappy -+ size[j].value = pplayer->score.units; -+ break; -+ case HISTORIAN_HAPPIEST: -+ size[j].value -+ = (((pplayer->score.happy - pplayer->score.unhappy - - 2 * pplayer->score.angry) * 1000) / - (1 + total_player_citizens(pplayer))); -- break; -+ break; - case HISTORIAN_LARGEST: -- size[j].value = total_player_citizens(pplayer); -- break; -+ size[j].value = total_player_citizens(pplayer); -+ break; - } - size[j].player = pplayer; - j++; -- } /* else the player is dead or barbarian or observer */ -+ } /* Else the player is dead or barbarian or observer */ - } players_iterate_end; - - qsort(size, j, sizeof(size[0]), secompare); - report->body[0] = '\0'; - for (i = 0; i < j; i++) { - if (i > 0 && size[i].value < size[i - 1].value) { -- /* since i < j, only top entry reigns Supreme */ -+ /* Since i < j, only top entry reigns Supreme */ - rank = ((i * ARRAY_SIZE(ranking)) / j) + 1; - } - if (rank >= ARRAY_SIZE(ranking)) { -- /* clamp to final entry */ -+ /* Clamp to final entry */ - rank = ARRAY_SIZE(ranking) - 1; - } - cat_snprintf(report->body, REPORT_BODYSIZE, -- _(ranking[rank]), -- i + 1, -- nation_plural_for_player(size[i].player)); -+ _(ranking[rank]), -+ i + 1, -+ nation_plural_for_player(size[i].player)); - fc_strlcat(report->body, "\n", REPORT_BODYSIZE); - } - fc_snprintf(report->title, REPORT_TITLESIZE, _(historian_message[which_news]), -@@ -340,7 +340,7 @@ void report_top_cities(struct conn_list *dest) - - for (i = 0; i < game.info.top_cities_count; i++) { - size[i].value = 0; -- size[i].city = NULL; -+ size[i].city = nullptr; - } - - shuffled_players_iterate(pplayer) { -@@ -360,7 +360,7 @@ void report_top_cities(struct conn_list *dest) - for (i = 0; i < game.info.top_cities_count; i++) { - int wonders; - -- if (size[i].city == NULL) { -+ if (size[i].city == nullptr) { - /* - * There are less than game.info.top_cities_count cities in - * the whole game. -@@ -717,7 +717,7 @@ static int get_settlers(const struct player *pplayer) - int result = 0; - - if (!game.scenario.prevent_new_cities) { -- /* count up settlers */ -+ /* Count up settlers */ - unit_list_iterate(pplayer->units, punit) { - if (unit_can_do_action(punit, ACTION_FOUND_CITY)) { - result++; -@@ -957,6 +957,7 @@ static const char *percent_to_text(int value) - static const char *production_to_text(int value) - { - int clip = MAX(0, value); -+ - /* TRANS: "M tons" = million tons, so always plural */ - return value_units(clip, PL_(" M tons", " M tons", clip)); - } -@@ -1015,7 +1016,7 @@ static void dem_line_item(char *outptr, size_t out_size, - struct player *pplayer, struct dem_row *prow, - bv_cols selcols) - { -- if (NULL != pplayer && BV_ISSET(selcols, DEM_COL_QUANTITY)) { -+ if (pplayer != nullptr && BV_ISSET(selcols, DEM_COL_QUANTITY)) { - const char *text = prow->to_text(prow->get_value(pplayer)); - - cat_snprintf(outptr, out_size, " %s", text); -@@ -1023,26 +1024,26 @@ static void dem_line_item(char *outptr, size_t out_size, - 18 - (int) get_internal_string_length(text), ""); - } - -- if (NULL != pplayer && BV_ISSET(selcols, DEM_COL_RANK)) { -+ if (pplayer != nullptr && BV_ISSET(selcols, DEM_COL_RANK)) { - int basis = prow->get_value(pplayer); - int place = 1; - - players_iterate(other) { - if (GOOD_PLAYER(other) -- && ((prow->greater_values_are_better -- && prow->get_value(other) > basis) -- || (!prow->greater_values_are_better -- && prow->get_value(other) < basis))) { -- place++; -+ && ((prow->greater_values_are_better -+ && prow->get_value(other) > basis) -+ || (!prow->greater_values_are_better -+ && prow->get_value(other) < basis))) { -+ place++; - } - } players_iterate_end; - - cat_snprintf(outptr, out_size, _("(ranked %d)"), place); - } -- -- if (NULL == pplayer || BV_ISSET(selcols, DEM_COL_BEST)) { -+ -+ if (pplayer == nullptr || BV_ISSET(selcols, DEM_COL_BEST)) { - struct player *best_player = pplayer; -- int best_value = NULL != pplayer ? prow->get_value(pplayer) : 0; -+ int best_value = (pplayer != nullptr) ? prow->get_value(pplayer) : 0; - - players_iterate(other) { - if (GOOD_PLAYER(other)) { -@@ -1057,20 +1058,20 @@ static void dem_line_item(char *outptr, size_t out_size, - } - } players_iterate_end; - -- if (NULL == pplayer -+ if (pplayer == nullptr - || (team_has_embassy(pplayer->team, best_player) - && (pplayer != best_player))) { - cat_snprintf(outptr, out_size, " %s: %s", -- nation_plural_for_player(best_player), -- prow->to_text(prow->get_value(best_player))); -+ nation_plural_for_player(best_player), -+ prow->to_text(prow->get_value(best_player))); - } - } - } - - /**********************************************************************//** -- Verify that a given demography string is valid. See -- game.demography. If the string is not valid the index of the _first_ -- invalid character is return as 'error'. -+ Verify that a given demography string is valid. See game.demography. -+ If the string is not valid the index of the _first_ invalid character -+ is return as 'error'. - - Other settings callback functions are in settings.c, but this one uses - static values from this file so it's done separately. -@@ -1079,8 +1080,8 @@ bool is_valid_demography(const char *demography, int *error) - { - int len = strlen(demography), i; - -- /* We check each character individually to see if it's valid. This -- * does not check for duplicate entries. */ -+ /* We check each character individually to see if it's valid. -+ * This does not check for duplicate entries. */ - for (i = 0; i < len; i++) { - bool found = FALSE; - int j; -@@ -1088,8 +1089,8 @@ bool is_valid_demography(const char *demography, int *error) - /* See if the character is a valid column label. */ - for (j = 0; j < DEM_COL_LAST; j++) { - if (demography[i] == coltable[j].key) { -- found = TRUE; -- break; -+ found = TRUE; -+ break; - } - } - -@@ -1100,13 +1101,13 @@ bool is_valid_demography(const char *demography, int *error) - /* See if the character is a valid row label. */ - for (j = 0; j < ARRAY_SIZE(rowtable); j++) { - if (demography[i] == rowtable[j].key) { -- found = TRUE; -- break; -+ found = TRUE; -+ break; - } - } - - if (!found) { -- if (error != NULL) { -+ if (error != nullptr) { - (*error) = i; - } - /* The character is invalid. */ -@@ -1120,7 +1121,7 @@ bool is_valid_demography(const char *demography, int *error) - - /**********************************************************************//** - Send demographics report; what gets reported depends on value of -- demographics server option. -+ demographics server option. - **************************************************************************/ - void report_demographics(struct connection *pconn) - { -@@ -1192,7 +1193,7 @@ void report_achievements(struct connection *pconn) - char buffer[4096]; - struct player *pplayer = pconn->playing; - -- if (pplayer == NULL) { -+ if (pplayer == nullptr) { - return; - } - -@@ -1219,7 +1220,7 @@ void report_achievements(struct connection *pconn) - static void plrdata_slot_init(struct plrdata_slot *plrdata, - const char *name) - { -- fc_assert_ret(plrdata->name == NULL); -+ fc_assert_ret(plrdata->name == nullptr); - - plrdata->name = fc_calloc(MAX_LEN_NAME, sizeof(plrdata->name)); - plrdata_slot_replace(plrdata, name); -@@ -1231,7 +1232,7 @@ static void plrdata_slot_init(struct plrdata_slot *plrdata, - static void plrdata_slot_replace(struct plrdata_slot *plrdata, - const char *name) - { -- fc_assert_ret(plrdata->name != NULL); -+ fc_assert_ret(plrdata->name != nullptr); - - fc_strlcpy(plrdata->name, name, MAX_LEN_NAME); - } -@@ -1241,9 +1242,9 @@ static void plrdata_slot_replace(struct plrdata_slot *plrdata, - **************************************************************************/ - static void plrdata_slot_free(struct plrdata_slot *plrdata) - { -- if (plrdata->name != NULL) { -+ if (plrdata->name != nullptr) { - free(plrdata->name); -- plrdata->name = NULL; -+ plrdata->name = nullptr; - } - } - -@@ -1266,8 +1267,8 @@ static bool scan_score_log(char *id) - * saving couple of bytes. */ - char plr_name[MAX(MAX_LEN_NAME, MAX_SCORELOG_LINE_LEN - strlen("addplayer "))]; - -- fc_assert_ret_val(score_log != NULL, FALSE); -- fc_assert_ret_val(score_log->fp != NULL, FALSE); -+ fc_assert_ret_val(score_log != nullptr, FALSE); -+ fc_assert_ret_val(score_log->fp != nullptr, FALSE); - - score_log->last_turn = -1; - id[0] = '\0'; -@@ -1352,7 +1353,7 @@ static bool scan_score_log(char *id) - } - - plrdata = score_log->plrdata + plr_no; -- if (plrdata->name != NULL) { -+ if (plrdata->name != nullptr) { - log_error("[%s:%d] Two names for one player (id %d)!", - game.server.scorefile, line_nr, plr_no); - return FALSE; -@@ -1376,7 +1377,7 @@ static bool scan_score_log(char *id) - } - - plrdata = score_log->plrdata + plr_no; -- if (plrdata->name == NULL) { -+ if (plrdata->name == nullptr) { - log_error("[%s:%d] Trying to remove undefined player (id %d)!", - game.server.scorefile, line_nr, plr_no); - return FALSE; -@@ -1410,19 +1411,19 @@ static bool scan_score_log(char *id) - **************************************************************************/ - void log_civ_score_init(void) - { -- if (score_log != NULL) { -+ if (score_log != nullptr) { - return; - } - - score_log = fc_calloc(1, sizeof(*score_log)); -- score_log->fp = NULL; -+ score_log->fp = nullptr; - score_log->last_turn = -1; - score_log->plrdata = fc_calloc(player_slot_count(), - sizeof(*score_log->plrdata)); - player_slots_iterate(pslot) { - struct plrdata_slot *plrdata = score_log->plrdata - + player_slot_index(pslot); -- plrdata->name = NULL; -+ plrdata->name = nullptr; - } player_slots_iterate_end; - - latest_history_report.turn = -2; -@@ -1434,20 +1435,20 @@ void log_civ_score_init(void) - void log_civ_score_free(void) - { - if (!score_log) { -- /* nothing to do */ -+ /* Nothing to do */ - return; - } - - if (score_log->fp) { - fclose(score_log->fp); -- score_log->fp = NULL; -+ score_log->fp = nullptr; - } - - if (score_log->plrdata) { - player_slots_iterate(pslot) { - struct plrdata_slot *plrdata = score_log->plrdata - + player_slot_index(pslot); -- if (plrdata->name != NULL) { -+ if (plrdata->name != nullptr) { - free(plrdata->name); - } - } player_slots_iterate_end; -@@ -1455,7 +1456,7 @@ void log_civ_score_free(void) - } - - free(score_log); -- score_log = NULL; -+ score_log = nullptr; - } - - /**********************************************************************//** -@@ -1534,7 +1535,7 @@ void log_civ_score_now(void) - oper = SL_APPEND; - - fclose(score_log->fp); -- score_log->fp = NULL; -+ score_log->fp = nullptr; - } - } - -@@ -1581,7 +1582,7 @@ void log_civ_score_now(void) - player_slots_iterate(pslot) { - struct plrdata_slot *plrdata = score_log->plrdata - + player_slot_index(pslot); -- if (plrdata->name != NULL -+ if (plrdata->name != nullptr - && player_slot_is_used(pslot)) { - struct player *pplayer = player_slot_get_player(pslot); - -@@ -1596,7 +1597,7 @@ void log_civ_score_now(void) - players_iterate(pplayer) { - struct plrdata_slot *plrdata = score_log->plrdata + player_index(pplayer); - -- if (plrdata->name == NULL && GOOD_PLAYER(pplayer)) { -+ if (plrdata->name == nullptr && GOOD_PLAYER(pplayer)) { - switch (game.server.scoreloglevel) { - case SL_HUMANS: - if (is_ai(pplayer)) { -@@ -1619,7 +1620,7 @@ void log_civ_score_now(void) - if (GOOD_PLAYER(pplayer)) { - switch (game.server.scoreloglevel) { - case SL_HUMANS: -- if (is_ai(pplayer) && plrdata->name == NULL) { -+ if (is_ai(pplayer) && plrdata->name == nullptr) { - /* If a human player toggled into AI mode, don't break. */ - break; - } --- -2.42.0 - diff --git a/freeciv/version.txt b/freeciv/version.txt index f56cb5fea..e2dacf362 100644 --- a/freeciv/version.txt +++ b/freeciv/version.txt @@ -1,9 +1,9 @@ # The Git SHA hash for the commit to checkout from # https://github.com/freeciv/freeciv -FCREV=3148f236ff688a5270d9e1e2ad82a915c41b0128 +FCREV=e8beaa91d5b6116dc59ce1c1dc4ded6bc6f64066 -ORIGCAPSTR="+Freeciv.Devel-\${MAIN_VERSION}-2023.Nov.06" +ORIGCAPSTR="+Freeciv.Devel-\${MAIN_VERSION}-2023.Nov.10" # There's no need to bump this constantly as current freeciv-web # makes no connections to outside world - all connections are From 1f42f88b7087ae6e2d1ac96a8b8246c715a31087 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 25 Dec 2023 23:38:53 +0200 Subject: [PATCH 2/3] Server: Backport 0014-Improve-savemain.c-coding-style.patch Signed-off-by: Marko Lindqvist --- freeciv/apply_patches.sh | 4 + ...0014-Improve-savemain.c-coding-style.patch | 199 ++++++++++++++++++ freeciv/patches/savegame.patch | 30 +-- 3 files changed, 218 insertions(+), 15 deletions(-) create mode 100644 freeciv/patches/backports/0014-Improve-savemain.c-coding-style.patch diff --git a/freeciv/apply_patches.sh b/freeciv/apply_patches.sh index e29e10b94..5088cb9d0 100755 --- a/freeciv/apply_patches.sh +++ b/freeciv/apply_patches.sh @@ -18,6 +18,9 @@ # 0031-Meson-Enable-implicit-fallthrough-compiler-warnings.patch # Stricter compiler warnings # RM #76 +# 0014-Improve-savemain.c-coding-style.patch +# Baseline for freeciv-web patches +# RM #79 # Not in the upstream Freeciv server # ---------------------------------- @@ -44,6 +47,7 @@ declare -a PATCHLIST=( "backports/0027-worklist_item_postpone_req_vec-Add-break-for-VUT_PLA" "backports/0029-universal_value_initial-Fix-switch-case-fall-through" "backports/0031-Meson-Enable-implicit-fallthrough-compiler-warnings" + "backports/0014-Improve-savemain.c-coding-style" "meson_webperimental" "metachange" "text_fixes" diff --git a/freeciv/patches/backports/0014-Improve-savemain.c-coding-style.patch b/freeciv/patches/backports/0014-Improve-savemain.c-coding-style.patch new file mode 100644 index 000000000..4ccf41103 --- /dev/null +++ b/freeciv/patches/backports/0014-Improve-savemain.c-coding-style.patch @@ -0,0 +1,199 @@ +From 90c56937cd86414106794849c0325e1429f8aef3 Mon Sep 17 00:00:00 2001 +From: Marko Lindqvist +Date: Mon, 25 Dec 2023 20:41:38 +0200 +Subject: [PATCH 14/14] Improve savemain.c coding style + +See RM #79 + +Signed-off-by: Marko Lindqvist +--- + server/savegame/savemain.c | 50 +++++++++++++++++++------------------- + 1 file changed, 25 insertions(+), 25 deletions(-) + +diff --git a/server/savegame/savemain.c b/server/savegame/savemain.c +index cdafeff659..1ed82c773a 100644 +--- a/server/savegame/savemain.c ++++ b/server/savegame/savemain.c +@@ -35,7 +35,7 @@ + + #include "savemain.h" + +-static fc_thread *save_thread = NULL; ++static fc_thread *save_thread = nullptr; + + /************************************************************************//** + Main entry point for loading a game. +@@ -44,30 +44,30 @@ void savegame_load(struct section_file *sfile) + { + const char *savefile_options; + +- fc_assert_ret(sfile != NULL); ++ fc_assert_ret(sfile != nullptr); + + #ifdef DEBUG_TIMERS + struct timer *loadtimer = timer_new(TIMER_CPU, TIMER_DEBUG, "load"); + timer_start(loadtimer); +-#endif /* DEBUG_TIMERS */ ++#endif // DEBUG_TIMERS + + savefile_options = secfile_lookup_str(sfile, "savefile.options"); + +- if (!savefile_options) { ++ if (savefile_options == nullptr) { + log_error("Missing savefile options. Can not load the savegame."); + return; + } + + if (has_capabilities("+version3", savefile_options)) { +- /* load new format (freeciv 3.0.x and newer) */ ++ /* Load new format (freeciv 3.0.x and newer) */ + log_verbose("loading savefile in 3.0+ format ..."); + savegame3_load(sfile); + } else if (has_capabilities("+version2", savefile_options)) { +- /* load old format (freeciv 2.3 - 2.6) */ ++ /* Load old format (freeciv 2.3 - 2.6) */ + log_verbose("loading savefile in 2.3 - 2.6 format ..."); + savegame2_load(sfile); + } else { +- log_error("Too old savegame format not supported any more."); ++ log_error("Too old savegame. Format not supported any more."); + return; + } + +@@ -87,7 +87,7 @@ void savegame_load(struct section_file *sfile) + timer_stop(loadtimer); + log_debug("Loading secfile in %.3f seconds.", timer_read_seconds(loadtimer)); + timer_destroy(loadtimer); +-#endif /* DEBUG_TIMERS */ ++#endif // DEBUG_TIMERS + } + + /************************************************************************//** +@@ -122,12 +122,13 @@ static void save_thread_data_free(struct save_thread_data *stdata) + static void save_thread_run(void *arg) + { + struct save_thread_data *stdata = (struct save_thread_data *)arg; +- ++ + if (!secfile_save(stdata->sfile, stdata->filepath, stdata->save_compress_level, + stdata->save_compress_type)) { + con_write(C_FAIL, _("Failed saving game as %s"), stdata->filepath); + log_error("Game saving failed: %s", secfile_error()); +- notify_conn(NULL, NULL, E_LOG_ERROR, ftc_warning, _("Failed saving game.")); ++ notify_conn(nullptr, nullptr, E_LOG_ERROR, ftc_warning, ++ _("Failed saving game.")); + } else { + con_write(C_OK, _("Game saved as %s"), stdata->filepath); + } +@@ -151,7 +152,7 @@ void save_game(const char *orig_filename, const char *save_reason, + stdata->save_compress_type = game.server.save_compress_type; + stdata->save_compress_level = game.server.save_compress_level; + +- if (!orig_filename) { ++ if (orig_filename == nullptr) { + stdata->filepath[0] = '\0'; + filename = stdata->filepath; + } else { +@@ -172,15 +173,15 @@ void save_game(const char *orig_filename, const char *save_reason, + } else { + char *end_dot; + char *strip_extensions[] = { +- ".sav", ".gz", ".bz2", ".xz", ".zst", NULL }; ++ ".sav", ".gz", ".bz2", ".xz", ".zst", nullptr }; + bool stripped = TRUE; + + while ((end_dot = strrchr(dot, '.')) && stripped) { +- int i; ++ int i; + + stripped = FALSE; + +- for (i = 0; strip_extensions[i] != NULL && !stripped; i++) { ++ for (i = 0; strip_extensions[i] != nullptr && !stripped; i++) { + if (!strcmp(end_dot, strip_extensions[i])) { + *end_dot = '\0'; + stripped = TRUE; +@@ -190,7 +191,7 @@ void save_game(const char *orig_filename, const char *save_reason, + } + } + +- /* If orig_filename is NULL or empty, use a generated default name. */ ++ /* If orig_filename is nullptr or empty, use a generated default name. */ + if (filename[0] == '\0') { + /* Manual save */ + generate_save_name(game.server.save_name, filename, +@@ -240,7 +241,7 @@ void save_game(const char *orig_filename, const char *save_reason, + default: + log_error(_("Unsupported compression type %d."), + stdata->save_compress_type); +- notify_conn(NULL, NULL, E_SETTING, ftc_warning, ++ notify_conn(nullptr, nullptr, E_SETTING, ftc_warning, + _("Unsupported compression type %d."), + stdata->save_compress_type); + break; +@@ -257,7 +258,7 @@ void save_game(const char *orig_filename, const char *save_reason, + log_error(_("Can't create saves directory %s!"), + srvarg.saves_pathname); + /* Don't tell server paths to clients */ +- notify_conn(NULL, NULL, E_SETTING, ftc_warning, ++ notify_conn(nullptr, nullptr, E_SETTING, ftc_warning, + _("Can't create saves directory!")); + + save_thread_data_free(stdata); +@@ -275,7 +276,7 @@ void save_game(const char *orig_filename, const char *save_reason, + log_error(_("Can't create scenario saves directory %s!"), + srvarg.scenarios_pathname); + /* Don't tell server paths to clients */ +- notify_conn(NULL, NULL, E_SETTING, ftc_warning, ++ notify_conn(nullptr, nullptr, E_SETTING, ftc_warning, + _("Can't create scenario saves directory!")); + + save_thread_data_free(stdata); +@@ -295,19 +296,19 @@ void save_game(const char *orig_filename, const char *save_reason, + sz_strlcpy(stdata->filepath, tmpname); + } + +- if (save_thread != NULL) { ++ if (save_thread != nullptr) { + /* Previously started thread */ + fc_thread_wait(save_thread); + if (!game.server.threaded_save) { + /* Setting has changed since the last save */ + free(save_thread); +- save_thread = NULL; ++ save_thread = nullptr; + } + } else if (game.server.threaded_save) { + save_thread = fc_malloc(sizeof(save_thread)); + } + +- if (save_thread != NULL) { ++ if (save_thread != nullptr) { + fc_thread_start(save_thread, &save_thread_run, stdata); + } else { + save_thread_run(stdata); +@@ -316,7 +317,7 @@ void save_game(const char *orig_filename, const char *save_reason, + #ifdef LOG_TIMERS + log_verbose("Save time: %g seconds (%g apparent)", + timer_read_seconds(timer_cpu), timer_read_seconds(timer_user)); +-#endif ++#endif // LOG_TIMERS + + timer_destroy(timer_cpu); + timer_destroy(timer_user); +@@ -327,10 +328,9 @@ void save_game(const char *orig_filename, const char *save_reason, + ****************************************************************************/ + void save_system_close(void) + { +- if (save_thread != NULL) { ++ if (save_thread != nullptr) { + fc_thread_wait(save_thread); + free(save_thread); +- save_thread = NULL; ++ save_thread = nullptr; + } + } +- +-- +2.43.0 + diff --git a/freeciv/patches/savegame.patch b/freeciv/patches/savegame.patch index 5f67d64bb..836ae656c 100644 --- a/freeciv/patches/savegame.patch +++ b/freeciv/patches/savegame.patch @@ -1,6 +1,6 @@ diff -Nurd freeciv/server/commands.c freeciv/server/commands.c ---- freeciv/server/commands.c 2023-11-23 00:08:14.914204235 +0200 -+++ freeciv/server/commands.c 2023-11-23 00:08:21.958242708 +0200 +--- freeciv/server/commands.c 2023-12-25 20:51:02.322522586 +0200 ++++ freeciv/server/commands.c 2023-12-25 20:51:10.406577004 +0200 @@ -552,7 +552,7 @@ "all cities and units etc. Use with care!"), NULL, CMD_ECHO_ALL, VCF_NONE, 50 @@ -11,12 +11,12 @@ diff -Nurd freeciv/server/commands.c freeciv/server/commands.c N_("save\n" "save "), diff -Nurd freeciv/server/savegame/savemain.c freeciv/server/savegame/savemain.c ---- freeciv/server/savegame/savemain.c 2023-11-23 00:08:14.922204280 +0200 -+++ freeciv/server/savegame/savemain.c 2023-11-23 00:08:21.958242708 +0200 -@@ -152,8 +152,8 @@ +--- freeciv/server/savegame/savemain.c 2023-12-25 20:51:02.326522613 +0200 ++++ freeciv/server/savegame/savemain.c 2023-12-25 20:52:18.935034920 +0200 +@@ -153,8 +153,8 @@ stdata->save_compress_level = game.server.save_compress_level; - if (!orig_filename) { + if (orig_filename == nullptr) { - stdata->filepath[0] = '\0'; - filename = stdata->filepath; + con_write(C_FAIL, _("Failed saving game. Missing filename.")); @@ -24,11 +24,11 @@ diff -Nurd freeciv/server/savegame/savemain.c freeciv/server/savegame/savemain.c } else { sz_strlcpy(stdata->filepath, orig_filename); if ((filename = strrchr(stdata->filepath, '/'))) { -@@ -190,13 +190,6 @@ +@@ -191,13 +191,6 @@ } } -- /* If orig_filename is NULL or empty, use a generated default name. */ +- /* If orig_filename is nullptr or empty, use a generated default name. */ - if (filename[0] == '\0') { - /* Manual save */ - generate_save_name(game.server.save_name, filename, @@ -39,8 +39,8 @@ diff -Nurd freeciv/server/savegame/savemain.c freeciv/server/savegame/savemain.c timer_user = timer_new(TIMER_USER, TIMER_ACTIVE, "save user"); timer_start(timer_cpu); diff -Nurd freeciv/server/stdinhand.c freeciv/server/stdinhand.c ---- freeciv/server/stdinhand.c 2023-11-23 00:08:14.918204257 +0200 -+++ freeciv/server/stdinhand.c 2023-11-23 00:08:21.962242728 +0200 +--- freeciv/server/stdinhand.c 2023-12-25 20:51:02.326522613 +0200 ++++ freeciv/server/stdinhand.c 2023-12-25 20:51:10.406577004 +0200 @@ -21,6 +21,7 @@ #include #include @@ -49,7 +49,7 @@ diff -Nurd freeciv/server/stdinhand.c freeciv/server/stdinhand.c #ifdef FREECIV_HAVE_LIBREADLINE #include -@@ -670,11 +671,6 @@ +@@ -671,11 +672,6 @@ **************************************************************************/ static bool save_command(struct connection *caller, char *arg, bool check) { @@ -61,7 +61,7 @@ diff -Nurd freeciv/server/stdinhand.c freeciv/server/stdinhand.c if (!check) { save_game(arg, "User request", FALSE); } -@@ -3791,6 +3787,7 @@ +@@ -3792,6 +3788,7 @@ struct section_file *file; char arg[MAX_LEN_PATH]; struct conn_list *global_observers; @@ -69,7 +69,7 @@ diff -Nurd freeciv/server/stdinhand.c freeciv/server/stdinhand.c if (!filename || filename[0] == '\0') { cmd_reply(CMD_LOAD, caller, C_FAIL, _("Usage:\n%s"), -@@ -3810,10 +3807,21 @@ +@@ -3811,10 +3808,21 @@ } { @@ -92,7 +92,7 @@ diff -Nurd freeciv/server/stdinhand.c freeciv/server/stdinhand.c }; const char *exts[] = { "sav", "gz", "bz2", "xz", "sav.gz", "sav.bz2", "sav.xz", "sav.zst", NULL -@@ -3864,9 +3872,12 @@ +@@ -3865,9 +3873,12 @@ cmd_reply(CMD_LOAD, caller, C_FAIL, _("Could not load savefile: %s"), arg); dlsend_packet_game_load(game.est_connections, FALSE, arg); @@ -105,7 +105,7 @@ diff -Nurd freeciv/server/stdinhand.c freeciv/server/stdinhand.c if (check) { return TRUE; } -@@ -4522,6 +4533,35 @@ +@@ -4523,6 +4534,35 @@ level = command_level(command_by_number(cmd)); From 97710d894b812628ee0ee3b255523795d0824618 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 27 Dec 2023 21:09:12 +0200 Subject: [PATCH 3/3] Server: Backport 0017-Fix-city-removal-server-crashes.patch Signed-off-by: Marko Lindqvist --- freeciv/apply_patches.sh | 4 ++ ...0017-Fix-city-removal-server-crashes.patch | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 freeciv/patches/backports/0017-Fix-city-removal-server-crashes.patch diff --git a/freeciv/apply_patches.sh b/freeciv/apply_patches.sh index 5088cb9d0..27acc18af 100755 --- a/freeciv/apply_patches.sh +++ b/freeciv/apply_patches.sh @@ -21,6 +21,9 @@ # 0014-Improve-savemain.c-coding-style.patch # Baseline for freeciv-web patches # RM #79 +# 0017-Fix-city-removal-server-crashes.patch +# Crash fix +# RM #81 # Not in the upstream Freeciv server # ---------------------------------- @@ -48,6 +51,7 @@ declare -a PATCHLIST=( "backports/0029-universal_value_initial-Fix-switch-case-fall-through" "backports/0031-Meson-Enable-implicit-fallthrough-compiler-warnings" "backports/0014-Improve-savemain.c-coding-style" + "backports/0017-Fix-city-removal-server-crashes" "meson_webperimental" "metachange" "text_fixes" diff --git a/freeciv/patches/backports/0017-Fix-city-removal-server-crashes.patch b/freeciv/patches/backports/0017-Fix-city-removal-server-crashes.patch new file mode 100644 index 000000000..652b9bdd5 --- /dev/null +++ b/freeciv/patches/backports/0017-Fix-city-removal-server-crashes.patch @@ -0,0 +1,55 @@ +From 37508b45f7591f3acb749afb223aeefcaeb76749 Mon Sep 17 00:00:00 2001 +From: Marko Lindqvist +Date: Wed, 27 Dec 2023 15:11:56 +0200 +Subject: [PATCH 17/17] Fix city removal server crashes + +When city removal wipes a unit that's not homed to the city, +but on the same tile, recursive city refresh was crashing +due to city vision and advisor data being already deleted. + +See RM #81 + +Signed-off-by: Marko Lindqvist +--- + server/citytools.c | 17 +++++++++++------ + 1 file changed, 11 insertions(+), 6 deletions(-) + +diff --git a/server/citytools.c b/server/citytools.c +index f760deb3e0..87917e0b77 100644 +--- a/server/citytools.c ++++ b/server/citytools.c +@@ -3416,11 +3416,13 @@ void city_landlocked_sell_coastal_improvements(struct tile *ptile) + ****************************************************************************/ + void city_refresh_vision(struct city *pcity) + { +- v_radius_t vision_radius_sq +- = V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2); ++ if (pcity->server.vision != nullptr) { ++ v_radius_t vision_radius_sq ++ = V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2); + +- vision_change_sight(pcity->server.vision, vision_radius_sq); +- ASSERT_VISION(pcity->server.vision); ++ vision_change_sight(pcity->server.vision, vision_radius_sq); ++ ASSERT_VISION(pcity->server.vision); ++ } + } + + /************************************************************************//** +@@ -3525,8 +3527,11 @@ bool city_map_update_radius_sq(struct city *pcity) + city_refresh_vision(pcity); + } + +- /* If city is under AI control, update it */ +- adv_city_update(pcity); ++ /* City removal might be ongoing, and advisor data already deleted */ ++ if (pcity->server.adv != nullptr) { ++ /* If city is under AI control, update it */ ++ adv_city_update(pcity); ++ } + + notify_player(city_owner(pcity), city_tile(pcity), E_CITY_RADIUS_SQ, + ftc_server, _("The size of the city map of %s is %s."), +-- +2.43.0 +