From 7f1553890e614d5c7afd7f01a11277b822fd4a05 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 12 Mar 2011 21:59:09 +0200 Subject: Add /uptime chat command to show client uptime. --- src/commandhandler.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/commandhandler.cpp') diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 1d374541e..9f007acf1 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -254,6 +254,10 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab) { handleWait(args, tab); } + else if (type == "uptime") + { + handleUptime(args, tab); + } else if (tab->handleCommand(type, args)) { // Nothing to do @@ -1097,6 +1101,55 @@ void CommandHandler::handleWait(const std::string &args, player_node->waitFor(args); } +void CommandHandler::handleUptime(const std::string &args, + ChatTab *tab _UNUSED_) +{ + if (!debugChatTab) + return; + + if (cur_time < start_time) + { + debugChatTab->chatLog(strprintf(_("Client uptime: %s"), "unknown")); + } + else + { + std::string str; + const int timeDiff = cur_time - start_time; + const int min = timeDiff / 60; + const int hours = min / 60; + const int days = hours / 24; + const int weeks = days / 7; + if (weeks > 0) + { + str = strprintf(ngettext("%d week", "%d weeks", weeks), weeks); + } + if (days > 0) + { + if (!str.empty()) + str += ", "; + str += strprintf(ngettext("%d day", "%d days", days), days); + } + if (hours > 0) + { + if (!str.empty()) + str += ", "; + str += strprintf(ngettext("%d hour", "%d hours", hours), hours); + } + if (min > 0) + { + if (!str.empty()) + str += ", "; + str += strprintf(ngettext("%d minute", "%d minutes", min), min); + } + if (str.empty()) + { + str += strprintf(ngettext("%d second", "%d seconds", + timeDiff), timeDiff); + } + debugChatTab->chatLog(strprintf(_("Client uptime: %s"), str.c_str())); + } +} + void CommandHandler::handleCacheInfo(const std::string &args _UNUSED_, ChatTab *tab _UNUSED_) { -- cgit v1.2.3-60-g2f50