1 |
/** |
2 |
* channels.h: Data structures for channel information. |
3 |
* |
4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
* Rights to this code are as documented in COPYING. |
6 |
* |
7 |
* |
8 |
* Portions of this file were derived from sources bearing the following license: |
9 |
* Copyright © 2005 William Pitcock, et al. |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: channels.h,v 1.7 2007-09-16 18:54:42 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#ifndef CHANNELS_H |
16 |
#define CHANNELS_H |
17 |
|
18 |
#include <map> |
19 |
|
20 |
#include <util/containers.h> |
21 |
#include <ermyth/callback.h> |
22 |
#include <util/predicates.h> |
23 |
|
24 |
#define MAXEXTMODES 5 |
25 |
|
26 |
// Channel modes |
27 |
enum |
28 |
{ |
29 |
CMODE_INVITE = 1 << 0, |
30 |
CMODE_KEY = 1 << 1, |
31 |
CMODE_LIMIT = 1 << 2, |
32 |
CMODE_MOD = 1 << 3, |
33 |
CMODE_NOEXT = 1 << 4, |
34 |
CMODE_OP = 1 << 5, /* SPECIAL */ |
35 |
CMODE_PRIV = 1 << 6, /* AKA PARA */ |
36 |
CMODE_SEC = 1 << 7, |
37 |
CMODE_TOPIC = 1 << 8, |
38 |
CMODE_VOICE = 1 << 9 /* SPECIAL */ |
39 |
}; |
40 |
|
41 |
class channel_t : public zero_initialised |
42 |
{ |
43 |
struct callbacks |
44 |
{ |
45 |
functor::callback1<channel_t *> add; |
46 |
functor::callback1<channel_t *> akick_add; |
47 |
functor::callback1<channel_t *> remove; |
48 |
functor::callback6<channel_t *, user_t *, server_t *, |
49 |
char const * const /* setter */, |
50 |
time_t /* ts */, |
51 |
char const * const /* topic */, |
52 |
bool /* return value */> can_change_topic; |
53 |
functor::callback3<channel_t *, user_t *, char const * const> message; |
54 |
functor::callback1<channel_t *> topic; |
55 |
functor::callback1<channel_t *> tschange; |
56 |
}; |
57 |
|
58 |
public: |
59 |
unsigned modes; |
60 |
|
61 |
char *name; |
62 |
|
63 |
char *key; |
64 |
unsigned int limit; |
65 |
char *extmodes[MAXEXTMODES]; /* non-standard simple modes with param eg +j */ |
66 |
|
67 |
unsigned int nummembers; |
68 |
|
69 |
time_t ts; |
70 |
|
71 |
char *topic; |
72 |
char *topic_setter; |
73 |
time_t topicts; |
74 |
|
75 |
list_t members; |
76 |
list_t bans; |
77 |
|
78 |
static callbacks callback; |
79 |
}; |
80 |
|
81 |
/* struct for channel memberships */ |
82 |
class chanuser_t : public zero_initialised |
83 |
{ |
84 |
struct callbacks |
85 |
{ |
86 |
functor::callback1<chanuser_t *, bool> join; |
87 |
functor::callback1<chanuser_t *> part; |
88 |
}; |
89 |
|
90 |
public: |
91 |
unsigned modes; |
92 |
|
93 |
channel_t *chan; |
94 |
user_t *user; |
95 |
node_t unode; |
96 |
node_t cnode; |
97 |
|
98 |
static callbacks callback; |
99 |
}; |
100 |
|
101 |
struct chanban_t : zero_initialised |
102 |
{ |
103 |
channel_t *chan; |
104 |
char *mask; |
105 |
int type; /* 'b', 'e', 'I', etc -- jilles */ |
106 |
}; |
107 |
|
108 |
enum mtype |
109 |
{ |
110 |
MTYPE_NUL, |
111 |
MTYPE_ADD, |
112 |
MTYPE_DEL |
113 |
}; |
114 |
|
115 |
struct cmode_t |
116 |
{ |
117 |
char mode; |
118 |
unsigned int value; |
119 |
}; |
120 |
|
121 |
struct extmode_t |
122 |
{ |
123 |
char mode; |
124 |
bool (*check) (char const * const, channel_t *, mychan_t *, user_t *, myuser_t *); |
125 |
}; |
126 |
|
127 |
#if 0 |
128 |
/* channel related hooks */ |
129 |
typedef struct |
130 |
{ |
131 |
chanuser_t *cu; /* Write NULL here if you kicked the user. |
132 |
When kicking the last user, you must join a |
133 |
service first, otherwise the channel may be |
134 |
destroyed and crashes may occur. The service may |
135 |
not part until you return; chanserv provides |
136 |
MC_INHABIT to help with this. |
137 |
This also prevents kick/rejoin floods. |
138 |
If this is NULL, a previous function kicked |
139 |
the user */ |
140 |
} hook_channel_joinpart_t; |
141 |
|
142 |
typedef struct |
143 |
{ |
144 |
user_t *u; |
145 |
channel_t *c; |
146 |
char *msg; |
147 |
} hook_cmessage_data_t; |
148 |
|
149 |
struct hook_channel_topic_check_t |
150 |
{ |
151 |
user_t *u; /* Online user that changed the topic */ |
152 |
server_t *s; /* Server that restored a topic */ |
153 |
channel_t *c; /* Channel still has old topic */ |
154 |
char const * const setter; /* Stored setter string, can be nick, nick!user@host |
155 |
or server */ |
156 |
time_t ts; /* Time the topic was changed */ |
157 |
char const * const topic; /* New topic */ |
158 |
int approved; /* Write non-zero here to cancel the change */ |
159 |
|
160 |
hook_channel_topic_check_t (char const * const _setter, char const * const _topic) |
161 |
: setter (_setter), topic (_topic) |
162 |
{ |
163 |
} |
164 |
}; |
165 |
#endif |
166 |
|
167 |
/* cmode.C */ |
168 |
E char *flags_to_string (int flags); |
169 |
E int mode_to_flag (char c); |
170 |
E void channel_mode (user_t *source, channel_t *chan, int parc, char const * const parv[]); |
171 |
E void channel_mode (user_t *source, channel_t *chan, char const * const arg); |
172 |
E void channel_mode_va (user_t *source, channel_t *chan, int parc, char const * const parv0, ...); |
173 |
E void clear_simple_modes (channel_t *c); |
174 |
E char *channel_modes (channel_t *c, bool doparams); |
175 |
E void modestack_flush_channel (channel_t *channel); |
176 |
E void modestack_forget_channel (channel_t *channel); |
177 |
E void modestack_finalize_channel (channel_t *channel); |
178 |
E void modestack_mode_simple (char *source, channel_t *channel, mtype dir, int flags); |
179 |
E void modestack_mode_limit (char *source, channel_t *channel, mtype dir, unsigned int limit); |
180 |
E void modestack_mode_ext (char *source, channel_t *channel, mtype dir, int i, char const * const value); |
181 |
E void modestack_mode_param (char *source, channel_t *channel, mtype dir, char type, char const * const value); |
182 |
E void check_modes (mychan_t *mychan, bool sendnow); |
183 |
|
184 |
/* channels.C */ |
185 |
typedef std::pair<char const * const, channel_t *> channel_pair; |
186 |
typedef std::map<char const * const, channel_t *, irccase_lt> channel_map; |
187 |
E channel_map chanlist; |
188 |
|
189 |
E void init_channels (void); |
190 |
|
191 |
E channel_t *channel_add (char const * const name, unsigned int ts, server_t *creator); |
192 |
E void channel_delete (channel_t *c); |
193 |
E channel_t *channel_find (char const * const name); |
194 |
|
195 |
E chanuser_t *chanuser_add (channel_t *chan, char const * const user); |
196 |
E void chanuser_delete (channel_t *chan, user_t *user); |
197 |
E chanuser_t *chanuser_find (channel_t *chan, user_t *user); |
198 |
|
199 |
E chanban_t *chanban_add (channel_t *chan, char const * const mask, int type); |
200 |
E void chanban_delete (chanban_t *c); |
201 |
E chanban_t *chanban_find (channel_t *chan, char const * const mask, int type); |
202 |
E void chanban_clear (channel_t *chan); |
203 |
|
204 |
#endif |