0
0
Fork 0
mirror of https://git.do.srb2.org/STJr/SRB2.git synced 2025-03-06 01:12:04 +00:00

Split packet handling switch into functions

This commit is contained in:
LJ Sonic 2022-12-29 10:23:12 +01:00
parent 33c76453e1
commit 262ed6b7f3
3 changed files with 605 additions and 563 deletions

File diff suppressed because it is too large Load diff

View file

@ -413,12 +413,17 @@ boolean CL_SendFileRequest(void)
} }
// get request filepak and put it on the send queue // get request filepak and put it on the send queue
// returns false if a requested file was not found or cannot be sent void PT_RequestFile(SINT8 node)
boolean PT_RequestFile(INT32 node)
{ {
UINT8 *p = netbuffer->u.textcmd; UINT8 *p = netbuffer->u.textcmd;
UINT8 id; UINT8 id;
if (client || !cv_downloading.value)
{
Net_CloseConnection(node); // close connection if you are not the server or disabled downloading
return;
}
while (p < netbuffer->u.textcmd + MAXTEXTCMD-1) // Don't allow hacked client to overflow while (p < netbuffer->u.textcmd + MAXTEXTCMD-1) // Don't allow hacked client to overflow
{ {
id = READUINT8(p); id = READUINT8(p);
@ -428,11 +433,12 @@ boolean PT_RequestFile(INT32 node)
if (!AddFileToSendQueue(node, id)) if (!AddFileToSendQueue(node, id))
{ {
SV_AbortSendFiles(node); SV_AbortSendFiles(node);
return false; // don't read the rest of the files Net_CloseConnection(node); // close connection if one of the requested files could not be sent
return; // don't read the rest of the files
} }
} }
return true; // no problems with any files return; // no problems with any files
} }
/** Checks if the files needed aren't already loaded or on the disk /** Checks if the files needed aren't already loaded or on the disk
@ -1137,13 +1143,15 @@ void FileSendTicker(void)
} }
} }
void PT_FileAck(void) void PT_FileAck(SINT8 node)
{ {
fileack_pak *packet = &netbuffer->u.fileack; fileack_pak *packet = &netbuffer->u.fileack;
INT32 node = doomcom->remotenode;
filetran_t *trans = &transfer[node]; filetran_t *trans = &transfer[node];
INT32 i, j; INT32 i, j;
if (client)
return;
// Wrong file id? Ignore it, it's probably a late packet // Wrong file id? Ignore it, it's probably a late packet
if (!(trans->txlist && packet->fileid == trans->txlist->fileid)) if (!(trans->txlist && packet->fileid == trans->txlist->fileid))
return; return;
@ -1190,12 +1198,12 @@ void PT_FileAck(void)
} }
} }
void PT_FileReceived(void) void PT_FileReceived(SINT8 node)
{ {
filetx_t *trans = transfer[doomcom->remotenode].txlist; filetx_t *trans = transfer[node].txlist;
if (trans && netbuffer->u.filereceived == trans->fileid) if (server && trans && netbuffer->u.filereceived == trans->fileid)
SV_EndFileSend(doomcom->remotenode); SV_EndFileSend(node);
} }
static void SendAckPacket(fileack_pak *packet, UINT8 fileid) static void SendAckPacket(fileack_pak *packet, UINT8 fileid)
@ -1281,8 +1289,27 @@ void FileReceiveTicker(void)
} }
} }
void PT_FileFragment(void) void PT_FileFragment(SINT8 node, INT32 netconsole)
{ {
if (nodeingame[node])
{
// Only accept PT_FILEFRAGMENT from the server.
if (node != servernode)
{
CONS_Alert(CONS_WARNING, M_GetText("%s received from non-host %d\n"), "PT_FILEFRAGMENT", node);
if (server)
SendKick(netconsole, KICK_MSG_CON_FAIL | KICK_MSG_KEEP_BODY);
return;
}
if (server)
return;
}
else if (server || node != servernode)
{
Net_CloseConnection(node);
return;
}
INT32 filenum = netbuffer->u.filetxpak.fileid; INT32 filenum = netbuffer->u.filetxpak.fileid;
fileneeded_t *file = &fileneeded[filenum]; fileneeded_t *file = &fileneeded[filenum];
UINT32 fragmentpos = LONG(netbuffer->u.filetxpak.position); UINT32 fragmentpos = LONG(netbuffer->u.filetxpak.position);

View file

@ -90,16 +90,16 @@ void AddRamToSendQueue(INT32 node, void *data, size_t size, freemethod_t freemet
UINT8 fileid); UINT8 fileid);
void FileSendTicker(void); void FileSendTicker(void);
void PT_FileAck(void); void PT_FileAck(SINT8 node);
void PT_FileReceived(void); void PT_FileReceived(SINT8 node);
boolean SendingFile(INT32 node); boolean SendingFile(INT32 node);
void FileReceiveTicker(void); void FileReceiveTicker(void);
void PT_FileFragment(void); void PT_FileFragment(SINT8 node, INT32 netconsole);
boolean CL_CheckDownloadable(void); boolean CL_CheckDownloadable(void);
boolean CL_SendFileRequest(void); boolean CL_SendFileRequest(void);
boolean PT_RequestFile(INT32 node); void PT_RequestFile(SINT8 node);
typedef enum typedef enum
{ {