cl_main.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // cl_main.c -- client main loop
  16. #include "quakedef.h"
  17. #include "winquake.h"
  18. #ifdef _WIN32
  19. #include "winsock.h"
  20. #else
  21. #include <netinet/in.h>
  22. #endif
  23. // we need to declare some mouse variables here, because the menu system
  24. // references them even when on a unix system.
  25. qboolean noclip_anglehack; // remnant from old quake
  26. cvar_t rcon_password = {"rcon_password", "", false};
  27. cvar_t rcon_address = {"rcon_address", ""};
  28. cvar_t cl_timeout = {"cl_timeout", "60"};
  29. cvar_t cl_shownet = {"cl_shownet","0"}; // can be 0, 1, or 2
  30. cvar_t cl_sbar = {"cl_sbar", "0", true};
  31. cvar_t cl_hudswap = {"cl_hudswap", "0", true};
  32. cvar_t cl_maxfps = {"cl_maxfps", "0", true};
  33. cvar_t lookspring = {"lookspring","0", true};
  34. cvar_t lookstrafe = {"lookstrafe","0", true};
  35. cvar_t sensitivity = {"sensitivity","3", true};
  36. cvar_t m_pitch = {"m_pitch","0.022", true};
  37. cvar_t m_yaw = {"m_yaw","0.022"};
  38. cvar_t m_forward = {"m_forward","1"};
  39. cvar_t m_side = {"m_side","0.8"};
  40. cvar_t entlatency = {"entlatency", "20"};
  41. cvar_t cl_predict_players = {"cl_predict_players", "1"};
  42. cvar_t cl_predict_players2 = {"cl_predict_players2", "1"};
  43. cvar_t cl_solid_players = {"cl_solid_players", "1"};
  44. cvar_t localid = {"localid", ""};
  45. static qboolean allowremotecmd = true;
  46. //
  47. // info mirrors
  48. //
  49. cvar_t password = {"password", "", false, true};
  50. cvar_t spectator = {"spectator", "", false, true};
  51. cvar_t name = {"name","unnamed", true, true};
  52. cvar_t team = {"team","", true, true};
  53. cvar_t skin = {"skin","", true, true};
  54. cvar_t topcolor = {"topcolor","0", true, true};
  55. cvar_t bottomcolor = {"bottomcolor","0", true, true};
  56. cvar_t rate = {"rate","2500", true, true};
  57. cvar_t noaim = {"noaim","0", true, true};
  58. cvar_t msg = {"msg","1", true, true};
  59. extern cvar_t cl_hightrack;
  60. client_static_t cls;
  61. client_state_t cl;
  62. entity_state_t cl_baselines[MAX_EDICTS];
  63. efrag_t cl_efrags[MAX_EFRAGS];
  64. entity_t cl_static_entities[MAX_STATIC_ENTITIES];
  65. lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
  66. dlight_t cl_dlights[MAX_DLIGHTS];
  67. // refresh list
  68. // this is double buffered so the last frame
  69. // can be scanned for oldorigins of trailing objects
  70. int cl_numvisedicts, cl_oldnumvisedicts;
  71. entity_t *cl_visedicts, *cl_oldvisedicts;
  72. entity_t cl_visedicts_list[2][MAX_VISEDICTS];
  73. double connect_time = -1; // for connection retransmits
  74. quakeparms_t host_parms;
  75. qboolean host_initialized; // true if into command execution
  76. qboolean nomaster;
  77. double host_frametime;
  78. double realtime; // without any filtering or bounding
  79. double oldrealtime; // last frame run
  80. int host_framecount;
  81. int host_hunklevel;
  82. byte *host_basepal;
  83. byte *host_colormap;
  84. netadr_t master_adr; // address of the master server
  85. cvar_t host_speeds = {"host_speeds","0"}; // set for running times
  86. cvar_t show_fps = {"show_fps","0"}; // set for running times
  87. cvar_t developer = {"developer","0"};
  88. int fps_count;
  89. jmp_buf host_abort;
  90. void Master_Connect_f (void);
  91. float server_version = 0; // version of server we connected to
  92. char emodel_name[] =
  93. { 'e' ^ 0xff, 'm' ^ 0xff, 'o' ^ 0xff, 'd' ^ 0xff, 'e' ^ 0xff, 'l' ^ 0xff, 0 };
  94. char pmodel_name[] =
  95. { 'p' ^ 0xff, 'm' ^ 0xff, 'o' ^ 0xff, 'd' ^ 0xff, 'e' ^ 0xff, 'l' ^ 0xff, 0 };
  96. char prespawn_name[] =
  97. { 'p'^0xff, 'r'^0xff, 'e'^0xff, 's'^0xff, 'p'^0xff, 'a'^0xff, 'w'^0xff, 'n'^0xff,
  98. ' '^0xff, '%'^0xff, 'i'^0xff, ' '^0xff, '0'^0xff, ' '^0xff, '%'^0xff, 'i'^0xff, 0 };
  99. char modellist_name[] =
  100. { 'm'^0xff, 'o'^0xff, 'd'^0xff, 'e'^0xff, 'l'^0xff, 'l'^0xff, 'i'^0xff, 's'^0xff, 't'^0xff,
  101. ' '^0xff, '%'^0xff, 'i'^0xff, ' '^0xff, '%'^0xff, 'i'^0xff, 0 };
  102. char soundlist_name[] =
  103. { 's'^0xff, 'o'^0xff, 'u'^0xff, 'n'^0xff, 'd'^0xff, 'l'^0xff, 'i'^0xff, 's'^0xff, 't'^0xff,
  104. ' '^0xff, '%'^0xff, 'i'^0xff, ' '^0xff, '%'^0xff, 'i'^0xff, 0 };
  105. /*
  106. ==================
  107. CL_Quit_f
  108. ==================
  109. */
  110. void CL_Quit_f (void)
  111. {
  112. if (1 /* key_dest != key_console */ /* && cls.state != ca_dedicated */)
  113. {
  114. M_Menu_Quit_f ();
  115. return;
  116. }
  117. CL_Disconnect ();
  118. Sys_Quit ();
  119. }
  120. /*
  121. =======================
  122. CL_Version_f
  123. ======================
  124. */
  125. void CL_Version_f (void)
  126. {
  127. Con_Printf ("Version %4.2f\n", VERSION);
  128. Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
  129. }
  130. /*
  131. =======================
  132. CL_SendConnectPacket
  133. called by CL_Connect_f and CL_CheckResend
  134. ======================
  135. */
  136. void CL_SendConnectPacket (void)
  137. {
  138. netadr_t adr;
  139. char data[2048];
  140. double t1, t2;
  141. // JACK: Fixed bug where DNS lookups would cause two connects real fast
  142. // Now, adds lookup time to the connect time.
  143. // Should I add it to realtime instead?!?!
  144. if (cls.state != ca_disconnected)
  145. return;
  146. t1 = Sys_DoubleTime ();
  147. if (!NET_StringToAdr (cls.servername, &adr))
  148. {
  149. Con_Printf ("Bad server address\n");
  150. connect_time = -1;
  151. return;
  152. }
  153. if (!NET_IsClientLegal(&adr))
  154. {
  155. Con_Printf ("Illegal server address\n");
  156. connect_time = -1;
  157. return;
  158. }
  159. if (adr.port == 0)
  160. adr.port = BigShort (27500);
  161. t2 = Sys_DoubleTime ();
  162. connect_time = realtime+t2-t1; // for retransmit requests
  163. cls.qport = Cvar_VariableValue("qport");
  164. Info_SetValueForStarKey (cls.userinfo, "*ip", NET_AdrToString(adr), MAX_INFO_STRING);
  165. // Con_Printf ("Connecting to %s...\n", cls.servername);
  166. sprintf (data, "%c%c%c%cconnect %i %i %i \"%s\"\n",
  167. 255, 255, 255, 255, PROTOCOL_VERSION, cls.qport, cls.challenge, cls.userinfo);
  168. NET_SendPacket (strlen(data), data, adr);
  169. }
  170. /*
  171. =================
  172. CL_CheckForResend
  173. Resend a connect message if the last one has timed out
  174. =================
  175. */
  176. void CL_CheckForResend (void)
  177. {
  178. netadr_t adr;
  179. char data[2048];
  180. double t1, t2;
  181. if (connect_time == -1)
  182. return;
  183. if (cls.state != ca_disconnected)
  184. return;
  185. if (connect_time && realtime - connect_time < 5.0)
  186. return;
  187. t1 = Sys_DoubleTime ();
  188. if (!NET_StringToAdr (cls.servername, &adr))
  189. {
  190. Con_Printf ("Bad server address\n");
  191. connect_time = -1;
  192. return;
  193. }
  194. if (!NET_IsClientLegal(&adr))
  195. {
  196. Con_Printf ("Illegal server address\n");
  197. connect_time = -1;
  198. return;
  199. }
  200. if (adr.port == 0)
  201. adr.port = BigShort (27500);
  202. t2 = Sys_DoubleTime ();
  203. connect_time = realtime+t2-t1; // for retransmit requests
  204. Con_Printf ("Connecting to %s...\n", cls.servername);
  205. sprintf (data, "%c%c%c%cgetchallenge\n", 255, 255, 255, 255);
  206. NET_SendPacket (strlen(data), data, adr);
  207. }
  208. void CL_BeginServerConnect(void)
  209. {
  210. connect_time = 0;
  211. CL_CheckForResend();
  212. }
  213. /*
  214. ================
  215. CL_Connect_f
  216. ================
  217. */
  218. void CL_Connect_f (void)
  219. {
  220. char *server;
  221. if (Cmd_Argc() != 2)
  222. {
  223. Con_Printf ("usage: connect <server>\n");
  224. return;
  225. }
  226. server = Cmd_Argv (1);
  227. CL_Disconnect ();
  228. strncpy (cls.servername, server, sizeof(cls.servername)-1);
  229. CL_BeginServerConnect();
  230. }
  231. /*
  232. =====================
  233. CL_Rcon_f
  234. Send the rest of the command line over as
  235. an unconnected command.
  236. =====================
  237. */
  238. void CL_Rcon_f (void)
  239. {
  240. char message[1024];
  241. int i;
  242. netadr_t to;
  243. if (!rcon_password.string)
  244. {
  245. Con_Printf ("You must set 'rcon_password' before\n"
  246. "issuing an rcon command.\n");
  247. return;
  248. }
  249. message[0] = 255;
  250. message[1] = 255;
  251. message[2] = 255;
  252. message[3] = 255;
  253. message[4] = 0;
  254. strcat (message, "rcon ");
  255. strcat (message, rcon_password.string);
  256. strcat (message, " ");
  257. for (i=1 ; i<Cmd_Argc() ; i++)
  258. {
  259. strcat (message, Cmd_Argv(i));
  260. strcat (message, " ");
  261. }
  262. if (cls.state >= ca_connected)
  263. to = cls.netchan.remote_address;
  264. else
  265. {
  266. if (!strlen(rcon_address.string))
  267. {
  268. Con_Printf ("You must either be connected,\n"
  269. "or set the 'rcon_address' cvar\n"
  270. "to issue rcon commands\n");
  271. return;
  272. }
  273. NET_StringToAdr (rcon_address.string, &to);
  274. }
  275. NET_SendPacket (strlen(message)+1, message
  276. , to);
  277. }
  278. /*
  279. =====================
  280. CL_ClearState
  281. =====================
  282. */
  283. void CL_ClearState (void)
  284. {
  285. int i;
  286. S_StopAllSounds (true);
  287. Con_DPrintf ("Clearing memory\n");
  288. D_FlushCaches ();
  289. Mod_ClearAll ();
  290. if (host_hunklevel) // FIXME: check this...
  291. Hunk_FreeToLowMark (host_hunklevel);
  292. CL_ClearTEnts ();
  293. // wipe the entire cl structure
  294. memset (&cl, 0, sizeof(cl));
  295. SZ_Clear (&cls.netchan.message);
  296. // clear other arrays
  297. memset (cl_efrags, 0, sizeof(cl_efrags));
  298. memset (cl_dlights, 0, sizeof(cl_dlights));
  299. memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
  300. //
  301. // allocate the efrags and chain together into a free list
  302. //
  303. cl.free_efrags = cl_efrags;
  304. for (i=0 ; i<MAX_EFRAGS-1 ; i++)
  305. cl.free_efrags[i].entnext = &cl.free_efrags[i+1];
  306. cl.free_efrags[i].entnext = NULL;
  307. }
  308. /*
  309. =====================
  310. CL_Disconnect
  311. Sends a disconnect message to the server
  312. This is also called on Host_Error, so it shouldn't cause any errors
  313. =====================
  314. */
  315. void CL_Disconnect (void)
  316. {
  317. byte final[10];
  318. connect_time = -1;
  319. #ifdef _WIN32
  320. SetWindowText (mainwindow, "QuakeWorld: disconnected");
  321. #endif
  322. // stop sounds (especially looping!)
  323. S_StopAllSounds (true);
  324. // if running a local server, shut it down
  325. if (cls.demoplayback)
  326. CL_StopPlayback ();
  327. else if (cls.state != ca_disconnected)
  328. {
  329. if (cls.demorecording)
  330. CL_Stop_f ();
  331. final[0] = clc_stringcmd;
  332. strcpy (final+1, "drop");
  333. Netchan_Transmit (&cls.netchan, 6, final);
  334. Netchan_Transmit (&cls.netchan, 6, final);
  335. Netchan_Transmit (&cls.netchan, 6, final);
  336. cls.state = ca_disconnected;
  337. cls.demoplayback = cls.demorecording = cls.timedemo = false;
  338. }
  339. Cam_Reset();
  340. if (cls.download) {
  341. fclose(cls.download);
  342. cls.download = NULL;
  343. }
  344. CL_StopUpload();
  345. }
  346. void CL_Disconnect_f (void)
  347. {
  348. CL_Disconnect ();
  349. }
  350. /*
  351. ====================
  352. CL_User_f
  353. user <name or userid>
  354. Dump userdata / masterdata for a user
  355. ====================
  356. */
  357. void CL_User_f (void)
  358. {
  359. int uid;
  360. int i;
  361. if (Cmd_Argc() != 2)
  362. {
  363. Con_Printf ("Usage: user <username / userid>\n");
  364. return;
  365. }
  366. uid = atoi(Cmd_Argv(1));
  367. for (i=0 ; i<MAX_CLIENTS ; i++)
  368. {
  369. if (!cl.players[i].name[0])
  370. continue;
  371. if (cl.players[i].userid == uid
  372. || !strcmp(cl.players[i].name, Cmd_Argv(1)) )
  373. {
  374. Info_Print (cl.players[i].userinfo);
  375. return;
  376. }
  377. }
  378. Con_Printf ("User not in server.\n");
  379. }
  380. /*
  381. ====================
  382. CL_Users_f
  383. Dump userids for all current players
  384. ====================
  385. */
  386. void CL_Users_f (void)
  387. {
  388. int i;
  389. int c;
  390. c = 0;
  391. Con_Printf ("userid frags name\n");
  392. Con_Printf ("------ ----- ----\n");
  393. for (i=0 ; i<MAX_CLIENTS ; i++)
  394. {
  395. if (cl.players[i].name[0])
  396. {
  397. Con_Printf ("%6i %4i %s\n", cl.players[i].userid, cl.players[i].frags, cl.players[i].name);
  398. c++;
  399. }
  400. }
  401. Con_Printf ("%i total users\n", c);
  402. }
  403. void CL_Color_f (void)
  404. {
  405. // just for quake compatability...
  406. int top, bottom;
  407. char num[16];
  408. if (Cmd_Argc() == 1)
  409. {
  410. Con_Printf ("\"color\" is \"%s %s\"\n",
  411. Info_ValueForKey (cls.userinfo, "topcolor"),
  412. Info_ValueForKey (cls.userinfo, "bottomcolor") );
  413. Con_Printf ("color <0-13> [0-13]\n");
  414. return;
  415. }
  416. if (Cmd_Argc() == 2)
  417. top = bottom = atoi(Cmd_Argv(1));
  418. else
  419. {
  420. top = atoi(Cmd_Argv(1));
  421. bottom = atoi(Cmd_Argv(2));
  422. }
  423. top &= 15;
  424. if (top > 13)
  425. top = 13;
  426. bottom &= 15;
  427. if (bottom > 13)
  428. bottom = 13;
  429. sprintf (num, "%i", top);
  430. Cvar_Set ("topcolor", num);
  431. sprintf (num, "%i", bottom);
  432. Cvar_Set ("bottomcolor", num);
  433. }
  434. /*
  435. ==================
  436. CL_FullServerinfo_f
  437. Sent by server when serverinfo changes
  438. ==================
  439. */
  440. void CL_FullServerinfo_f (void)
  441. {
  442. char *p;
  443. float v;
  444. if (Cmd_Argc() != 2)
  445. {
  446. Con_Printf ("usage: fullserverinfo <complete info string>\n");
  447. return;
  448. }
  449. strcpy (cl.serverinfo, Cmd_Argv(1));
  450. if ((p = Info_ValueForKey(cl.serverinfo, "*vesion")) && *p) {
  451. v = Q_atof(p);
  452. if (v) {
  453. if (!server_version)
  454. Con_Printf("Version %1.2f Server\n", v);
  455. server_version = v;
  456. }
  457. }
  458. }
  459. /*
  460. ==================
  461. CL_FullInfo_f
  462. Allow clients to change userinfo
  463. ==================
  464. Casey was here :)
  465. */
  466. void CL_FullInfo_f (void)
  467. {
  468. char key[512];
  469. char value[512];
  470. char *o;
  471. char *s;
  472. if (Cmd_Argc() != 2)
  473. {
  474. Con_Printf ("fullinfo <complete info string>\n");
  475. return;
  476. }
  477. s = Cmd_Argv(1);
  478. if (*s == '\\')
  479. s++;
  480. while (*s)
  481. {
  482. o = key;
  483. while (*s && *s != '\\')
  484. *o++ = *s++;
  485. *o = 0;
  486. if (!*s)
  487. {
  488. Con_Printf ("MISSING VALUE\n");
  489. return;
  490. }
  491. o = value;
  492. s++;
  493. while (*s && *s != '\\')
  494. *o++ = *s++;
  495. *o = 0;
  496. if (*s)
  497. s++;
  498. if (!stricmp(key, pmodel_name) || !stricmp(key, emodel_name))
  499. continue;
  500. Info_SetValueForKey (cls.userinfo, key, value, MAX_INFO_STRING);
  501. }
  502. }
  503. /*
  504. ==================
  505. CL_SetInfo_f
  506. Allow clients to change userinfo
  507. ==================
  508. */
  509. void CL_SetInfo_f (void)
  510. {
  511. if (Cmd_Argc() == 1)
  512. {
  513. Info_Print (cls.userinfo);
  514. return;
  515. }
  516. if (Cmd_Argc() != 3)
  517. {
  518. Con_Printf ("usage: setinfo [ <key> <value> ]\n");
  519. return;
  520. }
  521. if (!stricmp(Cmd_Argv(1), pmodel_name) || !strcmp(Cmd_Argv(1), emodel_name))
  522. return;
  523. Info_SetValueForKey (cls.userinfo, Cmd_Argv(1), Cmd_Argv(2), MAX_INFO_STRING);
  524. if (cls.state >= ca_connected)
  525. Cmd_ForwardToServer ();
  526. }
  527. /*
  528. ====================
  529. CL_Packet_f
  530. packet <destination> <contents>
  531. Contents allows \n escape character
  532. ====================
  533. */
  534. void CL_Packet_f (void)
  535. {
  536. char send[2048];
  537. int i, l;
  538. char *in, *out;
  539. netadr_t adr;
  540. if (Cmd_Argc() != 3)
  541. {
  542. Con_Printf ("packet <destination> <contents>\n");
  543. return;
  544. }
  545. if (!NET_StringToAdr (Cmd_Argv(1), &adr))
  546. {
  547. Con_Printf ("Bad address\n");
  548. return;
  549. }
  550. in = Cmd_Argv(2);
  551. out = send+4;
  552. send[0] = send[1] = send[2] = send[3] = 0xff;
  553. l = strlen (in);
  554. for (i=0 ; i<l ; i++)
  555. {
  556. if (in[i] == '\\' && in[i+1] == 'n')
  557. {
  558. *out++ = '\n';
  559. i++;
  560. }
  561. else
  562. *out++ = in[i];
  563. }
  564. *out = 0;
  565. NET_SendPacket (out-send, send, adr);
  566. }
  567. /*
  568. =====================
  569. CL_NextDemo
  570. Called to play the next demo in the demo loop
  571. =====================
  572. */
  573. void CL_NextDemo (void)
  574. {
  575. char str[1024];
  576. if (cls.demonum == -1)
  577. return; // don't play demos
  578. if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS)
  579. {
  580. cls.demonum = 0;
  581. if (!cls.demos[cls.demonum][0])
  582. {
  583. // Con_Printf ("No demos listed with startdemos\n");
  584. cls.demonum = -1;
  585. return;
  586. }
  587. }
  588. sprintf (str,"playdemo %s\n", cls.demos[cls.demonum]);
  589. Cbuf_InsertText (str);
  590. cls.demonum++;
  591. }
  592. /*
  593. =================
  594. CL_Changing_f
  595. Just sent as a hint to the client that they should
  596. drop to full console
  597. =================
  598. */
  599. void CL_Changing_f (void)
  600. {
  601. if (cls.download) // don't change when downloading
  602. return;
  603. S_StopAllSounds (true);
  604. cl.intermission = 0;
  605. cls.state = ca_connected; // not active anymore, but not disconnected
  606. Con_Printf ("\nChanging map...\n");
  607. }
  608. /*
  609. =================
  610. CL_Reconnect_f
  611. The server is changing levels
  612. =================
  613. */
  614. void CL_Reconnect_f (void)
  615. {
  616. if (cls.download) // don't change when downloading
  617. return;
  618. S_StopAllSounds (true);
  619. if (cls.state == ca_connected) {
  620. Con_Printf ("reconnecting...\n");
  621. MSG_WriteChar (&cls.netchan.message, clc_stringcmd);
  622. MSG_WriteString (&cls.netchan.message, "new");
  623. return;
  624. }
  625. if (!*cls.servername) {
  626. Con_Printf("No server to reconnect to...\n");
  627. return;
  628. }
  629. CL_Disconnect();
  630. CL_BeginServerConnect();
  631. }
  632. /*
  633. =================
  634. CL_ConnectionlessPacket
  635. Responses to broadcasts, etc
  636. =================
  637. */
  638. void CL_ConnectionlessPacket (void)
  639. {
  640. char *s;
  641. int c;
  642. MSG_BeginReading ();
  643. MSG_ReadLong (); // skip the -1
  644. c = MSG_ReadByte ();
  645. if (!cls.demoplayback)
  646. Con_Printf ("%s: ", NET_AdrToString (net_from));
  647. // Con_DPrintf ("%s", net_message.data + 5);
  648. if (c == S2C_CONNECTION)
  649. {
  650. Con_Printf ("connection\n");
  651. if (cls.state >= ca_connected)
  652. {
  653. if (!cls.demoplayback)
  654. Con_Printf ("Dup connect received. Ignored.\n");
  655. return;
  656. }
  657. Netchan_Setup (&cls.netchan, net_from, cls.qport);
  658. MSG_WriteChar (&cls.netchan.message, clc_stringcmd);
  659. MSG_WriteString (&cls.netchan.message, "new");
  660. cls.state = ca_connected;
  661. Con_Printf ("Connected.\n");
  662. allowremotecmd = false; // localid required now for remote cmds
  663. return;
  664. }
  665. // remote command from gui front end
  666. if (c == A2C_CLIENT_COMMAND)
  667. {
  668. char cmdtext[2048];
  669. Con_Printf ("client command\n");
  670. if ((*(unsigned *)net_from.ip != *(unsigned *)net_local_adr.ip
  671. && *(unsigned *)net_from.ip != htonl(INADDR_LOOPBACK)) )
  672. {
  673. Con_Printf ("Command packet from remote host. Ignored.\n");
  674. return;
  675. }
  676. #ifdef _WIN32
  677. ShowWindow (mainwindow, SW_RESTORE);
  678. SetForegroundWindow (mainwindow);
  679. #endif
  680. s = MSG_ReadString ();
  681. strncpy(cmdtext, s, sizeof(cmdtext) - 1);
  682. cmdtext[sizeof(cmdtext) - 1] = 0;
  683. s = MSG_ReadString ();
  684. while (*s && isspace(*s))
  685. s++;
  686. while (*s && isspace(s[strlen(s) - 1]))
  687. s[strlen(s) - 1] = 0;
  688. if (!allowremotecmd && (!*localid.string || strcmp(localid.string, s))) {
  689. if (!*localid.string) {
  690. Con_Printf("===========================\n");
  691. Con_Printf("Command packet received from local host, but no "
  692. "localid has been set. You may need to upgrade your server "
  693. "browser.\n");
  694. Con_Printf("===========================\n");
  695. return;
  696. }
  697. Con_Printf("===========================\n");
  698. Con_Printf("Invalid localid on command packet received from local host. "
  699. "\n|%s| != |%s|\n"
  700. "You may need to reload your server browser and QuakeWorld.\n",
  701. s, localid.string);
  702. Con_Printf("===========================\n");
  703. Cvar_Set("localid", "");
  704. return;
  705. }
  706. Cbuf_AddText (cmdtext);
  707. allowremotecmd = false;
  708. return;
  709. }
  710. // print command from somewhere
  711. if (c == A2C_PRINT)
  712. {
  713. Con_Printf ("print\n");
  714. s = MSG_ReadString ();
  715. Con_Print (s);
  716. return;
  717. }
  718. // ping from somewhere
  719. if (c == A2A_PING)
  720. {
  721. char data[6];
  722. Con_Printf ("ping\n");
  723. data[0] = 0xff;
  724. data[1] = 0xff;
  725. data[2] = 0xff;
  726. data[3] = 0xff;
  727. data[4] = A2A_ACK;
  728. data[5] = 0;
  729. NET_SendPacket (6, &data, net_from);
  730. return;
  731. }
  732. if (c == S2C_CHALLENGE) {
  733. Con_Printf ("challenge\n");
  734. s = MSG_ReadString ();
  735. cls.challenge = atoi(s);
  736. CL_SendConnectPacket ();
  737. return;
  738. }
  739. #if 0
  740. if (c == svc_disconnect) {
  741. Con_Printf ("disconnect\n");
  742. Host_EndGame ("Server disconnected");
  743. return;
  744. }
  745. #endif
  746. Con_Printf ("unknown: %c\n", c);
  747. }
  748. /*
  749. =================
  750. CL_ReadPackets
  751. =================
  752. */
  753. void CL_ReadPackets (void)
  754. {
  755. // while (NET_GetPacket ())
  756. while (CL_GetMessage())
  757. {
  758. //
  759. // remote command packet
  760. //
  761. if (*(int *)net_message.data == -1)
  762. {
  763. CL_ConnectionlessPacket ();
  764. continue;
  765. }
  766. if (net_message.cursize < 8)
  767. {
  768. Con_Printf ("%s: Runt packet\n",NET_AdrToString(net_from));
  769. continue;
  770. }
  771. //
  772. // packet from server
  773. //
  774. if (!cls.demoplayback &&
  775. !NET_CompareAdr (net_from, cls.netchan.remote_address))
  776. {
  777. Con_DPrintf ("%s:sequenced packet without connection\n"
  778. ,NET_AdrToString(net_from));
  779. continue;
  780. }
  781. if (!Netchan_Process(&cls.netchan))
  782. continue; // wasn't accepted for some reason
  783. CL_ParseServerMessage ();
  784. // if (cls.demoplayback && cls.state >= ca_active && !CL_DemoBehind())
  785. // return;
  786. }
  787. //
  788. // check timeout
  789. //
  790. if (cls.state >= ca_connected
  791. && realtime - cls.netchan.last_received > cl_timeout.value)
  792. {
  793. Con_Printf ("\nServer connection timed out.\n");
  794. CL_Disconnect ();
  795. return;
  796. }
  797. }
  798. //=============================================================================
  799. /*
  800. =====================
  801. CL_Download_f
  802. =====================
  803. */
  804. void CL_Download_f (void)
  805. {
  806. char *p, *q;
  807. if (cls.state == ca_disconnected)
  808. {
  809. Con_Printf ("Must be connected.\n");
  810. return;
  811. }
  812. if (Cmd_Argc() != 2)
  813. {
  814. Con_Printf ("Usage: download <datafile>\n");
  815. return;
  816. }
  817. sprintf (cls.downloadname, "%s/%s", com_gamedir, Cmd_Argv(1));
  818. p = cls.downloadname;
  819. for (;;) {
  820. if ((q = strchr(p, '/')) != NULL) {
  821. *q = 0;
  822. Sys_mkdir(cls.downloadname);
  823. *q = '/';
  824. p = q + 1;
  825. } else
  826. break;
  827. }
  828. strcpy(cls.downloadtempname, cls.downloadname);
  829. cls.download = fopen (cls.downloadname, "wb");
  830. cls.downloadtype = dl_single;
  831. MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
  832. SZ_Print (&cls.netchan.message, va("download %s\n",Cmd_Argv(1)));
  833. }
  834. #ifdef _WINDOWS
  835. #include <windows.h>
  836. /*
  837. =================
  838. CL_Minimize_f
  839. =================
  840. */
  841. void CL_Windows_f (void) {
  842. // if (modestate == MS_WINDOWED)
  843. // ShowWindow(mainwindow, SW_MINIMIZE);
  844. // else
  845. SendMessage(mainwindow, WM_SYSKEYUP, VK_TAB, 1 | (0x0F << 16) | (1<<29));
  846. }
  847. #endif
  848. /*
  849. =================
  850. CL_Init
  851. =================
  852. */
  853. void CL_Init (void)
  854. {
  855. extern cvar_t baseskin;
  856. extern cvar_t noskins;
  857. char st[80];
  858. cls.state = ca_disconnected;
  859. Info_SetValueForKey (cls.userinfo, "name", "unnamed", MAX_INFO_STRING);
  860. Info_SetValueForKey (cls.userinfo, "topcolor", "0", MAX_INFO_STRING);
  861. Info_SetValueForKey (cls.userinfo, "bottomcolor", "0", MAX_INFO_STRING);
  862. Info_SetValueForKey (cls.userinfo, "rate", "2500", MAX_INFO_STRING);
  863. Info_SetValueForKey (cls.userinfo, "msg", "1", MAX_INFO_STRING);
  864. sprintf (st, "%4.2f-%04d", VERSION, build_number());
  865. Info_SetValueForStarKey (cls.userinfo, "*ver", st, MAX_INFO_STRING);
  866. CL_InitInput ();
  867. CL_InitTEnts ();
  868. CL_InitPrediction ();
  869. CL_InitCam ();
  870. Pmove_Init ();
  871. //
  872. // register our commands
  873. //
  874. Cvar_RegisterVariable (&show_fps);
  875. Cvar_RegisterVariable (&host_speeds);
  876. Cvar_RegisterVariable (&developer);
  877. Cvar_RegisterVariable (&cl_warncmd);
  878. Cvar_RegisterVariable (&cl_upspeed);
  879. Cvar_RegisterVariable (&cl_forwardspeed);
  880. Cvar_RegisterVariable (&cl_backspeed);
  881. Cvar_RegisterVariable (&cl_sidespeed);
  882. Cvar_RegisterVariable (&cl_movespeedkey);
  883. Cvar_RegisterVariable (&cl_yawspeed);
  884. Cvar_RegisterVariable (&cl_pitchspeed);
  885. Cvar_RegisterVariable (&cl_anglespeedkey);
  886. Cvar_RegisterVariable (&cl_shownet);
  887. Cvar_RegisterVariable (&cl_sbar);
  888. Cvar_RegisterVariable (&cl_hudswap);
  889. Cvar_RegisterVariable (&cl_maxfps);
  890. Cvar_RegisterVariable (&cl_timeout);
  891. Cvar_RegisterVariable (&lookspring);
  892. Cvar_RegisterVariable (&lookstrafe);
  893. Cvar_RegisterVariable (&sensitivity);
  894. Cvar_RegisterVariable (&m_pitch);
  895. Cvar_RegisterVariable (&m_yaw);
  896. Cvar_RegisterVariable (&m_forward);
  897. Cvar_RegisterVariable (&m_side);
  898. Cvar_RegisterVariable (&rcon_password);
  899. Cvar_RegisterVariable (&rcon_address);
  900. Cvar_RegisterVariable (&entlatency);
  901. Cvar_RegisterVariable (&cl_predict_players2);
  902. Cvar_RegisterVariable (&cl_predict_players);
  903. Cvar_RegisterVariable (&cl_solid_players);
  904. Cvar_RegisterVariable (&localid);
  905. Cvar_RegisterVariable (&baseskin);
  906. Cvar_RegisterVariable (&noskins);
  907. //
  908. // info mirrors
  909. //
  910. Cvar_RegisterVariable (&name);
  911. Cvar_RegisterVariable (&password);
  912. Cvar_RegisterVariable (&spectator);
  913. Cvar_RegisterVariable (&skin);
  914. Cvar_RegisterVariable (&team);
  915. Cvar_RegisterVariable (&topcolor);
  916. Cvar_RegisterVariable (&bottomcolor);
  917. Cvar_RegisterVariable (&rate);
  918. Cvar_RegisterVariable (&msg);
  919. Cvar_RegisterVariable (&noaim);
  920. Cmd_AddCommand ("version", CL_Version_f);
  921. Cmd_AddCommand ("changing", CL_Changing_f);
  922. Cmd_AddCommand ("disconnect", CL_Disconnect_f);
  923. Cmd_AddCommand ("record", CL_Record_f);
  924. Cmd_AddCommand ("rerecord", CL_ReRecord_f);
  925. Cmd_AddCommand ("stop", CL_Stop_f);
  926. Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
  927. Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
  928. Cmd_AddCommand ("skins", Skin_Skins_f);
  929. Cmd_AddCommand ("allskins", Skin_AllSkins_f);
  930. Cmd_AddCommand ("quit", CL_Quit_f);
  931. Cmd_AddCommand ("connect", CL_Connect_f);
  932. Cmd_AddCommand ("reconnect", CL_Reconnect_f);
  933. Cmd_AddCommand ("rcon", CL_Rcon_f);
  934. Cmd_AddCommand ("packet", CL_Packet_f);
  935. Cmd_AddCommand ("user", CL_User_f);
  936. Cmd_AddCommand ("users", CL_Users_f);
  937. Cmd_AddCommand ("setinfo", CL_SetInfo_f);
  938. Cmd_AddCommand ("fullinfo", CL_FullInfo_f);
  939. Cmd_AddCommand ("fullserverinfo", CL_FullServerinfo_f);
  940. Cmd_AddCommand ("color", CL_Color_f);
  941. Cmd_AddCommand ("download", CL_Download_f);
  942. Cmd_AddCommand ("nextul", CL_NextUpload);
  943. Cmd_AddCommand ("stopul", CL_StopUpload);
  944. //
  945. // forward to server commands
  946. //
  947. Cmd_AddCommand ("kill", NULL);
  948. Cmd_AddCommand ("pause", NULL);
  949. Cmd_AddCommand ("say", NULL);
  950. Cmd_AddCommand ("say_team", NULL);
  951. Cmd_AddCommand ("serverinfo", NULL);
  952. //
  953. // Windows commands
  954. //
  955. #ifdef _WINDOWS
  956. Cmd_AddCommand ("windows", CL_Windows_f);
  957. #endif
  958. }
  959. /*
  960. ================
  961. Host_EndGame
  962. Call this to drop to a console without exiting the qwcl
  963. ================
  964. */
  965. void Host_EndGame (char *message, ...)
  966. {
  967. va_list argptr;
  968. char string[1024];
  969. va_start (argptr,message);
  970. vsprintf (string,message,argptr);
  971. va_end (argptr);
  972. Con_Printf ("\n===========================\n");
  973. Con_Printf ("Host_EndGame: %s\n",string);
  974. Con_Printf ("===========================\n\n");
  975. CL_Disconnect ();
  976. longjmp (host_abort, 1);
  977. }
  978. /*
  979. ================
  980. Host_Error
  981. This shuts down the client and exits qwcl
  982. ================
  983. */
  984. void Host_Error (char *error, ...)
  985. {
  986. va_list argptr;
  987. char string[1024];
  988. static qboolean inerror = false;
  989. if (inerror)
  990. Sys_Error ("Host_Error: recursively entered");
  991. inerror = true;
  992. va_start (argptr,error);
  993. vsprintf (string,error,argptr);
  994. va_end (argptr);
  995. Con_Printf ("Host_Error: %s\n",string);
  996. CL_Disconnect ();
  997. cls.demonum = -1;
  998. inerror = false;
  999. // FIXME
  1000. Sys_Error ("Host_Error: %s\n",string);
  1001. }
  1002. /*
  1003. ===============
  1004. Host_WriteConfiguration
  1005. Writes key bindings and archived cvars to config.cfg
  1006. ===============
  1007. */
  1008. void Host_WriteConfiguration (void)
  1009. {
  1010. FILE *f;
  1011. if (host_initialized)
  1012. {
  1013. f = fopen (va("%s/config.cfg",com_gamedir), "w");
  1014. if (!f)
  1015. {
  1016. Con_Printf ("Couldn't write config.cfg.\n");
  1017. return;
  1018. }
  1019. Key_WriteBindings (f);
  1020. Cvar_WriteVariables (f);
  1021. fclose (f);
  1022. }
  1023. }
  1024. //============================================================================
  1025. #if 0
  1026. /*
  1027. ==================
  1028. Host_SimulationTime
  1029. This determines if enough time has passed to run a simulation frame
  1030. ==================
  1031. */
  1032. qboolean Host_SimulationTime(float time)
  1033. {
  1034. float fps;
  1035. if (oldrealtime > realtime)
  1036. oldrealtime = 0;
  1037. if (cl_maxfps.value)
  1038. fps = max(30.0, min(cl_maxfps.value, 72.0));
  1039. else
  1040. fps = max(30.0, min(rate.value/80.0, 72.0));
  1041. if (!cls.timedemo && (realtime + time) - oldrealtime < 1.0/fps)
  1042. return false; // framerate is too high
  1043. return true;
  1044. }
  1045. #endif
  1046. /*
  1047. ==================
  1048. Host_Frame
  1049. Runs all active servers
  1050. ==================
  1051. */
  1052. int nopacketcount;
  1053. void Host_Frame (float time)
  1054. {
  1055. static double time1 = 0;
  1056. static double time2 = 0;
  1057. static double time3 = 0;
  1058. int pass1, pass2, pass3;
  1059. float fps;
  1060. if (setjmp (host_abort) )
  1061. return; // something bad happened, or the server disconnected
  1062. // decide the simulation time
  1063. realtime += time;
  1064. if (oldrealtime > realtime)
  1065. oldrealtime = 0;
  1066. if (cl_maxfps.value)
  1067. fps = max(30.0, min(cl_maxfps.value, 72.0));
  1068. else
  1069. fps = max(30.0, min(rate.value/80.0, 72.0));
  1070. if (!cls.timedemo && realtime - oldrealtime < 1.0/fps)
  1071. return; // framerate is too high
  1072. host_frametime = realtime - oldrealtime;
  1073. oldrealtime = realtime;
  1074. if (host_frametime > 0.2)
  1075. host_frametime = 0.2;
  1076. // get new key events
  1077. Sys_SendKeyEvents ();
  1078. // allow mice or other external controllers to add commands
  1079. IN_Commands ();
  1080. // process console commands
  1081. Cbuf_Execute ();
  1082. // fetch results from server
  1083. CL_ReadPackets ();
  1084. // send intentions now
  1085. // resend a connection request if necessary
  1086. if (cls.state == ca_disconnected) {
  1087. CL_CheckForResend ();
  1088. } else
  1089. CL_SendCmd ();
  1090. // Set up prediction for other players
  1091. CL_SetUpPlayerPrediction(false);
  1092. // do client side motion prediction
  1093. CL_PredictMove ();
  1094. // Set up prediction for other players
  1095. CL_SetUpPlayerPrediction(true);
  1096. // build a refresh entity list
  1097. CL_EmitEntities ();
  1098. // update video
  1099. if (host_speeds.value)
  1100. time1 = Sys_DoubleTime ();
  1101. SCR_UpdateScreen ();
  1102. if (host_speeds.value)
  1103. time2 = Sys_DoubleTime ();
  1104. // update audio
  1105. if (cls.state == ca_active)
  1106. {
  1107. S_Update (r_origin, vpn, vright, vup);
  1108. CL_DecayLights ();
  1109. }
  1110. else
  1111. S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);
  1112. CDAudio_Update();
  1113. if (host_speeds.value)
  1114. {
  1115. pass1 = (time1 - time3)*1000;
  1116. time3 = Sys_DoubleTime ();
  1117. pass2 = (time2 - time1)*1000;
  1118. pass3 = (time3 - time2)*1000;
  1119. Con_Printf ("%3i tot %3i server %3i gfx %3i snd\n",
  1120. pass1+pass2+pass3, pass1, pass2, pass3);
  1121. }
  1122. host_framecount++;
  1123. fps_count++;
  1124. }
  1125. static void simple_crypt(char *buf, int len)
  1126. {
  1127. while (len--)
  1128. *buf++ ^= 0xff;
  1129. }
  1130. void Host_FixupModelNames(void)
  1131. {
  1132. simple_crypt(emodel_name, sizeof(emodel_name) - 1);
  1133. simple_crypt(pmodel_name, sizeof(pmodel_name) - 1);
  1134. simple_crypt(prespawn_name, sizeof(prespawn_name) - 1);
  1135. simple_crypt(modellist_name, sizeof(modellist_name) - 1);
  1136. simple_crypt(soundlist_name, sizeof(soundlist_name) - 1);
  1137. }
  1138. //============================================================================
  1139. /*
  1140. ====================
  1141. Host_Init
  1142. ====================
  1143. */
  1144. void Host_Init (quakeparms_t *parms)
  1145. {
  1146. COM_InitArgv (parms->argc, parms->argv);
  1147. COM_AddParm ("-game");
  1148. COM_AddParm ("qw");
  1149. Sys_mkdir("qw");
  1150. if (COM_CheckParm ("-minmemory"))
  1151. parms->memsize = MINIMUM_MEMORY;
  1152. host_parms = *parms;
  1153. if (parms->memsize < MINIMUM_MEMORY)
  1154. Sys_Error ("Only %4.1f megs of memory reported, can't execute game", parms->memsize / (float)0x100000);
  1155. Memory_Init (parms->membase, parms->memsize);
  1156. Cbuf_Init ();
  1157. Cmd_Init ();
  1158. V_Init ();
  1159. COM_Init ();
  1160. Host_FixupModelNames();
  1161. NET_Init (PORT_CLIENT);
  1162. Netchan_Init ();
  1163. W_LoadWadFile ("gfx.wad");
  1164. Key_Init ();
  1165. Con_Init ();
  1166. M_Init ();
  1167. Mod_Init ();
  1168. // Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
  1169. Con_Printf ("%4.1f megs RAM used.\n",parms->memsize/ (1024*1024.0));
  1170. R_InitTextures ();
  1171. host_basepal = (byte *)COM_LoadHunkFile ("gfx/palette.lmp");
  1172. if (!host_basepal)
  1173. Sys_Error ("Couldn't load gfx/palette.lmp");
  1174. host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp");
  1175. if (!host_colormap)
  1176. Sys_Error ("Couldn't load gfx/colormap.lmp");
  1177. #ifdef __linux__
  1178. IN_Init ();
  1179. CDAudio_Init ();
  1180. VID_Init (host_basepal);
  1181. Draw_Init ();
  1182. SCR_Init ();
  1183. R_Init ();
  1184. // S_Init (); // S_Init is now done as part of VID. Sigh.
  1185. cls.state = ca_disconnected;
  1186. Sbar_Init ();
  1187. CL_Init ();
  1188. #else
  1189. VID_Init (host_basepal);
  1190. Draw_Init ();
  1191. SCR_Init ();
  1192. R_Init ();
  1193. // S_Init (); // S_Init is now done as part of VID. Sigh.
  1194. #ifdef GLQUAKE
  1195. S_Init();
  1196. #endif
  1197. cls.state = ca_disconnected;
  1198. CDAudio_Init ();
  1199. Sbar_Init ();
  1200. CL_Init ();
  1201. IN_Init ();
  1202. #endif
  1203. Cbuf_InsertText ("exec quake.rc\n");
  1204. Cbuf_AddText ("echo Type connect <internet address> or use GameSpy to connect to a game.\n");
  1205. Cbuf_AddText ("cl_warncmd 1\n");
  1206. Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
  1207. host_hunklevel = Hunk_LowMark ();
  1208. host_initialized = true;
  1209. Con_Printf ("\nClient Version %4.2f (Build %04d)\n\n", VERSION, build_number());
  1210. Con_Printf ("€������ QuakeWorld Initialized ������‚\n");
  1211. }
  1212. /*
  1213. ===============
  1214. Host_Shutdown
  1215. FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better
  1216. to run quit through here before the final handoff to the sys code.
  1217. ===============
  1218. */
  1219. void Host_Shutdown(void)
  1220. {
  1221. static qboolean isdown = false;
  1222. if (isdown)
  1223. {
  1224. printf ("recursive shutdown\n");
  1225. return;
  1226. }
  1227. isdown = true;
  1228. Host_WriteConfiguration ();
  1229. CDAudio_Shutdown ();
  1230. NET_Shutdown ();
  1231. S_Shutdown();
  1232. IN_Shutdown ();
  1233. if (host_basepal)
  1234. VID_Shutdown();
  1235. }