Add a command to list current file transfers

This commit is contained in:
Louis-Antoine 2020-05-20 00:24:53 +02:00
parent c8948909d3
commit 06060c02d3
3 changed files with 38 additions and 0 deletions

View File

@ -501,6 +501,8 @@ void D_RegisterServerCommands(void)
COM_AddCommand("archivetest", Command_Archivetest_f);
#endif
COM_AddCommand("downloads", Command_Downloads_f);
// for master server connection
AddMServCommands();

View File

@ -1386,6 +1386,40 @@ void CloseNetFile(void)
}
}
void Command_Downloads_f(void)
{
INT32 node;
for (node = 0; node < MAXNETNODES; node++)
if (transfer[node].txlist
&& transfer[node].txlist->ram == SF_FILE) // Node is downloading a file?
{
const char *name = transfer[node].txlist->id.filename;
UINT32 position = transfer[node].position;
UINT32 size = transfer[node].txlist->size;
char ratecolor;
// Avoid division by zero errors
if (!size)
size = 1;
name = &name[strlen(name) - nameonlylength(name)];
switch (4 * (position - 1) / size)
{
case 0: ratecolor = '\x85'; break;
case 1: ratecolor = '\x87'; break;
case 2: ratecolor = '\x82'; break;
case 3: ratecolor = '\x83'; break;
default: ratecolor = '\x80';
}
CONS_Printf("%2d %c%s ", node, ratecolor, name); // Node and file name
CONS_Printf("\x80%uK\x84/\x80%uK ", position / 1024, size / 1024); // Progress in kB
CONS_Printf("\x80(%c%u%%\x80) ", ratecolor, (UINT32)(100.0 * position / size)); // Progress in %
CONS_Printf("%s\n", I_GetNodeAddress(node)); // Address and newline
}
}
// Functions cut and pasted from Doomatic :)
void nameonly(char *s)

View File

@ -122,6 +122,8 @@ void SV_AbortSendFiles(INT32 node);
void CloseNetFile(void);
void CL_AbortDownloadResume(void);
void Command_Downloads_f(void);
boolean fileexist(char *filename, time_t ptime);
// Search a file in the wadpath, return FS_FOUND when found