From 8aeb4438ea5f178bb27f8359b8df325337cb51ba Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 12 Nov 2004 21:48:07 +0000 Subject: [PATCH] moved rate and connecttime from netconn structure to client structure in preparation for DP_SV_BOTCLIENT extension git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4737 d7cf8633-e32d-0410-b094-e92efae38249 --- host_cmd.c | 6 +++--- netconn.c | 14 ++++---------- netconn.h | 3 --- server.h | 6 ++++++ sv_main.c | 12 +++++++++--- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/host_cmd.c b/host_cmd.c index 7324da76..a6b67ca6 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -84,7 +84,7 @@ void Host_Status_f (void) { if (!client->active) continue; - seconds = (int)(realtime - client->netconnection->connecttime); + seconds = (int)(realtime - client->connecttime); minutes = seconds / 60; if (minutes) { @@ -1014,7 +1014,7 @@ void Host_Rate_f(void) return; } - host_client->netconnection->rate = rate; + host_client->rate = rate; } /* @@ -1201,7 +1201,7 @@ void Host_Spawn_f (void) pr_global_struct->self = EDICT_TO_PROG(sv_player); PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing"); - if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time) + if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time) Sys_Printf("%s entered the game\n", host_client->name); PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing"); diff --git a/netconn.c b/netconn.c index 9ab6cd5e..49ca4dca 100755 --- a/netconn.c +++ b/netconn.c @@ -420,13 +420,7 @@ netconn_t *NetConn_Open(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress) conn = Mem_Alloc(netconn_mempool, sizeof(*conn)); conn->mysocket = mysocket; conn->peeraddress = *peeraddress; - // updated by receiving "rate" command from client - conn->rate = NET_MINRATE; - // no limits for local player - if (LHNETADDRESS_GetAddressType(peeraddress) == LHNETADDRESSTYPE_LOOP) - conn->rate = 1000000000; conn->canSend = true; - conn->connecttime = realtime; conn->lastMessageTime = realtime; // LordHavoc: (inspired by ProQuake) use a short connect timeout to // reduce effectiveness of connection request floods @@ -1074,7 +1068,7 @@ int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, if (clientnum < svs.maxclients) { // duplicate connection request - if (realtime - client->netconnection->connecttime < 2.0) + if (realtime - client->connecttime < 2.0) { // client is still trying to connect, // so we send a duplicate reply @@ -1201,7 +1195,7 @@ int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, if (clientnum < svs.maxclients) { // duplicate connection request - if (realtime - client->netconnection->connecttime < 2.0) + if (realtime - client->connecttime < 2.0) { // client is still trying to connect, // so we send a duplicate reply @@ -1315,7 +1309,7 @@ int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, MSG_WriteString(&net_message, client->name); MSG_WriteLong(&net_message, client->colors); MSG_WriteLong(&net_message, (int)client->edict->v->frags); - MSG_WriteLong(&net_message, (int)(realtime - client->netconnection->connecttime)); + MSG_WriteLong(&net_message, (int)(realtime - client->connecttime)); MSG_WriteString(&net_message, client->netconnection->address); *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK)); NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress); @@ -1386,7 +1380,7 @@ void NetConn_ServerFrame(void) for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++) { // never timeout loopback connections - if (host_client->netconnection && realtime > host_client->netconnection->timeout && LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(host_client->netconnection->mysocket)) != LHNETADDRESSTYPE_LOOP) + if (host_client->netconnection && realtime > host_client->netconnection->timeout && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP) { Con_Printf("Client \"%s\" connection timed out\n", host_client->name); sv_player = host_client->edict; diff --git a/netconn.h b/netconn.h index cf7c5b74..a1082fd2 100755 --- a/netconn.h +++ b/netconn.h @@ -117,9 +117,6 @@ typedef struct netconn_s lhnetsocket_t *mysocket; lhnetaddress_t peeraddress; - // requested rate in bytes per second - int rate; - // this is mostly identical to qsocket_t from quake // if this time is reached, kick off peer diff --git a/server.h b/server.h index 15f51932..7b45edfa 100644 --- a/server.h +++ b/server.h @@ -117,6 +117,12 @@ typedef struct client_s // remove this client immediately qboolean deadsocket; + // requested rate in bytes per second + int rate; + + // realtime this client connected + double connecttime; + // reliable messages must be sent periodically double last_message; diff --git a/sv_main.c b/sv_main.c index e884eaec..4dcf5de7 100644 --- a/sv_main.c +++ b/sv_main.c @@ -362,7 +362,7 @@ void SV_ConnectClient (int clientnum, netconn_t *netconnection) client->active = true; client->netconnection = netconnection; - Con_DPrintf("Client %s connected\n", client->netconnection->address); + Con_DPrintf("Client %s connected\n", client->netconnection ? client->netconnection->address : "botclient"); strcpy(client->name, "unconnected"); strcpy(client->old_name, "unconnected"); @@ -371,6 +371,12 @@ void SV_ConnectClient (int clientnum, netconn_t *netconnection) client->message.data = client->msgbuf; client->message.maxsize = sizeof(client->msgbuf); client->message.allowoverflow = true; // we can catch it + // updated by receiving "rate" command from client + client->rate = NET_MINRATE; + // no limits for local player + if (client->netconnection && LHNETADDRESS_GetAddressType(&client->netconnection->peeraddress) == LHNETADDRESSTYPE_LOOP) + client->rate = 1000000000; + client->connecttime = realtime; if (sv.loadgame) memcpy (client->spawn_parms, spawn_parms, sizeof(spawn_parms)); @@ -1061,8 +1067,8 @@ qboolean SV_SendClientDatagram (client_t *client) if (sv_maxrate.integer != maxrate) Cvar_SetValueQuick(&sv_maxrate, maxrate); - rate = bound(NET_MINRATE, client->netconnection->rate, maxrate); - rate = (int)(client->netconnection->rate * sys_ticrate.value); + rate = bound(NET_MINRATE, client->rate, maxrate); + rate = (int)(client->rate * sys_ticrate.value); maxsize = bound(100, rate, 1400); maxsize2 = 1400; } -- 2.39.2