DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
host.h File Reference
#include <setjmp.h>
#include "qtypes.h"
#include "qdefs.h"
#include "cmd.h"
#include "cvar.h"
+ Include dependency graph for host.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  host_static_t
 

Enumerations

enum  host_state_t {
  host_init , host_loading , host_active , host_shutdown ,
  host_failing , host_failed
}
 

Functions

void Host_AbortCurrentFrame (void) DP_FUNC_NORETURN
 
void Host_Error (const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
 
double Host_Frame (double time)
 
void Host_Init (void)
 
void Host_LockSession (void)
 
void Host_SaveConfig (const char *file)
 
void Host_Shutdown (void)
 
void Host_UnlockSession (void)
 
void Host_UpdateVersion (void)
 

Variables

cvar_t developer
 
cvar_t developer_entityparsing
 
cvar_t developer_extra
 
cvar_t developer_insane
 
cvar_t developer_loadfile
 
cvar_t developer_loading
 
host_static_t host
 
cvar_t host_isclient
 
static const char *const host_state_str []
 
cvar_t sessionid
 

Enumeration Type Documentation

◆ host_state_t

Enumerator
host_init 
host_loading 
host_active 
host_shutdown 

states >= host_shutdown cause graceful shutdown, see Sys_HandleCrash() comments

host_failing 

crashing (inside crash handler)

host_failed 

crashed or aborted, SDL dialog open

Definition at line 21 of file host.h.

22{
host_state_t
Definition host.h:22
@ host_loading
Definition host.h:24
@ host_failed
crashed or aborted, SDL dialog open
Definition host.h:29
@ host_init
Definition host.h:23
@ host_active
Definition host.h:25
@ host_failing
crashing (inside crash handler)
Definition host.h:28
@ host_shutdown
states >= host_shutdown cause graceful shutdown, see Sys_HandleCrash() comments
Definition host.h:27

Function Documentation

◆ Host_AbortCurrentFrame()

void Host_AbortCurrentFrame ( void )

Definition at line 70 of file host.c.

71{
72 // in case we were previously nice, make us mean again
74
75 longjmp (host.abortframe, 1);
76}
host_static_t host
Definition host.c:41
jmp_buf abortframe
Definition host.h:43
void Sys_MakeProcessMean(void)
Definition sys_shared.c:961

References host_static_t::abortframe, host, and Sys_MakeProcessMean().

Referenced by Host_Error().

◆ Host_Error()

void Host_Error ( const char * error,
... )

Definition at line 85 of file host.c.

86{
87 static char hosterrorstring1[MAX_INPUTLINE]; // THREAD UNSAFE
88 static char hosterrorstring2[MAX_INPUTLINE]; // THREAD UNSAFE
89 static qbool hosterror = false;
90 va_list argptr;
91 int outfd = sys.outfd;
92
93 // set output to stderr
94 sys.outfd = fileno(stderr);
95
96 // turn off rcon redirect if it was active when the crash occurred
97 // to prevent loops when it is a networking problem
99
100 va_start (argptr,error);
101 dpvsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr);
102 va_end (argptr);
103
104 Con_Printf(CON_ERROR "Host_Error: %s\n", hosterrorstring1);
105
106 // LadyHavoc: if crashing very early, or currently shutting down, do
107 // Sys_Error instead
108 if (host.framecount < 1 || host.state != host_active)
109 Sys_Error ("Host_Error during %s: %s", host_state_str[host.state], hosterrorstring1);
110
111 if (hosterror)
112 Sys_Error ("Host_Error: recursively entered (original error was: %s new error is: %s)", hosterrorstring2, hosterrorstring1);
113 hosterror = true;
114
115 dp_strlcpy(hosterrorstring2, hosterrorstring1, sizeof(hosterrorstring2));
116
119
120 // print out where the crash happened, if it was caused by QC (and do a cleanup)
121 PRVM_Crash();
122
125
126 if (cls.state == ca_dedicated)
127 Sys_Error("Host_Error: %s", hosterrorstring1); // dedicated servers exit
128
129 // prevent an endless loop if the error was triggered by a command
131
132 CL_DisconnectEx(false, "Host_Error: %s", hosterrorstring1);
133 cls.demonum = -1; // stop demo loop
134
135 hosterror = false;
136
137 // restore configured outfd
138 sys.outfd = outfd;
139
140 // can't abort a frame if we didn't start one yet, won't get here in that case (see above)
142}
void CL_DisconnectEx(qbool kicked, const char *fmt,...)
Definition cl_main.c:370
client_static_t cls
Definition cl_main.c:116
void CL_Parse_ErrorCleanUp(void)
Definition cl_parse.c:4317
void CL_Parse_DumpPacket(void)
Definition cl_parse.c:4308
@ ca_dedicated
Definition client.h:530
void Cbuf_Clear(cmd_buf_t *cbuf)
Clears all command buffers.
Definition cmd.c:436
cmd_state_t * cmd_local
command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code uses...
Definition cmd.c:25
int dpvsnprintf(char *buffer, size_t buffersize, const char *format, va_list args)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:1010
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
void Con_Rcon_Redirect_Abort(void)
Definition console.c:1048
#define CON_ERROR
Definition console.h:102
void Host_AbortCurrentFrame(void)
Definition host.c:70
static const char *const host_state_str[]
Definition host.h:31
void error(string err,...)
void PRVM_Crash(void)
Definition prvm_exec.c:750
#define MAX_INPUTLINE
maximum size of console commandline, QuakeC strings, and many other text processing buffers
Definition qdefs.h:94
bool qbool
Definition qtypes.h:9
cactive_t state
Definition client.h:568
cmd_buf_t * cbuf
Definition cmd.h:137
int state
Definition host.h:44
void(* SV_Shutdown)(void)
Definition host.h:60
unsigned int framecount
incremented every frame, never reset, >0 means Host_AbortCurrentFrame() is possible
Definition host.h:45
struct host_static_t::@12 hook
int outfd
Definition sys.h:149
void Sys_Error(const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
Causes the entire program to exit ASAP.
Definition sys_shared.c:724
sys_t sys
Definition sys_shared.c:42

References ca_dedicated, cmd_state_t::cbuf, Cbuf_Clear(), CL_DisconnectEx(), CL_Parse_DumpPacket(), CL_Parse_ErrorCleanUp(), cls, cmd_local, CON_ERROR, Con_Printf(), Con_Rcon_Redirect_Abort(), client_static_t::demonum, dp_strlcpy, dpvsnprintf(), error(), host_static_t::framecount, host_static_t::hook, host, Host_AbortCurrentFrame(), host_active, host_state_str, MAX_INPUTLINE, sys_t::outfd, PRVM_Crash(), client_static_t::state, host_static_t::state, host_static_t::SV_Shutdown, sys, and Sys_Error().

Referenced by AddPortalToNodes(), CL_ExpandCSQCRenderEntities(), CL_ExpandEntities(), CL_ParseDownload(), CL_ParseServerInfo(), CL_ParseServerMessage(), CL_ParseStatic(), CL_ParseTempEntity(), CL_ValidateState(), CL_VM_Init(), CSQC_ReadEntities(), Curl_Begin(), EntityFrame_CL_ReadFrame(), EntityFrameQuake_ReadEntity(), EntityFrameQW_CL_ReadFrame(), EntityState5_ReadUpdate(), Mod_BSP_LoadSubmodels(), Mod_BSP_RecursiveNodePortals(), Mod_DARKPLACESMODEL_Load(), Mod_FindName(), Mod_IBSP_Load(), Mod_IDP0_Load(), Mod_IDP2_Load(), Mod_IDP3_Load(), Mod_IDS2_Load(), Mod_IDSP_Load(), Mod_INTERQUAKEMODEL_Load(), Mod_MAP_Load(), Mod_PSKMODEL_Load(), Mod_Q1BSP_Load(), Mod_Q1BSP_LoadClipnodes(), Mod_Q1BSP_LoadEdges(), Mod_Q1BSP_LoadFaces(), Mod_Q1BSP_LoadLeaffaces(), Mod_Q1BSP_LoadLeafs(), Mod_Q1BSP_LoadNodes(), Mod_Q1BSP_LoadPlanes(), Mod_Q1BSP_LoadSurfedges(), Mod_Q1BSP_LoadTexinfo(), Mod_Q1BSP_LoadVertexes(), Mod_Q2BSP_Load(), Mod_Q2BSP_LoadBrushes(), Mod_Q2BSP_LoadBrushSides(), Mod_Q2BSP_LoadLeafBrushes(), Mod_Q2BSP_LoadLeafs(), Mod_Q2BSP_LoadNodes(), Mod_Q2BSP_LoadTexinfo(), Mod_Q3BSP_Load(), Mod_Q3BSP_LoadBrushes(), Mod_Q3BSP_LoadBrushSides(), Mod_Q3BSP_LoadBrushSides_IG(), Mod_Q3BSP_LoadEffects(), Mod_Q3BSP_LoadFaces(), Mod_Q3BSP_LoadLeafBrushes(), Mod_Q3BSP_LoadLeafFaces(), Mod_Q3BSP_LoadLeafs(), Mod_Q3BSP_LoadLightGrid(), Mod_Q3BSP_LoadLightmaps(), Mod_Q3BSP_LoadModels(), Mod_Q3BSP_LoadNodes(), Mod_Q3BSP_LoadPlanes(), Mod_Q3BSP_LoadPVS(), Mod_Q3BSP_LoadTextures(), Mod_Q3BSP_LoadTriangles(), Mod_Q3BSP_LoadVertices(), Mod_Sprite_SharedSetup(), Mod_VBSP_Load(), Mod_VBSP_LoadEdges(), Mod_VBSP_LoadFaces(), Mod_VBSP_LoadPlanes(), Mod_VBSP_LoadSurfedges(), Mod_VBSP_LoadTexinfo(), Mod_VBSP_LoadVertexes(), Mod_ZYMOTICMODEL_Load(), NetConn_OpenServerPorts(), QW_CL_ParseDownload(), QW_CL_ParseModelList(), QW_CL_ParseSoundList(), R_FreeTexture(), R_FreeTexturePool(), R_GetTexTypeInfo(), R_MakeResizeBufferBigger(), R_UpdateTexture(), RemovePortalFromNodes(), SV_Loadgame_f(), SV_VM_Setup(), and SZ_GetSpace().

◆ Host_Frame()

double Host_Frame ( double time)

Definition at line 618 of file host.c.

619{
620 double cl_wait, sv_wait;
621
623
624 TaskQueue_Frame(false);
625
626 // keep the random time dependent, but not when playing demos/benchmarking
628 rand();
629
631
633
634 // Run any downloads
635 Curl_Frame();
636
637 // get new SDL events and add commands from keybindings to the cbuf
639
640 // process console commands
642
643 R_TimeReport("---");
644
645 // if the accumulators haven't become positive yet, wait a while
646 sv_wait = - SV_Frame(time);
647 cl_wait = - CL_Frame(time);
648
650
651 if (cls.state == ca_dedicated)
652 return sv_wait; // dedicated
653 else if (!sv.active || svs.threaded)
654 return cl_wait; // connected to server, main menu, or server is on different thread
655 else
656 return min(cl_wait, sv_wait); // listen server or singleplayer
657}
double CL_Frame(double time)
Definition cl_main.c:2802
void Cbuf_Frame(cmd_buf_t *cbuf)
Definition cmd.c:417
void Log_DestBuffer_Flush(void)
call this once per frame to send out replies to rcon streaming clients
Definition console.c:465
float time
void Curl_Frame(void)
Definition libcurl.c:1134
#define min(A, B)
Definition mathlib.h:37
void NetConn_UpdateSockets(void)
Definition netconn.c:1306
void R_TimeReport(const char *desc)
Definition r_stats.c:193
server_t sv
local server
Definition sv_main.c:223
cvar_t sv_random_seed
Definition sv_main.c:149
double SV_Frame(double time)
Definition sv_main.c:2527
server_static_t svs
persistant server info
Definition sv_main.c:224
const char * string
Definition cvar.h:71
cmd_buf_t * cbuf
Definition host.h:51
qbool restless
don't sleep
Definition host.h:49
qbool threaded
Definition server.h:44
qbool active
false if only a net client
Definition server.h:66
void Sys_SDL_HandleEvents(void)
Perform Key_Event () callbacks until the input que is empty.
Definition vid_null.c:50
void TaskQueue_Frame(qbool shutdown)
Definition taskqueue.c:213
#define Mem_CheckSentinelsGlobal()
Definition zone.h:102

References server_t::active, ca_dedicated, host_static_t::cbuf, Cbuf_Frame(), CL_Frame(), cls, Curl_Frame(), host_static_t::framecount, host, Log_DestBuffer_Flush(), Mem_CheckSentinelsGlobal, min, NetConn_UpdateSockets(), R_TimeReport(), host_static_t::restless, client_static_t::state, cvar_t::string, sv, SV_Frame(), sv_random_seed, svs, Sys_SDL_HandleEvents(), TaskQueue_Frame(), server_static_t::threaded, and time.

Referenced by Sys_Frame().

◆ Host_Init()

void Host_Init ( void )

Definition at line 377 of file host.c.

378{
379 int i;
380 char vabuf[1024];
381
382 Sys_SDL_Init();
383
384 Memory_Init();
385
390
392
393 host.realtime = 0;
395
396 if (Sys_CheckParm("-profilegameonly"))
397 Sys_AllowProfiling(false);
398
399 // LadyHavoc: quake never seeded the random number generator before... heh
400 if (Sys_CheckParm("-benchmark"))
401 srand(0); // predictable random sequence for -benchmark
402 else
403 srand((unsigned int)time(NULL));
404
405 // FIXME: this is evil, but possibly temporary
406 // LadyHavoc: doesn't seem very temporary...
407 // LadyHavoc: made this a saved cvar
408// COMMANDLINEOPTION: Console: -developer enables warnings and other notices (RECOMMENDED for mod developers)
409 if (Sys_CheckParm("-developer"))
410 {
412 developer.string = "1";
413 }
414
415 if (Sys_CheckParm("-developer2") || Sys_CheckParm("-developer3"))
416 {
418 developer.string = "1";
427 }
428
429 if (Sys_CheckParm("-developer3"))
430 {
433 }
434
435 // -dedicated is checked in SV_ServerOptions() but that's too late for Cvar_RegisterVariable() to skip all the client-only cvars
436 if (Sys_CheckParm ("-dedicated") || !cl_available)
438
439 // set and print initial version string (will be updated when gamename is changed)
440 Host_UpdateVersion(); // checks for cls.state == ca_dedicated
441 Con_Printf("%s\n", engineversion);
442
443 // initialize console command/cvar/alias/command execution systems
444 Cmd_Init();
445
446 // initialize memory subsystem cvars/commands
448
449 // initialize console and logging and its cvars/commands
450 // this enables Con_Printf() messages to be coloured
451 Con_Init();
452
453 // initialize various cvars that could not be initialized earlier
454 u8_Init();
458
459 // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name, gamename)
460 FS_Init();
461
462 // initialize process nice level
464
465 // initialize ixtable
466 Mathlib_Init();
467
468 // register the cvars for session locking
470
471 // must be after FS_Init
472 Crypto_Init();
474
475 NetConn_Init();
476 Curl_Init();
477 PRVM_Init();
478 Mod_Init();
479 World_Init();
480 SV_Init();
482
483 Thread_Init();
485
486 CL_Init();
487
488 // save off current state of aliases, commands and cvars for later restore if FS_GameDir_f is called
489 // NOTE: menu commands are freed by Cmd_RestoreInitState
491
492 // here comes the not so critical stuff
493
495 Cbuf_Execute(cmd_local->cbuf); // cannot be in Host_AddConfigText as that would cause Host_LoadConfig_f to loop!
496
498
499 Log_Start();
500
501 if (cls.state != ca_dedicated)
502 {
503 // put up the loading image so the user doesn't stare at a black screen...
505 S_Startup();
506#ifdef CONFIG_MENU
507 MR_Init();
508#endif
509 }
510
511 // check for special benchmark mode
512// COMMANDLINEOPTION: Client: -benchmark <demoname> runs a timedemo and quits, results of any timedemo can be found in gamedir/benchmark.log (for example id1/benchmark.log)
513 i = Sys_CheckParm("-benchmark");
514 if (i && i + 1 < sys.argc)
516 {
517 Cbuf_AddText(cmd_local, va(vabuf, sizeof(vabuf), "timedemo %s\n", sys.argv[i + 1]));
519 }
520
521 // check for special demo mode
522// COMMANDLINEOPTION: Client: -demo <demoname> runs a playdemo and quits
523 i = Sys_CheckParm("-demo");
524 if (i && i + 1 < sys.argc)
526 {
527 Cbuf_AddText(cmd_local, va(vabuf, sizeof(vabuf), "playdemo %s\n", sys.argv[i + 1]));
529 }
530
531#ifdef CONFIG_VIDEO_CAPTURE
532// COMMANDLINEOPTION: Client: -capturedemo <demoname> captures a playdemo and quits
533 i = Sys_CheckParm("-capturedemo");
534 if (i && i + 1 < sys.argc)
536 {
537 Cbuf_AddText(cmd_local, va(vabuf, sizeof(vabuf), "playdemo %s\ncl_capturevideo 1\n", sys.argv[i + 1]));
538 Cbuf_Execute((cmd_local)->cbuf);
539 }
540#endif
541
542 if (cls.state == ca_dedicated || Sys_CheckParm("-listen"))
544 {
545 Cbuf_AddText(cmd_local, "startmap_dm\n");
547 }
548
550 {
551#ifdef CONFIG_MENU
552 Cbuf_AddText(cmd_local, "togglemenu 1\n");
553#endif
555 }
556
557 Con_DPrint("========Initialized=========\n");
559
560 if (cls.state != ca_dedicated)
562}
void CL_StartVideo(void)
Definition cl_main.c:2786
void CL_Init(void)
Definition cl_main.c:2988
void SCR_BeginLoadingPlaque(qbool startup)
Definition cl_screen.c:1838
void Cmd_SaveInitState(void)
called by Host_Init, this marks cvars, commands and aliases with their init values
Definition cmd.c:2159
void Cbuf_AddText(cmd_state_t *cmd, const char *text)
Definition cmd.c:264
void Cmd_Init(void)
Command execution takes a null terminated string, breaks it into tokens, then searches for a command ...
Definition cmd.c:1492
void Cbuf_Execute(cmd_buf_t *cbuf)
Definition cmd.c:351
char * va(char *buf, size_t buflen, const char *format,...)
Definition common.c:972
void COM_Init_Commands(void)
Definition common.c:917
void Con_Init(void)
Definition console.c:861
void Log_Start(void)
Definition console.c:542
void Con_DPrint(const char *msg)
A Con_Print that only shows up if the "developer" cvar is set.
Definition console.c:1531
void Crypto_Init_Commands(void)
Definition crypto.c:1449
void Crypto_Init(void)
Definition crypto.c:1072
void FS_Init(void)
Definition fs.c:2342
cvar_t gl_printcheckerror
Definition gl_backend.c:9
cvar_t gl_paranoid
Definition gl_backend.c:8
cvar_t developer_insane
Definition host.c:50
static void Host_InitSession(void)
Definition host.c:309
cvar_t developer
Definition host.c:48
char engineversion[128]
version string for the corner of the console, crash messages, status command, etc
Definition host.c:304
void Host_UpdateVersion(void)
Definition host.c:162
cvar_t developer_extra
Definition host.c:49
static void Host_AddConfigText(cmd_state_t *cmd)
Definition host.c:232
static void Host_InitLocal(void)
Definition host.c:279
void Curl_Init_Commands(void)
Definition libcurl.c:1578
void Curl_Init(void)
Definition libcurl.c:810
void Mathlib_Init(void)
Definition mathlib.c:833
void MR_Init(void)
Definition menu.c:5543
void Mod_Init(void)
void NetConn_Init(void)
Definition netconn.c:4094
void PRVM_Init(void)
int i
#define NULL
Definition qtypes.h:12
void SV_StartThread(void)
Definition sv_main.c:2850
void SV_Init(void)
Definition sv_main.c:504
void S_Startup(void)
Definition snd_main.c:476
qbool demoplayback
Definition client.h:587
qbool connect_trying
Definition client.h:609
float value
Definition cvar.h:74
int integer
Definition cvar.h:73
double dirtytime
the main loop wall time for this frame, equal to Sys_DirtyTime() at the start of this host frame
Definition host.h:47
void(* ConnectLocal)(void)
Definition host.h:55
double realtime
the accumulated mainloop time since application started (with filtering), without any slowmo or clamp...
Definition host.h:46
void(* ToggleMenu)(void)
Definition host.h:57
void(* Disconnect)(qbool, const char *,...)
Definition host.h:56
int argc
Definition sys.h:146
const char ** argv
Definition sys.h:147
void Sys_SDL_Init(void)
Definition sys_null.c:22
void Sys_InitProcessNice(void)
called to set process priority for dedicated servers
Definition sys_shared.c:955
void Sys_AllowProfiling(qbool enable)
Definition sys_shared.c:65
double Sys_DirtyTime(void)
Definition sys_shared.c:417
void Sys_Init_Commands(void)
called after command system is initialized but before first Con_Print
Definition sys_shared.c:353
int Sys_CheckParm(const char *parm)
Definition sys_shared.c:327
void TaskQueue_Init(void)
Definition taskqueue.c:53
int Thread_Init(void)
Definition thread_null.c:4
void u8_Init(void)
Definition utf8lib.c:13
int cl_available
Definition vid_null.c:24
void World_Init(void)
Definition world.c:38
cvar_t developer_memorydebug
Definition zone.c:91
cvar_t developer_memory
Definition zone.c:90
void Memory_Init_Commands(void)
Definition zone.c:907
void Memory_Init(void)
Definition zone.c:882

References server_t::active, sys_t::argc, sys_t::argv, ca_dedicated, cmd_state_t::cbuf, Cbuf_AddText(), Cbuf_Execute(), cl_available, CL_Init(), CL_StartVideo(), cls, Cmd_Init(), cmd_local, Cmd_SaveInitState(), COM_Init_Commands(), Con_DPrint(), Con_Init(), Con_Printf(), client_static_t::connect_trying, host_static_t::ConnectLocal, Crypto_Init(), Crypto_Init_Commands(), Curl_Init(), Curl_Init_Commands(), client_static_t::demoplayback, developer, developer_extra, developer_insane, developer_memory, developer_memorydebug, host_static_t::dirtytime, host_static_t::Disconnect, engineversion, FS_Init(), gl_paranoid, gl_printcheckerror, host_static_t::hook, host, host_active, Host_AddConfigText(), host_init, Host_InitLocal(), Host_InitSession(), Host_UpdateVersion(), i, cvar_t::integer, Log_Start(), Mathlib_Init(), Memory_Init(), Memory_Init_Commands(), Mod_Init(), MR_Init(), NetConn_Init(), NULL, PRVM_Init(), host_static_t::realtime, S_Startup(), SCR_BeginLoadingPlaque(), client_static_t::state, host_static_t::state, cvar_t::string, sv, SV_Init(), host_static_t::SV_Shutdown, SV_StartThread(), sys, Sys_AllowProfiling(), Sys_CheckParm(), Sys_DirtyTime(), Sys_Init_Commands(), Sys_InitProcessNice(), Sys_SDL_Init(), TaskQueue_Init(), Thread_Init(), time, host_static_t::ToggleMenu, u8_Init(), va(), cvar_t::value, and World_Init().

Referenced by Sys_Main().

◆ Host_LockSession()

void Host_LockSession ( void )

Definition at line 330 of file host.c.

331{
333 return;
334 locksession_run = true;
335 if(locksession.integer != 0 && !Sys_CheckParm("-readonly"))
336 {
337 char vabuf[1024];
338 char *p = va(vabuf, sizeof(vabuf), "%slock%s", *fs_userdir ? fs_userdir : fs_basedir, sessionid.string);
339 FS_CreatePath(p);
340 locksession_fh = FS_SysOpen(p, "wl", false);
341 // TODO maybe write the pid into the lockfile, while we are at it? may help server management tools
342 if(!locksession_fh)
343 {
344 if(locksession.integer == 2)
345 {
346 Con_Printf(CON_WARN "WARNING: session lock %s could not be acquired. Please run with -sessionid and an unique session name. Continuing anyway.\n", p);
347 }
348 else
349 {
350 Sys_Error("session lock %s could not be acquired. Please run with -sessionid and an unique session name.\n", p);
351 }
352 }
353 }
354}
#define CON_WARN
Definition console.h:101
qfile_t * FS_SysOpen(const char *filepath, const char *mode, qbool nonblocking)
Definition fs.c:2484
void FS_CreatePath(char *path)
Definition fs.c:1028
char fs_basedir[MAX_OSPATH]
Definition fs.c:444
char fs_userdir[MAX_OSPATH]
Definition fs.c:442
cvar_t sessionid
Definition host.c:58
static qfile_t * locksession_fh
Definition host.c:307
cvar_t locksession
Definition host.c:59
static qbool locksession_run
Definition host.c:308

References Con_Printf(), CON_WARN, fs_basedir, FS_CreatePath(), FS_SysOpen(), fs_userdir, cvar_t::integer, locksession, locksession_fh, locksession_run, sessionid, cvar_t::string, Sys_CheckParm(), Sys_Error(), and va().

Referenced by Crypto_LoadKeys(), and PRVM_Prog_Load().

◆ Host_SaveConfig()

void Host_SaveConfig ( const char * file)

Definition at line 195 of file host.c.

196{
197 qfile_t *f;
198
199// dedicated servers initialize the host but don't parse and set the
200// config.cfg cvars
201 // LadyHavoc: don't save a config if it crashed in startup
202 if (host.framecount >= 3 && cls.state != ca_dedicated && !Sys_CheckParm("-benchmark") && !Sys_CheckParm("-capturedemo"))
203 {
204 f = FS_OpenRealFile(file, "wb", false);
205 if (!f)
206 {
207 Con_Printf(CON_ERROR "Couldn't write %s\n", file);
208 return;
209 }
210 else
211 Con_Printf("Saving config to %s ...\n", file);
212
215#ifdef __EMSCRIPTEN__
216 js_syncFS(false);
217#endif
218 FS_Close (f);
219 }
220}
cvar_state_t cvars_all
Definition cvar.c:28
void Cvar_WriteVariables(cvar_state_t *cvars, qfile_t *f)
Definition cvar.c:985
qfile_t * FS_OpenRealFile(const char *filepath, const char *mode, qbool quiet)
Definition fs.c:2901
int FS_Close(qfile_t *file)
Definition fs.c:2970
void Key_WriteBindings(qfile_t *f)
Definition keys.c:1681
float f

References ca_dedicated, cls, CON_ERROR, Con_Printf(), Cvar_WriteVariables(), cvars_all, f, host_static_t::framecount, FS_Close(), FS_OpenRealFile(), host, Key_WriteBindings(), client_static_t::state, and Sys_CheckParm().

Referenced by FS_ChangeGameDirs(), Host_SaveConfig_f(), and Host_Shutdown().

◆ Host_Shutdown()

void Host_Shutdown ( void )

Definition at line 571 of file host.c.

572{
573 if (Sys_CheckParm("-profilegameonly"))
574 Sys_AllowProfiling(false);
575
576 if(cls.state != ca_dedicated)
577 CL_Shutdown();
578
579 // end the server thread
580 if (svs.threaded)
582
583 // shut down local server if active
586
587 // AK shutdown PRVM
588 // AK hmm, no PRVM_Shutdown(); yet
589
591
592 Curl_Shutdown ();
594
598 Cmd_Shutdown();
600 Log_Close();
602
604
605 Con_Shutdown();
607}
void CL_Shutdown(void)
Definition cl_main.c:2951
void Cmd_Shutdown(void)
Definition cmd.c:1575
void Con_Shutdown(void)
Definition console.c:941
void Log_Close(void)
Definition console.c:521
void Crypto_Shutdown(void)
Definition crypto.c:1043
void Host_UnlockSession(void)
Definition host.c:356
void Host_SaveConfig(const char *file)
Definition host.c:195
void Curl_Shutdown(void)
Definition libcurl.c:828
void NetConn_Shutdown(void)
Definition netconn.c:4201
#define CONFIGFILENAME
Definition quakedef.h:29
void SV_StopThread(void)
Definition sv_main.c:2860
void Sys_SDL_Shutdown(void)
INFO: This is only called by Host_Shutdown so we dont need testing for recursion.
Definition sys_null.c:9
void TaskQueue_Shutdown(void)
Definition taskqueue.c:60
void Thread_Shutdown(void)
Definition thread_null.c:9
void Memory_Shutdown(void)
Definition zone.c:897

References ca_dedicated, CL_Shutdown(), cls, Cmd_Shutdown(), Con_Shutdown(), CONFIGFILENAME, Crypto_Shutdown(), Curl_Shutdown(), host_static_t::hook, host, Host_SaveConfig(), Host_UnlockSession(), Log_Close(), Memory_Shutdown(), NetConn_Shutdown(), client_static_t::state, host_static_t::SV_Shutdown, SV_StopThread(), svs, Sys_AllowProfiling(), Sys_CheckParm(), Sys_SDL_Shutdown(), TaskQueue_Shutdown(), Thread_Shutdown(), and server_static_t::threaded.

Referenced by Sys_Frame().

◆ Host_UnlockSession()

void Host_UnlockSession ( void )

Definition at line 356 of file host.c.

357{
358 if(!locksession_run)
359 return;
360 locksession_run = false;
361
363 {
365 // NOTE: we can NOT unlink the lock here, as doing so would
366 // create a race condition if another process created it
367 // between our close and our unlink
369 }
370}

References FS_Close(), locksession_fh, locksession_run, and NULL.

Referenced by Host_Shutdown().

◆ Host_UpdateVersion()

void Host_UpdateVersion ( void )

Definition at line 162 of file host.c.

163{
164 dpsnprintf(engineversion, sizeof(engineversion), "%s %s%s %s", gamename ? gamename : "DarkPlaces", DP_OS_NAME, cls.state == ca_dedicated ? " dedicated" : "", buildstring);
165}
const char * buildstring
Definition builddate.c:5
const char * gamename
Definition com_game.c:27
int dpsnprintf(char *buffer, size_t buffersize, const char *format,...)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:997
#define DP_OS_NAME
Definition sys.h:95

References buildstring, ca_dedicated, cls, DP_OS_NAME, dpsnprintf(), engineversion, gamename, and client_static_t::state.

Referenced by COM_ChangeGameTypeForGameDirs(), and Host_Init().

Variable Documentation

◆ developer

cvar_t developer
extern

Definition at line 48 of file host.c.

48{CF_CLIENT | CF_SERVER | CF_ARCHIVE, "developer","0", "shows debugging messages and information (recommended for all developers and level designers); the value -1 also suppresses buffering and logging these messages"};
#define CF_SERVER
cvar/command that only the server can change/execute
Definition cmd.h:49
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48
#define CF_ARCHIVE
cvar should have its set value saved to config.cfg and persist across sessions
Definition cmd.h:53

Referenced by Con_DPrint(), Con_DPrintf(), Con_DrawConsole(), Con_MaskPrint(), Curl_GetDownloadInfo(), GL_Backend_CompileShader(), Host_Init(), Host_InitLocal(), IN_Move_TouchScreen_SteelStorm(), PRVM_ED_CallSpawnFunction(), SV_ReadClientMessage(), SV_SpawnServer(), Sys_Print(), VM_physics_addforce(), VM_physics_addtorque(), VM_physics_enable(), and VM_remove().

◆ developer_entityparsing

cvar_t developer_entityparsing
extern

Definition at line 53 of file host.c.

53{CF_CLIENT, "developer_entityparsing", "0", "prints detailed network entities information each time a packet is received"};

Referenced by Host_InitLocal(), PRVM_ED_ParseEdict(), PRVM_ED_ParseGlobals(), PRVM_ED_Write(), PRVM_ED_WriteGlobals(), and SV_Loadgame_f().

◆ developer_extra

◆ developer_insane

cvar_t developer_insane
extern

Definition at line 50 of file host.c.

50{CF_CLIENT | CF_SERVER, "developer_insane", "0", "prints huge streams of information about internal workings, entire contents of files being read/written, etc. Not recommended!"};

Referenced by Buffer_Callback(), CLVM_ExecuteProgram(), Host_Init(), Host_InitLocal(), Key_Event(), Mod_LoadQ3Shaders(), PRVM_SetEngineString(), PRVM_SetTempString(), and SVVM_ExecuteProgram().

◆ developer_loadfile

cvar_t developer_loadfile
extern

Definition at line 51 of file host.c.

51{CF_CLIENT | CF_SERVER, "developer_loadfile","0", "prints name and size of every file loaded via the FS_LoadFile function (which is almost everything)"};

Referenced by FS_LoadAndCloseQFile(), and Host_InitLocal().

◆ developer_loading

◆ host

host_static_t host
extern

Definition at line 41 of file host.c.

Referenced by Cbuf_Execute_Deferred(), CL_DisconnectEx(), CL_DrawVideo(), CL_FinishTimeDemo(), CL_Frame(), CL_GetVideoBySlot(), CL_Init(), CL_InitCommands(), CL_ParseServerMessage(), CL_Rcon_f(), CL_ReadDemoMessage(), CL_RestartVideo(), CL_SendMove(), CL_SetVideoState(), CL_StopPlayback(), CL_TimeDemo_f(), CL_UpdateScreen(), CL_Video_Frame(), CL_VM_Init(), Cmd_ExecuteString(), Cmd_Init(), Con_DrawConsole(), Con_DrawInput(), Crypto_ClientParsePacket(), Crypto_ServerFindInstance(), Crypto_ServerParsePacket(), CSQC_SetGlobals(), Curl_Frame(), Draw_Frame(), Host_AbortCurrentFrame(), Host_Error(), Host_Frame(), Host_Init(), Host_Quit_f(), Host_SaveConfig(), Host_Shutdown(), LHNET_Read(), LHNET_Write(), LHNETADDRESS_FromString(), M_Demo_Draw(), M_Draw(), M_GameOptions_Draw(), M_Keys_Draw(), M_LanConfig_Draw(), M_Load_Draw(), M_Main_Draw(), M_ModList_Draw(), M_MultiPlayer_Draw(), M_NetStart_Change(), M_Options_PrintCheckbox(), M_Options_PrintCommand(), M_Options_PrintSlider(), M_Quit_Key(), M_Save_Draw(), M_ServerList_Draw(), M_Setup_Draw(), M_SinglePlayer_Draw(), M_Video_Draw(), MP_Draw(), MP_Init(), NetConn_CanSend(), NetConn_ClientFrame(), NetConn_ClientParsePacket(), NetConn_Heartbeat(), NetConn_Open(), NetConn_PreventFlood(), NetConn_ReceivedMessage(), NetConn_SendUnreliableMessage(), NetConn_ServerParsePacket(), NetConn_UpdateCleartime(), NetConn_UpdateSockets(), OpenVideo(), PRVM_ED_CanAlloc(), PRVM_ED_ClearEdict(), PRVM_ED_Free(), PRVM_ED_LoadFromFile(), PRVM_ED_ParseEdict(), PRVM_Prog_Load(), R_RenderTarget_FreeUnused(), R_RenderTarget_Get(), R_Shadow_BounceGrid_AssignPhotons_Task(), R_Shadow_BounceGrid_ConvertPixelsAndUpload(), R_Shadow_PrepareLight(), R_Shadow_UpdateBounceGridTexture(), R_TimeReport_EndFrame(), R_View_UpdateEntityVisible(), R_View_WorldVisibility(), S_PaintAndSubmit(), S_Startup(), Sbar_DeathmatchOverlay(), Sbar_ShowFPS(), Sbar_ShowFPS_Update(), SCR_DrawNet(), SCR_DrawNetGraph_DrawGraph(), SCR_DrawQWDownload(), SCR_DrawScreen(), SendCvar_f(), SV_Changelevel_f(), SV_CheckTimeouts(), SV_ConnectClient(), SV_ExecuteClientMoves(), SV_Frame(), SV_Init(), SV_InitOperatorCommands(), SV_Loadgame_f(), SV_Map_f(), SV_MarkWriteEntityStateToClient(), SV_Name_f(), SV_Restart_f(), SV_Savegame_to(), SV_SendClientDatagram(), SV_SendServerinfo(), SV_SpawnServer(), SV_Status_f(), SV_ThreadFunc(), Sys_Error(), Sys_Frame(), Sys_HandleCrash(), Sys_HandleSignal(), Sys_SDL_HandleEvents(), Sys_Sleep(), VID_KeyEventForButton(), VID_TouchscreenCursor(), VM_CL_setpause(), VM_gettime(), VM_SV_setpause(), VM_Warning(), and WakeVideo().

◆ host_isclient

cvar_t host_isclient
extern

Definition at line 61 of file host.c.

61{CF_SHARED | CF_READONLY, "_host_isclient", "0", "If 1, clientside is active."};
#define CF_READONLY
cvar cannot be changed from the console or the command buffer, and is considered CF_PERSISTENT
Definition cmd.h:54
#define CF_SHARED
Definition cmd.h:67

Referenced by CL_Init(), Cmd_CL_Callback(), Host_InitLocal(), SV_BroadcastPrint(), SV_CheckTimeouts(), SV_IsLocalServer(), SV_Kick_f(), SV_Say(), SV_SendCvar_f(), and SV_SpawnServer().

◆ host_state_str

const char* const host_state_str[]
static
Initial value:
=
{
[host_init] = "init",
[host_loading] = "loading",
[host_active] = "normal operation",
[host_shutdown] = "shutdown",
[host_failing] = "crashing",
[host_failed] = "crashed",
}

Definition at line 31 of file host.h.

32{
33 [host_init] = "init",
34 [host_loading] = "loading",
35 [host_active] = "normal operation",
36 [host_shutdown] = "shutdown",
37 [host_failing] = "crashing",
38 [host_failed] = "crashed",
39};

Referenced by Host_Error().

◆ sessionid

cvar_t sessionid
extern

Definition at line 58 of file host.c.

58{CF_CLIENT | CF_SERVER | CF_READONLY, "sessionid", "", "ID of the current session (use the -sessionid parameter to set it); this is always either empty or begins with a dot (.)"};

Referenced by Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), Crypto_Keys_f(), Crypto_LoadKeys(), Crypto_SavePubKeyTextFile(), Host_InitSession(), and Host_LockSession().