diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-29 22:25:04 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-29 22:25:04 +0200 |
commit | 13fd1bb4f19e4791e000cb71cca2065820184bdb (patch) | |
tree | 147254923044d6842a803b20b48ed607e76fa28d /src/Client/InformationManager.cpp | |
parent | 07768a871691433e2f3c490aa14c45cde40e00b4 (diff) | |
download | mad-13fd1bb4f19e4791e000cb71cca2065820184bdb.tar mad-13fd1bb4f19e4791e000cb71cca2065820184bdb.zip |
Daemon-Liste wird jetzt vom Core aktualisiert
Diffstat (limited to 'src/Client/InformationManager.cpp')
-rw-r--r-- | src/Client/InformationManager.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index 3a8caab..8a3227c 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -21,6 +21,8 @@ #include "Requests/DaemonListRequest.h" #include <Common/Logger.h> #include <Common/RequestManager.h> +#include <Net/Packets/ErrorPacket.h> +#include <Net/Packets/HostStatePacket.h> namespace Mad { @@ -28,12 +30,44 @@ namespace Client { std::auto_ptr<InformationManager> InformationManager::informationManager; + +void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::DAEMON_STATE_UPDATE) { + Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + signalFinished().emit(); + return; + } + + // TODO Require authentication + + Net::Packets::HostStatePacket hostStatePacket(packet); + + std::map<std::string, Common::HostInfo>::iterator host = informationManager->daemons.find(hostStatePacket.getName()); + if(host != informationManager->daemons.end()) + host->second.setState(hostStatePacket.getState()); + else + Common::Logger::log(Common::Logger::WARNING, "Received a state update for an unknown host."); + + connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())); + + signalFinished().emit(); +} + + InformationManager::InformationManager(Net::Connection *connection) : initFinished(false) { Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>( new Requests::DaemonListRequest(sigc::mem_fun(this, &InformationManager::daemonListRequestFinished)) ) ); + + Common::RequestManager::getRequestManager()->registerPacketType<DaemonStateUpdateRequest>(Net::Packet::DAEMON_STATE_UPDATE); +} + +InformationManager::~InformationManager() { + Common::RequestManager::getRequestManager()->unregisterPacketType(Net::Packet::DAEMON_STATE_UPDATE); } void InformationManager::daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request) { |