channels.h

Go to the documentation of this file.
00001 /* Channel support
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 CHANNELS_H
00011 #define CHANNELS_H
00012 
00013 #include "anope.h"
00014 #include "extensible.h"
00015 #include "modes.h"
00016 #include "serialize.h"
00017 
00018 typedef Anope::hash_map<Channel *> channel_map;
00019 
00020 extern CoreExport channel_map ChannelList;
00021 
00022 /* A user container, there is one of these per user per channel. */
00023 struct ChanUserContainer : public Extensible
00024 {
00025         User *user;
00026         Channel *chan;
00027         /* Status the user has in the channel */
00028         ChannelStatus status;
00029 
00030         ChanUserContainer(User *u, Channel *c) : user(u), chan(c) { }
00031 };
00032 
00033 enum ChannelFlag
00034 {
00035         /* ChanServ is currently holding the channel */
00036         CH_INHABIT,
00037         /* Channel still exists when emptied */
00038         CH_PERSIST,
00039         /* If set the channel is syncing users (channel was just created) and it should not be deleted */
00040         CH_SYNCING
00041 };
00042 
00043 class CoreExport Channel : public Base, public Extensible
00044 {
00045  public:
00046         typedef std::multimap<Anope::string, Anope::string> ModeList;
00047  private:
00050         ModeList modes;
00051 
00052  public:
00053         /* Channel name */
00054         Anope::string name;
00055         /* Set if this channel is registered. ci->c == this. Contains information relevant to the registered channel */
00056         Serialize::Reference<ChannelInfo> ci;
00057         /* When the channel was created */
00058         time_t creation_time;
00059         std::set<ChannelFlag> flags;
00060 
00061         /* Users in the channel */
00062         typedef std::list<ChanUserContainer *> ChanUserList;
00063         ChanUserList users;
00064 
00065         /* Current topic of the channel */
00066         Anope::string topic;
00067         /* Who set the topic */
00068         Anope::string topic_setter;
00069         /* The timestamp associated with the topic. Not necessarually anywhere close to Anope::CurTime.
00070          * This is the time the topic was *originally set*. When we restore the topic we want to change the TS back
00071          * to this, but we can only do this on certain IRCds.
00072          */
00073         time_t topic_ts;
00074         /* The actual time the topic was set, probably close to Anope::CurTime */
00075         time_t topic_time;
00076 
00077         time_t server_modetime;         /* Time of last server MODE */
00078         time_t chanserv_modetime;       /* Time of last check_modes() */
00079         int16_t server_modecount;       /* Number of server MODEs this second */
00080         int16_t chanserv_modecount;     /* Number of check_mode()'s this sec */
00081         int16_t bouncy_modes;           /* Did we fail to set modes here? */
00082 
00087         Channel(const Anope::string &nname, time_t ts = Anope::CurTime);
00088 
00091         ~Channel();
00092 
00096         void Reset();
00097 
00100         void Sync();
00101 
00104         void CheckModes();
00105 
00110         ChanUserContainer* JoinUser(User *u);
00111 
00115         void DeleteUser(User *u);
00116 
00121         ChanUserContainer *FindUser(const User *u) const;
00122 
00128         bool HasUserStatus(const User *u, ChannelModeStatus *cms) const;
00129 
00136         bool HasUserStatus(const User *u, const Anope::string &name) const;
00137 
00143         size_t HasMode(const Anope::string &name, const Anope::string &param = "");
00144 
00151         void SetModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string &param = "", bool enforce_mlock = true);
00152 
00159         void RemoveModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string &param = "", bool enforce_mlock = true);
00160 
00167         void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param = "", bool enforce_mlock = true);
00168 
00176         void SetMode(BotInfo *bi, const Anope::string &name, const Anope::string &param = "", bool enforce_mlock = true);
00177 
00184         void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param = "", bool enforce_mlock = true);
00185 
00193         void RemoveMode(BotInfo *bi, const Anope::string &name, const Anope::string &param = "", bool enforce_mlock = true);
00194 
00200         bool GetParam(const Anope::string &name, Anope::string &target) const;
00201 
00207         void SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...);
00208 
00214         void SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts = 0, bool enforce_mlock = true);
00215 
00221         bool MatchesList(User *u, const Anope::string &list);
00222 
00228         void KickInternal(MessageSource &source, const Anope::string &nick, const Anope::string &reason);
00229 
00236         bool Kick(BotInfo *bi, User *u, const char *reason = NULL, ...);
00237 
00241         const ModeList &GetModes() const;
00242 
00247         std::pair<ModeList::iterator, ModeList::iterator> GetModeList(const Anope::string &name);
00248 
00254         Anope::string GetModes(bool complete, bool plus);
00255 
00261         void ChangeTopicInternal(const Anope::string &user, const Anope::string &newtopic, time_t ts = Anope::CurTime);
00262 
00268         void ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts = Anope::CurTime);
00269 
00272         void Hold();
00273 
00280         void SetCorrectModes(User *u, bool give_mode, bool check_noop);
00281 
00287         bool Unban(const User *u, bool full = false);
00288 
00293         static Channel* Find(const Anope::string &name);
00294 };
00295 
00296 #endif // CHANNELS_H