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