[Freeciv-Dev] Re: (PR#8745) Bug: conndlg and scenarios
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8745 >
attached is a patch which allows single player work with scenarios.
I requires a change to packets.def and a new capability.
-mike
diff -Nur -Xcvs/diff_ignore snap/client/gui-gtk-2.0/connectdlg.c
snap-conn/client/gui-gtk-2.0/connectdlg.c
--- snap/client/gui-gtk-2.0/connectdlg.c 2004-08-28 10:38:51.000000000
-0500
+++ snap-conn/client/gui-gtk-2.0/connectdlg.c 2004-08-28 20:47:56.681590640
-0500
@@ -458,12 +458,8 @@
gtk_list_store_clear(storesaved);
- if (packet->nplayers != 0) {
- game.nplayers = packet->nplayers;
- }
-
/* we couldn't load the savegame, we could have gotten the name wrong, etc */
- if (packet->nplayers == 0
+ if (!packet->load_successful
|| strcmp(current_filename, packet->load_filename) != 0) {
gtk_window_set_title(GTK_WINDOW(dialog), _("Couldn't load the savegame"));
return;
@@ -474,6 +470,8 @@
gtk_window_set_title(GTK_WINDOW(dialog), ++buf);
}
+ game.nplayers = packet->nplayers;
+
for (i = 0; i < packet->nplayers; i++) {
GtkTreeIter iter;
@@ -486,10 +484,23 @@
3, packet->is_alive[i] ? _("Alive") : _("Dead"),
4, packet->is_ai[i] ? _("AI") : _("Human"), -1);
- /* set flag. */
- flag = get_flag(packet->nation_flag[i]);
- gtk_list_store_set(storesaved, &iter, 1, flag, -1);
- g_object_unref(flag);
+ /* set flag if we've got one to set. */
+ if (strcmp(packet->nation_flag[i], "") != 0) {
+ flag = get_flag(packet->nation_flag[i]);
+ gtk_list_store_set(storesaved, &iter, 1, flag, -1);
+ g_object_unref(flag);
+ }
+ }
+
+ /* if nplayers is zero, we suppose it's a scenario */
+ if (packet->load_successful && packet->nplayers == 0) {
+ char message[MAX_LEN_MSG];
+
+ my_snprintf(message, sizeof(message), "/create %s", user_name);
+ send_chat(message);
+ my_snprintf(message, sizeof(message), "/ai %s", user_name);
+ send_chat(message);
+ send_packet_single_playerlist_req(&aconnection);
}
}
diff -Nur -Xcvs/diff_ignore snap/common/capstr.c snap-conn/common/capstr.c
--- snap/common/capstr.c 2004-08-28 10:38:52.000000000 -0500
+++ snap-conn/common/capstr.c 2004-08-28 18:52:32.427812852 -0500
@@ -78,7 +78,8 @@
"+change_production +tilespec1 +no_earth +trans " \
"+want_hack invasions bombard +killstack2 spec +spec2 " \
"+city_map startunits +turn_last_built +happyborders " \
- "+connid +love2 +ocean_num +govclean +orders3 +rev_fin"
+ "+connid +love2 +ocean_num +govclean +orders3 +rev_fin " \
+ "+plist"
/* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
*
@@ -147,6 +148,9 @@
*
* "rev_fin" means the revolution_finishes value replaces the revolution
* value.
+ *
+ * "plist" means that the playerlist sends an extra field that tells the
+ * server if a game load was successful or not.
*/
void init_our_capability(void)
diff -Nur -Xcvs/diff_ignore snap/common/packets.def snap-conn/common/packets.def
--- snap/common/packets.def 2004-08-28 10:38:52.000000000 -0500
+++ snap-conn/common/packets.def 2004-08-28 18:50:49.446413350 -0500
@@ -1265,6 +1265,7 @@
end
PACKET_SINGLE_PLAYERLIST_REPLY=111;sc
+ BOOL load_successful;
UINT8 nplayers;
STRING load_filename[MAX_LEN_PACKET];
STRING name[MAX_NUM_PLAYERS:nplayers][MAX_LEN_NAME];
diff -Nur -Xcvs/diff_ignore snap/server/plrhand.c snap-conn/server/plrhand.c
--- snap/server/plrhand.c 2004-08-28 10:38:55.000000000 -0500
+++ snap-conn/server/plrhand.c 2004-08-28 20:48:06.712193117 -0500
@@ -2105,6 +2105,7 @@
int i;
struct packet_single_playerlist_reply packet;
+ packet.load_successful = last_game_load_successful;
packet.nplayers = game.nplayers;
sz_strlcpy(packet.load_filename, srvarg.load_filename);
@@ -2119,7 +2120,7 @@
sz_strlcpy(packet.name[i], pplayer->name);
sz_strlcpy(packet.username[i], pplayer->username);
- if (game.nation_count) {
+ if (game.nation_count && pplayer->nation != NO_NATION_SELECTED) {
sz_strlcpy(packet.nation_name[i], get_nation_name(pplayer->nation));
sz_strlcpy(packet.nation_flag[i],
get_nation_by_plr(pplayer)->flag_graphic_str);
diff -Nur -Xcvs/diff_ignore snap/server/stdinhand.c snap-conn/server/stdinhand.c
--- snap/server/stdinhand.c 2004-08-28 10:38:55.000000000 -0500
+++ snap-conn/server/stdinhand.c 2004-08-28 20:58:53.227681806 -0500
@@ -65,6 +65,7 @@
#include "stdinhand.h"
+bool last_game_load_successful = FALSE;
static enum cmdlevel_id default_access_level = ALLOW_INFO;
static enum cmdlevel_id first_access_level = ALLOW_CTRL;
@@ -4231,12 +4232,14 @@
if (!arg || arg[0] == '\0') {
cmd_reply(CMD_LOAD, caller, C_FAIL, _("Usage: load <filename>"));
+ last_game_load_successful = (check) ? FALSE : last_game_load_successful;
return FALSE;
}
if (server_state != PRE_GAME_STATE) {
cmd_reply(CMD_LOAD, caller, C_FAIL, _("Can't load a game while another "
"is running."));
+ last_game_load_successful = (check) ? FALSE : last_game_load_successful;
return FALSE;
}
@@ -4244,6 +4247,7 @@
if (!section_file_load_nodup(&file, arg)) {
cmd_reply(CMD_LOAD, caller, C_FAIL, _("Couldn't load savefile: %s"), arg);
+ last_game_load_successful = (check) ? FALSE : last_game_load_successful;
return FALSE;
}
@@ -4285,6 +4289,8 @@
}
} players_iterate_end;
} conn_list_iterate_end;
+
+ last_game_load_successful = TRUE;
return TRUE;
}
diff -Nur -Xcvs/diff_ignore snap/server/stdinhand.h snap-conn/server/stdinhand.h
--- snap/server/stdinhand.h 2004-04-09 22:43:58.000000000 -0500
+++ snap-conn/server/stdinhand.h 2004-08-28 18:50:01.648831598 -0500
@@ -20,6 +20,8 @@
#define SERVER_COMMAND_PREFIX '/'
/* the character to mark chatlines as server commands */
+extern bool last_game_load_successful;
+
void stdinhand_init(void);
void stdinhand_turn(void);
void stdinhand_free(void);
- [Freeciv-Dev] Re: (PR#8745) Bug: conndlg and scenarios,
Mike Kaufman <=
|
|