Refactor Lua file transfer code

This commit is contained in:
Louis-Antoine 2020-05-19 15:16:51 +02:00
parent db85c62c6f
commit 06d3af6716
2 changed files with 23 additions and 31 deletions

View File

@ -314,16 +314,7 @@ void Got_LuaFile(UINT8 **cp, INT32 playernum)
RemoveLuaFileTransfer();
if (server && luafiletransfers)
{
if (FIL_FileOK(luafiletransfers->realfilename))
SV_PrepareSendLuaFileToNextNode();
else
{
// Send a net command with 0 as its first byte to indicate the file couldn't be opened
success = 0;
SendNetXCmd(XD_LUAFILE, &success, 1);
}
}
SV_PrepareSendLuaFile();
}

View File

@ -538,26 +538,9 @@ void AddLuaFileTransfer(const char *filename, const char *mode)
strlcpy(filetransfer->mode, mode, sizeof(filetransfer->mode));
if (server)
{
INT32 i;
// Set status to "waiting" for everyone
for (i = 0; i < MAXNETNODES; i++)
filetransfer->nodestatus[i] = LFTNS_WAITING;
if (!luafiletransfers->next) // Only if there is no transfer already going on
{
if (FIL_ReadFileOK(filetransfer->realfilename))
SV_PrepareSendLuaFileToNextNode();
else
{
// Send a net command with 0 as its first byte to indicate the file couldn't be opened
UINT8 success = 0;
SendNetXCmd(XD_LUAFILE, &success, 1);
}
}
}
// Only if there is no transfer already going on
if (server && filetransfer == luafiletransfers)
SV_PrepareSendLuaFile();
// Store the callback so it can be called once everyone has the file
filetransfer->id = id;
@ -571,7 +554,7 @@ void AddLuaFileTransfer(const char *filename, const char *mode)
}
}
void SV_PrepareSendLuaFileToNextNode(void)
static void SV_PrepareSendLuaFileToNextNode(void)
{
INT32 i;
UINT8 success = 1;
@ -595,6 +578,24 @@ void SV_PrepareSendLuaFileToNextNode(void)
SendNetXCmd(XD_LUAFILE, &success, 1);
}
void SV_PrepareSendLuaFile(void)
{
INT32 i;
// Set status to "waiting" for everyone
for (i = 0; i < MAXNETNODES; i++)
luafiletransfers->nodestatus[i] = LFTNS_WAITING;
if (FIL_ReadFileOK(luafiletransfers->realfilename))
SV_PrepareSendLuaFileToNextNode();
else
{
// Send a net command with 0 as its first byte to indicate the file couldn't be opened
UINT8 success = 0;
SendNetXCmd(XD_LUAFILE, &success, 1);
}
}
void SV_HandleLuaFileSent(UINT8 node)
{
luafiletransfers->nodestatus[node] = LFTNS_SENT;