2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // host.c -- coordinates spawning and killing of local servers
31 A server can always be started, even if the system started out as a client
34 A client can NOT be started if the system started as a dedicated server.
36 Memory is cleared / released when a server or client begins, not when they end.
40 // how many frames have occurred
41 // (checked by Host_Error and Host_SaveConfig_f)
43 // LordHavoc: set when quit is executed
44 qboolean host_shuttingdown = false;
46 double host_frametime;
47 // LordHavoc: the real frametime, before slowmo and clamping are applied (used for console scrolling)
48 double host_realframetime;
49 // the real time, without any slowmo or clamping
51 // realtime from previous frame
54 // used for -developer commandline parameter, hacky hacky
58 client_t *host_client;
60 jmp_buf host_abortframe;
62 // pretend frames take this amount of time (in seconds), 0 = realtime
63 cvar_t host_framerate = {0, "host_framerate","0", "locks frame timing to this value in seconds, 0.05 is 20fps for example, note that this can easily run too fast, use host_maxfps if you want to limit your framerate instead, or sys_ticrate to limit server speed"};
64 // shows time used by certain subsystems
65 cvar_t host_speeds = {0, "host_speeds","0", "reports how much time is used in server/graphics/sound"};
66 // LordHavoc: framerate independent slowmo
67 cvar_t slowmo = {0, "slowmo", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"};
68 // LordHavoc: framerate upper cap
69 cvar_t cl_maxfps = {CVAR_SAVE, "cl_maxfps", "1000", "maximum fps cap, if game is running faster than this it will wait before running another frame (useful to make cpu time available to other programs)"};
71 // print broadcast messages in dedicated mode
72 cvar_t sv_echobprint = {CVAR_SAVE, "sv_echobprint", "1", "prints gamecode bprint() calls to server console"};
74 cvar_t sys_ticrate = {CVAR_SAVE, "sys_ticrate","0.05", "how long a server frame is in seconds, 0.05 is 20fps server rate, 0.1 is 10fps (can not be set higher than 0.1), 0 runs as many server frames as possible (makes games against bots a little smoother, overwhelms network players)"};
75 cvar_t sv_fixedframeratesingleplayer = {0, "sv_fixedframeratesingleplayer", "0", "allows you to use server-style timing system in singleplayer (don't run faster than sys_ticrate)"};
76 cvar_t serverprofile = {0, "serverprofile","0", "print some timings on server code"};
78 cvar_t fraglimit = {CVAR_NOTIFY, "fraglimit","0", "ends level if this many frags is reached by any player"};
79 cvar_t timelimit = {CVAR_NOTIFY, "timelimit","0", "ends level at this time (in minutes)"};
80 cvar_t teamplay = {CVAR_NOTIFY, "teamplay","0", "teamplay mode, values depend on mod but typically 0 = no teams, 1 = no team damage no self damage, 2 = team damage and self damage, some mods support 3 = no team damage but can damage self"};
82 cvar_t samelevel = {CVAR_NOTIFY, "samelevel","0", "repeats same level if level ends (due to timelimit or someone hitting an exit)"};
83 cvar_t noexit = {CVAR_NOTIFY, "noexit","0", "kills anyone attempting to use an exit"};
85 cvar_t developer = {0, "developer","0", "prints additional debugging messages and information (recommended for modders and level designers)"};
86 cvar_t developer_entityparsing = {0, "developer_entityparsing", "0", "prints detailed network entities information each time a packet is received"};
88 cvar_t skill = {0, "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)"};
89 cvar_t deathmatch = {0, "deathmatch","0", "deathmatch mode, values depend on mod but typically 0 = no deathmatch, 1 = normal deathmatch with respawning weapons, 2 = weapons stay (players can only pick up new weapons)"};
90 cvar_t coop = {0, "coop","0", "coop mode, 0 = no coop, 1 = coop mode, multiple players playing through the singleplayer game (coop mode also shuts off deathmatch)"};
92 cvar_t pausable = {0, "pausable","1", "allow players to pause or not"};
94 cvar_t temp1 = {0, "temp1","0", "general cvar for mods to use, in stock id1 this selects which death animation to use on players (0 = random death, other values select specific death scenes)"};
96 cvar_t timestamps = {CVAR_SAVE, "timestamps", "0", "prints timestamps on console messages"};
97 cvar_t timeformat = {CVAR_SAVE, "timeformat", "[%b %e %X] ", "time format to use on timestamped console messages"};
101 Host_AbortCurrentFrame
103 aborts the current host frame and goes on with the next one
106 void Host_AbortCurrentFrame(void)
108 longjmp (host_abortframe, 1);
115 This shuts down both the client and server
118 void Host_Error (const char *error, ...)
120 static char hosterrorstring1[MAX_INPUTLINE];
121 static char hosterrorstring2[MAX_INPUTLINE];
122 static qboolean hosterror = false;
125 // turn off rcon redirect if it was active when the crash occurred
126 rcon_redirect = false;
128 va_start (argptr,error);
129 dpvsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr);
132 Con_Printf("Host_Error: %s\n", hosterrorstring1);
134 // LordHavoc: if crashing very early, or currently shutting down, do
136 if (host_framecount < 3 || host_shuttingdown)
137 Sys_Error ("Host_Error: %s", hosterrorstring1);
140 Sys_Error ("Host_Error: recursively entered (original error was: %s new error is: %s)", hosterrorstring2, hosterrorstring1);
143 strcpy(hosterrorstring2, hosterrorstring1);
145 CL_Parse_DumpPacket();
147 CL_Parse_ErrorCleanUp();
151 // print out where the crash happened, if it was caused by QC (and do a cleanup)
155 Host_ShutdownServer ();
157 if (cls.state == ca_dedicated)
158 Sys_Error ("Host_Error: %s",hosterrorstring2); // dedicated servers exit
165 Host_AbortCurrentFrame();
168 void Host_ServerOptions (void)
175 // COMMANDLINEOPTION: Server: -dedicated [playerlimit] starts a dedicated server (with a command console), default playerlimit is 8
176 // COMMANDLINEOPTION: Server: -listen [playerlimit] starts a multiplayer server with graphical client, like singleplayer but other players can connect, default playerlimit is 8
177 // if no client is in the executable or -dedicated is specified on
178 // commandline, start a dedicated server
179 i = COM_CheckParm ("-dedicated");
180 if (i || !cl_available)
182 cls.state = ca_dedicated;
183 // check for -dedicated specifying how many players
184 if (i && i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
185 svs.maxclients = atoi (com_argv[i+1]);
186 if (COM_CheckParm ("-listen"))
187 Con_Printf ("Only one of -dedicated or -listen can be specified\n");
188 // default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users)
189 Cvar_SetValue("sv_public", 1);
191 else if (cl_available)
193 // client exists and not dedicated, check if -listen is specified
194 cls.state = ca_disconnected;
195 i = COM_CheckParm ("-listen");
198 // default players unless specified
199 if (i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
200 svs.maxclients = atoi (com_argv[i+1]);
204 // default players in some games, singleplayer in most
205 if (gamemode != GAME_GOODVSBAD2 && gamemode != GAME_NEXUIZ && gamemode != GAME_BATTLEMECH)
210 svs.maxclients = bound(1, svs.maxclients, MAX_SCOREBOARD);
212 svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
214 if (svs.maxclients > 1 && !deathmatch.integer)
215 Cvar_SetValueQuick(&deathmatch, 1);
219 =======================
221 ======================
223 void Host_SaveConfig_f(void);
224 void Host_InitLocal (void)
226 Cmd_AddCommand("saveconfig", Host_SaveConfig_f, "save settings to config.cfg immediately (also automatic when quitting)");
228 Cvar_RegisterVariable (&host_framerate);
229 Cvar_RegisterVariable (&host_speeds);
230 Cvar_RegisterVariable (&slowmo);
231 Cvar_RegisterVariable (&cl_maxfps);
233 Cvar_RegisterVariable (&sv_echobprint);
235 Cvar_RegisterVariable (&sys_ticrate);
236 Cvar_RegisterVariable (&sv_fixedframeratesingleplayer);
237 Cvar_RegisterVariable (&serverprofile);
239 Cvar_RegisterVariable (&fraglimit);
240 Cvar_RegisterVariable (&timelimit);
241 Cvar_RegisterVariable (&teamplay);
242 Cvar_RegisterVariable (&samelevel);
243 Cvar_RegisterVariable (&noexit);
244 Cvar_RegisterVariable (&skill);
245 Cvar_RegisterVariable (&developer);
246 if (forcedeveloper) // make it real now that the cvar is registered
247 Cvar_SetValue("developer", 1);
248 Cvar_RegisterVariable (&developer_entityparsing);
249 Cvar_RegisterVariable (&deathmatch);
250 Cvar_RegisterVariable (&coop);
252 Cvar_RegisterVariable (&pausable);
254 Cvar_RegisterVariable (&temp1);
256 Cvar_RegisterVariable (×tamps);
257 Cvar_RegisterVariable (&timeformat);
265 Writes key bindings and archived cvars to config.cfg
268 void Host_SaveConfig_f(void)
272 // dedicated servers initialize the host but don't parse and set the
274 // LordHavoc: don't save a config if it crashed in startup
275 if (host_framecount >= 3 && cls.state != ca_dedicated)
277 f = FS_Open ("config.cfg", "wb", false, false);
280 Con_Print("Couldn't write config.cfg.\n");
284 Key_WriteBindings (f);
285 Cvar_WriteVariables (f);
296 Sends text across to be displayed
297 FIXME: make this just a stuffed echo?
300 void SV_ClientPrint(const char *msg)
302 if (host_client->netconnection)
304 MSG_WriteByte(&host_client->netconnection->message, svc_print);
305 MSG_WriteString(&host_client->netconnection->message, msg);
313 Sends text across to be displayed
314 FIXME: make this just a stuffed echo?
317 void SV_ClientPrintf(const char *fmt, ...)
320 char msg[MAX_INPUTLINE];
322 va_start(argptr,fmt);
323 dpvsnprintf(msg,sizeof(msg),fmt,argptr);
333 Sends text to all active clients
336 void SV_BroadcastPrint(const char *msg)
341 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
343 if (client->spawned && client->netconnection)
345 MSG_WriteByte(&client->netconnection->message, svc_print);
346 MSG_WriteString(&client->netconnection->message, msg);
350 if (sv_echobprint.integer && cls.state == ca_dedicated)
358 Sends text to all active clients
361 void SV_BroadcastPrintf(const char *fmt, ...)
364 char msg[MAX_INPUTLINE];
366 va_start(argptr,fmt);
367 dpvsnprintf(msg,sizeof(msg),fmt,argptr);
370 SV_BroadcastPrint(msg);
377 Send text over to the client to be executed
380 void Host_ClientCommands(const char *fmt, ...)
383 char string[MAX_INPUTLINE];
385 if (!host_client->netconnection)
388 va_start(argptr,fmt);
389 dpvsnprintf(string, sizeof(string), fmt, argptr);
392 MSG_WriteByte(&host_client->netconnection->message, svc_stufftext);
393 MSG_WriteString(&host_client->netconnection->message, string);
397 =====================
400 Called when the player is getting totally kicked off the host
401 if (crash = true), don't bother sending signofs
402 =====================
404 void SV_DropClient(qboolean crash)
407 Con_Printf("Client \"%s\" dropped\n", host_client->name);
409 // make sure edict is not corrupt (from a level change for example)
410 host_client->edict = PRVM_EDICT_NUM(host_client - svs.clients + 1);
412 if (host_client->netconnection)
414 // free the client (the body stays around)
417 // LordHavoc: no opportunity for resending, so use unreliable 3 times
418 unsigned char bufdata[8];
420 memset(&buf, 0, sizeof(buf));
422 buf.maxsize = sizeof(bufdata);
423 MSG_WriteByte(&buf, svc_disconnect);
424 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol);
425 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol);
426 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol);
428 // break the net connection
429 NetConn_Close(host_client->netconnection);
430 host_client->netconnection = NULL;
433 // call qc ClientDisconnect function
434 // LordHavoc: don't call QC if server is dead (avoids recursive
435 // Host_Error in some mods when they run out of edicts)
436 if (host_client->clientconnectcalled && sv.active && host_client->edict)
438 // call the prog function for removing a client
439 // this will set the body to a dead frame, among other things
440 int saveSelf = prog->globals.server->self;
441 host_client->clientconnectcalled = false;
442 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
443 PRVM_ExecuteProgram(prog->globals.server->ClientDisconnect, "QC function ClientDisconnect is missing");
444 prog->globals.server->self = saveSelf;
447 // remove leaving player from scoreboard
448 //host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
449 //if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
451 //host_client->edict->fields.server->frags = 0;
452 host_client->name[0] = 0;
453 host_client->colors = 0;
454 host_client->frags = 0;
455 // send notification to all clients
456 // get number of client manually just to make sure we get it right...
457 i = host_client - svs.clients;
458 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
459 MSG_WriteByte (&sv.reliable_datagram, i);
460 MSG_WriteString (&sv.reliable_datagram, host_client->name);
461 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
462 MSG_WriteByte (&sv.reliable_datagram, i);
463 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
464 MSG_WriteByte (&sv.reliable_datagram, svc_updatefrags);
465 MSG_WriteByte (&sv.reliable_datagram, i);
466 MSG_WriteShort (&sv.reliable_datagram, host_client->frags);
468 // free the client now
469 if (host_client->entitydatabase)
470 EntityFrame_FreeDatabase(host_client->entitydatabase);
471 if (host_client->entitydatabase4)
472 EntityFrame4_FreeDatabase(host_client->entitydatabase4);
473 if (host_client->entitydatabase5)
474 EntityFrame5_FreeDatabase(host_client->entitydatabase5);
478 // clear a fields that matter to DP_SV_CLIENTNAME and DP_SV_CLIENTCOLORS, and also frags
479 PRVM_ED_ClearEdict(host_client->edict);
482 // clear the client struct (this sets active to false)
483 memset(host_client, 0, sizeof(*host_client));
485 // update server listing on the master because player count changed
486 // (which the master uses for filtering empty/full servers)
487 NetConn_Heartbeat(1);
494 This only happens at the end of a game, not between levels
497 void Host_ShutdownServer(void)
501 Con_DPrintf("Host_ShutdownServer\n");
506 NetConn_Heartbeat(2);
507 NetConn_Heartbeat(2);
509 // make sure all the clients know we're disconnecting
511 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
512 if (host_client->active)
513 SV_DropClient(false); // server shutdown
516 NetConn_CloseServerPorts();
522 memset(&sv, 0, sizeof(sv));
523 memset(svs.clients, 0, svs.maxclients*sizeof(client_t));
531 This clears all the memory used by both the client and server, but does
532 not reinitialize anything.
535 void Host_ClearMemory (void)
537 Con_DPrint("Clearing memory\n");
541 memset (&sv, 0, sizeof(sv));
542 memset (&cl, 0, sizeof(cl));
546 //============================================================================
552 Returns false if the time is too short to run a frame
555 extern qboolean cl_capturevideo_active;
556 extern double cl_capturevideo_framerate;
557 extern qfile_t *cl_capturevideo_soundfile;
558 qboolean Host_FilterTime (double time)
560 double timecap, timeleft;
563 if (sys_ticrate.value < 0.00999 || sys_ticrate.value > 0.10001)
564 Cvar_SetValue("sys_ticrate", bound(0.01, sys_ticrate.value, 0.1));
565 if (slowmo.value < 0)
566 Cvar_SetValue("slowmo", 0);
567 if (host_framerate.value < 0.00001 && host_framerate.value != 0)
568 Cvar_SetValue("host_framerate", 0);
569 if (cl_maxfps.value < 1)
570 Cvar_SetValue("cl_maxfps", 1);
574 // disable time effects during timedemo
575 cl.frametime = host_realframetime = host_frametime = realtime - oldrealtime;
576 oldrealtime = realtime;
580 // check if framerate is too high
581 // default to sys_ticrate (server framerate - presumably low) unless we
582 // have a good reason to run faster
583 timecap = host_framerate.value;
585 timecap = sys_ticrate.value;
586 if (cls.state != ca_dedicated)
588 if (cl_capturevideo_active)
589 timecap = 1.0 / cl_capturevideo_framerate;
590 else if (vid_activewindow)
591 timecap = 1.0 / cl_maxfps.value;
594 timeleft = timecap - (realtime - oldrealtime);
598 if (timeleft * 1000 >= 10)
602 // don't totally hog the CPU
603 // try to hit exactly a steady framerate by not sleeping the full amount
604 msleft = (int)floor(timeleft * 1000);
611 // LordHavoc: copy into host_realframetime as well
612 host_realframetime = host_frametime = realtime - oldrealtime;
613 oldrealtime = realtime;
615 if (cl_capturevideo_active && !cl_capturevideo_soundfile)
616 host_frametime = timecap;
618 // apply slowmo scaling
619 host_frametime *= slowmo.value;
621 // host_framerate overrides all else
622 if (host_framerate.value)
623 host_frametime = host_framerate.value;
625 // never run a frame longer than 1 second
626 if (host_frametime > 1)
629 cl.frametime = host_frametime;
637 Host_GetConsoleCommands
639 Add them exactly as if they had been typed at the console
642 void Host_GetConsoleCommands (void)
648 cmd = Sys_ConsoleInput ();
661 void Host_ServerFrame (void)
663 // execute one or more server frames, with an upper limit on how much
664 // execution time to spend on server frames to avoid freezing the game if
665 // the server is overloaded, this execution time limit means the game will
666 // slow down if the server is taking too long.
667 int framecount, framelimit = 100;
668 double advancetime, aborttime;
674 sv.timer += host_realframetime;
676 // run the world state
677 // don't allow simulation to run too fast or too slow or logic glitches can occur
679 // setup the VM frame
681 // stop running server frames if the wall time reaches this value
682 aborttime = Sys_DoubleTime() + 0.05;
683 for (framecount = 0;framecount < framelimit && sv.timer > 0;framecount++)
685 if (sys_ticrate.value <= 0)
686 advancetime = sv.timer;
687 else if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
688 advancetime = min(sv.timer, sys_ticrate.value);
690 advancetime = sys_ticrate.value;
691 advancetime = min(advancetime, 0.1);
692 sv.timer -= advancetime;
694 // only advance time if not paused
695 // the game also pauses in singleplayer when menu or console is used
696 sv.frametime = advancetime * slowmo.value;
697 if (host_framerate.value)
698 sv.frametime = host_framerate.value;
699 if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive)))
702 // set the time and clear the general datagram
705 // move things around and think unless paused
709 // send all messages to the clients
710 SV_SendClientMessages();
712 // if this server frame took too long, break out of the loop
713 if (Sys_DoubleTime() >= aborttime)
717 // end the server VM frame
720 // send an heartbeat if enough time has passed since the last one
721 NetConn_Heartbeat(0);
723 // if we fell behind too many frames just don't worry about it
733 Runs all active servers
736 void _Host_Frame (float time)
738 static double time1 = 0;
739 static double time2 = 0;
740 static double time3 = 0;
741 int pass1, pass2, pass3;
743 if (setjmp(host_abortframe))
744 return; // something bad happened, or the server disconnected
746 // decide the simulation time
747 if (!Host_FilterTime(time))
750 // keep the random time dependent
753 cl.islocalgame = NetConn_IsLocalGame();
755 // get new key events
758 // Collect input into cmd
761 // process console commands
764 // if running the server locally, make intentions now
765 //if (cl.islocalgame)
768 //-------------------
772 //-------------------
774 // receive server packets now, which might contain rcon commands, which
775 // may change level or other such things we don't want to have happen in
776 // the middle of Host_Frame
777 NetConn_ServerFrame();
779 // check for commands typed to the host
780 Host_GetConsoleCommands();
785 //-------------------
789 //-------------------
791 cl.oldtime = cl.time;
792 cl.time += cl.frametime;
794 NetConn_ClientFrame();
796 if (cls.state == ca_connected)
799 // if running the server remotely, send intentions now after
800 // the incoming messages have been read
801 //if (!cl.islocalgame)
810 if (host_speeds.integer)
811 time1 = Sys_DoubleTime();
815 if (host_speeds.integer)
816 time2 = Sys_DoubleTime();
819 if(csqc_usecsqclistener)
821 S_Update(&csqc_listenermatrix);
822 csqc_usecsqclistener = false;
825 S_Update(&r_refdef.viewentitymatrix);
829 if (host_speeds.integer)
831 pass1 = (time1 - time3)*1000000;
832 time3 = Sys_DoubleTime();
833 pass2 = (time2 - time1)*1000000;
834 pass3 = (time3 - time2)*1000000;
835 Con_Printf("%6ius total %6ius server %6ius gfx %6ius snd\n",
836 pass1+pass2+pass3, pass1, pass2, pass3);
842 void Host_Frame (float time)
845 static double timetotal;
846 static int timecount;
849 if (!serverprofile.integer)
855 time1 = Sys_DoubleTime ();
857 time2 = Sys_DoubleTime ();
859 timetotal += time2 - time1;
862 if (timecount < 1000)
865 m = timetotal*1000/timecount;
869 for (i=0 ; i<svs.maxclients ; i++)
871 if (svs.clients[i].active)
875 Con_Printf("serverprofile: %2i clients %2i msec\n", c, m);
878 //============================================================================
880 qboolean vid_opened = false;
881 void Host_StartVideo(void)
883 if (!vid_opened && cls.state != ca_dedicated)
891 char engineversion[128];
893 qboolean sys_nostdout = false;
895 extern void Render_Init(void);
896 extern void Mathlib_Init(void);
897 extern void FS_Init(void);
898 extern void FS_Shutdown(void);
899 extern void PR_Cmd_Init(void);
900 extern void COM_Init_Commands(void);
901 extern void FS_Init_Commands(void);
902 extern void COM_CheckRegistered(void);
903 extern qboolean host_stuffcmdsrun;
910 void Host_Init (void)
915 // LordHavoc: quake never seeded the random number generator before... heh
918 // used by everything
921 // initialize console and logging
924 // initialize console command/cvar/alias/command execution systems
930 // initialize console window (only used by sys_win.c)
933 // detect gamemode from commandline options or executable name
936 // construct a version string for the corner of the console
937 #if defined(__linux__)
941 #elif defined(__FreeBSD__)
943 #elif defined(__NetBSD__)
945 #elif defined(__OpenBSD__)
947 #elif defined(MACOSX)
949 #elif defined(__MORPHOS__)
954 dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
956 // COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from
957 if (COM_CheckParm("-nostdout"))
960 Con_Printf("%s\n", engineversion);
962 // FIXME: this is evil, but possibly temporary
963 // COMMANDLINEOPTION: Console: -developer enables warnings and other notices (RECOMMENDED for mod developers)
964 if (COM_CheckParm("-developer"))
966 forcedeveloper = true;
967 developer.integer = 1;
971 // initialize filesystem (including fs_basedir, fs_gamedir, -path, -game, scr_screenshot_name)
974 // initialize various cvars that could not be initialized earlier
975 Memory_Init_Commands();
981 COM_CheckRegistered();
983 // initialize ixtable
994 Host_ServerOptions();
996 if (cls.state != ca_dedicated)
998 Con_Printf("Initializing client\n");
1013 // set up the default startmap_sp and startmap_dm aliases (mods can
1014 // override these) and then execute the quake.rc startup script
1015 if (gamemode == GAME_NEHAHRA)
1016 Cbuf_AddText("alias startmap_sp \"map nehstart\"\nalias startmap_dm \"map nehstart\"\nexec quake.rc\n");
1017 else if (gamemode == GAME_TRANSFUSION)
1018 Cbuf_AddText("alias startmap_sp \"map e1m1\"\n""alias startmap_dm \"map bb1\"\nexec quake.rc\n");
1019 else if (gamemode == GAME_TEU)
1020 Cbuf_AddText("alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec teu.rc\n");
1022 Cbuf_AddText("alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec quake.rc\n");
1025 // if stuffcmds wasn't run, then quake.rc is probably missing, use default
1026 if (!host_stuffcmdsrun)
1028 Cbuf_AddText("exec default.cfg\nexec config.cfg\nexec autoexec.cfg\nstuffcmds\n");
1032 // save console log up to this point to log_file if it was set by configs
1035 // FIXME: put this into some neat design, but the menu should be allowed to crash
1036 // without crashing the whole game, so this should just be a short-time solution
1039 // here comes the not so critical stuff
1040 if (setjmp(host_abortframe)) {
1044 if (cls.state != ca_dedicated)
1049 // check for special benchmark mode
1050 // 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)
1051 i = COM_CheckParm("-benchmark");
1052 if (i && i + 1 < com_argc)
1053 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1055 Cbuf_AddText(va("timedemo %s\n", com_argv[i + 1]));
1059 // check for special demo mode
1060 // COMMANDLINEOPTION: Client: -demo <demoname> runs a playdemo and quits
1061 i = COM_CheckParm("-demo");
1062 if (i && i + 1 < com_argc)
1063 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1065 Cbuf_AddText(va("playdemo %s\n", com_argv[i + 1]));
1069 // check for special demolooponly mode
1070 // COMMANDLINEOPTION: Client: -demolooponly <demoname> runs a playdemo and quits
1071 i = COM_CheckParm("-demolooponly");
1072 if (i && i + 1 < com_argc)
1073 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1075 Cbuf_AddText(va("playdemo %s\n", com_argv[i + 1]));
1079 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1080 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1082 Cbuf_AddText("startmap_dm\n");
1086 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1088 if (gamemode == GAME_NEXUIZ)
1089 Cbuf_AddText("togglemenu\nplayvideo logo\ncd loop 1\n");
1091 Cbuf_AddText("togglemenu\n");
1095 Con_DPrint("========Initialized=========\n");
1105 FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better
1106 to run quit through here before the final handoff to the sys code.
1109 void Host_Shutdown(void)
1111 static qboolean isdown = false;
1115 Con_Print("recursive shutdown\n");
1120 // be quiet while shutting down
1123 // disconnect client from server if active
1126 // shut down local server if active
1127 Host_ShutdownServer ();
1134 // AK hmm, no PRVM_Shutdown(); yet
1136 CL_Video_Shutdown();
1138 Host_SaveConfig_f();
1140 CDAudio_Shutdown ();
1142 NetConn_Shutdown ();
1145 if (cls.state != ca_dedicated)
1147 R_Modules_Shutdown();