/* net_svc_qw.c (description) Copyright (C) 2001 Adam Olsen 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: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA */ static const char rcsid[] = "$Id$"; #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifndef _WIN32 # ifdef HAVE_UNISTD_H # include # endif #else # include #endif #ifdef HAVE_STRING_H # include #endif #ifdef HAVE_STRINGS_H # include #endif #include "QF/msg.h" #include "QF/net_svc_qw.h" #include "QF/net_ucmd.h" #include "QF/sound.h" #include "QF/sys.h" net_svc_emit_t net_svc_qw_emit_jumptable[] = { [svc_qwupdatestat] = (net_svc_emit_t) NET_SVC_QWUpdateStat_Emit, [svc_qwsound] = (net_svc_emit_t) NET_SVC_QWSound_Emit, [svc_qwprint] = (net_svc_emit_t) NET_SVC_QWPrint_Emit, [svc_serverdata] = (net_svc_emit_t) NET_SVC_ServerData_Emit, [svc_qwtempentity] = (net_svc_emit_t) NET_SVC_QWTempEntity_Emit, [svc_qwintermission] = (net_svc_emit_t) NET_SVC_QWIntermission_Emit, [svc_qwcdtrack] = (net_svc_emit_t) NET_SVC_QWCDTrack_Emit, [svc_smallkick] = (net_svc_emit_t) NET_SVC_SmallKick_Emit, [svc_bigkick] = (net_svc_emit_t) NET_SVC_BigKick_Emit, [svc_updateping] = (net_svc_emit_t) NET_SVC_UpdatePing_Emit, [svc_updateentertime] = (net_svc_emit_t) NET_SVC_UpdateEnterTime_Emit, [svc_updatestatlong] = (net_svc_emit_t) NET_SVC_UpdateStatLong_Emit, [svc_muzzleflash] = (net_svc_emit_t) NET_SVC_MuzzleFlash_Emit, [svc_updateuserinfo] = (net_svc_emit_t) NET_SVC_UpdateUserInfo_Emit, [svc_download] = (net_svc_emit_t) NET_SVC_Download_Emit, [svc_playerinfo] = (net_svc_emit_t) NET_SVC_Playerinfo_Emit, [svc_nails] = (net_svc_emit_t) NET_SVC_Nails_Emit, [svc_chokecount] = (net_svc_emit_t) NET_SVC_ChokeCount_Emit, [svc_modellist] = (net_svc_emit_t) NET_SVC_Modellist_Emit, [svc_soundlist] = (net_svc_emit_t) NET_SVC_Soundlist_Emit, [svc_packetentities] = (net_svc_emit_t) NET_SVC_PacketEntities_Emit, [svc_deltapacketentities] = (net_svc_emit_t) NET_SVC_DeltaPacketEntities_Emit, [svc_maxspeed] = (net_svc_emit_t) NET_SVC_MaxSpeed_Emit, [svc_entgravity] = (net_svc_emit_t) NET_SVC_EntGravity_Emit, [svc_setinfo] = (net_svc_emit_t) NET_SVC_SetInfo_Emit, [svc_qwserverinfo] = (net_svc_emit_t) NET_SVC_QWServerInfo_Emit, [svc_updatepl] = (net_svc_emit_t) NET_SVC_UpdatePL_Emit, }; int net_svc_qw_emit_count = sizeof (net_svc_qw_emit_jumptable) / sizeof (net_svc_emit_t); net_svc_parse_t net_svc_qw_parse_jumptable[] = { [svc_qwupdatestat] = (net_svc_parse_t) NET_SVC_QWUpdateStat_Parse, [svc_qwsound] = (net_svc_parse_t) NET_SVC_QWSound_Parse, [svc_qwprint] = (net_svc_parse_t) NET_SVC_QWPrint_Parse, [svc_serverdata] = (net_svc_parse_t) NET_SVC_ServerData_Parse, [svc_qwtempentity] = (net_svc_parse_t) NET_SVC_QWTempEntity_Parse, [svc_qwintermission] = (net_svc_parse_t) NET_SVC_QWIntermission_Parse, [svc_qwcdtrack] = (net_svc_parse_t) NET_SVC_QWCDTrack_Parse, [svc_smallkick] = (net_svc_parse_t) NET_SVC_SmallKick_Parse, [svc_bigkick] = (net_svc_parse_t) NET_SVC_BigKick_Parse, [svc_updateping] = (net_svc_parse_t) NET_SVC_UpdatePing_Parse, [svc_updateentertime] = (net_svc_parse_t) NET_SVC_UpdateEnterTime_Parse, [svc_updatestatlong] = (net_svc_parse_t) NET_SVC_UpdateStatLong_Parse, [svc_muzzleflash] = (net_svc_parse_t) NET_SVC_MuzzleFlash_Parse, [svc_updateuserinfo] = (net_svc_parse_t) NET_SVC_UpdateUserInfo_Parse, [svc_download] = (net_svc_parse_t) NET_SVC_Download_Parse, [svc_playerinfo] = (net_svc_parse_t) NET_SVC_Playerinfo_Parse, [svc_nails] = (net_svc_parse_t) NET_SVC_Nails_Parse, [svc_chokecount] = (net_svc_parse_t) NET_SVC_ChokeCount_Parse, [svc_modellist] = (net_svc_parse_t) NET_SVC_Modellist_Parse, [svc_soundlist] = (net_svc_parse_t) NET_SVC_Soundlist_Parse, [svc_packetentities] = (net_svc_parse_t) NET_SVC_PacketEntities_Parse, [svc_deltapacketentities] = (net_svc_parse_t) NET_SVC_DeltaPacketEntities_Parse, [svc_maxspeed] = (net_svc_parse_t) NET_SVC_MaxSpeed_Parse, [svc_entgravity] = (net_svc_parse_t) NET_SVC_EntGravity_Parse, [svc_setinfo] = (net_svc_parse_t) NET_SVC_SetInfo_Parse, [svc_qwserverinfo] = (net_svc_parse_t) NET_SVC_QWServerInfo_Parse, [svc_updatepl] = (net_svc_parse_t) NET_SVC_UpdatePL_Parse, }; int net_svc_qw_parse_count = sizeof (net_svc_qw_parse_jumptable) / sizeof (net_svc_parse_t); net_status_t NET_SVC_QWUpdateStat_Emit (net_svc_qwupdatestat_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->stat); MSG_WriteByte (buf, block->value); return buf->overflowed; } net_status_t NET_SVC_QWUpdateStat_Parse (net_svc_qwupdatestat_t *block, msg_t *msg) { block->stat = MSG_ReadByte (msg); block->value = MSG_ReadByte (msg); return msg->badread; } net_status_t NET_SVC_QWSound_Emit (net_svc_qwsound_t *block, sizebuf_t *buf) { int i, header; header = block->channel; header |= block->entity << 3; if (block->volume != DEFAULT_SOUND_PACKET_VOLUME) header |= SND_VOLUME; if (block->attenuation != DEFAULT_SOUND_PACKET_VOLUME) header |= SND_ATTENUATION; MSG_WriteShort (buf, header); if (header & SND_VOLUME) MSG_WriteByte (buf, block->volume * 255); if (header & SND_ATTENUATION) MSG_WriteByte (buf, block->attenuation * 64); MSG_WriteByte (buf, block->sound_num); for (i = 0; i < 3; i++) MSG_WriteCoord (buf, block->position[i]); return buf->overflowed; } net_status_t NET_SVC_QWSound_Parse (net_svc_qwsound_t *block, msg_t *msg) { int i, header; header = MSG_ReadShort (msg); if (header & SND_VOLUME) block->volume = MSG_ReadByte (msg) / 255.0; else block->volume = DEFAULT_SOUND_PACKET_VOLUME / 255.0; if (header & SND_ATTENUATION) block->attenuation = MSG_ReadByte (msg) / 64.0; else block->attenuation = DEFAULT_SOUND_PACKET_ATTENUATION; block->sound_num = MSG_ReadByte (msg); for (i = 0; i < 3; i++) block->position[i] = MSG_ReadCoord (msg); block->entity = (header >> 3) & 1023; block->channel = header & 7; return msg->badread; } net_status_t NET_SVC_QWPrint_Emit (net_svc_qwprint_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->level); MSG_WriteString (buf, block->message); return buf->overflowed; } net_status_t NET_SVC_QWPrint_Parse (net_svc_qwprint_t *block, msg_t *msg) { block->level = MSG_ReadByte (msg); block->message = MSG_ReadString (msg); return msg->badread; } net_status_t NET_SVC_ServerData_Emit (net_svc_serverdata_t *block, sizebuf_t *buf) { MSG_WriteLong (buf, block->protocolversion); MSG_WriteLong (buf, block->servercount); MSG_WriteString (buf, block->gamedir); MSG_WriteByte (buf, block->playernum | (block->spectator ? 128 : 0)); MSG_WriteString (buf, block->levelname); MSG_WriteFloat (buf, block->movevars.gravity); MSG_WriteFloat (buf, block->movevars.stopspeed); MSG_WriteFloat (buf, block->movevars.maxspeed); MSG_WriteFloat (buf, block->movevars.spectatormaxspeed); MSG_WriteFloat (buf, block->movevars.accelerate); MSG_WriteFloat (buf, block->movevars.airaccelerate); MSG_WriteFloat (buf, block->movevars.wateraccelerate); MSG_WriteFloat (buf, block->movevars.friction); MSG_WriteFloat (buf, block->movevars.waterfriction); MSG_WriteFloat (buf, block->movevars.entgravity); return buf->overflowed; } net_status_t NET_SVC_ServerData_Parse (net_svc_serverdata_t *block, msg_t *msg) { block->protocolversion = MSG_ReadLong (msg); // I could abort now if the version is wrong, but why bother? block->servercount = MSG_ReadLong (msg); block->gamedir = MSG_ReadString (msg); // high bit means spectator block->playernum = MSG_ReadByte (msg); block->spectator = block->playernum >> 7; block->playernum &= ~(1 << 7); block->levelname = MSG_ReadString (msg); block->movevars.gravity = MSG_ReadFloat (msg); block->movevars.stopspeed = MSG_ReadFloat (msg); block->movevars.maxspeed = MSG_ReadFloat (msg); block->movevars.spectatormaxspeed = MSG_ReadFloat (msg); block->movevars.accelerate = MSG_ReadFloat (msg); block->movevars.airaccelerate = MSG_ReadFloat (msg); block->movevars.wateraccelerate = MSG_ReadFloat (msg); block->movevars.friction = MSG_ReadFloat (msg); block->movevars.waterfriction = MSG_ReadFloat (msg); block->movevars.entgravity = MSG_ReadFloat (msg); return msg->badread; } net_status_t NET_SVC_QWTempEntity_Emit (net_svc_qwtempentity_t *block, sizebuf_t *buf) { int i; MSG_WriteByte (buf, block->type); switch (block->type) { case TE_WIZSPIKE: case TE_KNIGHTSPIKE: case TE_SPIKE: case TE_SUPERSPIKE: case TE_EXPLOSION: case TE_TAREXPLOSION: case TE_LAVASPLASH: case TE_TELEPORT: case TE_LIGHTNINGBLOOD: for (i = 0; i < 3; i++) MSG_WriteCoord (buf, block->position[i]); break; case TE_LIGHTNING1: case TE_LIGHTNING2: case TE_LIGHTNING3: case TE_BEAM: MSG_WriteShort (buf, block->beamentity); for (i = 0; i < 3; i++) MSG_WriteShort (buf, block->position[i]); for (i = 0; i < 3; i++) MSG_WriteCoord (buf, block->beamend[i]); break; case TE_EXPLOSION2: for (i = 0; i < 3; i++) MSG_WriteCoord (buf, block->position[i]); MSG_WriteByte (buf, block->colorstart); MSG_WriteByte (buf, block->colorlength); break; case TE_GUNSHOT: case TE_BLOOD: MSG_WriteByte (buf, block->gunshotcount); for (i = 0; i < 3; i++) MSG_WriteCoord (buf, block->position[i]); break; default: return NET_ERROR; } return buf->overflowed; } net_status_t NET_SVC_QWTempEntity_Parse (net_svc_qwtempentity_t *block, msg_t *msg) { int i; block->type = MSG_ReadByte (msg); switch (block->type) { case TE_WIZSPIKE: case TE_KNIGHTSPIKE: case TE_SPIKE: case TE_SUPERSPIKE: case TE_EXPLOSION: case TE_TAREXPLOSION: case TE_LAVASPLASH: case TE_TELEPORT: case TE_LIGHTNINGBLOOD: for (i = 0; i < 3; i++) block->position[i] = MSG_ReadCoord (msg); break; case TE_LIGHTNING1: case TE_LIGHTNING2: case TE_LIGHTNING3: case TE_BEAM: block->beamentity = MSG_ReadShort (msg); for (i = 0; i < 3; i++) block->position[i] = MSG_ReadCoord (msg); for (i = 0; i < 3; i++) block->beamend[i] = MSG_ReadCoord (msg); break; case TE_EXPLOSION2: for (i = 0; i < 3; i++) block->position[i] = MSG_ReadCoord (msg); block->colorstart = MSG_ReadByte (msg); block->colorlength = MSG_ReadByte (msg); break; case TE_GUNSHOT: case TE_BLOOD: block->gunshotcount = MSG_ReadByte (msg); for (i = 0; i < 3; i++) block->position[i] = MSG_ReadCoord (msg); break; default: return NET_ERROR; } return msg->badread; } net_status_t NET_SVC_QWIntermission_Emit (net_svc_qwintermission_t *block, sizebuf_t *buf) { int i; for (i = 0; i < 3; i++) MSG_WriteCoord (buf, block->origin[i]); for (i = 0; i < 3; i++) MSG_WriteAngle (buf, block->angles[i]); return buf->overflowed; } net_status_t NET_SVC_QWIntermission_Parse (net_svc_qwintermission_t *block, msg_t *msg) { int i; for (i = 0; i < 3; i++) block->origin[i] = MSG_ReadCoord (msg); for (i = 0; i < 3; i++) block->angles[i] = MSG_ReadAngle (msg); return msg->badread; } net_status_t NET_SVC_QWCDTrack_Emit (net_svc_qwcdtrack_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->cdtrack); return buf->overflowed; } net_status_t NET_SVC_QWCDTrack_Parse (net_svc_qwcdtrack_t *block, msg_t *msg) { block->cdtrack = MSG_ReadByte (msg); return msg->badread; } net_status_t NET_SVC_SmallKick_Emit (net_svc_smallkick_t *block, sizebuf_t *buf) { return buf->overflowed; } net_status_t NET_SVC_SmallKick_Parse (net_svc_smallkick_t *block, msg_t *msg) { return msg->badread; } net_status_t NET_SVC_BigKick_Emit (net_svc_bigkick_t *block, sizebuf_t *buf) { return buf->overflowed; } net_status_t NET_SVC_BigKick_Parse (net_svc_bigkick_t *block, msg_t *msg) { return msg->badread; } net_status_t NET_SVC_UpdatePing_Emit (net_svc_updateping_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->player); MSG_WriteShort (buf, block->ping); return buf->overflowed; } net_status_t NET_SVC_UpdatePing_Parse (net_svc_updateping_t *block, msg_t *msg) { block->player = MSG_ReadByte (msg); block->ping = MSG_ReadShort (msg); return msg->badread; } net_status_t NET_SVC_UpdateEnterTime_Emit (net_svc_updateentertime_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->player); MSG_WriteFloat (buf, block->secondsago); return buf->overflowed; } net_status_t NET_SVC_UpdateEnterTime_Parse (net_svc_updateentertime_t *block, msg_t *msg) { block->player = MSG_ReadByte (msg); block->secondsago = MSG_ReadFloat (msg); return msg->badread; } net_status_t NET_SVC_UpdateStatLong_Emit (net_svc_updatestatlong_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->stat); MSG_WriteLong (buf, block->value); return buf->overflowed; } net_status_t NET_SVC_UpdateStatLong_Parse (net_svc_updatestatlong_t *block, msg_t *msg) { block->stat = MSG_ReadByte (msg); block->value = MSG_ReadLong (msg); return msg->badread; } net_status_t NET_SVC_MuzzleFlash_Emit (net_svc_muzzleflash_t *block, sizebuf_t *buf) { MSG_WriteShort (buf, block->player); return buf->overflowed; } net_status_t NET_SVC_MuzzleFlash_Parse (net_svc_muzzleflash_t *block, msg_t *msg) { block->player = MSG_ReadShort (msg); return msg->badread; } net_status_t NET_SVC_UpdateUserInfo_Emit (net_svc_updateuserinfo_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->slot); MSG_WriteLong (buf, block->userid); MSG_WriteString (buf, block->userinfo); return buf->overflowed; } net_status_t NET_SVC_UpdateUserInfo_Parse (net_svc_updateuserinfo_t *block, msg_t *msg) { block->slot = MSG_ReadByte (msg); block->userid = MSG_ReadLong (msg); block->userinfo = MSG_ReadString (msg); return msg->badread; } net_status_t NET_SVC_Download_Emit (net_svc_download_t *block, sizebuf_t *buf) { MSG_WriteShort (buf, block->size); MSG_WriteByte (buf, block->percent); if (block->size == -2) MSG_WriteString (buf, block->name); else if (block->size > 0) MSG_WriteBlock (buf, block->data, block->size); return buf->overflowed; } net_status_t NET_SVC_Download_Parse (net_svc_download_t *block, msg_t *msg) { block->size = MSG_ReadShort (msg); block->percent = MSG_ReadByte (msg); block->name = block->data = 0; if (block->size == -2) block->name = MSG_ReadString (msg); else if (block->size > 0) { block->data = MSG_ReadBlock (msg, block->size); if (!block->data) block->size = 0; // size was beyond the end of the packet } return msg->badread; } net_status_t NET_SVC_Playerinfo_Emit (net_svc_playerinfo_t *block, sizebuf_t *buf) { int i; MSG_WriteByte (buf, block->playernum); MSG_WriteShort (buf, block->flags); for (i = 0; i < 3; i++) MSG_WriteCoord (buf, block->origin[i]); MSG_WriteByte (buf, block->frame); if (block->flags & PF_MSEC) MSG_WriteByte (buf, block->msec); if (block->flags & PF_COMMAND) NET_WriteDeltaUsercmd (buf, &nullcmd, &block->usercmd); // FIXME for (i = 0; i < 3; i++) if (block->flags & (PF_VELOCITY1 << i)) MSG_WriteShort (buf, block->velocity[i]); if (block->flags & PF_MODEL) MSG_WriteByte (buf, block->modelindex); if (block->flags & PF_SKINNUM) MSG_WriteByte (buf, block->skinnum); if (block->flags & PF_EFFECTS) MSG_WriteByte (buf, block->effects); if (block->flags & PF_WEAPONFRAME) MSG_WriteByte (buf, block->weaponframe); return buf->overflowed; } net_status_t NET_SVC_Playerinfo_Parse (net_svc_playerinfo_t *block, msg_t *msg) { int i; block->playernum = MSG_ReadByte (msg); block->flags = MSG_ReadShort (msg); for (i = 0; i < 3; i++) block->origin[i] = MSG_ReadCoord (msg); block->frame = MSG_ReadByte (msg); if (block->flags & PF_MSEC) block->msec = MSG_ReadByte (msg); else block->msec = 0; // eww, FIXME if (block->flags & PF_COMMAND) NET_ReadDeltaUsercmd (msg, &nullcmd, &block->usercmd); for (i = 0; i < 3; i++) { if (block->flags & (PF_VELOCITY1 << i)) block->velocity[i] = MSG_ReadShort (msg); else block->velocity[i] = 0; } if (block->flags & PF_MODEL) block->modelindex = MSG_ReadByte (msg); else block->modelindex = 0; // suboptimal, but oh well if (block->flags & PF_SKINNUM) block->skinnum = MSG_ReadByte (msg); else block->skinnum = 0; if (block->flags & PF_EFFECTS) block->effects = MSG_ReadByte (msg); else block->effects = 0; if (block->flags & PF_WEAPONFRAME) block->weaponframe = MSG_ReadByte (msg); else block->weaponframe = 0; return msg->badread; } net_status_t NET_SVC_Nails_Emit (net_svc_nails_t *block, sizebuf_t *buf) { int i, j; int x, y, z, p, yaw; byte bits[6]; // [48 bits] xyzpy 12 12 12 4 8 if (block->numnails > MAX_PROJECTILES) return NET_ERROR; MSG_WriteByte (buf, block->numnails); for (i = 0; i < block->numnails; i++) { x = (int) (block->nails[i].origin[0] + 4096) >> 1; y = (int) (block->nails[i].origin[1] + 4096) >> 1; z = (int) (block->nails[i].origin[2] + 4096) >> 1; p = (int) (16 * block->nails[i].angles[0] / 360) & 15; yaw = (int) (256 * block->nails[i].angles[1] / 360) & 255; bits[0] = x; bits[1] = (x >> 8) | (y << 4); bits[2] = (y >> 4); bits[3] = z; bits[4] = (z >> 8) | (p << 4); bits[5] = yaw; for (j = 0; j < 6; j++) MSG_WriteByte (buf, bits[j]); } return buf->overflowed; } net_status_t NET_SVC_Nails_Parse (net_svc_nails_t *block, msg_t *msg) { int i, j; byte bits[6]; block->numnails = MSG_ReadByte (msg); for (i = 0; i < block->numnails; i++) { for (j = 0; j < 6; j++) bits[j] = MSG_ReadByte (msg); if (i >= MAX_PROJECTILES) return NET_ERROR; // [48 bits] xyzpy 12 12 12 4 8 // format is 12 bits per origin coord, 4 for angles[0], // 8 for angles[1], and 0 for angles[2] block->nails[i].origin[0] = ((bits[0] + ((bits[1] & 15) << 8)) << 1) - 4096; block->nails[i].origin[1] = (((bits[1] >> 4) + (bits[2] << 4)) << 1) - 4096; block->nails[i].origin[2] = ((bits[3] + ((bits[4] & 15) << 8)) << 1) - 4096; block->nails[i].angles[0] = 360 * (bits[4] >> 4) / 16; block->nails[i].angles[1] = 360 * bits[5] / 256; block->nails[i].angles[2] = 0; } return msg->badread; } net_status_t NET_SVC_ChokeCount_Emit (net_svc_chokecount_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->count); return buf->overflowed; } net_status_t NET_SVC_ChokeCount_Parse (net_svc_chokecount_t *block, msg_t *msg) { block->count = MSG_ReadByte (msg); return msg->badread; } net_status_t NET_SVC_Modellist_Emit (net_svc_modellist_t *block, sizebuf_t *buf) { int i = 0; MSG_WriteByte (buf, block->startmodel); do MSG_WriteString (buf, block->models[i]); while (*block->models[i++]); MSG_WriteByte (buf, block->nextmodel); return buf->overflowed; } net_status_t NET_SVC_Modellist_Parse (net_svc_modellist_t *block, msg_t *msg) { int i; block->startmodel = MSG_ReadByte (msg); for (i = 0;; i++) { block->models[i] = MSG_ReadString (msg); if (!*block->models[i]) break; if (i >= MAX_MODELS) return NET_ERROR; } block->nextmodel = MSG_ReadByte (msg); return msg->badread; } net_status_t NET_SVC_Soundlist_Emit (net_svc_soundlist_t *block, sizebuf_t *buf) { int i = 0; MSG_WriteByte (buf, block->startsound); do MSG_WriteString (buf, block->sounds[i]); while (*block->sounds[i++]); MSG_WriteByte (buf, block->nextsound); return buf->overflowed; } net_status_t NET_SVC_Soundlist_Parse (net_svc_soundlist_t *block, msg_t *msg) { int i; block->startsound = MSG_ReadByte (msg); for (i = 0;; i++) { block->sounds[i] = MSG_ReadString (msg); if (!*block->sounds[i]) break; if (i >= MAX_SOUNDS) return NET_ERROR; } block->nextsound = MSG_ReadByte (msg); return msg->badread; } // this is a sub-block, not a real block void NET_SVC_Delta_Emit (entity_state_t *es, unsigned int bits, sizebuf_t *buf) { // bytes of bits: [EXT2][EXT1][ORIG][MORE] bits = es->flags; if (bits & U_MOREBITS) MSG_WriteByte (buf, bits & 255); if (bits & U_EXTEND1) { MSG_WriteByte (buf, (bits >> 16) & 255); if (bits & U_EXTEND2) MSG_WriteByte (buf, (bits >> 24) & 255); } if (bits & U_MODEL) MSG_WriteByte (buf, es->modelindex); if (bits & U_FRAME) MSG_WriteByte (buf, es->frame); if (bits & U_COLORMAP) MSG_WriteByte (buf, es->colormap); if (bits & U_SKIN) MSG_WriteByte (buf, es->skinnum); if (bits & U_EFFECTS) MSG_WriteByte (buf, es->effects); if (bits & U_ORIGIN1) MSG_WriteCoord (buf, es->origin[0]); if (bits & U_ANGLE1) MSG_WriteAngle (buf, es->angles[0]); if (bits & U_ORIGIN2) MSG_WriteCoord (buf, es->origin[1]); if (bits & U_ANGLE2) MSG_WriteAngle (buf, es->angles[1]); if (bits & U_ORIGIN3) MSG_WriteCoord (buf, es->origin[2]); if (bits & U_ANGLE3) MSG_WriteAngle (buf, es->angles[2]); if (bits & U_ALPHA) MSG_WriteByte (buf, es->alpha); if (bits & U_SCALE) MSG_WriteByte (buf, es->scale); if (bits & U_EFFECTS2) MSG_WriteByte (buf, es->effects >> 8); if (bits & U_GLOWSIZE) MSG_WriteByte (buf, es->glow_size); if (bits & U_GLOWCOLOR) MSG_WriteByte (buf, es->glow_color); if (bits & U_COLORMOD) MSG_WriteByte (buf, es->colormod); if (bits & U_FRAME2) MSG_WriteByte (buf, es->frame >> 8); if (bits & U_SOLID) { // FIXME } } // this is a sub-block, not a real block static void NET_SVC_Delta_Parse (entity_state_t *es, unsigned int bits, msg_t *msg) { // bytes of bits: [EXT2][EXT1][ORIG][MORE] es->number = bits & 511; bits &= ~511; es->frame = 0; es->effects = 0; if (bits & U_MOREBITS) bits |= MSG_ReadByte (msg); if (bits & U_EXTEND1) { bits |= MSG_ReadByte (msg) << 16; if (bits & U_EXTEND2) bits |= MSG_ReadByte (msg) << 24; } es->flags = bits; if (bits & U_MODEL) es->modelindex = MSG_ReadByte (msg); if (bits & U_FRAME) es->frame = MSG_ReadByte (msg); if (bits & U_COLORMAP) es->colormap = MSG_ReadByte (msg); if (bits & U_SKIN) es->skinnum = MSG_ReadByte (msg); if (bits & U_EFFECTS) es->effects = MSG_ReadByte (msg); if (bits & U_ORIGIN1) es->origin[0] = MSG_ReadCoord (msg); if (bits & U_ANGLE1) es->angles[0] = MSG_ReadAngle (msg); if (bits & U_ORIGIN2) es->origin[1] = MSG_ReadCoord (msg); if (bits & U_ANGLE2) es->angles[1] = MSG_ReadAngle (msg); if (bits & U_ORIGIN3) es->origin[2] = MSG_ReadCoord (msg); if (bits & U_ANGLE3) es->angles[2] = MSG_ReadAngle (msg); if (bits & U_ALPHA) es->alpha = MSG_ReadByte (msg); if (bits & U_SCALE) es->scale = MSG_ReadByte (msg); if (bits & U_EFFECTS2) { if (bits & U_EFFECTS) es->effects = (es->effects & 0xFF) | (MSG_ReadByte (msg) << 8); else es->effects = MSG_ReadByte (msg) << 8; } if (bits & U_GLOWSIZE) es->glow_size = MSG_ReadByte (msg); if (bits & U_GLOWCOLOR) es->glow_color = MSG_ReadByte (msg); if (bits & U_COLORMOD) es->colormod = MSG_ReadByte (msg); if (bits & U_FRAME2) { if (bits & U_FRAME) es->frame = (es->frame & 0xFF) | (MSG_ReadByte (msg) << 8); else es->frame = MSG_ReadByte (msg) << 8; } if (bits & U_SOLID) { // FIXME } } net_status_t NET_SVC_PacketEntities_Emit (net_svc_packetentities_t *block, sizebuf_t *buf) { int word, delta; unsigned short bits; for (word = 0, delta = 0; !buf->overflowed; word++) { if (word > MAX_PACKET_ENTITIES * 2) return NET_ERROR; bits = block->words[word]; MSG_WriteShort (buf, bits); if (!bits) break; if (!(bits & U_REMOVE)) { if (delta >= MAX_PACKET_ENTITIES) return NET_ERROR; NET_SVC_Delta_Emit (&block->deltas[delta], bits, buf); delta++; } } return buf->overflowed; } net_status_t NET_SVC_PacketEntities_Parse (net_svc_packetentities_t *block, msg_t *msg) { int word, delta; unsigned short bits; for (word = 0, delta = 0; !msg->badread; word++) { if (word > MAX_PACKET_ENTITIES * 2) return NET_ERROR; bits = (unsigned short) MSG_ReadShort (msg); block->words[word] = bits; if (!bits) break; if (!(bits & U_REMOVE)) { if (delta >= MAX_PACKET_ENTITIES) return NET_ERROR; NET_SVC_Delta_Parse (&block->deltas[delta], bits, msg); delta++; } } block->numwords = word; block->numdeltas = delta; return msg->badread; } net_status_t NET_SVC_DeltaPacketEntities_Emit (net_svc_deltapacketentities_t *block, sizebuf_t *buf) { int word, delta; unsigned short bits; MSG_WriteByte (buf, block->from); for (word = 0, delta = 0; !buf->overflowed; word++) { if (word > MAX_PACKET_ENTITIES * 2) return NET_ERROR; bits = block->words[word]; MSG_WriteShort (buf, bits); if (!bits) break; if (!(bits & U_REMOVE)) { if (delta >= MAX_PACKET_ENTITIES) return NET_ERROR; NET_SVC_Delta_Emit (&block->deltas[delta], bits, buf); delta++; } } return buf->overflowed; } net_status_t NET_SVC_DeltaPacketEntities_Parse (net_svc_deltapacketentities_t *block, msg_t *msg) { int word, delta; unsigned short bits; block->from = MSG_ReadByte (msg); for (word = 0, delta = 0; !msg->badread; word++) { if (word > MAX_PACKET_ENTITIES * 2) return NET_ERROR; bits = (unsigned short) MSG_ReadShort (msg); block->words[word] = bits; if (!bits) break; if (!(bits & U_REMOVE)) { if (delta >= MAX_PACKET_ENTITIES) return NET_ERROR; NET_SVC_Delta_Parse (&block->deltas[delta], bits, msg); delta++; } } block->numwords = word; block->numdeltas = delta; return msg->badread; } net_status_t NET_SVC_MaxSpeed_Emit (net_svc_maxspeed_t *block, sizebuf_t *buf) { MSG_WriteFloat (buf, block->maxspeed); return buf->overflowed; } net_status_t NET_SVC_MaxSpeed_Parse (net_svc_maxspeed_t *block, msg_t *msg) { block->maxspeed = MSG_ReadFloat (msg); return msg->badread; } net_status_t NET_SVC_EntGravity_Emit (net_svc_entgravity_t *block, sizebuf_t *buf) { MSG_WriteFloat (buf, block->gravity); return buf->overflowed; } net_status_t NET_SVC_EntGravity_Parse (net_svc_entgravity_t *block, msg_t *msg) { block->gravity = MSG_ReadFloat (msg); return msg->badread; } net_status_t NET_SVC_SetInfo_Emit (net_svc_setinfo_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->slot); MSG_WriteString (buf, block->key); MSG_WriteString (buf, block->value); return buf->overflowed; } net_status_t NET_SVC_SetInfo_Parse (net_svc_setinfo_t *block, msg_t *msg) { block->slot = MSG_ReadByte (msg); block->key = MSG_ReadString (msg); block->value = MSG_ReadString (msg); return msg->badread; } net_status_t NET_SVC_QWServerInfo_Emit (net_svc_qwserverinfo_t *block, sizebuf_t *buf) { MSG_WriteString (buf, block->key); MSG_WriteString (buf, block->value); return buf->overflowed; } net_status_t NET_SVC_QWServerInfo_Parse (net_svc_qwserverinfo_t *block, msg_t *msg) { block->key = MSG_ReadString (msg); block->value = MSG_ReadString (msg); return msg->badread; } net_status_t NET_SVC_UpdatePL_Emit (net_svc_updatepl_t *block, sizebuf_t *buf) { MSG_WriteByte (buf, block->player); MSG_WriteByte (buf, block->packetloss); return buf->overflowed; } net_status_t NET_SVC_UpdatePL_Parse (net_svc_updatepl_t *block, msg_t *msg) { block->player = MSG_ReadByte (msg); block->packetloss = MSG_ReadByte (msg); return msg->badread; }