[Freeciv-Dev] (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 >
New patch:
- I renamed send_packet_game_load as send_game_load_reply. I wanted to
move it out of stdinhand.c but there really isn't anywhere better.
- When we load a scenario we /create, /aitoggle, and /take the new
player. After this the server settings can be opened up out of the menu.
There are still problems:
- With scenarios that don't have aifill (like earth-80x50) you need to
set aifill. But this can't be done from the settings dialog.
- Opening the settings dialog from the menu is obviously a poor
interface. There should be a button for this in the load page.
This whole thing is pretty ugly. But I guess that's the only way to get
it to work...
jason
? common/output
Index: client/packhand_gen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand_gen.c,v
retrieving revision 1.6
diff -u -r1.6 packhand_gen.c
--- client/packhand_gen.c 29 Jul 2004 00:09:26 -0000 1.6
+++ client/packhand_gen.c 6 Sep 2004 07:22:18 -0000
@@ -308,8 +308,8 @@
((struct packet_single_want_hack_reply *)packet)->you_have_hack);
return TRUE;
- case PACKET_SINGLE_PLAYERLIST_REPLY:
- handle_single_playerlist_reply(packet);
+ case PACKET_GAME_LOAD:
+ handle_game_load(packet);
return TRUE;
case PACKET_OPTIONS_SETTABLE_CONTROL:
Index: client/packhand_gen.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand_gen.h,v
retrieving revision 1.6
diff -u -r1.6 packhand_gen.h
--- client/packhand_gen.h 29 Jul 2004 00:09:26 -0000 1.6
+++ client/packhand_gen.h 6 Sep 2004 07:22:18 -0000
@@ -94,8 +94,8 @@
struct packet_ruleset_control;
void handle_ruleset_control(struct packet_ruleset_control *packet);
void handle_single_want_hack_reply(bool you_have_hack);
-struct packet_single_playerlist_reply;
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
*packet);
+struct packet_game_load;
+void handle_game_load(struct packet_game_load *packet);
struct packet_options_settable_control;
void handle_options_settable_control(struct packet_options_settable_control
*packet);
struct packet_options_settable;
Index: client/gui-gtk/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/connectdlg.c,v
retrieving revision 1.46
diff -u -r1.46 connectdlg.c
--- client/gui-gtk/connectdlg.c 10 Apr 2004 03:47:48 -0000 1.46
+++ client/gui-gtk/connectdlg.c 6 Sep 2004 07:22:18 -0000
@@ -350,11 +350,10 @@
}
/**************************************************************************
- this regenerates the player information from a game on the server.
+ this regenerates the player information from a loaded game on the server.
currently a stub. TODO
**************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
- *packet)
+void handle_game_load(struct packet_game_load *packet)
{
/* PORTME */
}
Index: client/gui-gtk-2.0/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/connectdlg.c,v
retrieving revision 1.38
diff -u -r1.38 connectdlg.c
--- client/gui-gtk-2.0/connectdlg.c 28 Aug 2004 07:21:01 -0000 1.38
+++ client/gui-gtk-2.0/connectdlg.c 6 Sep 2004 07:22:18 -0000
@@ -445,10 +445,9 @@
}
/**************************************************************************
- this regenerates the player information from a game on the server.
+ this regenerates the player information from a loaded game on the server.
**************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
- *packet)
+void handle_game_load(struct packet_game_load *packet)
{
int i;
@@ -458,12 +457,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 +469,7 @@
gtk_window_set_title(GTK_WINDOW(dialog), ++buf);
}
+ game.nplayers = packet->nplayers;
for (i = 0; i < packet->nplayers; i++) {
GtkTreeIter iter;
@@ -486,10 +482,32 @@
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) {
+ GtkTreeIter iter;
+ 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);
+ my_snprintf(message, sizeof(message), "/take %s", user_name);
+ send_chat(message);
+
+ /* create a false entry */
+ gtk_list_store_append(storesaved, &iter);
+ gtk_list_store_set(storesaved, &iter,
+ 0, user_name,
+ 3, _("Alive"),
+ 4, _("Human"), -1);
}
}
@@ -520,7 +538,6 @@
my_snprintf(message, sizeof(message), "/load %s", current_filename);
send_chat(message);
- send_packet_single_playerlist_req(&aconnection);
}
}
Index: client/gui-sdl/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/connectdlg.c,v
retrieving revision 1.22
diff -u -r1.22 connectdlg.c
--- client/gui-sdl/connectdlg.c 10 Apr 2004 03:47:48 -0000 1.22
+++ client/gui-sdl/connectdlg.c 6 Sep 2004 07:22:19 -0000
@@ -81,10 +81,9 @@
}
/**************************************************************************
- provide a packet handler for packet_single_playerlist_reply
+ provide a packet handler for packet_game_load
**************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
- *packet)
+void handle_game_load(struct packet_game_load *packet)
{
/* PORTME */
}
Index: client/gui-stub/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/connectdlg.c,v
retrieving revision 1.11
diff -u -r1.11 connectdlg.c
--- client/gui-stub/connectdlg.c 10 Apr 2004 03:47:48 -0000 1.11
+++ client/gui-stub/connectdlg.c 6 Sep 2004 07:22:19 -0000
@@ -85,10 +85,9 @@
}
/**************************************************************************
- provide a packet handler for packet_single_playerlist_reply
+ provide a packet handler for packet_game_load
**************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
- *packet)
+void handle_game_load(struct packet_game_load *packet)
{
/* PORTME */
}
Index: client/gui-win32/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/connectdlg.c,v
retrieving revision 1.22
diff -u -r1.22 connectdlg.c
--- client/gui-win32/connectdlg.c 21 Aug 2004 16:34:03 -0000 1.22
+++ client/gui-win32/connectdlg.c 6 Sep 2004 07:22:19 -0000
@@ -105,8 +105,7 @@
/**************************************************************************
PORTME
**************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
- *packet)
+void handle_game_load(struct packet_game_load *packet)
{
}
Index: client/gui-xaw/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/connectdlg.c,v
retrieving revision 1.34
diff -u -r1.34 connectdlg.c
--- client/gui-xaw/connectdlg.c 10 Apr 2004 03:47:49 -0000 1.34
+++ client/gui-xaw/connectdlg.c 6 Sep 2004 07:22:19 -0000
@@ -235,11 +235,10 @@
}
/**************************************************************************
- this regenerates the player information from a game on the server.
+ this regenerates the player information from a loaded game on the server.
currently a stub. TODO
**************************************************************************/
-void handle_single_playerlist_reply(struct packet_single_playerlist_reply
- *packet)
+void handle_game_load(struct packet_game_load *packet)
{
/* PORTME */
}
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.47
diff -u -r1.47 packets.def
--- common/packets.def 6 Sep 2004 02:58:11 -0000 1.47
+++ common/packets.def 6 Sep 2004 07:22:19 -0000
@@ -1260,10 +1260,8 @@
BOOL you_have_hack;
end
-PACKET_SINGLE_PLAYERLIST_REQ=110;cs,handle-per-conn,no-handle
-end
-
-PACKET_SINGLE_PLAYERLIST_REPLY=111;sc
+PACKET_GAME_LOAD=111;sc,handle-via-packet,lsend
+ BOOL load_successful;
UINT8 nplayers;
STRING load_filename[MAX_LEN_PACKET];
STRING name[MAX_NUM_PLAYERS:nplayers][MAX_LEN_NAME];
Index: common/packets_gen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets_gen.c,v
retrieving revision 1.51
diff -u -r1.51 packets_gen.c
--- common/packets_gen.c 6 Sep 2004 02:58:11 -0000 1.51
+++ common/packets_gen.c 6 Sep 2004 07:22:20 -0000
@@ -377,11 +377,8 @@
case PACKET_SINGLE_WANT_HACK_REPLY:
return receive_packet_single_want_hack_reply(pc, type);
- case PACKET_SINGLE_PLAYERLIST_REQ:
- return receive_packet_single_playerlist_req(pc, type);
-
- case PACKET_SINGLE_PLAYERLIST_REPLY:
- return receive_packet_single_playerlist_reply(pc, type);
+ case PACKET_GAME_LOAD:
+ return receive_packet_game_load(pc, type);
case PACKET_OPTIONS_SETTABLE_CONTROL:
return receive_packet_options_settable_control(pc, type);
@@ -734,11 +731,8 @@
case PACKET_SINGLE_WANT_HACK_REPLY:
return "PACKET_SINGLE_WANT_HACK_REPLY";
- case PACKET_SINGLE_PLAYERLIST_REQ:
- return "PACKET_SINGLE_PLAYERLIST_REQ";
-
- case PACKET_SINGLE_PLAYERLIST_REPLY:
- return "PACKET_SINGLE_PLAYERLIST_REPLY";
+ case PACKET_GAME_LOAD:
+ return "PACKET_GAME_LOAD";
case PACKET_OPTIONS_SETTABLE_CONTROL:
return "PACKET_OPTIONS_SETTABLE_CONTROL";
@@ -26308,95 +26302,25 @@
return send_packet_single_want_hack_reply(pc, real_packet);
}
-static struct packet_single_playerlist_req
*receive_packet_single_playerlist_req_100(struct connection *pc, enum
packet_type type)
-{
- RECEIVE_PACKET_START(packet_single_playerlist_req, real_packet);
-
- RECEIVE_PACKET_END(real_packet);
-}
-
-static int send_packet_single_playerlist_req_100(struct connection *pc)
-{
- SEND_PACKET_START(PACKET_SINGLE_PLAYERLIST_REQ);
- SEND_PACKET_END;
-}
-
-static void ensure_valid_variant_packet_single_playerlist_req(struct
connection *pc)
-{
- int variant = -1;
-
- if(pc->phs.variant[PACKET_SINGLE_PLAYERLIST_REQ] != -1) {
- return;
- }
-
- if(FALSE) {
- } else if(TRUE) {
- variant = 100;
- } else {
- die("unknown variant");
- }
- pc->phs.variant[PACKET_SINGLE_PLAYERLIST_REQ] = variant;
-}
-
-struct packet_single_playerlist_req
*receive_packet_single_playerlist_req(struct connection *pc, enum packet_type
type)
-{
- if(!pc->used) {
- freelog(LOG_ERROR,
- "WARNING: trying to read data from the closed connection %s",
- conn_description(pc));
- return NULL;
- }
- assert(pc->phs.variant != NULL);
- if(!is_server) {
- freelog(LOG_ERROR, "Receiving packet_single_playerlist_req at the
client.");
- }
- ensure_valid_variant_packet_single_playerlist_req(pc);
-
- switch(pc->phs.variant[PACKET_SINGLE_PLAYERLIST_REQ]) {
- case 100: return receive_packet_single_playerlist_req_100(pc, type);
- default: die("unknown variant"); return NULL;
- }
-}
-
-int send_packet_single_playerlist_req(struct connection *pc)
-{
- if(!pc->used) {
- freelog(LOG_ERROR,
- "WARNING: trying to send data to the closed connection %s",
- conn_description(pc));
- return -1;
- }
- assert(pc->phs.variant != NULL);
- if(is_server) {
- freelog(LOG_ERROR, "Sending packet_single_playerlist_req from the
server.");
- }
- ensure_valid_variant_packet_single_playerlist_req(pc);
-
- switch(pc->phs.variant[PACKET_SINGLE_PLAYERLIST_REQ]) {
- case 100: return send_packet_single_playerlist_req_100(pc);
- default: die("unknown variant"); return -1;
- }
-}
-
-#define hash_packet_single_playerlist_reply_100 hash_const
+#define hash_packet_game_load_100 hash_const
-#define cmp_packet_single_playerlist_reply_100 cmp_const
+#define cmp_packet_game_load_100 cmp_const
-BV_DEFINE(packet_single_playerlist_reply_100_fields, 8);
+BV_DEFINE(packet_game_load_100_fields, 9);
-static struct packet_single_playerlist_reply
*receive_packet_single_playerlist_reply_100(struct connection *pc, enum
packet_type type)
+static struct packet_game_load *receive_packet_game_load_100(struct connection
*pc, enum packet_type type)
{
- packet_single_playerlist_reply_100_fields fields;
- struct packet_single_playerlist_reply *old;
+ packet_game_load_100_fields fields;
+ struct packet_game_load *old;
struct hash_table **hash = &pc->phs.received[type];
- struct packet_single_playerlist_reply *clone;
- RECEIVE_PACKET_START(packet_single_playerlist_reply, real_packet);
+ struct packet_game_load *clone;
+ RECEIVE_PACKET_START(packet_game_load, real_packet);
DIO_BV_GET(&din, fields);
if (!*hash) {
- *hash = hash_new(hash_packet_single_playerlist_reply_100,
cmp_packet_single_playerlist_reply_100);
+ *hash = hash_new(hash_packet_game_load_100, cmp_packet_game_load_100);
}
old = hash_delete_entry(*hash, real_packet);
@@ -26406,7 +26330,8 @@
memset(real_packet, 0, sizeof(*real_packet));
}
- if (BV_ISSET(fields, 0)) {
+ real_packet->load_successful = BV_ISSET(fields, 0);
+ if (BV_ISSET(fields, 1)) {
{
int readin;
@@ -26414,10 +26339,10 @@
real_packet->nplayers = readin;
}
}
- if (BV_ISSET(fields, 1)) {
+ if (BV_ISSET(fields, 2)) {
dio_get_string(&din, real_packet->load_filename,
sizeof(real_packet->load_filename));
}
- if (BV_ISSET(fields, 2)) {
+ if (BV_ISSET(fields, 3)) {
{
int i;
@@ -26431,7 +26356,7 @@
}
}
}
- if (BV_ISSET(fields, 3)) {
+ if (BV_ISSET(fields, 4)) {
{
int i;
@@ -26445,7 +26370,7 @@
}
}
}
- if (BV_ISSET(fields, 4)) {
+ if (BV_ISSET(fields, 5)) {
{
int i;
@@ -26459,7 +26384,7 @@
}
}
}
- if (BV_ISSET(fields, 5)) {
+ if (BV_ISSET(fields, 6)) {
{
int i;
@@ -26473,7 +26398,7 @@
}
}
}
- if (BV_ISSET(fields, 6)) {
+ if (BV_ISSET(fields, 7)) {
{
int i;
@@ -26487,7 +26412,7 @@
}
}
}
- if (BV_ISSET(fields, 7)) {
+ if (BV_ISSET(fields, 8)) {
{
int i;
@@ -26512,18 +26437,18 @@
RECEIVE_PACKET_END(real_packet);
}
-static int send_packet_single_playerlist_reply_100(struct connection *pc,
const struct packet_single_playerlist_reply *packet)
+static int send_packet_game_load_100(struct connection *pc, const struct
packet_game_load *packet)
{
- const struct packet_single_playerlist_reply *real_packet = packet;
- packet_single_playerlist_reply_100_fields fields;
- struct packet_single_playerlist_reply *old, *clone;
+ const struct packet_game_load *real_packet = packet;
+ packet_game_load_100_fields fields;
+ struct packet_game_load *old, *clone;
bool differ, old_from_hash, force_send_of_unchanged = TRUE;
- struct hash_table **hash = &pc->phs.sent[PACKET_SINGLE_PLAYERLIST_REPLY];
+ struct hash_table **hash = &pc->phs.sent[PACKET_GAME_LOAD];
int different = 0;
- SEND_PACKET_START(PACKET_SINGLE_PLAYERLIST_REPLY);
+ SEND_PACKET_START(PACKET_GAME_LOAD);
if (!*hash) {
- *hash = hash_new(hash_packet_single_playerlist_reply_100,
cmp_packet_single_playerlist_reply_100);
+ *hash = hash_new(hash_packet_game_load_100, cmp_packet_game_load_100);
}
BV_CLR_ALL(fields);
@@ -26535,13 +26460,17 @@
force_send_of_unchanged = TRUE;
}
+ differ = (old->load_successful != real_packet->load_successful);
+ if(differ) {different++;}
+ if(packet->load_successful) {BV_SET(fields, 0);}
+
differ = (old->nplayers != real_packet->nplayers);
if(differ) {different++;}
- if(differ) {BV_SET(fields, 0);}
+ if(differ) {BV_SET(fields, 1);}
differ = (strcmp(old->load_filename, real_packet->load_filename) != 0);
if(differ) {different++;}
- if(differ) {BV_SET(fields, 1);}
+ if(differ) {BV_SET(fields, 2);}
{
@@ -26557,7 +26486,7 @@
}
}
if(differ) {different++;}
- if(differ) {BV_SET(fields, 2);}
+ if(differ) {BV_SET(fields, 3);}
{
@@ -26573,7 +26502,7 @@
}
}
if(differ) {different++;}
- if(differ) {BV_SET(fields, 3);}
+ if(differ) {BV_SET(fields, 4);}
{
@@ -26589,7 +26518,7 @@
}
}
if(differ) {different++;}
- if(differ) {BV_SET(fields, 4);}
+ if(differ) {BV_SET(fields, 5);}
{
@@ -26605,7 +26534,7 @@
}
}
if(differ) {different++;}
- if(differ) {BV_SET(fields, 5);}
+ if(differ) {BV_SET(fields, 6);}
{
@@ -26621,7 +26550,7 @@
}
}
if(differ) {different++;}
- if(differ) {BV_SET(fields, 6);}
+ if(differ) {BV_SET(fields, 7);}
{
@@ -26637,7 +26566,7 @@
}
}
if(differ) {different++;}
- if(differ) {BV_SET(fields, 7);}
+ if(differ) {BV_SET(fields, 8);}
if (different == 0 && !force_send_of_unchanged) {
return 0;
@@ -26645,13 +26574,14 @@
DIO_BV_PUT(&dout, fields);
- if (BV_ISSET(fields, 0)) {
+ /* field 0 is folded into the header */
+ if (BV_ISSET(fields, 1)) {
dio_put_uint8(&dout, real_packet->nplayers);
}
- if (BV_ISSET(fields, 1)) {
+ if (BV_ISSET(fields, 2)) {
dio_put_string(&dout, real_packet->load_filename);
}
- if (BV_ISSET(fields, 2)) {
+ if (BV_ISSET(fields, 3)) {
{
int i;
@@ -26661,7 +26591,7 @@
}
}
}
- if (BV_ISSET(fields, 3)) {
+ if (BV_ISSET(fields, 4)) {
{
int i;
@@ -26671,7 +26601,7 @@
}
}
}
- if (BV_ISSET(fields, 4)) {
+ if (BV_ISSET(fields, 5)) {
{
int i;
@@ -26681,7 +26611,7 @@
}
}
}
- if (BV_ISSET(fields, 5)) {
+ if (BV_ISSET(fields, 6)) {
{
int i;
@@ -26691,7 +26621,7 @@
}
}
}
- if (BV_ISSET(fields, 6)) {
+ if (BV_ISSET(fields, 7)) {
{
int i;
@@ -26701,7 +26631,7 @@
}
}
}
- if (BV_ISSET(fields, 7)) {
+ if (BV_ISSET(fields, 8)) {
{
int i;
@@ -26724,11 +26654,11 @@
SEND_PACKET_END;
}
-static void ensure_valid_variant_packet_single_playerlist_reply(struct
connection *pc)
+static void ensure_valid_variant_packet_game_load(struct connection *pc)
{
int variant = -1;
- if(pc->phs.variant[PACKET_SINGLE_PLAYERLIST_REPLY] != -1) {
+ if(pc->phs.variant[PACKET_GAME_LOAD] != -1) {
return;
}
@@ -26738,10 +26668,10 @@
} else {
die("unknown variant");
}
- pc->phs.variant[PACKET_SINGLE_PLAYERLIST_REPLY] = variant;
+ pc->phs.variant[PACKET_GAME_LOAD] = variant;
}
-struct packet_single_playerlist_reply
*receive_packet_single_playerlist_reply(struct connection *pc, enum packet_type
type)
+struct packet_game_load *receive_packet_game_load(struct connection *pc, enum
packet_type type)
{
if(!pc->used) {
freelog(LOG_ERROR,
@@ -26751,17 +26681,17 @@
}
assert(pc->phs.variant != NULL);
if(is_server) {
- freelog(LOG_ERROR, "Receiving packet_single_playerlist_reply at the
server.");
+ freelog(LOG_ERROR, "Receiving packet_game_load at the server.");
}
- ensure_valid_variant_packet_single_playerlist_reply(pc);
+ ensure_valid_variant_packet_game_load(pc);
- switch(pc->phs.variant[PACKET_SINGLE_PLAYERLIST_REPLY]) {
- case 100: return receive_packet_single_playerlist_reply_100(pc, type);
+ switch(pc->phs.variant[PACKET_GAME_LOAD]) {
+ case 100: return receive_packet_game_load_100(pc, type);
default: die("unknown variant"); return NULL;
}
}
-int send_packet_single_playerlist_reply(struct connection *pc, const struct
packet_single_playerlist_reply *packet)
+int send_packet_game_load(struct connection *pc, const struct packet_game_load
*packet)
{
if(!pc->used) {
freelog(LOG_ERROR,
@@ -26771,16 +26701,23 @@
}
assert(pc->phs.variant != NULL);
if(!is_server) {
- freelog(LOG_ERROR, "Sending packet_single_playerlist_reply from the
client.");
+ freelog(LOG_ERROR, "Sending packet_game_load from the client.");
}
- ensure_valid_variant_packet_single_playerlist_reply(pc);
+ ensure_valid_variant_packet_game_load(pc);
- switch(pc->phs.variant[PACKET_SINGLE_PLAYERLIST_REPLY]) {
- case 100: return send_packet_single_playerlist_reply_100(pc, packet);
+ switch(pc->phs.variant[PACKET_GAME_LOAD]) {
+ case 100: return send_packet_game_load_100(pc, packet);
default: die("unknown variant"); return -1;
}
}
+void lsend_packet_game_load(struct conn_list *dest, const struct
packet_game_load *packet)
+{
+ conn_list_iterate(*dest, pconn) {
+ send_packet_game_load(pconn, packet);
+ } conn_list_iterate_end;
+}
+
#define hash_packet_options_settable_control_100 hash_const
#define cmp_packet_options_settable_control_100 cmp_const
Index: common/packets_gen.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets_gen.h,v
retrieving revision 1.42
diff -u -r1.42 packets_gen.h
--- common/packets_gen.h 6 Sep 2004 02:58:12 -0000 1.42
+++ common/packets_gen.h 6 Sep 2004 07:22:21 -0000
@@ -994,11 +994,8 @@
bool you_have_hack;
};
-struct packet_single_playerlist_req {
- char __dummy; /* to avoid malloc(0); */
-};
-
-struct packet_single_playerlist_reply {
+struct packet_game_load {
+ bool load_successful;
int nplayers;
char load_filename[MAX_LEN_PACKET];
char name[MAX_NUM_PLAYERS][MAX_LEN_NAME];
@@ -1141,8 +1138,7 @@
PACKET_UNIT_LOAD,
PACKET_SINGLE_WANT_HACK_REQ,
PACKET_SINGLE_WANT_HACK_REPLY,
- PACKET_SINGLE_PLAYERLIST_REQ, /* 110 */
- PACKET_SINGLE_PLAYERLIST_REPLY,
+ PACKET_GAME_LOAD = 111,
PACKET_OPTIONS_SETTABLE_CONTROL,
PACKET_OPTIONS_SETTABLE,
PACKET_SELECT_RACES,
@@ -1605,11 +1601,9 @@
int send_packet_single_want_hack_reply(struct connection *pc, const struct
packet_single_want_hack_reply *packet);
int dsend_packet_single_want_hack_reply(struct connection *pc, bool
you_have_hack);
-struct packet_single_playerlist_req
*receive_packet_single_playerlist_req(struct connection *pc, enum packet_type
type);
-int send_packet_single_playerlist_req(struct connection *pc);
-
-struct packet_single_playerlist_reply
*receive_packet_single_playerlist_reply(struct connection *pc, enum packet_type
type);
-int send_packet_single_playerlist_reply(struct connection *pc, const struct
packet_single_playerlist_reply *packet);
+struct packet_game_load *receive_packet_game_load(struct connection *pc, enum
packet_type type);
+int send_packet_game_load(struct connection *pc, const struct packet_game_load
*packet);
+void lsend_packet_game_load(struct conn_list *dest, const struct
packet_game_load *packet);
struct packet_options_settable_control
*receive_packet_options_settable_control(struct connection *pc, enum
packet_type type);
int send_packet_options_settable_control(struct connection *pc, const struct
packet_options_settable_control *packet);
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.319
diff -u -r1.319 plrhand.c
--- server/plrhand.c 27 Aug 2004 17:36:53 -0000 1.319
+++ server/plrhand.c 6 Sep 2004 07:22:21 -0000
@@ -2095,41 +2095,3 @@
send_player_info(pplayer, NULL);
}
-
-/**************************************************************************
- we should only send this packet to a client starting up in cmdlevel hack.
- for now, there's no better place for this to go.
-**************************************************************************/
-void handle_single_playerlist_req(struct connection *pconn)
-{
- int i;
- struct packet_single_playerlist_reply packet;
-
- packet.nplayers = game.nplayers;
-
- sz_strlcpy(packet.load_filename, srvarg.load_filename);
-
- for (i = 0; i < game.nplayers; i++) {
- struct player *pplayer = &game.players[i];
-
- if (game.nation_count && is_barbarian(pplayer)){
- packet.nplayers--;
- continue;
- }
-
- sz_strlcpy(packet.name[i], pplayer->name);
- sz_strlcpy(packet.username[i], pplayer->username);
- if (game.nation_count) {
- 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);
- } else { /* No nations picked */
- sz_strlcpy(packet.nation_name[i], "");
- sz_strlcpy(packet.nation_flag[i], "");
- }
- packet.is_alive[i] = pplayer->is_alive;
- packet.is_ai[i] = pplayer->ai.control;
- }
-
- send_packet_single_playerlist_reply(pconn, &packet);
-}
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.66
diff -u -r1.66 plrhand.h
--- server/plrhand.h 3 Sep 2004 04:22:37 -0000 1.66
+++ server/plrhand.h 6 Sep 2004 07:22:21 -0000
@@ -98,6 +98,4 @@
bool civil_war_triggered(struct player *pplayer);
void civil_war(struct player *pplayer);
-void handle_single_playerlist_req(struct connection *pconn);
-
#endif /* FC__PLRHAND_H */
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.185
diff -u -r1.185 srv_main.c
--- server/srv_main.c 4 Sep 2004 21:25:58 -0000 1.185
+++ server/srv_main.c 6 Sep 2004 07:22:22 -0000
@@ -924,11 +924,6 @@
return TRUE;
}
- if (type == PACKET_SINGLE_PLAYERLIST_REQ) {
- handle_single_playerlist_req(pconn);
- return TRUE;
- }
-
pplayer = pconn->player;
if(!pplayer) {
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.343
diff -u -r1.343 stdinhand.c
--- server/stdinhand.c 4 Sep 2004 20:36:10 -0000 1.343
+++ server/stdinhand.c 6 Sep 2004 07:22:22 -0000
@@ -37,6 +37,7 @@
#include "log.h"
#include "map.h"
#include "mem.h"
+#include "packets.h"
#include "player.h"
#include "registry.h"
#include "shared.h" /* fc__attribute, bool type, etc. */
@@ -797,7 +798,6 @@
return FALSE;
}
-
if ((pplayer=find_player_by_name(arg))) {
cmd_reply(CMD_CREATE, caller, C_BOUNCE,
_("A player already exists by that name."));
@@ -2929,6 +2929,53 @@
}
/**************************************************************************
+ After a /load is completed, a reply is sent to all connections to tell
+ them about the load. This information is used by the conndlg to
+ set up the graphical interface for starting the game.
+**************************************************************************/
+static void send_load_game_reply(bool load_successful)
+{
+ int i;
+ struct packet_game_load packet;
+
+ /* Clear everything to be safe. */
+ memset(&packet, 0, sizeof(packet));
+
+ sz_strlcpy(packet.load_filename, srvarg.load_filename);
+ packet.load_successful = load_successful;
+
+ if (load_successful) {
+ packet.nplayers = game.nplayers;
+
+ for (i = 0; i < game.nplayers; i++) {
+ struct player *pplayer = &game.players[i];
+
+ if (game.nation_count && is_barbarian(pplayer)){
+ packet.nplayers--;
+ continue;
+ }
+
+ sz_strlcpy(packet.name[i], pplayer->name);
+ sz_strlcpy(packet.username[i], pplayer->username);
+ if (game.nation_count) {
+ 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);
+ } else { /* No nations picked */
+ sz_strlcpy(packet.nation_name[i], "");
+ sz_strlcpy(packet.nation_flag[i], "");
+ }
+ packet.is_alive[i] = pplayer->is_alive;
+ packet.is_ai[i] = pplayer->ai.control;
+ }
+ } else {
+ packet.nplayers = 0;
+ }
+
+ lsend_packet_game_load(&game.est_connections, &packet);
+}
+
+/**************************************************************************
...
**************************************************************************/
bool load_command(struct connection *caller, char *arg, bool check)
@@ -2938,12 +2985,14 @@
if (!arg || arg[0] == '\0') {
cmd_reply(CMD_LOAD, caller, C_FAIL, _("Usage: load <filename>"));
+ send_load_game_reply(FALSE);
return FALSE;
}
if (server_state != PRE_GAME_STATE) {
cmd_reply(CMD_LOAD, caller, C_FAIL, _("Can't load a game while another "
"is running."));
+ send_load_game_reply(FALSE);
return FALSE;
}
@@ -2951,6 +3000,7 @@
if (!section_file_load_nodup(&file, arg)) {
cmd_reply(CMD_LOAD, caller, C_FAIL, _("Couldn't load savefile: %s"), arg);
+ send_load_game_reply(FALSE);
return FALSE;
}
@@ -2978,6 +3028,9 @@
sanity_check();
+ /* Everything seemed to load ok; spread the good news. */
+ send_load_game_reply(TRUE);
+
/* attach connections to players. currently, this applies only
* to connections that have the correct username. Any attachments
* made before the game load are unattached. */
|
|