diff -ruN -X freeciv/diff_ignore freeciv.patched/client/civclient.c freeciv.mod/client/civclient.c --- freeciv.patched/client/civclient.c Mon Jan 15 01:02:30 2001 +++ freeciv.mod/client/civclient.c Mon Jan 15 01:07:50 2001 @@ -37,6 +37,7 @@ #include "rand.h" #include "support.h" #include "version.h" +#include "result.h" #include "chatline_g.h" #include "citydlg_g.h" @@ -412,11 +413,15 @@ send_packet_unit_info(&aconnection, &info); } +#define TEST_WAITNG /************************************************************************** ... **************************************************************************/ void send_move_unit(struct unit *punit) { +#ifdef TEST_WAITNG + send_move_unit_and_wait_for_result(punit); +#else struct packet_move_unit move; move.unid = punit->id; @@ -430,7 +435,38 @@ #endif send_packet_move_unit(&aconnection, &move); +#endif } + +/************************************************************************** +... +**************************************************************************/ +enum result send_move_unit_and_wait_for_result(struct unit *punit) +{ + struct packet_move_unit move; + char *packet; + enum result result; + + move.unid = punit->id; + move.x = punit->x; + move.y = punit->y; + move.dry_run = FALSE; + move.report_result = TRUE; + + send_packet_move_unit(&aconnection, &move); + + input_from_server2(aconnection.sock, PACKET_RESULT, &packet); + + result=handle_result((struct packet_generic_integer *)packet); + + /* from handle_packet_input() */ + free(packet); + + freelog(LOG_NORMAL, "send_move_unit_and_wait_for_result: result %d", + result); + return result; +} + /************************************************************************** ... **************************************************************************/ diff -ruN -X freeciv/diff_ignore freeciv.patched/client/civclient.h freeciv.mod/client/civclient.h --- freeciv.patched/client/civclient.h Mon Jan 15 01:02:30 2001 +++ freeciv.mod/client/civclient.h Mon Jan 15 00:39:25 2001 @@ -23,6 +23,7 @@ void send_unit_info(struct unit *punit); void send_move_unit(struct unit *punit); +enum result send_move_unit_and_wait_for_result(struct unit *punit); void send_report_request(enum report_type type); void user_ended_turn(void); diff -ruN -X freeciv/diff_ignore freeciv.patched/client/clinet.c freeciv.mod/client/clinet.c --- freeciv.patched/client/clinet.c Tue Jan 2 02:11:30 2001 +++ freeciv.mod/client/clinet.c Mon Jan 15 00:55:34 2001 @@ -188,7 +188,7 @@ **************************************************************************/ void input_from_server(int fid) { - if(read_socket_data(fid, aconnection.buffer)>=0) { + if (read_socket_data(fid, aconnection.buffer) >= 0) { int type, result; char *packet; @@ -200,12 +200,41 @@ break; } } - } - else { + } else { close_socket_callback(&aconnection); } } +/************************************************************************** + This function is called when the client received a + new input from the server +**************************************************************************/ +void input_from_server2(int fid, int stop_type, char **packet_store) +{ + while (1) { + if (read_socket_data(fid, aconnection.buffer) >= 0) { + int type, result; + char *packet; + + while (1) { + packet = get_packet_from_connection(&aconnection, &type, &result); + if (result) { + printf("expecting packet %d got %d at %p\n", + stop_type, type, packet); + if (type == stop_type) { + *packet_store = packet; + return; + } + handle_packet_input(packet, type); + } else { + break; + } + } + } else { + close_socket_callback(&aconnection); + } + } +} #define SPECLIST_TAG server #define SPECLIST_TYPE struct server diff -ruN -X freeciv/diff_ignore freeciv.patched/client/clinet.h freeciv.mod/client/clinet.h --- freeciv.patched/client/clinet.h Sun Jan 2 12:55:22 2000 +++ freeciv.mod/client/clinet.h Mon Jan 15 00:56:36 2001 @@ -20,7 +20,8 @@ int connect_to_server(char *name, char *hostname, int port, char *errbuf, int n_errbuf); -void input_from_server(int fd); +void input_from_server(int fid); +void input_from_server2(int fid, int stop_type, char **packet_store); void disconnect_from_server(void); extern struct connection aconnection; diff -ruN -X freeciv/diff_ignore freeciv.patched/client/packhand.c freeciv.mod/client/packhand.c --- freeciv.patched/client/packhand.c Mon Jan 15 01:02:30 2001 +++ freeciv.mod/client/packhand.c Mon Jan 15 00:36:38 2001 @@ -2169,7 +2169,7 @@ /************************************************************************** ... **************************************************************************/ -void handle_result(struct packet_generic_integer *packet) +enum result handle_result(struct packet_generic_integer *packet) { #ifdef PROFILE_RESULTS enum result result = packet->value; @@ -2183,13 +2183,14 @@ for (i = 0; i < R_LAST; i++) if (counts[i] > 0) { - int promille = (counts[i] * 1000) / total; + int permille = (counts[i] * 1000) / total; freelog(LOG_DEBUG, "%4d/%4d = %3d.%d%% for %2d '%s'", - counts[i], total, promille / 10, promille % 10, + counts[i], total, permille / 10, permille % 10, i, get_result_string(i)); } } #endif - freelog(LOG_DEBUG, "Got result %d", packet->value); + freelog(LOG_NORMAL, "handle_result: result %d", packet->value); + return packet->value; } diff -ruN -X freeciv/diff_ignore freeciv.patched/client/packhand.h freeciv.mod/client/packhand.h --- freeciv.patched/client/packhand.h Mon Jan 15 01:02:30 2001 +++ freeciv.mod/client/packhand.h Mon Jan 15 00:41:55 2001 @@ -58,6 +58,6 @@ void handle_ruleset_game(struct packet_ruleset_game *packet); void handle_diplomat_action(struct packet_diplomat_action *packet); void handle_sabotage_list(struct packet_sabotage_list *packet); -void handle_result(struct packet_generic_integer *packet); +enum result handle_result(struct packet_generic_integer *packet); #endif /* FC__PACKHAND_H */