/* * @brief */ static void Cl_ParseBaseline(void) { static entity_state_t null_state; const uint16_t number = Net_ReadShort(&net_message); const uint16_t bits = Net_ReadShort(&net_message); entity_state_t *state = &cl.entities[number].baseline; Net_ReadDeltaEntity(&net_message, &null_state, state, number, bits); }
/* * @brief */ void Cl_ParseConfigString(void) { const uint16_t i = (uint16_t) Net_ReadShort(&net_message); if (i >= MAX_CONFIG_STRINGS) { Com_Error(ERR_DROP, "Invalid index %i\n", i); } strcpy(cl.config_strings[i], Net_ReadString(&net_message)); const char *s = cl.config_strings[i]; if (i > CS_MODELS && i < CS_MODELS + MAX_MODELS) { if (cls.state == CL_ACTIVE) { cl.model_precache[i - CS_MODELS] = R_LoadModel(s); if (cl.config_strings[i][0] == '*') { cl.model_clip[i - CS_MODELS] = Cm_Model(s); } else { cl.model_clip[i - CS_MODELS] = NULL; } } } else if (i >= CS_SOUNDS && i < CS_SOUNDS + MAX_SOUNDS) { if (cls.state == CL_ACTIVE) { cl.sound_precache[i - CS_SOUNDS] = S_LoadSample(s); } } else if (i >= CS_IMAGES && i < CS_IMAGES + MAX_IMAGES) { if (cls.state == CL_ACTIVE) { cl.image_precache[i - CS_IMAGES] = R_LoadImage(s, IT_PIC); } } cls.cgame->UpdateConfigString(i); }
/** * @brief */ static void Cl_ParseServerData(void) { // wipe the cl_client_t struct Cl_ClearState(); Cl_SetKeyDest(KEY_CONSOLE); // parse protocol version number const uint16_t major = Net_ReadShort(&net_message); const uint16_t minor = Net_ReadShort(&net_message); // ensure protocol major matches if (major != PROTOCOL_MAJOR) { Com_Error(ERROR_DROP, "Server is using protocol major %d\n", major); } // determine if we're viewing a demo cl.demo_server = Net_ReadByte(&net_message); // game directory char *str = Net_ReadString(&net_message); if (g_strcmp0(Cvar_GetString("game"), str)) { Fs_SetGame(str); // reload the client game Cl_InitCgame(); } // ensure protocol minor matches if (minor != cls.cgame->protocol) { Com_Error(ERROR_DROP, "Server is using protocol minor %d\n", minor); } // parse client slot number, which is our entity number + 1 cl.client_num = Net_ReadShort(&net_message); // get the full level name str = Net_ReadString(&net_message); Com_Print("\n"); Com_Print("^2%s^7\n", str); }
/** * @brief */ static void Cl_ParseBaseline(void) { static entity_state_t null_state; const uint16_t number = Net_ReadShort(&net_message); const uint16_t bits = Net_ReadShort(&net_message); cl_entity_t *ent = &cl.entities[number]; Net_ReadDeltaEntity(&net_message, &null_state, &ent->baseline, number, bits); // initialize clipping matrices if (ent->baseline.solid) { if (ent->baseline.solid == SOLID_BSP) { Matrix4x4_CreateFromEntity(&ent->matrix, ent->baseline.origin, ent->baseline.angles, 1.0); Matrix4x4_Invert_Simple(&ent->inverse_matrix, &ent->matrix); } else { // bounding-box entities Matrix4x4_CreateFromEntity(&ent->matrix, ent->baseline.origin, vec3_origin, 1.0); Matrix4x4_Invert_Simple(&ent->inverse_matrix, &ent->matrix); } } }
/* * @brief A download message has been received from the server. */ static void Cl_ParseDownload(void) { int32_t size, percent; // read the data size = Net_ReadShort(&net_message); percent = Net_ReadByte(&net_message); if (size < 0) { Com_Debug("Server does not have this file\n"); if (cls.download.file) { // if here, we tried to resume a file but the server said no Fs_Close(cls.download.file); cls.download.file = NULL; } Cl_RequestNextDownload(); return; } // open the file if not opened yet if (!cls.download.file) { if (!(cls.download.file = Fs_OpenWrite(cls.download.tempname))) { net_message.read += size; Com_Warn("Failed to open %s\n", cls.download.tempname); Cl_RequestNextDownload(); return; } } Fs_Write(cls.download.file, net_message.data + net_message.read, 1, size); net_message.read += size; if (percent != 100) { Net_WriteByte(&cls.net_chan.message, CL_CMD_STRING); Net_WriteString(&cls.net_chan.message, "nextdl"); } else { Fs_Close(cls.download.file); cls.download.file = NULL; // add new archives to the search path if (Fs_Rename(cls.download.tempname, cls.download.name)) { if (strstr(cls.download.name, ".zip")) { Fs_AddToSearchPath(cls.download.name); } } else { Com_Error(ERR_DROP, "Failed to rename %s\n", cls.download.name); } // get another file if needed Cl_RequestNextDownload(); } }
/* * @brief */ static void Cl_ParseServerData(void) { char *str; int32_t i; // wipe the cl_client_t struct Cl_ClearState(); cls.state = CL_CONNECTED; cls.key_state.dest = KEY_CONSOLE; // parse protocol version number i = Net_ReadLong(&net_message); // ensure protocol matches if (i != PROTOCOL) { Com_Error(ERR_DROP, "Server is using unknown protocol %d\n", i); } // retrieve spawn count and packet rate cl.server_count = Net_ReadLong(&net_message); cl.server_hz = Net_ReadLong(&net_message); // determine if we're viewing a demo cl.demo_server = Net_ReadByte(&net_message); // game directory str = Net_ReadString(&net_message); if (g_strcmp0(Cvar_GetString("game"), str)) { Fs_SetGame(str); // reload the client game Cl_InitCgame(); } // parse player entity number cl.entity_num = Net_ReadShort(&net_message); // get the full level name str = Net_ReadString(&net_message); Com_Print("\n"); Com_Print("%c%s\n", 2, str); }
/* * @brief */ static void Cl_ParseSound(void) { vec3_t origin; vec_t *org; uint16_t index; uint16_t ent_num; int32_t atten; int32_t flags; flags = Net_ReadByte(&net_message); if ((index = Net_ReadByte(&net_message)) > MAX_SOUNDS) Com_Error(ERR_DROP, "Bad index (%d)\n", index); if (flags & S_ATTEN) atten = Net_ReadByte(&net_message); else atten = ATTEN_DEFAULT; if (flags & S_ENTNUM) { // entity relative ent_num = Net_ReadShort(&net_message); if (ent_num > MAX_EDICTS) Com_Error(ERR_DROP, "Bad entity number (%d)\n", ent_num); } else { ent_num = 0; } if (flags & S_ORIGIN) { // positioned in space Net_ReadPosition(&net_message, origin); org = origin; } else // use ent_num org = NULL; if (!cl.sound_precache[index]) return; S_PlaySample(org, ent_num, cl.sound_precache[index], atten); }