Refactor Lua file transfer code
This commit is contained in:
parent
db85c62c6f
commit
06d3af6716
|
@ -314,16 +314,7 @@ void Got_LuaFile(UINT8 **cp, INT32 playernum)
|
||||||
RemoveLuaFileTransfer();
|
RemoveLuaFileTransfer();
|
||||||
|
|
||||||
if (server && luafiletransfers)
|
if (server && luafiletransfers)
|
||||||
{
|
SV_PrepareSendLuaFile();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -538,26 +538,9 @@ void AddLuaFileTransfer(const char *filename, const char *mode)
|
||||||
|
|
||||||
strlcpy(filetransfer->mode, mode, sizeof(filetransfer->mode));
|
strlcpy(filetransfer->mode, mode, sizeof(filetransfer->mode));
|
||||||
|
|
||||||
if (server)
|
// Only if there is no transfer already going on
|
||||||
{
|
if (server && filetransfer == luafiletransfers)
|
||||||
INT32 i;
|
SV_PrepareSendLuaFile();
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the callback so it can be called once everyone has the file
|
// Store the callback so it can be called once everyone has the file
|
||||||
filetransfer->id = id;
|
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;
|
INT32 i;
|
||||||
UINT8 success = 1;
|
UINT8 success = 1;
|
||||||
|
@ -595,6 +578,24 @@ void SV_PrepareSendLuaFileToNextNode(void)
|
||||||
SendNetXCmd(XD_LUAFILE, &success, 1);
|
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)
|
void SV_HandleLuaFileSent(UINT8 node)
|
||||||
{
|
{
|
||||||
luafiletransfers->nodestatus[node] = LFTNS_SENT;
|
luafiletransfers->nodestatus[node] = LFTNS_SENT;
|
||||||
|
|
Loading…
Reference in New Issue