? ddddd ? dipls.gz ? ideee ? ping.diff ? ping10-timing.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 ? server/.sernet.c.swp 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/11/01 21:38:28 @@ -418,13 +418,14 @@ case PACKET_ADVANCE_FOCUS: handle_advance_focus((struct packet_generic_integer *)packet); break; - + case PACKET_CONN_INFO: handle_conn_info((struct packet_conn_info *)packet); break; - + case PACKET_CONN_PING: send_packet_generic_empty(&aconnection, PACKET_CONN_PONG); + handle_ping_packet((struct packet_ping_packet *) packet); break; case PACKET_SELECT_NATION_OK: Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.257 diff -u -r1.257 packhand.c --- client/packhand.c 2002/11/01 17:51:12 1.257 +++ client/packhand.c 2002/11/01 21:38:30 @@ -1312,6 +1312,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/11/01 21:38:30 @@ -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/11/01 21:38:30 @@ -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.23 diff -u -r1.23 connection.h --- common/connection.h 2002/10/30 22:34:03 1.23 +++ common/connection.h 2002/11/01 21:38:30 @@ -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/11/01 21:38:31 @@ -655,6 +655,8 @@ game.netwait = GAME_DEFAULT_NETWAIT; game.last_ping = 0; game.pingtimeout = GAME_DEFAULT_PINGTIMEOUT; + game.pingclientevery=20; + game.ping_seq_nbr = 0; 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/11/01 21:38:31 @@ -70,6 +70,8 @@ int netwait; time_t last_ping; int pingtimeout; + int pingclientevery; + int ping_seq_nbr; 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/11/01 21:38:32 @@ -295,6 +295,7 @@ return receive_packet_generic_message(pc); case PACKET_CONN_PING: + return receive_packet_ping(pc); case PACKET_CONN_PONG: case PACKET_BEFORE_NEW_YEAR: case PACKET_PROCESSING_STARTED: @@ -803,6 +804,57 @@ 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_CONN_PING); + conn_list_iterate(game.game_connections, pconn) { + if (!pconn->used) continue; + i++; + } conn_list_iterate_end; + dio_put_uint8(&dout,game.ping_seq_nbr%128); + 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->seq_nbr); + 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/11/01 21:38:33 @@ -465,6 +465,7 @@ int city_style; int nation; bool turn_done; + int ping_time; int nturns_idle; bool is_alive; int reputation; @@ -503,6 +504,17 @@ char capability[MAX_LEN_CAPSTR]; }; +/*************** + Ping packet +***************/ +struct packet_ping { + int seq_nbr; + 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 +948,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.84 diff -u -r1.84 player.h --- common/player.h 2002/11/01 17:40:46 1.84 +++ common/player.h 2002/11/01 21:38:33 @@ -162,6 +162,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/11/01 21:38:33 @@ -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/11/01 21:38:33 @@ -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/11/01 21:38:36 @@ -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,24 +394,33 @@ } } - /* send PACKET_CONN_PING & cut mute players */ - if ((time(NULL)>game.last_ping + game.pingtimeout)) { + /* Pinging around for statistics*/ + if ((time(NULL)>(game.last_ping + game.pingtimeout/game.pingclientevery*(game.ping_seq_nbr%game.pingclientevery)))) { for(i=0; iused) { - send_packet_generic_empty(pconn, PACKET_CONN_PING); - - if (pconn->ponged) { - pconn->ponged = FALSE; - } else { - freelog(LOG_NORMAL, "cut connection %s due to ping timeout", - conn_description(pconn)); - close_socket_callback(pconn); - } + 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); + /* cut mute players */ + if (!(game.ping_seq_nbr%game.pingclientevery)) { + if (pconn->ponged) { + pconn->ponged = FALSE; + } else { + freelog(LOG_NORMAL, "cut connection %s due to ping timeout", + conn_description(pconn)); + close_socket_callback(pconn); + } + } + ping_connection(pconn); } } + if (!(game.ping_seq_nbr%game.pingclientevery)) game.last_ping = time(NULL); - } + + game.ping_seq_nbr++; + } /* Don't wait if timeout == -1 (i.e. on auto games) */ if (server_state != PRE_GAME_STATE && game.timeout == -1) { @@ -819,3 +830,25 @@ send_packet_generic_empty(pconn, PACKET_PROCESSING_FINISHED); pconn->server.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); + freelog(LOG_VERBOSE,"Ping time is: %d", (int)read_timer_useconds(pconn->ping_timer)/10); + +} + 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/11/01 21:38:36 @@ -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/11/01 21:38:36 @@ -859,6 +859,7 @@ break; case PACKET_CONN_PONG: pconn->ponged = TRUE; + pong_connection(pconn); break; case PACKET_UNIT_AIRLIFT: handle_unit_airlift(pplayer, (struct packet_unit_request *)packet);