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)
42 int host_framecount = 0;
43 // LordHavoc: set when quit is executed
44 qboolean host_shuttingdown = false;
46 // the real time since application started, without any slowmo or clamping
50 client_t *host_client;
52 jmp_buf host_abortframe;
54 // pretend frames take this amount of time (in seconds), 0 = realtime
55 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"};
56 // shows time used by certain subsystems
57 cvar_t host_speeds = {0, "host_speeds","0", "reports how much time is used in server/graphics/sound"};
58 // LordHavoc: framerate independent slowmo
59 cvar_t slowmo = {0, "slowmo", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"};
60 // LordHavoc: framerate upper cap
61 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)"};
63 // print broadcast messages in dedicated mode
64 cvar_t sv_echobprint = {CVAR_SAVE, "sv_echobprint", "1", "prints gamecode bprint() calls to server console"};
66 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)"};
67 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)"};
69 cvar_t fraglimit = {CVAR_NOTIFY, "fraglimit","0", "ends level if this many frags is reached by any player"};
70 cvar_t timelimit = {CVAR_NOTIFY, "timelimit","0", "ends level at this time (in minutes)"};
71 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"};
73 cvar_t samelevel = {CVAR_NOTIFY, "samelevel","0", "repeats same level if level ends (due to timelimit or someone hitting an exit)"};
74 cvar_t noexit = {CVAR_NOTIFY, "noexit","0", "kills anyone attempting to use an exit"};
76 cvar_t developer = {0, "developer","0", "prints additional debugging messages and information (recommended for modders and level designers)"};
77 cvar_t developer_entityparsing = {0, "developer_entityparsing", "0", "prints detailed network entities information each time a packet is received"};
79 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)"};
80 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)"};
81 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)"};
83 cvar_t pausable = {0, "pausable","1", "allow players to pause or not"};
85 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)"};
87 cvar_t timestamps = {CVAR_SAVE, "timestamps", "0", "prints timestamps on console messages"};
88 cvar_t timeformat = {CVAR_SAVE, "timeformat", "[%b %e %X] ", "time format to use on timestamped console messages"};
92 Host_AbortCurrentFrame
94 aborts the current host frame and goes on with the next one
97 void Host_AbortCurrentFrame(void)
99 longjmp (host_abortframe, 1);
106 This shuts down both the client and server
109 void Host_Error (const char *error, ...)
111 static char hosterrorstring1[MAX_INPUTLINE];
112 static char hosterrorstring2[MAX_INPUTLINE];
113 static qboolean hosterror = false;
116 // turn off rcon redirect if it was active when the crash occurred
117 rcon_redirect = false;
119 va_start (argptr,error);
120 dpvsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr);
123 Con_Printf("Host_Error: %s\n", hosterrorstring1);
125 // LordHavoc: if crashing very early, or currently shutting down, do
127 if (host_framecount < 3 || host_shuttingdown)
128 Sys_Error ("Host_Error: %s", hosterrorstring1);
131 Sys_Error ("Host_Error: recursively entered (original error was: %s new error is: %s)", hosterrorstring2, hosterrorstring1);
134 strcpy(hosterrorstring2, hosterrorstring1);
136 CL_Parse_DumpPacket();
138 CL_Parse_ErrorCleanUp();
142 // print out where the crash happened, if it was caused by QC (and do a cleanup)
146 Host_ShutdownServer ();
148 if (cls.state == ca_dedicated)
149 Sys_Error ("Host_Error: %s",hosterrorstring2); // dedicated servers exit
156 Host_AbortCurrentFrame();
159 void Host_ServerOptions (void)
166 // COMMANDLINEOPTION: Server: -dedicated [playerlimit] starts a dedicated server (with a command console), default playerlimit is 8
167 // COMMANDLINEOPTION: Server: -listen [playerlimit] starts a multiplayer server with graphical client, like singleplayer but other players can connect, default playerlimit is 8
168 // if no client is in the executable or -dedicated is specified on
169 // commandline, start a dedicated server
170 i = COM_CheckParm ("-dedicated");
171 if (i || !cl_available)
173 cls.state = ca_dedicated;
174 // check for -dedicated specifying how many players
175 if (i && i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
176 svs.maxclients = atoi (com_argv[i+1]);
177 if (COM_CheckParm ("-listen"))
178 Con_Printf ("Only one of -dedicated or -listen can be specified\n");
179 // default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users)
180 Cvar_SetValue("sv_public", 1);
182 else if (cl_available)
184 // client exists and not dedicated, check if -listen is specified
185 cls.state = ca_disconnected;
186 i = COM_CheckParm ("-listen");
189 // default players unless specified
190 if (i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
191 svs.maxclients = atoi (com_argv[i+1]);
195 // default players in some games, singleplayer in most
196 if (gamemode != GAME_GOODVSBAD2 && gamemode != GAME_NEXUIZ && gamemode != GAME_BATTLEMECH)
201 svs.maxclients = bound(1, svs.maxclients, MAX_SCOREBOARD);
203 svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
205 if (svs.maxclients > 1 && !deathmatch.integer && !coop.integer)
206 Cvar_SetValueQuick(&deathmatch, 1);
210 =======================
212 ======================
214 void Host_SaveConfig_f(void);
215 static void Host_InitLocal (void)
217 Cmd_AddCommand("saveconfig", Host_SaveConfig_f, "save settings to config.cfg immediately (also automatic when quitting)");
219 Cvar_RegisterVariable (&host_framerate);
220 Cvar_RegisterVariable (&host_speeds);
221 Cvar_RegisterVariable (&slowmo);
222 Cvar_RegisterVariable (&cl_maxfps);
224 Cvar_RegisterVariable (&sv_echobprint);
226 Cvar_RegisterVariable (&sys_ticrate);
227 Cvar_RegisterVariable (&sv_fixedframeratesingleplayer);
229 Cvar_RegisterVariable (&fraglimit);
230 Cvar_RegisterVariable (&timelimit);
231 Cvar_RegisterVariable (&teamplay);
232 Cvar_RegisterVariable (&samelevel);
233 Cvar_RegisterVariable (&noexit);
234 Cvar_RegisterVariable (&skill);
235 Cvar_RegisterVariable (&developer);
236 Cvar_RegisterVariable (&developer_entityparsing);
237 Cvar_RegisterVariable (&deathmatch);
238 Cvar_RegisterVariable (&coop);
240 Cvar_RegisterVariable (&pausable);
242 Cvar_RegisterVariable (&temp1);
244 Cvar_RegisterVariable (×tamps);
245 Cvar_RegisterVariable (&timeformat);
253 Writes key bindings and archived cvars to config.cfg
256 void Host_SaveConfig_f(void)
260 // dedicated servers initialize the host but don't parse and set the
262 // LordHavoc: don't save a config if it crashed in startup
263 if (host_framecount >= 3 && cls.state != ca_dedicated)
265 f = FS_Open ("config.cfg", "wb", false, false);
268 Con_Print("Couldn't write config.cfg.\n");
272 Key_WriteBindings (f);
273 Cvar_WriteVariables (f);
284 Sends text across to be displayed
285 FIXME: make this just a stuffed echo?
288 void SV_ClientPrint(const char *msg)
290 if (host_client->netconnection)
292 MSG_WriteByte(&host_client->netconnection->message, svc_print);
293 MSG_WriteString(&host_client->netconnection->message, msg);
301 Sends text across to be displayed
302 FIXME: make this just a stuffed echo?
305 void SV_ClientPrintf(const char *fmt, ...)
308 char msg[MAX_INPUTLINE];
310 va_start(argptr,fmt);
311 dpvsnprintf(msg,sizeof(msg),fmt,argptr);
321 Sends text to all active clients
324 void SV_BroadcastPrint(const char *msg)
329 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
331 if (client->spawned && client->netconnection)
333 MSG_WriteByte(&client->netconnection->message, svc_print);
334 MSG_WriteString(&client->netconnection->message, msg);
338 if (sv_echobprint.integer && cls.state == ca_dedicated)
346 Sends text to all active clients
349 void SV_BroadcastPrintf(const char *fmt, ...)
352 char msg[MAX_INPUTLINE];
354 va_start(argptr,fmt);
355 dpvsnprintf(msg,sizeof(msg),fmt,argptr);
358 SV_BroadcastPrint(msg);
365 Send text over to the client to be executed
368 void Host_ClientCommands(const char *fmt, ...)
371 char string[MAX_INPUTLINE];
373 if (!host_client->netconnection)
376 va_start(argptr,fmt);
377 dpvsnprintf(string, sizeof(string), fmt, argptr);
380 MSG_WriteByte(&host_client->netconnection->message, svc_stufftext);
381 MSG_WriteString(&host_client->netconnection->message, string);
385 =====================
388 Called when the player is getting totally kicked off the host
389 if (crash = true), don't bother sending signofs
390 =====================
392 void SV_DropClient(qboolean crash)
395 Con_Printf("Client \"%s\" dropped\n", host_client->name);
397 // make sure edict is not corrupt (from a level change for example)
398 host_client->edict = PRVM_EDICT_NUM(host_client - svs.clients + 1);
400 if (host_client->netconnection)
402 // free the client (the body stays around)
405 // LordHavoc: no opportunity for resending, so use unreliable 3 times
406 unsigned char bufdata[8];
408 memset(&buf, 0, sizeof(buf));
410 buf.maxsize = sizeof(bufdata);
411 MSG_WriteByte(&buf, svc_disconnect);
412 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol);
413 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol);
414 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol);
416 // break the net connection
417 NetConn_Close(host_client->netconnection);
418 host_client->netconnection = NULL;
421 // call qc ClientDisconnect function
422 // LordHavoc: don't call QC if server is dead (avoids recursive
423 // Host_Error in some mods when they run out of edicts)
424 if (host_client->clientconnectcalled && sv.active && host_client->edict)
426 // call the prog function for removing a client
427 // this will set the body to a dead frame, among other things
428 int saveSelf = prog->globals.server->self;
429 host_client->clientconnectcalled = false;
430 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
431 PRVM_ExecuteProgram(prog->globals.server->ClientDisconnect, "QC function ClientDisconnect is missing");
432 prog->globals.server->self = saveSelf;
435 // remove leaving player from scoreboard
436 //host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
437 //if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
439 //host_client->edict->fields.server->frags = 0;
440 host_client->name[0] = 0;
441 host_client->colors = 0;
442 host_client->frags = 0;
443 // send notification to all clients
444 // get number of client manually just to make sure we get it right...
445 i = host_client - svs.clients;
446 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
447 MSG_WriteByte (&sv.reliable_datagram, i);
448 MSG_WriteString (&sv.reliable_datagram, host_client->name);
449 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
450 MSG_WriteByte (&sv.reliable_datagram, i);
451 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
452 MSG_WriteByte (&sv.reliable_datagram, svc_updatefrags);
453 MSG_WriteByte (&sv.reliable_datagram, i);
454 MSG_WriteShort (&sv.reliable_datagram, host_client->frags);
456 // free the client now
457 if (host_client->entitydatabase)
458 EntityFrame_FreeDatabase(host_client->entitydatabase);
459 if (host_client->entitydatabase4)
460 EntityFrame4_FreeDatabase(host_client->entitydatabase4);
461 if (host_client->entitydatabase5)
462 EntityFrame5_FreeDatabase(host_client->entitydatabase5);
466 // clear a fields that matter to DP_SV_CLIENTNAME and DP_SV_CLIENTCOLORS, and also frags
467 PRVM_ED_ClearEdict(host_client->edict);
470 // clear the client struct (this sets active to false)
471 memset(host_client, 0, sizeof(*host_client));
473 // update server listing on the master because player count changed
474 // (which the master uses for filtering empty/full servers)
475 NetConn_Heartbeat(1);
482 This only happens at the end of a game, not between levels
485 void Host_ShutdownServer(void)
489 Con_DPrintf("Host_ShutdownServer\n");
494 NetConn_Heartbeat(2);
495 NetConn_Heartbeat(2);
497 // make sure all the clients know we're disconnecting
499 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
500 if (host_client->active)
501 SV_DropClient(false); // server shutdown
504 NetConn_CloseServerPorts();
510 memset(&sv, 0, sizeof(sv));
511 memset(svs.clients, 0, svs.maxclients*sizeof(client_t));
515 //============================================================================
519 Host_GetConsoleCommands
521 Add them exactly as if they had been typed at the console
524 void Host_GetConsoleCommands (void)
530 cmd = Sys_ConsoleInput ();
541 Runs all active servers
544 static void Host_Init(void);
547 static double time1 = 0;
548 static double time2 = 0;
549 static double time3 = 0;
550 // these are static because of setjmp/longjmp warnings in mingw32 gcc 2.95.3
551 static double frameoldtime, framenewtime, frametime, cl_timer, sv_timer;
558 framenewtime = Sys_DoubleTime();
561 if (setjmp(host_abortframe))
562 continue; // something bad happened, or the server disconnected
564 frameoldtime = framenewtime;
565 framenewtime = Sys_DoubleTime();
566 frametime = framenewtime - frameoldtime;
567 realtime += frametime;
569 // if there is some time remaining from last frame, rest the timers
575 // accumulate the new frametime into the timers
576 cl_timer += frametime;
577 sv_timer += frametime;
579 if (slowmo.value < 0)
580 Cvar_SetValue("slowmo", 0);
581 if (host_framerate.value < 0.00001 && host_framerate.value != 0)
582 Cvar_SetValue("host_framerate", 0);
583 if (cl_maxfps.value < 1)
584 Cvar_SetValue("cl_maxfps", 1);
586 // if the accumulators haven't become positive yet, keep waiting
587 if (!cls.timedemo && cl_timer <= 0 && sv_timer <= 0)
591 if (cls.state == ca_dedicated)
596 wait = max(cl_timer, sv_timer);
597 msleft = (int)floor(wait * -1000.0);
603 // keep the random time dependent
606 cl.islocalgame = NetConn_IsLocalGame();
608 // get new key events
611 // when a server is running we only execute console commands on server frames
612 // (this mainly allows frikbot .way config files to work properly by staying in sync with the server qc)
613 // otherwise we execute them on all frames
614 if (sv_timer > 0 || !sv.active)
616 // process console commands
620 NetConn_UpdateSockets();
622 //-------------------
626 //-------------------
632 // if there is no server, run server timing at 10fps
637 // execute one or more server frames, with an upper limit on how much
638 // execution time to spend on server frames to avoid freezing the game if
639 // the server is overloaded, this execution time limit means the game will
640 // slow down if the server is taking too long.
641 int framecount, framelimit = 1;
642 double advancetime, aborttime = 0;
644 // receive server packets now, which might contain rcon commands, which
645 // may change level or other such things we don't want to have happen in
646 // the middle of Host_Frame
647 NetConn_ServerFrame();
649 // check for commands typed to the host
650 Host_GetConsoleCommands();
652 // run the world state
653 // don't allow simulation to run too fast or too slow or logic glitches can occur
655 // stop running server frames if the wall time reaches this value
656 if (sys_ticrate.value <= 0 || (cl.islocalgame && !sv_fixedframeratesingleplayer.integer))
657 advancetime = sv_timer;
660 advancetime = sys_ticrate.value;
661 // listen servers can run multiple server frames per client frame
662 if (cls.state == ca_connected)
665 aborttime = Sys_DoubleTime() + 0.1;
668 advancetime = min(advancetime, 0.1);
670 // only advance time if not paused
671 // the game also pauses in singleplayer when menu or console is used
672 sv.frametime = advancetime * slowmo.value;
673 if (host_framerate.value)
674 sv.frametime = host_framerate.value;
675 if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive)))
678 // setup the VM frame
681 for (framecount = 0;framecount < framelimit && sv_timer > 0;framecount++)
683 sv_timer -= advancetime;
685 // move things around and think unless paused
689 // send all messages to the clients
690 SV_SendClientMessages();
692 // clear the general datagram
695 // if this server frame took too long, break out of the loop
696 if (framelimit > 1 && Sys_DoubleTime() >= aborttime)
700 // end the server VM frame
703 // send an heartbeat if enough time has passed since the last one
704 NetConn_Heartbeat(0);
708 //-------------------
712 //-------------------
714 if (cl_timer > 0 || cls.timedemo)
716 if (cls.state == ca_dedicated)
718 // if there is no client, run client timing at 10fps
720 if (host_speeds.integer)
721 time1 = time2 = Sys_DoubleTime();
726 frametime = cl.realframetime = min(cl_timer, 1);
728 // decide the simulation time
731 if (cls.capturevideo_active && !cls.capturevideo_soundfile)
733 frametime = 1.0 / cls.capturevideo_framerate;
734 cl.realframetime = max(cl.realframetime, frametime);
736 else if (vid_activewindow)
737 frametime = cl.realframetime = max(cl.realframetime, 1.0 / cl_maxfps.value);
739 frametime = cl.realframetime = 0.1;
741 // deduct the frame time from the accumulator
742 cl_timer -= cl.realframetime;
744 // apply slowmo scaling
745 frametime *= slowmo.value;
747 // host_framerate overrides all else
748 if (host_framerate.value)
749 frametime = host_framerate.value;
752 cl.oldtime = cl.time;
753 cl.time += frametime;
755 // Collect input into cmd
758 NetConn_ClientFrame();
760 if (cls.state == ca_connected)
763 // if running the server remotely, send intentions now after
764 // the incoming messages have been read
765 //if (!cl.islocalgame)
770 if (host_speeds.integer)
771 time1 = Sys_DoubleTime();
779 if (host_speeds.integer)
780 time2 = Sys_DoubleTime();
783 if(csqc_usecsqclistener)
785 S_Update(&csqc_listenermatrix);
786 csqc_usecsqclistener = false;
789 S_Update(&r_refdef.viewentitymatrix);
794 if (host_speeds.integer)
796 int pass1, pass2, pass3;
797 pass1 = (int)((time1 - time3)*1000000);
798 time3 = Sys_DoubleTime();
799 pass2 = (int)((time2 - time1)*1000000);
800 pass3 = (int)((time3 - time2)*1000000);
801 Con_Printf("%6ius total %6ius server %6ius gfx %6ius snd\n",
802 pass1+pass2+pass3, pass1, pass2, pass3);
810 //============================================================================
812 qboolean vid_opened = false;
813 void Host_StartVideo(void)
815 if (!vid_opened && cls.state != ca_dedicated)
823 char engineversion[128];
825 qboolean sys_nostdout = false;
827 extern void Render_Init(void);
828 extern void Mathlib_Init(void);
829 extern void FS_Init(void);
830 extern void FS_Shutdown(void);
831 extern void PR_Cmd_Init(void);
832 extern void COM_Init_Commands(void);
833 extern void FS_Init_Commands(void);
834 extern void COM_CheckRegistered(void);
835 extern qboolean host_stuffcmdsrun;
842 static void Host_Init (void)
847 // FIXME: this is evil, but possibly temporary
848 // COMMANDLINEOPTION: Console: -developer enables warnings and other notices (RECOMMENDED for mod developers)
849 if (COM_CheckParm("-developer"))
851 developer.value = developer.integer = 100;
852 developer.string = "100";
855 if (COM_CheckParm("-developer2"))
857 developer.value = developer.integer = 100;
858 developer.string = "100";
859 developer_memory.value = developer_memory.integer = 100;
860 developer.string = "100";
861 developer_memorydebug.value = developer_memorydebug.integer = 100;
862 developer_memorydebug.string = "100";
865 // LordHavoc: quake never seeded the random number generator before... heh
868 // used by everything
871 // initialize console and logging
874 // initialize console command/cvar/alias/command execution systems
880 // initialize console window (only used by sys_win.c)
883 // detect gamemode from commandline options or executable name
886 // construct a version string for the corner of the console
887 #if defined(__linux__)
891 #elif defined(__FreeBSD__)
893 #elif defined(__NetBSD__)
895 #elif defined(__OpenBSD__)
897 #elif defined(MACOSX)
899 #elif defined(__MORPHOS__)
904 dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
906 // COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from
907 if (COM_CheckParm("-nostdout"))
910 Con_Printf("%s\n", engineversion);
912 // initialize filesystem (including fs_basedir, fs_gamedir, -path, -game, scr_screenshot_name)
915 // initialize various cvars that could not be initialized earlier
916 Memory_Init_Commands();
922 COM_CheckRegistered();
924 // initialize ixtable
935 Host_ServerOptions();
937 if (cls.state != ca_dedicated)
939 Con_Printf("Initializing client\n");
954 // set up the default startmap_sp and startmap_dm aliases (mods can
955 // override these) and then execute the quake.rc startup script
956 if (gamemode == GAME_NEHAHRA)
957 Cbuf_AddText("alias startmap_sp \"map nehstart\"\nalias startmap_dm \"map nehstart\"\nexec quake.rc\n");
958 else if (gamemode == GAME_TRANSFUSION)
959 Cbuf_AddText("alias startmap_sp \"map e1m1\"\n""alias startmap_dm \"map bb1\"\nexec quake.rc\n");
960 else if (gamemode == GAME_TEU)
961 Cbuf_AddText("alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec teu.rc\n");
963 Cbuf_AddText("alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec quake.rc\n");
966 // if stuffcmds wasn't run, then quake.rc is probably missing, use default
967 if (!host_stuffcmdsrun)
969 Cbuf_AddText("exec default.cfg\nexec config.cfg\nexec autoexec.cfg\nstuffcmds\n");
973 // put up the loading image so the user doesn't stare at a black screen...
974 SCR_BeginLoadingPlaque();
976 // FIXME: put this into some neat design, but the menu should be allowed to crash
977 // without crashing the whole game, so this should just be a short-time solution
979 // here comes the not so critical stuff
980 if (setjmp(host_abortframe)) {
984 if (cls.state != ca_dedicated)
989 // check for special benchmark mode
990 // 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)
991 i = COM_CheckParm("-benchmark");
992 if (i && i + 1 < com_argc)
993 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
995 Cbuf_AddText(va("timedemo %s\n", com_argv[i + 1]));
999 // check for special demo mode
1000 // COMMANDLINEOPTION: Client: -demo <demoname> runs a playdemo and quits
1001 i = COM_CheckParm("-demo");
1002 if (i && i + 1 < com_argc)
1003 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1005 Cbuf_AddText(va("playdemo %s\n", com_argv[i + 1]));
1009 // check for special demolooponly mode
1010 // COMMANDLINEOPTION: Client: -demolooponly <demoname> runs a playdemo and quits
1011 i = COM_CheckParm("-demolooponly");
1012 if (i && i + 1 < com_argc)
1013 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1015 Cbuf_AddText(va("playdemo %s\n", com_argv[i + 1]));
1019 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1020 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1022 Cbuf_AddText("startmap_dm\n");
1026 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1028 if (gamemode == GAME_NEXUIZ)
1029 Cbuf_AddText("togglemenu\nplayvideo logo\ncd loop 1\n");
1031 Cbuf_AddText("togglemenu\n");
1035 Con_DPrint("========Initialized=========\n");
1037 //Host_StartVideo();
1045 FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better
1046 to run quit through here before the final handoff to the sys code.
1049 void Host_Shutdown(void)
1051 static qboolean isdown = false;
1055 Con_Print("recursive shutdown\n");
1060 // be quiet while shutting down
1063 // disconnect client from server if active
1066 // shut down local server if active
1067 Host_ShutdownServer ();
1074 // AK hmm, no PRVM_Shutdown(); yet
1076 CL_Video_Shutdown();
1078 Host_SaveConfig_f();
1080 CDAudio_Shutdown ();
1082 NetConn_Shutdown ();
1085 if (cls.state != ca_dedicated)
1087 R_Modules_Shutdown();