diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/client/civclient.c nationciv/client/civclient.c --- freeciv/client/civclient.c Sat Jan 13 02:10:04 2001 +++ nationciv/client/civclient.c Sun Jan 21 20:58:36 2001 @@ -209,10 +209,6 @@ handle_tile_info((struct packet_tile_info *)packet); break; - case PACKET_SELECT_NATION: - handle_select_nation((struct packet_generic_values *)packet); - break; - case PACKET_PLAYER_INFO: handle_player_info((struct packet_player_info *)packet); break; @@ -361,6 +357,18 @@ handle_conn_info((struct packet_conn_info *)packet); break; + case PACKET_SELECT_NATION: + handle_select_nation((struct packet_generic_integer *)packet); + break; + + case PACKET_NATION_ACCEPTED: + handle_nation_accepted((struct packet_generic_integer *)packet); + break; + + case PACKET_NATIONS_AVAILABLE: + handle_nations_available((struct packet_nations_available *)packet); + break; + default: freelog(LOG_ERROR, "Received unknown packet (type %d) from server!", type); /* Old clients (<= some 1.11.5-devel, capstr +1.11) used to exit() diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/client/gui-gtk/dialogs.c nationciv/client/gui-gtk/dialogs.c --- freeciv/client/gui-gtk/dialogs.c Fri Sep 1 23:05:01 2000 +++ nationciv/client/gui-gtk/dialogs.c Sun Jan 21 20:58:36 2001 @@ -2069,38 +2069,20 @@ /************************************************************************** ... **************************************************************************/ -void races_toggles_set_sensitive(int bits1, int bits2) +void races_toggles_set_sensitive(struct packet_nations_available *p) { - int i, mybits; + int i; - mybits=bits1; - - for(i=0; i>=1; - } - - mybits=bits2; - - for(i=32; itaken[i]) { + gtk_widget_set_sensitive(races_toggles[g_list_index(sorted_races_list, + GINT_TO_POINTER(i))], FALSE); + if (i == selected_nation) select_random_race(); } else { - gtk_widget_set_sensitive( races_toggles[g_list_index(sorted_races_list, - GINT_TO_POINTER(i))], TRUE ); + gtk_widget_set_sensitive(races_toggles[g_list_index(sorted_races_list, + GINT_TO_POINTER(i))], TRUE); } - mybits>>=1; } } diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/client/gui-xaw/dialogs.c nationciv/client/gui-xaw/dialogs.c --- freeciv/client/gui-xaw/dialogs.c Fri Sep 1 23:05:05 2000 +++ nationciv/client/gui-xaw/dialogs.c Sun Jan 21 20:58:36 2001 @@ -2114,23 +2114,20 @@ /************************************************************************** ... **************************************************************************/ -void races_toggles_set_sensitive(int bits1, int bits2) +void races_toggles_set_sensitive(struct packet_nations_available *p) { int i, race, selected; - Boolean sens; for(i=0; i> ((race<32)?race:race-32) )&1 ); - XtSetSensitive(races_toggles[i], sens); + XtSetSensitive(races_toggles[i], !p->taken[race]); } - if((selected=races_buttons_get_current())==-1) + if ((selected=races_buttons_get_current()) == -1) return; - race = races_toggles_to_nations[selected]; - if( (bits1 & (1<32 && (bits2 & (1<<(race-32))) ) ) + race = races_toggles_to_nations[selected]; + if (p->taken[race]) XawToggleUnsetCurrent(races_toggles[0]); } diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/client/include/dialogs_g.h nationciv/client/include/dialogs_g.h --- freeciv/client/include/dialogs_g.h Sun Apr 16 16:35:42 2000 +++ nationciv/client/include/dialogs_g.h Sun Jan 21 20:58:36 2001 @@ -16,6 +16,7 @@ struct tile; struct unit; struct city; +struct packet_nations_available; void popup_notify_goto_dialog(char *headline, char *lines, int x, int y); void popup_notify_dialog(char *caption, char *headline, char *lines); @@ -25,7 +26,7 @@ void popup_unit_select_dialog(struct tile *ptile); -void races_toggles_set_sensitive(int bits1, int bits2); +void races_toggles_set_sensitive(struct packet_nations_available *p); void popup_revolution_dialog(void); void popup_government_dialog(void); diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/client/packhand.c nationciv/client/packhand.c --- freeciv/client/packhand.c Mon Jan 15 01:08:29 2001 +++ nationciv/client/packhand.c Sun Jan 21 21:01:45 2001 @@ -1515,23 +1515,43 @@ /************************************************************************** ... **************************************************************************/ -void handle_select_nation(struct packet_generic_values *packet) +void handle_select_nation(struct packet_generic_integer *packet) { - if(get_client_state()==CLIENT_SELECT_RACE_STATE) { - if(packet->value2 == 0xffff) { + if (get_client_state()==CLIENT_PRE_GAME_STATE) { + set_client_state(CLIENT_SELECT_RACE_STATE); + popup_races_dialog(); + } else if (get_client_state()!= CLIENT_SELECT_RACE_STATE) { + freelog(LOG_ERROR, "Got select nation packet in incompatible client state"); + } +} + +/************************************************************************** +... +**************************************************************************/ +void handle_nation_accepted(struct packet_generic_integer *packet) +{ + if (get_client_state() == CLIENT_SELECT_RACE_STATE) { + if (packet->value) { set_client_state(CLIENT_WAITING_FOR_GAME_START_STATE); popdown_races_dialog(); + } else { /* not accepted */ + /* nothing */ } - else - races_toggles_set_sensitive( packet->value1, packet->value2); + } else { + freelog(LOG_ERROR, "Got nation accepted while not in select race state"); } - else if(get_client_state()==CLIENT_PRE_GAME_STATE) { - set_client_state(CLIENT_SELECT_RACE_STATE); - popup_races_dialog(); - races_toggles_set_sensitive( packet->value1, packet->value2); +} + +/************************************************************************** +... +**************************************************************************/ +void handle_nations_available(struct packet_nations_available *packet) +{ + if (get_client_state()==CLIENT_SELECT_RACE_STATE) { + races_toggles_set_sensitive(packet); + } else { + freelog(LOG_ERROR, "Got nations available packet in wrong client state"); } - else - freelog(LOG_ERROR, "got a select nation packet in an incompatible state"); } /************************************************************************** diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/client/packhand.h nationciv/client/packhand.h --- freeciv/client/packhand.h Sun Aug 27 17:08:13 2000 +++ nationciv/client/packhand.h Sun Jan 21 20:58:37 2001 @@ -22,7 +22,9 @@ void handle_conn_info(struct packet_conn_info *packet); void handle_game_info(struct packet_game_info *packet); void handle_map_info(struct packet_map_info *pinfo); -void handle_select_nation(struct packet_generic_values *packet); +void handle_select_nation(struct packet_generic_integer *packet); +void handle_nation_accepted(struct packet_generic_integer *packet); +void handle_nations_available(struct packet_nations_available *packet); void handle_unit_info(struct packet_unit_info *packet); void handle_chat_msg(struct packet_generic_message *packet); diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/common/capstr.c nationciv/common/capstr.c --- freeciv/common/capstr.c Fri Oct 27 23:42:17 2000 +++ nationciv/common/capstr.c Sun Jan 21 20:58:37 2001 @@ -73,7 +73,7 @@ #define CAPABILITY "+1.11 diplomat_investigate_fix production_change_fix" \ " game_ruleset nuclear_fallout land_channel_requirement event_wonder_obsolete" \ " event00_fix conn_info gen_impr_oversights diplo_move_city packet_short_city" \ -" indef_impr_types worklist_true_ids shared_vision activity_patrol" +" indef_impr_types worklist_true_ids shared_vision activity_patrol +more_nations" /* "+1.11" is protocol for 1.11.0 stable release. @@ -129,6 +129,9 @@ "activity_patrol" is the patrol activity and the ability to send a goto route from the client to the server (for both goto and patrol activities). + + "+more_nations" is raising the hardcoded max number of nation rulesets + that can be used. */ void init_our_capability(void) diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/common/nation.h nationciv/common/nation.h --- freeciv/common/nation.h Sat Mar 4 04:55:27 2000 +++ nationciv/common/nation.h Sun Jan 21 20:58:37 2001 @@ -16,7 +16,7 @@ #include "shared.h" /* MAX_LEN_NAME */ #define MAX_NUM_TECH_GOALS 10 -#define MAX_NUM_NATIONS 63 +#define MAX_NUM_NATIONS 255 #define MAX_NUM_LEADERS 16 typedef int Nation_Type_id; diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/common/packets.c nationciv/common/packets.c --- freeciv/common/packets.c Fri Dec 15 18:43:31 2000 +++ nationciv/common/packets.c Sun Jan 21 20:58:37 2001 @@ -233,9 +233,6 @@ case PACKET_TILE_INFO: return receive_packet_tile_info(pc); - case PACKET_SELECT_NATION: - return receive_packet_generic_values(pc); - case PACKET_REMOVE_UNIT: case PACKET_REMOVE_CITY: case PACKET_GAME_STATE: @@ -363,6 +360,13 @@ case PACKET_PATROL_ROUTE: return receive_packet_goto_route(pc); + case PACKET_SELECT_NATION: + return receive_packet_generic_integer(pc); + case PACKET_NATION_ACCEPTED: + return receive_packet_generic_integer(pc); + case PACKET_NATIONS_AVAILABLE: + return receive_packet_nations_available(pc); + default: freelog(LOG_ERROR, "unknown packet type %d received from %s", type, conn_description(pc)); @@ -4189,4 +4193,59 @@ freelog(LOG_ERROR, "invalid type in receive_packet_goto_route()"); return NULL; } +} + + +/************************************************************************** +... +**************************************************************************/ +int send_packet_nations_available(struct connection *pc, + struct packet_nations_available *packet) +{ + unsigned char buffer[MAX_LEN_PACKET], *cptr; + int count = game.playable_nation_count; + int n_itr = 0; + + cptr = put_uint8(buffer+2, PACKET_NATIONS_AVAILABLE); + + while (n_itr < count) { + unsigned char next8 = 0; + int i; + for (i=0; i<8 && n_itrtaken[n_itr] ? 1 : 0) << i; + n_itr++; + } + cptr = put_uint8(cptr, next8); + } + + put_uint16(buffer, cptr-buffer); + return send_connection_data(pc, buffer, cptr-buffer); +} + +/************************************************************************** +... +**************************************************************************/ +struct packet_nations_available *receive_packet_nations_available(struct connection *pc) +{ + struct pack_iter iter; + struct packet_nations_available *packet = + fc_malloc(sizeof(struct packet_nations_available)); + int count = game.playable_nation_count; + int n_itr = 0; + + pack_iter_init(&iter, pc); + + while (n_itr < count) { + int next8; + int i; + iget_uint8(&iter, &next8); + for (i=0; i<8 && n_itrtaken[n_itr] = next8 & (1<buffer); + return packet; } diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/common/packets.h nationciv/common/packets.h --- freeciv/common/packets.h Fri Oct 27 23:42:18 2000 +++ nationciv/common/packets.h Sun Jan 21 20:58:37 2001 @@ -37,7 +37,6 @@ PACKET_TURN_DONE, PACKET_NEW_YEAR, PACKET_TILE_INFO, - PACKET_SELECT_NATION, PACKET_ALLOC_NATION, PACKET_SHOW_MESSAGE, PACKET_PLAYER_INFO, @@ -115,6 +114,9 @@ PACKET_PLAYER_REMOVE_VISION, PACKET_GOTO_ROUTE, PACKET_PATROL_ROUTE, + PACKET_SELECT_NATION, + PACKET_NATION_ACCEPTED, + PACKET_NATIONS_AVAILABLE, PACKET_LAST /* leave this last */ }; @@ -848,6 +850,11 @@ int unit_id; }; +struct packet_nations_available +{ + char taken[MAX_NUM_NATIONS]; +}; + /* These two are non-static for meta.c; others are now static --dwp */ unsigned char *put_uint16(unsigned char *buffer, int val); unsigned char *put_string(unsigned char *buffer, char *mystring); @@ -1056,6 +1063,10 @@ int send_packet_goto_route(struct connection *pc, struct packet_goto_route *packet, enum goto_route_type type); struct packet_goto_route *receive_packet_goto_route(struct connection *pc); + +int send_packet_nations_available(struct connection *pc, + struct packet_nations_available *packet); +struct packet_nations_available *receive_packet_nations_available(struct connection *pc); #include "packets_lsend.h" /* lsend_packet_* functions */ diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/common/packets_lsend.c nationciv/common/packets_lsend.c --- freeciv/common/packets_lsend.c Mon Oct 30 13:42:08 2000 +++ nationciv/common/packets_lsend.c Sun Jan 21 20:58:51 2001 @@ -352,3 +352,11 @@ conn_list_iterate_end; } +void lsend_packet_nations_available(struct conn_list *dest, + struct packet_nations_available *packet) +{ + conn_list_iterate(*dest, pconn) + send_packet_nations_available(pconn, packet); + conn_list_iterate_end; +} + diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/common/packets_lsend.h nationciv/common/packets_lsend.h --- freeciv/common/packets_lsend.h Mon Oct 30 13:42:08 2000 +++ nationciv/common/packets_lsend.h Sun Jan 21 20:58:51 2001 @@ -99,3 +99,5 @@ struct packet_sabotage_list *packet); void lsend_packet_goto_route(struct conn_list *dest, struct packet_goto_route *packet, enum goto_route_type type); +void lsend_packet_nations_available(struct conn_list *dest, + struct packet_nations_available *packet); diff -Nur -X/data/freeciv-dev/freeciv/diff_ignore freeciv/server/srv_main.c nationciv/server/srv_main.c --- freeciv/server/srv_main.c Sun Jan 21 18:46:54 2001 +++ nationciv/server/srv_main.c Sun Jan 21 20:58:37 2001 @@ -106,8 +106,9 @@ static void handle_request_join_game(struct connection *pconn, struct packet_req_join_game *request); static void handle_turn_done(struct player *pplayer); -static void send_nation_used_info(struct player *pplayer); static void send_select_nation(struct player *pplayer); +static void send_nation_accepted(struct player *pplayer, int accepted); +static void send_nations_available(struct player *pplayer); static void enable_fog_of_war_player(struct player *pplayer); static void disable_fog_of_war_player(struct player *pplayer); static void enable_fog_of_war(void); @@ -299,12 +300,12 @@ * in generate_ai_players() later */ server_state = RUN_GAME_STATE; - for(i=0; ination == MAX_NUM_NATIONS && !pplayer->ai.control) { + send_select_nation(pplayer); server_state = SELECT_RACES_STATE; } - } + } players_iterate_end; while(server_state==SELECT_RACES_STATE) { sniff_packets(); @@ -1170,19 +1171,18 @@ struct packet_alloc_nation *packet) { int i, nation_used_count; - struct packet_generic_values select_nation; remove_leading_trailing_spaces(packet->name); if (strlen(packet->name)==0) { notify_player(pplayer, _("Please choose a non-blank name.")); - send_select_nation(pplayer, 0); + send_nation_accepted(pplayer, 0); return; } for(i=0; ination_no) { - send_select_nation(pplayer, 0); /* it failed - nation taken */ + send_nation_accepted(pplayer, 0); /* it failed - nation taken */ return; } else /* Check to see if name has been taken. @@ -1199,7 +1199,7 @@ notify_player(pplayer, _("Another player already has the name '%s'. " "Please choose another name."), packet->name); - send_select_nation(pplayer, 0); + send_nation_accepted(pplayer, 0); return; } @@ -1207,9 +1207,7 @@ get_nation_name(packet->nation_no), packet->name); /* inform player his choice was ok */ - select_nation.value2=0xffff; - lsend_packet_generic_values(&pplayer->connections, PACKET_SELECT_NATION, - &select_nation); + send_nation_accepted(pplayer, 1); pplayer->nation=packet->nation_no; sz_strlcpy(pplayer->name, packet->name); @@ -1220,7 +1218,7 @@ nation_used_count = 0; for(i=0; iconnections, + PACKET_SELECT_NATION, &select); +} + +/************************************************************************** +Tells player whether his choice was accepted +**************************************************************************/ +static void send_nation_accepted(struct player *pplayer, int accepted) +{ + struct packet_generic_integer accept; + accept.value = accepted; + lsend_packet_generic_integer(&pplayer->connections, + PACKET_NATION_ACCEPTED, &accept); +} + +/************************************************************************** +... +**************************************************************************/ +static void send_nations_available(struct player *pplayer) +{ int i; - struct packet_generic_values select_nation; - - select_nation.value1=0; /* assume int is 32 bit, safe */ - select_nation.value2=0; - - /* set bits in mask corresponding to nations already selected by others */ - for( i=0; ination != MAX_NUM_NATIONS) { + nations.taken[pplayer2->nation] = 1; } + } players_iterate_end; - lsend_packet_generic_values(&pplayer->connections, PACKET_SELECT_NATION, - &select_nation); + lsend_packet_nations_available(&pplayer->connections, &nations); } /**************************************************************************