ref: 25ae4973fab0cfffe47fbc8373dae8a8715786d7
parent: 835d92710f1f958b899eb842c556b75fbb809244
author: Simon Howard <[email protected]>
date: Sat Feb 23 11:53:58 EST 2019
net: Display appropriate message on connect failure. Previously, the "reject reason" would not be set if the server simply never responded to the connection attempt. So ensure that an error string of some kind is always set when NET_CL_Connect is called. As part of this, the handling for REJECTED packets has been moved to the client code; only the server only sends such packets, so it makes no sense for it to be in the common code.
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -109,6 +109,9 @@
static net_gamesettings_t settings;
+// Why did the server reject us?
+char *net_client_reject_reason = NULL;
+
// true if the client code is in use
boolean net_client_connected;
@@ -462,6 +465,37 @@
}
}
+static void SetRejectReason(const char *s)
+{
+ free(net_client_reject_reason);
+ if (s != NULL)
+ {
+ net_client_reject_reason = strdup(s);
+ }
+ else
+ {
+ net_client_reject_reason = NULL;
+ }
+}
+
+static void NET_CL_ParseReject(net_packet_t *packet)
+{
+ char *msg;
+
+ msg = NET_ReadSafeString(packet);
+ if (msg == NULL)
+ {
+ return;
+ }
+
+ if (client_connection.state == NET_CONN_STATE_CONNECTING)
+ {
+ client_connection.state = NET_CONN_STATE_DISCONNECTED;
+ client_connection.disconnect_reason = NET_DISCONNECT_REMOTE;
+ SetRejectReason(msg);
+ }
+}
+
// data received while we are waiting for the game to start
static void NET_CL_ParseWaitingData(net_packet_t *packet)
@@ -919,6 +953,10 @@
NET_CL_ParseSYN(packet);
break;
+ case NET_PACKET_TYPE_REJECTED:
+ NET_CL_ParseReject(packet);
+ break;
+
case NET_PACKET_TYPE_WAITING_DATA:
NET_CL_ParseWaitingData(packet);
break;
@@ -1040,6 +1078,7 @@
// initialize module for client mode
if (!addr->module->InitClient())
{
+ SetRejectReason("Failed to initialize client module");
return false;
}
@@ -1054,6 +1093,7 @@
// try to connect
start_time = I_GetTimeMS();
last_send_time = -1;
+ SetRejectReason("Unknown reason");
while (client_connection.state == NET_CONN_STATE_CONNECTING)
{
@@ -1069,6 +1109,7 @@
// time out after 5 seconds
if (nowtime - start_time > 5000)
{
+ SetRejectReason("No response from server");
break;
}
@@ -1093,6 +1134,7 @@
{
// connected ok!
NET_Log("client: connected successfully");
+ SetRejectReason(NULL);
client_state = CLIENT_STATE_WAITING_LAUNCH;
drone = data->drone;
--- a/src/net_common.c
+++ b/src/net_common.c
@@ -50,9 +50,6 @@
static FILE *net_debug = NULL;
-// Why did the server reject us?
-char *net_client_reject_reason = NULL;
-
static void NET_Conn_Init(net_connection_t *conn, net_addr_t *addr,
net_protocol_t protocol)
{
@@ -129,29 +126,6 @@
}
}
-static void NET_Conn_ParseReject(net_connection_t *conn, net_packet_t *packet)
-{
- char *msg;
-
- msg = NET_ReadSafeString(packet);
-
- if (msg == NULL)
- {
- return;
- }
-
- if (conn->state == NET_CONN_STATE_CONNECTING)
- {
- // rejected by server
-
- conn->state = NET_CONN_STATE_DISCONNECTED;
- conn->disconnect_reason = NET_DISCONNECT_REMOTE;
-
- free(net_client_reject_reason);
- net_client_reject_reason = strdup(msg);
- }
-}
-
static void NET_Conn_ParseReliableACK(net_connection_t *conn, net_packet_t *packet)
{
unsigned int seq;
@@ -272,9 +246,6 @@
break;
case NET_PACKET_TYPE_KEEPALIVE:
// No special action needed.
- break;
- case NET_PACKET_TYPE_REJECTED:
- NET_Conn_ParseReject(conn, packet);
break;
case NET_PACKET_TYPE_RELIABLE_ACK:
NET_Conn_ParseReliableACK(conn, packet);