mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
Merge branch 'fix-luafile-transfer' into 'next'
Prevent a single client from blocking Lua file transfers See merge request STJr/SRB2!1435
This commit is contained in:
commit
933fad7702
2 changed files with 30 additions and 9 deletions
|
@ -562,7 +562,7 @@ static void SV_PrepareSendLuaFileToNextNode(void)
|
||||||
|
|
||||||
// Find a client to send the file to
|
// Find a client to send the file to
|
||||||
for (i = 1; i < MAXNETNODES; i++)
|
for (i = 1; i < MAXNETNODES; i++)
|
||||||
if (nodeingame[i] && luafiletransfers->nodestatus[i] == LFTNS_WAITING) // Node waiting
|
if (luafiletransfers->nodestatus[i] == LFTNS_WAITING) // Node waiting
|
||||||
{
|
{
|
||||||
// Tell the client we're about to send them the file
|
// Tell the client we're about to send them the file
|
||||||
netbuffer->packettype = PT_SENDINGLUAFILE;
|
netbuffer->packettype = PT_SENDINGLUAFILE;
|
||||||
|
@ -570,6 +570,7 @@ static void SV_PrepareSendLuaFileToNextNode(void)
|
||||||
I_Error("Failed to send a PT_SENDINGLUAFILE packet\n"); // !!! Todo: Handle failure a bit better lol
|
I_Error("Failed to send a PT_SENDINGLUAFILE packet\n"); // !!! Todo: Handle failure a bit better lol
|
||||||
|
|
||||||
luafiletransfers->nodestatus[i] = LFTNS_ASKED;
|
luafiletransfers->nodestatus[i] = LFTNS_ASKED;
|
||||||
|
luafiletransfers->nodetimeouts[i] = I_GetTime() + 30 * TICRATE;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -588,7 +589,7 @@ void SV_PrepareSendLuaFile(void)
|
||||||
|
|
||||||
// Set status to "waiting" for everyone
|
// Set status to "waiting" for everyone
|
||||||
for (i = 0; i < MAXNETNODES; i++)
|
for (i = 0; i < MAXNETNODES; i++)
|
||||||
luafiletransfers->nodestatus[i] = LFTNS_WAITING;
|
luafiletransfers->nodestatus[i] = (nodeingame[i] ? LFTNS_WAITING : LFTNS_NONE);
|
||||||
|
|
||||||
if (FIL_ReadFileOK(luafiletransfers->realfilename))
|
if (FIL_ReadFileOK(luafiletransfers->realfilename))
|
||||||
{
|
{
|
||||||
|
@ -649,12 +650,14 @@ void RemoveAllLuaFileTransfers(void)
|
||||||
|
|
||||||
void SV_AbortLuaFileTransfer(INT32 node)
|
void SV_AbortLuaFileTransfer(INT32 node)
|
||||||
{
|
{
|
||||||
if (luafiletransfers
|
if (luafiletransfers)
|
||||||
&& (luafiletransfers->nodestatus[node] == LFTNS_ASKED
|
|
||||||
|| luafiletransfers->nodestatus[node] == LFTNS_SENDING))
|
|
||||||
{
|
{
|
||||||
luafiletransfers->nodestatus[node] = LFTNS_WAITING;
|
if (luafiletransfers->nodestatus[node] == LFTNS_ASKED
|
||||||
SV_PrepareSendLuaFileToNextNode();
|
|| luafiletransfers->nodestatus[node] == LFTNS_SENDING)
|
||||||
|
{
|
||||||
|
SV_PrepareSendLuaFileToNextNode();
|
||||||
|
}
|
||||||
|
luafiletransfers->nodestatus[node] = LFTNS_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -928,6 +931,22 @@ void FileSendTicker(void)
|
||||||
filetx_t *f;
|
filetx_t *f;
|
||||||
INT32 packetsent, ram, i, j;
|
INT32 packetsent, ram, i, j;
|
||||||
|
|
||||||
|
// If someone is taking too long to download, kick them with a timeout
|
||||||
|
// to prevent blocking the rest of the server...
|
||||||
|
if (luafiletransfers)
|
||||||
|
{
|
||||||
|
for (i = 1; i < MAXNETNODES; i++)
|
||||||
|
{
|
||||||
|
luafiletransfernodestatus_t status = luafiletransfers->nodestatus[i];
|
||||||
|
|
||||||
|
if (status != LFTNS_NONE && status != LFTNS_WAITING && status != LFTNS_SENT
|
||||||
|
&& I_GetTime() > luafiletransfers->nodetimeouts[i])
|
||||||
|
{
|
||||||
|
Net_ConnectionTimeout(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!filestosend) // No file to send
|
if (!filestosend) // No file to send
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -85,10 +85,11 @@ boolean PT_RequestFile(INT32 node);
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
LFTNS_NONE, // This node is not connected
|
||||||
LFTNS_WAITING, // This node is waiting for the server to send the file
|
LFTNS_WAITING, // This node is waiting for the server to send the file
|
||||||
LFTNS_ASKED, // The server has told the node they're ready to send the file
|
LFTNS_ASKED, // The server has told the node they're ready to send the file
|
||||||
LFTNS_SENDING, // The server is sending the file to this node
|
LFTNS_SENDING, // The server is sending the file to this node
|
||||||
LFTNS_SENT // The node already has the file
|
LFTNS_SENT // The node already has the file
|
||||||
} luafiletransfernodestatus_t;
|
} luafiletransfernodestatus_t;
|
||||||
|
|
||||||
typedef struct luafiletransfer_s
|
typedef struct luafiletransfer_s
|
||||||
|
@ -99,6 +100,7 @@ typedef struct luafiletransfer_s
|
||||||
INT32 id; // Callback ID
|
INT32 id; // Callback ID
|
||||||
boolean ongoing;
|
boolean ongoing;
|
||||||
luafiletransfernodestatus_t nodestatus[MAXNETNODES];
|
luafiletransfernodestatus_t nodestatus[MAXNETNODES];
|
||||||
|
tic_t nodetimeouts[MAXNETNODES];
|
||||||
struct luafiletransfer_s *next;
|
struct luafiletransfer_s *next;
|
||||||
} luafiletransfer_t;
|
} luafiletransfer_t;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue