]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
Initialize console commands and cvars before anything else
[xonotic/darkplaces.git] / sv_main.c
index 19d267505397cf825b218ef83904bd1841de49bb..d8b29cb16c98ba44887595f00407bc0e83f00f77 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -47,7 +47,7 @@ cvar_t pausable = {CVAR_SERVER, "pausable","1", "allow players to pause or not (
 cvar_t pr_checkextension = {CVAR_SERVER | CVAR_READONLY, "pr_checkextension", "1", "indicates to QuakeC that the standard quakec extensions system is available (if 0, quakec should not attempt to use extensions)"};
 cvar_t samelevel = {CVAR_SERVER | CVAR_NOTIFY, "samelevel","0", "repeats same level if level ends (due to timelimit or someone hitting an exit)"};
 cvar_t skill = {CVAR_SERVER, "skill","1", "difficulty level of game, affects monster layouts in levels, 0 = easy, 1 = normal, 2 = hard, 3 = nightmare (same layout as hard but monsters fire twice)"};
-cvar_t slowmo = {CVAR_CLIENT | CVAR_SERVER, "slowmo", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"};
+cvar_t host_timescale = {CVAR_CLIENT | CVAR_SERVER, "host_timescale", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"};
 
 cvar_t sv_accelerate = {CVAR_SERVER, "sv_accelerate", "10", "rate at which a player accelerates to sv_maxspeed"};
 cvar_t sv_aim = {CVAR_SERVER | CVAR_SAVE, "sv_aim", "2", "maximum cosine angle for quake's vertical autoaim, a value above 1 completely disables the autoaim, quake used 0.93"};
@@ -124,6 +124,7 @@ cvar_t sv_gameplayfix_q1bsptracelinereportstexture = {CVAR_SERVER, "sv_gameplayf
 cvar_t sv_gameplayfix_unstickplayers = {CVAR_SERVER, "sv_gameplayfix_unstickplayers", "1", "big hack to try and fix the rare case of MOVETYPE_WALK entities getting stuck in the world clipping hull."};
 cvar_t sv_gameplayfix_unstickentities = {CVAR_SERVER, "sv_gameplayfix_unstickentities", "1", "hack to check if entities are crossing world collision hull and try to move them to the right position"};
 cvar_t sv_gameplayfix_fixedcheckwatertransition = {CVAR_SERVER, "sv_gameplayfix_fixedcheckwatertransition", "1", "fix two very stupid bugs in SV_CheckWaterTransition when watertype is CONTENTS_EMPTY (the bugs causes waterlevel to be 1 on first frame, -1 on second frame - the fix makes it 0 on both frames)"};
+cvar_t sv_gameplayfix_customstats = {CVAR_SERVER, "sv_gameplayfix_customstats", "0", "Disable stats higher than 220, for use by certain games such as Xonotic"};
 cvar_t sv_gravity = {CVAR_SERVER | CVAR_NOTIFY, "sv_gravity","800", "how fast you fall (512 = roughly earth gravity)"};
 cvar_t sv_init_frame_count = {CVAR_SERVER, "sv_init_frame_count", "2", "number of frames to run to allow everything to settle before letting clients connect"};
 cvar_t sv_idealpitchscale = {CVAR_SERVER, "sv_idealpitchscale","0.8", "how much to look up/down slopes and stairs when not using freelook"};
@@ -204,7 +205,7 @@ server_static_t svs;
 
 mempool_t *sv_mempool = NULL;
 
-extern cvar_t slowmo;
+extern cvar_t host_timescale;
 extern float           scr_centertime_off;
 
 // MUST match effectnameindex_t in client.h
@@ -413,7 +414,14 @@ prvm_required_field_t sv_reqglobals[] =
 #undef PRVM_DECLARE_function
 };
 
+static void Host_Timescale_c(char *string)
+{
+       double value;
+       value = atof(string);
 
+       if(value < 0.00001 && value != 0)
+               string[0] = '0', string[1] = 0;
+}
 
 //============================================================================
 
@@ -422,12 +430,7 @@ static void SV_AreaStats_f(cmd_state_t *cmd)
        World_PrintAreaStats(&sv.world, "server");
 }
 
-/*
-===============
-SV_Init
-===============
-*/
-void SV_Init (void)
+void SV_Init_Commands(void)
 {
        // init the csqc progs cvars, since they are updated/used by the server code
        // TODO: fix this since this is a quick hack to make some of [515]'s broken code run ;) [9/13/2006 Black]
@@ -435,7 +438,6 @@ void SV_Init (void)
        extern cvar_t csqc_progcrc;
        extern cvar_t csqc_progsize;
        extern cvar_t csqc_usedemoprogs;
-
        Cvar_RegisterVariable(&sv_worldmessage);
        Cvar_RegisterVariable(&sv_worldname);
        Cvar_RegisterVariable(&sv_worldnamenoextension);
@@ -446,12 +448,10 @@ void SV_Init (void)
        Cvar_RegisterVariable (&csqc_progsize);
        Cvar_RegisterVariable (&csqc_usedemoprogs);
 
-       Cmd_AddCommand(&cmd_server, "sv_saveentfile", SV_SaveEntFile_f, "save map entities to .ent file (to allow external editing)");
-       Cmd_AddCommand(&cmd_server, "sv_areastats", SV_AreaStats_f, "prints statistics on entity culling during collision traces");
-       Cmd_AddCommand(&cmd_serverfromclient, "sv_startdownload", SV_StartDownload_f, "begins sending a file to the client (network protocol use only)");
-       Cmd_AddCommand(&cmd_serverfromclient, "download", SV_Download_f, "downloads a specified file from the server");
-       Cmd_AddCommand(&cmd_client, "sv_startdownload", Cmd_ForwardToServer_f, "begins sending a file to the client (network protocol use only)");
-       Cmd_AddCommand(&cmd_client, "download", Cmd_ForwardToServer_f, "downloads a specified file from the server");
+       Cmd_AddCommand(CMD_SHARED, "sv_saveentfile", SV_SaveEntFile_f, "save map entities to .ent file (to allow external editing)");
+       Cmd_AddCommand(CMD_SHARED, "sv_areastats", SV_AreaStats_f, "prints statistics on entity culling during collision traces");
+       Cmd_AddCommand(CMD_CLIENT | CMD_SERVER_FROM_CLIENT, "sv_startdownload", SV_StartDownload_f, "begins sending a file to the client (network protocol use only)");
+       Cmd_AddCommand(CMD_CLIENT | CMD_SERVER_FROM_CLIENT, "download", SV_Download_f, "downloads a specified file from the server");
 
        Cvar_RegisterVariable (&sv_disablenotify);
        Cvar_RegisterVariable (&coop);
@@ -464,7 +464,10 @@ void SV_Init (void)
        Cvar_RegisterVariable (&pr_checkextension);
        Cvar_RegisterVariable (&samelevel);
        Cvar_RegisterVariable (&skill);
-       Cvar_RegisterVariable (&slowmo);
+       Cvar_RegisterVariable (&host_timescale);
+       Cvar_RegisterCallback (&host_timescale, Host_Timescale_c);
+       Cvar_RegisterAlias (&host_timescale, "slowmo");
+       Cvar_RegisterAlias (&host_timescale, "timescale");
        Cvar_RegisterVariable (&sv_accelerate);
        Cvar_RegisterVariable (&sv_aim);
        Cvar_RegisterVariable (&sv_airaccel_qw);
@@ -540,6 +543,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_gameplayfix_unstickplayers);
        Cvar_RegisterVariable (&sv_gameplayfix_unstickentities);
        Cvar_RegisterVariable (&sv_gameplayfix_fixedcheckwatertransition);
+       Cvar_RegisterVariable (&sv_gameplayfix_customstats);
        Cvar_RegisterVariable (&sv_gravity);
        Cvar_RegisterVariable (&sv_init_frame_count);
        Cvar_RegisterVariable (&sv_idealpitchscale);
@@ -615,7 +619,15 @@ void SV_Init (void)
        Cvar_RegisterVariable (&halflifebsp);
        Cvar_RegisterVariable (&sv_mapformat_is_quake2);
        Cvar_RegisterVariable (&sv_mapformat_is_quake3);
+}
 
+/*
+===============
+SV_Init
+===============
+*/
+void SV_Init (void)
+{
        sv_mempool = Mem_AllocPool("server", 0, NULL);
 }
 
@@ -1057,7 +1069,7 @@ void SV_SendServerinfo (client_t *client)
        client->ping = 0;
 
        // allow the client some time to send his keepalives, even if map loading took ages
-       client->netconnection->timeout = realtime + net_connecttimeout.value;
+       client->netconnection->timeout = host.realtime + net_connecttimeout.value;
 }
 
 /*
@@ -1118,7 +1130,7 @@ void SV_ConnectClient (int clientnum, netconn_t *netconnection)
        client->unreliablemsg.maxsize = sizeof(client->unreliablemsg_data);
        // updated by receiving "rate" command from client, this is also the default if not using a DP client
        client->rate = 1000000000;
-       client->connecttime = realtime;
+       client->connecttime = host.realtime;
 
        if (!sv.loadgame)
        {
@@ -1737,12 +1749,12 @@ static void SV_MarkWriteEntityStateToClient(entity_state_t *s)
                                                        break;
                                        if(eyeindex < sv.writeentitiestoclient_numeyes)
                                                svs.clients[sv.writeentitiestoclient_clientnumber].visibletime[s->number] =
-                                                       realtime + (
+                                                       host.realtime + (
                                                                s->number <= svs.maxclients
                                                                        ? sv_cullentities_trace_delay_players.value
                                                                        : sv_cullentities_trace_delay.value
                                                        );
-                                       else if (realtime > svs.clients[sv.writeentitiestoclient_clientnumber].visibletime[s->number])
+                                       else if (host.realtime > svs.clients[sv.writeentitiestoclient_clientnumber].visibletime[s->number])
                                        {
                                                sv.writeentitiestoclient_stats_culled_trace++;
                                                return;
@@ -2030,7 +2042,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
                // angle fixing was requested by global thinking code...
                // so store the current angles for later use
                VectorCopy(PRVM_serveredictvector(ent, angles), host_client->fixangle_angles);
-               host_client->fixangle_angles_set = TRUE;
+               host_client->fixangle_angles_set = true;
 
                // and clear fixangle for the next frame
                PRVM_serveredictfloat(ent, fixangle) = 0;
@@ -2041,7 +2053,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
                MSG_WriteByte (msg, svc_setangle);
                for (i=0 ; i < 3 ; i++)
                        MSG_WriteAngle (msg, host_client->fixangle_angles[i], sv.protocol);
-               host_client->fixangle_angles_set = FALSE;
+               host_client->fixangle_angles_set = false;
        }
 
        // the runes are in serverflags, pack them into the items value, also pack
@@ -2107,47 +2119,50 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
        //stats[STAT_SECRETS] = PRVM_serverglobalfloat(found_secrets);
        //stats[STAT_MONSTERS] = PRVM_serverglobalfloat(killed_monsters);
 
-       // movement settings for prediction
-       // note: these are not sent in protocols with lower MAX_CL_STATS limits
-       stats[STAT_MOVEFLAGS] = MOVEFLAG_VALID
-               | (sv_gameplayfix_q2airaccelerate.integer ? MOVEFLAG_Q2AIRACCELERATE : 0)
-               | (sv_gameplayfix_nogravityonground.integer ? MOVEFLAG_NOGRAVITYONGROUND : 0)
-               | (sv_gameplayfix_gravityunaffectedbyticrate.integer ? MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE : 0)
-       ;
-       statsf[STAT_MOVEVARS_TICRATE] = sys_ticrate.value;
-       statsf[STAT_MOVEVARS_TIMESCALE] = slowmo.value;
-       statsf[STAT_MOVEVARS_GRAVITY] = sv_gravity.value;
-       statsf[STAT_MOVEVARS_STOPSPEED] = sv_stopspeed.value;
-       statsf[STAT_MOVEVARS_MAXSPEED] = sv_maxspeed.value;
-       statsf[STAT_MOVEVARS_SPECTATORMAXSPEED] = sv_maxspeed.value; // FIXME: QW has a separate cvar for this
-       statsf[STAT_MOVEVARS_ACCELERATE] = sv_accelerate.value;
-       statsf[STAT_MOVEVARS_AIRACCELERATE] = sv_airaccelerate.value >= 0 ? sv_airaccelerate.value : sv_accelerate.value;
-       statsf[STAT_MOVEVARS_WATERACCELERATE] = sv_wateraccelerate.value >= 0 ? sv_wateraccelerate.value : sv_accelerate.value;
-       statsf[STAT_MOVEVARS_ENTGRAVITY] = gravity;
-       statsf[STAT_MOVEVARS_JUMPVELOCITY] = sv_jumpvelocity.value;
-       statsf[STAT_MOVEVARS_EDGEFRICTION] = sv_edgefriction.value;
-       statsf[STAT_MOVEVARS_MAXAIRSPEED] = sv_maxairspeed.value;
-       statsf[STAT_MOVEVARS_STEPHEIGHT] = sv_stepheight.value;
-       statsf[STAT_MOVEVARS_AIRACCEL_QW] = sv_airaccel_qw.value;
-       statsf[STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR] = sv_airaccel_qw_stretchfactor.value;
-       statsf[STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION] = sv_airaccel_sideways_friction.value;
-       statsf[STAT_MOVEVARS_FRICTION] = sv_friction.value;
-       statsf[STAT_MOVEVARS_WATERFRICTION] = sv_waterfriction.value >= 0 ? sv_waterfriction.value : sv_friction.value;
-       statsf[STAT_MOVEVARS_AIRSTOPACCELERATE] = sv_airstopaccelerate.value;
-       statsf[STAT_MOVEVARS_AIRSTRAFEACCELERATE] = sv_airstrafeaccelerate.value;
-       statsf[STAT_MOVEVARS_MAXAIRSTRAFESPEED] = sv_maxairstrafespeed.value;
-       statsf[STAT_MOVEVARS_AIRSTRAFEACCEL_QW] = sv_airstrafeaccel_qw.value;
-       statsf[STAT_MOVEVARS_AIRCONTROL] = sv_aircontrol.value;
-       statsf[STAT_MOVEVARS_AIRCONTROL_POWER] = sv_aircontrol_power.value;
-       statsf[STAT_MOVEVARS_AIRCONTROL_PENALTY] = sv_aircontrol_penalty.value;
-       statsf[STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL] = sv_warsowbunny_airforwardaccel.value;
-       statsf[STAT_MOVEVARS_WARSOWBUNNY_ACCEL] = sv_warsowbunny_accel.value;
-       statsf[STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED] = sv_warsowbunny_topspeed.value;
-       statsf[STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL] = sv_warsowbunny_turnaccel.value;
-       statsf[STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO] = sv_warsowbunny_backtosideratio.value;
-       statsf[STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW] = sv_airspeedlimit_nonqw.value;
-       statsf[STAT_FRAGLIMIT] = fraglimit.value;
-       statsf[STAT_TIMELIMIT] = timelimit.value;
+       if(!sv_gameplayfix_customstats.integer)
+       {
+               statsf[STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR] = sv_airaccel_qw_stretchfactor.value;
+               statsf[STAT_MOVEVARS_AIRCONTROL_PENALTY] = sv_aircontrol_penalty.value;
+               statsf[STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW] = sv_airspeedlimit_nonqw.value;               
+               statsf[STAT_MOVEVARS_AIRSTRAFEACCEL_QW] = sv_airstrafeaccel_qw.value;
+               statsf[STAT_MOVEVARS_AIRCONTROL_POWER] = sv_aircontrol_power.value;
+               // movement settings for prediction
+               // note: these are not sent in protocols with lower MAX_CL_STATS limits
+               stats[STAT_MOVEFLAGS] = MOVEFLAG_VALID
+                       | (sv_gameplayfix_q2airaccelerate.integer ? MOVEFLAG_Q2AIRACCELERATE : 0)
+                       | (sv_gameplayfix_nogravityonground.integer ? MOVEFLAG_NOGRAVITYONGROUND : 0)
+                       | (sv_gameplayfix_gravityunaffectedbyticrate.integer ? MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE : 0)
+               ;
+               statsf[STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL] = sv_warsowbunny_airforwardaccel.value;
+               statsf[STAT_MOVEVARS_WARSOWBUNNY_ACCEL] = sv_warsowbunny_accel.value;
+               statsf[STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED] = sv_warsowbunny_topspeed.value;
+               statsf[STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL] = sv_warsowbunny_turnaccel.value;
+               statsf[STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO] = sv_warsowbunny_backtosideratio.value;
+               statsf[STAT_MOVEVARS_AIRSTOPACCELERATE] = sv_airstopaccelerate.value;
+               statsf[STAT_MOVEVARS_AIRSTRAFEACCELERATE] = sv_airstrafeaccelerate.value;
+               statsf[STAT_MOVEVARS_MAXAIRSTRAFESPEED] = sv_maxairstrafespeed.value;
+               statsf[STAT_MOVEVARS_AIRCONTROL] = sv_aircontrol.value;
+               statsf[STAT_FRAGLIMIT] = fraglimit.value;
+               statsf[STAT_TIMELIMIT] = timelimit.value;
+               statsf[STAT_MOVEVARS_FRICTION] = sv_friction.value;     
+               statsf[STAT_MOVEVARS_WATERFRICTION] = sv_waterfriction.value >= 0 ? sv_waterfriction.value : sv_friction.value;
+               statsf[STAT_MOVEVARS_TICRATE] = sys_ticrate.value;
+               statsf[STAT_MOVEVARS_TIMESCALE] = host_timescale.value;
+               statsf[STAT_MOVEVARS_GRAVITY] = sv_gravity.value;
+               statsf[STAT_MOVEVARS_STOPSPEED] = sv_stopspeed.value;
+               statsf[STAT_MOVEVARS_MAXSPEED] = sv_maxspeed.value;
+               statsf[STAT_MOVEVARS_SPECTATORMAXSPEED] = sv_maxspeed.value; // FIXME: QW has a separate cvar for this
+               statsf[STAT_MOVEVARS_ACCELERATE] = sv_accelerate.value;
+               statsf[STAT_MOVEVARS_AIRACCELERATE] = sv_airaccelerate.value >= 0 ? sv_airaccelerate.value : sv_accelerate.value;
+               statsf[STAT_MOVEVARS_WATERACCELERATE] = sv_wateraccelerate.value >= 0 ? sv_wateraccelerate.value : sv_accelerate.value;
+               statsf[STAT_MOVEVARS_ENTGRAVITY] = gravity;
+               statsf[STAT_MOVEVARS_JUMPVELOCITY] = sv_jumpvelocity.value;
+               statsf[STAT_MOVEVARS_EDGEFRICTION] = sv_edgefriction.value;
+               statsf[STAT_MOVEVARS_MAXAIRSPEED] = sv_maxairspeed.value;
+               statsf[STAT_MOVEVARS_STEPHEIGHT] = sv_stepheight.value;
+               statsf[STAT_MOVEVARS_AIRACCEL_QW] = sv_airaccel_qw.value;
+               statsf[STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION] = sv_airaccel_sideways_friction.value;
+       }
 
        if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3 || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3 || sv.protocol == PROTOCOL_DARKPLACES4 || sv.protocol == PROTOCOL_DARKPLACES5)
        {
@@ -2381,7 +2396,7 @@ static void SV_SendClientDatagram (client_t *client)
                timedelta *= 1 - net_burstreserve.value;
 
                // only try to use excess time
-               timedelta = bound(0, realtime - host_client->netconnection->cleartime, timedelta);
+               timedelta = bound(0, host.realtime - host_client->netconnection->cleartime, timedelta);
 
                // but we know next packet will be in sys_ticrate, so we can use up THAT bandwidth
                timedelta += sys_ticrate.value;
@@ -2441,12 +2456,12 @@ static void SV_SendClientDatagram (client_t *client)
                // now write as many entities as we can fit, and also sends stats
                SV_WriteEntitiesToClient (client, client->edict, &msg, maxsize);
        }
-       else if (realtime > client->keepalivetime)
+       else if (host.realtime > client->keepalivetime)
        {
                // the player isn't totally in the game yet
                // send small keepalive messages if too much time has passed
                // (may also be sending downloads)
-               client->keepalivetime = realtime + 5;
+               client->keepalivetime = host.realtime + 5;
                MSG_WriteChar (&msg, svc_nop);
        }
 
@@ -3531,7 +3546,7 @@ void SV_SpawnServer (const char *server)
        }
 
        // Once all init frames have been run, we consider svqc code fully initialized.
-       prog->inittime = realtime;
+       prog->inittime = host.realtime;
 
        if (cls.state == ca_dedicated)
                Mod_PurgeUnused();
@@ -3599,7 +3614,7 @@ static void SVVM_end_increase_edicts(prvm_prog_t *prog)
 
        // link every entity except world
        for (i = 1, ent = prog->edicts;i < prog->num_edicts;i++, ent++)
-               if (!ent->priv.server->free)
+               if (!ent->priv.server->free && !VectorCompare(PRVM_serveredictvector(ent, absmin), PRVM_serveredictvector(ent, absmax)))
                        SV_LinkEdict(ent);
 }
 
@@ -4030,7 +4045,7 @@ static int SV_ThreadFunc(void *voiddata)
 
                        // only advance time if not paused
                        // the game also pauses in singleplayer when menu or console is used
-                       sv.frametime = advancetime * slowmo.value;
+                       sv.frametime = advancetime * host_timescale.value;
                        if (host_framerate.value)
                                sv.frametime = host_framerate.value;
                        if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive || cl.csqc_paused)))