}
if (sv_echobprint.integer && cls.state == ca_dedicated)
- Sys_Print(msg);
+ Con_Print(msg);
}
/*
int i;
Con_Printf("Client \"%s\" dropped\n", host_client->name);
- // send any final messages (don't check for errors)
+ // make sure edict is not corrupt (from a level change for example)
+ host_client->edict = EDICT_NUM(host_client - svs.clients + 1);
+
if (host_client->netconnection)
{
// free the client (the body stays around)
MSG_WriteByte(&host_client->message, svc_disconnect);
NetConn_SendUnreliableMessage(host_client->netconnection, &host_client->message);
}
-
// break the net connection
NetConn_Close(host_client->netconnection);
host_client->netconnection = NULL;
+ }
- // LordHavoc: don't call QC if server is dead (avoids recursive
- // Host_Error in some mods when they run out of edicts)
- if (sv.active && host_client->edict && host_client->spawned)
- {
- // call the prog function for removing a client
- // this will set the body to a dead frame, among other things
- int saveSelf = pr_global_struct->self;
- pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
- PR_ExecuteProgram(pr_global_struct->ClientDisconnect, "QC function ClientDisconnect is missing");
- pr_global_struct->self = saveSelf;
- }
+ // call qc ClientDisconnect function
+ // LordHavoc: don't call QC if server is dead (avoids recursive
+ // Host_Error in some mods when they run out of edicts)
+ if (host_client->active && sv.active && host_client->edict && host_client->spawned)
+ {
+ // call the prog function for removing a client
+ // this will set the body to a dead frame, among other things
+ int saveSelf = pr_global_struct->self;
+ pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
+ PR_ExecuteProgram(pr_global_struct->ClientDisconnect, "QC function ClientDisconnect is missing");
+ pr_global_struct->self = saveSelf;
}
// remove leaving player from scoreboard
- // clear a fields that matter to DP_SV_CLIENTNAME and DP_SV_CLIENTCOLORS, and also frags
- ED_ClearEdict(host_client->edict);
//host_client->edict->v->netname = PR_SetString(host_client->name);
//if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
// val->_float = 0;
EntityFrame4_FreeDatabase(host_client->entitydatabase4);
if (host_client->entitydatabase5)
EntityFrame5_FreeDatabase(host_client->entitydatabase5);
+
+ if (sv.active)
+ {
+ // clear a fields that matter to DP_SV_CLIENTNAME and DP_SV_CLIENTCOLORS, and also frags
+ ED_ClearEdict(host_client->edict);
+ }
+
// clear the client struct (this sets active to false)
memset(host_client, 0, sizeof(*host_client));
timeleft = (oldrealtime - realtime) + timecap;
if (timeleft > 0)
{
+ int msleft;
// don't totally hog the CPU
- if (timeleft >= 0.03)
- Sys_Sleep((int)(timeleft * 1000) - 10);
+ if (cls.state == ca_dedicated)
+ {
+ // if dedicated, try to use as little cpu as possible by waiting
+ // just a little longer than necessary
+ // (yes this means it doesn't quite keep up with the framerate)
+ msleft = (int)ceil(timeleft * 1000);
+ }
+ else
+ {
+ // if not dedicated, try to hit exactly a steady framerate by not
+ // sleeping the full amount
+ msleft = (int)floor(timeleft * 1000);
+ }
+ if (msleft > 0)
+ Sys_Sleep(msleft);
return false;
}
*/
void Host_ServerFrame (void)
{
- // never run more than 20 frames at a time as a sanity limit
- int framecount, framelimit = 20;
- double advancetime;
- static double frametimetotal = 0, lastservertime = 0;
- frametimetotal += host_frametime;
- // LordHavoc: cap server at sys_ticrate in networked games
- if (frametimetotal < 0.001 || (!cl.islocalgame && cls.state == ca_connected && sv.active && ((realtime - lastservertime) < sys_ticrate.value)))
+ // never run more than 5 frames at a time as a sanity limit
+ int framecount, framelimit = 5;
+ double advancetime, newtime;
+ if (!sv.active)
+ return;
+ newtime = Sys_DoubleTime();
+ // if this is the first frame of a new server, ignore the huge time difference
+ if (!sv.timer)
+ sv.timer = newtime;
+ // if we're already past the new time, don't run a frame
+ // (does not happen if cl.islocalgame)
+ if (sv.timer > newtime)
return;
- lastservertime = realtime;
-
- // set the time and clear the general datagram
- SV_ClearDatagram();
-
// run the world state
// don't allow simulation to run too fast or too slow or logic glitches can occur
- for (framecount = 0;framecount < framelimit && frametimetotal > 0;framecount++, frametimetotal -= advancetime)
+ for (framecount = 0;framecount < framelimit && sv.timer < newtime;framecount++)
{
- advancetime = min(frametimetotal, sys_ticrate.value);
+ if (cl.islocalgame)
+ advancetime = min(newtime - sv.timer, sys_ticrate.value);
+ else
+ advancetime = sys_ticrate.value;
+ sv.timer += advancetime;
// only advance time if not paused
// the game also pauses in singleplayer when menu or console is used
- if (!sv.paused && (!cl.islocalgame || (key_dest == key_game && !key_consoleactive)))
- sv.frametime = advancetime;
- else
+ sv.frametime = advancetime * slowmo.value;
+ if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive)))
sv.frametime = 0;
pr_global_struct->frametime = sv.frametime;
+ // set the time and clear the general datagram
+ SV_ClearDatagram();
+
// check for network packets to the server each world step incase they
// come in midframe (particularly if host is running really slow)
NetConn_ServerFrame();
// move things around and think unless paused
if (sv.frametime)
SV_Physics();
- }
- // send all messages to the clients
- SV_SendClientMessages();
+ // send all messages to the clients
+ SV_SendClientMessages();
- // send an heartbeat if enough time has passed since the last one
- NetConn_Heartbeat(0);
+ // send an heartbeat if enough time has passed since the last one
+ NetConn_Heartbeat(0);
+ }
+ // if we fell behind too many frames just don't worry about it
+ if (sv.timer < newtime)
+ sv.timer = newtime;
}
static double time2 = 0;
static double time3 = 0;
int pass1, pass2, pass3;
- usercmd_t cmd; // Used for receiving input
if (setjmp(host_abortserver))
return; // something bad happened, or the server disconnected
IN_Commands();
// Collect input into cmd
- IN_ProcessMove(&cmd);
+ IN_ProcessMove();
// process console commands
Cbuf_Execute();
// if running the server locally, make intentions now
if (cls.state == ca_connected && sv.active)
- CL_SendCmd(&cmd);
+ CL_SendCmd();
//-------------------
//
// if running the server remotely, send intentions now after
// the incoming messages have been read
if (!sv.active)
- CL_SendCmd(&cmd);
+ CL_SendCmd();
CL_ReadFromServer();
}
if (cls.state != ca_dedicated)
{
VID_Open();
+ CL_InitTEnts (); // We must wait after sound startup to load tent sounds
SCR_BeginLoadingPlaque();
MR_Init();
}