summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-08-04 22:22:40 -0600
committerJared Adams <jaxad0127@gmail.com>2010-08-05 01:04:58 -0600
commitdd1463241c00f38de5855b9e9869b773f683373f (patch)
treea5ceea8ccfded6f48214021bc7481a98b81abebc
parent154ea41225505eee0c77652a04738d845a2e93cd (diff)
downloadmana-dd1463241c00f38de5855b9e9869b773f683373f.tar.gz
mana-dd1463241c00f38de5855b9e9869b773f683373f.tar.bz2
mana-dd1463241c00f38de5855b9e9869b773f683373f.tar.xz
mana-dd1463241c00f38de5855b9e9869b773f683373f.zip
Have Being manage speech creation and add permissions to events
The Being and Player Chat events now have the precomuted permissions for SPEECH_LOG and SPEECH_FLOAT. The Being class now acts on those events to show speech (if SPEECH_FLOAT is present). ChatWindow now checks for the SPEECH_LOG permission. Reviewed-by: Freeyorp
-rw-r--r--src/being.cpp21
-rw-r--r--src/being.h5
-rw-r--r--src/gui/chat.cpp4
-rw-r--r--src/localplayer.cpp2
-rw-r--r--src/localplayer.h3
-rw-r--r--src/net/manaserv/chathandler.cpp5
-rw-r--r--src/net/tmwa/chathandler.cpp42
7 files changed, 59 insertions, 23 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 344636a5..9be5986c 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -26,6 +26,7 @@
#include "client.h"
#include "configuration.h"
#include "effectmanager.h"
+#include "event.h"
#include "graphics.h"
#include "guild.h"
#include "localplayer.h"
@@ -33,6 +34,7 @@
#include "map.h"
#include "particle.h"
#include "party.h"
+#include "playerrelations.h"
#include "simpleanimation.h"
#include "sound.h"
#include "sprite.h"
@@ -114,6 +116,7 @@ Being::Being(int id, Type type, int subtype, Map *map):
setShowName(true);
updateColors();
+ listen("Chat");
}
Being::~Being()
@@ -1198,3 +1201,21 @@ void Being::talkTo()
{
Net::getNpcHandler()->talk(mId);
}
+
+void Being::event(const std::string &channel, const Mana::Event &event)
+{
+ if (channel == "Chat" &&
+ (event.getName() == "Being" || event.getName() == "Player") &&
+ event.getInt("permissions") & PlayerRelation::SPEECH_FLOAT)
+ {
+ try
+ {
+ if (mId == event.getInt("beingId"))
+ {
+ setSpeech(event.getString("text"));
+ }
+ }
+ catch (Mana::BadEvent badEvent)
+ {}
+ }
+}
diff --git a/src/being.h b/src/being.h
index a379bdaa..a55e2d3a 100644
--- a/src/being.h
+++ b/src/being.h
@@ -24,6 +24,7 @@
#include "actorsprite.h"
#include "configlistener.h"
+#include "listener.h"
#include "map.h"
#include "particlecontainer.h"
#include "position.h"
@@ -62,7 +63,7 @@ enum Gender
GENDER_UNSPECIFIED = 2
};
-class Being : public ActorSprite, public ConfigListener
+class Being : public ActorSprite, public ConfigListener, public Mana::Listener
{
public:
/**
@@ -493,6 +494,8 @@ class Being : public ActorSprite, public ConfigListener
void talkTo();
+ void event(const std::string &channel, const Mana::Event &event);
+
protected:
/**
* Sets the new path for this being.
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index ba912276..b1d4b131 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -25,6 +25,7 @@
#include "configuration.h"
#include "localplayer.h"
#include "party.h"
+#include "playerrelations.h"
#include "gui/recorder.h"
#include "gui/setup.h"
@@ -439,7 +440,8 @@ void ChatWindow::event(const std::string &channel, const Mana::Event &event)
}
else if (event.getName() == "Being")
{
- localChatTab->chatLog(event.getString("message"), BY_OTHER);
+ if (event.getInt("permissions") & PlayerRelation::SPEECH_LOG)
+ localChatTab->chatLog(event.getString("message"), BY_OTHER);
}
}
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 7034cf31..53648725 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -1109,6 +1109,8 @@ void LocalPlayer::event(const std::string &channel, const Mana::Event &event)
}
}
}
+ else
+ Being::event(channel, event);
}
void LocalPlayer::changeAwayMode()
diff --git a/src/localplayer.h b/src/localplayer.h
index 14ab5482..2fb93e9b 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -49,8 +49,7 @@ class AwayListener : public gcn::ActionListener
/**
* The local player character.
*/
-class LocalPlayer : public Being, public ActorSpriteListener,
- public Mana::Listener
+class LocalPlayer : public Being, public ActorSpriteListener
{
public:
/**
diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp
index 9a8f6e34..71e4efde 100644
--- a/src/net/manaserv/chathandler.cpp
+++ b/src/net/manaserv/chathandler.cpp
@@ -27,6 +27,7 @@
#include "channel.h"
#include "channelmanager.h"
#include "eventmanager.h"
+#include "playerrelations.h"
#include "gui/widgets/channeltab.h"
@@ -158,7 +159,6 @@ void ChatHandler::handleGameChatMessage(Net::MessageIn &msg)
if (being)
{
mes = being->getName() + " : " + chatMsg;
- being->setSpeech(chatMsg, SPEECH_TIME);
}
else
mes = "Unknown : " + chatMsg;
@@ -168,6 +168,9 @@ void ChatHandler::handleGameChatMessage(Net::MessageIn &msg)
event.setString("text", chatMsg);
event.setString("nick", being->getName());
event.setInt("beingId", id);
+ event.setInt("permissions", player_relations
+ .checkPermissionSilently(being->getName(),
+ PlayerRelation::SPEECH_LOG | PlayerRelation::SPEECH_FLOAT));
Mana::EventManager::trigger("Chat", event);
}
diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp
index b3400528..a5d7f337 100644
--- a/src/net/tmwa/chathandler.cpp
+++ b/src/net/tmwa/chathandler.cpp
@@ -155,28 +155,33 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
chatMsg.erase(0, pos + 3);
}
+ int perms;
+
+ if (being->getType() == Being::PLAYER)
+ {
+ perms = player_relations.checkPermissionSilently(sender_name,
+ PlayerRelation::SPEECH_LOG | PlayerRelation::SPEECH_FLOAT);
+ }
+ else
+ {
+ perms = player_relations.getDefault()
+ & (PlayerRelation::SPEECH_LOG
+ | PlayerRelation::SPEECH_FLOAT);
+ }
+
trim(chatMsg);
std::string reducedMessage = chatMsg;
chatMsg = removeColors(sender_name) + " : " + reducedMessage;
- // 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))
- {
- Mana::Event event("Being");
- event.setString("message", chatMsg);
- event.setString("text", reducedMessage);
- event.setString("nick", sender_name);
- event.setInt("beingId", beingId);
- Mana::EventManager::trigger("Chat", event);
- }
+ Mana::Event event("Being");
+ event.setString("message", chatMsg);
+ event.setString("text", reducedMessage);
+ event.setString("nick", sender_name);
+ event.setInt("beingId", beingId);
+ event.setInt("permissions", perms);
+ Mana::EventManager::trigger("Chat", event);
- if (player_relations.hasPermission(sender_name,
- PlayerRelation::SPEECH_FLOAT))
- {
- being->setSpeech(chatMsg, SPEECH_TIME);
- }
break;
}
@@ -205,9 +210,10 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
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));
Mana::EventManager::trigger("Chat", event);
-
- player_node->setSpeech(chatMsg, SPEECH_TIME);
}
else
{