From 59143e174f946c66e2e437e32b6f6b28c506115a Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Mon, 2 Aug 2010 03:13:49 +0300
Subject: Fix chat spoofing. Remove colors from nicks in public chat.

Signed-off-by: Chuck Miller <shadowmil@gmail.com>
---
 src/net/tmwa/chathandler.cpp | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

(limited to 'src')

diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp
index 640d04c1..00d29662 100644
--- a/src/net/tmwa/chathandler.cpp
+++ b/src/net/tmwa/chathandler.cpp
@@ -110,7 +110,8 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
             break;
 
         // Received speech from being
-        case SMSG_BEING_CHAT: {
+        case SMSG_BEING_CHAT:
+        {
             chatMsgLength = msg.readInt16() - 8;
             being = beingManager->findBeing(msg.readInt32());
 
@@ -121,24 +122,42 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
 
             std::string::size_type pos = chatMsg.find(" : ", 0);
             std::string sender_name = ((pos == std::string::npos)
-                                       ? ""
-                                       : chatMsg.substr(0, pos));
+                                       ? "" : chatMsg.substr(0, pos));
 
-            // We use getIgnorePlayer instead of ignoringPlayer here because ignorePlayer' side
-            // effects are triggered right below for Being::IGNORE_SPEECH_FLOAT.
-            if (player_relations.checkPermissionSilently(sender_name, PlayerRelation::SPEECH_LOG))
-                localChatTab->chatLog(chatMsg, BY_OTHER);
+            if (sender_name != being->getName()
+                && being->getType() == Being::PLAYER)
+            {
+                if (!being->getName().empty())
+                    sender_name = being->getName();
+            }
+            else
+            {
+                chatMsg.erase(0, pos + 3);
+            }
 
-            chatMsg.erase(0, pos + 3);
             trim(chatMsg);
 
-            if (player_relations.hasPermission(sender_name, PlayerRelation::SPEECH_FLOAT))
+            // We use getIgnorePlayer instead of ignoringPlayer here
+            // because ignorePlayer' side effects are triggered
+            // right below for Being::IGNORE_SPEECH_FLOAT.
+            if (player_relations.checkPermissionSilently(sender_name,
+                PlayerRelation::SPEECH_LOG) && chatWindow)
+            {
+                localChatTab->chatLog(removeColors(sender_name) + " : "
+                                      + chatMsg, BY_OTHER);
+            }
+
+            if (player_relations.hasPermission(sender_name,
+                PlayerRelation::SPEECH_FLOAT))
+            {
                 being->setSpeech(chatMsg, SPEECH_TIME);
+            }
             break;
         }
 
         case SMSG_PLAYER_CHAT:
-        case SMSG_GM_CHAT: {
+        case SMSG_GM_CHAT:
+        {
             chatMsgLength = msg.readInt16() - 4;
 
             if (chatMsgLength <= 0)
-- 
cgit v1.2.3-70-g09d2