]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
made darkplaces compile successfully with g++ to test for errors C doesn't care about...
[xonotic/darkplaces.git] / sv_main.c
index 63dd5a81d7767e23814306232899d9243184ce02..7935327ff6fa65d41405112a16b1b62ba9289319 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -72,6 +72,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_edgefriction);
        Cvar_RegisterVariable (&sv_stopspeed);
        Cvar_RegisterVariable (&sv_maxspeed);
+       Cvar_RegisterVariable (&sv_maxairspeed);
        Cvar_RegisterVariable (&sv_accelerate);
        Cvar_RegisterVariable (&sv_idealpitchscale);
        Cvar_RegisterVariable (&sv_aim);
@@ -110,7 +111,7 @@ static void SV_SaveEntFile_f(void)
                return;
        }
        FS_StripExtension(sv.worldmodel->name, basename, sizeof(basename));
-       FS_WriteFile(va("%s.ent", basename), sv.worldmodel->brush.entities, strlen(sv.worldmodel->brush.entities));
+       FS_WriteFile(va("%s.ent", basename), sv.worldmodel->brush.entities, (fs_offset_t)strlen(sv.worldmodel->brush.entities));
 }
 
 
@@ -209,13 +210,22 @@ void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int v
        int sound_num, field_mask, i, ent;
 
        if (volume < 0 || volume > 255)
-               Host_Error ("SV_StartSound: volume = %i", volume);
+       {
+               Con_Printf ("SV_StartSound: volume = %i", volume);
+               return;
+       }
 
        if (attenuation < 0 || attenuation > 4)
-               Host_Error ("SV_StartSound: attenuation = %f", attenuation);
+       {
+               Con_Printf ("SV_StartSound: attenuation = %f", attenuation);
+               return;
+       }
 
        if (channel < 0 || channel > 7)
-               Host_Error ("SV_StartSound: channel = %i", channel);
+       {
+               Con_Printf ("SV_StartSound: channel = %i", channel);
+               return;
+       }
 
        if (sv.datagram.cursize > MAX_PACKETFRAGMENT-21)
                return;
@@ -474,7 +484,8 @@ void SV_PrepareEntitiesForSending(void)
        for (e = 1, ent = PRVM_NEXT_EDICT(prog->edicts);e < prog->num_edicts;e++, ent = PRVM_NEXT_EDICT(ent))
        {
                sendentitiesindex[e] = NULL;
-               if (ent->priv.server->free)
+               // the 2 billion unit check is actually to detect NAN origins (we really don't want to send those)
+               if (ent->priv.server->free || VectorLength2(ent->fields.server->origin) > 2000000000.0*2000000000.0)
                        continue;
 
                cs = defaultstate;
@@ -895,7 +906,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
        // stuff the sigil bits into the high bits of items for sbar, or else
        // mix in items2
        val = PRVM_GETEDICTFIELDVALUE(ent, eval_items2);
-       if (val)
+       if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE)
                items = (int)ent->fields.server->items | ((int)val->_float << 23);
        else
                items = (int)ent->fields.server->items | ((int)prog->globals.server->serverflags << 28);
@@ -1513,8 +1524,8 @@ Tell all the clients that the server is changing levels
 */
 void SV_SendReconnect (void)
 {
-       char    data[128];
-       sizebuf_t       msg;
+       qbyte data[128];
+       sizebuf_t msg;
 
        msg.data = data;
        msg.cursize = 0;
@@ -1612,7 +1623,7 @@ void SV_SpawnServer (const char *server)
 {
        prvm_edict_t *ent;
        int i;
-       qbyte *entities;
+       char *entities;
        model_t *worldmodel;
        char modelname[sizeof(sv.modelname)];
 
@@ -1669,6 +1680,10 @@ void SV_SpawnServer (const char *server)
 
        memset (&sv, 0, sizeof(sv));
 
+       SV_VM_Setup();
+
+       sv.active = true;
+
        strlcpy (sv.name, server, sizeof (sv.name));
 
        sv.protocol = Protocol_EnumForName(sv_protocolname.string);
@@ -1680,8 +1695,6 @@ void SV_SpawnServer (const char *server)
                sv.protocol = PROTOCOL_QUAKE;
        }
 
-       SV_VM_Setup();
-
        SV_VM_Begin();
 
 // load progs to get entity field count
@@ -1699,7 +1712,7 @@ void SV_SpawnServer (const char *server)
        // progs fields, often accessed by server
        prog->edictsfields = PR_Alloc(prog->max_edicts * prog->edict_size);*/
        // used by PushMove to move back pushed entities
-       sv.moved_edicts = PRVM_Alloc(prog->max_edicts * sizeof(prvm_edict_t *));
+       sv.moved_edicts = (prvm_edict_t **)PRVM_Alloc(prog->max_edicts * sizeof(prvm_edict_t *));
        /*for (i = 0;i < prog->max_edicts;i++)
        {
                ent = prog->edicts + i;
@@ -1727,6 +1740,7 @@ void SV_SpawnServer (const char *server)
        //prog->num_edicts = svs.maxclients+1;
 
        sv.state = ss_loading;
+       prog->allowworldwrites = true;
        sv.paused = false;
 
        *prog->time = sv.time = 1.0;
@@ -1779,7 +1793,7 @@ void SV_SpawnServer (const char *server)
        // load replacement entity file if found
        entities = NULL;
        if (sv_entpatch.integer)
-               entities = FS_LoadFile(va("maps/%s.ent", sv.name), tempmempool, true);
+               entities = (char *)FS_LoadFile(va("maps/%s.ent", sv.name), tempmempool, true);
        if (entities)
        {
                Con_Printf("Loaded maps/%s.ent\n", sv.name);
@@ -1793,10 +1807,14 @@ void SV_SpawnServer (const char *server)
        // LordHavoc: clear world angles (to fix e3m3.bsp)
        VectorClear(prog->edicts->fields.server->angles);
 
-       sv.active = true;
-
 // all setup is completed, any further precache statements are errors
        sv.state = ss_active;
+       prog->allowworldwrites = false;
+
+       // we need to reset the spawned flag on all connected clients here so that
+       // their thinks don't run during startup (before PutClientInServer)
+       for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
+               host_client->spawned = false;
 
 // run two frames to allow everything to settle
        for (i = 0;i < 2;i++)
@@ -1832,7 +1850,7 @@ void SV_VM_CB_BeginIncreaseEdicts(void)
        prvm_edict_t *ent;
 
        PRVM_Free( sv.moved_edicts );
-       sv.moved_edicts = PRVM_Alloc(prog->max_edicts * sizeof(prvm_edict_t *));
+       sv.moved_edicts = (prvm_edict_t **)PRVM_Alloc(prog->max_edicts * sizeof(prvm_edict_t *));
 
        // links don't survive the transition, so unlink everything
        for (i = 0, ent = prog->edicts;i < prog->max_edicts;i++, ent++)
@@ -1869,7 +1887,7 @@ void SV_VM_CB_InitEdict(prvm_edict_t *e)
                e->fields.server->colormap = num + 1;
                e->fields.server->team = (svs.clients[num].colors & 15) + 1;
                // set netname/clientcolors back to client values so that
-               // DP_SV_CLIENTNAME and DPV_SV_CLIENTCOLORS will not immediately
+               // DP_SV_CLIENTNAME and DP_SV_CLIENTCOLORS will not immediately
                // reset them
                e->fields.server->netname = PRVM_SetEngineString(svs.clients[num].name);
                if ((val = PRVM_GETEDICTFIELDVALUE(e, eval_clientcolors)))