summaryrefslogtreecommitdiffstats
path: root/src/Client/CommandParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client/CommandParser.cpp')
-rw-r--r--src/Client/CommandParser.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 9644d71..badbef7 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -19,8 +19,10 @@
#include "CommandParser.h"
#include "Requests/CoreStatusRequest.h"
+#include "Requests/DaemonListRequest.h"
#include <Common/Requests/DisconnectRequest.h>
#include <Net/Packets/HostStatusPacket.h>
+#include <Net/Packets/NameListPacket.h>
#include <iostream>
#include <cstdio>
@@ -30,6 +32,7 @@ namespace Client {
const CommandParser::Command CommandParser::commands[] = {
{{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand},
+ {{"list_hosts", "hosts", 0}, "list_hosts", "Lists the currently active hosts", "Lists the currently active hosts", &CommandParser::listHostsCommand},
{{"status", "st", 0}, "status", "Displays server status information", "Displays server status information.", &CommandParser::statusCommand},
{{"exit", "quit", 0}, "exit", "Closes the connection and quits the client", "Closes the connection and quits the client.", &CommandParser::exitCommand},
{{0}, 0, 0, 0, 0}
@@ -83,6 +86,12 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) {
}
}
+void CommandParser::listHostsCommand(const std::vector<std::string>&) {
+ activeRequests++;
+
+ Requests::DaemonListRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonListRequestFinished));
+}
+
void CommandParser::statusCommand(const std::vector<std::string>&) {
activeRequests++;
@@ -153,6 +162,24 @@ void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPack
requestFinished();
}
+void CommandParser::daemonListRequestFinished(const Net::Packets::NameListPacket &packet) {
+ const std::vector<std::string>& hosts = packet.getNameList();
+
+ if(hosts.empty()) {
+ std::cout << "There aren't any active hosts." << std::endl << std::endl;
+ }
+ else {
+ std::cout << "Active hosts:" << std::endl;
+
+ for(std::vector<std::string>::const_iterator host = hosts.begin(); host != hosts.end(); ++host)
+ std::cout << "\t" << *host << 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;