- 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, net_status_t NET_SVC_TempEntity_Emit (net_svc_tempentity_t *block,
sizebuf_t *buf); sizebuf_t *buf);
net_status_t NET_SVC_TempEntity_Parse (net_svc_tempentity_t *block, msg_t *msg); 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, net_status_t NET_SVC_SpawnStaticSound_Parse (net_svc_spawnstaticsound_t *block,
msg_t *msg); 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, net_status_t NET_SVC_UpdateUserInfo_Parse (net_svc_updateuserinfo_t *block,
msg_t *msg); 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_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_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_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_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); 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; 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_status_t
NET_SVC_SpawnStaticSound_Parse (net_svc_spawnstaticsound_t *block, NET_SVC_SpawnStaticSound_Parse (net_svc_spawnstaticsound_t *block,
msg_t *msg) msg_t *msg)
@ -384,8 +399,17 @@ NET_SVC_SpawnStaticSound_Parse (net_svc_spawnstaticsound_t *block,
} }
net_status_t net_status_t
NET_SVC_UpdateUserInfo_Parse (net_svc_updateuserinfo_t *block, NET_SVC_UpdateUserInfo_Emit (net_svc_updateuserinfo_t *block, sizebuf_t *buf)
msg_t *msg) {
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->slot = MSG_ReadByte (msg);
block->userid = MSG_ReadLong (msg); block->userid = MSG_ReadLong (msg);
@ -394,6 +418,16 @@ NET_SVC_UpdateUserInfo_Parse (net_svc_updateuserinfo_t *block,
return msg->badread; 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_status_t
NET_SVC_SetInfo_Parse (net_svc_setinfo_t *block, msg_t *msg) 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; 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_status_t
NET_SVC_ServerInfo_Parse (net_svc_serverinfo_t *block, msg_t *msg) 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; 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_status_t
NET_SVC_Download_Parse (net_svc_download_t *block, msg_t *msg) 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 "bothdefs.h"
#include "compat.h" #include "compat.h"
#include "net_svc.h"
#include "server.h" #include "server.h"
#include "sv_progs.h" #include "sv_progs.h"
@ -828,12 +829,15 @@ SV_Heartbeat_f (void)
void void
SV_SendServerInfoChange (const char *key, const char *value) SV_SendServerInfoChange (const char *key, const char *value)
{ {
net_svc_serverinfo_t block;
if (!sv.state) if (!sv.state)
return; return;
block.key = key;
block.value = value;
MSG_WriteByte (&sv.reliable_datagram, svc_serverinfo); MSG_WriteByte (&sv.reliable_datagram, svc_serverinfo);
MSG_WriteString (&sv.reliable_datagram, key); NET_SVC_ServerInfo_Emit (&block, &sv.reliable_datagram);
MSG_WriteString (&sv.reliable_datagram, value);
} }
/* /*

View file

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

View file

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

View file

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