moved rate and connecttime from netconn structure to client structure in preparation...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 12 Nov 2004 21:48:07 +0000 (21:48 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 12 Nov 2004 21:48:07 +0000 (21:48 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4737 d7cf8633-e32d-0410-b094-e92efae38249

host_cmd.c
netconn.c
netconn.h
server.h
sv_main.c

index 7324da7..a6b67ca 100644 (file)
@@ -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");
index 9ab6cd5..49ca4dc 100755 (executable)
--- 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;
index cf7c5b7..a1082fd 100755 (executable)
--- 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
index 15f5193..7b45edf 100644 (file)
--- 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;
 
index e884eae..4dcf5de 100644 (file)
--- 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;
        }