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