1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
|
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// cl_parse.c -- parse a message received from the server
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "client.h"
char *svc_strings[256] =
{
"svc_bad",
"svc_muzzleflash",
"svc_muzzlflash2",
"svc_temp_entity",
"svc_layout",
"svc_inventory",
"svc_nop",
"svc_disconnect",
"svc_reconnect",
"svc_sound",
"svc_print",
"svc_stufftext",
"svc_serverdata",
"svc_configstring",
"svc_spawnbaseline",
"svc_centerprint",
"svc_download",
"svc_playerinfo",
"svc_packetentities",
"svc_deltapacketentities",
"svc_frame"
};
static size_t szr; // just for unused result warnings
/*
==============
Q_strncpyz
==============
*/
void Q_strncpyz( char *dest, const char *src, size_t size )
{
#if defined HAVE_STRLCPY
strlcpy( dest, src, size );
#else
if( size )
{
while( --size && (*dest++ = *src++) );
*dest = '\0';
}
#endif
}
//=============================================================================
void CL_DownloadFileName(char *dest, int destlen, char *fn)
{
Com_sprintf (dest, destlen, "%s/%s", FS_Gamedir(), fn);
}
/*
===============
CL_CheckOrDownloadFile
Returns true if the file exists, otherwise it attempts
to start a download from the server.
===============
*/
qboolean CL_CheckOrDownloadFile (char *filename)
{
FILE *fp;
char name[MAX_OSPATH];
char shortname[MAX_OSPATH];
char shortname2[MAX_OSPATH];
qboolean jpg = false;
if (strstr (filename, ".."))
{
Com_Printf ("Refusing to download a path with ..\n");
return true;
}
//if pcx, strip extension and change to .jpg, we do not use .pcx anymore
if(filename[strlen(filename)-1] == 'x')
{
//Filter out any potentially screwed up texture paths(meshes only reside in these folders)
if (strncmp(filename, "models", 6) && strncmp(filename, "vehicles", 8)
&& strncmp(filename, "maps", 4))
return true;
COM_StripExtension ( filename, shortname );
sprintf(filename, "%s.jpg", shortname);
}
//if jpg, be sure to also try tga
if(filename[strlen(filename)-2] == 'p' && filename[strlen(filename)-1] == 'g')
jpg = true;
if (FS_LoadFile (filename, NULL) != -1)
{
// it exists, no need to download
return true;
}
if(jpg)
{
//didn't find .jpg skin, try for .tga skin
//check for presence of a local .tga(but leave filename as original extension)
//if we find a .tga, don't try to download anything
COM_StripExtension ( filename, shortname );
sprintf(shortname2, "%s.tga", shortname);
if (FS_LoadFile (shortname2, NULL) != -1)
{
// it exists, no need to download
return true;
}
}
strcpy (cls.downloadname, filename);
// download to a temp name, and only rename
// to the real name when done, so if interrupted
// a runt file wont be left
COM_StripExtension (cls.downloadname, cls.downloadtempname);
strcat (cls.downloadtempname, ".tmp");
// attempt an http download if available(never try to dl game model skins here)
if(cls.downloadurl[0] && CL_HttpDownload())
return false;
//ZOID
// check to see if we already have a tmp for this file, if so, try to resume
// open the file if not opened yet
CL_DownloadFileName(name, sizeof(name), cls.downloadtempname);
// FS_CreatePath (name);
fp = fopen (name, "r+b");
if (fp)
{ // it exists
int len;
len = FS_filelength( fp );
cls.download = fp;
// give the server an offset to start the download
Com_Printf ("Resuming %s\n", cls.downloadname);
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
MSG_WriteString (&cls.netchan.message,
va("download %s %i", cls.downloadname, len));
} else
{
Com_Printf ("Downloading %s\n", cls.downloadname);
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
MSG_WriteString (&cls.netchan.message,
va("download %s", cls.downloadname));
}
cls.downloadnumber++;
send_packet_now = true;
return false;
}
/*
===============
CL_Download_f
Request a download from the server
===============
*/
void CL_Download_f (void)
{
char filename[MAX_OSPATH];
if (Cmd_Argc() != 2)
{
Com_Printf("Usage: download <filename>\n");
return;
}
Com_sprintf(filename, sizeof(filename), "%s", Cmd_Argv(1));
if (strstr (filename, ".."))
{
Com_Printf ("Refusing to download a path with ..\n");
return;
}
if (FS_LoadFile (filename, NULL) != -1)
{ // it exists, no need to download
Com_Printf("File already exists.\n");
return;
}
strcpy (cls.downloadname, filename);
Com_Printf ("Downloading %s\n", cls.downloadname);
// download to a temp name, and only rename
// to the real name when done, so if interrupted
// a runt file wont be left
COM_StripExtension (cls.downloadname, cls.downloadtempname);
strcat (cls.downloadtempname, ".tmp");
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
MSG_WriteString (&cls.netchan.message,
va("download %s", cls.downloadname));
cls.downloadnumber++;
}
/*
======================
CL_RegisterSounds
======================
*/
void CL_RegisterSounds (void)
{
int i;
S_BeginRegistration ();
CL_RegisterTEntSounds ();
for (i=1 ; i<MAX_SOUNDS ; i++)
{
if (!cl.configstrings[CS_SOUNDS+i][0])
break;
cl.sound_precache[i] = S_RegisterSound (cl.configstrings[CS_SOUNDS+i]);
Sys_SendKeyEvents (); // pump message loop
}
S_EndRegistration ();
}
/*
=====================
CL_ParseDownload
A download message has been received from the server
=====================
*/
void CL_ParseDownload (void)
{
int size, percent;
char name[MAX_OSPATH];
int r;
// read the data
size = MSG_ReadShort (&net_message);
percent = MSG_ReadByte (&net_message);
if (size < 0) //fix issues with bad data being dl'd
{
Com_Printf ("Server does not have file %s.\n", cls.downloadname);
//nuke the temp filename, we don't want that getting left around.
cls.downloadtempname[0] = 0;
cls.downloadname[0] = 0;
if (cls.download)
{
// if here, we tried to resume a file but the server said no
fclose (cls.download);
cls.download = NULL;
}
CL_RequestNextDownload ();
return;
}
// open the file if not opened yet
if (!cls.download)
{
CL_DownloadFileName(name, sizeof(name), cls.downloadtempname);
FS_CreatePath (name);
cls.download = fopen (name, "wb");
if (!cls.download)
{
net_message.readcount += size;
Com_Printf ("Failed to open %s\n", cls.downloadtempname);
CL_RequestNextDownload ();
return;
}
}
szr = fwrite (net_message.data + net_message.readcount, 1, size, cls.download);
net_message.readcount += size;
if (percent != 100)
{
// request next block
cls.downloadpercent = percent;
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
SZ_Print (&cls.netchan.message, "nextdl");
send_packet_now = true;
}
else
{
char oldn[MAX_OSPATH];
char newn[MAX_OSPATH];
// Com_Printf ("100%%\n");
fclose (cls.download);
// rename the temp file to it's final name
CL_DownloadFileName(oldn, sizeof(oldn), cls.downloadtempname);
CL_DownloadFileName(newn, sizeof(newn), cls.downloadname);
r = rename (oldn, newn);
if (r)
Com_Printf ("failed to rename.\n");
cls.download = NULL;
cls.downloadpercent = 0;
// get another file if needed
CL_RequestNextDownload ();
}
}
/*
=====================================================================
SERVER CONNECTING MESSAGES
=====================================================================
*/
/*
==================
CL_ParseServerData
==================
*/
void CL_ParseServerData (void)
{
extern cvar_t *fs_gamedirvar;
char *str;
int i;
Com_DPrintf ("Serverdata packet received.\n");
//
// wipe the client_state_t struct
//
CL_ClearState ();
cls.state = ca_connected;
// parse protocol version number
i = MSG_ReadLong (&net_message);
cls.serverProtocol = i;
// BIG HACK to let demos from release work with the 3.0x patch!!!
if (Com_ServerState() && PROTOCOL_VERSION == 34)
{
}
else if (i != PROTOCOL_VERSION)
Com_Error (ERR_DROP,"Server returned version %i, not %i", i, PROTOCOL_VERSION);
cl.servercount = MSG_ReadLong (&net_message);
cl.attractloop = MSG_ReadByte (&net_message);
// game directory
str = MSG_ReadString (&net_message);
strncpy (cl.gamedir, str, sizeof(cl.gamedir)-1);
// set gamedir
if ((*str && (!fs_gamedirvar->string || !*fs_gamedirvar->string || strcmp(fs_gamedirvar->string, str))) || (!*str && (fs_gamedirvar->string || *fs_gamedirvar->string)))
Cvar_Set("game", str);
// parse player entity number
cl.playernum = MSG_ReadShort (&net_message);
// get the full level name
str = MSG_ReadString (&net_message);
// seperate the printfs so the server message can have a color
Com_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");
Com_Printf ("%c%s\n", 2, str);
// need to prep refresh at next oportunity
cl.refresh_prepped = false;
}
/*
==================
CL_ParseBaseline
==================
*/
void CL_ParseBaseline (void)
{
entity_state_t *es;
int bits;
int newnum;
entity_state_t nullstate;
memset (&nullstate, 0, sizeof(nullstate));
newnum = CL_ParseEntityBits ( (unsigned *)&bits );
es = &cl_entities[newnum].baseline;
CL_ParseDelta (&nullstate, es, newnum, bits);
}
/*
================
CL_LoadClientinfo
================
*/
void CL_LoadClientinfo (clientinfo_t *ci, char *s)
{
int i;
char *t;
char model_name[MAX_QPATH];
char skin_name[MAX_QPATH];
char model_filename[MAX_QPATH];
char skin_filename[MAX_QPATH];
char weapon_filename[MAX_QPATH];
FILE *file;
strncpy(ci->cinfo, s, sizeof(ci->cinfo));
ci->cinfo[sizeof(ci->cinfo)-1] = 0;
// isolate the player's name
strncpy(ci->name, s, sizeof(ci->name));
ci->name[sizeof(ci->name)-1] = 0;
t = strstr (s, "\\");
if (t)
{
ci->name[t-s] = 0;
s = t+1;
}
// isolate the model name
strcpy (model_name, s);
t = strstr(model_name, "/");
if (!t)
t = strstr(model_name, "\\");
if (!t)
t = model_name;
*t = 0;
ci->helmet = NULL; //we only worry about this in these cases of missing textures or models
ci->lod1 = NULL;
ci->lod2 = NULL;
if (cl_noskins->value || *s == 0)
{
Com_sprintf (model_filename, sizeof(model_filename), "players/martianenforcer/tris.md2");
Com_sprintf (weapon_filename, sizeof(weapon_filename), "players/martianenforcer/weapon.md2");
Com_sprintf (skin_filename, sizeof(skin_filename), "players/martianenforcer/default.pcx");
Com_sprintf (ci->iconname, sizeof(ci->iconname), "/players/martianenforcer/default_i.pcx");
ci->model = R_RegisterModel (model_filename);
ci->helmet = R_RegisterModel("players/martianenforcer/helmet.md2");
// weapon file
for (i = 0; i < num_cl_weaponmodels; i++)
{
Com_sprintf (weapon_filename, sizeof(weapon_filename), "players/martianenforcer/%s", cl_weaponmodels[i]);
ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
if (!cl_vwep->value)
break; // only one when vwep is off
}
ci->skin = R_RegisterSkin (skin_filename);
ci->icon = R_RegisterPic (ci->iconname);
}
else
{
// isolate the skin name
strcpy (skin_name, s + strlen(model_name) + 1);
// model file
Com_sprintf (model_filename, sizeof(model_filename), "players/%s/tris.md2", model_name);
ci->model = R_RegisterModel (model_filename);
if (!ci->model)
{
Com_sprintf (model_filename, sizeof(model_filename), "players/martianenforcer/tris.md2");
ci->model = R_RegisterModel (model_filename);
ci->helmet = R_RegisterModel("players/martianenforcer/helmet.md2");
strcpy(model_name, "martianenforcer");
}
// skin file
Com_sprintf (skin_filename, sizeof(skin_filename), "players/%s/%s.pcx", model_name, skin_name);
ci->skin = R_RegisterSkin (skin_filename);
// if don't have a skin, it means that the model didn't have
// it, so default
if (!ci->skin)
{
strcpy(skin_name, "default");
Com_sprintf (skin_filename, sizeof(skin_filename), "players/%s/default.pcx", model_name);
ci->skin = R_RegisterSkin (skin_filename);
}
// weapon file
for (i = 0; i < num_cl_weaponmodels; i++)
{
Com_sprintf (weapon_filename, sizeof(weapon_filename), "players/%s/%s", model_name, cl_weaponmodels[i]);
ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
if (!ci->weaponmodel[i] == 0) {
Com_sprintf (weapon_filename, sizeof(weapon_filename), "players/martianenforcer/%s", cl_weaponmodels[i]);
ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
}
if (!cl_vwep->value)
break; // only one when vwep is off
}
// icon file
Com_sprintf (ci->iconname, sizeof(ci->iconname), "/players/%s/%s_i.pcx", model_name, skin_name);
ci->icon = R_RegisterPic (ci->iconname);
}
//check for level of detail models
if (cl_noskins->value || *s == 0)
strcpy(model_name, "martianenforcer");
Com_sprintf(model_filename, sizeof(model_filename), "players/%s/lod1.md2", model_name);
i = 0;
do
model_filename[i] = tolower(model_filename[i]);
while (model_filename[i++]);
FS_FOpenFile (model_filename, &file);
if(file)
{
//exists
fclose(file);
ci->lod1 = R_RegisterModel(model_filename);
}
else
ci->lod1 = NULL;
Com_sprintf(model_filename, sizeof(model_filename), "players/%s/lod2.md2", model_name);
i = 0;
do
model_filename[i] = tolower(model_filename[i]);
while (model_filename[i++]);
FS_FOpenFile (model_filename, &file);
if(file)
{
//exists
fclose(file);
ci->lod2 = R_RegisterModel(model_filename);
}
else
ci->lod2 = NULL;
// must have loaded all data types to be valid
if (!ci->skin || !ci->icon || !ci->model || !ci->weaponmodel[0])
{
ci->skin = NULL;
ci->icon = NULL;
ci->model = NULL;
ci->weaponmodel[0] = NULL;
return;
}
}
/*
================
CL_ParseClientinfo
Load the skin, icon, and model for a client
================
*/
void CL_ParseClientinfo (int player)
{
char *s;
clientinfo_t *ci;
s = cl.configstrings[player+CS_PLAYERSKINS];
ci = &cl.clientinfo[player];
CL_LoadClientinfo (ci, s);
}
void CL_ParseTaunt( char *s)
{
int l, j;
char tauntsound[MAX_OSPATH];
//parse
strcpy( scr_playericon, COM_Parse( &s ) );
l = strlen(scr_playericon);
for (j=0 ; j<l ; j++)
scr_playericon[j] = tolower(scr_playericon[j]);
Com_sprintf(scr_playericon, sizeof(scr_playericon), "%s_i", scr_playericon);
strcpy( tauntsound, COM_Parse( &s ) );
Q_strncpyz2( scr_playername, COM_Parse( &s ), sizeof(scr_playername) );
if(cl_playtaunts->value)
{
S_StartSound (NULL, 0, 0, S_RegisterSound (tauntsound), 1, ATTN_NONE, 0);
scr_playericonalpha = 2.0;
}
}
/*
================
CL_ParseConfigString
================
*/
void CL_ParseConfigString (void)
{
int i;
char *s;
char olds[MAX_QPATH];
size_t length;
i = MSG_ReadShort (&net_message);
if (i < 0 || i >= MAX_CONFIGSTRINGS)
Com_Error (ERR_DROP, "configstring > MAX_CONFIGSTRINGS");
s = MSG_ReadString(&net_message);
strncpy (olds, cl.configstrings[i], sizeof(olds));
olds[sizeof(olds) - 1] = 0;
//r1: overflow may be desired by some mods in stats programs for example. who knows.
length = strlen(s);
if (length >= (sizeof(cl.configstrings[0]) * (MAX_CONFIGSTRINGS-i)) - 1)
Com_Error (ERR_DROP, "CL_ParseConfigString: configstring %d exceeds available space", i);
//r1: don't allow basic things to overflow
if (i != CS_NAME && i < CS_GENERAL)
{
if (i >= CS_STATUSBAR && i < CS_AIRACCEL)
{
strncpy (cl.configstrings[i], s, (sizeof(cl.configstrings[i]) * (CS_AIRACCEL - i))-1);
}
else
{
// Alien Arena client/server protocol depends on MAX_QPATH being 64
if (length >= MAX_QPATH)
Com_Printf ("WARNING: Configstring %d of length %d exceeds MAX_QPATH.\n", i, length);
Q_strncpyz (cl.configstrings[i], s, sizeof(cl.configstrings[i])-1);
}
}
else
{
strcpy (cl.configstrings[i], s);
}
// do something apropriate
if (i >= CS_LIGHTS && i < CS_LIGHTS+MAX_LIGHTSTYLES)
CL_SetLightstyle (i - CS_LIGHTS);
else if (i >= CS_MODELS && i < CS_MODELS+MAX_MODELS)
{
if (cl.refresh_prepped)
{
cl.model_draw[i-CS_MODELS] = R_RegisterModel (cl.configstrings[i]);
if (cl.configstrings[i][0] == '*')
cl.model_clip[i-CS_MODELS] = CM_InlineModel (cl.configstrings[i]);
else
cl.model_clip[i-CS_MODELS] = NULL;
}
}
else if (i >= CS_SOUNDS && i < CS_SOUNDS+MAX_MODELS)
{
if (cl.refresh_prepped)
cl.sound_precache[i-CS_SOUNDS] = S_RegisterSound (cl.configstrings[i]);
}
else if (i >= CS_IMAGES && i < CS_IMAGES+MAX_MODELS)
{
if (cl.refresh_prepped)
cl.image_precache[i-CS_IMAGES] = R_RegisterPic (cl.configstrings[i]);
}
else if (i >= CS_PLAYERSKINS && i < CS_PLAYERSKINS+MAX_CLIENTS)
{
if (cl.refresh_prepped && strcmp(olds, s))
CL_ParseClientinfo (i-CS_PLAYERSKINS);
}
else if ( i == CS_GENERAL)
CL_ParseTaunt(s);
}
/*
=====================================================================
ACTION MESSAGES
=====================================================================
*/
/*
==================
CL_ParseStartSoundPacket
==================
*/
void CL_ParseStartSoundPacket(void)
{
vec3_t pos_v;
float *pos;
int channel, ent;
int sound_num;
float volume;
float attenuation;
int flags;
float ofs;
flags = MSG_ReadByte (&net_message);
sound_num = MSG_ReadByte (&net_message);
if (flags & SND_VOLUME)
volume = MSG_ReadByte (&net_message) / 255.0;
else
volume = DEFAULT_SOUND_PACKET_VOLUME;
if (flags & SND_ATTENUATION)
attenuation = MSG_ReadByte (&net_message) / 64.0;
else
attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
if (flags & SND_OFFSET)
ofs = MSG_ReadByte (&net_message) / 1000.0;
else
ofs = 0;
if (flags & SND_ENT)
{ // entity reletive
channel = MSG_ReadShort(&net_message);
ent = channel>>3;
if (ent > MAX_EDICTS)
Com_Error (ERR_DROP,"CL_ParseStartSoundPacket: ent = %i", ent);
channel &= 7;
}
else
{
ent = 0;
channel = 0;
}
if (flags & SND_POS)
{ // positioned in space
MSG_ReadPos (&net_message, pos_v);
pos = pos_v;
}
else // use entity number
pos = NULL;
if (!cl.sound_precache[sound_num])
return;
S_StartSound (pos, ent, channel, cl.sound_precache[sound_num], volume, attenuation, ofs);
}
void SHOWNET(char *s)
{
if (cl_shownet->value>=2)
Com_Printf ("%3i:%s\n", net_message.readcount-1, s);
}
/*
=====================
CL_ParseServerMessage
=====================
*/
void CL_ParseServerMessage (void)
{
int cmd;
char *s;
int i;
//
// if recording demos, copy the message out
//
if (cl_shownet->value == 1)
Com_Printf ("%i ",net_message.cursize);
else if (cl_shownet->value >= 2)
Com_Printf ("------------------\n");
//
// parse the message
//
while (1)
{
if (net_message.readcount > net_message.cursize)
{
Com_Error (ERR_DROP,"CL_ParseServerMessage: Bad server message");
break;
}
cmd = MSG_ReadByte (&net_message);
if (cmd == -1)
{
SHOWNET("END OF MESSAGE");
break;
}
if (cl_shownet->value>=2)
{
if (!svc_strings[cmd])
Com_Printf ("%3i:BAD CMD %i\n", net_message.readcount-1,cmd);
else
SHOWNET(svc_strings[cmd]);
}
// other commands
switch (cmd)
{
default:
Com_Error (ERR_DROP,"CL_ParseServerMessage: Illegible server message\n");
break;
case svc_nop:
// Com_Printf ("svc_nop\n");
break;
case svc_disconnect:
Com_Error (ERR_DISCONNECT,"Server disconnected\n");
break;
case svc_reconnect:
Com_Printf ("Server disconnected, reconnecting\n");
// stop download
if(cls.download)
{
if(cls.downloadhttp) // clean up http downloads
CL_HttpDownloadCleanup();
else // or just stop legacy ones
fclose(cls.download);
cls.download = NULL;
}
cls.state = ca_connecting;
cls.connect_time = -99999; // CL_CheckForResend() will fire immediately
break;
case svc_print:
i = MSG_ReadByte (&net_message);
if (i == PRINT_CHAT)
{
S_StartLocalSound ("misc/talk.wav");
}
Com_Printf ("%s", MSG_ReadString (&net_message));
break;
case svc_centerprint:
SCR_CenterPrint (MSG_ReadString (&net_message));
break;
case svc_stufftext:
s = MSG_ReadString (&net_message);
Com_DPrintf ("stufftext: %s\n", s);
Cbuf_AddText (s);
break;
case svc_serverdata:
Cbuf_Execute (); // make sure any stuffed commands are done
CL_ParseServerData ();
break;
case svc_configstring:
CL_ParseConfigString ();
break;
case svc_sound:
CL_ParseStartSoundPacket();
break;
case svc_spawnbaseline:
CL_ParseBaseline ();
break;
case svc_temp_entity:
CL_ParseTEnt ();
break;
case svc_muzzleflash:
CL_ParseMuzzleFlash ();
break;
case svc_download:
CL_ParseDownload ();
break;
case svc_frame:
CL_ParseFrame ();
break;
case svc_inventory:
CL_ParseInventory ();
break;
case svc_layout:
s = MSG_ReadString (&net_message);
strncpy (cl.layout, s, sizeof(cl.layout)-1);
break;
case svc_playerinfo:
case svc_packetentities:
case svc_deltapacketentities:
Com_Error (ERR_DROP, "Out of place frame data");
break;
}
}
CL_AddNetgraph ();
//
// we don't know if it is ok to save a demo message until
// after we have parsed the frame
//
if (cls.demorecording && !cls.demowaiting)
CL_WriteDemoMessage ();
}
|