summaryrefslogtreecommitdiff
path: root/src/net/tmwa/chathandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tmwa/chathandler.cpp')
-rw-r--r--src/net/tmwa/chathandler.cpp122
1 files changed, 82 insertions, 40 deletions
diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp
index 00d29662..97304c28 100644
--- a/src/net/tmwa/chathandler.cpp
+++ b/src/net/tmwa/chathandler.cpp
@@ -21,14 +21,13 @@
#include "net/tmwa/chathandler.h"
+#include "actorspritemanager.h"
#include "being.h"
-#include "beingmanager.h"
+#include "event.h"
#include "game.h"
#include "localplayer.h"
#include "playerrelations.h"
-#include "gui/widgets/chattab.h"
-
#include "net/messagein.h"
#include "net/messageout.h"
@@ -45,7 +44,7 @@ namespace TmwAthena {
ChatHandler::ChatHandler()
{
- static const Uint16 _messages[] = {
+ static const uint16_t _messages[] = {
SMSG_BEING_CHAT,
SMSG_PLAYER_CHAT,
SMSG_WHISPER,
@@ -60,8 +59,6 @@ ChatHandler::ChatHandler()
void ChatHandler::handleMessage(Net::MessageIn &msg)
{
- if (!localChatTab) return;
-
Being *being;
std::string chatMsg;
std::string nick;
@@ -70,19 +67,36 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
switch (msg.getId())
{
case SMSG_WHISPER_RESPONSE:
+ if (mSentWhispers.empty())
+ nick = "user";
+ else
+ {
+ nick = mSentWhispers.front();
+ mSentWhispers.pop();
+ }
+
switch (msg.readInt8())
{
case 0x00:
- // comment out since we'll local echo in chat.cpp instead, then only report failures
- //localChatTab->chatLog("Whisper sent", BY_SERVER);
+ // Success (don't need to report)
break;
case 0x01:
- localChatTab->chatLog(_("Whisper could not be sent, user "
- "is offline."), BY_SERVER);
+ {
+ Event event(Event::WhisperError);
+ event.setString("nick", nick);
+ event.setString("error", strprintf(_("Whisper could "
+ "not be sent, %s is offline."), nick.c_str()));
+ event.trigger(Event::ChatChannel);
+ }
break;
case 0x02:
- localChatTab->chatLog(_("Whisper could not be sent, "
- "ignored by user."), BY_SERVER);
+ {
+ Event event(Event::WhisperError);
+ event.setString("nick", nick);
+ event.setString("error", strprintf(_("Whisper could "
+ "not be sent, ignored by %s."), nick.c_str()));
+ event.Event::trigger(Event::ChatChannel);
+ }
break;
}
break;
@@ -100,11 +114,16 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
if (nick != "Server")
{
if (player_relations.hasPermission(nick, PlayerRelation::WHISPER))
- chatWindow->whisper(nick, chatMsg);
+ {
+ Event event(Event::Whisper);
+ event.setString("nick", nick);
+ event.setString("message", chatMsg);
+ event.trigger(Event::ChatChannel);
+ }
}
else
{
- localChatTab->chatLog(chatMsg, BY_SERVER);
+ SERVER_NOTICE(chatMsg)
}
break;
@@ -113,7 +132,8 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
case SMSG_BEING_CHAT:
{
chatMsgLength = msg.readInt16() - 8;
- being = beingManager->findBeing(msg.readInt32());
+ int beingId = msg.readInt32();
+ being = actorSpriteManager->findBeing(beingId);
if (!being || chatMsgLength <= 0)
break;
@@ -135,23 +155,33 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
chatMsg.erase(0, pos + 3);
}
- trim(chatMsg);
+ int perms;
- // 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)
+ if (being->getType() == Being::PLAYER)
{
- localChatTab->chatLog(removeColors(sender_name) + " : "
- + chatMsg, BY_OTHER);
+ perms = player_relations.checkPermissionSilently(sender_name,
+ PlayerRelation::SPEECH_LOG | PlayerRelation::SPEECH_FLOAT);
}
-
- if (player_relations.hasPermission(sender_name,
- PlayerRelation::SPEECH_FLOAT))
+ else
{
- being->setSpeech(chatMsg, SPEECH_TIME);
+ perms = player_relations.getDefault()
+ & (PlayerRelation::SPEECH_LOG
+ | PlayerRelation::SPEECH_FLOAT);
}
+
+ trim(chatMsg);
+
+ std::string reducedMessage = chatMsg;
+ chatMsg = removeColors(sender_name) + " : " + reducedMessage;
+
+ Event event(Event::Being);
+ event.setString("message", chatMsg);
+ event.setString("text", reducedMessage);
+ event.setString("nick", sender_name);
+ event.setInt("beingId", beingId);
+ event.setInt("permissions", perms);
+ event.trigger(Event::ChatChannel);
+
break;
}
@@ -164,22 +194,32 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
break;
chatMsg = msg.readString(chatMsgLength);
- std::string::size_type pos = chatMsg.find(" : ", 0);
if (msg.getId() == SMSG_PLAYER_CHAT)
{
- localChatTab->chatLog(chatMsg, BY_PLAYER);
+ std::string::size_type pos = chatMsg.find(" : ", 0);
+ std::string mes = chatMsg;
if (pos != std::string::npos)
chatMsg.erase(0, pos + 3);
trim(chatMsg);
- player_node->setSpeech(chatMsg, SPEECH_TIME);
+ Event event(Event::Player);
+ event.setString("message", mes);
+ event.setString("text", chatMsg);
+ event.setString("nick", player_node->getName());
+ event.setInt("beingId", player_node->getId());
+ event.setInt("permissions", player_relations.getDefault()
+ & (PlayerRelation::SPEECH_LOG
+ | PlayerRelation::SPEECH_FLOAT));
+ event.trigger(Event::ChatChannel);
}
else
{
- localChatTab->chatLog(chatMsg, BY_GM);
+ Event event(Event::Announcement);
+ event.setString("message", chatMsg);
+ event.trigger(Event::ChatChannel);
}
break;
}
@@ -187,7 +227,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
case SMSG_MVP:
// Display MVP player
msg.readInt32(); // id
- localChatTab->chatLog(_("MVP player."), BY_SERVER);
+ SERVER_NOTICE(_("MVP player."))
break;
}
}
@@ -216,47 +256,49 @@ void ChatHandler::privateMessage(const std::string &recipient,
outMsg.writeInt16(text.length() + 28);
outMsg.writeString(recipient, 24);
outMsg.writeString(text, text.length());
+
+ mSentWhispers.push(recipient);
}
void ChatHandler::channelList()
{
- localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
+ SERVER_NOTICE(_("Channels are not supported!"))
}
void ChatHandler::enterChannel(const std::string &channel,
const std::string &password)
{
- localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
+ SERVER_NOTICE(_("Channels are not supported!"))
}
void ChatHandler::quitChannel(int channelId)
{
- localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
+ SERVER_NOTICE(_("Channels are not supported!"))
}
void ChatHandler::sendToChannel(int channelId, const std::string &text)
{
- localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
+ SERVER_NOTICE(_("Channels are not supported!"))
}
void ChatHandler::userList(const std::string &channel)
{
- localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
+ SERVER_NOTICE(_("Channels are not supported!"))
}
void ChatHandler::setChannelTopic(int channelId, const std::string &text)
{
- localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
+ SERVER_NOTICE(_("Channels are not supported!"))
}
void ChatHandler::setUserMode(int channelId, const std::string &name, int mode)
{
- localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
+ SERVER_NOTICE(_("Channels are not supported!"))
}
void ChatHandler::kickUser(int channelId, const std::string &name)
{
- localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
+ SERVER_NOTICE(_("Channels are not supported!"))
}
void ChatHandler::who()