From 06060c02d38d174031e2d0fc1488f44920323611 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Wed, 20 May 2020 00:24:53 +0200 Subject: [PATCH] Add a command to list current file transfers --- src/d_netcmd.c | 2 ++ src/d_netfil.c | 34 ++++++++++++++++++++++++++++++++++ src/d_netfil.h | 2 ++ 3 files changed, 38 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index dfc7351f5..042b99cc7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -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(); diff --git a/src/d_netfil.c b/src/d_netfil.c index c5f3d8658..9e43da791 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -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) diff --git a/src/d_netfil.h b/src/d_netfil.h index be58f807f..a653d5a4b 100644 --- a/src/d_netfil.h +++ b/src/d_netfil.h @@ -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