cl_parse.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  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_parse.c -- parse a message received from the server
  16. #include "quakedef.h"
  17. char *svc_strings[] =
  18. {
  19. "svc_bad",
  20. "svc_nop",
  21. "svc_disconnect",
  22. "svc_updatestat",
  23. "svc_version", // [long] server version
  24. "svc_setview", // [short] entity number
  25. "svc_sound", // <see code>
  26. "svc_time", // [float] server time
  27. "svc_print", // [string] null terminated string
  28. "svc_stufftext", // [string] stuffed into client's console buffer
  29. // the string should be \n terminated
  30. "svc_setangle", // [vec3] set the view angle to this absolute value
  31. "svc_serverinfo", // [long] version
  32. // [string] signon string
  33. // [string]..[0]model cache [string]...[0]sounds cache
  34. // [string]..[0]item cache
  35. "svc_lightstyle", // [byte] [string]
  36. "svc_updatename", // [byte] [string]
  37. "svc_updatefrags", // [byte] [short]
  38. "svc_clientdata", // <shortbits + data>
  39. "svc_stopsound", // <see code>
  40. "svc_updatecolors", // [byte] [byte]
  41. "svc_particle", // [vec3] <variable>
  42. "svc_damage", // [byte] impact [byte] blood [vec3] from
  43. "svc_spawnstatic",
  44. "OBSOLETE svc_spawnbinary",
  45. "svc_spawnbaseline",
  46. "svc_temp_entity", // <variable>
  47. "svc_setpause",
  48. "svc_signonnum",
  49. "svc_centerprint",
  50. "svc_killedmonster",
  51. "svc_foundsecret",
  52. "svc_spawnstaticsound",
  53. "svc_intermission",
  54. "svc_finale", // [string] music [string] text
  55. "svc_cdtrack", // [byte] track [byte] looptrack
  56. "svc_sellscreen",
  57. "svc_cutscene"
  58. };
  59. //=============================================================================
  60. /*
  61. ===============
  62. CL_EntityNum
  63. This error checks and tracks the total number of entities
  64. ===============
  65. */
  66. entity_t *CL_EntityNum (int num)
  67. {
  68. if (num >= cl.num_entities)
  69. {
  70. if (num >= MAX_EDICTS)
  71. Host_Error ("CL_EntityNum: %i is an invalid number",num);
  72. while (cl.num_entities<=num)
  73. {
  74. cl_entities[cl.num_entities].colormap = vid.colormap;
  75. cl.num_entities++;
  76. }
  77. }
  78. return &cl_entities[num];
  79. }
  80. /*
  81. ==================
  82. CL_ParseStartSoundPacket
  83. ==================
  84. */
  85. void CL_ParseStartSoundPacket(void)
  86. {
  87. vec3_t pos;
  88. int channel, ent;
  89. int sound_num;
  90. int volume;
  91. int field_mask;
  92. float attenuation;
  93. int i;
  94. field_mask = MSG_ReadByte();
  95. if (field_mask & SND_VOLUME)
  96. volume = MSG_ReadByte ();
  97. else
  98. volume = DEFAULT_SOUND_PACKET_VOLUME;
  99. if (field_mask & SND_ATTENUATION)
  100. attenuation = MSG_ReadByte () / 64.0;
  101. else
  102. attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
  103. channel = MSG_ReadShort ();
  104. sound_num = MSG_ReadByte ();
  105. ent = channel >> 3;
  106. channel &= 7;
  107. if (ent > MAX_EDICTS)
  108. Host_Error ("CL_ParseStartSoundPacket: ent = %i", ent);
  109. for (i=0 ; i<3 ; i++)
  110. pos[i] = MSG_ReadCoord ();
  111. S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0, attenuation);
  112. }
  113. /*
  114. ==================
  115. CL_KeepaliveMessage
  116. When the client is taking a long time to load stuff, send keepalive messages
  117. so the server doesn't disconnect.
  118. ==================
  119. */
  120. void CL_KeepaliveMessage (void)
  121. {
  122. float time;
  123. static float lastmsg;
  124. int ret;
  125. sizebuf_t old;
  126. byte olddata[8192];
  127. if (sv.active)
  128. return; // no need if server is local
  129. if (cls.demoplayback)
  130. return;
  131. // read messages from server, should just be nops
  132. old = net_message;
  133. memcpy (olddata, net_message.data, net_message.cursize);
  134. do
  135. {
  136. ret = CL_GetMessage ();
  137. switch (ret)
  138. {
  139. default:
  140. Host_Error ("CL_KeepaliveMessage: CL_GetMessage failed");
  141. case 0:
  142. break; // nothing waiting
  143. case 1:
  144. Host_Error ("CL_KeepaliveMessage: received a message");
  145. break;
  146. case 2:
  147. if (MSG_ReadByte() != svc_nop)
  148. Host_Error ("CL_KeepaliveMessage: datagram wasn't a nop");
  149. break;
  150. }
  151. } while (ret);
  152. net_message = old;
  153. memcpy (net_message.data, olddata, net_message.cursize);
  154. // check time
  155. time = Sys_FloatTime ();
  156. if (time - lastmsg < 5)
  157. return;
  158. lastmsg = time;
  159. // write out a nop
  160. Con_Printf ("--> client to server keepalive\n");
  161. MSG_WriteByte (&cls.message, clc_nop);
  162. NET_SendMessage (cls.netcon, &cls.message);
  163. SZ_Clear (&cls.message);
  164. }
  165. /*
  166. ==================
  167. CL_ParseServerInfo
  168. ==================
  169. */
  170. void CL_ParseServerInfo (void)
  171. {
  172. char *str;
  173. int i;
  174. int nummodels, numsounds;
  175. char model_precache[MAX_MODELS][MAX_QPATH];
  176. char sound_precache[MAX_SOUNDS][MAX_QPATH];
  177. Con_DPrintf ("Serverinfo packet received.\n");
  178. //
  179. // wipe the client_state_t struct
  180. //
  181. CL_ClearState ();
  182. // parse protocol version number
  183. i = MSG_ReadLong ();
  184. if (i != PROTOCOL_VERSION)
  185. {
  186. Con_Printf ("Server returned version %i, not %i", i, PROTOCOL_VERSION);
  187. return;
  188. }
  189. // parse maxclients
  190. cl.maxclients = MSG_ReadByte ();
  191. if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
  192. {
  193. Con_Printf("Bad maxclients (%u) from server\n", cl.maxclients);
  194. return;
  195. }
  196. cl.scores = Hunk_AllocName (cl.maxclients*sizeof(*cl.scores), "scores");
  197. // parse gametype
  198. cl.gametype = MSG_ReadByte ();
  199. // parse signon message
  200. str = MSG_ReadString ();
  201. strncpy (cl.levelname, str, sizeof(cl.levelname)-1);
  202. // seperate the printfs so the server message can have a color
  203. Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n");
  204. Con_Printf ("%c%s\n", 2, str);
  205. //
  206. // first we go through and touch all of the precache data that still
  207. // happens to be in the cache, so precaching something else doesn't
  208. // needlessly purge it
  209. //
  210. // precache models
  211. memset (cl.model_precache, 0, sizeof(cl.model_precache));
  212. for (nummodels=1 ; ; nummodels++)
  213. {
  214. str = MSG_ReadString ();
  215. if (!str[0])
  216. break;
  217. if (nummodels==MAX_MODELS)
  218. {
  219. Con_Printf ("Server sent too many model precaches\n");
  220. return;
  221. }
  222. strcpy (model_precache[nummodels], str);
  223. Mod_TouchModel (str);
  224. }
  225. // precache sounds
  226. memset (cl.sound_precache, 0, sizeof(cl.sound_precache));
  227. for (numsounds=1 ; ; numsounds++)
  228. {
  229. str = MSG_ReadString ();
  230. if (!str[0])
  231. break;
  232. if (numsounds==MAX_SOUNDS)
  233. {
  234. Con_Printf ("Server sent too many sound precaches\n");
  235. return;
  236. }
  237. strcpy (sound_precache[numsounds], str);
  238. S_TouchSound (str);
  239. }
  240. //
  241. // now we try to load everything else until a cache allocation fails
  242. //
  243. for (i=1 ; i<nummodels ; i++)
  244. {
  245. cl.model_precache[i] = Mod_ForName (model_precache[i], false);
  246. if (cl.model_precache[i] == NULL)
  247. {
  248. Con_Printf("Model %s not found\n", model_precache[i]);
  249. return;
  250. }
  251. CL_KeepaliveMessage ();
  252. }
  253. S_BeginPrecaching ();
  254. for (i=1 ; i<numsounds ; i++)
  255. {
  256. cl.sound_precache[i] = S_PrecacheSound (sound_precache[i]);
  257. CL_KeepaliveMessage ();
  258. }
  259. S_EndPrecaching ();
  260. // local state
  261. cl_entities[0].model = cl.worldmodel = cl.model_precache[1];
  262. R_NewMap ();
  263. Hunk_Check (); // make sure nothing is hurt
  264. noclip_anglehack = false; // noclip is turned off at start
  265. }
  266. /*
  267. ==================
  268. CL_ParseUpdate
  269. Parse an entity update message from the server
  270. If an entities model or origin changes from frame to frame, it must be
  271. relinked. Other attributes can change without relinking.
  272. ==================
  273. */
  274. int bitcounts[16];
  275. void CL_ParseUpdate (int bits)
  276. {
  277. int i;
  278. model_t *model;
  279. int modnum;
  280. qboolean forcelink;
  281. entity_t *ent;
  282. int num;
  283. int skin;
  284. if (cls.signon == SIGNONS - 1)
  285. { // first update is the final signon stage
  286. cls.signon = SIGNONS;
  287. CL_SignonReply ();
  288. }
  289. if (bits & U_MOREBITS)
  290. {
  291. i = MSG_ReadByte ();
  292. bits |= (i<<8);
  293. }
  294. if (bits & U_LONGENTITY)
  295. num = MSG_ReadShort ();
  296. else
  297. num = MSG_ReadByte ();
  298. ent = CL_EntityNum (num);
  299. for (i=0 ; i<16 ; i++)
  300. if (bits&(1<<i))
  301. bitcounts[i]++;
  302. if (ent->msgtime != cl.mtime[1])
  303. forcelink = true; // no previous frame to lerp from
  304. else
  305. forcelink = false;
  306. ent->msgtime = cl.mtime[0];
  307. if (bits & U_MODEL)
  308. {
  309. modnum = MSG_ReadByte ();
  310. if (modnum >= MAX_MODELS)
  311. Host_Error ("CL_ParseModel: bad modnum");
  312. }
  313. else
  314. modnum = ent->baseline.modelindex;
  315. model = cl.model_precache[modnum];
  316. if (model != ent->model)
  317. {
  318. ent->model = model;
  319. // automatic animation (torches, etc) can be either all together
  320. // or randomized
  321. if (model)
  322. {
  323. if (model->synctype == ST_RAND)
  324. ent->syncbase = (float)(rand()&0x7fff) / 0x7fff;
  325. else
  326. ent->syncbase = 0.0;
  327. }
  328. else
  329. forcelink = true; // hack to make null model players work
  330. #ifdef GLQUAKE
  331. if (num > 0 && num <= cl.maxclients)
  332. R_TranslatePlayerSkin (num - 1);
  333. #endif
  334. }
  335. if (bits & U_FRAME)
  336. ent->frame = MSG_ReadByte ();
  337. else
  338. ent->frame = ent->baseline.frame;
  339. if (bits & U_COLORMAP)
  340. i = MSG_ReadByte();
  341. else
  342. i = ent->baseline.colormap;
  343. if (!i)
  344. ent->colormap = vid.colormap;
  345. else
  346. {
  347. if (i > cl.maxclients)
  348. Sys_Error ("i >= cl.maxclients");
  349. ent->colormap = cl.scores[i-1].translations;
  350. }
  351. #ifdef GLQUAKE
  352. if (bits & U_SKIN)
  353. skin = MSG_ReadByte();
  354. else
  355. skin = ent->baseline.skin;
  356. if (skin != ent->skinnum) {
  357. ent->skinnum = skin;
  358. if (num > 0 && num <= cl.maxclients)
  359. R_TranslatePlayerSkin (num - 1);
  360. }
  361. #else
  362. if (bits & U_SKIN)
  363. ent->skinnum = MSG_ReadByte();
  364. else
  365. ent->skinnum = ent->baseline.skin;
  366. #endif
  367. if (bits & U_EFFECTS)
  368. ent->effects = MSG_ReadByte();
  369. else
  370. ent->effects = ent->baseline.effects;
  371. // shift the known values for interpolation
  372. VectorCopy (ent->msg_origins[0], ent->msg_origins[1]);
  373. VectorCopy (ent->msg_angles[0], ent->msg_angles[1]);
  374. if (bits & U_ORIGIN1)
  375. ent->msg_origins[0][0] = MSG_ReadCoord ();
  376. else
  377. ent->msg_origins[0][0] = ent->baseline.origin[0];
  378. if (bits & U_ANGLE1)
  379. ent->msg_angles[0][0] = MSG_ReadAngle();
  380. else
  381. ent->msg_angles[0][0] = ent->baseline.angles[0];
  382. if (bits & U_ORIGIN2)
  383. ent->msg_origins[0][1] = MSG_ReadCoord ();
  384. else
  385. ent->msg_origins[0][1] = ent->baseline.origin[1];
  386. if (bits & U_ANGLE2)
  387. ent->msg_angles[0][1] = MSG_ReadAngle();
  388. else
  389. ent->msg_angles[0][1] = ent->baseline.angles[1];
  390. if (bits & U_ORIGIN3)
  391. ent->msg_origins[0][2] = MSG_ReadCoord ();
  392. else
  393. ent->msg_origins[0][2] = ent->baseline.origin[2];
  394. if (bits & U_ANGLE3)
  395. ent->msg_angles[0][2] = MSG_ReadAngle();
  396. else
  397. ent->msg_angles[0][2] = ent->baseline.angles[2];
  398. if ( bits & U_NOLERP )
  399. ent->forcelink = true;
  400. if ( forcelink )
  401. { // didn't have an update last message
  402. VectorCopy (ent->msg_origins[0], ent->msg_origins[1]);
  403. VectorCopy (ent->msg_origins[0], ent->origin);
  404. VectorCopy (ent->msg_angles[0], ent->msg_angles[1]);
  405. VectorCopy (ent->msg_angles[0], ent->angles);
  406. ent->forcelink = true;
  407. }
  408. }
  409. /*
  410. ==================
  411. CL_ParseBaseline
  412. ==================
  413. */
  414. void CL_ParseBaseline (entity_t *ent)
  415. {
  416. int i;
  417. ent->baseline.modelindex = MSG_ReadByte ();
  418. ent->baseline.frame = MSG_ReadByte ();
  419. ent->baseline.colormap = MSG_ReadByte();
  420. ent->baseline.skin = MSG_ReadByte();
  421. for (i=0 ; i<3 ; i++)
  422. {
  423. ent->baseline.origin[i] = MSG_ReadCoord ();
  424. ent->baseline.angles[i] = MSG_ReadAngle ();
  425. }
  426. }
  427. /*
  428. ==================
  429. CL_ParseClientdata
  430. Server information pertaining to this client only
  431. ==================
  432. */
  433. void CL_ParseClientdata (int bits)
  434. {
  435. int i, j;
  436. if (bits & SU_VIEWHEIGHT)
  437. cl.viewheight = MSG_ReadChar ();
  438. else
  439. cl.viewheight = DEFAULT_VIEWHEIGHT;
  440. if (bits & SU_IDEALPITCH)
  441. cl.idealpitch = MSG_ReadChar ();
  442. else
  443. cl.idealpitch = 0;
  444. VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
  445. for (i=0 ; i<3 ; i++)
  446. {
  447. if (bits & (SU_PUNCH1<<i) )
  448. cl.punchangle[i] = MSG_ReadChar();
  449. else
  450. cl.punchangle[i] = 0;
  451. if (bits & (SU_VELOCITY1<<i) )
  452. cl.mvelocity[0][i] = MSG_ReadChar()*16;
  453. else
  454. cl.mvelocity[0][i] = 0;
  455. }
  456. // [always sent] if (bits & SU_ITEMS)
  457. i = MSG_ReadLong ();
  458. if (cl.items != i)
  459. { // set flash times
  460. Sbar_Changed ();
  461. for (j=0 ; j<32 ; j++)
  462. if ( (i & (1<<j)) && !(cl.items & (1<<j)))
  463. cl.item_gettime[j] = cl.time;
  464. cl.items = i;
  465. }
  466. cl.onground = (bits & SU_ONGROUND) != 0;
  467. cl.inwater = (bits & SU_INWATER) != 0;
  468. if (bits & SU_WEAPONFRAME)
  469. cl.stats[STAT_WEAPONFRAME] = MSG_ReadByte ();
  470. else
  471. cl.stats[STAT_WEAPONFRAME] = 0;
  472. if (bits & SU_ARMOR)
  473. i = MSG_ReadByte ();
  474. else
  475. i = 0;
  476. if (cl.stats[STAT_ARMOR] != i)
  477. {
  478. cl.stats[STAT_ARMOR] = i;
  479. Sbar_Changed ();
  480. }
  481. if (bits & SU_WEAPON)
  482. i = MSG_ReadByte ();
  483. else
  484. i = 0;
  485. if (cl.stats[STAT_WEAPON] != i)
  486. {
  487. cl.stats[STAT_WEAPON] = i;
  488. Sbar_Changed ();
  489. }
  490. i = MSG_ReadShort ();
  491. if (cl.stats[STAT_HEALTH] != i)
  492. {
  493. cl.stats[STAT_HEALTH] = i;
  494. Sbar_Changed ();
  495. }
  496. i = MSG_ReadByte ();
  497. if (cl.stats[STAT_AMMO] != i)
  498. {
  499. cl.stats[STAT_AMMO] = i;
  500. Sbar_Changed ();
  501. }
  502. for (i=0 ; i<4 ; i++)
  503. {
  504. j = MSG_ReadByte ();
  505. if (cl.stats[STAT_SHELLS+i] != j)
  506. {
  507. cl.stats[STAT_SHELLS+i] = j;
  508. Sbar_Changed ();
  509. }
  510. }
  511. i = MSG_ReadByte ();
  512. if (standard_quake)
  513. {
  514. if (cl.stats[STAT_ACTIVEWEAPON] != i)
  515. {
  516. cl.stats[STAT_ACTIVEWEAPON] = i;
  517. Sbar_Changed ();
  518. }
  519. }
  520. else
  521. {
  522. if (cl.stats[STAT_ACTIVEWEAPON] != (1<<i))
  523. {
  524. cl.stats[STAT_ACTIVEWEAPON] = (1<<i);
  525. Sbar_Changed ();
  526. }
  527. }
  528. }
  529. /*
  530. =====================
  531. CL_NewTranslation
  532. =====================
  533. */
  534. void CL_NewTranslation (int slot)
  535. {
  536. int i, j;
  537. int top, bottom;
  538. byte *dest, *source;
  539. if (slot > cl.maxclients)
  540. Sys_Error ("CL_NewTranslation: slot > cl.maxclients");
  541. dest = cl.scores[slot].translations;
  542. source = vid.colormap;
  543. memcpy (dest, vid.colormap, sizeof(cl.scores[slot].translations));
  544. top = cl.scores[slot].colors & 0xf0;
  545. bottom = (cl.scores[slot].colors &15)<<4;
  546. #ifdef GLQUAKE
  547. R_TranslatePlayerSkin (slot);
  548. #endif
  549. for (i=0 ; i<VID_GRADES ; i++, dest += 256, source+=256)
  550. {
  551. if (top < 128) // the artists made some backwards ranges. sigh.
  552. memcpy (dest + TOP_RANGE, source + top, 16);
  553. else
  554. for (j=0 ; j<16 ; j++)
  555. dest[TOP_RANGE+j] = source[top+15-j];
  556. if (bottom < 128)
  557. memcpy (dest + BOTTOM_RANGE, source + bottom, 16);
  558. else
  559. for (j=0 ; j<16 ; j++)
  560. dest[BOTTOM_RANGE+j] = source[bottom+15-j];
  561. }
  562. }
  563. /*
  564. =====================
  565. CL_ParseStatic
  566. =====================
  567. */
  568. void CL_ParseStatic (void)
  569. {
  570. entity_t *ent;
  571. int i;
  572. i = cl.num_statics;
  573. if (i >= MAX_STATIC_ENTITIES)
  574. Host_Error ("Too many static entities");
  575. ent = &cl_static_entities[i];
  576. cl.num_statics++;
  577. CL_ParseBaseline (ent);
  578. // copy it to the current state
  579. ent->model = cl.model_precache[ent->baseline.modelindex];
  580. ent->frame = ent->baseline.frame;
  581. ent->colormap = vid.colormap;
  582. ent->skinnum = ent->baseline.skin;
  583. ent->effects = ent->baseline.effects;
  584. VectorCopy (ent->baseline.origin, ent->origin);
  585. VectorCopy (ent->baseline.angles, ent->angles);
  586. R_AddEfrags (ent);
  587. }
  588. /*
  589. ===================
  590. CL_ParseStaticSound
  591. ===================
  592. */
  593. void CL_ParseStaticSound (void)
  594. {
  595. vec3_t org;
  596. int sound_num, vol, atten;
  597. int i;
  598. for (i=0 ; i<3 ; i++)
  599. org[i] = MSG_ReadCoord ();
  600. sound_num = MSG_ReadByte ();
  601. vol = MSG_ReadByte ();
  602. atten = MSG_ReadByte ();
  603. S_StaticSound (cl.sound_precache[sound_num], org, vol, atten);
  604. }
  605. #define SHOWNET(x) if(cl_shownet.value==2)Con_Printf ("%3i:%s\n", msg_readcount-1, x);
  606. /*
  607. =====================
  608. CL_ParseServerMessage
  609. =====================
  610. */
  611. void CL_ParseServerMessage (void)
  612. {
  613. int cmd;
  614. int i;
  615. //
  616. // if recording demos, copy the message out
  617. //
  618. if (cl_shownet.value == 1)
  619. Con_Printf ("%i ",net_message.cursize);
  620. else if (cl_shownet.value == 2)
  621. Con_Printf ("------------------\n");
  622. cl.onground = false; // unless the server says otherwise
  623. //
  624. // parse the message
  625. //
  626. MSG_BeginReading ();
  627. while (1)
  628. {
  629. if (msg_badread)
  630. Host_Error ("CL_ParseServerMessage: Bad server message");
  631. cmd = MSG_ReadByte ();
  632. if (cmd == -1)
  633. {
  634. SHOWNET("END OF MESSAGE");
  635. return; // end of message
  636. }
  637. // if the high bit of the command byte is set, it is a fast update
  638. if (cmd & 128)
  639. {
  640. SHOWNET("fast update");
  641. CL_ParseUpdate (cmd&127);
  642. continue;
  643. }
  644. SHOWNET(svc_strings[cmd]);
  645. // other commands
  646. switch (cmd)
  647. {
  648. default:
  649. Host_Error ("CL_ParseServerMessage: Illegible server message\n");
  650. break;
  651. case svc_nop:
  652. // Con_Printf ("svc_nop\n");
  653. break;
  654. case svc_time:
  655. cl.mtime[1] = cl.mtime[0];
  656. cl.mtime[0] = MSG_ReadFloat ();
  657. break;
  658. case svc_clientdata:
  659. i = MSG_ReadShort ();
  660. CL_ParseClientdata (i);
  661. break;
  662. case svc_version:
  663. i = MSG_ReadLong ();
  664. if (i != PROTOCOL_VERSION)
  665. Host_Error ("CL_ParseServerMessage: Server is protocol %i instead of %i\n", i, PROTOCOL_VERSION);
  666. break;
  667. case svc_disconnect:
  668. Host_EndGame ("Server disconnected\n");
  669. case svc_print:
  670. Con_Printf ("%s", MSG_ReadString ());
  671. break;
  672. case svc_centerprint:
  673. SCR_CenterPrint (MSG_ReadString ());
  674. break;
  675. case svc_stufftext:
  676. Cbuf_AddText (MSG_ReadString ());
  677. break;
  678. case svc_damage:
  679. V_ParseDamage ();
  680. break;
  681. case svc_serverinfo:
  682. CL_ParseServerInfo ();
  683. vid.recalc_refdef = true; // leave intermission full screen
  684. break;
  685. case svc_setangle:
  686. for (i=0 ; i<3 ; i++)
  687. cl.viewangles[i] = MSG_ReadAngle ();
  688. break;
  689. case svc_setview:
  690. cl.viewentity = MSG_ReadShort ();
  691. break;
  692. case svc_lightstyle:
  693. i = MSG_ReadByte ();
  694. if (i >= MAX_LIGHTSTYLES)
  695. Sys_Error ("svc_lightstyle > MAX_LIGHTSTYLES");
  696. Q_strcpy (cl_lightstyle[i].map, MSG_ReadString());
  697. cl_lightstyle[i].length = Q_strlen(cl_lightstyle[i].map);
  698. break;
  699. case svc_sound:
  700. CL_ParseStartSoundPacket();
  701. break;
  702. case svc_stopsound:
  703. i = MSG_ReadShort();
  704. S_StopSound(i>>3, i&7);
  705. break;
  706. case svc_updatename:
  707. Sbar_Changed ();
  708. i = MSG_ReadByte ();
  709. if (i >= cl.maxclients)
  710. Host_Error ("CL_ParseServerMessage: svc_updatename > MAX_SCOREBOARD");
  711. strcpy (cl.scores[i].name, MSG_ReadString ());
  712. break;
  713. case svc_updatefrags:
  714. Sbar_Changed ();
  715. i = MSG_ReadByte ();
  716. if (i >= cl.maxclients)
  717. Host_Error ("CL_ParseServerMessage: svc_updatefrags > MAX_SCOREBOARD");
  718. cl.scores[i].frags = MSG_ReadShort ();
  719. break;
  720. case svc_updatecolors:
  721. Sbar_Changed ();
  722. i = MSG_ReadByte ();
  723. if (i >= cl.maxclients)
  724. Host_Error ("CL_ParseServerMessage: svc_updatecolors > MAX_SCOREBOARD");
  725. cl.scores[i].colors = MSG_ReadByte ();
  726. CL_NewTranslation (i);
  727. break;
  728. case svc_particle:
  729. R_ParseParticleEffect ();
  730. break;
  731. case svc_spawnbaseline:
  732. i = MSG_ReadShort ();
  733. // must use CL_EntityNum() to force cl.num_entities up
  734. CL_ParseBaseline (CL_EntityNum(i));
  735. break;
  736. case svc_spawnstatic:
  737. CL_ParseStatic ();
  738. break;
  739. case svc_temp_entity:
  740. CL_ParseTEnt ();
  741. break;
  742. case svc_setpause:
  743. {
  744. cl.paused = MSG_ReadByte ();
  745. if (cl.paused)
  746. {
  747. CDAudio_Pause ();
  748. #ifdef _WIN32
  749. VID_HandlePause (true);
  750. #endif
  751. }
  752. else
  753. {
  754. CDAudio_Resume ();
  755. #ifdef _WIN32
  756. VID_HandlePause (false);
  757. #endif
  758. }
  759. }
  760. break;
  761. case svc_signonnum:
  762. i = MSG_ReadByte ();
  763. if (i <= cls.signon)
  764. Host_Error ("Received signon %i when at %i", i, cls.signon);
  765. cls.signon = i;
  766. CL_SignonReply ();
  767. break;
  768. case svc_killedmonster:
  769. cl.stats[STAT_MONSTERS]++;
  770. break;
  771. case svc_foundsecret:
  772. cl.stats[STAT_SECRETS]++;
  773. break;
  774. case svc_updatestat:
  775. i = MSG_ReadByte ();
  776. if (i < 0 || i >= MAX_CL_STATS)
  777. Sys_Error ("svc_updatestat: %i is invalid", i);
  778. cl.stats[i] = MSG_ReadLong ();;
  779. break;
  780. case svc_spawnstaticsound:
  781. CL_ParseStaticSound ();
  782. break;
  783. case svc_cdtrack:
  784. cl.cdtrack = MSG_ReadByte ();
  785. cl.looptrack = MSG_ReadByte ();
  786. if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
  787. CDAudio_Play ((byte)cls.forcetrack, true);
  788. else
  789. CDAudio_Play ((byte)cl.cdtrack, true);
  790. break;
  791. case svc_intermission:
  792. cl.intermission = 1;
  793. cl.completed_time = cl.time;
  794. vid.recalc_refdef = true; // go to full screen
  795. break;
  796. case svc_finale:
  797. cl.intermission = 2;
  798. cl.completed_time = cl.time;
  799. vid.recalc_refdef = true; // go to full screen
  800. SCR_CenterPrint (MSG_ReadString ());
  801. break;
  802. case svc_cutscene:
  803. cl.intermission = 3;
  804. cl.completed_time = cl.time;
  805. vid.recalc_refdef = true; // go to full screen
  806. SCR_CenterPrint (MSG_ReadString ());
  807. break;
  808. case svc_sellscreen:
  809. Cmd_ExecuteString ("help", src_command);
  810. break;
  811. }
  812. }
  813. }