Anope IRC Services  Version 2.0
channels.h
Go to the documentation of this file.
1 /* Channel support
2  *
3  * (C) 2008-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  */
9 
10 #ifndef CHANNELS_H
11 #define CHANNELS_H
12 
13 #include "anope.h"
14 #include "extensible.h"
15 #include "modes.h"
16 #include "serialize.h"
17 
19 
21 
22 /* A user container, there is one of these per user per channel. */
24 {
27  /* Status the user has in the channel */
29 
30  ChanUserContainer(User *u, Channel *c) : user(u), chan(c) { }
31 };
32 
33 class CoreExport Channel : public Base, public Extensible
34 {
35  public:
36  typedef std::multimap<Anope::string, Anope::string> ModeList;
37  private:
40  ModeList modes;
41 
42  public:
43  /* Channel name */
45  /* Set if this channel is registered. ci->c == this. Contains information relevant to the registered channel */
47  /* When the channel was created */
48  time_t creation_time;
49  /* If the channel has just been created in a netjoin */
50  bool syncing;
51  /* Is configured in the conf as a channel bots should be in */
52  bool botchannel;
53 
54  /* Users in the channel */
55  typedef std::map<User *, ChanUserContainer *> ChanUserList;
56  ChanUserList users;
57 
58  /* Current topic of the channel */
60  /* Who set the topic */
62  /* The timestamp associated with the topic. Not necessarually anywhere close to Anope::CurTime.
63  * This is the time the topic was *originally set*. When we restore the topic we want to change the TS back
64  * to this, but we can only do this on certain IRCds.
65  */
66  time_t topic_ts;
67  /* The actual time the topic was set, probably close to Anope::CurTime */
68  time_t topic_time;
69 
70  time_t server_modetime; /* Time of last server MODE */
71  time_t chanserv_modetime; /* Time of last check_modes() */
72  int16_t server_modecount; /* Number of server MODEs this second */
73  int16_t chanserv_modecount; /* Number of check_mode()'s this sec */
74  int16_t bouncy_modes; /* Did we fail to set modes here? */
75 
76  private:
81  Channel(const Anope::string &nname, time_t ts = Anope::CurTime);
82 
83  public:
86  ~Channel();
87 
91  void Reset();
92 
95  void Sync();
96 
99  void CheckModes();
100 
103  bool CheckDelete();
104 
110  ChanUserContainer* JoinUser(User *u, const ChannelStatus *status);
111 
115  void DeleteUser(User *u);
116 
121  ChanUserContainer *FindUser(User *u) const;
122 
128  bool HasUserStatus(User *u, ChannelModeStatus *cms);
129 
136  bool HasUserStatus(User *u, const Anope::string &name);
137 
143  size_t HasMode(const Anope::string &name, const Anope::string &param = "");
144 
151  void SetModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string &param = "", bool enforce_mlock = true);
152 
159  void RemoveModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string &param = "", bool enforce_mlock = true);
160 
167  void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param = "", bool enforce_mlock = true);
168 
176  void SetMode(BotInfo *bi, const Anope::string &name, const Anope::string &param = "", bool enforce_mlock = true);
177 
184  void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param = "", bool enforce_mlock = true);
185 
193  void RemoveMode(BotInfo *bi, const Anope::string &name, const Anope::string &param = "", bool enforce_mlock = true);
194 
200  bool GetParam(const Anope::string &name, Anope::string &target) const;
201 
207  void SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...);
208 
214  void SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts = 0, bool enforce_mlock = true);
215 
221  bool MatchesList(User *u, const Anope::string &list);
222 
228  void KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason);
229 
236  bool Kick(BotInfo *bi, User *u, const char *reason = NULL, ...);
237 
241  const ModeList &GetModes() const;
242 
247  std::pair<ModeList::iterator, ModeList::iterator> GetModeList(const Anope::string &name);
248 
254  Anope::string GetModes(bool complete, bool plus);
255 
261  void ChangeTopicInternal(const Anope::string &user, const Anope::string &newtopic, time_t ts = Anope::CurTime);
262 
268  void ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts = Anope::CurTime);
269 
275  void SetCorrectModes(User *u, bool give_modes);
276 
283  bool Unban(User *u, const Anope::string &mode, bool full = false);
284 
289  bool CheckKick(User *user);
290 
295  static Channel* Find(const Anope::string &name);
296 
302  static Channel *FindOrCreate(const Anope::string &name, bool &created, time_t ts = Anope::CurTime);
303 };
304 
305 #endif // CHANNELS_H
Definition: bots.h:24
int16_t server_modecount
Definition: channels.h:72
Definition: base.h:17
time_t creation_time
Definition: channels.h:48
Definition: users.h:34
Anope::string topic_setter
Definition: channels.h:61
ChanUserContainer(User *u, Channel *c)
Definition: channels.h:30
time_t server_modetime
Definition: channels.h:70
time_t chanserv_modetime
Definition: channels.h:71
time_t topic_ts
Definition: channels.h:66
Serialize::Reference< ChannelInfo > ci
Definition: channels.h:46
Anope::string name
Definition: channels.h:44
CoreExport time_t CurTime
Definition: main.cpp:41
Anope::string topic
Definition: channels.h:59
ModeList modes
Definition: channels.h:40
Channel * chan
Definition: channels.h:26
bool botchannel
Definition: channels.h:52
std::multimap< Anope::string, Anope::string > ModeList
Definition: channels.h:36
int16_t bouncy_modes
Definition: channels.h:74
std::map< User *, ChanUserContainer * > ChanUserList
Definition: channels.h:55
time_t topic_time
Definition: channels.h:68
CoreExport channel_map ChannelList
Definition: channels.cpp:29
ChanUserList users
Definition: channels.h:56
ChannelStatus status
Definition: channels.h:28
#define CoreExport
Definition: services.h:62
bool syncing
Definition: channels.h:50
int16_t chanserv_modecount
Definition: channels.h:73
Anope::hash_map< Channel * > channel_map
Definition: channels.h:18