1 |
/* |
2 |
* phandler.C: Generic protocol handling routines. |
3 |
* Rights to this code are documented in doc/pod/license.pod. |
4 |
* |
5 |
* Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 |
*/ |
7 |
|
8 |
static char const rcsid[] = "$Id"; |
9 |
|
10 |
#include "atheme.h" |
11 |
#include <account/chanacs.h> |
12 |
#include "uplink.h" |
13 |
|
14 |
unsigned int (*server_login) (void) = generic_server_login; |
15 |
void (*introduce_nick) (user_t *u) = generic_introduce_nick; |
16 |
void (*wallops_sts) (const char *text) = generic_wallops_sts; |
17 |
void (*join_sts) (channel_t *c, user_t *u, bool isnew, char *modes) = generic_join_sts; |
18 |
void (*chan_lowerts) (channel_t *c, user_t *u) = generic_chan_lowerts; |
19 |
void (*kick) (char *from, char *channel, char *to, char *reason) = generic_kick; |
20 |
void (*msg) (const char *from, const char *target, const char *fmt, ...) = generic_msg; |
21 |
void (*notice_user_sts) (user_t *from, user_t *target, const char *text) = generic_notice_user_sts; |
22 |
void (*notice_global_sts) (user_t *from, const char *mask, const char *text) = generic_notice_global_sts; |
23 |
void (*notice_channel_sts) (user_t *from, channel_t *target, const char *text) = generic_notice_channel_sts; |
24 |
void (*wallchops) (user_t *source, channel_t *target, const char *message) = generic_wallchops; |
25 |
void (*numeric_sts) (char *from, int numeric, char *target, char *fmt, ...) = generic_numeric_sts; |
26 |
void (*skill) (char *from, char *nick, char *fmt, ...) = generic_skill; |
27 |
void (*part_sts) (channel_t *c, user_t *u) = generic_part_sts; |
28 |
void (*kline_sts) (char *server, char *user, char *host, long duration, char *reason) = generic_kline_sts; |
29 |
void (*unkline_sts) (char *server, char *user, char *host) = generic_unkline_sts; |
30 |
void (*topic_sts) (channel_t *c, const char *setter, time_t ts, time_t prevts, const char *topic) = generic_topic_sts; |
31 |
void (*mode_sts) (char *sender, channel_t *target, char *modes) = generic_mode_sts; |
32 |
void (*ping_sts) (void) = generic_ping_sts; |
33 |
void (*quit_sts) (user_t *u, const char *reason) = generic_quit_sts; |
34 |
void (*ircd_on_login) (char *origin, char *user, char *wantedhost) = generic_on_login; |
35 |
bool (*ircd_on_logout) (char *origin, char *user, char *wantedhost) = generic_on_logout; |
36 |
void (*jupe) (const char *server, const char *reason) = generic_jupe; |
37 |
void (*sethost_sts) (char *source, char *target, char *host) = generic_sethost_sts; |
38 |
void (*fnc_sts) (user_t *source, user_t *u, char *newnick, int type) = generic_fnc_sts; |
39 |
void (*holdnick_sts) (user_t *source, int duration, const char *nick, myuser_t *account) = generic_holdnick_sts; |
40 |
void (*invite_sts) (user_t *source, user_t *target, channel_t *channel) = generic_invite_sts; |
41 |
void (*svslogin_sts) (char *target, char *nick, char *user, char *host, char *login) = generic_svslogin_sts; |
42 |
void (*sasl_sts) (char *target, char mode, char *data) = generic_sasl_sts; |
43 |
node_t *(*next_matching_ban) (channel_t *c, user_t *u, int type, node_t *first) = generic_next_matching_ban; |
44 |
node_t *(*next_matching_host_chanacs) (mychan_t *mc, user_t *u, node_t *first) = generic_next_matching_host_chanacs; |
45 |
|
46 |
unsigned int |
47 |
generic_server_login (void) |
48 |
{ |
49 |
/* Nothing to do here. */ |
50 |
return 0; |
51 |
} |
52 |
|
53 |
void |
54 |
generic_introduce_nick (user_t *u) |
55 |
{ |
56 |
/* Nothing to do here. */ |
57 |
} |
58 |
|
59 |
void |
60 |
generic_wallops_sts (const char *text) |
61 |
{ |
62 |
slog (LG_INFO, "Don't know how to send wallops: %s", text); |
63 |
} |
64 |
|
65 |
void |
66 |
generic_join_sts (channel_t *c, user_t *u, bool isnew, char *modes) |
67 |
{ |
68 |
/* We can't do anything here. Bail. */ |
69 |
} |
70 |
|
71 |
void |
72 |
generic_chan_lowerts (channel_t *c, user_t *u) |
73 |
{ |
74 |
slog (LG_ERROR, "chan_lowerts() called but not supported!"); |
75 |
join_sts (c, u, true, channel_modes (c, true)); |
76 |
} |
77 |
|
78 |
void |
79 |
generic_kick (char *from, char *channel, char *to, char *reason) |
80 |
{ |
81 |
/* We can't do anything here. Bail. */ |
82 |
} |
83 |
|
84 |
void |
85 |
generic_msg (const char *from, const char *target, const char *fmt, ...) |
86 |
{ |
87 |
va_list ap; |
88 |
char *buf; |
89 |
|
90 |
va_start (ap, fmt); |
91 |
vasprintf (&buf, fmt, ap); |
92 |
va_end (ap); |
93 |
|
94 |
slog (LG_INFO, "Cannot send message to %s (%s): don't know how. Load a protocol module perhaps?", target, buf); |
95 |
free (buf); |
96 |
} |
97 |
|
98 |
void |
99 |
generic_notice_user_sts (user_t *from, user_t *target, const char *text) |
100 |
{ |
101 |
slog (LG_INFO, "Cannot send notice to %s (%s): don't know how. Load a protocol module perhaps?", target->nick, text); |
102 |
} |
103 |
|
104 |
void |
105 |
generic_notice_global_sts (user_t *from, const char *mask, const char *text) |
106 |
{ |
107 |
slog (LG_INFO, "Cannot send global notice to %s (%s): don't know how. Load a protocol module perhaps?", mask, text); |
108 |
} |
109 |
|
110 |
void |
111 |
generic_notice_channel_sts (user_t *from, channel_t *target, const char *text) |
112 |
{ |
113 |
slog (LG_INFO, "Cannot send notice to %s (%s): don't know how. Load a protocol module perhaps?", target->name, text); |
114 |
} |
115 |
|
116 |
void |
117 |
generic_wallchops (user_t *sender, channel_t *channel, const char *message) |
118 |
{ |
119 |
/* ugly, but always works -- jilles */ |
120 |
node_t *n; |
121 |
chanuser_t *cu; |
122 |
|
123 |
LIST_FOREACH (n, channel->members.head) |
124 |
{ |
125 |
cu = (chanuser_t *) n->data; |
126 |
if (cu->user->server != me.me && cu->modes & CMODE_OP) |
127 |
notice (sender->nick, cu->user->nick, "[@%s] %s", channel->name, message); |
128 |
} |
129 |
} |
130 |
|
131 |
void |
132 |
generic_numeric_sts (char *from, int numeric, char *target, char *fmt, ...) |
133 |
{ |
134 |
va_list va; |
135 |
char *buf; |
136 |
|
137 |
va_start (va, fmt); |
138 |
vasprintf (&buf, fmt, va); |
139 |
va_end (va); |
140 |
|
141 |
sts (":%s %d %s %s", from, numeric, target, buf); |
142 |
free (buf); |
143 |
} |
144 |
|
145 |
void |
146 |
generic_skill (char *from, char *nick, char *fmt, ...) |
147 |
{ |
148 |
/* cant do anything here. bail. */ |
149 |
} |
150 |
|
151 |
void |
152 |
generic_part_sts (channel_t *c, user_t *u) |
153 |
{ |
154 |
/* cant do anything here. bail. */ |
155 |
} |
156 |
|
157 |
void |
158 |
generic_kline_sts (char *server, char *user, char *host, long duration, char *reason) |
159 |
{ |
160 |
/* cant do anything here. bail. */ |
161 |
} |
162 |
|
163 |
void |
164 |
generic_unkline_sts (char *server, char *user, char *host) |
165 |
{ |
166 |
/* cant do anything here. bail. */ |
167 |
} |
168 |
|
169 |
void |
170 |
generic_topic_sts (channel_t *c, const char *setter, time_t ts, time_t prevts, const char *topic) |
171 |
{ |
172 |
/* cant do anything here. bail. */ |
173 |
} |
174 |
|
175 |
void |
176 |
generic_mode_sts (char *sender, channel_t *target, char *modes) |
177 |
{ |
178 |
/* cant do anything here. bail. */ |
179 |
} |
180 |
|
181 |
void |
182 |
generic_ping_sts (void) |
183 |
{ |
184 |
/* cant do anything here. bail. */ |
185 |
} |
186 |
|
187 |
void |
188 |
generic_quit_sts (user_t *u, const char *reason) |
189 |
{ |
190 |
/* cant do anything here. bail. */ |
191 |
} |
192 |
|
193 |
void |
194 |
generic_on_login (char *origin, char *user, char *wantedhost) |
195 |
{ |
196 |
/* nothing to do here. */ |
197 |
} |
198 |
|
199 |
bool |
200 |
generic_on_logout (char *origin, char *user, char *wantedhost) |
201 |
{ |
202 |
/* nothing to do here. */ |
203 |
return false; |
204 |
} |
205 |
|
206 |
void |
207 |
generic_jupe (const char *server, const char *reason) |
208 |
{ |
209 |
/* nothing to do here. */ |
210 |
} |
211 |
|
212 |
void |
213 |
generic_sethost_sts (char *source, char *target, char *host) |
214 |
{ |
215 |
/* nothing to do here. */ |
216 |
} |
217 |
|
218 |
void |
219 |
generic_fnc_sts (user_t *source, user_t *u, char *newnick, int type) |
220 |
{ |
221 |
if (type == FNC_FORCE) |
222 |
skill (source->nick, u->nick, "Nickname enforcement (%s)", u->nick); |
223 |
} |
224 |
|
225 |
void |
226 |
generic_holdnick_sts (user_t *source, int duration, const char *nick, myuser_t *account) |
227 |
{ |
228 |
/* nothing to do here. */ |
229 |
} |
230 |
|
231 |
void |
232 |
generic_invite_sts (user_t *source, user_t *target, channel_t *channel) |
233 |
{ |
234 |
/* nothing to do here. */ |
235 |
} |
236 |
|
237 |
void |
238 |
generic_svslogin_sts (char *target, char *nick, char *user, char *host, char *login) |
239 |
{ |
240 |
/* nothing to do here. */ |
241 |
} |
242 |
|
243 |
void |
244 |
generic_sasl_sts (char *target, char mode, char *data) |
245 |
{ |
246 |
/* nothing to do here. */ |
247 |
} |
248 |
|
249 |
node_t * |
250 |
generic_next_matching_ban (channel_t *c, user_t *u, int type, node_t *first) |
251 |
{ |
252 |
chanban_t *cb; |
253 |
node_t *n; |
254 |
char hostbuf[NICKLEN + USERLEN + HOSTLEN]; |
255 |
char realbuf[NICKLEN + USERLEN + HOSTLEN]; |
256 |
char ipbuf[NICKLEN + USERLEN + HOSTLEN]; |
257 |
|
258 |
snprintf (hostbuf, sizeof hostbuf, "%s!%s@%s", u->nick, u->user, u->vhost); |
259 |
snprintf (realbuf, sizeof realbuf, "%s!%s@%s", u->nick, u->user, u->host); |
260 |
/* will be nick!user@ if ip unknown, doesn't matter */ |
261 |
snprintf (ipbuf, sizeof ipbuf, "%s!%s@%s", u->nick, u->user, u->ip); |
262 |
LIST_FOREACH (n, first) |
263 |
{ |
264 |
cb = static_cast<chanban_t *> (n->data); |
265 |
|
266 |
if (cb->type == type && (!match (cb->mask, hostbuf) || !match (cb->mask, realbuf) || !match (cb->mask, ipbuf) || (ircd->flags & IRCD_CIDR_BANS && !match_cidr (cb->mask, ipbuf)))) |
267 |
return n; |
268 |
} |
269 |
return NULL; |
270 |
} |
271 |
|
272 |
node_t * |
273 |
generic_next_matching_host_chanacs (mychan_t *mc, user_t *u, node_t *first) |
274 |
{ |
275 |
chanacs_t *ca; |
276 |
node_t *n; |
277 |
char hostbuf[NICKLEN + USERLEN + HOSTLEN]; |
278 |
char ipbuf[NICKLEN + USERLEN + HOSTLEN]; |
279 |
|
280 |
snprintf (hostbuf, sizeof hostbuf, "%s!%s@%s", u->nick, u->user, u->vhost); |
281 |
/* will be nick!user@ if ip unknown, doesn't matter */ |
282 |
snprintf (ipbuf, sizeof ipbuf, "%s!%s@%s", u->nick, u->user, u->ip); |
283 |
|
284 |
LIST_FOREACH (n, first) |
285 |
{ |
286 |
ca = static_cast<chanacs_t *> (n->data); |
287 |
|
288 |
if (ca->myuser != NULL) |
289 |
continue; |
290 |
if (!match (ca->host, hostbuf) || !match (ca->host, ipbuf) || (ircd->flags & IRCD_CIDR_BANS && !match_cidr (ca->host, ipbuf))) |
291 |
return n; |
292 |
} |
293 |
return NULL; |
294 |
} |
295 |
|
296 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
297 |
* vim:ts=8 |
298 |
* vim:sw=8 |
299 |
* vim:noexpandtab |
300 |
*/ |