forked from anope/anope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannels.h
310 lines (261 loc) · 10.4 KB
/
channels.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/* Channel support
*
* (C) 2008-2020 Anope Team
* Contact us at [email protected]
*
* Please read COPYING and README for further details.
*/
#ifndef CHANNELS_H
#define CHANNELS_H
#include "anope.h"
#include "extensible.h"
#include "modes.h"
#include "serialize.h"
typedef Anope::hash_map<Channel *> channel_map;
extern CoreExport channel_map ChannelList;
/* A user container, there is one of these per user per channel. */
struct ChanUserContainer : public Extensible
{
User *user;
Channel *chan;
/* Status the user has in the channel */
ChannelStatus status;
ChanUserContainer(User *u, Channel *c) : user(u), chan(c) { }
};
class CoreExport Channel : public Base, public Extensible
{
static std::vector<Channel *> deleting;
public:
typedef std::multimap<Anope::string, Anope::string> ModeList;
private:
/** A map of channel modes with their parameters set on this channel
*/
ModeList modes;
public:
/* Channel name */
Anope::string name;
/* Set if this channel is registered. ci->c == this. Contains information relevant to the registered channel */
Serialize::Reference<ChannelInfo> ci;
/* When the channel was created */
time_t creation_time;
/* If the channel has just been created in a netjoin */
bool syncing;
/* Is configured in the conf as a channel bots should be in */
bool botchannel;
/* Users in the channel */
typedef std::map<User *, ChanUserContainer *> ChanUserList;
ChanUserList users;
/* Current topic of the channel */
Anope::string topic;
/* Who set the topic */
Anope::string topic_setter;
/* The timestamp associated with the topic. Not necessarily anywhere close to Anope::CurTime.
* This is the time the topic was *originally set*. When we restore the topic we want to change the TS back
* to this, but we can only do this on certain IRCds.
*/
time_t topic_ts;
/* The actual time the topic was set, probably close to Anope::CurTime */
time_t topic_time;
time_t server_modetime; /* Time of last server MODE */
time_t chanserv_modetime; /* Time of last check_modes() */
int16_t server_modecount; /* Number of server MODEs this second */
int16_t chanserv_modecount; /* Number of check_mode()'s this sec */
int16_t bouncy_modes; /* Did we fail to set modes here? */
private:
/** Constructor
* @param name The channel name
* @param ts The time the channel was created
*/
Channel(const Anope::string &nname, time_t ts = Anope::CurTime);
public:
/** Destructor
*/
~Channel();
/** Call if we need to unset all modes and clear all user status (internally).
* Only useful if we get a SJOIN with a TS older than what we have here
*/
void Reset();
/** Restore the channel topic, set mlock (key), set stickied bans, etc
*/
void Sync();
/** Check if a channels modes are correct.
*/
void CheckModes();
/** Check if this channel should be deleted
*/
bool CheckDelete();
/** Join a user internally to the channel
* @param u The user
* @param status The status to give the user, if any
* @return The UserContainer for the user
*/
ChanUserContainer* JoinUser(User *u, const ChannelStatus *status);
/** Remove a user internally from the channel
* @param u The user
*/
void DeleteUser(User *u);
/** Check if the user is on the channel
* @param u The user
* @return A user container if found, else NULL
*/
ChanUserContainer *FindUser(User *u) const;
/** Check if a user has a status on a channel
* @param u The user
* @param cms The status mode, or NULL to represent no status
* @return true or false
*/
bool HasUserStatus(User *u, ChannelModeStatus *cms);
/** Check if a user has a status on a channel
* Use the overloaded function for ChannelModeStatus* to check for no status
* @param u The user
* @param name The mode name, eg CMODE_OP, CMODE_VOICE
* @return true or false
*/
bool HasUserStatus(User *u, const Anope::string &name);
/** See if a channel has a mode
* @param name The mode name
* @return The number of modes set
* @param param The optional mode param
*/
size_t HasMode(const Anope::string &name, const Anope::string ¶m = "");
/** Set a mode internally on a channel, this is not sent out to the IRCd
* @param setter The setter
* @param cm The mode
* @param param The param
* @param enforce_mlock true if mlocks should be enforced, false to override mlock
*/
void SetModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true);
/** Remove a mode internally on a channel, this is not sent out to the IRCd
* @param setter The Setter
* @param cm The mode
* @param param The param
* @param enforce_mlock true if mlocks should be enforced, false to override mlock
*/
void RemoveModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true);
/** Set a mode on a channel
* @param bi The client setting the modes
* @param cm The mode
* @param param Optional param arg for the mode
* @param enforce_mlock true if mlocks should be enforced, false to override mlock
*/
void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true);
/**
* Set a mode on a channel
* @param bi The client setting the modes
* @param name The mode name
* @param param Optional param arg for the mode
* @param enforce_mlock true if mlocks should be enforced, false to override mlock
*/
void SetMode(BotInfo *bi, const Anope::string &name, const Anope::string ¶m = "", bool enforce_mlock = true);
/** Remove a mode from a channel
* @param bi The client setting the modes
* @param cm The mode
* @param param Optional param arg for the mode
* @param enforce_mlock true if mlocks should be enforced, false to override mlock
*/
void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true);
/**
* Remove a mode from a channel
* @param bi The client setting the modes
* @param name The mode name
* @param param Optional param arg for the mode
* @param enforce_mlock true if mlocks should be enforced, false to override mlock
*/
void RemoveMode(BotInfo *bi, const Anope::string &name, const Anope::string ¶m = "", bool enforce_mlock = true);
/** Get a modes parameter for the channel
* @param name The mode
* @param target a string to put the param into
* @return true if the parameter was fetched, false if on error (mode not set) etc.
*/
bool GetParam(const Anope::string &name, Anope::string &target) const;
/** Set a string of modes on the channel
* @param bi The client setting the modes
* @param enforce_mlock Should mlock be enforced on this mode change
* @param cmodes The modes to set
*/
void SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...);
/** Set a string of modes internally on a channel
* @param source The setter
* @param mode the modes
* @param enforce_mlock true to enforce mlock
*/
void SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts = 0, bool enforce_mlock = true);
/** Does the given user match the given list? (CMODE_BAN, CMODE_EXCEPT, etc, a list mode)
* @param u The user
* @param list The mode of the list to check (eg CMODE_BAN)
* @return true if the user matches the list
*/
bool MatchesList(User *u, const Anope::string &list);
/** Kick a user from a channel internally
* @param source The sender of the kick
* @param nick The nick being kicked
* @param reason The reason for the kick
*/
void KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason);
/** Kick a user from the channel
* @param bi The sender, can be NULL for the service bot for this channel
* @param u The user being kicked
* @param reason The reason for the kick
* @return true if the kick was scucessful, false if a module blocked the kick
*/
bool Kick(BotInfo *bi, User *u, const char *reason = NULL, ...);
/** Get all modes set on this channel, excluding status modes.
* @return a map of modes and their optional parameters.
*/
const ModeList &GetModes() const;
/** Get a list of modes on a channel
* @param name A mode name to get the list of
* @return a vector of the list mode entries
*/
std::vector<Anope::string> GetModeList(const Anope::string &name);
/** Get a string of the modes set on this channel
* @param complete Include mode parameters
* @param plus If set to false (with complete), mode parameters will not be given for modes requring no parameters to be unset
* @return A mode string
*/
Anope::string GetModes(bool complete, bool plus);
/** Update the topic of the channel internally, and reset it if topiclock etc says to
* @param user The user setting the new topic
* @param newtopic The new topic
* @param ts The time the new topic is being set
*/
void ChangeTopicInternal(User *u, const Anope::string &user, const Anope::string &newtopic, time_t ts = Anope::CurTime);
/** Update the topic of the channel, and reset it if topiclock etc says to
* @param user The user setting the topic
* @param newtopic The new topic
* @param ts The time when the new topic is being set
*/
void ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts = Anope::CurTime);
/** Set the correct modes, or remove the ones granted without permission,
* for the specified user.
* @param user The user to give/remove modes to/from
* @param give_modes if true modes may be given to the user
*/
void SetCorrectModes(User *u, bool give_modes);
/** Unbans a user from this channel.
* @param u The user to unban
* @param mode The mode to unban
* @param full Whether or not to match using the user's real host and IP
* @return whether or not a ban was removed
*/
bool Unban(User *u, const Anope::string &mode, bool full = false);
/** Check whether a user is permitted to be on this channel
* @param u The user
* @return true if they are allowed, false if they aren't and were kicked
*/
bool CheckKick(User *user);
/** Finds a channel
* @param name The channel to find
* @return The channel, if found
*/
static Channel* Find(const Anope::string &name);
/** Finds or creates a channel
* @param name The channel name
* @param created Set to true if the channel was just created
* @param ts The time the channel was created
*/
static Channel *FindOrCreate(const Anope::string &name, bool &created, time_t ts = Anope::CurTime);
void QueueForDeletion();
static void DeleteChannels();
};
#endif // CHANNELS_H