- convert svc_playerinfo, cvs_nails, svc_modellist, and svc_soundlist

This commit is contained in:
Adam Olsen 2001-11-03 10:48:55 +00:00
parent 961ea0b693
commit c5f4af0109
4 changed files with 195 additions and 114 deletions

View file

@ -234,9 +234,16 @@ net_status_t NET_SVC_ServerInfo_Emit (net_svc_serverinfo_t *block,
net_status_t NET_SVC_ServerInfo_Parse (net_svc_serverinfo_t *block, msg_t *msg);
net_status_t NET_SVC_Download_Emit (net_svc_download_t *block, sizebuf_t *buf);
net_status_t NET_SVC_Download_Parse (net_svc_download_t *block, msg_t *msg);
net_status_t NET_SVC_Playerinfo_Emit (net_svc_playerinfo_t *block,
sizebuf_t *buf);
net_status_t NET_SVC_Playerinfo_Parse (net_svc_playerinfo_t *block, msg_t *msg);
net_status_t NET_SVC_Nails_Emit (net_svc_nails_t *block, sizebuf_t *buf);
net_status_t NET_SVC_Nails_Parse (net_svc_nails_t *block, msg_t *msg);
net_status_t NET_SVC_Modellist_Emit (net_svc_modellist_t *block,
sizebuf_t *buf);
net_status_t NET_SVC_Modellist_Parse (net_svc_modellist_t *block, msg_t *msg);
net_status_t NET_SVC_Soundlist_Emit (net_svc_soundlist_t *block,
sizebuf_t *buf);
net_status_t NET_SVC_Soundlist_Parse (net_svc_soundlist_t *block, msg_t *msg);
net_status_t NET_SVC_PacketEntities_Parse (net_svc_packetentities_t *block,
msg_t *msg);

View file

@ -495,6 +495,37 @@ NET_SVC_Download_Parse (net_svc_download_t *block, msg_t *msg)
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)
MSG_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)
{
@ -545,6 +576,39 @@ NET_SVC_Playerinfo_Parse (net_svc_playerinfo_t *block, msg_t *msg)
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)
{
@ -573,6 +637,20 @@ NET_SVC_Nails_Parse (net_svc_nails_t *block, msg_t *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)
{
@ -587,14 +665,26 @@ NET_SVC_Modellist_Parse (net_svc_modellist_t *block, msg_t *msg)
if (i >= MAX_MODELS)
return NET_ERROR;
}
// this is a bit redundant, but I think the robustness is a good thing
block->models[MAX_MODELS] = "";
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)
{
@ -609,8 +699,6 @@ NET_SVC_Soundlist_Parse (net_svc_soundlist_t *block, msg_t *msg)
if (i >= MAX_SOUNDS)
return NET_ERROR;
}
// this is a bit redundant, but I think the robustness is a good thing
block->sounds[MAX_SOUNDS] = "";
block->nextsound = MSG_ReadByte (msg);

View file

@ -42,6 +42,7 @@ static const char rcsid[] =
#include "compat.h"
#include "msg_ucmd.h"
#include "net_svc.h"
#include "server.h"
#include "sv_progs.h"
@ -125,34 +126,21 @@ SV_AddNailUpdate (edict_t *ent)
void
SV_EmitNailUpdate (sizebuf_t *msg)
{
byte bits[6]; // [48 bits] xyzpy 12 12 12 4 8
int i, n, p, x, y, z, yaw;
edict_t *ent;
int i;
net_svc_nails_t block;
if (!numnails)
return;
MSG_WriteByte (msg, svc_nails);
MSG_WriteByte (msg, numnails);
block.numnails = numnails;
for (n = 0; n < numnails; n++) {
ent = nails[n];
x = (int) (SVvector (ent, origin)[0] + 4096) >> 1;
y = (int) (SVvector (ent, origin)[1] + 4096) >> 1;
z = (int) (SVvector (ent, origin)[2] + 4096) >> 1;
p = (int) (16 * SVvector (ent, angles)[0] / 360) & 15;
yaw = (int) (256 * SVvector (ent, 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 (i = 0; i < 6; i++)
MSG_WriteByte (msg, bits[i]);
for (i = 0; i < numnails; i++) {
VectorCopy (SVvector (nails[i], origin), block.nails[i].origin);
VectorCopy (SVvector (nails[i], angles), block.nails[i].angles);
}
MSG_WriteByte (msg, svc_nails);
NET_SVC_Nails_Emit (&block, msg);
}
/*
@ -372,10 +360,10 @@ void
SV_WritePlayersToClient (client_t *client, edict_t *clent, byte * pvs,
sizebuf_t *msg)
{
int i, j, msec, pflags;
int i, j;
client_t *cl;
edict_t *ent;
usercmd_t cmd;
net_svc_playerinfo_t block;
for (j = 0, cl = svs.clients; j < MAX_CLIENTS; j++, cl++) {
if (cl->state != cs_spawned)
@ -397,82 +385,63 @@ SV_WritePlayersToClient (client_t *client, edict_t *clent, byte * pvs,
continue; // not visible
}
pflags = PF_MSEC | PF_COMMAND;
block.flags = PF_MSEC | PF_COMMAND;
if (SVfloat (ent, modelindex) != sv_playermodel)
pflags |= PF_MODEL;
block.flags |= PF_MODEL;
for (i = 0; i < 3; i++)
if (SVvector (ent, velocity)[i])
pflags |= PF_VELOCITY1 << i;
block.flags |= PF_VELOCITY1 << i;
if (SVfloat (ent, effects))
pflags |= PF_EFFECTS;
block.flags |= PF_EFFECTS;
if (SVfloat (ent, skin))
pflags |= PF_SKINNUM;
block.flags |= PF_SKINNUM;
if (SVfloat (ent, health) <= 0)
pflags |= PF_DEAD;
block.flags |= PF_DEAD;
if (SVvector (ent, mins)[2] != -24)
pflags |= PF_GIB;
block.flags |= PF_GIB;
if (cl->spectator) { // only sent origin and velocity to
// spectators
pflags &= PF_VELOCITY1 | PF_VELOCITY2 | PF_VELOCITY3;
block.flags &= PF_VELOCITY1 | PF_VELOCITY2 | PF_VELOCITY3;
} else if (ent == clent) { // don't send a lot of data on
// personal entity
pflags &= ~(PF_MSEC | PF_COMMAND);
block.flags &= ~(PF_MSEC | PF_COMMAND);
if (SVfloat (ent, weaponframe))
pflags |= PF_WEAPONFRAME;
block.flags |= PF_WEAPONFRAME;
}
if (client->spec_track && client->spec_track - 1 == j &&
SVfloat (ent, weaponframe)) pflags |= PF_WEAPONFRAME;
SVfloat (ent, weaponframe))
block.flags |= PF_WEAPONFRAME;
block.playernum = j;
VectorCopy (SVvector (ent, origin), block.origin);
block.frame = SVfloat (ent, frame);
block.msec = 1000 * (sv.time - cl->localtime);
if (block.msec > 255)
block.msec = 255;
block.usercmd = cl->lastcmd;
if (SVfloat (ent, health) <= 0) { // don't show the corpse
// looking around...
block.usercmd.angles[0] = 0;
block.usercmd.angles[1] = SVvector (ent, angles)[1];
block.usercmd.angles[0] = 0;
}
block.usercmd.buttons = 0; // never send buttons
block.usercmd.impulse = 0; // never send impulses
VectorCopy (SVvector (ent, velocity), block.velocity);
block.modelindex = SVfloat (ent, modelindex);
block.skinnum = SVfloat (ent, skin);
block.effects = SVfloat (ent, effects);
block.weaponframe = SVfloat (ent, weaponframe);
MSG_WriteByte (msg, svc_playerinfo);
MSG_WriteByte (msg, j);
MSG_WriteShort (msg, pflags);
for (i = 0; i < 3; i++)
MSG_WriteCoord (msg, SVvector (ent, origin)[i]);
MSG_WriteByte (msg, SVfloat (ent, frame));
if (pflags & PF_MSEC) {
msec = 1000 * (sv.time - cl->localtime);
if (msec > 255)
msec = 255;
MSG_WriteByte (msg, msec);
}
if (pflags & PF_COMMAND) {
cmd = cl->lastcmd;
if (SVfloat (ent, health) <= 0) { // don't show the corpse
// looking around...
cmd.angles[0] = 0;
cmd.angles[1] = SVvector (ent, angles)[1];
cmd.angles[0] = 0;
}
cmd.buttons = 0; // never send buttons
cmd.impulse = 0; // never send impulses
MSG_WriteDeltaUsercmd (msg, &nullcmd, &cmd);
}
for (i = 0; i < 3; i++)
if (pflags & (PF_VELOCITY1 << i))
MSG_WriteShort (msg, SVvector (ent, velocity)[i]);
if (pflags & PF_MODEL)
MSG_WriteByte (msg, SVfloat (ent, modelindex));
if (pflags & PF_SKINNUM)
MSG_WriteByte (msg, SVfloat (ent, skin));
if (pflags & PF_EFFECTS)
MSG_WriteByte (msg, SVfloat (ent, effects));
if (pflags & PF_WEAPONFRAME)
MSG_WriteByte (msg, SVfloat (ent, weaponframe));
NET_SVC_Playerinfo_Emit (&block, msg);
}
}

View file

@ -151,12 +151,14 @@ void
SV_Soundlist_f (void)
{
const char **s;
unsigned n;
int i, size;
net_svc_soundlist_t block;
if (host_client->state != cs_connected) {
SV_Printf ("soundlist not valid -- already spawned\n");
return;
}
// handle the case of a level changing while a client was connecting
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
SV_Printf ("SV_Soundlist_f from different level\n");
@ -164,34 +166,40 @@ SV_Soundlist_f (void)
return;
}
n = atoi (Cmd_Argv (2));
if (n >= MAX_SOUNDS) {
block.startsound = atoi (Cmd_Argv (2));
if (block.startsound >= MAX_SOUNDS) {
SV_Printf ("SV_Soundlist_f: Invalid soundlist index\n");
SV_New_f ();
return;
}
//NOTE: This doesn't go through ClientReliableWrite since it's before the user
//spawns. These functions are written to not overflow
// NOTE: This doesn't go through ClientReliableWrite since it's
// before the user spawns. These functions are written to not
// overflow
if (host_client->num_backbuf) {
SV_Printf ("WARNING %s: [SV_Soundlist] Back buffered (%d0, clearing",
SV_Printf ("WARNING %s: [SV_Soundlist] Back buffered (%d), clearing",
host_client->name, host_client->netchan.message.cursize);
host_client->num_backbuf = 0;
SZ_Clear (&host_client->netchan.message);
}
MSG_WriteByte (&host_client->netchan.message, svc_soundlist);
MSG_WriteByte (&host_client->netchan.message, n);
for (s = sv.sound_precache + 1 + n;
*s && host_client->netchan.message.cursize < (MAX_MSGLEN / 2);
s++, n++) MSG_WriteString (&host_client->netchan.message, *s);
MSG_WriteByte (&host_client->netchan.message, 0);
for (s = sv.sound_precache + 1 + block.startsound, i = 0, size = 0;
*s; i++, s++) {
if (host_client->netchan.message.cursize + size >= (MAX_MSGLEN / 2))
break;
size += strlen (*s) + 1;
block.sounds[i] = *s;
}
block.sounds[i] = "";
// next msg
if (*s)
MSG_WriteByte (&host_client->netchan.message, n);
block.nextsound = block.startsound + i;
else
MSG_WriteByte (&host_client->netchan.message, 0);
block.nextsound = 0;
MSG_WriteByte (&host_client->netchan.message, svc_soundlist);
NET_SVC_Soundlist_Emit (&block, &host_client->netchan.message);
}
/*
@ -201,12 +209,14 @@ void
SV_Modellist_f (void)
{
const char **s;
unsigned n;
int i, size;
net_svc_modellist_t block;
if (host_client->state != cs_connected) {
SV_Printf ("modellist not valid -- already spawned\n");
return;
}
// handle the case of a level changing while a client was connecting
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
SV_Printf ("SV_Modellist_f from different level\n");
@ -214,33 +224,40 @@ SV_Modellist_f (void)
return;
}
n = atoi (Cmd_Argv (2));
if (n >= MAX_MODELS) {
block.startmodel = atoi (Cmd_Argv (2));
if (block.startmodel >= MAX_MODELS) {
SV_Printf ("SV_Modellist_f: Invalid modellist index\n");
SV_New_f ();
return;
}
//NOTE: This doesn't go through ClientReliableWrite since it's before the user
//spawns. These functions are written to not overflow
// NOTE: This doesn't go through ClientReliableWrite since it's
// before the user spawns. These functions are written to not
// overflow
if (host_client->num_backbuf) {
SV_Printf ("WARNING %s: [SV_Modellist] Back buffered (%d0, clearing",
SV_Printf ("WARNING %s: [SV_Modellist] Back buffered (%d), clearing",
host_client->name, host_client->netchan.message.cursize);
host_client->num_backbuf = 0;
SZ_Clear (&host_client->netchan.message);
}
MSG_WriteByte (&host_client->netchan.message, svc_modellist);
MSG_WriteByte (&host_client->netchan.message, n);
for (s = sv.model_precache + 1 + n;
*s && host_client->netchan.message.cursize < (MAX_MSGLEN / 2);
s++, n++) MSG_WriteString (&host_client->netchan.message, *s);
MSG_WriteByte (&host_client->netchan.message, 0);
for (s = sv.model_precache + 1 + block.startmodel, i = 0, size = 0;
*s; i++, s++) {
if (host_client->netchan.message.cursize + size >= (MAX_MSGLEN / 2))
break;
size += strlen (*s) + 1;
block.models[i] = *s;
}
block.models[i] = "";
// next msg
if (*s)
MSG_WriteByte (&host_client->netchan.message, n);
block.nextmodel = block.startmodel + i;
else
MSG_WriteByte (&host_client->netchan.message, 0);
block.nextmodel = 0;
MSG_WriteByte (&host_client->netchan.message, svc_modellist);
NET_SVC_Modellist_Emit (&block, &host_client->netchan.message);
}
/*