00001 /* 00002 * The Mana World 00003 * Copyright (C) 2008 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #ifndef PLAYER_RELATIONS_H 00023 #define PLAYER_RELATIONS_H 00024 00025 #include <list> 00026 #include <map> 00027 #include <string> 00028 #include <vector> 00029 00030 class Being; 00031 class Player; 00032 00033 struct PlayerRelation 00034 { 00035 static const unsigned int EMOTE = (1 << 0); 00036 static const unsigned int SPEECH_FLOAT = (1 << 1); 00037 static const unsigned int SPEECH_LOG = (1 << 2); 00038 static const unsigned int WHISPER = (1 << 3); 00039 static const unsigned int TRADE = (1 << 4); 00040 00041 static const unsigned int RELATIONS_NR = 4; 00042 static const unsigned int RELATION_PERMISSIONS[RELATIONS_NR]; 00043 00044 static const unsigned int DEFAULT = EMOTE 00045 | SPEECH_FLOAT 00046 | SPEECH_LOG 00047 | WHISPER 00048 | TRADE; 00049 enum Relation { 00050 NEUTRAL = 0, 00051 FRIEND = 1, 00052 DISREGARDED = 2, 00053 IGNORED = 3 00054 }; 00055 00056 PlayerRelation(Relation relation); 00057 00058 Relation mRelation; // bitmask for all of the above 00059 }; 00060 00061 00065 class PlayerIgnoreStrategy 00066 { 00067 public: 00068 std::string mDescription; 00069 std::string mShortName; 00070 00071 virtual ~PlayerIgnoreStrategy() {} 00072 00076 virtual void ignore(Player *player, unsigned int flags) = 0; 00077 }; 00078 00079 class PlayerRelationsListener 00080 { 00081 public: 00082 PlayerRelationsListener() { } 00083 virtual ~PlayerRelationsListener() { } 00084 00085 virtual void updatedPlayer(const std::string &name) = 0; 00086 }; 00087 00093 class PlayerRelationsManager 00094 { 00095 public: 00096 PlayerRelationsManager(); 00097 ~PlayerRelationsManager(); 00098 00102 void init(); 00103 00107 void load(); 00108 00112 void store(); 00113 00118 unsigned int checkPermissionSilently(const std::string &player_name, 00119 unsigned int flags); 00120 00126 bool hasPermission(Being *being, unsigned int flags); 00127 00128 bool hasPermission(const std::string &being, unsigned int flags); 00129 00133 void setRelation(const std::string &name, 00134 PlayerRelation::Relation relation); 00135 00139 PlayerRelation::Relation getRelation(const std::string &name); 00140 00144 void removePlayer(const std::string &name); 00145 00149 unsigned int getDefault() const; 00150 00154 void setDefault(unsigned int permissions); 00155 00162 std::vector<PlayerIgnoreStrategy *> *getPlayerIgnoreStrategies(); 00163 00169 PlayerIgnoreStrategy *getPlayerIgnoreStrategy() const 00170 { 00171 return mIgnoreStrategy; 00172 } 00173 00177 void setPlayerIgnoreStrategy(PlayerIgnoreStrategy *strategy) 00178 { 00179 mIgnoreStrategy = strategy; 00180 } 00181 00189 int getPlayerIgnoreStrategyIndex(const std::string &shortname); 00190 00195 std::vector<std::string> *getPlayers(); 00196 00200 void clear(); 00201 00205 bool getPersistIgnores() const { return mPersistIgnores; } 00206 00212 void setPersistIgnores(bool value) { mPersistIgnores = value; } 00213 00214 void addListener(PlayerRelationsListener *listener) 00215 { 00216 mListeners.push_back(listener); 00217 } 00218 00219 void removeListener(PlayerRelationsListener *listener) 00220 { 00221 mListeners.remove(listener); 00222 } 00223 00224 private: 00225 void signalUpdate(const std::string &name); 00226 00227 bool mPersistIgnores; // If NOT set, we delete the ignored data upon reloading 00228 unsigned int mDefaultPermissions; 00229 00230 PlayerIgnoreStrategy *mIgnoreStrategy; 00231 std::map<std::string, PlayerRelation *> mRelations; 00232 std::list<PlayerRelationsListener *> mListeners; 00233 std::vector<PlayerIgnoreStrategy *> mIgnoreStrategies; 00234 }; 00235 00236 00237 extern PlayerRelationsManager player_relations; // singleton representation of player relations 00238 00239 00240 #endif /* !defined(PLAYER_RELATIONS_H) */