From d047c30275990f098bafa8cf3acc15d7fd8f5c9f Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Tue, 7 Mar 2006 18:24:12 +0000 Subject: Store the reason when a connection is disconnected, and display a message indicating when clients time out from the server. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 412 --- src/net_common.c | 10 +++++++++- src/net_common.h | 21 ++++++++++++++++++++- src/net_server.c | 11 ++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/net_common.c b/src/net_common.c index 0318df7a..396cdbed 100644 --- a/src/net_common.c +++ b/src/net_common.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_common.c 411 2006-03-07 12:57:52Z fraggle $ +// $Id: net_common.c 412 2006-03-07 18:24:12Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -158,6 +158,7 @@ static void NET_Conn_ParseDisconnect(net_connection_t *conn, net_packet_t *packe conn->last_send_time = I_GetTimeMS(); conn->state = NET_CONN_STATE_DISCONNECTED_SLEEP; + conn->disconnect_reason = NET_DISCONNECT_REMOTE; } // Parse a DISCONNECT_ACK packet @@ -172,6 +173,7 @@ static void NET_Conn_ParseDisconnectACK(net_connection_t *conn, // request. We have been disconnected successfully. conn->state = NET_CONN_STATE_DISCONNECTED; + conn->disconnect_reason = NET_DISCONNECT_LOCAL; conn->last_send_time = -1; } } @@ -192,6 +194,7 @@ static void NET_Conn_ParseReject(net_connection_t *conn, net_packet_t *packet) // rejected by server conn->state = NET_CONN_STATE_DISCONNECTED; + conn->disconnect_reason = NET_DISCONNECT_REMOTE; printf("Rejected by server: "); NET_SafePuts(msg); @@ -346,6 +349,7 @@ void NET_Conn_Disconnect(net_connection_t *conn) && conn->state != NET_CONN_STATE_DISCONNECTED_SLEEP) { conn->state = NET_CONN_STATE_DISCONNECTING; + conn->disconnect_reason = NET_DISCONNECT_LOCAL; conn->last_send_time = -1; conn->num_retries = 0; } @@ -368,6 +372,7 @@ void NET_Conn_Run(net_connection_t *conn) // time. Assume disconnected. conn->state = NET_CONN_STATE_DISCONNECTED; + conn->disconnect_reason = NET_DISCONNECT_TIMEOUT; } if (nowtime - conn->keepalive_send_time > KEEPALIVE_PERIOD * 1000) @@ -421,6 +426,7 @@ void NET_Conn_Run(net_connection_t *conn) // no more retries allowed. conn->state = NET_CONN_STATE_DISCONNECTED; + conn->disconnect_reason = NET_DISCONNECT_TIMEOUT; } } } @@ -452,6 +458,7 @@ void NET_Conn_Run(net_connection_t *conn) // Force disconnect. conn->state = NET_CONN_STATE_DISCONNECTED; + conn->disconnect_reason = NET_DISCONNECT_LOCAL; } } } @@ -465,6 +472,7 @@ void NET_Conn_Run(net_connection_t *conn) // Idle for 5 seconds, switch state conn->state = NET_CONN_STATE_DISCONNECTED; + conn->disconnect_reason = NET_DISCONNECT_REMOTE; } } } diff --git a/src/net_common.h b/src/net_common.h index af68157c..973a66e6 100644 --- a/src/net_common.h +++ b/src/net_common.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_common.h 411 2006-03-07 12:57:52Z fraggle $ +// $Id: net_common.h 412 2006-03-07 18:24:12Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -84,6 +84,24 @@ typedef enum } net_connstate_t; +// Reason a connection was terminated + +typedef enum +{ + // As the result of a local disconnect request + + NET_DISCONNECT_LOCAL, + + // As the result of a remote disconnect request + + NET_DISCONNECT_REMOTE, + + // Timeout (no data received in a long time) + + NET_DISCONNECT_TIMEOUT, + +} net_disconnect_reason_t; + #define MAX_RETRIES 5 typedef struct net_reliable_packet_s net_reliable_packet_t; @@ -91,6 +109,7 @@ typedef struct net_reliable_packet_s net_reliable_packet_t; typedef struct { net_connstate_t state; + net_disconnect_reason_t disconnect_reason; net_addr_t *addr; int last_send_time; int num_retries; diff --git a/src/net_server.c b/src/net_server.c index 4fb91d6e..773aea96 100644 --- a/src/net_server.c +++ b/src/net_server.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_server.c 410 2006-03-07 12:46:52Z fraggle $ +// $Id: net_server.c 412 2006-03-07 18:24:12Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -300,6 +300,8 @@ static void NET_SV_BroadcastMessage(char *s, ...) NET_SV_SendConsoleMessage(&clients[i], buf); } } + + NET_SafePuts(buf); } @@ -1235,6 +1237,13 @@ static void NET_SV_RunClient(net_client_t *client) NET_Conn_Run(&client->connection); + if (client->connection.state == NET_CONN_STATE_DISCONNECTED + && client->connection.disconnect_reason == NET_DISCONNECT_TIMEOUT) + { + NET_SV_BroadcastMessage("Client '%s' timed out and disconnected", + client->name); + } + // Is this client disconnected? if (client->connection.state == NET_CONN_STATE_DISCONNECTED) -- cgit v1.2.3