summaryrefslogtreecommitdiffstats
path: root/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core/RequestHandlers/IdentifyRequestHandler.cpp')
-rw-r--r--src/Core/RequestHandlers/IdentifyRequestHandler.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/Core/RequestHandlers/IdentifyRequestHandler.cpp b/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
index 48fccf2..4e65aca 100644
--- a/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
+++ b/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
@@ -19,26 +19,37 @@
#include "IdentifyRequestHandler.h"
#include "../ConnectionManager.h"
+#include <Common/Exception.h>
#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
+
+#include <iostream>
+
namespace Mad {
namespace Core {
namespace RequestHandlers {
-bool IdentifyRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::IDENTIFY)
- return false; // TODO Logging
+void IdentifyRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::IDENTIFY) {
+ std::cerr << "Received an unexpected packet." << std::endl;
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
- // TODO Require authentication
+ signalFinished().emit();
+ return;
+ }
- ConnectionManager::getConnectionManager()->identifyDaemonConnection(connection, std::string((const char*)packet.getData(), packet.getLength()));
+ // TODO Require authentication
+ try {
+ ConnectionManager::getConnectionManager()->identifyDaemonConnection(connection, std::string((const char*)packet.getData(), packet.getLength()));
- if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())))
- return false;
+ connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()));
+ }
+ catch(Common::Exception &e) {
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e));
+ }
signalFinished().emit();
-
- return true;
}
}