looks like this is closest to srb2classic so

make file downloading closer to srb2classic
WILL NEED TESTING
This commit is contained in:
minenice55 2026-04-24 02:06:39 -04:00
parent e51325f67d
commit 887f696dfb

View file

@ -1464,6 +1464,24 @@ void FileReceiveTicker(void)
}
}
static void OpenNewFileForDownload(doomdata_t *netbuffer, fileneeded_t *file, const char *filename)
{
filetx_pak *pak = (void*)&netbuffer->u.filetxpak;
file->file = fopen(filename, "wb");
if (!file->file)
I_Error("Can't create file %s: %s", filename, strerror(errno));
file->currentsize = 0;
file->totalsize = LONG(pak->filesize);
file->ackresendposition = UINT32_MAX; // Only used for resumed downloads
file->receivedfragments = calloc(file->totalsize / file->fragmentsize + 1, sizeof(*file->receivedfragments));
if (!file->receivedfragments)
I_Error("FileSendTicker: No more memory\n");
}
void PT_FileFragment(SINT8 node, INT32 netconsole)
{
if (nodeingame[node])
@ -1491,7 +1509,7 @@ void PT_FileFragment(SINT8 node, INT32 netconsole)
fileneeded_t *file = &fileneeded[filenum];
UINT32 fragmentpos = LONG(pak->position);
UINT16 fragmentsize = SHORT(pak->size);
UINT16 boundedfragmentsize = doomcom->datalength - BASEPACKETSIZE - sizeof(netbuffer->u.filetxpak);
UINT16 boundedfragmentsize = doomcom->datalength - sizeof(netbuffer->u.filetxpak);
char *filename;
filename = va("%s", file->filename);
@ -1540,13 +1558,22 @@ void PT_FileFragment(SINT8 node, INT32 netconsole)
{
file->file = fopen(filename, "r+b");
if (!file->file)
{
I_Error("Can't reopen file %s: %s", filename, strerror(errno));
CONS_Printf("\r%s...\n", filename);
CONS_Printf("Resuming download...\n");
file->currentsize = pauseddownload->currentsize;
file->receivedfragments = pauseddownload->receivedfragments;
file->ackresendposition = 0;
free(pauseddownload->receivedfragments);
CONS_Printf("Restarting download of file \"%s\"...\n", filename);
OpenNewFileForDownload(netbuffer, file, file->filename);
}
else
{
CONS_Printf("Resuming download of file \"%s\"...\n", filename);
file->currentsize = pauseddownload->currentsize;
file->receivedfragments = pauseddownload->receivedfragments;
file->ackresendposition = 0;
}
free(pauseddownload);
pauseddownload = NULL;
@ -1554,20 +1581,8 @@ void PT_FileFragment(SINT8 node, INT32 netconsole)
else
{
CL_AbortDownloadResume();
file->file = fopen(filename, "wb");
if (!file->file)
I_Error("Can't create file %s: %s", filename, strerror(errno));
CONS_Printf("\r%s...\n",filename);
file->currentsize = 0;
file->totalsize = LONG(pak->filesize);
file->ackresendposition = UINT32_MAX; // Only used for resumed downloads
file->receivedfragments = calloc(file->totalsize / fragmentsize + 1, sizeof(*file->receivedfragments));
if (!file->receivedfragments)
I_Error("FileSendTicker: No more memory\n");
OpenNewFileForDownload(netbuffer, file, file->filename);
CONS_Printf("Downloading addon \"%s\" from the server...\n", filename);
}
lasttimeackpacketsent = I_GetTime();
@ -1601,23 +1616,24 @@ void PT_FileFragment(SINT8 node, INT32 netconsole)
free(file->ackpacket);
file->status = FS_FOUND;
file->justdownloaded = true;
CONS_Printf(M_GetText("Downloading %s...(done)\n"),
filename);
// Tell the server we have received the file
netbuffer->packettype = PT_FILERECEIVED;
netbuffer->u.filereceived = filenum;
HSendPacket(servernode, true, 0, 1);
if (luafiletransfers)
{
// Tell the server we have received the file
netbuffer->packettype = PT_HASLUAFILE;
HSendPacket(servernode, true, 0, 0);
}
downloadcompletednum++;
downloadcompletedsize += file->totalsize;
CONS_Printf(M_GetText("Downloading %s...(done)\n"),
filename);
}
}
else // Already received