anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
regchannel.h (7368B)
1 /* 2 * 3 * (C) 2008-2022 Anope Team 4 * Contact us at team@anope.org 5 * 6 * Please read COPYING and README for further details. 7 */ 8 9 #ifndef REGCHANNEL_H 10 #define REGCHANNEL_H 11 12 #include "memo.h" 13 #include "modes.h" 14 #include "extensible.h" 15 #include "logger.h" 16 #include "modules.h" 17 #include "serialize.h" 18 #include "bots.h" 19 20 typedef Anope::hash_map<ChannelInfo *> registered_channel_map; 21 22 extern CoreExport Serialize::Checker<registered_channel_map> RegisteredChannelList; 23 24 /* AutoKick data. */ 25 class CoreExport AutoKick : public Serializable 26 { 27 public: 28 /* Channel this autokick is on */ 29 Serialize::Reference<ChannelInfo> ci; 30 31 Anope::string mask; 32 Serialize::Reference<NickCore> nc; 33 34 Anope::string reason; 35 Anope::string creator; 36 time_t addtime; 37 time_t last_used; 38 39 AutoKick(); 40 ~AutoKick(); 41 void Serialize(Serialize::Data &data) const anope_override; 42 static Serializable* Unserialize(Serializable *obj, Serialize::Data &); 43 }; 44 45 /* It matters that Base is here before Extensible (it is inherited by Serializable) 46 */ 47 class CoreExport ChannelInfo : public Serializable, public Extensible 48 { 49 /* channels who reference this one */ 50 Anope::map<int> references; 51 private: 52 Serialize::Reference<NickCore> founder; /* Channel founder */ 53 Serialize::Reference<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */ 54 Serialize::Checker<std::vector<ChanAccess *> > access; /* List of authorized users */ 55 Serialize::Checker<std::vector<AutoKick *> > akick; /* List of users to kickban */ 56 Anope::map<int16_t> levels; 57 58 public: 59 friend class ChanAccess; 60 friend class AutoKick; 61 62 Anope::string name; /* Channel name */ 63 Anope::string desc; 64 65 time_t time_registered; 66 time_t last_used; 67 68 Anope::string last_topic; /* The last topic that was set on this channel */ 69 Anope::string last_topic_setter; /* Setter */ 70 time_t last_topic_time; /* Time */ 71 72 Channel::ModeList last_modes; /* The last modes set on this channel */ 73 74 int16_t bantype; 75 76 MemoInfo memos; 77 78 Channel *c; /* Pointer to channel, if the channel exists */ 79 80 /* For BotServ */ 81 Serialize::Reference<BotInfo> bi; /* Bot used on this channel */ 82 83 time_t banexpire; /* Time bans expire in */ 84 85 /** Constructor 86 * @param chname The channel name 87 */ 88 ChannelInfo(const Anope::string &chname); 89 90 /** Copy constructor 91 * @param ci The ChannelInfo to copy settings from 92 */ 93 ChannelInfo(const ChannelInfo &ci); 94 95 ~ChannelInfo(); 96 97 void Serialize(Serialize::Data &data) const anope_override; 98 static Serializable* Unserialize(Serializable *obj, Serialize::Data &); 99 100 /** Change the founder of the channel 101 * @params nc The new founder 102 */ 103 void SetFounder(NickCore *nc); 104 105 /** Get the founder of the channel 106 * @return The founder 107 */ 108 NickCore *GetFounder() const; 109 110 void SetSuccessor(NickCore *nc); 111 NickCore *GetSuccessor() const; 112 113 /** Find which bot should send mode/topic/etc changes for this channel 114 * @return The bot 115 */ 116 BotInfo *WhoSends() const; 117 118 /** Add an entry to the channel access list 119 * @param access The entry 120 */ 121 void AddAccess(ChanAccess *access); 122 123 /** Get an entry from the channel access list by index 124 * 125 * @param index The index in the access list vector 126 * @return A ChanAccess struct corresponding to the index given, or NULL if outside the bounds 127 * 128 * Retrieves an entry from the access list that matches the given index. 129 */ 130 ChanAccess *GetAccess(unsigned index) const; 131 132 /** Retrieve the access for a user or group in the form of a vector of access entries 133 * (as multiple entries can affect a single user). 134 */ 135 AccessGroup AccessFor(const User *u, bool updateLastUsed = true); 136 AccessGroup AccessFor(const NickCore *nc, bool updateLastUsed = true); 137 138 /** Get the size of the access vector for this channel 139 * @return The access vector size 140 */ 141 unsigned GetAccessCount() const; 142 143 /** Get the number of access entries for this channel, 144 * including those that are on other channels. 145 */ 146 unsigned GetDeepAccessCount() const; 147 148 /** Erase an entry from the channel access list 149 * 150 * @param index The index in the access list vector 151 * 152 * @return The erased entry 153 */ 154 ChanAccess *EraseAccess(unsigned index); 155 156 /** Clear the entire channel access list 157 * 158 * Clears the entire access list by deleting every item and then clearing the vector. 159 */ 160 void ClearAccess(); 161 162 /** Add an akick entry to the channel by NickCore 163 * @param user The user who added the akick 164 * @param akicknc The nickcore being akicked 165 * @param reason The reason for the akick 166 * @param t The time the akick was added, defaults to now 167 * @param lu The time the akick was last used, defaults to never 168 */ 169 AutoKick* AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); 170 171 /** Add an akick entry to the channel by reason 172 * @param user The user who added the akick 173 * @param mask The mask of the akick 174 * @param reason The reason for the akick 175 * @param t The time the akick was added, defaults to now 176 * @param lu The time the akick was last used, defaults to never 177 */ 178 AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); 179 180 /** Get an entry from the channel akick list 181 * @param index The index in the akick vector 182 * @return The akick structure, or NULL if not found 183 */ 184 AutoKick* GetAkick(unsigned index) const; 185 186 /** Get the size of the akick vector for this channel 187 * @return The akick vector size 188 */ 189 unsigned GetAkickCount() const; 190 191 /** Erase an entry from the channel akick list 192 * @param index The index of the akick 193 */ 194 void EraseAkick(unsigned index); 195 196 /** Clear the whole akick list 197 */ 198 void ClearAkick(); 199 200 /** Get the level entries for the channel. 201 * @return The levels for the channel. 202 */ 203 const Anope::map<int16_t> &GetLevelEntries(); 204 205 /** Get the level for a privilege 206 * @param priv The privilege name 207 * @return the level 208 * @throws CoreException if priv is not a valid privilege 209 */ 210 int16_t GetLevel(const Anope::string &priv) const; 211 212 /** Set the level for a privilege 213 * @param priv The privilege priv 214 * @param level The new level 215 */ 216 void SetLevel(const Anope::string &priv, int16_t level); 217 218 /** Remove a privilege from the channel 219 * @param priv The privilege 220 */ 221 void RemoveLevel(const Anope::string &priv); 222 223 /** Clear all privileges from the channel 224 */ 225 void ClearLevels(); 226 227 /** Gets a ban mask for the given user based on the bantype 228 * of the channel. 229 * @param u The user 230 * @return A ban mask that affects the user 231 */ 232 Anope::string GetIdealBan(User *u) const; 233 234 /** Finds a ChannelInfo 235 * @param name channel name to lookup 236 * @return the ChannelInfo associated with the channel 237 */ 238 static ChannelInfo* Find(const Anope::string &name); 239 240 void AddChannelReference(const Anope::string &what); 241 void RemoveChannelReference(const Anope::string &what); 242 void GetChannelReferences(std::deque<Anope::string> &chans); 243 }; 244 245 /** Is the user the real founder? 246 * @param user The user 247 * @param ci The channel 248 * @return true or false 249 */ 250 extern CoreExport bool IsFounder(const User *user, const ChannelInfo *ci); 251 252 #endif // REGCHANNEL_H