+ if (sv_timer > 0)
+ {
+ if (!sv.active)
+ {
+ // if there is no server, run server timing at 10fps
+ sv_timer -= 0.1;
+ }
+ else
+ {
+ // execute one or more server frames, with an upper limit on how much
+ // execution time to spend on server frames to avoid freezing the game if
+ // the server is overloaded, this execution time limit means the game will
+ // slow down if the server is taking too long.
+ int framecount, framelimit = 1;
+ double advancetime, aborttime = 0;
+
+ // receive server packets now, which might contain rcon commands, which
+ // may change level or other such things we don't want to have happen in
+ // the middle of Host_Frame
+ NetConn_ServerFrame();
+
+ // run the world state
+ // don't allow simulation to run too fast or too slow or logic glitches can occur
+
+ // stop running server frames if the wall time reaches this value
+ if (sys_ticrate.value <= 0)
+ advancetime = sv_timer;
+ else if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
+ {
+ // synchronize to the client frametime, but no less than 10ms and no more than sys_ticrate
+ advancetime = bound(0.01, cl_timer, sys_ticrate.value);
+ framelimit = 10;
+ aborttime = Sys_DoubleTime() + 0.1;
+ }
+ else
+ {
+ advancetime = sys_ticrate.value;
+ // listen servers can run multiple server frames per client frame
+ if (cls.state == ca_connected)
+ {
+ framelimit = 10;
+ aborttime = Sys_DoubleTime() + 0.1;
+ }
+ }
+ advancetime = min(advancetime, 0.1);
+
+ // only advance time if not paused
+ // the game also pauses in singleplayer when menu or console is used
+ sv.frametime = advancetime * slowmo.value;
+ if (host_framerate.value)
+ sv.frametime = host_framerate.value;
+ if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive)))
+ sv.frametime = 0;
+
+ // setup the VM frame
+ SV_VM_Begin();
+
+ for (framecount = 0;framecount < framelimit && sv_timer > 0;framecount++)
+ {
+ sv_timer -= advancetime;
+
+ // move things around and think unless paused
+ if (sv.frametime)
+ SV_Physics();
+
+ // send all messages to the clients
+ SV_SendClientMessages();
+
+ // clear the general datagram
+ SV_ClearDatagram();
+
+ // if this server frame took too long, break out of the loop
+ if (framelimit > 1 && Sys_DoubleTime() >= aborttime)
+ break;
+ }
+
+ // end the server VM frame
+ SV_VM_End();
+
+ // send an heartbeat if enough time has passed since the last one
+ NetConn_Heartbeat(0);
+ }
+ }