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
32 A server can always be started, even if the system started out as a client
35 A client can NOT be started if the system started as a dedicated server.
37 Memory is cleared / released when a server or client begins, not when they end.
41 // how many frames have occurred
42 // (checked by Host_Error and Host_SaveConfig_f)
43 int host_framecount = 0;
44 // LordHavoc: set when quit is executed
45 qboolean host_shuttingdown = false;
47 // the real time since application started, without any slowmo or clamping
51 client_t *host_client;
53 jmp_buf host_abortframe;
56 cvar_t sv_random_seed = {0, "sv_random_seed", "", "random seed; when set, on every map start this random seed is used to initialize the random number generator. Don't touch it unless for benchmarking or debugging"};
58 // pretend frames take this amount of time (in seconds), 0 = realtime
59 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 cl_maxfps if you want to limit your framerate instead, or sys_ticrate to limit server speed"};
60 // shows time used by certain subsystems
61 cvar_t host_speeds = {0, "host_speeds","0", "reports how much time is used in server/graphics/sound"};
62 // LordHavoc: framerate independent slowmo
63 cvar_t slowmo = {0, "slowmo", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"};
64 // LordHavoc: framerate upper cap
65 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)"};
67 // print broadcast messages in dedicated mode
68 cvar_t sv_echobprint = {CVAR_SAVE, "sv_echobprint", "1", "prints gamecode bprint() calls to server console"};
70 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)"};
71 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)"};
73 cvar_t fraglimit = {CVAR_NOTIFY, "fraglimit","0", "ends level if this many frags is reached by any player"};
74 cvar_t timelimit = {CVAR_NOTIFY, "timelimit","0", "ends level at this time (in minutes)"};
75 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"};
77 cvar_t samelevel = {CVAR_NOTIFY, "samelevel","0", "repeats same level if level ends (due to timelimit or someone hitting an exit)"};
78 cvar_t noexit = {CVAR_NOTIFY, "noexit","0", "kills anyone attempting to use an exit"};
80 cvar_t developer = {0, "developer","0", "prints additional debugging messages and information (recommended for modders and level designers)"};
81 cvar_t developer_entityparsing = {0, "developer_entityparsing", "0", "prints detailed network entities information each time a packet is received"};
83 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)"};
84 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)"};
85 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)"};
87 cvar_t pausable = {0, "pausable","1", "allow players to pause or not"};
89 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)"};
91 cvar_t timestamps = {CVAR_SAVE, "timestamps", "0", "prints timestamps on console messages"};
92 cvar_t timeformat = {CVAR_SAVE, "timeformat", "[%Y-%m-%d %H:%M:%S] ", "time format to use on timestamped console messages"};
94 cvar_t sv_checkforpacketsduringsleep = {0, "sv_checkforpacketsduringsleep", "0", "uses select() function to wait between frames which can be interrupted by packets being received, instead of Sleep()/usleep()/SDL_Sleep() functions which do not check for packets"};
98 Host_AbortCurrentFrame
100 aborts the current host frame and goes on with the next one
103 void Host_AbortCurrentFrame(void)
105 longjmp (host_abortframe, 1);
112 This shuts down both the client and server
115 void Host_Error (const char *error, ...)
117 static char hosterrorstring1[MAX_INPUTLINE];
118 static char hosterrorstring2[MAX_INPUTLINE];
119 static qboolean hosterror = false;
122 // turn off rcon redirect if it was active when the crash occurred
123 rcon_redirect = false;
125 va_start (argptr,error);
126 dpvsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr);
129 Con_Printf("Host_Error: %s\n", hosterrorstring1);
131 // LordHavoc: if crashing very early, or currently shutting down, do
133 if (host_framecount < 3 || host_shuttingdown)
134 Sys_Error ("Host_Error: %s", hosterrorstring1);
137 Sys_Error ("Host_Error: recursively entered (original error was: %s new error is: %s)", hosterrorstring2, hosterrorstring1);
140 strlcpy(hosterrorstring2, hosterrorstring1, sizeof(hosterrorstring2));
142 CL_Parse_DumpPacket();
144 CL_Parse_ErrorCleanUp();
148 // print out where the crash happened, if it was caused by QC (and do a cleanup)
152 Host_ShutdownServer ();
154 if (cls.state == ca_dedicated)
155 Sys_Error ("Host_Error: %s",hosterrorstring2); // dedicated servers exit
162 Host_AbortCurrentFrame();
165 void Host_ServerOptions (void)
172 // COMMANDLINEOPTION: Server: -dedicated [playerlimit] starts a dedicated server (with a command console), default playerlimit is 8
173 // COMMANDLINEOPTION: Server: -listen [playerlimit] starts a multiplayer server with graphical client, like singleplayer but other players can connect, default playerlimit is 8
174 // if no client is in the executable or -dedicated is specified on
175 // commandline, start a dedicated server
176 i = COM_CheckParm ("-dedicated");
177 if (i || !cl_available)
179 cls.state = ca_dedicated;
180 // check for -dedicated specifying how many players
181 if (i && i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
182 svs.maxclients = atoi (com_argv[i+1]);
183 if (COM_CheckParm ("-listen"))
184 Con_Printf ("Only one of -dedicated or -listen can be specified\n");
185 // default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users)
186 Cvar_SetValue("sv_public", 1);
188 else if (cl_available)
190 // client exists and not dedicated, check if -listen is specified
191 cls.state = ca_disconnected;
192 i = COM_CheckParm ("-listen");
195 // default players unless specified
196 if (i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
197 svs.maxclients = atoi (com_argv[i+1]);
201 // default players in some games, singleplayer in most
202 if (gamemode != GAME_GOODVSBAD2 && gamemode != GAME_NEXUIZ && gamemode != GAME_BATTLEMECH)
207 svs.maxclients = bound(1, svs.maxclients, MAX_SCOREBOARD);
209 svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
211 if (svs.maxclients > 1 && !deathmatch.integer && !coop.integer)
212 Cvar_SetValueQuick(&deathmatch, 1);
216 =======================
218 ======================
220 void Host_SaveConfig_f(void);
221 void Host_LoadConfig_f(void);
222 static void Host_InitLocal (void)
224 Cmd_AddCommand("saveconfig", Host_SaveConfig_f, "save settings to config.cfg immediately (also automatic when quitting)");
225 Cmd_AddCommand("loadconfig", Host_LoadConfig_f, "reset everything and reload configs");
227 Cvar_RegisterVariable (&sv_random_seed);
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);
238 Cvar_RegisterVariable (&fraglimit);
239 Cvar_RegisterVariable (&timelimit);
240 Cvar_RegisterVariable (&teamplay);
241 Cvar_RegisterVariable (&samelevel);
242 Cvar_RegisterVariable (&noexit);
243 Cvar_RegisterVariable (&skill);
244 Cvar_RegisterVariable (&developer);
245 Cvar_RegisterVariable (&developer_entityparsing);
246 Cvar_RegisterVariable (&deathmatch);
247 Cvar_RegisterVariable (&coop);
249 Cvar_RegisterVariable (&pausable);
251 Cvar_RegisterVariable (&temp1);
253 Cvar_RegisterVariable (×tamps);
254 Cvar_RegisterVariable (&timeformat);
256 Cvar_RegisterVariable (&sv_checkforpacketsduringsleep);
264 Writes key bindings and archived cvars to config.cfg
267 void Host_SaveConfig_f(void)
271 // dedicated servers initialize the host but don't parse and set the
273 // LordHavoc: don't save a config if it crashed in startup
274 if (host_framecount >= 3 && cls.state != ca_dedicated && !COM_CheckParm("-benchmark"))
276 f = FS_Open ("config.cfg", "wb", false, false);
279 Con_Print("Couldn't write config.cfg.\n");
283 Key_WriteBindings (f);
284 Cvar_WriteVariables (f);
295 Resets key bindings and cvars to defaults and then reloads scripts
298 void Host_LoadConfig_f(void)
300 // unlock the cvar default strings so they can be updated by the new default.cfg
301 Cvar_UnlockDefaults();
302 // reset cvars to their defaults, and then exec startup scripts again
303 Cbuf_InsertText("cvar_resettodefaults_all;exec quake.rc\n");
310 Sends text across to be displayed
311 FIXME: make this just a stuffed echo?
314 void SV_ClientPrint(const char *msg)
316 if (host_client->netconnection)
318 MSG_WriteByte(&host_client->netconnection->message, svc_print);
319 MSG_WriteString(&host_client->netconnection->message, msg);
327 Sends text across to be displayed
328 FIXME: make this just a stuffed echo?
331 void SV_ClientPrintf(const char *fmt, ...)
334 char msg[MAX_INPUTLINE];
336 va_start(argptr,fmt);
337 dpvsnprintf(msg,sizeof(msg),fmt,argptr);
347 Sends text to all active clients
350 void SV_BroadcastPrint(const char *msg)
355 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
357 if (client->active && client->netconnection)
359 MSG_WriteByte(&client->netconnection->message, svc_print);
360 MSG_WriteString(&client->netconnection->message, msg);
364 if (sv_echobprint.integer && cls.state == ca_dedicated)
372 Sends text to all active clients
375 void SV_BroadcastPrintf(const char *fmt, ...)
378 char msg[MAX_INPUTLINE];
380 va_start(argptr,fmt);
381 dpvsnprintf(msg,sizeof(msg),fmt,argptr);
384 SV_BroadcastPrint(msg);
391 Send text over to the client to be executed
394 void Host_ClientCommands(const char *fmt, ...)
397 char string[MAX_INPUTLINE];
399 if (!host_client->netconnection)
402 va_start(argptr,fmt);
403 dpvsnprintf(string, sizeof(string), fmt, argptr);
406 MSG_WriteByte(&host_client->netconnection->message, svc_stufftext);
407 MSG_WriteString(&host_client->netconnection->message, string);
411 =====================
414 Called when the player is getting totally kicked off the host
415 if (crash = true), don't bother sending signofs
416 =====================
418 void SV_DropClient(qboolean crash)
421 Con_Printf("Client \"%s\" dropped\n", host_client->name);
423 // make sure edict is not corrupt (from a level change for example)
424 host_client->edict = PRVM_EDICT_NUM(host_client - svs.clients + 1);
426 if (host_client->netconnection)
428 // free the client (the body stays around)
431 // LordHavoc: no opportunity for resending, so use unreliable 3 times
432 unsigned char bufdata[8];
434 memset(&buf, 0, sizeof(buf));
436 buf.maxsize = sizeof(bufdata);
437 MSG_WriteByte(&buf, svc_disconnect);
438 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol, 10000);
439 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol, 10000);
440 NetConn_SendUnreliableMessage(host_client->netconnection, &buf, sv.protocol, 10000);
442 // break the net connection
443 NetConn_Close(host_client->netconnection);
444 host_client->netconnection = NULL;
447 // call qc ClientDisconnect function
448 // LordHavoc: don't call QC if server is dead (avoids recursive
449 // Host_Error in some mods when they run out of edicts)
450 if (host_client->clientconnectcalled && sv.active && host_client->edict)
452 // call the prog function for removing a client
453 // this will set the body to a dead frame, among other things
454 int saveSelf = prog->globals.server->self;
455 host_client->clientconnectcalled = false;
456 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
457 PRVM_ExecuteProgram(prog->globals.server->ClientDisconnect, "QC function ClientDisconnect is missing");
458 prog->globals.server->self = saveSelf;
461 // if a download is active, close it
462 if (host_client->download_file)
464 Con_DPrintf("Download of %s aborted when %s dropped\n", host_client->download_name, host_client->name);
465 FS_Close(host_client->download_file);
466 host_client->download_file = NULL;
467 host_client->download_name[0] = 0;
468 host_client->download_expectedposition = 0;
469 host_client->download_started = false;
472 // remove leaving player from scoreboard
473 host_client->name[0] = 0;
474 host_client->colors = 0;
475 host_client->frags = 0;
476 // send notification to all clients
477 // get number of client manually just to make sure we get it right...
478 i = host_client - svs.clients;
479 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
480 MSG_WriteByte (&sv.reliable_datagram, i);
481 MSG_WriteString (&sv.reliable_datagram, host_client->name);
482 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
483 MSG_WriteByte (&sv.reliable_datagram, i);
484 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
485 MSG_WriteByte (&sv.reliable_datagram, svc_updatefrags);
486 MSG_WriteByte (&sv.reliable_datagram, i);
487 MSG_WriteShort (&sv.reliable_datagram, host_client->frags);
489 // free the client now
490 if (host_client->entitydatabase)
491 EntityFrame_FreeDatabase(host_client->entitydatabase);
492 if (host_client->entitydatabase4)
493 EntityFrame4_FreeDatabase(host_client->entitydatabase4);
494 if (host_client->entitydatabase5)
495 EntityFrame5_FreeDatabase(host_client->entitydatabase5);
499 // clear a fields that matter to DP_SV_CLIENTNAME and DP_SV_CLIENTCOLORS, and also frags
500 PRVM_ED_ClearEdict(host_client->edict);
503 // clear the client struct (this sets active to false)
504 memset(host_client, 0, sizeof(*host_client));
506 // update server listing on the master because player count changed
507 // (which the master uses for filtering empty/full servers)
508 NetConn_Heartbeat(1);
515 This only happens at the end of a game, not between levels
518 void Host_ShutdownServer(void)
522 Con_DPrintf("Host_ShutdownServer\n");
527 NetConn_Heartbeat(2);
528 NetConn_Heartbeat(2);
530 // make sure all the clients know we're disconnecting
532 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
533 if (host_client->active)
534 SV_DropClient(false); // server shutdown
537 NetConn_CloseServerPorts();
543 memset(&sv, 0, sizeof(sv));
544 memset(svs.clients, 0, svs.maxclients*sizeof(client_t));
548 //============================================================================
552 Host_GetConsoleCommands
554 Add them exactly as if they had been typed at the console
557 void Host_GetConsoleCommands (void)
563 cmd = Sys_ConsoleInput ();
574 Runs all active servers
577 static void Host_Init(void);
583 double cl_timer, sv_timer;
584 double clframetime, deltarealtime, oldrealtime;
586 int pass1, pass2, pass3;
593 realtime = Sys_DoubleTime();
596 if (setjmp(host_abortframe))
597 continue; // something bad happened, or the server disconnected
599 oldrealtime = realtime;
600 realtime = Sys_DoubleTime();
602 deltarealtime = realtime - oldrealtime;
603 cl_timer += deltarealtime;
604 sv_timer += deltarealtime;
606 if (slowmo.value < 0)
607 Cvar_SetValue("slowmo", 0);
608 if (host_framerate.value < 0.00001 && host_framerate.value != 0)
609 Cvar_SetValue("host_framerate", 0);
610 if (cl_maxfps.value < 1)
611 Cvar_SetValue("cl_maxfps", 1);
613 // keep the random time dependent, but not when playing demos/benchmarking
614 if(!*sv_random_seed.string && !cls.demoplayback)
617 cl.islocalgame = NetConn_IsLocalGame();
619 // get new key events
622 NetConn_UpdateSockets();
624 // receive packets on each main loop iteration, as the main loop may
625 // be undersleeping due to select() detecting a new packet
627 NetConn_ServerFrame();
631 // check for commands typed to the host
632 Host_GetConsoleCommands();
634 // when a server is running we only execute console commands on server frames
635 // (this mainly allows frikbot .way config files to work properly by staying in sync with the server qc)
636 // otherwise we execute them on all frames
637 if (sv_timer > 0 || !sv.active)
639 // process console commands
643 //Con_Printf("%6.0f %6.0f\n", cl_timer * 1000000.0, sv_timer * 1000000.0);
645 // if the accumulators haven't become positive yet, wait a while
646 if (cls.state == ca_dedicated)
647 wait = sv_timer * -1000000.0;
649 wait = cl_timer * -1000000.0;
651 wait = max(cl_timer, sv_timer) * -1000000.0;
654 if (!cls.timedemo && wait > 0)
656 if (sv_checkforpacketsduringsleep.integer)
659 NetConn_SleepMicroseconds((int)wait);
664 Sys_Sleep((int)wait / 1000);
669 //-------------------
673 //-------------------
675 // limit the frametime steps to no more than 100ms each
681 if (sv.active && sv_timer > 0)
683 // execute one or more server frames, with an upper limit on how much
684 // execution time to spend on server frames to avoid freezing the game if
685 // the server is overloaded, this execution time limit means the game will
686 // slow down if the server is taking too long.
687 int framecount, framelimit = 1;
688 double advancetime, aborttime = 0;
690 // run the world state
691 // don't allow simulation to run too fast or too slow or logic glitches can occur
693 // stop running server frames if the wall time reaches this value
694 if (sys_ticrate.value <= 0)
695 advancetime = sv_timer;
696 else if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
698 // synchronize to the client frametime, but no less than 10ms and no more than sys_ticrate
699 advancetime = bound(0.01, cl_timer, sys_ticrate.value);
701 aborttime = realtime + 0.1;
705 advancetime = sys_ticrate.value;
706 // listen servers can run multiple server frames per client frame
707 if (cls.state == ca_connected)
710 aborttime = realtime + 0.1;
713 advancetime = min(advancetime, 0.1);
715 // only advance time if not paused
716 // the game also pauses in singleplayer when menu or console is used
717 sv.frametime = advancetime * slowmo.value;
718 if (host_framerate.value)
719 sv.frametime = host_framerate.value;
720 if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive)))
723 // setup the VM frame
726 for (framecount = 0;framecount < framelimit && sv_timer > 0;framecount++)
728 sv_timer -= advancetime;
730 // move things around and think unless paused
734 // if this server frame took too long, break out of the loop
735 if (framelimit > 1 && Sys_DoubleTime() >= aborttime)
739 // send all messages to the clients
740 SV_SendClientMessages();
742 // end the server VM frame
745 // send an heartbeat if enough time has passed since the last one
746 NetConn_Heartbeat(0);
749 //-------------------
753 //-------------------
755 if (cls.state != ca_dedicated && (cl_timer > 0 || cls.timedemo))
757 // decide the simulation time
758 if (cls.capturevideo.active)
760 if (cls.capturevideo.realtime)
761 clframetime = cl.realframetime = max(cl_timer, 1.0 / cls.capturevideo.framerate);
764 clframetime = 1.0 / cls.capturevideo.framerate;
765 cl.realframetime = max(cl_timer, clframetime);
768 else if (vid_activewindow)
769 clframetime = cl.realframetime = max(cl_timer, 1.0 / cl_maxfps.value);
771 clframetime = cl.realframetime = 0.1;
773 // apply slowmo scaling
774 clframetime *= slowmo.value;
776 // host_framerate overrides all else
777 if (host_framerate.value)
778 clframetime = host_framerate.value;
781 clframetime = cl.realframetime = cl_timer;
783 // deduct the frame time from the accumulator
784 cl_timer -= cl.realframetime;
786 cl.oldtime = cl.time;
787 cl.time += clframetime;
789 // Collect input into cmd
792 // check for new packets
793 NetConn_ClientFrame();
795 // read a new frame from a demo if needed
796 CL_ReadDemoMessage();
798 // now that packets have been read, send input to server
801 // update client world (interpolate entities, create trails, etc)
805 if (host_speeds.integer)
806 time1 = Sys_DoubleTime();
814 if (host_speeds.integer)
815 time2 = Sys_DoubleTime();
818 if(csqc_usecsqclistener)
820 S_Update(&csqc_listenermatrix);
821 csqc_usecsqclistener = false;
824 S_Update(&r_view.matrix);
828 if (host_speeds.integer)
830 pass1 = (int)((time1 - time3)*1000000);
831 time3 = Sys_DoubleTime();
832 pass2 = (int)((time2 - time1)*1000000);
833 pass3 = (int)((time3 - time2)*1000000);
834 Con_Printf("%6ius total %6ius server %6ius gfx %6ius snd\n",
835 pass1+pass2+pass3, pass1, pass2, pass3);
839 // if there is some time remaining from this frame, reset the timers
849 //============================================================================
851 qboolean vid_opened = false;
852 void Host_StartVideo(void)
854 if (!vid_opened && cls.state != ca_dedicated)
862 char engineversion[128];
864 qboolean sys_nostdout = false;
866 extern void Render_Init(void);
867 extern void Mathlib_Init(void);
868 extern void FS_Init(void);
869 extern void FS_Shutdown(void);
870 extern void PR_Cmd_Init(void);
871 extern void COM_Init_Commands(void);
872 extern void FS_Init_Commands(void);
873 extern qboolean host_stuffcmdsrun;
880 static void Host_Init (void)
885 // LordHavoc: quake never seeded the random number generator before... heh
886 if (COM_CheckParm("-benchmark"))
887 srand(0); // predictable random sequence for -benchmark
891 // FIXME: this is evil, but possibly temporary
892 // COMMANDLINEOPTION: Console: -developer enables warnings and other notices (RECOMMENDED for mod developers)
893 if (COM_CheckParm("-developer"))
895 developer.value = developer.integer = 100;
896 developer.string = "100";
899 if (COM_CheckParm("-developer2"))
901 developer.value = developer.integer = 100;
902 developer.string = "100";
903 developer_memory.value = developer_memory.integer = 100;
904 developer.string = "100";
905 developer_memorydebug.value = developer_memorydebug.integer = 100;
906 developer_memorydebug.string = "100";
909 // COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from
910 if (COM_CheckParm("-nostdout"))
913 // used by everything
916 // initialize console command/cvar/alias/command execution systems
919 // initialize memory subsystem cvars/commands
920 Memory_Init_Commands();
922 // initialize console and logging and its cvars/commands
925 // initialize various cvars that could not be initialized earlier
926 Curl_Init_Commands();
932 // initialize console window (only used by sys_win.c)
935 // detect gamemode from commandline options or executable name
938 // construct a version string for the corner of the console
939 #if defined(__linux__)
943 #elif defined(__FreeBSD__)
945 #elif defined(__NetBSD__)
947 #elif defined(__OpenBSD__)
949 #elif defined(MACOSX)
951 #elif defined(__MORPHOS__)
956 dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
957 Con_Printf("%s\n", engineversion);
959 // initialize ixtable
962 // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name)
975 Host_ServerOptions();
977 if (cls.state != ca_dedicated)
979 Con_Printf("Initializing client\n");
994 // set up the default startmap_sp and startmap_dm aliases (mods can
995 // override these) and then execute the quake.rc startup script
996 if (gamemode == GAME_NEHAHRA)
997 Cbuf_AddText("alias startmap_sp \"map nehstart\"\nalias startmap_dm \"map nehstart\"\nexec quake.rc\n");
998 else if (gamemode == GAME_TRANSFUSION)
999 Cbuf_AddText("alias startmap_sp \"map e1m1\"\n""alias startmap_dm \"map bb1\"\nexec quake.rc\n");
1000 else if (gamemode == GAME_TEU)
1001 Cbuf_AddText("alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec teu.rc\n");
1003 Cbuf_AddText("alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec quake.rc\n");
1006 // if stuffcmds wasn't run, then quake.rc is probably missing, use default
1007 if (!host_stuffcmdsrun)
1009 Cbuf_AddText("exec default.cfg\nexec config.cfg\nexec autoexec.cfg\nstuffcmds\n");
1013 // put up the loading image so the user doesn't stare at a black screen...
1014 SCR_BeginLoadingPlaque();
1016 // FIXME: put this into some neat design, but the menu should be allowed to crash
1017 // without crashing the whole game, so this should just be a short-time solution
1019 // here comes the not so critical stuff
1020 if (setjmp(host_abortframe)) {
1024 if (cls.state != ca_dedicated)
1029 // check for special benchmark mode
1030 // 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)
1031 i = COM_CheckParm("-benchmark");
1032 if (i && i + 1 < com_argc)
1033 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1035 Cbuf_AddText(va("timedemo %s\n", com_argv[i + 1]));
1039 // check for special demo mode
1040 // COMMANDLINEOPTION: Client: -demo <demoname> runs a playdemo and quits
1041 i = COM_CheckParm("-demo");
1042 if (i && i + 1 < com_argc)
1043 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1045 Cbuf_AddText(va("playdemo %s\n", com_argv[i + 1]));
1049 if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1050 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1052 Cbuf_AddText("startmap_dm\n");
1056 if (!sv.active && !cls.demoplayback && !cls.connect_trying)
1058 if (gamemode == GAME_NEXUIZ)
1059 Cbuf_AddText("togglemenu\nplayvideo logo\ncd loop 1\n");
1061 Cbuf_AddText("togglemenu\n");
1065 Con_DPrint("========Initialized=========\n");
1067 //Host_StartVideo();
1075 FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better
1076 to run quit through here before the final handoff to the sys code.
1079 void Host_Shutdown(void)
1081 static qboolean isdown = false;
1085 Con_Print("recursive shutdown\n");
1090 // be quiet while shutting down
1093 // disconnect client from server if active
1096 // shut down local server if active
1097 Host_ShutdownServer ();
1104 // AK hmm, no PRVM_Shutdown(); yet
1106 CL_Video_Shutdown();
1108 Host_SaveConfig_f();
1110 CDAudio_Shutdown ();
1113 NetConn_Shutdown ();
1116 if (cls.state != ca_dedicated)
1118 R_Modules_Shutdown();