<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40235 >
2008/5/8 Marko Lindqvist:
>
> Player changes when trying to /take player one is currently observing.
- Fixed crash when global observer does "/take -"
- ML
diff -Nurd -X.diff_ignore freeciv/server/stdinhand.c freeciv/server/stdinhand.c
--- freeciv/server/stdinhand.c 2008-05-07 17:44:45.000000000 +0300
+++ freeciv/server/stdinhand.c 2008-05-08 04:20:18.000000000 +0300
@@ -2900,7 +2900,8 @@
struct connection *pconn = caller;
struct player *pplayer = NULL;
bool res = FALSE;
-
+ bool was_observing_this;
+
/******** PART I: fill pconn and pplayer ********/
sz_strlcpy(buf, str);
@@ -2961,9 +2962,6 @@
goto end;
}
- if (!pplayer) {
- }
-
/* Make sure there is free player slot if there is need to
* create new player. This is necessary for previously
* detached connections only. Others can reuse the slot
@@ -2990,6 +2988,11 @@
/* others are sent below */
}
+ if (pconn->playing && pconn->playing == pplayer) {
+ /* Connection was obserwing the very player it now /take */
+ was_observing_this = TRUE;
+ }
+
/* if the player is controlled by another user,
* forcibly convert the user to an observer.
*/
@@ -3013,9 +3016,10 @@
} conn_list_iterate_end;
}
- /* if the connection is already attached to a player,
- * unattach and cleanup old player (rename, remove, etc) */
- if (NULL != pconn->playing) {
+ /* if the connection is already attached to another player,
+ * unattach and cleanup old player (rename, remove, etc)
+ * We may have been observing the player we now want to take */
+ if (NULL != pconn->playing && !was_observing_this) {
char name[MAX_LEN_NAME], username[MAX_LEN_NAME];
if (pplayer) {
@@ -3039,11 +3043,13 @@
}
} players_iterate_end;
- /* now attach to new player */
- res = attach_connection_to_player(pconn, pplayer, FALSE);
+ if (!was_observing_this || !pconn->playing) {
+ /* Now attach to new player */
+ res = attach_connection_to_player(pconn, pplayer, FALSE);
- /* Check aifill even if attach failed. Maybe we already detached. */
- aifill(game.info.aifill);
+ /* Check aifill even if attach failed. Maybe we already detached. */
+ aifill(game.info.aifill);
+ }
if (res) {
/* Successfully attached */
diff -Nurd -X.diff_ignore freeciv/server/stdinhand.c freeciv/server/stdinhand.c
--- freeciv/server/stdinhand.c 2008-05-08 00:24:57.000000000 +0300
+++ freeciv/server/stdinhand.c 2008-05-08 04:04:24.000000000 +0300
@@ -2896,7 +2896,8 @@
struct connection *pconn = caller;
struct player *pplayer = NULL;
bool res = FALSE;
-
+ bool was_observing_this;
+
/******** PART I: fill pconn and pplayer ********/
sz_strlcpy(buf, str);
@@ -2979,6 +2980,11 @@
/* others are sent below */
}
+ if (pconn->player && pconn->player == pplayer) {
+ /* Connection was obserwing the very player it now /take */
+ was_observing_this = TRUE;
+ }
+
/* if we're taking another player with a user attached,
* forcibly detach the user from the player. */
if (pplayer) {
@@ -2998,9 +3004,10 @@
} conn_list_iterate_end;
}
- /* if the connection is already attached to a player,
- * unattach and cleanup old player (rename, remove, etc) */
- if (pconn->player) {
+ /* if the connection is already attached to another player,
+ * unattach and cleanup old player (rename, remove, etc)
+ * We may have been observing the player we now want to take */
+ if (pconn->player && !was_observing_this) {
char name[MAX_LEN_NAME], username[MAX_LEN_NAME];
if (pplayer) {
@@ -3026,7 +3033,11 @@
/* now attach to new player */
pconn->observer = FALSE; /* do this before attach! */
- res = attach_connection_to_player(pconn, pplayer);
+
+ if (!was_observing_this || !pplayer) {
+ /* now attach to new player */
+ res = attach_connection_to_player(pconn, pplayer);
+ }
if (res) {
/* Successfully attached */
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev