From 769f15a318bdac2e53a49cf8d5c05382eef7b997 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Fri, 18 Jun 2010 13:58:31 +0000 Subject: [PATCH] =?UTF-8?q?Reformat=20und=20=C3=9Cberarbeitung=20der=20Kom?= =?UTF-8?q?mentare=20f=C3=BCr=20cl=5Fparse.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/cl_parse.c | 679 ++++++++++++++++++------------------------ 1 file changed, 290 insertions(+), 389 deletions(-) diff --git a/src/client/cl_parse.c b/src/client/cl_parse.c index 6edf8474..bdd0afac 100644 --- a/src/client/cl_parse.c +++ b/src/client/cl_parse.c @@ -1,28 +1,26 @@ /* -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 + * 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. + * + */ #include "header/client.h" -char *svc_strings[256] = -{ +char *svc_strings[256] = { "svc_bad", "svc_muzzleflash", @@ -39,7 +37,7 @@ char *svc_strings[256] = "svc_stufftext", "svc_serverdata", "svc_configstring", - "svc_spawnbaseline", + "svc_spawnbaseline", "svc_centerprint", "svc_download", "svc_playerinfo", @@ -48,77 +46,71 @@ char *svc_strings[256] = "svc_frame" }; -//============================================================================= - -void CL_DownloadFileName(char *dest, int destlen, char *fn) -{ +void CL_DownloadFileName(char *dest, int destlen, char *fn) { if (strncmp(fn, "players", 7) == 0) Com_sprintf (dest, destlen, "%s/%s", BASEDIRNAME, fn); + else 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. -=============== + * Returns true if the file exists, otherwise it attempts + * to start a download from the server. */ -qboolean CL_CheckOrDownloadFile (char *filename) -{ - FILE *fp; +qboolean CL_CheckOrDownloadFile (char *filename) { + FILE *fp; char name[MAX_OSPATH]; - char *ptr; - - if (strstr (filename, "..")) - { + char *ptr; + + if (strstr (filename, "..")) { Com_Printf ("Refusing to download a path with ..\n"); return true; } - // fix backslashes + /* fix backslashes - this is mostly für UNIX comaptiblity */ while ((ptr=strchr(filename,'\\'))) { - *ptr = '/'; + *ptr = '/'; } - if (FS_LoadFile (filename, NULL) != -1) - { // it exists, no need to download + if (FS_LoadFile (filename, 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 + /* 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"); - //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 + /* check to see if we already have a tmp for this file, if so, try to resume + and open the file if not opened yet */ CL_DownloadFileName(name, sizeof(name), cls.downloadtempname); fp = fopen (name, "r+b"); - if (fp) { // it exists + + if (fp) { + /* it exists */ int len; fseek(fp, 0, SEEK_END); len = ftell(fp); cls.download = fp; - // give the server an offset to start the download + /* 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)); + 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)); + va("download %s", cls.downloadname)); } cls.downloadnumber++; @@ -127,14 +119,9 @@ qboolean CL_CheckOrDownloadFile (char *filename) } /* -=============== -CL_Download_f - -Request a download from the server -=============== -*/ -void CL_Download_f (void) -{ + * Request a download from the server + */ +void CL_Download_f (void) { char filename[MAX_OSPATH]; if (Cmd_Argc() != 2) { @@ -144,14 +131,13 @@ void CL_Download_f (void) Com_sprintf(filename, sizeof(filename), "%s", Cmd_Argv(1)); - if (strstr (filename, "..")) - { + 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 + if (FS_LoadFile (filename, NULL) != -1) { + /* it exists, no need to download */ Com_Printf("File already exists.\n"); return; } @@ -159,80 +145,71 @@ void CL_Download_f (void) 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 + /* 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)); + va("download %s", cls.downloadname)); cls.downloadnumber++; } -/* -====================== -CL_RegisterSounds -====================== -*/ -void CL_RegisterSounds (void) -{ +void CL_RegisterSounds (void) { int i; S_BeginRegistration (); CL_RegisterTEntSounds (); - for (i=1 ; istring || !*fs_gamedirvar->string || strcmp(fs_gamedirvar->string, str))) || (!*str && (fs_gamedirvar->string || *fs_gamedirvar->string))) Cvar_Set("game", str); - // parse player entity number + /* parse player entity number */ cl.playernum = MSG_ReadShort (&net_message); - // get the full level name + /* get the full level name */ str = MSG_ReadString (&net_message); - if (cl.playernum == -1) - { // playing a cinematic or showing a pic, not a level + if (cl.playernum == -1) { + /* playing a cinematic or showing a pic, not a level */ SCR_PlayCinematic (str); - } - else - { - // seperate the printfs so the server message can have a color + + } else { + /* 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 + /* need to prep refresh at next oportunity */ cl.refresh_prepped = false; } } -/* -================== -CL_ParseBaseline -================== -*/ -void CL_ParseBaseline (void) -{ +void CL_ParseBaseline (void) { entity_state_t *es; unsigned bits; int newnum; @@ -363,15 +314,7 @@ void CL_ParseBaseline (void) CL_ParseDelta (&nullstate, es, newnum, bits); } - -/* -================ -CL_LoadClientinfo - -================ -*/ -void CL_LoadClientinfo (clientinfo_t *ci, char *s) -{ +void CL_LoadClientinfo (clientinfo_t *ci, char *s) { int i; char *t; char model_name[MAX_QPATH]; @@ -383,18 +326,17 @@ void CL_LoadClientinfo (clientinfo_t *ci, char *s) strncpy(ci->cinfo, s, sizeof(ci->cinfo)); ci->cinfo[sizeof(ci->cinfo)-1] = 0; - // isolate the player's name + /* isolate the player's name */ strncpy(ci->name, s, sizeof(ci->name)); ci->name[sizeof(ci->name)-1] = 0; t = strstr (s, "\\"); - if (t) - { + + if (t) { ci->name[t-s] = 0; s = t+1; } - if (cl_noskins->value || *s == 0) - { + if (cl_noskins->value || *s == 0) { strcpy (model_filename, "players/male/tris.md2"); strcpy (weapon_filename, "players/male/weapon.md2"); strcpy (skin_filename, "players/male/grunt.pcx"); @@ -404,78 +346,80 @@ void CL_LoadClientinfo (clientinfo_t *ci, char *s) ci->weaponmodel[0] = re.RegisterModel (weapon_filename); ci->skin = re.RegisterSkin (skin_filename); ci->icon = re.RegisterPic (ci->iconname); - } - else - { - // isolate the model name + + } else { + /* 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; - // isolate the skin name + /* isolate the skin name */ strcpy (skin_name, s + strlen(model_name) + 1); - // model file + /* model file */ Com_sprintf (model_filename, sizeof(model_filename), "players/%s/tris.md2", model_name); ci->model = re.RegisterModel (model_filename); - if (!ci->model) - { + + if (!ci->model) { strcpy(model_name, "male"); Com_sprintf (model_filename, sizeof(model_filename), "players/male/tris.md2"); ci->model = re.RegisterModel (model_filename); } - // skin file + /* skin file */ Com_sprintf (skin_filename, sizeof(skin_filename), "players/%s/%s.pcx", model_name, skin_name); ci->skin = re.RegisterSkin (skin_filename); - // if we don't have the skin and the model wasn't male, - // see if the male has it (this is for CTF's skins) - if (!ci->skin && Q_stricmp(model_name, "male")) - { - // change model to male + /* if we don't have the skin and the model wasn't male, + see if the male has it (this is for CTF's skins) */ + if (!ci->skin && Q_stricmp(model_name, "male")) { + /* change model to male */ strcpy(model_name, "male"); Com_sprintf (model_filename, sizeof(model_filename), "players/male/tris.md2"); ci->model = re.RegisterModel (model_filename); - // see if the skin exists for the male model + /* see if the skin exists for the male model */ Com_sprintf (skin_filename, sizeof(skin_filename), "players/%s/%s.pcx", model_name, skin_name); ci->skin = re.RegisterSkin (skin_filename); } - // if we still don't have a skin, it means that the male model didn't have - // it, so default to grunt + /* if we still don't have a skin, it means that the male model didn't have + it, so default to grunt */ if (!ci->skin) { - // see if the skin exists for the male model + /* see if the skin exists for the male model */ Com_sprintf (skin_filename, sizeof(skin_filename), "players/%s/grunt.pcx", model_name, skin_name); ci->skin = re.RegisterSkin (skin_filename); } - // weapon file + /* 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] = re.RegisterModel(weapon_filename); + if (!ci->weaponmodel[i] && strcmp(model_name, "cyborg") == 0) { - // try male + /* try male */ Com_sprintf (weapon_filename, sizeof(weapon_filename), "players/male/%s", cl_weaponmodels[i]); ci->weaponmodel[i] = re.RegisterModel(weapon_filename); } + if (!cl_vwep->value) - break; // only one when vwep is off + break; /* only one when vwep is off */ } - // icon file + /* icon file */ Com_sprintf (ci->iconname, sizeof(ci->iconname), "/players/%s/%s_i.pcx", model_name, skin_name); ci->icon = re.RegisterPic (ci->iconname); } - // must have loaded all data types to be valud - if (!ci->skin || !ci->icon || !ci->model || !ci->weaponmodel[0]) - { + /* 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; @@ -485,14 +429,9 @@ void CL_LoadClientinfo (clientinfo_t *ci, char *s) } /* -================ -CL_ParseClientinfo - -Load the skin, icon, and model for a client -================ -*/ -void CL_ParseClientinfo (int player) -{ + * Load the skin, icon, and model for a client + */ +void CL_ParseClientinfo (int player) { char *s; clientinfo_t *ci; @@ -503,21 +442,16 @@ void CL_ParseClientinfo (int player) CL_LoadClientinfo (ci, s); } - -/* -================ -CL_ParseConfigString -================ -*/ -void CL_ParseConfigString (void) -{ +void CL_ParseConfigString (void) { int i; char *s; char olds[MAX_QPATH]; 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)); @@ -525,282 +459,249 @@ void CL_ParseConfigString (void) strcpy (cl.configstrings[i], s); - // do something apropriate - + /* do something apropriate */ if (i >= CS_LIGHTS && i < CS_LIGHTS+MAX_LIGHTSTYLES) CL_SetLightstyle (i - CS_LIGHTS); - else if (i == CS_CDTRACK) - { - if (cl.refresh_prepped) - { + + else if (i == CS_CDTRACK) { + if (cl.refresh_prepped) { CDAudio_Play (atoi(cl.configstrings[CS_CDTRACK]), true); OGG_ResumeCmd(); } - } - else if (i >= CS_MODELS && i < CS_MODELS+MAX_MODELS) - { - if (cl.refresh_prepped) - { + + } else if (i >= CS_MODELS && i < CS_MODELS+MAX_MODELS) { + if (cl.refresh_prepped) { cl.model_draw[i-CS_MODELS] = re.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) - { + + } 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) - { + + } else if (i >= CS_IMAGES && i < CS_IMAGES+MAX_MODELS) { if (cl.refresh_prepped) cl.image_precache[i-CS_IMAGES] = re.RegisterPic (cl.configstrings[i]); - } - else if (i >= CS_PLAYERSKINS && i < CS_PLAYERSKINS+MAX_CLIENTS) - { + + } else if (i >= CS_PLAYERSKINS && i < CS_PLAYERSKINS+MAX_CLIENTS) { if (cl.refresh_prepped && strcmp(olds, s)) CL_ParseClientinfo (i-CS_PLAYERSKINS); } } - -/* -===================================================================== - -ACTION MESSAGES - -===================================================================== -*/ - -/* -================== -CL_ParseStartSoundPacket -================== -*/ -void CL_ParseStartSoundPacket(void) -{ - vec3_t pos_v; +void CL_ParseStartSoundPacket(void) { + vec3_t pos_v; float *pos; - int channel, ent; - int sound_num; - float volume; - float attenuation; + 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) + if (flags & SND_VOLUME) volume = MSG_ReadByte (&net_message) / 255.0f; + else volume = DEFAULT_SOUND_PACKET_VOLUME; - - if (flags & SND_ATTENUATION) - attenuation = MSG_ReadByte (&net_message) / 64.0f; - else - attenuation = DEFAULT_SOUND_PACKET_ATTENUATION; - if (flags & SND_OFFSET) + if (flags & SND_ATTENUATION) + attenuation = MSG_ReadByte (&net_message) / 64.0f; + + else + attenuation = DEFAULT_SOUND_PACKET_ATTENUATION; + + if (flags & SND_OFFSET) ofs = MSG_ReadByte (&net_message) / 1000.0f; + else ofs = 0; - if (flags & SND_ENT) - { // entity reletive - channel = MSG_ReadShort(&net_message); + 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 - { + + } else { ent = 0; channel = 0; } - if (flags & SND_POS) - { // positioned in space + if (flags & SND_POS) { + /* positioned in space */ MSG_ReadPos (&net_message, pos_v); - + pos = pos_v; - } - else // use entity number + + } 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) -{ +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; +void CL_ParseServerMessage (void) { + int cmd; + char *s; + int i; - // - // if recording demos, copy the message out - // + /* 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) - { + /* 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) - { + if (cmd == -1) { SHOWNET("END OF MESSAGE"); break; } - if (cl_shownet->value>=2) - { + 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: - break; - - case svc_disconnect: - Com_Error (ERR_DISCONNECT,"Server disconnected\n"); - break; - case svc_reconnect: - Com_Printf ("Server disconnected, reconnecting\n"); - if (cls.download) { - //ZOID, close download - fclose (cls.download); - cls.download = NULL; - } - cls.state = ca_connecting; - cls.connect_time = -99999; // CL_CheckForResend() will fire immediately - break; + /* other commands */ + switch (cmd) { + default: + Com_Error (ERR_DROP,"CL_ParseServerMessage: Illegible server message\n"); + break; - case svc_print: - i = MSG_ReadByte (&net_message); - if (i == PRINT_CHAT) - { - S_StartLocalSound ("misc/talk.wav"); - con.ormask = 128; - } - Com_Printf ("%s", MSG_ReadString (&net_message)); - con.ormask = 0; - 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_nop: + break; - case svc_temp_entity: - CL_ParseTEnt (); - break; + case svc_disconnect: + Com_Error (ERR_DISCONNECT,"Server disconnected\n"); + break; - case svc_muzzleflash: - CL_ParseMuzzleFlash (); - break; + case svc_reconnect: + Com_Printf ("Server disconnected, reconnecting\n"); - case svc_muzzleflash2: - CL_ParseMuzzleFlash2 (); - break; + if (cls.download) { + /* close download */ + fclose (cls.download); + cls.download = NULL; + } - case svc_download: - CL_ParseDownload (); - break; + cls.state = ca_connecting; + cls.connect_time = -99999; /* CL_CheckForResend() will fire immediately */ + break; - case svc_frame: - CL_ParseFrame (); - break; + case svc_print: + i = MSG_ReadByte (&net_message); - case svc_inventory: - CL_ParseInventory (); - break; + if (i == PRINT_CHAT) { + S_StartLocalSound ("misc/talk.wav"); + con.ormask = 128; + } - case svc_layout: - s = MSG_ReadString (&net_message); - strncpy (cl.layout, s, sizeof(cl.layout)-1); - break; + Com_Printf ("%s", MSG_ReadString (&net_message)); + con.ormask = 0; + break; - case svc_playerinfo: - case svc_packetentities: - case svc_deltapacketentities: - Com_Error (ERR_DROP, "Out of place frame data"); - 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_muzzleflash2: + CL_ParseMuzzleFlash2 (); + 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 - // + /* 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 (); } - -