summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Common/Request/DisconnectRequest.h4
-rw-r--r--src/Common/Request/IdentifyRequest.h (renamed from src/Common/Request/PingRequest.h)26
-rw-r--r--src/Common/Request/Makefile.am2
-rw-r--r--src/Common/Request/Makefile.in2
-rw-r--r--src/Common/RequestManager.cpp15
-rw-r--r--src/Net/Packet.h4
-rw-r--r--src/madc.cpp4
7 files changed, 29 insertions, 28 deletions
diff --git a/src/Common/Request/DisconnectRequest.h b/src/Common/Request/DisconnectRequest.h
index 9023c13..77509a0 100644
--- a/src/Common/Request/DisconnectRequest.h
+++ b/src/Common/Request/DisconnectRequest.h
@@ -48,7 +48,7 @@ class DisconnectRequest: public Request {
if(isSent())
return false;
- if(!connection->send(Net::Packet(Net::Packet::TYPE_DISCONNECT_REQ, requestId)))
+ if(!connection->send(Net::Packet(Net::Packet::TYPE_DISCONNECT, requestId)))
return false;
setSent();
@@ -59,7 +59,7 @@ class DisconnectRequest: public Request {
if(isFinished())
return false;
- if(packet.getType() != Net::Packet::TYPE_DISCONNECT_REP)
+ if(packet.getType() != Net::Packet::TYPE_OK)
return false; // TODO Logging
connection->disconnect();
diff --git a/src/Common/Request/PingRequest.h b/src/Common/Request/IdentifyRequest.h
index 92e3c1a..9df1548 100644
--- a/src/Common/Request/PingRequest.h
+++ b/src/Common/Request/IdentifyRequest.h
@@ -1,5 +1,5 @@
/*
- * PingRequest.h
+ * IdentifyRequest.h
*
* Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
*
@@ -17,13 +17,14 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_COMMON_REQUEST_PINGREQUEST_H_
-#define MAD_COMMON_REQUEST_PINGREQUEST_H_
+#ifndef IDENTIFYREQUEST_H_
+#define IDENTIFYREQUEST_H_
#include "Request.h"
#include "../RequestManager.h"
#include <Net/Connection.h>
#include <Net/Packet.h>
+#include <string>
#include <iostream>
@@ -31,13 +32,15 @@ namespace Mad {
namespace Common {
namespace Request {
-class PingRequest : public Request {
+class IdentifyRequest: public Request {
private:
- PingRequest() {}
+ IdentifyRequest(const std::string &hostname0) : hostname(hostname0) {}
+
+ std::string hostname;
public:
- static bool send(Net::Connection *connection, RequestManager &requestManager) {
- Request *request = new PingRequest();
+ static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0) {
+ Request *request = new IdentifyRequest(hostname0);
if(requestManager.sendRequest(connection, request))
return true;
@@ -50,7 +53,7 @@ class PingRequest : public Request {
if(isSent())
return false;
- if(!connection->send(Net::Packet(Net::Packet::TYPE_PING, requestId)))
+ if(!connection->send(Net::Packet(Net::Packet::TYPE_IDENTIFY_REQ, requestId, hostname.c_str(), hostname.length())))
return false;
setSent();
@@ -61,11 +64,10 @@ class PingRequest : public Request {
if(isFinished())
return false;
- if(packet.getType() != Net::Packet::TYPE_PONG)
+ if(packet.getType() != Net::Packet::TYPE_IDENTIFY_REP)
return false; // TODO Logging
- std::cout << "Received ping reply." << std::endl;
- std::cout << " Request ID: " << packet.getRequestId() << std::endl;
+ std::cout << "Identified as '" << hostname << "'." << std::endl;
setFinished();
return true;
@@ -76,4 +78,4 @@ class PingRequest : public Request {
}
}
-#endif /* MAD_COMMON_REQUEST_PINGREQUEST_H_ */
+#endif /* IDENTIFYREQUEST_H_ */
diff --git a/src/Common/Request/Makefile.am b/src/Common/Request/Makefile.am
index 17e47fe..a7de050 100644
--- a/src/Common/Request/Makefile.am
+++ b/src/Common/Request/Makefile.am
@@ -1 +1 @@
-noinst_HEADERS = DisconnectRequest.h PingRequest.h Request.h
+noinst_HEADERS = DisconnectRequest.h IdentifyRequest.h Request.h
diff --git a/src/Common/Request/Makefile.in b/src/Common/Request/Makefile.in
index d96c0a7..9c48118 100644
--- a/src/Common/Request/Makefile.in
+++ b/src/Common/Request/Makefile.in
@@ -162,7 +162,7 @@ sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-noinst_HEADERS = DisconnectRequest.h PingRequest.h Request.h
+noinst_HEADERS = DisconnectRequest.h IdentifyRequest.h Request.h
all: all-am
.SUFFIXES:
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index 86d3529..755f59b 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -47,16 +47,15 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack
}
switch(packet.getType()) {
- case Net::Packet::TYPE_PING:
- std::cout << "Received ping request." << std::endl;
- std::cout << " Request ID: " << packet.getRequestId() << std::endl;
-
- connection->send(Net::Packet(Net::Packet::TYPE_PONG, packet.getRequestId(), packet.getData(), packet.getLength()));
- break;
- case Net::Packet::TYPE_DISCONNECT_REQ:
- connection->send(Net::Packet(Net::Packet::TYPE_DISCONNECT_REP, packet.getRequestId()));
+ case Net::Packet::TYPE_DISCONNECT:
+ connection->send(Net::Packet(Net::Packet::TYPE_OK, packet.getRequestId()));
connection->disconnect();
break;
+ case Net::Packet::TYPE_IDENTIFY_REQ:
+ std::cout << "Received identify request from '" << std::string((char*)packet.getData(), packet.getLength()) << "'." << std::endl;
+
+ connection->send(Net::Packet(Net::Packet::TYPE_IDENTIFY_REP, packet.getRequestId(), packet.getData(), packet.getLength()));
+ break;
default:
std::cerr << "Received an unexpected packet." << std::endl;
}
diff --git a/src/Net/Packet.h b/src/Net/Packet.h
index c867ffa..2d2fb77 100644
--- a/src/Net/Packet.h
+++ b/src/Net/Packet.h
@@ -29,8 +29,8 @@ namespace Net {
class Packet {
public:
enum Type {
- TYPE_PING = 0x0000, TYPE_PONG = 0x0001,
- TYPE_DISCONNECT_REQ = 0x0010, TYPE_DISCONNECT_REP = 0x0011
+ TYPE_OK = 0x0000, TYPE_ERROR = 0x0001, TYPE_DISCONNECT = 0x0002,
+ TYPE_IDENTIFY_REQ = 0x0010, TYPE_IDENTIFY_REP = 0x0011
};
struct Data {
diff --git a/src/madc.cpp b/src/madc.cpp
index f987a9d..9609e56 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -22,7 +22,7 @@
#include "Net/Packet.h"
#include "Common/RequestManager.h"
#include "Common/Request/DisconnectRequest.h"
-#include "Common/Request/PingRequest.h"
+#include "Common/Request/IdentifyRequest.h"
#include <iostream>
int main() {
@@ -43,7 +43,7 @@ int main() {
requestManager.registerConnection(connection);
- Mad::Common::Request::PingRequest::send(connection, requestManager);
+ Mad::Common::Request::IdentifyRequest::send(connection, requestManager, "test");
Mad::Common::Request::DisconnectRequest::send(connection, requestManager);
while(connection->isConnected()) {