]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
Updated a few entries in the todo file
[xonotic/darkplaces.git] / sv_main.c
index 999be85c281b3d1b17d7b579caf084c11fb84396..d85aba281e10a340d4b0f0126e572a35834aebae 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -41,6 +41,8 @@ cvar_t sv_gameplayfix_stepwhilejumping = {0, "sv_gameplayfix_stepwhilejumping",
 cvar_t sv_gameplayfix_swiminbmodels = {0, "sv_gameplayfix_swiminbmodels", "1"};
 cvar_t sv_gameplayfix_setmodelrealbox = {0, "sv_gameplayfix_setmodelrealbox", "1"};
 
+cvar_t sv_progs = {0, "sv_progs", "progs.dat" };
+
 server_t sv;
 server_static_t svs;
 
@@ -84,6 +86,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_protocolname);
        Cvar_RegisterVariable (&sv_ratelimitlocalplayer);
        Cvar_RegisterVariable (&sv_maxrate);
+       Cvar_RegisterVariable (&sv_progs);
 
        SV_Phys_Init();
        SV_World_Init();
@@ -311,7 +314,7 @@ void SV_SendServerinfo (client_t *client)
                client->entitydatabase5 = EntityFrame5_AllocDatabase(sv_clients_mempool);
 
        MSG_WriteByte (&client->message, svc_print);
-       snprintf (message, sizeof (message), "\002\nServer: %s build %s (progs %i crc)", gamename, buildstring, pr_crc);
+       dpsnprintf (message, sizeof (message), "\002\nServer: %s build %s (progs %i crc)", gamename, buildstring, pr_crc);
        MSG_WriteString (&client->message,message);
 
        MSG_WriteByte (&client->message, svc_serverinfo);
@@ -449,6 +452,7 @@ void SV_PrepareEntitiesForSending(void)
        int e, i;
        float f;
        edict_t *ent;
+       eval_t *val;
        entity_state_t cs;
        // send all entities that touch the pvs
        numsendentities = 0;
@@ -480,6 +484,16 @@ void SV_PrepareEntitiesForSending(void)
                if (GETEDICTFIELDVALUE(ent, eval_glow_trail)->_float)
                        cs.flags |= RENDER_GLOWTRAIL;
 
+               // don't need to init cs.colormod because the defaultstate did that for us
+               //cs.colormod[0] = cs.colormod[1] = cs.colormod[2] = 32;
+               val = GETEDICTFIELDVALUE(ent, eval_colormod);
+               if (val->vector[0] || val->vector[1] || val->vector[2])
+               {
+                       i = val->vector[0] * 32.0f;cs.colormod[0] = bound(0, i, 255);
+                       i = val->vector[1] * 32.0f;cs.colormod[1] = bound(0, i, 255);
+                       i = val->vector[2] * 32.0f;cs.colormod[2] = bound(0, i, 255);
+               }
+
                cs.modelindex = 0;
                i = (int)ent->v->modelindex;
                if (i >= 1 && i < MAX_MODELS && *PR_GetString(ent->v->model))
@@ -649,7 +663,7 @@ void SV_MarkWriteEntityStateToClient(entity_state_t *s)
                        return;
                // always send world submodels, they don't generate much traffic
                // except in PROTOCOL_QUAKE where they hog bandwidth like crazy
-               else if (!(s->effects & EF_NODEPTHTEST) && (sv.protocol == PROTOCOL_QUAKE || !(isbmodel = (model = sv.models[s->modelindex]) != NULL && model->name[0] == '*')))
+               else if (!(s->effects & EF_NODEPTHTEST) && (!(isbmodel = (model = sv.models[s->modelindex]) != NULL && model->name[0] == '*') || sv.protocol == PROTOCOL_QUAKE))
                {
                        Mod_CheckLoaded(model);
                        // entity has survived every check so far, check if visible
@@ -877,11 +891,6 @@ void SV_WriteClientdataToMessage (client_t *client, edict_t *ent, sizebuf_t *msg
                VectorCopy(val->vector, punchvector);
 
        weaponmodelindex = SV_ModelIndex(PR_GetString(ent->v->weaponmodel), 1);
-       if (!weaponmodelindex)
-       {
-               Con_DPrintf("weaponmodel \"%s\" not precached\n", PR_GetString(ent->v->weaponmodel));
-               weaponmodelindex = 0;
-       }
 
        viewzoom = 255;
        if ((val = GETEDICTFIELDVALUE(ent, eval_viewzoom)))
@@ -1124,6 +1133,8 @@ void SV_UpdateToReliableMessages (void)
        client_t *client;
        eval_t *val;
        char *name;
+       char *model;
+       char *skin;
 
 // check for changes to be sent over the reliable streams
        for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
@@ -1162,6 +1173,26 @@ void SV_UpdateToReliableMessages (void)
                        MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
                }
 
+               // NEXUIZ_PLAYERMODEL
+               if( eval_playermodel ) {
+                       model = PR_GetString(GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string);
+                       if (model == NULL)
+                               model = "";
+                       // always point the string back at host_client->name to keep it safe
+                       strlcpy (host_client->playermodel, model, sizeof (host_client->playermodel));
+                       GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PR_SetString(host_client->playermodel);
+               }
+
+               // NEXUIZ_PLAYERSKIN
+               if( eval_playerskin ) {
+                       skin = PR_GetString(GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string);
+                       if (skin == NULL)
+                               skin = "";
+                       // always point the string back at host_client->name to keep it safe
+                       strlcpy (host_client->playerskin, skin, sizeof (host_client->playerskin));
+                       GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PR_SetString(host_client->playerskin);
+               }
+
                // frags
                host_client->frags = (int)host_client->edict->v->frags;
                if (host_client->old_frags != host_client->frags)
@@ -1314,30 +1345,22 @@ int SV_ModelIndex(char *s, int precachemode)
                {
                        if (precachemode)
                        {
-                               if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4 || sv.protocol == PROTOCOL_DARKPLACES5)
+                               if (sv.state != ss_loading && (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4 || sv.protocol == PROTOCOL_DARKPLACES5))
                                {
-                                       // not able to precache during game
-                                       if (precachemode == 2 && sv.state != ss_loading)
-                                       {
-                                               Con_Printf("SV_ModelIndex(\"%s\"): precache_model can only be done in spawn functions\n", filename);
-                                               return 0;
-                                       }
+                                       Con_Printf("SV_ModelIndex(\"%s\"): precache_model can only be done in spawn functions\n", filename);
+                                       return 0;
                                }
-                               else
+                               if (precachemode == 1)
+                                       Con_Printf("SV_ModelIndex(\"%s\"): not precached (fix your code), precaching anyway\n", filename);
+                               strlcpy(sv.model_precache[i], filename, sizeof(sv.model_precache[i]));
+                               sv.models[i] = Mod_ForName (sv.model_precache[i], true, false, false);
+                               if (sv.protocol == PROTOCOL_DARKPLACES6 && sv.state != ss_loading)
                                {
-                                       // able to precache during game
-                                       if (precachemode == 1)
-                                               Con_Printf("SV_ModelIndex(\"%s\"): not precached (fix your code), precaching anyway\n", filename);
-                                       strlcpy(sv.model_precache[i], filename, sizeof(sv.model_precache[i]));
-                                       sv.models[i] = Mod_ForName (sv.model_precache[i], true, false, false);
-                                       if (sv.state != ss_loading)
-                                       {
-                                               MSG_WriteByte(&sv.reliable_datagram, svc_precache);
-                                               MSG_WriteShort(&sv.reliable_datagram, i);
-                                               MSG_WriteString(&sv.reliable_datagram, filename);
-                                       }
-                                       return i;
+                                       MSG_WriteByte(&sv.reliable_datagram, svc_precache);
+                                       MSG_WriteShort(&sv.reliable_datagram, i);
+                                       MSG_WriteString(&sv.reliable_datagram, filename);
                                }
+                               return i;
                        }
                        Con_Printf("SV_ModelIndex(\"%s\"): not precached\n", filename);
                        return 0;
@@ -1345,10 +1368,7 @@ int SV_ModelIndex(char *s, int precachemode)
                if (!strcmp(sv.model_precache[i], filename))
                        return i;
        }
-       if (precachemode)
-               Con_Printf("SV_ModelIndex(\"%s\"): i == MAX_MODELS\n", filename);
-       else
-               Con_Printf("SV_ModelIndex(\"%s\"): not precached\n", filename);
+       Con_Printf("SV_ModelIndex(\"%s\"): i (%i) == MAX_MODELS (%i)\n", filename, i, MAX_MODELS);
        return 0;
 }
 
@@ -1364,33 +1384,31 @@ int SV_SoundIndex(char *s, int precachemode)
        char filename[MAX_QPATH];
        if (!s || !*s)
                return 0;
+       // testing
+       //if (precachemode == 2)
+       //      return 0;
        strlcpy(filename, s, sizeof(filename));
        for (i = 1;i < limit;i++)
        {
                if (!sv.sound_precache[i][0])
                {
-                       if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4 || sv.protocol == PROTOCOL_DARKPLACES5)
+                       if (precachemode)
                        {
-                               // not able to precache during game
-                               if (precachemode == 2 && sv.state != ss_loading)
+                               if (sv.state != ss_loading && (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4 || sv.protocol == PROTOCOL_DARKPLACES5))
                                {
                                        Con_Printf("SV_SoundIndex(\"%s\"): precache_sound can only be done in spawn functions\n", filename);
                                        return 0;
                                }
-                       }
-                       else
-                       {
-                               // able to precache during game
-                               if (precachemode)
+                               if (precachemode == 1)
+                                       Con_Printf("SV_SoundIndex(\"%s\"): not precached (fix your code), precaching anyway\n", filename);
+                               strlcpy(sv.sound_precache[i], filename, sizeof(sv.sound_precache[i]));
+                               if (sv.protocol == PROTOCOL_DARKPLACES6 && sv.state != ss_loading)
                                {
-                                       if (precachemode == 1)
-                                               Con_Printf("SV_SoundIndex(\"%s\"): not precached (fix your code), precaching anyway\n", filename);
-                                       strlcpy(sv.sound_precache[i], filename, sizeof(sv.sound_precache[i]));
                                        MSG_WriteByte(&sv.reliable_datagram, svc_precache);
                                        MSG_WriteShort(&sv.reliable_datagram, i + 32768);
                                        MSG_WriteString(&sv.reliable_datagram, filename);
-                                       return i;
                                }
+                               return i;
                        }
                        Con_Printf("SV_SoundIndex(\"%s\"): not precached\n", filename);
                        return 0;
@@ -1398,10 +1416,7 @@ int SV_SoundIndex(char *s, int precachemode)
                if (!strcmp(sv.sound_precache[i], filename))
                        return i;
        }
-       if (precachemode)
-               Con_Printf("SV_SoundIndex(\"%s\"): i == MAX_SOUNDS\n", filename);
-       else
-               Con_Printf("SV_SoundIndex(\"%s\"): not precached\n", filename);
+       Con_Printf("SV_SoundIndex(\"%s\"): i (%i) == MAX_SOUNDS (%i)\n", filename, i, MAX_SOUNDS);
        return 0;
 }
 
@@ -1592,7 +1607,10 @@ void SV_SpawnServer (const char *server)
 
        Con_DPrintf("SpawnServer: %s\n", server);
 
-       snprintf (modelname, sizeof(modelname), "maps/%s.bsp", server);
+       if (cls.state != ca_dedicated)
+               SCR_BeginLoadingPlaque();
+
+       dpsnprintf (modelname, sizeof(modelname), "maps/%s.bsp", server);
        worldmodel = Mod_ForName(modelname, false, true, true);
        if (!worldmodel || !worldmodel->TraceBox)
        {
@@ -1624,9 +1642,10 @@ void SV_SpawnServer (const char *server)
 //
        if (coop.integer)
                Cvar_SetValue ("deathmatch", 0);
-       current_skill = bound(0, (int)(skill.value + 0.5), 3);
-
-       Cvar_SetValue ("skill", (float)current_skill);
+       // LordHavoc: it can be useful to have skills outside the range 0-3...
+       //current_skill = bound(0, (int)(skill.value + 0.5), 3);
+       //Cvar_SetValue ("skill", (float)current_skill);
+       current_skill = (int)(skill.value + 0.5);
 
 //
 // set up the new server
@@ -1664,7 +1683,7 @@ void SV_SpawnServer (const char *server)
        }
 
 // load progs to get entity field count
-       PR_LoadProgs ();
+       PR_LoadProgs ( sv_progs.string );
 
 // allocate server memory
        // start out with just enough room for clients and a reasonable estimate of entities
@@ -1731,7 +1750,7 @@ void SV_SpawnServer (const char *server)
        strlcpy(sv.model_precache[1], sv.modelname, sizeof(sv.model_precache[1]));
        for (i = 1;i < sv.worldmodel->brush.numsubmodels;i++)
        {
-               snprintf(sv.model_precache[i+1], sizeof(sv.model_precache[i+1]), "*%i", i);
+               dpsnprintf(sv.model_precache[i+1], sizeof(sv.model_precache[i+1]), "*%i", i);
                sv.models[i+1] = Mod_ForName (sv.model_precache[i+1], false, false, false);
        }