Skip to content

Commit

Permalink
Server: Backport 0051-Adjust-nationality-of-remaining-units-after-pla…
Browse files Browse the repository at this point in the history
…yer-r.patch

Signed-off-by: Marko Lindqvist <[email protected]>
  • Loading branch information
cazfi committed Apr 5, 2024
1 parent 786505e commit 37268be
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions freeciv/apply_patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# 0041-Stop-sending-hidden-resources-to-the-client.patch
# Extra visibility fix
# RM #350
# 0051-Adjust-nationality-of-remaining-units-after-player-r.patch
# Fix to player removal
# RM #383

# Not in the upstream Freeciv server
# ----------------------------------
Expand Down Expand Up @@ -45,6 +48,7 @@ declare -a PATCHLIST=(
"backports/0025-Purge-worklist-items-with-unfulfilled-local-range-im"
"backports/0002-Fix-allied-victory-of-all-players"
"backports/0041-Stop-sending-hidden-resources-to-the-client"
"backports/0051-Adjust-nationality-of-remaining-units-after-player-r"
"RevertAmplio2ExtraUnits"
"meson_webperimental"
"metachange"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
From d9e61b2de945fc3cb8f934c6b514f5b4f441b1bd Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <[email protected]>
Date: Sun, 31 Mar 2024 18:34:19 +0300
Subject: [PATCH 51/57] Adjust nationality of remaining units after player
removal

Nationality of the units owned by other players could
previously be that of removed player, leading to a crash.
Now switch nationality of such units to that of their
current owner when player of their nationality is removed.

See RM #383

Signed-off-by: Marko Lindqvist <[email protected]>
---
common/player.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/common/player.c b/common/player.c
index d539a79dad..209b9c6571 100644
--- a/common/player.c
+++ b/common/player.c
@@ -659,8 +659,12 @@ void player_set_color(struct player *pplayer,
}

/*******************************************************************//**
- Clear all player data. If full is set, then the nation and the team will
- be cleared too.
+ Clear all player data.
+
+ If full is set, also
+ - The nation is cleared
+ - The team is cleared
+ - Nationality information of remaining units is adjusted
***********************************************************************/
void player_clear(struct player *pplayer, bool full)
{
@@ -717,6 +721,15 @@ void player_clear(struct player *pplayer, bool full)
if (full) {
team_remove_player(pplayer);

+ players_iterate_alive(owner) {
+ unit_list_iterate(owner->units, owned) {
+ if (unit_nationality(owned) == pplayer) {
+ /* Switch nationality to that of current owner. */
+ owned->nationality = owner;
+ }
+ } unit_list_iterate_end;
+ } players_iterate_alive_end;
+
/* This comes last because log calls in the above functions
* may use it. */
if (pplayer->nation != NULL) {
--
2.43.0

0 comments on commit 37268be

Please sign in to comment.