Fixed uptime output formatting to be less verbose.
This commit is contained in:
parent
c02c45f2d0
commit
6511761991
|
@ -35,10 +35,10 @@ static int command_access_denied(struct user* user)
|
|||
static int command_stats(struct user* user, const char* message)
|
||||
{
|
||||
struct adc_message* command;
|
||||
|
||||
|
||||
if (user->credentials < cred_super)
|
||||
return command_access_denied(user);
|
||||
|
||||
|
||||
char temp[128];
|
||||
|
||||
snprintf(temp, 128, "*** Stats: %zu users, peak: %zu. Network (up/down): %d/%d KB/s, peak: %d/%d KB/s",
|
||||
|
@ -83,34 +83,21 @@ static int command_uptime(struct user* user, const char* message)
|
|||
{
|
||||
struct adc_message* command;
|
||||
char tmp[128];
|
||||
size_t w;
|
||||
size_t d;
|
||||
size_t h;
|
||||
size_t m;
|
||||
size_t s;
|
||||
size_t D = (size_t) difftime(time(0), user->hub->tm_started);
|
||||
|
||||
w = D / (7 * 24 * 3600);
|
||||
D = D % (7 * 24 * 3600);
|
||||
d = D / (24 * 3600);
|
||||
D = D % (24 * 3600);
|
||||
h = D / 3600;
|
||||
D = D % 3600;
|
||||
m = D / 60;
|
||||
s = D % 60;
|
||||
|
||||
tmp[0] = 0;
|
||||
strcat(tmp, "*** Uptime: ");
|
||||
|
||||
if (w)
|
||||
{
|
||||
strcat(tmp, uhub_itoa((int) w));
|
||||
strcat(tmp, " week");
|
||||
if (w != 1) strcat(tmp, "s");
|
||||
strcat(tmp, ", ");
|
||||
}
|
||||
|
||||
if (w || d)
|
||||
if (d)
|
||||
{
|
||||
strcat(tmp, uhub_itoa((int) d));
|
||||
strcat(tmp, " day");
|
||||
|
@ -118,26 +105,11 @@ static int command_uptime(struct user* user, const char* message)
|
|||
strcat(tmp, ", ");
|
||||
}
|
||||
|
||||
if (w || d || h)
|
||||
{
|
||||
strcat(tmp, uhub_itoa((int) h));
|
||||
strcat(tmp, " hour");
|
||||
if (h != 1) strcat(tmp, "s");
|
||||
strcat(tmp, ", ");
|
||||
}
|
||||
|
||||
if (w || d || h || m)
|
||||
{
|
||||
strcat(tmp, uhub_itoa((int) m));
|
||||
strcat(tmp, " minute");
|
||||
if (m != 1) strcat(tmp, "s");
|
||||
strcat(tmp, ", and ");
|
||||
}
|
||||
|
||||
strcat(tmp, uhub_itoa((int) s));
|
||||
strcat(tmp, " second");
|
||||
if (s != 1) strcat(tmp, "s");
|
||||
strcat(tmp, ".");
|
||||
if (h < 10) strcat(tmp, "0");
|
||||
strcat(tmp, uhub_itoa((int) h));
|
||||
strcat(tmp, ":");
|
||||
if (m < 10) strcat(tmp, "0");
|
||||
strcat(tmp, uhub_itoa((int) m));
|
||||
|
||||
char* buffer = adc_msg_escape(tmp);
|
||||
command = adc_msg_construct(ADC_CMD_IMSG, strlen(buffer) + 6);
|
||||
|
|
Loading…
Reference in New Issue