summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2010-12-04 20:48:07 +0000
committerSimon Howard2010-12-04 20:48:07 +0000
commit3c57887b0a5352da1c7c4fe7f149c94bb6d70c31 (patch)
tree2ff2e80651c3ddf30f40c896a7eb4ce702ce5d7f
parent0194038cac0092499668d849a300eaffaa448421 (diff)
downloadchocolate-doom-3c57887b0a5352da1c7c4fe7f149c94bb6d70c31.tar.gz
chocolate-doom-3c57887b0a5352da1c7c4fe7f149c94bb6d70c31.tar.bz2
chocolate-doom-3c57887b0a5352da1c7c4fe7f149c94bb6d70c31.zip
Add ping time to query output.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2192
-rw-r--r--src/net_query.c18
-rw-r--r--src/net_query.h3
2 files changed, 15 insertions, 6 deletions
diff --git a/src/net_query.c b/src/net_query.c
index 6a934413..265e3804 100644
--- a/src/net_query.c
+++ b/src/net_query.c
@@ -42,11 +42,11 @@
// Time to wait for a response before declaring a timeout.
-#define QUERY_TIMEOUT_SECS 1
+#define QUERY_TIMEOUT_SECS 2
// Number of query attempts to make before giving up on a server.
-#define QUERY_MAX_ATTEMPTS 5
+#define QUERY_MAX_ATTEMPTS 3
typedef enum
{
@@ -69,6 +69,7 @@ typedef struct
query_target_state_t state;
net_addr_t *addr;
net_querydata_t data;
+ unsigned int ping_time;
unsigned int query_time;
unsigned int query_attempts;
boolean printed;
@@ -251,9 +252,13 @@ static void NET_Query_ParseResponse(net_addr_t *addr, net_packet_t *packet,
target->state = QUERY_TARGET_RESPONDED;
memcpy(&target->data, &querydata, sizeof(net_querydata_t));
+ // Calculate RTT.
+
+ target->ping_time = I_GetTimeMS() - target->query_time;
+
// Invoke callback to signal that we have a new address.
- callback(addr, &target->data, user_data);
+ callback(addr, &target->data, target->ping_time, user_data);
}
}
@@ -479,7 +484,7 @@ void NET_Query_Init(void)
// Callback that exits the query loop when the first server is found.
static void NET_Query_ExitCallback(net_addr_t *addr, net_querydata_t *data,
- void *user_data)
+ unsigned int ping_time, void *user_data)
{
NET_Query_ExitLoop();
}
@@ -552,7 +557,7 @@ void NET_QueryAddress(char *addr_str)
if (target->state == QUERY_TARGET_RESPONDED)
{
- NET_QueryPrintCallback(addr, &target->data, NULL);
+ NET_QueryPrintCallback(addr, &target->data, target->ping_time, NULL);
}
else
{
@@ -679,6 +684,7 @@ static void PrintHeader(void)
int i;
putchar('\n');
+ formatted_printf(5, "Ping");
formatted_printf(18, "Address");
formatted_printf(8, "Players");
puts("Description");
@@ -692,6 +698,7 @@ static void PrintHeader(void)
void NET_QueryPrintCallback(net_addr_t *addr,
net_querydata_t *data,
+ unsigned int ping_time,
void *user_data)
{
// If this is the first server, print the header.
@@ -702,6 +709,7 @@ void NET_QueryPrintCallback(net_addr_t *addr,
printed_header = true;
}
+ formatted_printf(5, "%4i", ping_time);
formatted_printf(18, "%s: ", NET_AddrToString(addr));
formatted_printf(8, "%i/%i", data->num_players,
data->max_players);
diff --git a/src/net_query.h b/src/net_query.h
index 98931593..01e059cb 100644
--- a/src/net_query.h
+++ b/src/net_query.h
@@ -29,6 +29,7 @@
typedef void (*net_query_callback_t)(net_addr_t *addr,
net_querydata_t *querydata,
+ unsigned int ping_time,
void *user_data);
extern int NET_LANQuery(net_query_callback_t callback, void *user_data);
@@ -37,7 +38,7 @@ extern void NET_QueryAddress(char *addr);
extern net_addr_t *NET_FindLANServer(void);
extern void NET_QueryPrintCallback(net_addr_t *addr, net_querydata_t *data,
- void *user_data);
+ unsigned int ping_time, void *user_data);
extern net_addr_t *NET_Query_ResolveMaster(net_context_t *context);
extern void NET_Query_AddToMaster(net_addr_t *master_addr);