summaryrefslogtreecommitdiff
path: root/src/net/chathandler.cpp~
diff options
context:
space:
mode:
authorHello=) <hello@themanaworld.org>2024-03-28 03:58:45 +0300
committerHello=) <hello@themanaworld.org>2024-03-28 03:58:45 +0300
commitdb0b1da0060f5eb4b2af040c22ea9373d36970af (patch)
treedc2bdc0478c341bf4368fee4993c20e52f2d41c1 /src/net/chathandler.cpp~
downloadguildbot-db0b1da0060f5eb4b2af040c22ea9373d36970af.tar.gz
guildbot-db0b1da0060f5eb4b2af040c22ea9373d36970af.tar.bz2
guildbot-db0b1da0060f5eb4b2af040c22ea9373d36970af.tar.xz
guildbot-db0b1da0060f5eb4b2af040c22ea9373d36970af.zip
Initial commit of Guild Bot, as seen in:
$ sha256sum guildsrc.zip ef61469ab59ce3f5dd3289505e89bd5b84e3a82b89cda90d25ae3c41f7464beb guildsrc.zip Verification shown its source 100% match to currently running version on TMWA. The following changes were made VS version found in guildsrc.zip: 1) src/build and src/dist content completely removed. Rationale: build-time artifacts; binaries contained login/password. 2) Executable flag (+x) removed from src/automation.cpp and src/main.cpp. Rationale: executable CPP sources are weird thing. No change to file content. 3) src/main.cpp changes: 3 lines: std::string main_username = "test"; std::string main_pw = "test"; std::string main_host = "127.0.0.1"; Rationale: avoid leaking real production credentials and ensure experimenters dont hammer real TMW prod server by experiments. Effort been made to preserve original file timestamps, etc. However toplevel src/ dir date adjusted to date of mentioned changes.
Diffstat (limited to 'src/net/chathandler.cpp~')
-rw-r--r--src/net/chathandler.cpp~147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/net/chathandler.cpp~ b/src/net/chathandler.cpp~
new file mode 100644
index 0000000..cb4c32c
--- /dev/null
+++ b/src/net/chathandler.cpp~
@@ -0,0 +1,147 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: chathandler.cpp 2112 2006-01-22 13:31:13Z der_doener $
+ */
+
+#include "chathandler.h"
+
+#include <SDL_types.h>
+#include <string>
+#include <sstream>
+#include <iostream>
+
+#include "messagein.h"
+#include "protocol.h"
+#include "messageout.h"
+#include "../automation.h"
+#include "../game.h"
+#include "../utils/stringutils.h"
+#include "../log.h"
+#include "nethandler.h"
+
+ChatHandler::ChatHandler()
+{
+ static const Uint16 _messages[] = {
+ SMSG_BEING_CHAT,
+ SMSG_PLAYER_CHAT,
+ SMSG_WHISPER,
+ SMSG_WHISPER_RESPONSE,
+ SMSG_GM_CHAT,
+ 0
+ };
+ handledMessages = _messages;
+}
+
+void ChatHandler::handleMessage(MessageIn *msg)
+{
+ //Being *being;
+ std::string chatMsg;
+ std::stringstream ss;
+ Sint16 chatMsgLength;
+
+ switch (msg->getId())
+ {
+ // Received speech from being
+ case SMSG_BEING_CHAT:
+ {
+
+ chatMsgLength = msg->readInt16() - 8;
+ msg->readInt32();
+
+ if (chatMsgLength <= 0)
+ break;
+
+ chatMsg = msg->readString(chatMsgLength);
+
+ std::string::size_type pos = chatMsg.find(" : ", 0);
+ std::string sender_name = ((pos == std::string::npos)
+ ? ""
+ : chatMsg.substr(0, pos));
+
+ std::string mess = chatMsg.substr(pos+3);
+ // do something with chat
+ break;
+ }
+ case SMSG_WHISPER:
+ {
+ chatMsgLength = msg->readInt16() - 28;
+ std::string nick = msg->readString(24);
+
+ if (chatMsgLength <= 0)
+ break;
+
+ chatMsg = msg->readString(chatMsgLength);
+ Automation::getAutomationHandler()->commandHandler(chatMsg, nick);
+
+ break;
+ }
+ case SMSG_WHISPER_RESPONSE:
+ {
+ int type = msg->readInt8();
+ switch (type)
+ {
+ case 0x00:
+ break;
+ case 0x01:
+ //logger->log("Whisper could not be sent, user is offline.");
+ break;
+ case 0x02:
+ //logger->log("Whisper could not be sent, ignored by user.");
+ break;
+ default:
+ /*if (logger)
+ logger->log("Unkown Whisper Response.");*/
+ break;
+ }
+ break;
+ }
+ case SMSG_PLAYER_CHAT:
+ case SMSG_GM_CHAT:
+ {
+ chatMsgLength = msg->readInt16() - 4;
+
+ if (chatMsgLength <= 0)
+ {
+ break;
+ }
+
+ chatMsg = msg->readString(chatMsgLength);
+
+ if (msg->getId() == SMSG_PLAYER_CHAT)
+ {
+
+ std::string::size_type pos = chatMsg.find(" : ", 0);
+ if (pos != std::string::npos)
+ {
+ chatMsg.erase(0, pos + 3);
+ }
+ //player_node->setSpeech(chatMsg, SPEECH_TIME);
+ }
+ else
+ {
+ //chatWindow->chatLog(chatMsg, BY_GM);
+ }
+ break;
+ }
+
+
+ }
+} \ No newline at end of file