ref: 124ca83db41b79b2fb48509e548a9d1205429390
parent: f7f8ce6c6328b41a2aa9394f148f07c5203cec11
author: Simon Howard <[email protected]>
date: Sun Jan 27 18:35:47 EST 2019
net: Add logging of client events.
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -277,7 +277,7 @@
++recvwindow_start;
- //printf("CL: advanced to %i\n", recvwindow_start);
+ NET_Log("client: advanced receive window to %d", recvwindow_start);
}
}
@@ -425,9 +425,12 @@
net_protocol_t protocol;
char *server_version;
+ NET_Log("client: processing SYN response");
+
server_version = NET_ReadSafeString(packet);
if (server_version == NULL)
{
+ NET_Log("client: error: failed to read server version");
return;
}
@@ -434,10 +437,12 @@
protocol = NET_ReadProtocol(packet);
if (protocol == NET_PROTOCOL_UNKNOWN)
{
+ NET_Log("client: error: can't find a common protocol");
return;
}
// We are now successfully connected.
+ NET_Log("client: connected to server");
client_connection.state = NET_CONN_STATE_CONNECTED;
client_connection.protocol = protocol;
@@ -491,8 +496,12 @@
{
unsigned int num_players;
+ NET_Log("client: processing launch packet");
+
if (client_state != CLIENT_STATE_WAITING_LAUNCH)
{
+ NET_Log("client: error: not in waiting launch state, client_state=%d",
+ client_state);
return;
}
@@ -502,22 +511,29 @@
if (!NET_ReadInt8(packet, &num_players))
{
+ NET_Log("client: error: failed to read number of players");
return;
}
net_client_wait_data.num_players = num_players;
client_state = CLIENT_STATE_WAITING_START;
+ NET_Log("client: now waiting for game start");
}
static void NET_CL_ParseGameStart(net_packet_t *packet)
{
+ NET_Log("client: processing game start packet");
+
if (!NET_ReadSettings(packet, &settings))
{
+ NET_Log("client: error: failed to read settings");
return;
}
if (client_state != CLIENT_STATE_WAITING_START)
{
+ NET_Log("client: error: not in waiting start state, client_state=%d",
+ client_state);
return;
}
@@ -525,6 +541,8 @@
|| settings.consoleplayer >= (signed int) settings.num_players)
{
// insane values
+ NET_Log("client: error: bad settings, num_players=%d, consoleplayer=%d",
+ settings.num_players, settings.consoleplayer);
return;
}
@@ -533,10 +551,12 @@
{
// Invalid player number: must be positive for real players,
// negative for drones
-
+ NET_Log("client: error: mismatch: drone=%d, consoleplayer=%d",
+ drone, settings.consoleplayer);
return;
}
+ NET_Log("client: beginning game state");
client_state = CLIENT_STATE_IN_GAME;
// Clear the receive window
@@ -620,24 +640,25 @@
resend_end = i;
}
- else
+ else if (resend_start >= 0)
{
- if (resend_start >= 0)
- {
- // End of a run of resend tics
-
- //printf("CL: resend request timed out: %i-%i\n", resend_start, resend_end);
- NET_CL_SendResendRequest(recvwindow_start + resend_start,
- recvwindow_start + resend_end);
-
- resend_start = -1;
- }
+ // End of a run of resend tics
+ NET_Log("client: resend request timed out for %d-%d (%d)",
+ recvwindow_start + resend_start,
+ recvwindow_start + resend_end,
+ recvwindow[resend_start].resend_time);
+ NET_CL_SendResendRequest(recvwindow_start + resend_start,
+ recvwindow_start + resend_end);
+ resend_start = -1;
}
}
if (resend_start >= 0)
{
- //printf("CL: resend request timed out: %i-%i\n", resend_start, resend_end);
+ NET_Log("client: resend request timed out for %d-%d (%d)",
+ recvwindow_start + resend_start,
+ recvwindow_start + resend_end,
+ recvwindow[resend_start].resend_time);
NET_CL_SendResendRequest(recvwindow_start + resend_start,
recvwindow_start + resend_end);
}
@@ -648,6 +669,8 @@
if (need_to_acknowledge && nowtime - gamedata_recv_time > 200)
{
+ NET_Log("client: no game data received since %d: triggering ack",
+ gamedata_recv_time);
NET_CL_SendGameDataACK();
}
}
@@ -664,12 +687,14 @@
int resend_start, resend_end;
size_t i;
int index;
-
+
+ NET_Log("client: processing game data packet");
+
// Read header
-
if (!NET_ReadInt8(packet, &seq)
|| !NET_ReadInt8(packet, &num_tics))
{
+ NET_Log("client: error: failed to read header");
return;
}
@@ -685,8 +710,8 @@
}
// Expand byte value into the full tic number
-
seq = NET_CL_ExpandTicNum(seq);
+ NET_Log("client: got game data, seq=%d, num_tics=%d", seq, num_tics);
for (i=0; i<num_tics; ++i)
{
@@ -696,6 +721,7 @@
if (!NET_ReadFullTiccmd(packet, &cmd, settings.lowres_turn))
{
+ NET_Log("client: error: failed to read ticcmd %d", i);
return;
}
@@ -712,6 +738,7 @@
recvobj->active = true;
recvobj->cmd = cmd;
+ NET_Log("client: stored tic %d in receive window", seq);
// If a packet is lost or arrives out of order, we might get
// the tic in the next packet instead (because of extratic).
@@ -764,9 +791,11 @@
}
// Possibly send a resend request
-
if (resend_start < resend_end)
{
+ NET_Log("client: request resend for %d-%d before %d",
+ recvwindow_start + resend_start,
+ recvwindow_start + resend_end - 1, seq);
NET_CL_SendResendRequest(recvwindow_start + resend_start,
recvwindow_start + resend_end - 1);
}
@@ -780,10 +809,12 @@
static unsigned int end;
static unsigned int num_tics;
+ NET_Log("client: processing resend request");
+
if (drone)
{
// Drones don't send gamedata.
-
+ NET_Log("client: error: resend request but we're a drone?");
return;
}
@@ -790,6 +821,7 @@
if (!NET_ReadInt32(packet, &start)
|| !NET_ReadInt8(packet, &num_tics))
{
+ NET_Log("client: error: couldn't read start and num_tics");
return;
}
@@ -796,6 +828,7 @@
end = start + num_tics - 1;
//printf("requested resend %i-%i .. ", start, end);
+ NET_Log("client: resend request: start=%d, num_tics=%d", start, num_tics);
// Check we have the tics being requested. If not, reduce the
// window of tics to only what we have.
@@ -814,16 +847,16 @@
--end;
}
- //printf("%i-%i\n", start, end);
-
// Resend those tics
-
if (start <= end)
{
- //printf("CL: resend %i-%i\n", start, start+num_tics-1);
-
+ NET_Log("client: resending %d-%d", start, end);
NET_CL_SendTics(start, end);
}
+ else
+ {
+ NET_Log("client: don't have the tics to resend");
+ }
}
// Console message that the server wants the client to print
@@ -853,6 +886,10 @@
return;
}
+ NET_Log("client: packet from server, type %d",
+ packet_type & ~NET_RELIABLE_PACKET);
+ NET_LogPacket(packet);
+
if (NET_Conn_Packet(&client_connection, packet, &packet_type))
{
// Packet eaten by the common connection code
@@ -956,6 +993,8 @@
{
net_packet_t *packet;
+ NET_Log("client: sending SYN");
+
packet = NET_NewPacket(10);
NET_WriteInt16(packet, NET_PACKET_TYPE_SYN);
NET_WriteInt32(packet, NET_MAGIC_NUMBER);
@@ -1041,7 +1080,7 @@
if (client_connection.state == NET_CONN_STATE_CONNECTED)
{
// connected ok!
-
+ NET_Log("client: connected successfully");
client_state = CLIENT_STATE_WAITING_LAUNCH;
drone = data->drone;
@@ -1050,7 +1089,7 @@
else
{
// failed to connect
-
+ NET_Log("client: failed to connect");
NET_CL_Shutdown();
return false;
@@ -1081,7 +1120,8 @@
{
return;
}
-
+
+ NET_Log("client: beginning disconnect");
NET_Conn_Disconnect(&client_connection);
start_time = I_GetTimeMS();
@@ -1093,9 +1133,11 @@
{
// time out after 5 seconds
+ NET_Log("client: no acknowledgement of disconnect received");
client_state = CLIENT_STATE_WAITING_START;
- fprintf(stderr, "NET_CL_Disconnect: Timeout while disconnecting from server\n");
+ fprintf(stderr, "NET_CL_Disconnect: Timeout while disconnecting "
+ "from server\n");
break;
}
@@ -1106,7 +1148,7 @@
}
// Finished sending disconnect packets, etc.
-
+ NET_Log("client: disconnect complete");
NET_CL_Shutdown();
}