3
* Copyright (C) 2008-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#ifndef BEING_PLAYERRELATIONS_H
24
#define BEING_PLAYERRELATIONS_H
26
#include "utils/stringvector.h"
31
#include "localconsts.h"
35
struct PlayerRelation final
37
static const unsigned int EMOTE = (1 << 0);
38
static const unsigned int SPEECH_FLOAT = (1 << 1);
39
static const unsigned int SPEECH_LOG = (1 << 2);
40
static const unsigned int WHISPER = (1 << 3);
41
static const unsigned int TRADE = (1 << 4);
42
static const unsigned int INVISIBLE = (1 << 5);
43
static const unsigned int BLACKLIST = (1 << 6);
44
static const unsigned int ENEMY = (1 << 7);
46
static const unsigned int RELATIONS_NR = 7;
47
static const unsigned int RELATION_PERMISSIONS[RELATIONS_NR];
49
static const unsigned int DEFAULT = EMOTE
65
explicit PlayerRelation(const Relation relation);
67
A_DELETE_COPY(PlayerRelation)
69
Relation mRelation; // bitmask for all of the above
74
* Ignore strategy: describes how we should handle ignores.
76
class PlayerIgnoreStrategy
79
std::string mDescription;
80
std::string mShortName;
82
PlayerIgnoreStrategy() :
88
A_DELETE_COPY(PlayerIgnoreStrategy)
90
virtual ~PlayerIgnoreStrategy()
94
* Handle the ignoring of the indicated action by the indicated player.
96
virtual void ignore(Being *const being,
97
const unsigned int flags) const = 0;
100
class PlayerRelationsListener
103
PlayerRelationsListener()
106
virtual ~PlayerRelationsListener()
109
virtual void updatedPlayer(const std::string &name) = 0;
111
virtual void updateAll() = 0;
115
* Player relations class, represents any particular relations and/or
116
* preferences the user of the local client has wrt other players (identified
119
class PlayerRelationsManager final
122
PlayerRelationsManager();
124
A_DELETE_COPY(PlayerRelationsManager)
126
~PlayerRelationsManager();
129
* Initialise player relations manager (load config file etc.)
134
* Load configuration from our config file, or substitute defaults.
136
void load(const bool oldConfig = false);
139
* Save configuration to our config file.
144
* Determines whether the player in question is being ignored, filtered by
145
* the specified flags.
147
unsigned int checkPermissionSilently(const std::string &player_name,
148
const unsigned int flags)
152
* Tests whether the player in question is being ignored for any of the
153
* actions in the specified flags. If so, trigger appropriate side effects
154
* if requested by the player.
156
bool hasPermission(const Being *const being,
157
const unsigned int flags) const A_WARN_UNUSED;
159
bool hasPermission(const std::string &being,
160
const unsigned int flags) const A_WARN_UNUSED;
163
* Updates the relationship with this player.
165
void setRelation(const std::string &name,
166
const PlayerRelation::Relation relation);
169
* Updates the relationship with this player.
171
PlayerRelation::Relation getRelation(const std::string &name)
175
* Deletes the information recorded for a player.
177
void removePlayer(const std::string &name);
180
* Retrieves the default permissions.
182
unsigned int getDefault() const A_WARN_UNUSED;
185
* Sets the default permissions.
187
void setDefault(const unsigned int permissions);
190
* Retrieves all known player ignore strategies.
192
* The player ignore strategies are allocated statically and must
195
std::vector<PlayerIgnoreStrategy *> *getPlayerIgnoreStrategies()
199
* Return the current player ignore strategy.
201
* \return A player ignore strategy, or nullptr
203
const PlayerIgnoreStrategy *getPlayerIgnoreStrategy() const
205
{ return mIgnoreStrategy; }
208
* Sets the strategy to call when ignoring players.
210
void setPlayerIgnoreStrategy(PlayerIgnoreStrategy *const strategy)
211
{ mIgnoreStrategy = strategy; }
214
* For a given ignore strategy short name, find the appropriate index
215
* in the ignore strategies vector.
217
* \param The short name of the ignore strategy to look up
218
* \return The appropriate index, or -1
220
int getPlayerIgnoreStrategyIndex(const std::string &shortname)
224
* Retrieves a sorted vector of all players for which we have any
225
* relations recorded.
227
StringVect *getPlayers() const A_WARN_UNUSED;
229
StringVect *getPlayersByRelation(const PlayerRelation::Relation rel)
233
* Removes all recorded player info.
238
* Do we persist our `ignore' setup?
240
bool getPersistIgnores() const
241
{ return mPersistIgnores; }
243
void ignoreTrade(const std::string &name);
245
bool isGoodName(Being *const being) const A_WARN_UNUSED;
247
bool isGoodName(const std::string &name) const A_WARN_UNUSED;
250
* Change the `ignore persist' flag.
252
* @param value Whether to persist ignores
254
void setPersistIgnores(const bool value)
255
{ mPersistIgnores = value; }
257
void addListener(PlayerRelationsListener *const listener)
258
{ mListeners.push_back(listener); }
260
void removeListener(PlayerRelationsListener *const listener)
261
{ mListeners.remove(listener); }
263
bool checkBadRelation(const std::string &name) const A_WARN_UNUSED;
266
void signalUpdate(const std::string &name);
268
bool mPersistIgnores; // If NOT set, we delete the
269
// ignored data upon reloading
270
unsigned int mDefaultPermissions;
272
bool checkName(const std::string &name) const A_WARN_UNUSED;
274
PlayerIgnoreStrategy *mIgnoreStrategy;
275
std::map<std::string, PlayerRelation *> mRelations;
276
std::list<PlayerRelationsListener *> mListeners;
277
std::vector<PlayerIgnoreStrategy *> mIgnoreStrategies;
281
extern PlayerRelationsManager player_relations; // singleton representation
282
// of player relations
285
#endif // BEING_PLAYERRELATIONS_H