summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-15 04:46:28 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-15 04:46:28 +0200
commit30bec92571ba23f1f2aa6b12149f6545a4ef0d7e (patch)
treee823812fc05dfa81a103f386df6be81745e2928e
parentfbe26b0e48e6f3714900833174fcf42196e86fc8 (diff)
downloadmad-30bec92571ba23f1f2aa6b12149f6545a4ef0d7e.tar
mad-30bec92571ba23f1f2aa6b12149f6545a4ef0d7e.zip
Hosts k?nnen jetzt aufgelistet werden
-rw-r--r--src/Client/CommandParser.cpp27
-rw-r--r--src/Client/CommandParser.h3
-rw-r--r--src/Client/Requests/CoreStatusRequest.cpp3
-rw-r--r--src/Client/Requests/DaemonListRequest.cpp66
-rw-r--r--src/Client/Requests/DaemonListRequest.h55
-rw-r--r--src/Client/Requests/Makefile.am4
-rw-r--r--src/Client/Requests/Makefile.in7
-rw-r--r--src/Core/ConnectionManager.cpp13
-rw-r--r--src/Core/ConnectionManager.h1
-rw-r--r--src/Core/RequestHandlers/CoreStatusRequestHandler.h6
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.cpp54
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.h40
-rw-r--r--src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h6
-rw-r--r--src/Core/RequestHandlers/Makefile.am4
-rw-r--r--src/Core/RequestHandlers/Makefile.in9
-rw-r--r--src/Net/Packet.h3
-rw-r--r--src/Net/Packets/HostStatusPacket.h1
-rw-r--r--src/Net/Packets/Makefile.am4
-rw-r--r--src/Net/Packets/Makefile.in7
-rw-r--r--src/Net/Packets/NameListPacket.cpp56
-rw-r--r--src/Net/Packets/NameListPacket.h65
21 files changed, 407 insertions, 27 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;
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 69ed217..40d36a7 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -31,6 +31,7 @@ class Connection;
namespace Packets {
class HostStatusPacket;
+class NameListPacket;
}
}
@@ -63,10 +64,12 @@ class CommandParser {
void printUsage(const std::string& command);
void helpCommand(const std::vector<std::string> &args);
+ void listHostsCommand(const std::vector<std::string>&);
void statusCommand(const std::vector<std::string>&);
void exitCommand(const std::vector<std::string>&);
void coreStatusRequestFinished(const Net::Packets::HostStatusPacket &packet);
+ void daemonListRequestFinished(const Net::Packets::NameListPacket &packet);
void requestFinished() {
activeRequests--;
diff --git a/src/Client/Requests/CoreStatusRequest.cpp b/src/Client/Requests/CoreStatusRequest.cpp
index 6d0f634..af34752 100644
--- a/src/Client/Requests/CoreStatusRequest.cpp
+++ b/src/Client/Requests/CoreStatusRequest.cpp
@@ -18,12 +18,9 @@
*/
#include "CoreStatusRequest.h"
-
#include <Common/RequestManager.h>
#include <Net/Packets/HostStatusPacket.h>
-#include <sigc++/signal.h>
-
namespace Mad {
namespace Client {
namespace Requests {
diff --git a/src/Client/Requests/DaemonListRequest.cpp b/src/Client/Requests/DaemonListRequest.cpp
new file mode 100644
index 0000000..a0e4cf1
--- /dev/null
+++ b/src/Client/Requests/DaemonListRequest.cpp
@@ -0,0 +1,66 @@
+/*
+ * DaemonListRequest.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "DaemonListRequest.h"
+#include <Common/RequestManager.h>
+#include <Net/Packets/NameListPacket.h>
+
+namespace Mad {
+namespace Client {
+namespace Requests {
+
+bool DaemonListRequest::send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::NameListPacket&> &callback) {
+ DaemonListRequest *request = new DaemonListRequest();
+
+ request->finished.connect(callback);
+
+ if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request))
+ return true;
+
+ delete request;
+ return false;
+}
+
+bool DaemonListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+ if(isSent())
+ return false;
+
+ if(!connection->send(Net::Packet(Net::Packet::LIST_DAEMONS, requestId)))
+ return false;
+
+ setSent();
+ return true;
+}
+
+bool DaemonListRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
+ if(isFinished())
+ return false;
+
+ if(packet.getType() != Net::Packet::OK)
+ return false; // TODO Logging
+
+ finished(Net::Packets::NameListPacket(packet));
+
+ setFinished();
+ return true;
+}
+
+}
+}
+}
diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h
new file mode 100644
index 0000000..1a820d7
--- /dev/null
+++ b/src/Client/Requests/DaemonListRequest.h
@@ -0,0 +1,55 @@
+/*
+ * DaemonListRequest.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
+#define MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
+
+#include <Common/Request.h>
+
+#include <sigc++/signal.h>
+
+namespace Mad {
+
+namespace Net {
+namespace Packets {
+class NameListPacket;
+}
+}
+
+namespace Client {
+namespace Requests {
+
+class DaemonListRequest : public Common::Request {
+ private:
+ sigc::signal<void,const Net::Packets::NameListPacket&> finished;
+
+ DaemonListRequest() {}
+
+ public:
+ static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::NameListPacket&> &callback);
+
+ virtual bool sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual bool handlePacket(Net::Connection*, const Net::Packet &packet);
+};
+
+}
+}
+}
+
+#endif /* MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_ */
diff --git a/src/Client/Requests/Makefile.am b/src/Client/Requests/Makefile.am
index 4ba72b6..bf15a08 100644
--- a/src/Client/Requests/Makefile.am
+++ b/src/Client/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = CoreStatusRequest.cpp
+librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp
-noinst_HEADERS = CoreStatusRequest.h
+noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h
diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in
index 174e64f..81f6cec 100644
--- a/src/Client/Requests/Makefile.in
+++ b/src/Client/Requests/Makefile.in
@@ -45,7 +45,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
-am_librequests_la_OBJECTS = CoreStatusRequest.lo
+am_librequests_la_OBJECTS = CoreStatusRequest.lo DaemonListRequest.lo
librequests_la_OBJECTS = $(am_librequests_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -184,8 +184,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = CoreStatusRequest.cpp
-noinst_HEADERS = CoreStatusRequest.h
+librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp
+noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h
all: all-am
.SUFFIXES:
@@ -238,6 +238,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CoreStatusRequest.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequest.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index 72bf07f..9cbda90 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -20,6 +20,7 @@
#include "ConnectionManager.h"
#include "ConfigManager.h"
#include "RequestHandlers/CoreStatusRequestHandler.h"
+#include "RequestHandlers/DaemonListRequestHandler.h"
#include "RequestHandlers/DaemonStatusRequestHandler.h"
#include "RequestHandlers/GSSAPIAuthRequestHandler.h"
#include "RequestHandlers/IdentifyRequestHandler.h"
@@ -66,6 +67,7 @@ ConnectionManager::ConnectionManager() {
Common::RequestManager::init(true);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::CoreStatusRequestHandler>(Net::Packet::CORE_STATUS);
+ Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonListRequestHandler>(Net::Packet::LIST_DAEMONS);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::IdentifyRequestHandler>(Net::Packet::IDENTIFY);
@@ -199,5 +201,16 @@ void ConnectionManager::identifyDaemonConnection(Net::Connection *connection, co
std::cerr << "Identified as '" << name << "'." << std::endl;
}
+std::map<std::string,DaemonInfo> ConnectionManager::getDaemonList() const {
+ std::map<std::string,DaemonInfo> ret;
+
+ for(std::map<std::string,Net::ServerConnection*>::const_iterator con = identifiedDaemonConnections.begin(); con != identifiedDaemonConnections.end(); ++con) {
+ if(con->second)
+ ret.insert(std::make_pair(con->first, daemonInfo.at(con->first)));
+ }
+
+ return ret;
+}
+
}
}
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index 6e098b6..ba029ec 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -84,6 +84,7 @@ class ConnectionManager {
Net::Connection* getDaemonConnection(const std::string &name) const;
void identifyDaemonConnection(Net::Connection *connection, const std::string &name);
+ std::map<std::string,DaemonInfo> getDaemonList() const;
};
}
diff --git a/src/Core/RequestHandlers/CoreStatusRequestHandler.h b/src/Core/RequestHandlers/CoreStatusRequestHandler.h
index c6c0da3..c9d3199 100644
--- a/src/Core/RequestHandlers/CoreStatusRequestHandler.h
+++ b/src/Core/RequestHandlers/CoreStatusRequestHandler.h
@@ -17,8 +17,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_CORE_REQUESTHANDLER_CORESTATUSREQUESTHANDLER_H_
-#define MAD_CORE_REQUESTHANDLER_CORESTATUSREQUESTHANDLER_H_
+#ifndef MAD_CORE_REQUESTHANDLERS_CORESTATUSREQUESTHANDLER_H_
+#define MAD_CORE_REQUESTHANDLERS_CORESTATUSREQUESTHANDLER_H_
#include <Common/RequestHandler.h>
@@ -37,4 +37,4 @@ class CoreStatusRequestHandler : public Common::RequestHandler {
}
}
-#endif /* MAD_CORE_REQUESTHANDLER_CORESTATUSREQUESTHANDLER_H_ */
+#endif /* MAD_CORE_REQUESTHANDLERS_CORESTATUSREQUESTHANDLER_H_ */
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
new file mode 100644
index 0000000..00ee0ff
--- /dev/null
+++ b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
@@ -0,0 +1,54 @@
+/*
+ * DaemonListRequestHandler.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "DaemonListRequestHandler.h"
+#include "../ConnectionManager.h"
+#include <Net/Connection.h>
+#include <Net/Packets/NameListPacket.h>
+
+namespace Mad {
+namespace Core {
+namespace RequestHandlers {
+
+bool DaemonListRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(isFinished())
+ return false;
+
+ if(packet.getType() != Net::Packet::LIST_DAEMONS)
+ return false; // TODO Logging
+
+ // TODO Require authentication
+
+ std::map<std::string,DaemonInfo> daemons = ConnectionManager::getConnectionManager()->getDaemonList();
+ std::vector<std::string> names;
+
+ for(std::map<std::string,DaemonInfo>::iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon)
+ names.push_back(daemon->first);
+
+ if(!connection->send(Net::Packets::NameListPacket(Net::Packet::OK, packet.getRequestId(), names)))
+ return false;
+
+ setFinished();
+
+ return true;
+}
+
+}
+}
+}
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.h b/src/Core/RequestHandlers/DaemonListRequestHandler.h
new file mode 100644
index 0000000..406d212
--- /dev/null
+++ b/src/Core/RequestHandlers/DaemonListRequestHandler.h
@@ -0,0 +1,40 @@
+/*
+ * DaemonListRequestHandler.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_
+#define MAD_CORE_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_
+
+#include <Common/RequestHandler.h>
+
+namespace Mad {
+namespace Core {
+namespace RequestHandlers {
+
+class DaemonListRequestHandler : public Common::RequestHandler {
+ public:
+ DaemonListRequestHandler() {}
+
+ virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet);
+};
+
+}
+}
+}
+
+#endif /* MAD_CORE_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_ */
diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
index a88969b..57ea14f 100644
--- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
+++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
@@ -17,8 +17,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_CORE_REQUESTHANDLER_GSSAPIAUTHREQUESTHANDLER_H_
-#define MAD_CORE_REQUESTHANDLER_GSSAPIAUTHREQUESTHANDLER_H_
+#ifndef MAD_CORE_REQUESTHANDLERS_GSSAPIAUTHREQUESTHANDLER_H_
+#define MAD_CORE_REQUESTHANDLERS_GSSAPIAUTHREQUESTHANDLER_H_
#include <Common/RequestHandler.h>
#include <gssapi/gssapi.h>
@@ -43,4 +43,4 @@ class GSSAPIAuthRequestHandler : public Common::RequestHandler {
}
}
-#endif /* MAD_CORE_REQUESTHANDLER_GSSAPIAUTHREQUESTHANDLER_H_ */
+#endif /* MAD_CORE_REQUESTHANDLERS_GSSAPIAUTHREQUESTHANDLER_H_ */
diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am
index c13d0d7..8155a80 100644
--- a/src/Core/RequestHandlers/Makefile.am
+++ b/src/Core/RequestHandlers/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequesthandlers.la
-librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp
+librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp
-noinst_HEADERS = CoreStatusRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h
+noinst_HEADERS = CoreStatusRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h
diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in
index 191fd28..88e1ca3 100644
--- a/src/Core/RequestHandlers/Makefile.in
+++ b/src/Core/RequestHandlers/Makefile.in
@@ -46,8 +46,8 @@ CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequesthandlers_la_LIBADD =
am_librequesthandlers_la_OBJECTS = CoreStatusRequestHandler.lo \
- DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo \
- IdentifyRequestHandler.lo
+ DaemonListRequestHandler.lo DaemonStatusRequestHandler.lo \
+ GSSAPIAuthRequestHandler.lo IdentifyRequestHandler.lo
librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -186,8 +186,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequesthandlers.la
-librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp
-noinst_HEADERS = CoreStatusRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h
+librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp
+noinst_HEADERS = CoreStatusRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h
all: all-am
.SUFFIXES:
@@ -240,6 +240,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CoreStatusRequestHandler.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IdentifyRequestHandler.Plo@am__quote@
diff --git a/src/Net/Packet.h b/src/Net/Packet.h
index e94f2ff..59e794d 100644
--- a/src/Net/Packet.h
+++ b/src/Net/Packet.h
@@ -33,7 +33,8 @@ class Packet {
enum Type {
OK = 0x0000, ERROR = 0x0001, DISCONNECT = 0x0002,
GSSAPI_AUTH = 0x0010, IDENTIFY = 0x0011,
- CORE_STATUS = 0x0020, DAEMON_STATUS = 0x0021
+ LIST_DAEMONS = 0x0020,
+ CORE_STATUS = 0x0030, DAEMON_STATUS = 0x0031
};
struct Data {
diff --git a/src/Net/Packets/HostStatusPacket.h b/src/Net/Packets/HostStatusPacket.h
index f023917..0de63de 100644
--- a/src/Net/Packets/HostStatusPacket.h
+++ b/src/Net/Packets/HostStatusPacket.h
@@ -50,7 +50,6 @@ class HostStatusPacket : public Packet {
}
HostStatusPacket(const HostStatusPacket &p) : Packet(p) {
- setLength(sizeof(CoreStatusData));
coreStatusData = (CoreStatusData*)&rawData->data;
}
diff --git a/src/Net/Packets/Makefile.am b/src/Net/Packets/Makefile.am
index e65e543..9e1f589 100644
--- a/src/Net/Packets/Makefile.am
+++ b/src/Net/Packets/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = libpackets.la
-libpackets_la_SOURCES = HostStatusPacket.cpp
+libpackets_la_SOURCES = HostStatusPacket.cpp NameListPacket.cpp
-noinst_HEADERS = HostStatusPacket.h
+noinst_HEADERS = HostStatusPacket.h NameListPacket.h
diff --git a/src/Net/Packets/Makefile.in b/src/Net/Packets/Makefile.in
index b6a7338..6a7e39f 100644
--- a/src/Net/Packets/Makefile.in
+++ b/src/Net/Packets/Makefile.in
@@ -45,7 +45,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libpackets_la_LIBADD =
-am_libpackets_la_OBJECTS = HostStatusPacket.lo
+am_libpackets_la_OBJECTS = HostStatusPacket.lo NameListPacket.lo
libpackets_la_OBJECTS = $(am_libpackets_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -184,8 +184,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libpackets.la
-libpackets_la_SOURCES = HostStatusPacket.cpp
-noinst_HEADERS = HostStatusPacket.h
+libpackets_la_SOURCES = HostStatusPacket.cpp NameListPacket.cpp
+noinst_HEADERS = HostStatusPacket.h NameListPacket.h
all: all-am
.SUFFIXES:
@@ -238,6 +238,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostStatusPacket.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NameListPacket.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/Net/Packets/NameListPacket.cpp b/src/Net/Packets/NameListPacket.cpp
new file mode 100644
index 0000000..19f588a
--- /dev/null
+++ b/src/Net/Packets/NameListPacket.cpp
@@ -0,0 +1,56 @@
+/*
+ * NameListPacket.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "NameListPacket.h"
+#include <cstring>
+#include <sstream>
+
+namespace Mad {
+namespace Net {
+namespace Packets {
+
+void NameListPacket::assemblePacket() {
+ std::ostringstream stream;
+
+ for(std::vector<std::string>::iterator name = nameList.begin(); name != nameList.end(); ++name)
+ stream << *name << std::endl;
+
+ std::string str = stream.str();
+
+ setLength(str.length());
+ std::memcpy(rawData->data, str.c_str(), str.length());
+}
+
+void NameListPacket::parsePacket() {
+ nameList.clear();
+
+ std::istringstream stream(std::string((char*)getData(), getLength()));
+
+ while(!stream.eof()) {
+ std::string str;
+ std::getline(stream, str);
+
+ if(!str.empty())
+ nameList.push_back(str);
+ }
+}
+
+}
+}
+}
diff --git a/src/Net/Packets/NameListPacket.h b/src/Net/Packets/NameListPacket.h
new file mode 100644
index 0000000..89cc040
--- /dev/null
+++ b/src/Net/Packets/NameListPacket.h
@@ -0,0 +1,65 @@
+/*
+ * NameListPacket.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_NET_PACKETS_NAMELISTPACKET_H_
+#define MAD_NET_PACKETS_NAMELISTPACKET_H_
+
+#include "../Packet.h"
+
+#include <vector>
+#include <string>
+
+
+namespace Mad {
+namespace Net {
+namespace Packets {
+
+class NameListPacket : public Packet {
+ protected:
+ std::vector<std::string> nameList;
+
+ void assemblePacket();
+ void parsePacket();
+
+ public:
+ NameListPacket(Type type, uint16_t requestId, const std::vector<std::string> &nameList0) : Packet(type, requestId), nameList(nameList0) {
+ assemblePacket();
+ }
+
+ NameListPacket(const Packet &p) : Packet(p) {
+ parsePacket();
+ }
+
+ NameListPacket& operator=(const Packet &p) {
+ Packet::operator=(p);
+ parsePacket();
+
+ return *this;
+ }
+
+ const std::vector<std::string>& getNameList() const {
+ return nameList;
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_NET_PACKETS_NAMELISTPACKET_H_ */