regchannel.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * (C) 2008-2013 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  */
00009 
00010 #ifndef REGCHANNEL_H
00011 #define REGCHANNEL_H
00012 
00013 #include "memo.h"
00014 #include "modes.h"
00015 #include "extensible.h"
00016 #include "logger.h"
00017 #include "modules.h"
00018 #include "serialize.h"
00019 #include "bots.h"
00020 
00021 typedef Anope::hash_map<ChannelInfo *> registered_channel_map;
00022 
00023 extern CoreExport Serialize::Checker<registered_channel_map> RegisteredChannelList;
00024 
00025 /* Indices for TTB (Times To Ban) */
00026 enum
00027 {
00028         TTB_BOLDS,
00029         TTB_COLORS,
00030         TTB_REVERSES,
00031         TTB_UNDERLINES,
00032         TTB_BADWORDS,
00033         TTB_CAPS,
00034         TTB_FLOOD,
00035         TTB_REPEAT,
00036         TTB_ITALICS,
00037         TTB_AMSGS,
00038         TTB_SIZE
00039 };
00040 
00043 enum BadWordType
00044 {
00045         /* Always kicks if the word is said */
00046         BW_ANY,
00047         /* User must way the entire word */
00048         BW_SINGLE,
00049         /* The word has to start with the badword */
00050         BW_START,
00051         /* The word has to end with the badword */
00052         BW_END
00053 };
00054 
00055 /* Structure used to contain bad words. */
00056 struct CoreExport BadWord : Serializable
00057 {
00058         Serialize::Reference<ChannelInfo> ci;
00059         Anope::string word;
00060         BadWordType type;
00061 
00062         BadWord();
00063         ~BadWord();
00064         void Serialize(Serialize::Data &data) const anope_override;
00065         static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
00066 };
00067 
00068 /* AutoKick data. */
00069 class CoreExport AutoKick : public Serializable
00070 {
00071  public:
00072         /* Channel this autokick is on */
00073         Serialize::Reference<ChannelInfo> ci;
00074 
00075         Anope::string mask;
00076         Serialize::Reference<NickCore> nc;
00077 
00078         Anope::string reason;
00079         Anope::string creator;
00080         time_t addtime;
00081         time_t last_used;
00082 
00083         AutoKick();
00084         ~AutoKick();
00085         void Serialize(Serialize::Data &data) const anope_override;
00086         static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
00087 };
00088 
00089 struct CoreExport ModeLock : Serializable
00090 {
00091  public:
00092         Serialize::Reference<ChannelInfo> ci;
00093         bool set;
00094         Anope::string name;
00095         Anope::string param;
00096         Anope::string setter;
00097         time_t created;
00098 
00099         ModeLock(ChannelInfo *ch, bool s, const Anope::string &n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime);
00100         ~ModeLock();
00101 
00102         void Serialize(Serialize::Data &data) const anope_override;
00103         static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
00104 };
00105 
00106 struct CoreExport LogSetting : Serializable
00107 {
00108         Serialize::Reference<ChannelInfo> ci;
00109         /* Our service name of the command */
00110         Anope::string service_name;
00111         /* The name of the client the command is on */
00112         Anope::string command_service;
00113         /* Name of the command to the user, can have spaces */
00114         Anope::string command_name;
00115         Anope::string method, extra;
00116         Anope::string creator;
00117         time_t created;
00118 
00119         LogSetting() : Serializable("LogSetting") { }
00120         void Serialize(Serialize::Data &data) const anope_override;
00121         static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
00122 };
00123 
00124 /* It matters that Base is here before Extensible (it is inherited by Serializable)
00125  *
00126  * Possible flags:
00127  *     TOPICLOCK      - Topic can only be changed by TOPIC SET
00128  *     RESTRICTED     - Only users on the access list may join
00129  *     PEACE          - Don't allow ChanServ and BotServ commands to do bad things to users with higher access levels
00130  *     SECURE         - Don't allow any privileges
00131  *     NO_EXPIRE      - Channel does not expire
00132  *     MEMO_HARDMAX   - Channel memo limit may not be changed
00133  *     SECUREFOUNDER  - Stricter control of channel founder status
00134  *     SIGNKICK       - Sign kicks with the user who did the kick
00135  *     SIGNKICK_LEVEL - Sign kicks if level is < than the one defined by the SIGNKICK level
00136  *     SUSPENDED      - Channel is suepended
00137  *     PERSIST        - Channel still exists when empited (perm channel mode or leaving a botserv bot).
00138  *     STATS          - Chanstats are enabled
00139  *     NOAUTOOP       - If set users are not auto given any status on join
00140  *
00141  * BotServ flags:
00142  *     BS_DONTKICKOPS     - BotServ won't kick ops
00143  *     BS_DONTKICKVOICES  - BotServ won't kick voices
00144  *     BS_FANTASY         - BotServ bot accepts fantasy commands
00145  *     BS_GREET           - BotServ should show greets
00146  *     BS_NOBOT           - BotServ bots are not allowed to be in this channel
00147  *     BS_KICK_BOLDS      - BotServ kicks for bolds
00148  *     BS_KICK_COLORS     - BotServ kicks for colors
00149  *     BS_KICK_REVERSES   - BotServ kicks for reverses
00150  *     BS_KICK_UNDERLINES - BotServ kicks for underlines
00151  *     BS_KICK_BADWORD    - BotServ kicks for badwords
00152  *     BS_KICK_CAPS       - BotServ kicks for caps
00153  *     BS_KICK_FLOOD      - BotServ kicks for flood
00154  *     BS_KICK_REPEAT     - BotServ kicks for repeating
00155  *     BS_KICK_ITALICS    - BotServ kicks for italics
00156  *     BS_KICK_AMSGS      - BotServ kicks for amsgs
00157  */
00158 class CoreExport ChannelInfo : public Serializable, public Extensible
00159 {
00160  private:
00161         Serialize::Reference<NickCore> founder;                                 /* Channel founder */
00162         Serialize::Reference<NickCore> successor;                               /* Who gets the channel if the founder nick is dropped or expires */
00163         Serialize::Checker<std::vector<ChanAccess *> > access;                  /* List of authorized users */
00164         Serialize::Checker<std::vector<AutoKick *> > akick;                     /* List of users to kickban */
00165         Serialize::Checker<std::vector<BadWord *> > badwords;                   /* List of badwords */
00166         std::map<Anope::string, int16_t> levels;
00167 
00168  public:
00169         friend class ChanAccess;
00170         friend class AutoKick;
00171         friend struct BadWord;
00172 
00173         typedef std::multimap<Anope::string, ModeLock *> ModeList;
00174         Serialize::Checker<ModeList> mode_locks;
00175         Serialize::Checker<std::vector<LogSetting *> > log_settings;
00176 
00177         Anope::string name;                       /* Channel name */
00178         Anope::string desc;
00179 
00180         time_t time_registered;
00181         time_t last_used;
00182 
00183         Anope::string last_topic;                 /* The last topic that was set on this channel */
00184         Anope::string last_topic_setter;          /* Setter */
00185         time_t last_topic_time;                   /* Time */
00186 
00187         int16_t bantype;
00188 
00189         MemoInfo memos;
00190 
00191         Channel *c;                               /* Pointer to channel, if the channel exists */
00192 
00193         /* For BotServ */
00194         Serialize::Reference<BotInfo> bi;         /* Bot used on this channel */
00195         int16_t ttb[TTB_SIZE];                    /* Times to ban for each kicker */
00196 
00197         int16_t capsmin, capspercent;             /* For CAPS kicker */
00198         int16_t floodlines, floodsecs;            /* For FLOOD kicker */
00199         int16_t repeattimes;                      /* For REPEAT kicker */
00200 
00204         ChannelInfo(const Anope::string &chname);
00205 
00209         ChannelInfo(const ChannelInfo &ci);
00210 
00211         ~ChannelInfo();
00212 
00213         void Serialize(Serialize::Data &data) const anope_override;
00214         static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
00215 
00219         void SetFounder(NickCore *nc);
00220 
00224         NickCore *GetFounder() const;
00225 
00226         void SetSuccessor(NickCore *nc);
00227         NickCore *GetSuccessor() const;
00228 
00232         BotInfo *WhoSends() const;
00233 
00237         void AddAccess(ChanAccess *access);
00238 
00246         ChanAccess *GetAccess(unsigned index) const;
00247 
00251         AccessGroup AccessFor(const User *u);
00252         AccessGroup AccessFor(const NickCore *nc);
00253 
00257         unsigned GetAccessCount() const;
00258 
00265         void EraseAccess(unsigned index);
00266 
00271         void ClearAccess();
00272 
00280         AutoKick* AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
00281 
00289         AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
00290 
00295         AutoKick* GetAkick(unsigned index) const;
00296 
00300         unsigned GetAkickCount() const;
00301 
00305         void EraseAkick(unsigned index);
00306 
00309         void ClearAkick();
00310 
00316         BadWord* AddBadWord(const Anope::string &word, BadWordType type);
00317 
00322         BadWord* GetBadWord(unsigned index) const;
00323 
00327         unsigned GetBadWordCount() const;
00328 
00332         void EraseBadWord(unsigned index);
00333 
00336         void ClearBadWords();
00337 
00344         bool HasMLock(ChannelMode *mode, const Anope::string &param, bool status) const;
00345 
00354         bool SetMLock(ChannelMode *mode, bool status, const Anope::string &param = "", Anope::string setter = "", time_t created = Anope::CurTime);
00355 
00362         bool RemoveMLock(ChannelMode *mode, bool status, const Anope::string &param = "");
00363 
00364         void RemoveMLock(ModeLock *mlock);
00365 
00368         void ClearMLock();
00369 
00373         const ModeList &GetMLock() const;
00374 
00379         std::pair<ModeList::iterator, ModeList::iterator> GetModeList(const Anope::string &name);
00380 
00386         const ModeLock *GetMLock(const Anope::string &mname, const Anope::string &param = "");
00387 
00392         Anope::string GetMLockAsString(bool complete) const;
00393 
00398         bool CheckKick(User *user);
00399 
00404         void CheckTopic();
00405 
00409         void RestoreTopic();
00410 
00416         int16_t GetLevel(const Anope::string &priv) const;
00417 
00422         void SetLevel(const Anope::string &priv, int16_t level);
00423 
00427         void RemoveLevel(const Anope::string &priv);
00428 
00431         void ClearLevels();
00432 
00438         Anope::string GetIdealBan(User *u) const;
00439 
00444         static ChannelInfo* Find(const Anope::string &name);
00445 };
00446 
00452 extern CoreExport bool IsFounder(const User *user, const ChannelInfo *ci);
00453 
00454 #endif // REGCHANNEL_H