ref: d047c30275990f098bafa8cf3acc15d7fd8f5c9f
parent: b2a2c312907d214aacaa11f97a217e4a42cfe683
author: Simon Howard <fraggle@gmail.com>
date: Tue Mar 7 13:24:12 EST 2006
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
--- 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 @@
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 @@
// 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 @@
// 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 @@
&& 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 @@
// 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 @@
// no more retries allowed.
conn->state = NET_CONN_STATE_DISCONNECTED;
+ conn->disconnect_reason = NET_DISCONNECT_TIMEOUT;
}
}
}
@@ -452,6 +458,7 @@
// Force disconnect.
conn->state = NET_CONN_STATE_DISCONNECTED;
+ conn->disconnect_reason = NET_DISCONNECT_LOCAL;
}
}
}
@@ -465,6 +472,7 @@
// Idle for 5 seconds, switch state
conn->state = NET_CONN_STATE_DISCONNECTED;
+ conn->disconnect_reason = NET_DISCONNECT_REMOTE;
}
}
}
--- 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 @@
} 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_connstate_t state;
+ net_disconnect_reason_t disconnect_reason;
net_addr_t *addr;
int last_send_time;
int num_retries;
--- 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 @@
NET_SV_SendConsoleMessage(&clients[i], buf);
}
}
+
+ NET_SafePuts(buf);
}
@@ -1234,6 +1236,13 @@
// Run common code
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?