summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp36
-rw-r--r--src/Client/CommandParser.h19
2 files changed, 48 insertions, 7 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 4faec95..6f5f38b 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -84,7 +84,7 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) {
void CommandParser::statusCommand(const std::vector<std::string>&) {
activeRequests++;
- Common::Request::CoreStatusRequest::send(connection, *requestManager, sigc::mem_fun(this, &CommandParser::requestFinished));
+ Common::Request::CoreStatusRequest::send(connection, *requestManager, sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished));
}
void CommandParser::exitCommand(const std::vector<std::string>&) {
@@ -94,6 +94,40 @@ void CommandParser::exitCommand(const std::vector<std::string>&) {
Common::Request::DisconnectRequest::send(connection, *requestManager, sigc::mem_fun(this, &CommandParser::requestFinished));
}
+void CommandParser::coreStatusRequestFinished(const Net::Packets::CoreStatusPacket &packet) {
+ std::cout << "Server status:" << std::endl;
+
+ if(packet.getUptime()) {
+ unsigned long days = packet.getUptime()/86400;
+ unsigned long hours = (packet.getUptime()%86400)/3600;
+ unsigned long minutes = (packet.getUptime()%3600)/60;
+
+ std::cout << "\tUptime: ";
+
+ if(days) std::cout << days << " days ";
+
+ std::cout << hours << ":";
+
+ std::streamsize width = std::cout.width(2);
+ std::cout.fill('0');
+ std::cout << minutes;
+
+ std::cout.width(width);
+
+ if(packet.getIdleTime()) {
+ std::streamsize prec = std::cout.precision(3);
+ std::cout << " (load average: " << (100.0f-(packet.getIdleTime()*100.0f/packet.getUptime())) << "%)";
+ std::cout.precision(prec);
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+
+ requestFinished();
+}
+
bool CommandParser::split(const std::string &str, std::vector<std::string> &ret) {
std::string temp;
bool quoteSingle = false, quoteDouble = false, escape = false;
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 891323f..34f7a28 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -32,6 +32,11 @@ class RequestManager;
namespace Net {
class Connection;
+
+namespace Packets {
+class CoreStatusPacket;
+}
+
}
namespace Client {
@@ -59,12 +64,6 @@ class CommandParser {
bool split(const std::string &str, std::vector<std::string> &ret);
- void requestFinished() {
- activeRequests--;
-
- finished();
- }
-
const Command* findCommand(const std::string& command);
void printUsage(const std::string& command);
@@ -72,6 +71,14 @@ class CommandParser {
void statusCommand(const std::vector<std::string>&);
void exitCommand(const std::vector<std::string>&);
+ void coreStatusRequestFinished(const Net::Packets::CoreStatusPacket &packet);
+
+ void requestFinished() {
+ activeRequests--;
+
+ finished();
+ }
+
public:
CommandParser(Common::RequestManager *requestManager0, Net::Connection *connection0) : requestManager(requestManager0), connection(connection0), activeRequests(0), disconnect(false) {}