summaryrefslogtreecommitdiff
path: root/src/commandhandler.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-12 21:59:09 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-12 21:59:09 +0200
commit7f1553890e614d5c7afd7f01a11277b822fd4a05 (patch)
tree1d6cb7011db199d41efb3060ce9ede0c57a3b810 /src/commandhandler.cpp
parent0c6bf93ee13f0b3344079ebf4e60c5ec8323f0bd (diff)
downloadplus-7f1553890e614d5c7afd7f01a11277b822fd4a05.tar.gz
plus-7f1553890e614d5c7afd7f01a11277b822fd4a05.tar.bz2
plus-7f1553890e614d5c7afd7f01a11277b822fd4a05.tar.xz
plus-7f1553890e614d5c7afd7f01a11277b822fd4a05.zip
Add /uptime chat command to show client uptime.
Diffstat (limited to 'src/commandhandler.cpp')
-rw-r--r--src/commandhandler.cpp53
1 files changed, 53 insertions, 0 deletions
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_)
{