From d7e5f88ee35647fe839c32b9609bbbe075dde54d Mon Sep 17 00:00:00 2001 From: Adam Olsen Date: Fri, 2 Nov 2001 14:52:29 +0000 Subject: [PATCH] - 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. --- qw/include/net_svc.h | 8 +++++ qw/source/net_svc.c | 61 ++++++++++++++++++++++++++++++++-- qw/source/sv_ccmds.c | 8 +++-- qw/source/sv_main.c | 8 +++-- qw/source/sv_pr_cmds.c | 32 +++++++----------- qw/source/sv_user.c | 74 ++++++++++++++++++++++++++---------------- 6 files changed, 136 insertions(+), 55 deletions(-) diff --git a/qw/include/net_svc.h b/qw/include/net_svc.h index 1046179d6..853f15fe5 100644 --- a/qw/include/net_svc.h +++ b/qw/include/net_svc.h @@ -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); diff --git a/qw/source/net_svc.c b/qw/source/net_svc.c index 9469e9aba..5aa4617b8 100644 --- a/qw/source/net_svc.c +++ b/qw/source/net_svc.c @@ -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) { diff --git a/qw/source/sv_ccmds.c b/qw/source/sv_ccmds.c index 807ee0a9c..8f6676c87 100644 --- a/qw/source/sv_ccmds.c +++ b/qw/source/sv_ccmds.c @@ -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); } /* diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index b3c58b8d7..9dc59260e 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -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); } /* diff --git a/qw/source/sv_pr_cmds.c b/qw/source/sv_pr_cmds.c index 883d96b77..6d73e5383 100644 --- a/qw/source/sv_pr_cmds.c +++ b/qw/source/sv_pr_cmds.c @@ -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); } } } diff --git a/qw/source/sv_user.c b/qw/source/sv_user.c index 4fc969c96..e95d0e9c7 100644 --- a/qw/source/sv_user.c +++ b/qw/source/sv_user.c @@ -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); } }