summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Petithory <vincent.petithory@gmail.com>2014-07-09 23:45:28 +0200
committerAndrei Karas <akaras@inbox.ru>2014-07-19 18:21:02 +0300
commitcf351788fe4326ea04936d63c612465c16f85e1e (patch)
tree0e383aa6cd2b1957467e31571f87e88442b82ebe /src
parentae9190b3f9a372f0bdf48b863f7b8e58f655ae3d (diff)
downloadmanaplus-cf351788fe4326ea04936d63c612465c16f85e1e.tar.gz
manaplus-cf351788fe4326ea04936d63c612465c16f85e1e.tar.bz2
manaplus-cf351788fe4326ea04936d63c612465c16f85e1e.tar.xz
manaplus-cf351788fe4326ea04936d63c612465c16f85e1e.zip
IPC: remove message typesr; forward raw string to chatInput
Diffstat (limited to 'src')
-rw-r--r--src/net/ipc.cpp47
1 files changed, 9 insertions, 38 deletions
diff --git a/src/net/ipc.cpp b/src/net/ipc.cpp
index 4fb9bd058..531ce4435 100644
--- a/src/net/ipc.cpp
+++ b/src/net/ipc.cpp
@@ -26,15 +26,10 @@
#include "utils/stringutils.h"
#include <iostream>
-#include "commandhandler.h"
#include "logger.h"
IPC *ipc = nullptr;
-const std::string IPC_TYPE_CMD = "CMD";
-const std::string IPC_TYPE_TALK = "TALK";
-const std::string IPC_TYPE_LTALK = "LTALK";
-
IPC::IPC(unsigned short port) :
mListen(false),
mNumReqs(0),
@@ -95,7 +90,7 @@ int IPC::acceptLoop(void *ptr)
sock = SDLNet_TCP_Accept(ipc->mSocket);
if (!sock)
{
- logger->log("IPC: unable to accept connection");
+ logger->log_r("IPC: unable to accept connection");
continue;
}
char data[max_length] = {0};
@@ -103,42 +98,18 @@ int IPC::acceptLoop(void *ptr)
result = SDLNet_TCP_Recv(sock, data, max_length);
if (result <= 0)
{
- logger->log("IPC: unable to accept connection");
+ logger->log_r("IPC: unable to accept connection");
SDLNet_TCP_Close(sock);
continue;
}
- // Parse input: TYPE args
- const std::string req(data);
- const size_t pos = req.find(' ');
- const std::string type(req, 0, pos);
- std::string args(req, pos == std::string::npos
- ? req.size() : pos + 1);
- args = trim(args);
-
+ std::string req(data);
+ req = trim(req);
+
std::string resp;
- if (type == IPC_TYPE_CMD)
- {
- commandHandler->handleCommand(args, debugChatTab);
- ipc->mNumReqs++;
- resp = strprintf("[%s](%d) OK\n", IPC_TYPE_CMD.c_str(), ipc->mNumReqs);
- }
- else if (type == IPC_TYPE_LTALK)
- {
- chatWindow->localChatInput(args);
- ipc->mNumReqs++;
- resp = strprintf("[%s](%d) OK\n", IPC_TYPE_LTALK.c_str(), ipc->mNumReqs);
- }
- else if (type == IPC_TYPE_TALK)
- {
- chatWindow->chatInput(args);
- ipc->mNumReqs++;
- resp = strprintf("[%s](%d) OK\n", IPC_TYPE_TALK.c_str(), ipc->mNumReqs);
- }
- else
- {
- resp = type + ": no handler for this IPC type\n";
- }
+ chatWindow->chatInput(req);
+ ipc->mNumReqs++;
+ resp = strprintf("[%d] %s\n", ipc->mNumReqs, req.c_str());
int len;
const char *respc;
@@ -147,7 +118,7 @@ int IPC::acceptLoop(void *ptr)
result = SDLNet_TCP_Send(sock, respc, len);
if (result < len)
{
- logger->log("IPC: SDLNet_TCP_Send: %s\n", SDLNet_GetError());
+ logger->log_r("IPC: SDLNet_TCP_Send: %s\n", SDLNet_GetError());
SDLNet_TCP_Close(sock);
continue;
}