]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
Lots of str[n]cat, str[n]cpy, and [v]sprintf have been replaced by strlcat, strlcpy...
[xonotic/darkplaces.git] / sv_main.c
index 8810480ed3ca00ae6d48e91e1c2ddd984a01b8b7..ac6368249cca465938f4f9b4cb49f219079259cc 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -258,7 +258,7 @@ void SV_SendServerinfo (client_t *client)
        MSG_WriteString (&client->message,message);
 
        MSG_WriteByte (&client->message, svc_serverinfo);
-       MSG_WriteLong (&client->message, DPPROTOCOL_VERSION4);
+       MSG_WriteLong (&client->message, PROTOCOL_DARKPLACES4);
        MSG_WriteByte (&client->message, svs.maxclients);
 
        if (!coop.integer && deathmatch.integer)
@@ -985,6 +985,16 @@ void SV_WriteEntitiesToClient(client_t *client, edict_t *clent, sizebuf_t *msg)
        buf.data = data;
        buf.maxsize = sizeof(data);
 
+       d = client->entitydatabase4;
+
+       for (i = 0;i < MAX_ENTITY_HISTORY;i++)
+               if (!d->commit[i].numentities)
+                       break;
+       // if commit buffer full, just don't bother writing an update this frame
+       if (i == MAX_ENTITY_HISTORY)
+               return;
+       d->currentcommit = d->commit + i;
+
        // this state's number gets played around with later
        ClearStateToDefault(&inactiveentitystate);
        //inactiveentitystate = defaultstate;
@@ -1021,17 +1031,23 @@ void SV_WriteEntitiesToClient(client_t *client, edict_t *clent, sizebuf_t *msg)
        for (i = 0;i < numsendentities;i++)
                SV_MarkWriteEntityStateToClient(sendentities + i);
 
-       d = client->entitydatabase4;
        // calculate maximum bytes to allow in this packet
        // deduct 4 to account for the end data
        maxbytes = min(msg->maxsize, MAX_PACKETFRAGMENT) - 4;
 
-       d->currentcommit = d->commit + EntityFrame4_SV_ChooseCommitToReplace(d);
        d->currentcommit->numentities = 0;
        d->currentcommit->framenum = ++client->entityframenumber;
        MSG_WriteByte(msg, svc_entities);
        MSG_WriteLong(msg, d->referenceframenum);
        MSG_WriteLong(msg, d->currentcommit->framenum);
+       if (developer_networkentities.integer >= 1)
+       {
+               Con_Printf("send svc_entities ref:%i num:%i (database: ref:%i commits:", d->referenceframenum, d->currentcommit->framenum, d->referenceframenum);
+               for (i = 0;i < MAX_ENTITY_HISTORY;i++)
+                       if (d->commit[i].numentities)
+                               Con_Printf(" %i", d->commit[i].framenum);
+               Con_Printf(")\n");
+       }
        if (d->currententitynumber >= sv.max_edicts)
                startnumber = 1;
        else
@@ -1191,7 +1207,7 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
        if ( ent->v->waterlevel >= 2)
                bits |= SU_INWATER;
 
-       // dpprotocol
+       // PROTOCOL_DARKPLACES
        VectorClear(punchvector);
        if ((val = GETEDICTFIELDVALUE(ent, eval_punchvector)))
                VectorCopy(val->vector, punchvector);
@@ -1214,8 +1230,8 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
        {
                if (ent->v->punchangle[i])
                        bits |= (SU_PUNCH1<<i);
-               if (punchvector[i]) // dpprotocol
-                       bits |= (SU_PUNCHVEC1<<i); // dpprotocol
+               if (punchvector[i]) // PROTOCOL_DARKPLACES
+                       bits |= (SU_PUNCHVEC1<<i); // PROTOCOL_DARKPLACES
                if (ent->v->velocity[i])
                        bits |= (SU_VELOCITY1<<i);
        }
@@ -1251,9 +1267,9 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
        for (i=0 ; i<3 ; i++)
        {
                if (bits & (SU_PUNCH1<<i))
-                       MSG_WritePreciseAngle(msg, ent->v->punchangle[i]); // dpprotocol
-               if (bits & (SU_PUNCHVEC1<<i)) // dpprotocol
-                       MSG_WriteDPCoord(msg, punchvector[i]); // dpprotocol
+                       MSG_WritePreciseAngle(msg, ent->v->punchangle[i]); // PROTOCOL_DARKPLACES
+               if (bits & (SU_PUNCHVEC1<<i)) // PROTOCOL_DARKPLACES
+                       MSG_WriteDPCoord(msg, punchvector[i]); // PROTOCOL_DARKPLACES
                if (bits & (SU_VELOCITY1<<i))
                        MSG_WriteChar (msg, ent->v->velocity[i]/16);
        }
@@ -1275,7 +1291,7 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
        MSG_WriteByte (msg, ent->v->ammo_rockets);
        MSG_WriteByte (msg, ent->v->ammo_cells);
 
-       if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE)
+       if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
        {
                for(i=0;i<32;i++)
                {
@@ -1347,14 +1363,14 @@ void SV_UpdateToReliableMessages (void)
        for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
        {
                // update the host_client fields we care about according to the entity fields
-               sv_player = host_client->edict;
+               sv_player = EDICT_NUM(i+1);
                s = PR_GetString(sv_player->v->netname);
                if (s != host_client->name)
                {
                        if (s == NULL)
                                s = "";
                        // point the string back at host_client->name to keep it safe
-                       strncpy(host_client->name, s, sizeof(host_client->name) - 1);
+                       strlcpy (host_client->name, s, sizeof (host_client->name));
                        sv_player->v->netname = PR_SetString(host_client->name);
                }
                if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)) && host_client->colors != val->_float)