- conver svc_spawnstaticsound, svc_updateuserinfo, svc_setinfo,

svc_serverinfo, and svc_download

I havn't tested svc_download, since I don't want to play with having
seperate dirs for the client vs server on one computer.
This commit is contained in:
Adam Olsen 2001-11-02 14:52:29 +00:00
parent 9f088567d1
commit d7e5f88ee3
6 changed files with 136 additions and 55 deletions

View file

@ -219,12 +219,20 @@ net_status_t NET_SVC_SpawnStatic_Parse (net_svc_spawnstatic_t *block,
net_status_t NET_SVC_TempEntity_Emit (net_svc_tempentity_t *block,
sizebuf_t *buf);
net_status_t NET_SVC_TempEntity_Parse (net_svc_tempentity_t *block, msg_t *msg);
net_status_t NET_SVC_SpawnStaticSound_Emit (net_svc_spawnstaticsound_t *block,
sizebuf_t *buf);
net_status_t NET_SVC_SpawnStaticSound_Parse (net_svc_spawnstaticsound_t *block,
msg_t *msg);
net_status_t NET_SVC_UpdateUserInfo_Emit (net_svc_updateuserinfo_t *block,
sizebuf_t *buf);
net_status_t NET_SVC_UpdateUserInfo_Parse (net_svc_updateuserinfo_t *block,
msg_t *msg);
net_status_t NET_SVC_SetInfo_Emit (net_svc_setinfo_t *block, sizebuf_t *buf);
net_status_t NET_SVC_SetInfo_Parse (net_svc_setinfo_t *block, msg_t *msg);
net_status_t NET_SVC_ServerInfo_Emit (net_svc_serverinfo_t *block,
sizebuf_t *buf);
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_Parse (net_svc_playerinfo_t *block, msg_t *msg);
net_status_t NET_SVC_Nails_Parse (net_svc_nails_t *block, msg_t *msg);

View file

@ -368,6 +368,21 @@ NET_SVC_TempEntity_Parse (net_svc_tempentity_t *block, msg_t *msg)
return msg->badread;
}
net_status_t
NET_SVC_SpawnStaticSound_Emit (net_svc_spawnstaticsound_t *block,
sizebuf_t *buf)
{
int i;
for (i = 0; i < 3; i++)
MSG_WriteCoord (buf, block->position[i]);
MSG_WriteByte (buf, block->sound_num);
MSG_WriteByte (buf, block->volume);
MSG_WriteByte (buf, block->attenuation);
return buf->overflowed;
}
net_status_t
NET_SVC_SpawnStaticSound_Parse (net_svc_spawnstaticsound_t *block,
msg_t *msg)
@ -384,8 +399,17 @@ NET_SVC_SpawnStaticSound_Parse (net_svc_spawnstaticsound_t *block,
}
net_status_t
NET_SVC_UpdateUserInfo_Parse (net_svc_updateuserinfo_t *block,
msg_t *msg)
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);
@ -394,6 +418,16 @@ NET_SVC_UpdateUserInfo_Parse (net_svc_updateuserinfo_t *block,
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)
{
@ -404,6 +438,15 @@ NET_SVC_SetInfo_Parse (net_svc_setinfo_t *block, msg_t *msg)
return msg->badread;
}
net_status_t
NET_SVC_ServerInfo_Emit (net_svc_serverinfo_t *block, sizebuf_t *buf)
{
MSG_WriteString (buf, block->key);
MSG_WriteString (buf, block->value);
return buf->overflowed;
}
net_status_t
NET_SVC_ServerInfo_Parse (net_svc_serverinfo_t *block, msg_t *msg)
{
@ -413,6 +456,20 @@ NET_SVC_ServerInfo_Parse (net_svc_serverinfo_t *block, msg_t *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)
SZ_Write (buf, block->data, block->size); // FIXME: should be a MSG_* function
return buf->overflowed;
}
net_status_t
NET_SVC_Download_Parse (net_svc_download_t *block, msg_t *msg)
{

View file

@ -51,6 +51,7 @@ static const char rcsid[] =
#include "bothdefs.h"
#include "compat.h"
#include "net_svc.h"
#include "server.h"
#include "sv_progs.h"
@ -828,12 +829,15 @@ SV_Heartbeat_f (void)
void
SV_SendServerInfoChange (const char *key, const char *value)
{
net_svc_serverinfo_t block;
if (!sv.state)
return;
block.key = key;
block.value = value;
MSG_WriteByte (&sv.reliable_datagram, svc_serverinfo);
MSG_WriteString (&sv.reliable_datagram, key);
MSG_WriteString (&sv.reliable_datagram, value);
NET_SVC_ServerInfo_Emit (&block, &sv.reliable_datagram);
}
/*

View file

@ -365,6 +365,7 @@ SV_FullClientUpdate (client_t *client, sizebuf_t *buf)
{
char info[MAX_INFO_STRING];
int i;
net_svc_updateuserinfo_t block;
i = client - svs.clients;
@ -389,10 +390,11 @@ SV_FullClientUpdate (client_t *client, sizebuf_t *buf)
strncpy (info, client->userinfo, sizeof (info));
Info_RemovePrefixedKeys (info, '_', client_info_filters); // server passwords, etc
block.slot = i;
block.userid = client->userid;
block.userinfo = info;
MSG_WriteByte (buf, svc_updateuserinfo);
MSG_WriteByte (buf, i);
MSG_WriteLong (buf, client->userid);
MSG_WriteString (buf, info);
NET_SVC_UpdateUserInfo_Emit (&block, buf);
}
/*

View file

@ -280,17 +280,16 @@ PF_ambientsound (progs_t *pr)
{
const char **check;
const char *samp;
float *pos;
float vol, attenuation;
int i, soundnum;
net_svc_spawnstaticsound_t block;
pos = G_VECTOR (pr, OFS_PARM0);
VectorCopy (G_VECTOR (pr, OFS_PARM0), block.position);
samp = G_STRING (pr, OFS_PARM1);
vol = G_FLOAT (pr, OFS_PARM2);
attenuation = G_FLOAT (pr, OFS_PARM3);
block.volume = G_FLOAT (pr, OFS_PARM2) * 255;
block.attenuation = G_FLOAT (pr, OFS_PARM3) * 64;
// check to see if samp was properly precached
for (soundnum = 0, check = sv.sound_precache; *check; check++, soundnum++)
for (block.sound_num = 0, check = sv.sound_precache; *check;
check++, block.sound_num++)
if (!strcmp (*check, samp))
break;
@ -301,14 +300,7 @@ PF_ambientsound (progs_t *pr)
// add an svc_spawnambient command to the level signon packet
MSG_WriteByte (&sv.signon, svc_spawnstaticsound);
for (i = 0; i < 3; i++)
MSG_WriteCoord (&sv.signon, pos[i]);
MSG_WriteByte (&sv.signon, soundnum);
MSG_WriteByte (&sv.signon, vol * 255);
MSG_WriteByte (&sv.signon, attenuation * 64);
NET_SVC_SpawnStaticSound_Emit (&block, &sv.signon);
}
/*
@ -1366,6 +1358,7 @@ PF_setinfokey (progs_t *pr)
int e1 = NUM_FOR_EDICT (pr, edict);
const char *key = G_STRING (pr, OFS_PARM1);
const char *value = G_STRING (pr, OFS_PARM2);
net_svc_setinfo_t block;
if (e1 == 0) {
Info_SetValueForKey (localinfo, key, value, MAX_LOCALINFO_STRING,
@ -1376,12 +1369,11 @@ PF_setinfokey (progs_t *pr)
SV_ExtractFromUserinfo (&svs.clients[e1 - 1]);
if (Info_FilterForKey (key, client_info_filters)) {
block.slot = e1 - 1;
block.key = key;
block.value = Info_ValueForKey (svs.clients[e1 - 1].userinfo, key);
MSG_WriteByte (&sv.reliable_datagram, svc_setinfo);
MSG_WriteByte (&sv.reliable_datagram, e1 - 1);
MSG_WriteString (&sv.reliable_datagram, key);
MSG_WriteString (&sv.reliable_datagram,
Info_ValueForKey (svs.clients[e1 - 1].userinfo,
key));
NET_SVC_SetInfo_Emit (&block, &sv.reliable_datagram);
}
}
}

View file

@ -548,27 +548,27 @@ void
SV_NextDownload_f (void)
{
byte buffer[1024];
int r;
int percent;
int size;
net_svc_download_t block;
if (!host_client->download)
return;
r = host_client->downloadsize - host_client->downloadcount;
if (r > 768)
r = 768;
r = Qread (host_client->download, buffer, r);
ClientReliableWrite_Begin (host_client, svc_download, 6 + r);
ClientReliableWrite_Short (host_client, r);
block.size = host_client->downloadsize - host_client->downloadcount;
if (block.size > 768)
block.size = 768;
block.size = Qread (host_client->download, buffer, block.size);
host_client->downloadcount += r;
size = host_client->downloadsize;
if (!size)
size = 1;
percent = host_client->downloadcount * 100 / size;
ClientReliableWrite_Byte (host_client, percent);
ClientReliableWrite_SZ (host_client, buffer, r);
host_client->downloadcount += block.size;
block.percent = host_client->downloadcount * 100 /
(host_client->downloadsize ?: 1);
block.data = buffer;
ClientReliableWrite_Begin (host_client, svc_download, 6 + block.size);
if (host_client->num_backbuf) {
NET_SVC_Download_Emit (&block, &host_client->backbuf);
ClientReliable_FinishWrite (host_client);
} else
NET_SVC_Download_Emit (&block, &host_client->netchan.message);
if (host_client->downloadcount != host_client->downloadsize)
return;
@ -677,6 +677,7 @@ SV_BeginDownload_f (void)
int size;
char realname[MAX_OSPATH];
int zip;
net_svc_download_t block;
name = Cmd_Argv (1);
// hacked by zoid to allow more conrol over download
@ -694,9 +695,14 @@ SV_BeginDownload_f (void)
|| (strncmp (name, "maps/", 5) == 0 && !allow_download_maps->int_val)
// MUST be in a subdirectory
|| !strstr (name, "/")) { // don't allow anything with .. path
block.size = -1;
block.percent = 0;
ClientReliableWrite_Begin (host_client, svc_download, 4);
ClientReliableWrite_Short (host_client, -1);
ClientReliableWrite_Byte (host_client, 0);
if (host_client->num_backbuf) {
NET_SVC_Download_Emit (&block, &host_client->backbuf);
ClientReliable_FinishWrite (host_client);
} else
NET_SVC_Download_Emit (&block, &host_client->netchan.message);
return;
}
@ -732,19 +738,30 @@ SV_BeginDownload_f (void)
}
SV_Printf ("Couldn't download %s to %s\n", name, host_client->name);
block.size = -1;
block.percent = 0;
ClientReliableWrite_Begin (host_client, svc_download, 4);
ClientReliableWrite_Short (host_client, -1);
ClientReliableWrite_Byte (host_client, 0);
if (host_client->num_backbuf) {
NET_SVC_Download_Emit (&block, &host_client->backbuf);
ClientReliable_FinishWrite (host_client);
} else
NET_SVC_Download_Emit (&block, &host_client->netchan.message);
return;
}
if (zip && strcmp (realname, name)) {
SV_Printf ("download renamed to %s\n", realname);
block.size = -2;
block.percent = 0;
block.name = realname;
ClientReliableWrite_Begin (host_client, svc_download,
strlen (realname) + 5);
ClientReliableWrite_Short (host_client, -2);
ClientReliableWrite_Byte (host_client, 0);
ClientReliableWrite_String (host_client, realname);
if (host_client->num_backbuf)
NET_SVC_Download_Emit (&block, &host_client->backbuf);
else
NET_SVC_Download_Emit (&block, &host_client->netchan.message);
ClientReliable_FinishWrite (host_client);
}
@ -1101,6 +1118,8 @@ SV_Msg_f (void)
void
SV_SetInfo_f (void)
{
net_svc_setinfo_t block;
if (Cmd_Argc () == 1) {
SV_Printf ("User info settings:\n");
Info_Print (host_client->userinfo);
@ -1139,12 +1158,11 @@ SV_SetInfo_f (void)
SV_ExtractFromUserinfo (host_client);
if (Info_FilterForKey (Cmd_Argv (1), client_info_filters)) {
block.slot = host_client - svs.clients;
block.key = Cmd_Argv (1);
block.value = Info_ValueForKey (host_client->userinfo, Cmd_Argv (1));
MSG_WriteByte (&sv.reliable_datagram, svc_setinfo);
MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
MSG_WriteString (&sv.reliable_datagram, Cmd_Argv (1));
MSG_WriteString (&sv.reliable_datagram,
Info_ValueForKey (host_client->userinfo,
Cmd_Argv (1)));
NET_SVC_SetInfo_Emit (&block, &sv.reliable_datagram);
}
}