From cf351788fe4326ea04936d63c612465c16f85e1e Mon Sep 17 00:00:00 2001 From: Vincent Petithory Date: Wed, 9 Jul 2014 23:45:28 +0200 Subject: IPC: remove message typesr; forward raw string to chatInput --- src/net/ipc.cpp | 47 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) (limited to 'src') 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 -#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; } -- cgit v1.2.3-60-g2f50