summaryrefslogtreecommitdiff
path: root/src
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
parent0c6bf93ee13f0b3344079ebf4e60c5ec8323f0bd (diff)
downloadmanaplus-7f1553890e614d5c7afd7f01a11277b822fd4a05.tar.gz
manaplus-7f1553890e614d5c7afd7f01a11277b822fd4a05.tar.bz2
manaplus-7f1553890e614d5c7afd7f01a11277b822fd4a05.tar.xz
manaplus-7f1553890e614d5c7afd7f01a11277b822fd4a05.zip
Add /uptime chat command to show client uptime.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp3
-rw-r--r--src/client.h3
-rw-r--r--src/commandhandler.cpp53
-rw-r--r--src/commandhandler.h2
-rw-r--r--src/gui/chat.cpp1
5 files changed, 62 insertions, 0 deletions
diff --git a/src/client.cpp b/src/client.cpp
index e1753753e..5c183a17d 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -152,6 +152,7 @@ volatile int cur_time;
volatile bool runCounters;
bool isSafeMode = false;
int serverVersion;
+int start_time;
/**
* Advances game logic counter.
@@ -535,6 +536,8 @@ Client::Client(const Options &options):
optionChanged("fpslimit");
+ start_time = time(NULL);
+
// Initialize PlayerInfo
PlayerInfo::init();
}
diff --git a/src/client.h b/src/client.h
index e3f596c1a..eb859f0a8 100644
--- a/src/client.h
+++ b/src/client.h
@@ -34,6 +34,8 @@
#include <string>
+#include <sys/time.h>
+
#ifdef __GNUC__
#define _UNUSED_ __attribute__ ((unused))
#else
@@ -60,6 +62,7 @@ extern volatile int tick_time;
extern volatile int cur_time;
extern bool isSafeMode;
extern int serverVersion;
+extern int start_time;
class ErrorListener : public gcn::ActionListener
{
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_)
{
diff --git a/src/commandhandler.h b/src/commandhandler.h
index fb4039e04..779a6e6fd 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -272,6 +272,8 @@ class CommandHandler
void handleWait(const std::string &args, ChatTab *tab);
+ void handleUptime(const std::string &args, ChatTab *tab);
+
void handleCacheInfo(const std::string &args, ChatTab *tab _UNUSED_);
bool parse2Int(const std::string &args, int *x, int *y);
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index b2f51a5e6..399202b70 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -262,6 +262,7 @@ void ChatWindow::fillCommands()
mCommands.push_back("/dirs");
mCommands.push_back("/info");
mCommands.push_back("/wait");
+ mCommands.push_back("/uptime");
}
void ChatWindow::resetToDefaultSize()