Mana
Loading...
Searching...
No Matches
playerrelations.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2008-2009 The Mana World Development Team
4 * Copyright (C) 2009-2024 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <list>
25#include <map>
26#include <string>
27#include <vector>
28
29class Being;
30
32{
33 Neutral = 0,
34 Friend = 1,
35 Disregarded = 2,
36 Ignored = 3
37};
38constexpr unsigned int RELATIONS_NR = 4;
39
41{
42 // Used as flags
43 enum {
44 EMOTE = 1 << 0,
45 SPEECH_FLOAT = 1 << 1,
46 SPEECH_LOG = 1 << 2,
47 WHISPER = 1 << 3,
48 TRADE = 1 << 4,
49
51 };
52};
53
54static constexpr const char *DEFAULT_IGNORE_STRATEGY = "nop";
55
60{
61public:
62 std::string mDescription;
63 std::string mShortName;
64
65 virtual ~PlayerIgnoreStrategy() = default;
66
70 virtual void ignore(Being *being, unsigned int flags) = 0;
71};
72
74{
75public:
77 virtual ~PlayerRelationsListener() = default;
78
79 virtual void playerRelationsUpdated() = 0;
80};
81
88{
89public:
92
96 void init();
97
101 void store();
102
107 unsigned int checkPermissionSilently(const std::string &player_name,
108 unsigned int flags);
109
115 bool hasPermission(Being *being, unsigned int flags);
116
117 bool hasPermission(const std::string &being, unsigned int flags);
118
122 void setRelation(const std::string &name, PlayerRelation relation);
123
127 PlayerRelation getRelation(const std::string &name) const;
128
132 void removePlayer(const std::string &name);
133
137 unsigned int getDefault() const;
138
142 void setDefault(unsigned int permissions);
143
147 std::vector<PlayerIgnoreStrategy *> &getPlayerIgnoreStrategies();
148
158
163 {
164 mIgnoreStrategy = strategy;
165 }
166
174 int getPlayerIgnoreStrategyIndex(const std::string &shortName);
175
180 std::vector<std::string> getPlayers() const;
181
183 {
184 mListeners.push_back(listener);
185 }
186
188 {
189 mListeners.remove(listener);
190 }
191
192private:
193 void signalUpdate();
194
196 std::map<std::string, PlayerRelation> mRelations;
197 std::list<PlayerRelationsListener *> mListeners;
198 std::vector<PlayerIgnoreStrategy *> mIgnoreStrategies;
199};
200
201
202extern PlayerRelationsManager player_relations; // singleton representation of player relations
Definition being.h:65
Ignore strategy: describes how we should handle ignores.
virtual void ignore(Being *being, unsigned int flags)=0
Handle the ignoring of the indicated action by the indicated player.
virtual ~PlayerIgnoreStrategy()=default
PlayerRelationsListener()=default
virtual void playerRelationsUpdated()=0
virtual ~PlayerRelationsListener()=default
Player relations class, represents any particular relations and/or preferences the user of the local ...
void store()
Save configuration to our config file.
std::vector< PlayerIgnoreStrategy * > mIgnoreStrategies
PlayerIgnoreStrategy * mIgnoreStrategy
void init()
Initialise player relations manager (load config file etc.)
std::vector< std::string > getPlayers() const
Retrieves a sorted vector of all players for which we have any relations recorded.
PlayerRelationsManager()=default
PlayerRelation getRelation(const std::string &name) const
Updates the relationship with this player.
std::map< std::string, PlayerRelation > mRelations
unsigned int getDefault() const
Retrieves the default permissions.
bool hasPermission(Being *being, unsigned int flags)
Tests whether the player in question is being ignored for any of the actions in the specified flags.
void removeListener(PlayerRelationsListener *listener)
void addListener(PlayerRelationsListener *listener)
std::vector< PlayerIgnoreStrategy * > & getPlayerIgnoreStrategies()
Retrieves all known player ignore strategies.
void setDefault(unsigned int permissions)
Sets the default permissions.
PlayerIgnoreStrategy * getPlayerIgnoreStrategy() const
Return the current player ignore strategy.
int getPlayerIgnoreStrategyIndex(const std::string &shortName)
For a given ignore strategy short name, find the appropriate index in the ignore strategies vector.
void setPlayerIgnoreStrategy(PlayerIgnoreStrategy *strategy)
Sets the strategy to call when ignoring players.
void setRelation(const std::string &name, PlayerRelation relation)
Updates the relationship with this player.
void removePlayer(const std::string &name)
Deletes the information recorded for a player.
unsigned int checkPermissionSilently(const std::string &player_name, unsigned int flags)
Determines whether the player in question is being ignored, filtered by the specified flags.
std::list< PlayerRelationsListener * > mListeners
PlayerRelation
constexpr unsigned int RELATIONS_NR
PlayerRelationsManager player_relations