summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/beinghandler.cpp6
-rw-r--r--src/net/chathandler.cpp43
-rw-r--r--src/net/tradehandler.cpp15
-rw-r--r--src/net/tradehandler.h18
4 files changed, 40 insertions, 42 deletions
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp
index 4c77523a..959a4972 100644
--- a/src/net/beinghandler.cpp
+++ b/src/net/beinghandler.cpp
@@ -36,6 +36,7 @@
#include "../main.h"
#include "../particle.h"
#include "../sound.h"
+#include "../player_relations.h"
const int EMOTION_TIME = 150; /**< Duration of emotion icon */
@@ -245,8 +246,9 @@ void BeingHandler::handleMessage(MessageIn *msg)
break;
}
- dstBeing->mEmotion = msg->readInt8();
- dstBeing->mEmotionTime = EMOTION_TIME;
+ if (player_relations.hasPermission(dstBeing, PlayerRelation::EMOTE))
+ dstBeing->setEmote(msg->readInt8(), EMOTION_TIME);
+
break;
case SMSG_BEING_CHANGE_LOOKS:
diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp
index d2e1361e..524911d3 100644
--- a/src/net/chathandler.cpp
+++ b/src/net/chathandler.cpp
@@ -32,6 +32,7 @@
#include "../being.h"
#include "../beingmanager.h"
#include "../game.h"
+#include "../player_relations.h"
#include "../gui/chat.h"
@@ -40,6 +41,8 @@
extern Being *player_node;
+#define SERVER_NAME "Server"
+
ChatHandler::ChatHandler()
{
static const Uint16 _messages[] = {
@@ -89,14 +92,20 @@ void ChatHandler::handleMessage(MessageIn *msg)
break;
chatMsg = msg->readString(chatMsgLength);
- if (nick != "Server")
+ if (nick != SERVER_NAME)
chatMsg = nick + " : " + chatMsg;
- chatWindow->chatLog(chatMsg, (nick == "Server") ? BY_SERVER : ACT_WHISPER);
+
+ if (nick == SERVER_NAME)
+ chatWindow->chatLog(chatMsg, BY_SERVER);
+ else {
+ if (player_relations.hasPermission(nick, PlayerRelation::WHISPER))
+ chatWindow->chatLog(chatMsg, ACT_WHISPER);
+ }
break;
// Received speech from being
- case SMSG_BEING_CHAT:
+ case SMSG_BEING_CHAT: {
chatMsgLength = msg->readInt16() - 8;
being = beingManager->findBeing(msg->readInt32());
@@ -106,14 +115,27 @@ void ChatHandler::handleMessage(MessageIn *msg)
}
chatMsg = msg->readString(chatMsgLength);
- chatWindow->chatLog(chatMsg, BY_OTHER);
- chatMsg.erase(0, chatMsg.find(" : ", 0) + 3);
+
+ std::string::size_type pos = chatMsg.find(" : ", 0);
+ std::string sender_name = ((pos == std::string::npos)
+ ? ""
+ : 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))
+ chatWindow->chatLog(chatMsg, BY_OTHER);
+
+ chatMsg.erase(0, pos + 3);
trim(chatMsg);
- being->setSpeech(chatMsg, SPEECH_TIME);
+
+ 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)
@@ -122,17 +144,17 @@ void ChatHandler::handleMessage(MessageIn *msg)
}
chatMsg = msg->readString(chatMsgLength);
+ std::string::size_type pos = chatMsg.find(" : ", 0);
if (msg->getId() == SMSG_PLAYER_CHAT)
{
chatWindow->chatLog(chatMsg, BY_PLAYER);
- std::string::size_type pos = chatMsg.find(" : ", 0);
if (pos != std::string::npos)
- {
chatMsg.erase(0, pos + 3);
- }
+
trim(chatMsg);
+
player_node->setSpeech(chatMsg, SPEECH_TIME);
}
else
@@ -140,6 +162,7 @@ void ChatHandler::handleMessage(MessageIn *msg)
chatWindow->chatLog(chatMsg, BY_GM);
}
break;
+ }
case SMSG_WHO_ANSWER:
chatWindow->chatLog("Online users: " + toString(msg->readInt32()),
diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp
index 57060684..9b3c590e 100644
--- a/src/net/tradehandler.cpp
+++ b/src/net/tradehandler.cpp
@@ -28,6 +28,7 @@
#include "../item.h"
#include "../localplayer.h"
+#include "../player_relations.h"
#include "../gui/chat.h"
#include "../gui/confirm_dialog.h"
@@ -48,8 +49,7 @@ namespace {
} listener;
}
-TradeHandler::TradeHandler():
- mAcceptTradeRequests(true)
+TradeHandler::TradeHandler()
{
static const Uint16 _messages[] = {
SMSG_TRADE_REQUEST,
@@ -64,15 +64,6 @@ TradeHandler::TradeHandler():
handledMessages = _messages;
}
-void TradeHandler::setAcceptTradeRequests(bool acceptTradeRequests)
-{
- mAcceptTradeRequests = acceptTradeRequests;
- if (mAcceptTradeRequests) {
- chatWindow->chatLog("Accepting incoming trade requests", BY_SERVER);
- } else {
- chatWindow->chatLog("Ignoring incoming trade requests", BY_SERVER);
- }
-}
void TradeHandler::handleMessage(MessageIn *msg)
{
@@ -87,7 +78,7 @@ void TradeHandler::handleMessage(MessageIn *msg)
// special message about the player being occupied.
tradePartnerName = msg->readString(24);
- if (mAcceptTradeRequests)
+ if (player_relations.hasPermission(tradePartnerName, PlayerRelation::TRADE))
{
if (!player_node->tradeRequestOk())
{
diff --git a/src/net/tradehandler.h b/src/net/tradehandler.h
index 00f2cf38..a1971004 100644
--- a/src/net/tradehandler.h
+++ b/src/net/tradehandler.h
@@ -34,24 +34,6 @@ class TradeHandler : public MessageHandler
TradeHandler();
void handleMessage(MessageIn *msg);
-
- /**
- * Returns whether trade requests are accepted.
- *
- * @see setAcceptTradeRequests
- */
- bool acceptTradeRequests() const
- { return mAcceptTradeRequests; }
-
- /**
- * Sets whether trade requests are accepted. When set to false, trade
- * requests are automatically denied. When true, a popup will ask the
- * player whether he wants to trade.
- */
- void setAcceptTradeRequests(bool acceptTradeRequests);
-
- private:
- bool mAcceptTradeRequests;
};
#endif