From 651176199181690cbfe9bb72dce5be4d152f47a7 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Fri, 6 Mar 2009 00:46:45 +0100 Subject: [PATCH] Fixed uptime output formatting to be less verbose. --- src/commands.c | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/src/commands.c b/src/commands.c index d976ee8..04c3488 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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);