summaryrefslogtreecommitdiffstats
path: root/resource/listener.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'resource/listener.cpp')
-rw-r--r--resource/listener.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/resource/listener.cpp b/resource/listener.cpp
index f5920b7..da1edc3 100644
--- a/resource/listener.cpp
+++ b/resource/listener.cpp
@@ -1,6 +1,7 @@
1#include "listener.h" 1#include "listener.h"
2 2
3#include "common/console.h" 3#include "common/console.h"
4#include "common/commands.h"
4 5
5#include <QLocalSocket> 6#include <QLocalSocket>
6#include <QTimer> 7#include <QTimer>
@@ -106,9 +107,37 @@ void Listener::readFromSocket()
106 if (client.socket == socket) { 107 if (client.socket == socket) {
107 Console::main()->log(QString(" Client: %1").arg(client.name)); 108 Console::main()->log(QString(" Client: %1").arg(client.name));
108 client.commandBuffer += socket->readAll(); 109 client.commandBuffer += socket->readAll();
109 Console::main()->log(QString(" Command: %1").arg(QString(client.commandBuffer))); 110 processClientBuffer(client);
110 break; 111 break;
111 } 112 }
112 } 113 }
114}
113 115
116void Listener::processClientBuffer(Client &client)
117{
118 static const int headerSize = (sizeof(int) * 2);
119 Console::main()->log(QString("processing %1").arg(client.commandBuffer.size()));
120 if (client.commandBuffer.size() < headerSize) {
121 return;
122 }
123
124 int commandId, size;
125 commandId = *(int*)client.commandBuffer.constData();
126 size = *(int*)(client.commandBuffer.constData() + sizeof(int));
127
128 if (size <= client.commandBuffer.size() - headerSize) {
129 QByteArray data = client.commandBuffer.mid(headerSize, size);
130 client.commandBuffer.remove(0, headerSize + size);
131
132 switch (commandId) {
133 case Commands::HandshakeCommand:
134 client.name = data;
135 Console::main()->log(QString(" Handshake from %1").arg(client.name));
136 //TODO: reply?
137 break;
138 default:
139 // client.hasSentCommand = true;
140 break;
141 }
142 }
114} 143}