mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 09:51:41 +00:00
- move the svc_print handling into a seperate function (CL_ParsePrint)
- add NET_SVC_{Print,Download}_Parse functions and assosiated net_svc_{print,download}_t structs. - make CL_Parse{Print,Download} use the above stuff
This commit is contained in:
parent
6c0d760102
commit
7d26e6e2b9
3 changed files with 96 additions and 43 deletions
|
@ -34,6 +34,20 @@
|
|||
|
||||
#include "bothdefs.h"
|
||||
|
||||
typedef struct net_svc_print_s
|
||||
{
|
||||
byte level;
|
||||
const char *message;
|
||||
} net_svc_print_t;
|
||||
|
||||
typedef struct net_svc_download_s
|
||||
{
|
||||
short size;
|
||||
byte percent;
|
||||
const char *name; // only one of name or data will be set
|
||||
const byte *data;
|
||||
} net_svc_download_t;
|
||||
|
||||
typedef struct net_svc_soundlist_s
|
||||
{
|
||||
byte startsound;
|
||||
|
@ -48,6 +62,8 @@ typedef struct net_svc_modellist_s
|
|||
byte nextmodel;
|
||||
} net_svc_modellist_t;
|
||||
|
||||
void NET_SVC_Print_Parse (net_svc_print_t *print, msg_t *message);
|
||||
void NET_SVC_Download_Parse (net_svc_download_t *download, msg_t *message);
|
||||
void NET_SVC_Soundlist_Parse (net_svc_soundlist_t *soundlist, msg_t *message);
|
||||
void NET_SVC_Modellist_Parse (net_svc_modellist_t *modellist, msg_t *message);
|
||||
|
||||
|
|
|
@ -404,19 +404,16 @@ void
|
|||
CL_ParseDownload (void)
|
||||
{
|
||||
byte name[1024];
|
||||
int size, percent, r;
|
||||
int r;
|
||||
net_svc_download_t download;
|
||||
|
||||
// read the data
|
||||
size = MSG_ReadShort (net_message);
|
||||
percent = MSG_ReadByte (net_message);
|
||||
NET_SVC_Download_Parse (&download, net_message);
|
||||
|
||||
if (cls.demoplayback) {
|
||||
if (size > 0)
|
||||
net_message->readcount += size;
|
||||
return; // not in demo playback
|
||||
}
|
||||
|
||||
if (size == -1) {
|
||||
if (download.size == -1) {
|
||||
Con_Printf ("File not found.\n");
|
||||
if (cls.download) {
|
||||
Con_Printf ("cls.download shouldn't have been set\n");
|
||||
|
@ -427,8 +424,8 @@ CL_ParseDownload (void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (size == -2) {
|
||||
const char *newname = MSG_ReadString (net_message);
|
||||
if (download.size == -2) {
|
||||
const char *newname = download.name;
|
||||
|
||||
if (strncmp (newname, cls.downloadname, strlen (cls.downloadname))
|
||||
|| strstr (newname + strlen (cls.downloadname), "/")) {
|
||||
|
@ -446,6 +443,11 @@ CL_ParseDownload (void)
|
|||
Con_Printf ("downloading to %s\n", cls.downloadname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (download.size <= 0) {
|
||||
Host_EndGame ("Bad download block, size %d", download.size);
|
||||
}
|
||||
|
||||
// open the file if not opened yet
|
||||
if (!cls.download) {
|
||||
if (strncmp (cls.downloadtempname, "skins/", 6))
|
||||
|
@ -459,31 +461,28 @@ CL_ParseDownload (void)
|
|||
|
||||
cls.download = Qopen (name, "wb");
|
||||
if (!cls.download) {
|
||||
net_message->readcount += size;
|
||||
Con_Printf ("Failed to open %s\n", cls.downloadtempname);
|
||||
CL_RequestNextDownload ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Qwrite (cls.download, net_message->message->data + net_message->readcount,
|
||||
size);
|
||||
net_message->readcount += size;
|
||||
Qwrite (cls.download, download.data, download.size);
|
||||
|
||||
if (percent != 100) {
|
||||
if (download.percent != 100) {
|
||||
// change display routines by zoid
|
||||
// request next block
|
||||
#if 0
|
||||
Con_Printf (".");
|
||||
if (10 * (percent / 10) != cls.downloadpercent) {
|
||||
cls.downloadpercent = 10 * (percent / 10);
|
||||
if (10 * (download.percent / 10) != cls.downloadpercent) {
|
||||
cls.downloadpercent = 10 * (download.percent / 10);
|
||||
Con_Printf ("%i%%", cls.downloadpercent);
|
||||
}
|
||||
#endif
|
||||
if (percent != cls.downloadpercent)
|
||||
if (download.percent != cls.downloadpercent)
|
||||
VID_SetCaption (va ("Downloading %s %d%%", cls.downloadname,
|
||||
percent));
|
||||
cls.downloadpercent = percent;
|
||||
download.percent));
|
||||
cls.downloadpercent = download.percent;
|
||||
|
||||
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
|
||||
SZ_Print (&cls.netchan.message, "nextdl");
|
||||
|
@ -600,6 +599,36 @@ CL_StopUpload (void)
|
|||
upload_data = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
CL_ParsePrint (void)
|
||||
{
|
||||
const char *string;
|
||||
char tmpstring[2048];
|
||||
net_svc_print_t print;
|
||||
|
||||
NET_SVC_Print_Parse (&print, net_message);
|
||||
string = print.message;
|
||||
|
||||
if (print.level == PRINT_CHAT) {
|
||||
// TODO: cl_nofake 2 -- accept fake messages from
|
||||
// teammates
|
||||
|
||||
if (cl_nofake->int_val) {
|
||||
char *c;
|
||||
strncpy (tmpstring, string, sizeof (tmpstring));
|
||||
tmpstring[sizeof (tmpstring) - 1] = 0;
|
||||
for (c = tmpstring; *c; c++)
|
||||
if (*c == '\r')
|
||||
*c = '#';
|
||||
string = tmpstring;
|
||||
}
|
||||
con_ormask = 128;
|
||||
S_LocalSound ("misc/talk.wav");
|
||||
}
|
||||
Con_Printf ("%s", string);
|
||||
con_ormask = 0;
|
||||
}
|
||||
|
||||
/* SERVER CONNECTING MESSAGES */
|
||||
|
||||
void Draw_ClearCache (void);
|
||||
|
@ -1151,31 +1180,10 @@ CL_ParseServerMessage (void)
|
|||
Host_EndGame ("Server disconnected");
|
||||
break;
|
||||
|
||||
case svc_print: {
|
||||
char p[2048];
|
||||
i = MSG_ReadByte (net_message);
|
||||
s = MSG_ReadString (net_message);
|
||||
if (i == PRINT_CHAT) {
|
||||
// TODO: cl_nofake 2 -- accept fake messages from
|
||||
// teammates
|
||||
|
||||
if (cl_nofake->int_val) {
|
||||
char *c;
|
||||
strncpy (p, s, sizeof (p));
|
||||
p[sizeof (p) - 1] = 0;
|
||||
for (c = p; *c; c++) {
|
||||
if (*c == '\r')
|
||||
*c = '#';
|
||||
}
|
||||
s = p;
|
||||
}
|
||||
con_ormask = 128;
|
||||
S_LocalSound ("misc/talk.wav");
|
||||
}
|
||||
Con_Printf ("%s", s);
|
||||
con_ormask = 0;
|
||||
case svc_print:
|
||||
CL_ParsePrint ();
|
||||
break;
|
||||
}
|
||||
|
||||
case svc_centerprint:
|
||||
SCR_CenterPrint (MSG_ReadString (net_message));
|
||||
break;
|
||||
|
|
|
@ -49,6 +49,35 @@ static const char rcsid[] =
|
|||
#include "compat.h"
|
||||
#include "net_svc.h"
|
||||
|
||||
void
|
||||
NET_SVC_Print_Parse (net_svc_print_t *print, msg_t *message)
|
||||
{
|
||||
print->level = MSG_ReadByte (message);
|
||||
print->message = MSG_ReadString (message);
|
||||
}
|
||||
|
||||
void
|
||||
NET_SVC_Download_Parse (net_svc_download_t *download, msg_t *message)
|
||||
{
|
||||
download->size = MSG_ReadShort (message);
|
||||
download->percent = MSG_ReadByte (message);
|
||||
|
||||
if (download->size == -2)
|
||||
download->name = MSG_ReadString (message);
|
||||
else if (download->size > 0) {
|
||||
// FIXME: this should really be a MSG function
|
||||
if (message->readcount + download->size <= message->message->cursize) {
|
||||
download->data = message->message->data + message->readcount;
|
||||
message->readcount += download->size;
|
||||
} else {
|
||||
// size was beyond the end of the packet
|
||||
message->readcount = message->message->cursize;
|
||||
message->badread = true;
|
||||
download->size = 0; // FIXME: CL_ParseDownload doesn't handle this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NET_SVC_Soundlist_Parse (net_svc_soundlist_t *soundlist, msg_t *message)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue