? ddddd ? dipls.gz ? ideee ? ping.diff ? ping2.diff ? ping3-broken.diff ? ping4.diff ? ping5.diff ? ping6-timing.diff ? ping7.diff ? ping8-timing.diff ? ping9-timing.diff ? reaction-time.diff ? reaction-time2.diff ? schnelldipl ? unter.diff Index: client/civclient.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v retrieving revision 1.149 diff -u -r1.149 civclient.c --- client/civclient.c 2002/10/09 13:39:47 1.149 +++ client/civclient.c 2002/10/29 14:44:26 @@ -427,6 +427,11 @@ send_packet_generic_empty(&aconnection, PACKET_CONN_PONG); break; + case PACKET_PING: + send_packet_generic_empty(&aconnection, PACKET_PONG); + handle_ping_packet((struct packet_ping_packet *) packet); + break; + case PACKET_SELECT_NATION_OK: handle_select_nation(NULL); break; Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.256 diff -u -r1.256 packhand.c --- client/packhand.c 2002/09/23 22:47:09 1.256 +++ client/packhand.c 2002/10/29 14:44:27 @@ -1311,6 +1311,21 @@ update_players_dialog(); } +/************************************************************************* +... +**************************************************************************/ +void handle_ping_packet(struct packet_ping *packet) +{ + int i; + freelog(LOG_VERBOSE,"connections: %d",packet->connections); + for (i=0; i < packet->connections; i++ ){ + freelog(LOG_VERBOSE,"id: %d, player_no: %d, ping %d", + packet->id[i],packet->player_num[i], packet->ping_time[i]); + game.players[packet->player_num[i]].ping_time=packet->ping_time[i]; + } + update_players_dialog(); +} + /************************************************************************** Ideally the client should let the player choose which type of modules and components to build, and (possibly) where to extend Index: client/packhand.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.h,v retrieving revision 1.29 diff -u -r1.29 packhand.h --- client/packhand.h 2002/09/10 14:01:06 1.29 +++ client/packhand.h 2002/10/29 14:44:27 @@ -20,6 +20,7 @@ void handle_tile_info(struct packet_tile_info *packet); void handle_player_info(struct packet_player_info *pinfo); void handle_conn_info(struct packet_conn_info *pinfo); +void handle_ping_packet(struct packet_ping *packet); void handle_game_info(struct packet_game_info *pinfo); void handle_map_info(struct packet_map_info *pinfo); void handle_select_nation(struct packet_nations_used *packet); Index: client/gui-gtk/plrdlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/plrdlg.c,v retrieving revision 1.37 diff -u -r1.37 plrdlg.c --- client/gui-gtk/plrdlg.c 2002/08/08 22:10:18 1.37 +++ client/gui-gtk/plrdlg.c 2002/10/29 14:44:28 @@ -70,7 +70,7 @@ static void players_list_ucallback(GtkWidget *w, gint row, gint column); static void players_sship_callback(GtkWidget *w, gpointer data); -#define NUM_COLUMNS 11 /* number of columns in total */ +#define NUM_COLUMNS 12 /* number of columns in total */ #define DEF_SORT_COLUMN 2 /* default sort column (1 = nation) */ /**************************************************************** @@ -122,7 +122,7 @@ static gchar *titles_[NUM_COLUMNS] = { N_("Name"), N_("Flag"), N_("Nation"), N_("Ai"), N_("Embassy"), N_("Dipl.State"), N_("Vision"), N_("Reputation"), - N_("State"), N_("Host"), N_("Idle") + N_("State"), N_("Host"), N_("Idle"), N_("Ping") }; static gchar **titles; int i; @@ -247,7 +247,7 @@ static void build_row(char **row, int i, int update) { static char namebuf[MAX_LEN_NAME], flagbuf[1], aibuf[2], dsbuf[32], - repbuf[32], statebuf[32], idlebuf[32]; + repbuf[32], statebuf[32], idlebuf[32], pingbuf[32]; const struct player_diplstate *pds; /* we cassume that neither name nor the nation of a player changes */ @@ -306,6 +306,12 @@ idlebuf[0] = '\0'; } + /* text for ping */ + if (game.players[i].is_connected) { + my_snprintf(pingbuf, sizeof(pingbuf)," %6d.%02d ms", game.players[i].ping_time/100, game.players[i].ping_time%100); + } else { + pingbuf[0] = '\0'; + } /* text for reputation */ my_snprintf(repbuf, sizeof(repbuf), reputation_text(game.players[i].reputation)); @@ -319,6 +325,7 @@ row[8] = statebuf; row[9] = (char *) player_addr_hack(&game.players[i]); /* Fixme */ row[10] = idlebuf; + row[11] = pingbuf; } #define MIN_DIMENSION 5 Index: common/connection.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/connection.h,v retrieving revision 1.22 diff -u -r1.22 connection.h --- common/connection.h 2002/08/07 11:21:45 1.22 +++ common/connection.h 2002/10/29 14:44:28 @@ -98,6 +98,9 @@ time_t last_write; bool ponged; /* have received a PACKET_CONN_PONG? */ + struct timer *ping_timer; + int ping_time; + struct conn_list self; /* list with this connection as single element */ char name[MAX_LEN_NAME]; char addr[MAX_LEN_ADDR]; Index: common/game.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.c,v retrieving revision 1.149 diff -u -r1.149 game.c --- common/game.c 2002/10/17 08:35:32 1.149 +++ common/game.c 2002/10/29 14:44:28 @@ -655,6 +655,8 @@ game.netwait = GAME_DEFAULT_NETWAIT; game.last_ping = 0; game.pingtimeout = GAME_DEFAULT_PINGTIMEOUT; + game.last_conn_ping= 0; + game.pingclientevery=2; game.end_year = GAME_DEFAULT_END_YEAR; game.year = GAME_START_YEAR; game.turn = 0; Index: common/game.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.h,v retrieving revision 1.114 diff -u -r1.114 game.h --- common/game.h 2002/09/25 00:58:11 1.114 +++ common/game.h 2002/10/29 14:44:28 @@ -70,6 +70,8 @@ int netwait; time_t last_ping; int pingtimeout; + time_t last_conn_ping; + int pingclientevery; time_t turn_start; int end_year; int year; Index: common/packets.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v retrieving revision 1.220 diff -u -r1.220 packets.c --- common/packets.c 2002/10/27 22:42:18 1.220 +++ common/packets.c 2002/10/29 14:44:30 @@ -294,6 +294,9 @@ case PACKET_TURN_DONE: return receive_packet_generic_message(pc); + case PACKET_PING: + return receive_packet_ping(pc); + case PACKET_PONG: case PACKET_CONN_PING: case PACKET_CONN_PONG: case PACKET_BEFORE_NEW_YEAR: @@ -803,6 +806,55 @@ dio_get_string(&din, preq->name, sizeof(preq->name)); RECEIVE_PACKET_END(preq); +} + +/************************************************************************* +This is the ping packet +**************************************************************************/ +int send_packet_ping_player(struct connection *pc) +{ + int i=0; + + SEND_PACKET_START(PACKET_PING); + conn_list_iterate(game.game_connections, pconn) { + if (!pconn->used) continue; + i++; + } conn_list_iterate_end; + dio_put_uint8(&dout,i); + freelog(LOG_VERBOSE,"Number of connections: %d",i); + conn_list_iterate(game.game_connections, pconn) { + struct player *pplayer = pconn->player; + if (!pconn->used) continue; + freelog(LOG_VERBOSE,"id: %d, pl_nr: %d ping_time: %d", + pconn->id,pplayer->player_no,pconn->ping_time); + dio_put_uint8(&dout,pconn->id); + dio_put_uint8(&dout,pplayer->player_no); + dio_put_uint32(&dout,pconn->ping_time); + } + conn_list_iterate_end; + + SEND_PACKET_END; +} + +/************************************************************************* +... +**************************************************************************/ + +struct packet_ping *receive_packet_ping(struct connection *pc) +{ + int i; + RECEIVE_PACKET_START(packet_ping,packet); + dio_get_uint8(&din,&packet->connections); + for (i = 0; i < packet->connections; i++) { + dio_get_uint8(&din,&packet->id[i]); + dio_get_uint8(&din,&packet->player_num[i]); + dio_get_uint32(&din,&packet->ping_time[i]); + freelog(LOG_VERBOSE,"id: %d ", packet->id[i]); + freelog(LOG_VERBOSE,"player_num: %d ", packet->player_num[i]); + freelog(LOG_VERBOSE,"ping_time: %d",packet->ping_time[i]); + } + + RECEIVE_PACKET_END(packet); } /************************************************************************* Index: common/packets.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v retrieving revision 1.126 diff -u -r1.126 packets.h --- common/packets.h 2002/10/19 04:02:07 1.126 +++ common/packets.h 2002/10/29 14:44:30 @@ -128,6 +128,8 @@ PACKET_SELECT_NATION_OK, PACKET_FREEZE_HINT, PACKET_THAW_HINT, + PACKET_PING, + PACKET_PONG, PACKET_LAST /* leave this last */ }; @@ -465,6 +467,7 @@ int city_style; int nation; bool turn_done; + int ping_time; int nturns_idle; bool is_alive; int reputation; @@ -503,6 +506,16 @@ char capability[MAX_LEN_CAPSTR]; }; +/*************** + Ping packet +***************/ +struct packet_ping { + int connections; + int id[MAX_NUM_PLAYERS]; + int player_num[MAX_NUM_PLAYERS]; + int ping_time[MAX_NUM_PLAYERS]; +}; + /********************************************************* The server tells the client all about a spaceship: *********************************************************/ @@ -936,6 +949,9 @@ int send_packet_game_info(struct connection *pc, const struct packet_game_info *pinfo); struct packet_game_info *receive_packet_game_info(struct connection *pc); + +int send_packet_ping_player(struct connection *pc); +struct packet_ping *receive_packet_ping(struct connection *pc); struct packet_player_info *receive_packet_player_info(struct connection *pc); Index: common/player.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/player.h,v retrieving revision 1.82 diff -u -r1.82 player.h --- common/player.h 2002/09/23 22:47:10 1.82 +++ common/player.h 2002/10/29 14:44:30 @@ -161,6 +161,7 @@ int government; Nation_Type_id nation; bool turn_done; + int ping_time; int nturns_idle; bool is_alive; bool got_tech; Index: common/timing.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/timing.c,v retrieving revision 1.10 diff -u -r1.10 timing.c --- common/timing.c 2002/02/14 15:17:20 1.10 +++ common/timing.c 2002/10/29 14:44:30 @@ -357,6 +357,27 @@ } /********************************************************************** + Read value from timer. If the timer is not stopped, this stops the + timer, reads it (and accumulates), and then restarts it. + Returns 0 for unused timers. +***********************************************************************/ + +long read_timer_useconds(struct timer *t) +{ + assert(t != NULL); + if (t->use == TIMER_IGNORE) { + return 0; + } + if (t->state == TIMER_STARTED) { + stop_timer(t); + t->state = TIMER_STARTED; + } + return (long)(t->sec*N_USEC_PER_SEC) + t->usec; + +} + + +/********************************************************************** Read the timer, then free it. This is intended to be useful for a simple one-off timing, eg: { @@ -373,6 +394,14 @@ free_timer(t); return val; } + +long read_timer_useconds_free(struct timer *t) +{ + long val = read_timer_useconds(t); + free_timer(t); + return val; +} + /********************************************************************** Sleeps until the given number of microseconds have elapsed since the Index: common/timing.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/timing.h,v retrieving revision 1.4 diff -u -r1.4 timing.h --- common/timing.h 2002/04/12 13:50:57 1.4 +++ common/timing.h 2002/10/29 14:44:30 @@ -62,6 +62,9 @@ double read_timer_seconds(struct timer *t); double read_timer_seconds_free(struct timer *t); +long read_timer_useconds(struct timer *t); +long read_timer_useconds_free(struct timer *t); + void usleep_since_timer_start(struct timer *t, long usec); void usleep_since_timer_start_free(struct timer *t, long usec); Index: server/sernet.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v retrieving revision 1.96 diff -u -r1.96 sernet.c --- server/sernet.c 2002/10/18 09:58:49 1.96 +++ server/sernet.c 2002/10/29 14:44:31 @@ -75,6 +75,7 @@ #include "meta.h" #include "srv_main.h" #include "stdinhand.h" +#include "timing.h" #include "sernet.h" @@ -111,6 +112,7 @@ static void start_processing_request(struct connection *pconn, int request_id); static void finish_processing_request(struct connection *pconn); +static void ping_connection(struct connection *pconn); static bool no_input = FALSE; @@ -392,6 +394,21 @@ } } + /* Pinging around for statistics*/ + if ((time(NULL)>game.last_conn_ping + game.pingclientevery)) { + for(i=0; iused) { + if(pconn->ping_timer) + pconn->ping_time=read_timer_useconds(pconn->ping_timer)/10; + else + pconn->ping_timer=new_timer_start(TIMER_USER, TIMER_ACTIVE); + + ping_connection(pconn); + } + } + game.last_conn_ping = time(NULL); + } /* send PACKET_CONN_PING & cut mute players */ if ((time(NULL)>game.last_ping + game.pingtimeout)) { for(i=0; iserver.currently_processed_request_id = 0; } + +/************************************************************************** +This is the ping function +**************************************************************************/ + +static void ping_connection(struct connection *pconn) +{ + clear_timer_start(pconn->ping_timer); + send_packet_ping_player(pconn); +} + +/************************************************************************** +This is the pong function +**************************************************************************/ + +void pong_connection(struct connection *pconn) +{ + stop_timer(pconn->ping_timer); +} + Index: server/sernet.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/sernet.h,v retrieving revision 1.7 diff -u -r1.7 sernet.h --- server/sernet.h 2000/09/18 20:36:15 1.7 +++ server/sernet.h 2002/10/29 14:44:31 @@ -25,5 +25,5 @@ void close_connections_and_socket(void); void init_connections(void); void close_connection(struct connection *pconn); - +void pong_connection(struct connection *pconn); #endif /* FC__SERNET_H */ Index: server/srv_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v retrieving revision 1.98 diff -u -r1.98 srv_main.c --- server/srv_main.c 2002/10/18 09:58:49 1.98 +++ server/srv_main.c 2002/10/29 14:44:32 @@ -656,6 +656,7 @@ && type != PACKET_ALLOC_NATION && type != PACKET_CHAT_MSG && type != PACKET_CONN_PONG + && type != PACKET_PONG && type != PACKET_REPORT_REQUEST) { if (server_state == GAME_OVER_STATE) { /* This can happen by accident, so we don't want to print @@ -859,6 +860,9 @@ break; case PACKET_CONN_PONG: pconn->ponged = TRUE; + break; + case PACKET_PONG: + pong_connection(pconn); break; case PACKET_UNIT_AIRLIFT: handle_unit_airlift(pplayer, (struct packet_unit_request *)packet); Index: server/stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.257 diff -u -r1.257 stdinhand.c --- server/stdinhand.c 2002/10/16 18:40:54 1.257 +++ server/stdinhand.c 2002/10/29 14:44:35 @@ -2922,8 +2922,8 @@ section_file_free(&file); freelog(LOG_VERBOSE, "Load time: %g seconds (%g apparent)", - read_timer_seconds_free(loadtimer), - read_timer_seconds_free(uloadtimer)); + (int)read_timer_seconds_free(loadtimer), + (int)read_timer_seconds_free(uloadtimer)); /* associate players with any connections that may * be present. currently, this applies only to connections