ManaPlus
playerrelations.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef BEING_PLAYERRELATIONS_H
25 #define BEING_PLAYERRELATIONS_H
26 
27 #include "utils/stringvector.h"
28 
29 #include "enums/being/relation.h"
30 
31 #include <list>
32 #include <map>
33 
34 #include "localconsts.h"
35 
36 class Being;
39 
40 struct PlayerRelation;
41 
48 {
49  public:
51 
53 
55 
59  void init();
60 
64  void load();
65 
69  void store() const;
70 
75  unsigned int checkPermissionSilently(const std::string &player_name,
76  const unsigned int flags)
77  const A_WARN_UNUSED;
78 
84  bool hasPermission(const Being *const being,
85  const unsigned int flags) const A_WARN_UNUSED;
86 
87  bool hasPermission(const std::string &being,
88  const unsigned int flags) const A_WARN_UNUSED;
89 
93  void setRelation(const std::string &name,
94  const RelationT relation);
95 
99  RelationT getRelation(const std::string &name) const A_WARN_UNUSED;
100 
104  void removePlayer(const std::string &name);
105 
109  unsigned int getDefault() const A_WARN_UNUSED;
110 
114  void setDefault(const unsigned int permissions);
115 
122  STD_VECTOR<PlayerIgnoreStrategy *> *getPlayerIgnoreStrategies()
124 
131  noexcept2
133  { return mIgnoreStrategy; }
134 
139  noexcept2
140  { mIgnoreStrategy = strategy; }
141 
149  int getPlayerIgnoreStrategyIndex(const std::string &shortname)
151 
157 
159  const A_WARN_UNUSED;
160 
164  void clear();
165 
170  { return mPersistIgnores; }
171 
172  void ignoreTrade(const std::string &name) const;
173 
174  bool isGoodName(Being *const being) const A_WARN_UNUSED;
175 
176  bool isGoodName(const std::string &name) const A_WARN_UNUSED;
177 
183  void setPersistIgnores(const bool value) noexcept2
184  { mPersistIgnores = value; }
185 
187  { mListeners.push_back(listener); }
188 
190  { mListeners.remove(listener); }
191 
192  bool checkBadRelation(const std::string &name) const A_WARN_UNUSED;
193 
194  private:
195  void signalUpdate(const std::string &name);
196 
197  bool mPersistIgnores; // If NOT set, we delete the
198  // ignored data upon reloading
199  unsigned int mDefaultPermissions;
200 
201  static bool checkName(const std::string &name) A_WARN_UNUSED;
202 
204  std::map<std::string, PlayerRelation *> mRelations;
205  std::list<PlayerRelationsListener *> mListeners;
206  STD_VECTOR<PlayerIgnoreStrategy *> mIgnoreStrategies;
207 };
208 
209 
210 extern PlayerRelationsManager playerRelations; // singleton representation
211  // of player relations
212 
213 
214 #endif // BEING_PLAYERRELATIONS_H
Definition: being.h:96
unsigned int mDefaultPermissions
StringVect * getPlayers() const
void setDefault(const unsigned int permissions)
void setPlayerIgnoreStrategy(PlayerIgnoreStrategy *const strategy)
void addListener(PlayerRelationsListener *const listener)
bool isGoodName(Being *const being) const
void setPersistIgnores(const bool value)
std::vector< PlayerIgnoreStrategy * > mIgnoreStrategies
PlayerIgnoreStrategy * mIgnoreStrategy
StringVect * getPlayersByRelation(const RelationT rel) const
void removeListener(PlayerRelationsListener *const listener)
std::vector< PlayerIgnoreStrategy * > * getPlayerIgnoreStrategies()
unsigned int getDefault() const
static bool checkName(const std::string &name)
void ignoreTrade(const std::string &name) const
RelationT getRelation(const std::string &name) const
void signalUpdate(const std::string &name)
bool hasPermission(const Being *const being, const unsigned int flags) const
bool checkBadRelation(const std::string &name) const
bool getPersistIgnores() const
int getPlayerIgnoreStrategyIndex(const std::string &shortname)
std::map< std::string, PlayerRelation * > mRelations
const PlayerIgnoreStrategy * getPlayerIgnoreStrategy() const
unsigned int checkPermissionSilently(const std::string &player_name, const unsigned int flags) const
void removePlayer(const std::string &name)
std::list< PlayerRelationsListener * > mListeners
void setRelation(const std::string &name, const RelationT relation)
#define RETURNS_NONNULL
Definition: localconsts.h:167
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
PlayerRelationsManager playerRelations
Relation ::T RelationT
Definition: relation.h:39
std::vector< std::string > StringVect
Definition: stringvector.h:29