? dipls.gz ? ideee ? ping.diff ? ping2.diff ? ping3-broken.diff ? ping4.diff ? ping5.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/28 20:22:40 @@ -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/28 20:22:41 @@ -1311,6 +1311,21 @@ update_players_dialog(); } +/************************************************************************* +... +**************************************************************************/ +void handle_ping_packet(struct packet_ping *packet) +{ /* FIXME */ + int i; + freelog(LOG_VERBOBSE,"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/28 20:22:41 @@ -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/28 20:22:42 @@ -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/28 20:22:42 @@ -98,6 +98,9 @@ time_t last_write; bool ponged; /* have received a PACKET_CONN_PONG? */ + struct timeval begin,end; + 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/28 20:22:42 @@ -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/28 20:22:42 @@ -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/28 20:22:44 @@ -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,const struct packet_ping *packet) +{ + 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/28 20:22:44 @@ -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,10 @@ 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, + const struct packet_ping *ping); +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/28 20:22:44 @@ -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: 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/28 20:22:45 @@ -111,6 +111,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 +393,26 @@ } } + /* Pinging around for statistics*/ + if ((time(NULL)>game.last_conn_ping + game.pingclientevery)) { + for(i=0; iused) { + long sec,usec; + sec = pconn->end.tv_sec - pconn->begin.tv_sec; + usec = pconn->end.tv_usec - pconn->begin.tv_usec; + if(usec < 0) { + usec += 1000000; + sec--; + } + pconn->ping_time=sec*100000+usec/10; + freelog(LOG_VERBOSE,"Ping of %d was: %d,%d ms", + pconn->id,pconn->ping_time/100,pconn->ping_time%100); + 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) +{ + if (gettimeofday(&pconn->begin,(struct timezone *)0)) { + freelog(LOG_ERROR, "can not get time\n"); + } + freelog(LOG_VERBOSE,"Ping sent to %d",pconn->id); + freelog(LOG_VERBOSE,"Starting time is : %d sec %d usec\n", + (int)pconn->begin.tv_sec, (int)pconn->begin.tv_usec); + send_packet_ping_player(pconn, PACKET_PING); +} + +/************************************************************************** +This is the pong function +**************************************************************************/ + +void pong_connection(struct connection *pconn) +{ + if (gettimeofday(&pconn->end,(struct timezone *)0)) { + freelog(LOG_ERROR, "can not get time\n"); + } + freelog(LOG_VERBOSE,"Pong recieved from %d",pconn->id); + freelog(LOG_VERBOSE,"Returning time is : %d sec %d usec\n", + (int)pconn->end.tv_sec, (int)pconn->end.tv_usec); +} + 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/28 20:22:45 @@ -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/28 20:22:46 @@ -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);