From 30bec92571ba23f1f2aa6b12149f6545a4ef0d7e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 15 Sep 2008 04:46:28 +0200 Subject: Hosts k?nnen jetzt aufgelistet werden --- src/Client/CommandParser.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/Client/CommandParser.cpp') 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 #include +#include #include #include @@ -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 &args) { } } +void CommandParser::listHostsCommand(const std::vector&) { + activeRequests++; + + Requests::DaemonListRequest::send(connection, sigc::mem_fun(this, &CommandParser::daemonListRequestFinished)); +} + void CommandParser::statusCommand(const std::vector&) { activeRequests++; @@ -153,6 +162,24 @@ void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPack requestFinished(); } +void CommandParser::daemonListRequestFinished(const Net::Packets::NameListPacket &packet) { + const std::vector& 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::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 &ret) { std::string temp; bool quoteSingle = false, quoteDouble = false, escape = false; -- cgit v1.2.3