]>
Commit | Line | Data |
---|---|---|
d76ed9a9 AS |
1 | /* proto-p10.c - IRC protocol output |
2 | * Copyright 2000-2004 srvx Development Team | |
3 | * | |
83ff05c3 | 4 | * This file is part of x3. |
d76ed9a9 | 5 | * |
d0f04f71 | 6 | * x3 is free software; you can redistribute it and/or modify |
d76ed9a9 | 7 | * it under the terms of the GNU General Public License as published by |
348683aa | 8 | * the Free Software Foundation; either version 3 of the License, or |
d76ed9a9 AS |
9 | * (at your option) any later version. |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with srvx; if not, write to the Free Software Foundation, | |
18 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
19 | */ | |
20 | ||
3fdd6a74 | 21 | #include "nickserv.h" |
23475fc6 | 22 | #include "chanserv.h" |
89d871d8 | 23 | #include "hash.h" |
08895577 | 24 | #include "helpfile.h" |
37ef8ee3 | 25 | #include "hosthiding.h" |
d76ed9a9 | 26 | #include "proto-common.c" |
47956fc5 | 27 | #include "opserv.h" |
d76ed9a9 AS |
28 | |
29 | /* Full commands. */ | |
30 | #define CMD_ACCOUNT "ACCOUNT" | |
31 | #define CMD_ADMIN "ADMIN" | |
763de701 | 32 | #define CMD_ALIST "ALIST" |
d76ed9a9 AS |
33 | #define CMD_ASLL "ASLL" |
34 | #define CMD_AWAY "AWAY" | |
35 | #define CMD_BURST "BURST" | |
36 | #define CMD_CLEARMODE "CLEARMODE" | |
37 | #define CMD_CLOSE "CLOSE" | |
38 | #define CMD_CNOTICE "CNOTICE" | |
39 | #define CMD_CONNECT "CONNECT" | |
40 | #define CMD_CPRIVMSG "CPRIVMSG" | |
41 | #define CMD_CREATE "CREATE" | |
42 | #define CMD_DESTRUCT "DESTRUCT" | |
43 | #define CMD_DESYNCH "DESYNCH" | |
44 | #define CMD_DIE "DIE" | |
45 | #define CMD_DNS "DNS" | |
46 | #define CMD_EOB "END_OF_BURST" | |
47 | #define CMD_EOB_ACK "EOB_ACK" | |
48 | #define CMD_ERROR "ERROR" | |
49 | #define CMD_FAKEHOST "FAKE" | |
50 | #define CMD_GET "GET" | |
51 | #define CMD_GLINE "GLINE" | |
52 | #define CMD_HASH "HASH" | |
53 | #define CMD_HELP "HELP" | |
54 | #define CMD_INFO "INFO" | |
55 | #define CMD_INVITE "INVITE" | |
56 | #define CMD_ISON "ISON" | |
57 | #define CMD_JOIN "JOIN" | |
58 | #define CMD_JUPE "JUPE" | |
59 | #define CMD_KICK "KICK" | |
60 | #define CMD_KILL "KILL" | |
61 | #define CMD_LINKS "LINKS" | |
62 | #define CMD_LIST "LIST" | |
63 | #define CMD_LUSERS "LUSERS" | |
64 | #define CMD_MAP "MAP" | |
23475fc6 | 65 | #define CMD_MARK "MARK" |
d76ed9a9 AS |
66 | #define CMD_MODE "MODE" |
67 | #define CMD_MOTD "MOTD" | |
68 | #define CMD_NAMES "NAMES" | |
69 | #define CMD_NICK "NICK" | |
70 | #define CMD_NOTICE "NOTICE" | |
71 | #define CMD_OPER "OPER" | |
72 | #define CMD_OPMODE "OPMODE" | |
73 | #define CMD_PART "PART" | |
74 | #define CMD_PASS "PASS" | |
75 | #define CMD_PING "PING" | |
76 | #define CMD_PONG "PONG" | |
77 | #define CMD_POST "POST" | |
78 | #define CMD_PRIVMSG "PRIVMSG" | |
79 | #define CMD_PRIVS "PRIVS" | |
80 | #define CMD_PROTO "PROTO" | |
81 | #define CMD_QUIT "QUIT" | |
82 | #define CMD_REHASH "REHASH" | |
e10feb7a | 83 | #define CMD_REMOVE "REMOVE" |
d76ed9a9 AS |
84 | #define CMD_RESET "RESET" |
85 | #define CMD_RESTART "RESTART" | |
86 | #define CMD_RPING "RPING" | |
87 | #define CMD_RPONG "RPONG" | |
88 | #define CMD_SERVER "SERVER" | |
89 | #define CMD_SERVLIST "SERVLIST" | |
90 | #define CMD_SERVSET "SERVSET" | |
91 | #define CMD_SET "SET" | |
92 | #define CMD_SETTIME "SETTIME" | |
59b38cc0 | 93 | #define CMD_SGLINE "SGLINE" |
d914d1cb | 94 | #define CMD_SHUN "SHUN" |
d76ed9a9 | 95 | #define CMD_SILENCE "SILENCE" |
56b83e80 | 96 | #define CMD_SMO "SMO" |
1c76f1b4 | 97 | #define CMD_SNO "SNO" |
59b38cc0 | 98 | #define CMD_SSHUN "SSHUN" |
4b2dcc0d | 99 | #define CMD_SPAMFILTER "SPAMFILTER" |
d76ed9a9 AS |
100 | #define CMD_SQUERY "SQUERY" |
101 | #define CMD_SQUIT "SQUIT" | |
102 | #define CMD_STATS "STATS" | |
cd25f2e9 | 103 | #define CMD_SVSJOIN "SVSJOIN" |
d76ed9a9 | 104 | #define CMD_SVSNICK "SVSNICK" |
cd25f2e9 | 105 | #define CMD_SVSPART "SVSPART" |
5e6460e4 | 106 | #define CMD_SVSQUIT "SVSQUIT" |
56958740 | 107 | #define CMD_SWHOIS "SWHOIS" |
d76ed9a9 AS |
108 | #define CMD_TIME "TIME" |
109 | #define CMD_TOPIC "TOPIC" | |
110 | #define CMD_TRACE "TRACE" | |
111 | #define CMD_UPING "UPING" | |
112 | #define CMD_USER "USER" | |
113 | #define CMD_USERHOST "USERHOST" | |
114 | #define CMD_USERIP "USERIP" | |
115 | #define CMD_VERSION "VERSION" | |
116 | #define CMD_WALLCHOPS "WALLCHOPS" | |
117 | #define CMD_WALLOPS "WALLOPS" | |
55342ce8 | 118 | #define CMD_WALLHOPS "WALLHOPS" |
d76ed9a9 AS |
119 | #define CMD_WALLUSERS "WALLUSERS" |
120 | #define CMD_WALLVOICES "WALLVOICES" | |
55342ce8 | 121 | #define CMD_WALLHOPS "WALLHOPS" |
d76ed9a9 AS |
122 | #define CMD_WHO "WHO" |
123 | #define CMD_WHOIS "WHOIS" | |
124 | #define CMD_WHOWAS "WHOWAS" | |
e10feb7a | 125 | #define CMD_ZLINE "ZLINE" |
d76ed9a9 AS |
126 | |
127 | /* Tokenized commands. */ | |
128 | #define TOK_ACCOUNT "AC" | |
129 | #define TOK_ADMIN "AD" | |
763de701 | 130 | #define TOK_ALIST "AL" |
d76ed9a9 AS |
131 | #define TOK_ASLL "LL" |
132 | #define TOK_AWAY "A" | |
133 | #define TOK_BURST "B" | |
134 | #define TOK_CLEARMODE "CM" | |
135 | #define TOK_CLOSE "CLOSE" | |
136 | #define TOK_CNOTICE "CN" | |
137 | #define TOK_CONNECT "CO" | |
138 | #define TOK_CPRIVMSG "CP" | |
139 | #define TOK_CREATE "C" | |
140 | #define TOK_DESTRUCT "DE" | |
141 | #define TOK_DESYNCH "DS" | |
142 | #define TOK_DIE "DIE" | |
143 | #define TOK_DNS "DNS" | |
144 | #define TOK_EOB "EB" | |
145 | #define TOK_EOB_ACK "EA" | |
146 | #define TOK_ERROR "Y" | |
fede8b64 | 147 | #define TOK_EXEMPT "EX" |
d76ed9a9 AS |
148 | #define TOK_FAKEHOST "FA" |
149 | #define TOK_GET "GET" | |
150 | #define TOK_GLINE "GL" | |
151 | #define TOK_HASH "HASH" | |
152 | #define TOK_HELP "HELP" | |
153 | #define TOK_INFO "F" | |
154 | #define TOK_INVITE "I" | |
155 | #define TOK_ISON "ISON" | |
156 | #define TOK_JOIN "J" | |
157 | #define TOK_JUPE "JU" | |
158 | #define TOK_KICK "K" | |
159 | #define TOK_KILL "D" | |
160 | #define TOK_LINKS "LI" | |
161 | #define TOK_LIST "LIST" | |
162 | #define TOK_LUSERS "LU" | |
163 | #define TOK_MAP "MAP" | |
23475fc6 | 164 | #define TOK_MARK "MK" |
d76ed9a9 AS |
165 | #define TOK_MODE "M" |
166 | #define TOK_MOTD "MO" | |
167 | #define TOK_NAMES "E" | |
168 | #define TOK_NICK "N" | |
169 | #define TOK_NOTICE "O" | |
170 | #define TOK_OPER "OPER" | |
171 | #define TOK_OPMODE "OM" | |
172 | #define TOK_PART "L" | |
173 | #define TOK_PASS "PA" | |
174 | #define TOK_PING "G" | |
175 | #define TOK_PONG "Z" | |
176 | #define TOK_POST "POST" | |
177 | #define TOK_PRIVMSG "P" | |
178 | #define TOK_PRIVS "PRIVS" | |
179 | #define TOK_PROTO "PROTO" | |
180 | #define TOK_QUIT "Q" | |
181 | #define TOK_REHASH "REHASH" | |
e10feb7a | 182 | #define TOK_REMOVE "RM" |
d76ed9a9 AS |
183 | #define TOK_RESET "RESET" |
184 | #define TOK_RESTART "RESTART" | |
185 | #define TOK_RPING "RI" | |
186 | #define TOK_RPONG "RO" | |
187 | #define TOK_SERVER "S" | |
188 | #define TOK_SERVLIST "SERVSET" | |
189 | #define TOK_SERVSET "SERVSET" | |
190 | #define TOK_SET "SET" | |
191 | #define TOK_SETTIME "SE" | |
59b38cc0 | 192 | #define TOK_SGLINE "SGL" |
d914d1cb | 193 | #define TOK_SHUN "SU" |
d76ed9a9 | 194 | #define TOK_SILENCE "U" |
56b83e80 | 195 | #define TOK_SMO "SMO" |
1c76f1b4 | 196 | #define TOK_SNO "SNO" |
59b38cc0 | 197 | #define TOK_SSHUN "SSU" |
4b2dcc0d | 198 | #define TOK_SPAMFILTER "SF" |
d76ed9a9 AS |
199 | #define TOK_SQUERY "SQUERY" |
200 | #define TOK_SQUIT "SQ" | |
201 | #define TOK_STATS "R" | |
cd25f2e9 | 202 | #define TOK_SVSJOIN "SJ" |
d76ed9a9 | 203 | #define TOK_SVSNICK "SN" |
cd25f2e9 | 204 | #define TOK_SVSPART "SP" |
5e6460e4 | 205 | #define TOK_SVSQUIT "SX" |
56958740 | 206 | #define TOK_SWHOIS "SW" |
d76ed9a9 AS |
207 | #define TOK_TIME "TI" |
208 | #define TOK_TOPIC "T" | |
209 | #define TOK_TRACE "TR" | |
210 | #define TOK_UPING "UP" | |
211 | #define TOK_USER "USER" | |
212 | #define TOK_USERHOST "USERHOST" | |
213 | #define TOK_USERIP "USERIP" | |
214 | #define TOK_VERSION "V" | |
215 | #define TOK_WALLCHOPS "WC" | |
216 | #define TOK_WALLOPS "WA" | |
55342ce8 | 217 | #define TOK_WALLHOPS "WH" |
d76ed9a9 AS |
218 | #define TOK_WALLUSERS "WU" |
219 | #define TOK_WALLVOICES "WV" | |
55342ce8 | 220 | #define TOK_WALLHOPS "WH" |
d76ed9a9 AS |
221 | #define TOK_WHO "H" |
222 | #define TOK_WHOIS "W" | |
223 | #define TOK_WHOWAS "X" | |
e10feb7a | 224 | #define TOK_ZLINE "ZL" |
d76ed9a9 AS |
225 | |
226 | /* Protocol messages; aliased to full commands or tokens depending | |
227 | on compile-time configuration. ircu prefers tokens WITH THE | |
228 | EXCEPTION OF THE SERVER AND PASS COMMANDS, which cannot be | |
229 | tokenized, because clients' (ie. a linking server) commands are | |
230 | only checked against the full command list. | |
231 | */ | |
232 | #if defined(ENABLE_TOKENS) | |
233 | #define TYPE(NAME) TOK_ ## NAME | |
234 | #else /* !ENABLE_TOKENS */ | |
235 | #define TYPE(NAME) CMD_ ## NAME | |
236 | #endif /* ENABLE_TOKENS */ | |
237 | ||
238 | #define P10_ACCOUNT TYPE(ACCOUNT) | |
239 | #define P10_ADMIN TYPE(ADMIN) | |
240 | #define P10_ASLL TYPE(ASLL) | |
241 | #define P10_AWAY TYPE(AWAY) | |
242 | #define P10_BURST TYPE(BURST) | |
243 | #define P10_CLEARMODE TYPE(CLEARMODE) | |
244 | #define P10_CLOSE TYPE(CLOSE) | |
245 | #define P10_CNOTICE TYPE(CNOTICE) | |
246 | #define P10_CONNECT TYPE(CONNECT) | |
247 | #define P10_CPRIVMSG TYPE(CPRIVMSG) | |
248 | #define P10_CREATE TYPE(CREATE) | |
249 | #define P10_DESTRUCT TYPE(DESTRUCT) | |
250 | #define P10_DESYNCH TYPE(DESYNCH) | |
251 | #define P10_DIE TYPE(DIE) | |
252 | #define P10_DNS TYPE(DNS) | |
253 | #define P10_EOB TYPE(EOB) | |
254 | #define P10_EOB_ACK TYPE(EOB_ACK) | |
255 | #define P10_ERROR TYPE(ERROR) | |
256 | #define P10_FAKEHOST TYPE(FAKEHOST) | |
257 | #define P10_GET TYPE(GET) | |
258 | #define P10_GLINE TYPE(GLINE) | |
259 | #define P10_HASH TYPE(HASH) | |
260 | #define P10_HELP TYPE(HELP) | |
261 | #define P10_INFO TYPE(INFO) | |
262 | #define P10_INVITE TYPE(INVITE) | |
263 | #define P10_ISON TYPE(ISON) | |
264 | #define P10_JOIN TYPE(JOIN) | |
265 | #define P10_JUPE TYPE(JUPE) | |
266 | #define P10_KICK TYPE(KICK) | |
267 | #define P10_KILL TYPE(KILL) | |
268 | #define P10_LINKS TYPE(LINKS) | |
269 | #define P10_LIST TYPE(LIST) | |
270 | #define P10_LUSERS TYPE(LUSERS) | |
271 | #define P10_MAP TYPE(MAP) | |
23475fc6 | 272 | #define P10_MARK TYPE(MARK) |
d76ed9a9 AS |
273 | #define P10_MODE TYPE(MODE) |
274 | #define P10_MOTD TYPE(MOTD) | |
275 | #define P10_NAMES TYPE(NAMES) | |
276 | #define P10_NICK TYPE(NICK) | |
277 | #define P10_NOTICE TYPE(NOTICE) | |
278 | #define P10_OPER TYPE(OPER) | |
279 | #define P10_OPMODE TYPE(OPMODE) | |
280 | #define P10_PART TYPE(PART) | |
281 | #define P10_PASS CMD_PASS | |
282 | #define P10_PING TYPE(PING) | |
283 | #define P10_PONG TYPE(PONG) | |
284 | #define P10_POST TYPE(POST) | |
285 | #define P10_PRIVMSG TYPE(PRIVMSG) | |
286 | #define P10_PRIVS TYPE(PRIVS) | |
287 | #define P10_PROTO TYPE(PROTO) | |
288 | #define P10_QUIT TYPE(QUIT) | |
289 | #define P10_REHASH TYPE(REHASH) | |
e10feb7a | 290 | #define P10_REMOVE TYPE(REMOVE) |
d76ed9a9 AS |
291 | #define P10_RESET TYPE(RESET) |
292 | #define P10_RESTART TYPE(RESTART) | |
293 | #define P10_RPING TYPE(RPING) | |
294 | #define P10_RPONG TYPE(RPONG) | |
295 | #define P10_SERVER CMD_SERVER | |
296 | #define P10_SERVLIST TYPE(SERVLIST) | |
297 | #define P10_SERVSET TYPE(SERVSET) | |
298 | #define P10_SET TYPE(SET) | |
299 | #define P10_SETTIME TYPE(SETTIME) | |
59b38cc0 | 300 | #define P10_SGLINE TYPE(SGLINE) |
d914d1cb | 301 | #define P10_SHUN TYPE(SHUN) |
d76ed9a9 | 302 | #define P10_SILENCE TYPE(SILENCE) |
56b83e80 | 303 | #define P10_SMO TYPE(SMO) |
1c76f1b4 | 304 | #define P10_SNO TYPE(SNO) |
59b38cc0 | 305 | #define P10_SSHUN TYPE(SSHUN) |
4b2dcc0d | 306 | #define P10_SPAMFILTER TYPE(SPAMFILTER) |
d76ed9a9 AS |
307 | #define P10_SQUERY TYPE(SQUERY) |
308 | #define P10_SQUIT TYPE(SQUIT) | |
309 | #define P10_STATS TYPE(STATS) | |
cd25f2e9 | 310 | #define P10_SVSJOIN TYPE(SVSJOIN) |
d76ed9a9 | 311 | #define P10_SVSNICK TYPE(SVSNICK) |
cd25f2e9 | 312 | #define P10_SVSPART TYPE(SVSPART) |
5e6460e4 | 313 | #define P10_SVSQUIT TYPE(SVSQUIT) |
56958740 | 314 | #define P10_SWHOIS TYPE(SWHOIS) |
d76ed9a9 AS |
315 | #define P10_TIME TYPE(TIME) |
316 | #define P10_TOPIC TYPE(TOPIC) | |
317 | #define P10_TRACE TYPE(TRACE) | |
318 | #define P10_UPING TYPE(UPING) | |
319 | #define P10_USER TYPE(USER) | |
320 | #define P10_USERHOST TYPE(USERHOST) | |
321 | #define P10_USERIP TYPE(USERIP) | |
322 | #define P10_VERSION TYPE(VERSION) | |
323 | #define P10_WALLCHOPS TYPE(WALLCHOPS) | |
324 | #define P10_WALLOPS TYPE(WALLOPS) | |
55342ce8 | 325 | #define P10_WALLHOPS TYPE(WALLHOPS) |
d76ed9a9 AS |
326 | #define P10_WALLUSERS TYPE(WALLUSERS) |
327 | #define P10_WALLVOICES TYPE(WALLVOICES) | |
328 | #define P10_WHO TYPE(WHO) | |
329 | #define P10_WHOIS TYPE(WHOIS) | |
330 | #define P10_WHOWAS TYPE(WHOWAS) | |
e10feb7a | 331 | #define P10_ZLINE TYPE(ZLINE) |
850bf0cf | 332 | #define P10_EXEMPT TYPE(EXEMPT) |
d76ed9a9 AS |
333 | |
334 | /* Servers claiming to have a boot or link time before PREHISTORY | |
335 | * trigger errors to the log. We hope no server has been running | |
336 | * constantly since September 1994. :) | |
337 | */ | |
338 | #define PREHISTORY 780000000 | |
339 | ||
08895577 | 340 | #define MODELEN 40 + KEYLEN |
341 | ||
d76ed9a9 AS |
342 | static struct server *servers_num[64*64]; |
343 | static privmsg_func_t *privmsg_funcs; | |
344 | static unsigned int num_privmsg_funcs; | |
345 | static privmsg_func_t *notice_funcs; | |
346 | static unsigned int num_notice_funcs; | |
347 | static struct dict *unbursted_channels; | |
1136f709 | 348 | static const char *his_servername; |
349 | static const char *his_servercomment; | |
805e7c7a | 350 | static int extended_accounts; |
d76ed9a9 | 351 | |
8d882965 MB |
352 | /* These correspond to 1 << X: 01234567890123456789012345 */ |
353 | const char irc_user_mode_chars[] = "oOiw dkgh x BnIX azDRWHLq"; | |
57fdf922 | 354 | |
d76ed9a9 AS |
355 | static struct userNode *AddUser(struct server* uplink, const char *nick, const char *ident, const char *hostname, const char *modes, const char *numeric, const char *userinfo, time_t timestamp, const char *realip); |
356 | ||
357 | extern int off_channel; | |
08895577 | 358 | extern int DefConLevel; |
08895577 | 359 | extern int DefConTimeOut; |
360 | extern char *DefConChanModes; | |
d76ed9a9 | 361 | |
2f61d1d7 | 362 | static int parse_oplevel(char *str); |
363 | ||
89d871d8 | 364 | char privbuf[512] = ""; |
365 | ||
d76ed9a9 AS |
366 | /* Numerics can be XYY, XYYY, or XXYYY; with X's identifying the |
367 | * server and Y's indentifying the client on that server. */ | |
368 | struct server* | |
369 | GetServerN(const char *numeric) | |
370 | { | |
371 | switch (strlen(numeric)) { | |
372 | default: | |
373 | return servers_num[base64toint(numeric, 2)]; | |
374 | case 4: | |
375 | case 3: | |
376 | case 1: | |
377 | return servers_num[base64toint(numeric, 1)]; | |
378 | case 0: | |
379 | return NULL; | |
380 | } | |
381 | } | |
382 | ||
383 | struct userNode* | |
384 | GetUserN(const char *numeric) /* using numeric */ | |
385 | { | |
386 | struct userNode *un; | |
387 | struct server *s; | |
388 | int n, slen, ulen; | |
389 | ||
390 | switch (strlen(numeric)) { | |
391 | default: | |
392 | log_module(MAIN_LOG, LOG_WARNING, "GetUserN(%s): numeric too long!", numeric); | |
393 | return NULL; | |
394 | case 5: slen = 2; ulen = 3; break; | |
395 | case 4: slen = 1; ulen = 3; break; | |
396 | case 3: slen = 1; ulen = 2; break; | |
397 | case 2: case 1: case 0: | |
398 | log_module(MAIN_LOG, LOG_WARNING, "GetUserN(%s): numeric too short!", numeric); | |
399 | return NULL; | |
400 | } | |
401 | if (!(s = servers_num[base64toint(numeric, slen)])) { | |
402 | log_module(MAIN_LOG, LOG_WARNING, "GetUserN(%s): couldn't find server (len=%d)!", numeric, slen); | |
403 | return NULL; | |
404 | } | |
405 | n = base64toint(numeric+slen, ulen) & s->num_mask; | |
406 | if (!(un = s->users[n])) { | |
407 | log_module(MAIN_LOG, LOG_WARNING, "GetUserN(%s) couldn't find user!", numeric); | |
408 | } | |
409 | return un; | |
410 | } | |
411 | ||
da5b7dfc AS |
412 | extern struct userNode *opserv; |
413 | static void | |
414 | check_ctcp(struct userNode *user, struct userNode *bot, char *text, UNUSED_ARG(int server_qualified)) | |
415 | { | |
416 | char *cmd; | |
417 | /* if its a version reply, do an alert check (only alerts with version=something) */ | |
418 | if(bot == opserv) { | |
419 | if(text[0] == '\001') { | |
420 | text++; | |
421 | cmd = mysep(&text, " "); | |
422 | if(!irccasecmp(cmd, "VERSION")) { | |
423 | char *version = mysep(&text, "\n"); | |
424 | if(!version) | |
425 | version = ""; | |
426 | /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */ | |
427 | /* TODO: setup a ctcp_funcs thing to handle this and other CTCPS properly */ | |
428 | user->version_reply = strdup(version); | |
429 | /* TODO: put this in the db */ | |
430 | if(match_ircglob(version, "WebTV;*")) | |
431 | user->no_notice = true; /* webbies cant see notices */ | |
432 | } | |
433 | } | |
434 | } | |
435 | } | |
436 | ||
437 | ||
d76ed9a9 AS |
438 | static void |
439 | privmsg_user_helper(struct userNode *un, void *data) | |
440 | { | |
441 | struct privmsg_desc *pd = data; | |
442 | unsigned int num = un->num_local; | |
443 | if (!pd->is_notice) { | |
444 | if ((num < num_privmsg_funcs) && privmsg_funcs[num]) { | |
445 | privmsg_funcs[num](pd->user, un, pd->text, pd->is_qualified); | |
446 | } | |
447 | } else { | |
448 | if ((num < num_notice_funcs) && notice_funcs[num]) { | |
da5b7dfc | 449 | check_ctcp(pd->user, un, pd->text, pd->is_qualified); |
d76ed9a9 AS |
450 | notice_funcs[num](pd->user, un, pd->text, pd->is_qualified); |
451 | } | |
452 | } | |
453 | } | |
454 | ||
47956fc5 AS |
455 | /* equiv to user doing /connect server port target */ |
456 | void irc_connect(struct userNode *user, char *server, unsigned int port, struct server *target) | |
457 | { | |
458 | putsock("%s " P10_CONNECT " %s %d %s", user->numeric, server, port, target->numeric); | |
459 | } | |
460 | ||
461 | void | |
462 | irc_squit_route(struct server *srv, const char *message, ...) | |
463 | { | |
464 | va_list arg_list; | |
465 | char buffer[MAXLEN]; | |
466 | va_start(arg_list, message); | |
467 | vsnprintf(buffer, MAXLEN-2, message, arg_list); | |
468 | buffer[MAXLEN-1] = 0; | |
469 | ||
470 | /* When would we squit ourselves exactly?? -Rubin */ | |
471 | if(srv == self && cManager.uplink->state == CONNECTED ) { | |
472 | unsigned int i; | |
473 | ||
474 | /* Quit all clients linked to me. */ | |
475 | for(i = 0; i <= self->num_mask; i++) { | |
476 | if(!self->users[i]) | |
477 | continue; | |
478 | irc_quit(self->users[i], buffer); | |
479 | } | |
480 | } | |
481 | ||
482 | putsock("%s " P10_SQUIT " %s %d :%s", self->numeric, srv->name, 0, buffer); | |
483 | ||
484 | if(srv == self) { | |
485 | /* Force a reconnect to the currently selected server. */ | |
486 | cManager.uplink->tries = 0; | |
487 | log_module(MAIN_LOG, LOG_INFO, "Squitting from uplink: %s", buffer); | |
488 | close_socket(); | |
489 | } | |
490 | } | |
491 | ||
d76ed9a9 AS |
492 | void |
493 | irc_server(struct server *srv) | |
494 | { | |
495 | char extranum[COMBO_NUMERIC_LEN+1]; | |
496 | ||
497 | inttobase64(extranum, srv->num_mask, (srv->numeric[1] || (srv->num_mask >= 64*64)) ? 3 : 2); | |
498 | if (srv == self) { | |
a837dcf5 | 499 | putsock(P10_SERVER " %s %d " FMT_TIME_T " " FMT_TIME_T " J10 %s%s +s6 :%s", |
1136f709 | 500 | srv->name, srv->hops+1, srv->boot, srv->link_time, srv->numeric, extranum, srv->description); |
d76ed9a9 | 501 | } else { |
a837dcf5 | 502 | putsock("%s " P10_SERVER " %s %d " FMT_TIME_T " " FMT_TIME_T " %c10 %s%s +s6 :%s", |
1136f709 | 503 | self->numeric, srv->name, srv->hops+1, srv->boot, srv->link_time, (srv->self_burst ? 'J' : 'P'), srv->numeric, extranum, srv->description); |
d76ed9a9 AS |
504 | } |
505 | } | |
506 | ||
cf8bedff | 507 | void |
2f61d1d7 | 508 | irc_p10_pton(irc_in_addr_t *ip, const char *input) |
509 | { | |
510 | if (strlen(input) == 6) { | |
511 | unsigned int value; | |
512 | memset(ip, 0, 6 * sizeof(ip->in6[0])); | |
513 | value = base64toint(input, 6); | |
514 | if (value) | |
515 | ip->in6[5] = htons(65535); | |
516 | ip->in6[6] = htons(value >> 16); | |
517 | ip->in6[7] = htons(value & 65535); | |
518 | } else { | |
519 | unsigned int pos = 0; | |
520 | do { | |
521 | if (*input == '_') { | |
522 | unsigned int left; | |
7da677be | 523 | for (left = (25 - strlen(input)) / 3 - pos; left; left--) |
2f61d1d7 | 524 | ip->in6[pos++] = 0; |
525 | input++; | |
526 | } else { | |
527 | ip->in6[pos++] = ntohs(base64toint(input, 3)); | |
528 | input += 3; | |
529 | } | |
530 | } while (pos < 8); | |
531 | } | |
532 | } | |
533 | ||
cf8bedff | 534 | void |
2f61d1d7 | 535 | irc_p10_ntop(char *output, const irc_in_addr_t *ip) |
536 | { | |
537 | if (!irc_in_addr_is_valid(*ip)) { | |
538 | strcpy(output, "AAAAAA"); | |
539 | } else if (irc_in_addr_is_ipv4(*ip)) { | |
540 | unsigned int in4; | |
541 | in4 = (ntohs(ip->in6[6]) << 16) | ntohs(ip->in6[7]); | |
542 | inttobase64(output, in4, 6); | |
543 | output[6] = '\0'; | |
544 | } else if (irc_in_addr_is_ipv6(*ip)) { | |
545 | unsigned int max_start, max_zeros, curr_zeros, zero, ii; | |
546 | /* Can start by printing out the leading non-zero parts. */ | |
547 | for (ii = 0; (ip->in6[ii]) && (ii < 8); ++ii) { | |
548 | inttobase64(output, ntohs(ip->in6[ii]), 3); | |
549 | output += 3; | |
550 | } | |
551 | /* Find the longest run of zeros. */ | |
552 | for (max_start = zero = ii, max_zeros = curr_zeros = 0; ii < 8; ++ii) { | |
553 | if (!ip->in6[ii]) | |
554 | curr_zeros++; | |
555 | else if (curr_zeros > max_zeros) { | |
556 | max_start = ii - curr_zeros; | |
557 | max_zeros = curr_zeros; | |
558 | curr_zeros = 0; | |
559 | } | |
560 | } | |
561 | if (curr_zeros > max_zeros) { | |
562 | max_start = ii - curr_zeros; | |
563 | max_zeros = curr_zeros; | |
564 | curr_zeros = 0; | |
565 | } | |
566 | /* Print the rest of the address */ | |
567 | for (ii = zero; ii < 8; ) { | |
568 | if ((ii == max_start) && max_zeros) { | |
569 | *output++ = '_'; | |
570 | ii += max_zeros; | |
571 | } else { | |
572 | inttobase64(output, ntohs(ip->in6[ii]), 3); | |
573 | output += 3; | |
574 | } | |
575 | } | |
576 | *output = '\0'; | |
577 | } else { | |
578 | strcpy(output, "???"); | |
579 | } | |
580 | } | |
581 | ||
d76ed9a9 AS |
582 | void |
583 | irc_user(struct userNode *user) | |
584 | { | |
2f61d1d7 | 585 | char b64ip[25]; |
1136f709 | 586 | if (!user || IsDummy(user)) |
d76ed9a9 | 587 | return; |
2f61d1d7 | 588 | irc_p10_ntop(b64ip, &user->ip); |
d76ed9a9 | 589 | if (user->modes) { |
d76ed9a9 AS |
590 | char modes[32]; |
591 | ||
57fdf922 | 592 | irc_user_modes(user, modes, sizeof(modes)); |
d76ed9a9 | 593 | /* we don't need to put the + in modes because it's in the format string. */ |
a837dcf5 | 594 | putsock("%s " P10_NICK " %s %d " FMT_TIME_T " %s %s +%s %s %s :%s", |
d76ed9a9 AS |
595 | user->uplink->numeric, user->nick, user->uplink->hops+1, user->timestamp, user->ident, user->hostname, modes, b64ip, user->numeric, user->info); |
596 | } else { | |
a837dcf5 | 597 | putsock("%s " P10_NICK " %s %d " FMT_TIME_T " %s %s %s %s :%s", |
d76ed9a9 AS |
598 | user->uplink->numeric, user->nick, user->uplink->hops+1, user->timestamp, user->ident, user->hostname, b64ip, user->numeric, user->info); |
599 | } | |
600 | } | |
601 | ||
a45e6ec7 | 602 | void |
603 | irc_rename(struct userNode *user, const char *new_handle) | |
604 | { | |
805e7c7a AS |
605 | if(extended_accounts) |
606 | putsock("%s " P10_ACCOUNT " %s M %s", self->numeric, user->numeric, new_handle); | |
a45e6ec7 | 607 | } |
608 | ||
609 | void | |
610 | irc_delete(struct userNode *user) | |
611 | { | |
805e7c7a AS |
612 | if(extended_accounts) |
613 | putsock("%s " P10_ACCOUNT " %s U", self->numeric, user->numeric); | |
a45e6ec7 | 614 | } |
615 | ||
d76ed9a9 | 616 | void |
b21e2cfe | 617 | irc_account(struct userNode *user, const char *stamp, time_t timestamp) |
d76ed9a9 | 618 | { |
805e7c7a | 619 | if(extended_accounts) |
a837dcf5 | 620 | putsock("%s " P10_ACCOUNT " %s R %s "FMT_TIME_T, self->numeric, user->numeric, stamp, timestamp); |
805e7c7a | 621 | else |
a837dcf5 | 622 | putsock("%s " P10_ACCOUNT " %s %s "FMT_TIME_T, self->numeric, user->numeric, stamp, timestamp); |
d76ed9a9 AS |
623 | } |
624 | ||
625 | void | |
626 | irc_fakehost(struct userNode *user, const char *host) | |
627 | { | |
628 | putsock("%s " P10_FAKEHOST " %s %s", self->numeric, user->numeric, host); | |
629 | } | |
630 | ||
631 | void | |
632 | irc_regnick(UNUSED_ARG(struct userNode *user)) | |
633 | { | |
634 | /* no operation here */ | |
635 | } | |
636 | ||
637 | void | |
638 | irc_nick(struct userNode *user, UNUSED_ARG(const char *old_nick)) | |
639 | { | |
640 | putsock("%s " P10_NICK " %s "FMT_TIME_T, user->numeric, user->nick, now); | |
641 | } | |
642 | ||
643 | void | |
644 | irc_fetchtopic(struct userNode *from, const char *to) | |
645 | { | |
646 | if (!from || !to) | |
647 | return; | |
648 | putsock("%s " P10_TOPIC " %s", from->numeric, to); | |
649 | } | |
650 | ||
651 | void | |
652 | irc_squit(struct server *srv, const char *message, const char *service_message) | |
653 | { | |
654 | if (!service_message) | |
655 | service_message = message; | |
656 | ||
657 | /* Are we leaving the network? */ | |
658 | if (srv == self && cManager.uplink->state == CONNECTED) { | |
659 | unsigned int i; | |
660 | ||
661 | /* Quit all clients linked to me. */ | |
662 | for (i = 0; i <= self->num_mask; i++) { | |
663 | if (!self->users[i]) | |
664 | continue; | |
665 | irc_quit(self->users[i], service_message); | |
666 | } | |
667 | } | |
668 | ||
669 | putsock("%s " P10_SQUIT " %s %d :%s", self->numeric, srv->name, 0, message); | |
670 | ||
671 | if (srv == self) { | |
672 | /* Force a reconnect to the currently selected server. */ | |
673 | cManager.uplink->tries = 0; | |
674 | log_module(MAIN_LOG, LOG_INFO, "Squitting from uplink: %s", message); | |
675 | close_socket(); | |
676 | } | |
677 | } | |
678 | ||
679 | void | |
680 | irc_wallchops(struct userNode *from, const char *to, const char *message) | |
681 | { | |
682 | putsock("%s " P10_WALLCHOPS " %s :%s", from->numeric, to, message); | |
683 | } | |
684 | ||
47956fc5 AS |
685 | void |
686 | irc_wallops(const char *format, ...) | |
687 | { | |
688 | va_list arg_list; | |
689 | char buffer[MAXLEN]; | |
690 | va_start(arg_list, format); | |
691 | vsnprintf(buffer, MAXLEN-2, format, arg_list); | |
692 | buffer[MAXLEN-1] = 0; | |
693 | putsock("%s " P10_WALLOPS " :%s", self->numeric, buffer); | |
694 | } | |
695 | ||
1136f709 | 696 | static int |
697 | deliver_to_dummy(struct userNode *source, struct userNode *dest, const char *message, int type) | |
698 | { | |
699 | unsigned int num; | |
700 | ||
701 | if (!dest || !IsDummy(dest) || !IsLocal(dest)) | |
702 | return 0; | |
703 | num = dest->num_local; | |
704 | switch (type) { | |
705 | default: | |
706 | if ((num < num_notice_funcs) && notice_funcs[num]) | |
707 | notice_funcs[num](source, dest, message, 0); | |
708 | break; | |
709 | case 1: | |
710 | if ((num < num_privmsg_funcs) && privmsg_funcs[num]) | |
711 | privmsg_funcs[num](source, dest, message, 0); | |
712 | break; | |
713 | } | |
714 | return 1; | |
715 | } | |
0e08a8e0 | 716 | |
d76ed9a9 AS |
717 | void |
718 | irc_notice(struct userNode *from, const char *to, const char *message) | |
719 | { | |
1136f709 | 720 | if (to[0] == '#' || to[0] == '$' |
721 | || !deliver_to_dummy(from, GetUserN(to), message, 0)) | |
722 | putsock("%s " P10_NOTICE " %s :%s", from->numeric, to, message); | |
d76ed9a9 AS |
723 | } |
724 | ||
725 | void | |
726 | irc_notice_user(struct userNode *from, struct userNode *to, const char *message) | |
727 | { | |
1136f709 | 728 | if (!deliver_to_dummy(from, to, message, 0)) |
729 | putsock("%s " P10_NOTICE " %s :%s", from->numeric, to->numeric, message); | |
d76ed9a9 AS |
730 | } |
731 | ||
732 | void | |
733 | irc_privmsg(struct userNode *from, const char *to, const char *message) | |
734 | { | |
1136f709 | 735 | if (to[0] == '#' || to[0] == '$' |
736 | || !deliver_to_dummy(from, GetUserN(to), message, 1)) | |
737 | putsock("%s " P10_PRIVMSG " %s :%s", from->numeric, to, message); | |
d76ed9a9 AS |
738 | } |
739 | ||
39c1a4ef | 740 | void |
0e08a8e0 AS |
741 | irc_privmsg_user(struct userNode *from, struct userNode *to, const char *message) |
742 | { | |
743 | putsock("%s " P10_PRIVMSG " %s :%s", from->numeric, to->numeric, message); | |
744 | } | |
745 | ||
746 | void | |
747 | irc_version_user(struct userNode *from, struct userNode *to) | |
748 | { | |
749 | irc_privmsg_user(from, to, "\001VERSION\001"); | |
750 | } | |
751 | ||
d76ed9a9 AS |
752 | void |
753 | irc_eob(void) | |
754 | { | |
755 | putsock("%s " P10_EOB, self->numeric); | |
756 | } | |
757 | ||
758 | void | |
759 | irc_eob_ack(void) | |
760 | { | |
761 | putsock("%s " P10_EOB_ACK, self->numeric); | |
08895577 | 762 | |
763 | char *nick; | |
764 | const char *str; | |
765 | str = conf_get_data("services/opserv/nick", RECDB_QSTRING); | |
766 | nick = strdup(str); | |
767 | ||
768 | if (nick && (DefConLevel < 5)) { | |
769 | DefConProcess(GetUserH(nick)); | |
770 | ||
771 | if (DefConTimeOut > 0) | |
772 | timeq_add(now + DefConTimeOut, defcon_timeout, NULL); | |
773 | } | |
d76ed9a9 AS |
774 | } |
775 | ||
956ee72d | 776 | void |
777 | irc_rpong(const char *from1, const char *from2, const char *pingtime, const char *clientinfo) | |
778 | { | |
779 | putsock("%s " P10_RPONG " %s %s %s :%s", self->numeric, from1, from2, pingtime, clientinfo); | |
780 | } | |
781 | ||
d76ed9a9 AS |
782 | void |
783 | irc_ping(const char *payload) | |
784 | { | |
785 | putsock("%s " P10_PING " :%s", self->numeric, payload); | |
786 | } | |
787 | ||
788 | void | |
789 | irc_pong(const char *who, const char *data) | |
790 | { | |
791 | putsock("%s " P10_PONG " %s :%s", self->numeric, who, data); | |
792 | } | |
793 | ||
2f61d1d7 | 794 | void |
795 | irc_pong_asll(const char *who, const char *orig_ts) | |
796 | { | |
797 | char *delim; | |
798 | struct timeval orig; | |
1136f709 | 799 | struct timeval sys_now; |
2f61d1d7 | 800 | int diff; |
801 | ||
802 | orig.tv_sec = strtoul(orig_ts, &delim, 10); | |
803 | orig.tv_usec = (*delim == '.') ? strtoul(delim + 1, NULL, 10) : 0; | |
1136f709 | 804 | gettimeofday(&sys_now, NULL); |
805 | diff = (sys_now.tv_sec - orig.tv_sec) * 1000 + (sys_now.tv_usec - orig.tv_usec) / 1000; | |
806 | putsock("%s " P10_PONG " %s %s %d %lu.%06lu", self->numeric, who, orig_ts, diff, (unsigned long)sys_now.tv_sec, (unsigned long)sys_now.tv_usec); | |
2f61d1d7 | 807 | } |
808 | ||
d76ed9a9 AS |
809 | void |
810 | irc_pass(const char *passwd) | |
811 | { | |
812 | putsock(P10_PASS " :%s", passwd); | |
813 | } | |
814 | ||
815 | void | |
816 | irc_introduce(const char *passwd) | |
817 | { | |
818 | void timed_send_ping(void *data); | |
819 | ||
820 | self->self_burst = self->burst = 1; | |
821 | irc_pass(passwd); | |
822 | irc_server(self); | |
823 | burst_length = 0; | |
824 | timeq_add(now + ping_freq, timed_send_ping, 0); | |
825 | } | |
826 | ||
827 | void | |
9a75756e | 828 | irc_gline(struct server *srv, struct gline *gline, int silent) |
d76ed9a9 | 829 | { |
995043b4 | 830 | putsock("%s " P10_GLINE " %s +%s " FMT_TIME_T " " FMT_TIME_T " :%s<%s> %s", |
831 | self->numeric, (srv ? srv->numeric : "*"), gline->target, gline->expires-now, now, silent ? "AUTO " : "", gline->issuer, gline->reason); | |
d76ed9a9 AS |
832 | } |
833 | ||
d914d1cb | 834 | void |
835 | irc_shun(struct server *srv, struct shun *shun) | |
836 | { | |
995043b4 | 837 | putsock("%s " P10_SHUN " %s +%s " FMT_TIME_T " :<%s> %s", |
838 | self->numeric, (srv ? srv->numeric : "*"), shun->target, shun->expires-now, shun->issuer, shun->reason); | |
d914d1cb | 839 | } |
840 | ||
d76ed9a9 AS |
841 | void |
842 | irc_settime(const char *srv_name_mask, time_t new_time) | |
843 | { | |
844 | ioset_set_time(new_time); | |
845 | if (!strcmp(srv_name_mask, "*")) | |
846 | srv_name_mask = ""; | |
847 | putsock("%s " P10_SETTIME " " FMT_TIME_T " %s", self->numeric, new_time, srv_name_mask); | |
848 | } | |
849 | ||
850 | void | |
851 | irc_ungline(const char *mask) | |
852 | { | |
853 | putsock("%s " P10_GLINE " * -%s", self->numeric, mask); | |
854 | } | |
855 | ||
d914d1cb | 856 | void |
857 | irc_unshun(const char *mask) | |
858 | { | |
859 | putsock("%s " P10_SHUN " * -%s", self->numeric, mask); | |
860 | } | |
861 | ||
e206ed60 | 862 | void |
d76ed9a9 AS |
863 | irc_burst(struct chanNode *chan) |
864 | { | |
865 | char burst_line[512]; | |
866 | int pos, base_len, len; | |
867 | struct modeNode *mn; | |
868 | struct banNode *bn; | |
2aef5f4b | 869 | struct exemptNode *en; |
d76ed9a9 | 870 | long last_mode=-1; |
1136f709 | 871 | unsigned int first_ban; |
872 | unsigned int first_exempt; | |
d76ed9a9 AS |
873 | unsigned int n; |
874 | ||
875 | base_len = sprintf(burst_line, "%s " P10_BURST " %s " FMT_TIME_T " ", | |
876 | self->numeric, chan->name, chan->timestamp); | |
877 | len = irc_make_chanmode(chan, burst_line+base_len); | |
878 | pos = base_len + len; | |
1136f709 | 879 | if (len > 0 && chan->members.used > 0) |
d76ed9a9 AS |
880 | burst_line[pos++] = ' '; |
881 | ||
d9d33535 AS |
882 | if(chan->members.used < 1) |
883 | return; /* dont burst empty channels (created by discrims) */ | |
d76ed9a9 AS |
884 | /* dump the users */ |
885 | for (n=0; n<chan->members.used; n++) { | |
886 | mn = chan->members.list[n]; | |
887 | if (pos > 500) { | |
888 | burst_line[pos-1] = 0; /* -1 to back up over the space or comma */ | |
889 | putsock("%s", burst_line); | |
890 | pos = base_len; | |
891 | last_mode = -1; | |
892 | } | |
c99dcaf6 | 893 | |
d76ed9a9 AS |
894 | memcpy(burst_line+pos, mn->user->numeric, strlen(mn->user->numeric)); |
895 | pos += strlen(mn->user->numeric); | |
896 | if (mn->modes && (mn->modes != last_mode)) { | |
897 | last_mode = mn->modes; | |
898 | burst_line[pos++] = ':'; | |
899 | if (last_mode & MODE_CHANOP) | |
900 | burst_line[pos++] = 'o'; | |
55342ce8 | 901 | if (last_mode & MODE_HALFOP) |
902 | burst_line[pos++] = 'h'; | |
d76ed9a9 AS |
903 | if (last_mode & MODE_VOICE) |
904 | burst_line[pos++] = 'v'; | |
905 | } | |
906 | if ((n+1)<chan->members.used) | |
907 | burst_line[pos++] = ','; | |
908 | } | |
909 | if (chan->banlist.used) { | |
910 | /* dump the bans */ | |
1136f709 | 911 | first_ban = 1; |
d76ed9a9 | 912 | |
1136f709 | 913 | for (n=0; n<chan->banlist.used; ) { |
914 | if (first_ban && (pos < 500)) { | |
915 | burst_line[pos++] = ':'; | |
916 | burst_line[pos++] = '%'; | |
917 | } | |
d76ed9a9 AS |
918 | bn = chan->banlist.list[n]; |
919 | len = strlen(bn->ban); | |
1136f709 | 920 | if (pos + 2 + len < 505) { |
921 | memcpy(burst_line + pos, bn->ban, len); | |
922 | pos += len; | |
923 | burst_line[pos++] = ' '; | |
924 | first_ban = 0; | |
925 | n++; | |
926 | } else { | |
927 | burst_line[pos-1] = 0; | |
d76ed9a9 AS |
928 | putsock("%s", burst_line); |
929 | pos = base_len; | |
1136f709 | 930 | first_ban = 1; |
d76ed9a9 | 931 | } |
d76ed9a9 AS |
932 | } |
933 | } | |
2aef5f4b | 934 | if (chan->exemptlist.used) { |
1136f709 | 935 | /* dump the exempts */ |
936 | first_exempt = 1; | |
937 | ||
938 | for (n=0; n<chan->exemptlist.used; ) { | |
939 | if (first_exempt && (pos < 500)) { | |
940 | burst_line[pos++] = ' '; | |
941 | burst_line[pos++] = '~'; | |
942 | burst_line[pos++] = ' '; | |
943 | } | |
2aef5f4b | 944 | en = chan->exemptlist.list[n]; |
945 | len = strlen(en->exempt); | |
1136f709 | 946 | if (pos + 2 + len < 505) { |
947 | memcpy(burst_line + pos, en->exempt, len); | |
948 | pos += len; | |
949 | burst_line[pos++] = ' '; | |
950 | first_exempt = 0; | |
951 | n++; | |
952 | } else { | |
953 | burst_line[pos-1] = 0; | |
2aef5f4b | 954 | putsock("%s", burst_line); |
955 | pos = base_len; | |
1136f709 | 956 | first_exempt = 1; |
2aef5f4b | 957 | } |
2aef5f4b | 958 | } |
959 | } | |
d76ed9a9 AS |
960 | /* print the last line */ |
961 | burst_line[pos] = 0; | |
962 | putsock("%s", burst_line); | |
963 | } | |
964 | ||
965 | void | |
966 | irc_quit(struct userNode *user, const char *message) | |
967 | { | |
968 | putsock("%s " P10_QUIT " :%s", user->numeric, message); | |
969 | } | |
970 | ||
971 | void | |
972 | irc_error(const char *to, const char *message) | |
973 | { | |
974 | if (to) { | |
975 | putsock("%s " P10_ERROR " :%s", to, message); | |
976 | } else { | |
977 | putsock(":%s " P10_ERROR " :%s", self->name, message); | |
978 | } | |
979 | } | |
980 | ||
981 | void | |
982 | irc_kill(struct userNode *from, struct userNode *target, const char *message) | |
983 | { | |
984 | if (from) { | |
985 | putsock("%s " P10_KILL " %s :%s!%s (%s)", | |
986 | from->numeric, target->numeric, self->name, from->nick, message); | |
987 | } else { | |
988 | putsock("%s " P10_KILL " %s :%s (%s)", | |
989 | self->numeric, target->numeric, self->name, message); | |
990 | } | |
991 | } | |
992 | ||
993 | void | |
994 | irc_mode(struct userNode *from, struct chanNode *target, const char *modes) | |
995 | { | |
ec311f39 | 996 | call_channel_mode_funcs(from, target, (char **)&modes, 0); |
d76ed9a9 AS |
997 | putsock("%s " P10_MODE " %s %s "FMT_TIME_T, |
998 | (from ? from->numeric : self->numeric), | |
999 | target->name, modes, target->timestamp); | |
1000 | } | |
1001 | ||
5a1daaab AS |
1002 | /* Added to allow services to mode users |
1003 | 2005 - 8 - 10 by Life4Christ | |
1004 | */ | |
1005 | void | |
1006 | irc_umode(struct userNode *target, const char *modes) | |
1007 | { | |
1008 | putsock("%s " P10_MODE " %s %s ",self->numeric,target->nick, modes); | |
1009 | } | |
1010 | ||
1011 | ||
d76ed9a9 AS |
1012 | void |
1013 | irc_invite(struct userNode *from, struct userNode *who, struct chanNode *to) | |
1014 | { | |
1015 | putsock("%s " P10_INVITE " %s %s", from->numeric, who->nick, to->name); | |
1016 | } | |
1017 | ||
5177fd21 | 1018 | void |
1019 | irc_silence(struct userNode *who, const char *mask, int add) | |
1020 | { | |
668dc38e | 1021 | putsock("%s " P10_SILENCE " %s %s%s", self->numeric, who->numeric, add ? "+" : "-", mask); |
5177fd21 | 1022 | } |
1023 | ||
d76ed9a9 AS |
1024 | void |
1025 | irc_join(struct userNode *who, struct chanNode *what) | |
1026 | { | |
1027 | if (what->members.used == 1) { | |
a837dcf5 | 1028 | putsock("%s " P10_CREATE " %s "FMT_TIME_T, |
d76ed9a9 AS |
1029 | who->numeric, what->name, what->timestamp); |
1030 | } else { | |
a837dcf5 | 1031 | putsock("%s " P10_JOIN " %s "FMT_TIME_T, who->numeric, what->name, what->timestamp); |
d76ed9a9 AS |
1032 | } |
1033 | } | |
1034 | ||
cd25f2e9 | 1035 | void |
1036 | irc_svsjoin(struct userNode *from, struct userNode *who, struct chanNode *to) | |
1037 | { | |
1038 | putsock("%s " P10_SVSJOIN " %s %s "FMT_TIME_T, from->uplink->numeric, who->numeric, to->name, now); | |
1039 | } | |
1040 | ||
39c1a4ef | 1041 | void |
1042 | irc_svspart(struct userNode *from, struct userNode *who, struct chanNode *to) | |
1043 | { | |
1044 | putsock("%s " P10_SVSPART " %s %s", from->uplink->numeric, who->numeric, to->name); | |
1045 | } | |
1046 | ||
5e6460e4 | 1047 | void |
f20f0ab5 | 1048 | irc_svsquit(struct userNode *from, struct userNode *who, char const *reason) |
5e6460e4 AS |
1049 | { |
1050 | putsock("%s " P10_SVSQUIT " %s :%s", from->uplink->numeric, who->numeric, reason); | |
1051 | } | |
1052 | ||
d76ed9a9 AS |
1053 | void |
1054 | irc_kick(struct userNode *who, struct userNode *target, struct chanNode *channel, const char *msg) | |
1055 | { | |
1056 | const char *numeric; | |
1057 | struct modeNode *mn = GetUserMode(channel, who); | |
1058 | numeric = ((mn && (mn->modes & MODE_CHANOP)) || off_channel) ? who->numeric : self->numeric; | |
1059 | putsock("%s " P10_KICK " %s %s :%s", | |
1060 | numeric, channel->name, target->numeric, msg); | |
1061 | } | |
1062 | ||
1063 | void | |
1064 | irc_stats(struct userNode *from, struct server *target, char type) | |
1065 | { | |
1066 | putsock("%s " P10_STATS " %c :%s", from->numeric, type, target->numeric); | |
1067 | } | |
1068 | ||
1069 | void | |
1070 | irc_svsnick(struct userNode *from, struct userNode *target, const char *newnick) | |
1071 | { | |
1072 | putsock("%s " P10_SVSNICK " %s %s "FMT_TIME_T, from->uplink->numeric, target->numeric, newnick, now); | |
1073 | } | |
1074 | ||
56958740 | 1075 | void |
1076 | irc_swhois(struct userNode *from, struct userNode *target, const char *message) | |
1077 | { | |
1078 | putsock("%s " P10_SWHOIS " %s %s%s", from->uplink->numeric, target->numeric, message ? ":" : "", | |
1079 | message ? message : ""); | |
1080 | ||
1081 | } | |
1082 | ||
d76ed9a9 AS |
1083 | void |
1084 | irc_part(struct userNode *who, struct chanNode *what, const char *reason) | |
1085 | { | |
1086 | if (reason) { | |
1087 | putsock("%s " P10_PART " %s :%s", who->numeric, what->name, reason); | |
1088 | } else { | |
1089 | putsock("%s " P10_PART " %s", who->numeric, what->name); | |
1090 | } | |
1091 | } | |
1092 | ||
1093 | void | |
7fda2b52 | 1094 | irc_topic(struct userNode *service, struct userNode *who, struct chanNode *what, const char *topic) |
d76ed9a9 | 1095 | { |
7fda2b52 | 1096 | |
da4f9236 | 1097 | int type = 4, host_in_topic = 0, hasident = 0; |
5006460e | 1098 | const char *hstr, *tstr; |
eb43ca8c | 1099 | char *host, *hostmask; |
1100 | char shost[MAXLEN]; | |
1101 | char sident[MAXLEN]; | |
5006460e | 1102 | |
1103 | tstr = conf_get_data("server/type", RECDB_QSTRING); | |
1104 | hstr = conf_get_data("server/host_in_topic", RECDB_QSTRING); | |
1105 | if(tstr) | |
1106 | type = atoi(tstr); | |
b5c80c61 AS |
1107 | else |
1108 | type = 4;/* default to 040 style topics */ | |
a20238a2 | 1109 | |
eb43ca8c | 1110 | if (hstr) { |
1111 | if (IsFakeHost(who)) | |
1112 | safestrncpy(shost, who->fakehost, sizeof(shost)); | |
1113 | else if (IsSetHost(who)) { | |
1114 | hostmask = strdup(who->sethost); | |
da4f9236 | 1115 | if ((host = (strrchr(hostmask, '@')))) { |
1116 | hasident = 1; | |
eb43ca8c | 1117 | *host++ = '\0'; |
da4f9236 | 1118 | } else |
eb43ca8c | 1119 | host = hostmask; |
1120 | ||
da4f9236 | 1121 | if (hasident) |
1122 | safestrncpy(sident, hostmask, sizeof(shost)); | |
1123 | else | |
1124 | safestrncpy(sident, who->ident, sizeof(shost)); | |
1125 | ||
eb43ca8c | 1126 | safestrncpy(shost, host, sizeof(shost)); |
1127 | } else | |
1128 | safestrncpy(shost, who->hostname, sizeof(shost)); | |
1129 | ||
1130 | host_in_topic = atoi(hstr); | |
1131 | } | |
5006460e | 1132 | |
dd019452 | 1133 | if (type >= 5) { |
5006460e | 1134 | putsock("%s " P10_TOPIC " %s %s%s%s%s%s " FMT_TIME_T " " FMT_TIME_T " :%s", service->numeric, what->name, |
eb43ca8c | 1135 | who->nick, host_in_topic ? "!" : "", host_in_topic ? (IsSetHost(who) ? sident : who->ident) : "", |
1136 | host_in_topic ? "@" : "", host_in_topic ? shost : "", what->timestamp, now, topic); | |
a20238a2 | 1137 | } else { |
b5c80c61 | 1138 | who = service; |
a20238a2 | 1139 | putsock("%s " P10_TOPIC " %s :%s", who->numeric, what->name, topic); |
1140 | } | |
d76ed9a9 AS |
1141 | } |
1142 | ||
1143 | void | |
1144 | irc_raw(const char *what) | |
1145 | { | |
1146 | putsock("%s", what); | |
1147 | } | |
1148 | ||
1149 | void | |
1150 | irc_numeric(struct userNode *user, unsigned int num, const char *format, ...) | |
1151 | { | |
1152 | va_list arg_list; | |
1153 | char buffer[MAXLEN]; | |
1154 | va_start(arg_list, format); | |
1155 | vsnprintf(buffer, MAXLEN-2, format, arg_list); | |
1156 | buffer[MAXLEN-1] = 0; | |
1157 | putsock(":%s %03d %s %s", self->name, num, user->nick, buffer); | |
1158 | } | |
1159 | ||
d82cf2f0 AS |
1160 | void |
1161 | irc_mark(struct userNode *user, char *mark) | |
1162 | { | |
1163 | char *host = user->hostname; | |
2c00fbc2 AS |
1164 | |
1165 | /* TODO: Allow mark overwrite. If they are marked, and their fakehost is oldmark.hostname, update it to newmark.hostname so mark can be called multiple times. Probably requires ircd modification also */ | |
1166 | if(user->mark) | |
1167 | return; | |
1168 | ||
d82cf2f0 AS |
1169 | /* if the mark will put us over the host length, clip some off the left hand side |
1170 | * to make room... | |
1171 | */ | |
1172 | if(strlen(host) + 1 + strlen(mark) > HOSTLEN) | |
1173 | host += 1 + ( (strlen(host) + 1 + strlen(mark)) - HOSTLEN ); | |
1174 | putsock("%s " CMD_MARK " %s DNSBL +m %s.%s", self->numeric, user->nick, mark, host); | |
1175 | putsock("%s " CMD_MARK " %s DNSBL_DATA %s", self->numeric, user->nick, mark); | |
2c00fbc2 AS |
1176 | |
1177 | /* Save it in the user */ | |
1178 | user->mark = strdup(mark); | |
1179 | ||
d82cf2f0 | 1180 | /* If they are not otherwise marked, mark their host with fakehost */ |
537128ea | 1181 | if(!IsFakeHost(user) && !IsSetHost(user) && !(IsHiddenHost(user) && user->handle_info) ) |
d82cf2f0 | 1182 | { |
c99dcaf6 | 1183 | struct modeNode *mn = NULL; |
1184 | char fakehost[HOSTLEN]; | |
1185 | unsigned int count = 0; | |
1186 | unsigned int n = 0; | |
1187 | ||
d82cf2f0 | 1188 | putsock("%s " CMD_FAKEHOST " %s %s.%s", self->numeric, user->numeric, mark, host); |
1b6b5e2f | 1189 | putsock("%s " CMD_MODE " %s +x", self->numeric, user->nick); |
c99dcaf6 | 1190 | |
1191 | snprintf(fakehost, sizeof(fakehost), "%s.%s", mark, host); | |
1192 | safestrncpy(user->fakehost, fakehost, sizeof(user->fakehost)); | |
1193 | ||
1194 | for (n=count=0; n<user->channels.used; n++) { | |
1195 | mn = user->channels.list[n]; | |
1b6b5e2f | 1196 | if (strlen(mn->channel->name) >= 1) /* Sanity */ |
1197 | check_bans(user, mn->channel->name); | |
c99dcaf6 | 1198 | } |
d82cf2f0 AS |
1199 | } |
1200 | } | |
1201 | ||
10be9be0 | 1202 | void irc_sno(unsigned int mask, char const* format, ...) { |
1203 | va_list arg_list; | |
1204 | char buffer[MAXLEN]; | |
1205 | va_start(arg_list, format); | |
1206 | vsnprintf(buffer, MAXLEN-2, format, arg_list); | |
1207 | buffer[MAXLEN-1] = 0; | |
1208 | putsock("%s " CMD_SNO " %d :%s", self->numeric, mask, buffer); | |
1209 | } | |
1210 | ||
d76ed9a9 AS |
1211 | static void send_burst(void); |
1212 | ||
1213 | static void | |
1214 | change_nicklen(int new_nicklen) | |
1215 | { | |
1216 | unsigned int nn; | |
1217 | char new_nick[NICKLEN+1]; | |
1218 | struct userNode *user; | |
1219 | ||
1220 | nicklen = new_nicklen; | |
1221 | /* fix up any users we have here */ | |
1222 | for (nn=0; nn<=self->num_mask; nn++) { | |
1223 | if (!(user = self->users[nn])) | |
1224 | continue; | |
1225 | safestrncpy(new_nick, user->nick, sizeof(new_nick)); | |
1226 | new_nick[nicklen] = 0; | |
1227 | NickChange(user, new_nick, 1); | |
1228 | } | |
1229 | } | |
1230 | ||
1231 | static CMD_FUNC(cmd_whois) | |
1232 | { | |
1233 | struct userNode *from; | |
1234 | struct userNode *who; | |
1136f709 | 1235 | char buf[MAXLEN]; |
1236 | unsigned int i, mlen, len; | |
d76ed9a9 AS |
1237 | |
1238 | if (argc < 3) | |
1239 | return 0; | |
1240 | if (!(from = GetUserH(origin))) { | |
1241 | log_module(MAIN_LOG, LOG_ERROR, "Could not find WHOIS origin user %s", origin); | |
1242 | return 0; | |
1243 | } | |
1136f709 | 1244 | if (!(who = GetUserH(argv[2]))) { |
d76ed9a9 AS |
1245 | irc_numeric(from, ERR_NOSUCHNICK, "%s@%s :No such nick", argv[2], self->name); |
1246 | return 1; | |
1247 | } | |
1136f709 | 1248 | |
1249 | if (IsFakeHost(who) && IsHiddenHost(who)) | |
1250 | irc_numeric(from, RPL_WHOISUSER, "%s %s %s * :%s", who->nick, who->ident, who->fakehost, who->info); | |
1251 | else if (IsHiddenHost(who) && who->handle_info && hidden_host_suffix) | |
1252 | irc_numeric(from, RPL_WHOISUSER, "%s %s %s.%s * :%s", who->nick, who->ident, who->handle_info->handle, hidden_host_suffix, who->info); | |
1253 | else | |
1254 | irc_numeric(from, RPL_WHOISUSER, "%s %s %s * :%s", who->nick, who->ident, who->hostname, who->info); | |
1255 | ||
b6f5999f | 1256 | if (!IsService(who) || (from == who)) { |
1136f709 | 1257 | struct modeNode *mn; |
1258 | mlen = strlen(self->name) + strlen(from->nick) + 12 + strlen(who->nick); | |
1259 | len = 0; | |
1260 | *buf = '\0'; | |
1261 | for (i = who->channels.used; i > 0; ) | |
1262 | { | |
1263 | mn = who->channels.list[--i]; | |
1264 | ||
1265 | if (!IsOper(from) && (mn->channel->modes & (MODE_PRIVATE | MODE_SECRET)) && !GetUserMode(mn->channel, from)) | |
1266 | continue; | |
1267 | ||
1268 | if (len + strlen(mn->channel->name) + mlen > MAXLEN - 5) | |
1269 | { | |
1270 | irc_numeric(from, RPL_WHOISCHANNELS, "%s :%s", who->nick, buf); | |
1271 | *buf = '\0'; | |
1272 | len = 0; | |
1273 | } | |
1274 | ||
1275 | if (IsDeaf(who)) | |
1276 | *(buf + len++) = '-'; | |
1277 | if ((mn->channel->modes & (MODE_PRIVATE | MODE_SECRET)) && !GetUserMode(mn->channel, from)) | |
1278 | *(buf + len++) = '*'; | |
1279 | if (mn->modes & MODE_CHANOP) | |
1280 | *(buf + len++) = '@'; | |
1281 | else if (mn->modes & MODE_HALFOP) | |
1282 | *(buf + len++) = '%'; | |
1283 | else if (mn->modes & MODE_VOICE) | |
1284 | *(buf + len++) = '+'; | |
1285 | ||
1286 | if (len) | |
1287 | *(buf + len) = '\0'; | |
1288 | strcpy(buf + len, mn->channel->name); | |
1289 | len += strlen(mn->channel->name); | |
1290 | strcat(buf + len, " "); | |
1291 | len++; | |
1292 | } | |
1293 | if (buf[0] != '\0') | |
1294 | irc_numeric(from, RPL_WHOISCHANNELS, "%s :%s", who->nick, buf); | |
d76ed9a9 | 1295 | } |
1136f709 | 1296 | |
1297 | if (his_servername && his_servercomment && !IsOper(from) && from != who) | |
a32da4c7 | 1298 | irc_numeric(from, RPL_WHOISSERVER, "%s %s :%s", who->nick, his_servername, his_servercomment); |
d76ed9a9 | 1299 | else |
a32da4c7 | 1300 | irc_numeric(from, RPL_WHOISSERVER, "%s %s :%s", who->nick, who->uplink->name, who->uplink->description); |
1136f709 | 1301 | |
1302 | if (IsAway(who)) | |
1303 | irc_numeric(from, RPL_AWAY, "%s :Away", who->nick); | |
a32da4c7 | 1304 | if (IsOper(who)) |
1136f709 | 1305 | irc_numeric(from, RPL_WHOISOPERATOR, "%s :%s", who->nick, IsLocal(who) ? "is a megalomaniacal power hungry tyrant" : "is an IRC Operator"); |
1306 | if (who->handle_info) | |
1307 | irc_numeric(from, RPL_WHOISACCOUNT, "%s %s :is logged in as", who->nick, who->handle_info->handle); | |
1308 | if (IsHiddenHost(who) && who->handle_info && (IsOper(from) || from == who)) | |
1309 | irc_numeric(from, RPL_WHOISACTUALLY, "%s %s@%s %s :Actual user@host, Actual IP", who->nick, who->ident, who->hostname, irc_ntoa(&who->ip)); | |
1310 | if (IsLocal(who) && !IsService(who) && (IsOper(from) || from == who)) | |
1311 | irc_numeric(from, RPL_WHOISIDLE, "%s %ld %ld :seconds idle, signon time", who->nick, now - who->idle_since, who->timestamp); | |
1312 | ||
d76ed9a9 AS |
1313 | irc_numeric(from, RPL_ENDOFWHOIS, "%s :End of /WHOIS list", who->nick); |
1314 | return 1; | |
1315 | } | |
1316 | ||
1317 | static CMD_FUNC(cmd_server) | |
1318 | { | |
1319 | struct server *srv; | |
1320 | const char *str; | |
1321 | ||
1322 | if (argc < 8) | |
1323 | return 0; | |
a32da4c7 | 1324 | if (self->uplink) { |
d76ed9a9 AS |
1325 | /* another server introduced us */ |
1326 | srv = AddServer(GetServerH(origin), argv[1], atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), argv[6], argv[argc-1]); | |
1327 | if (!srv) | |
1328 | return 0; | |
1329 | srv->self_burst = argv[5][0] == 'J'; | |
1330 | srv->burst = 1; | |
1331 | } else { | |
1332 | /* this must be our uplink */ | |
1333 | srv = self->uplink = AddServer(self, argv[1], atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), argv[6], argv[argc-1]); | |
1334 | if (!srv) | |
1335 | return 0; | |
1336 | srv->self_burst = argv[5][0] == 'J'; | |
1337 | srv->burst = 1; | |
1338 | if ((argv[7][0] == '+') && !force_n2k) { | |
1339 | log_module(MAIN_LOG, LOG_WARNING, "Got Undernet-style SERVER message but \"force_n2k\" not on."); | |
1340 | } | |
1341 | send_burst(); | |
1342 | } | |
1343 | ||
1344 | /* Fix up our timestamps if necessary. */ | |
1345 | if (srv->boot <= PREHISTORY) { | |
1346 | /* Server from the mists of time.. */ | |
1347 | if (srv->hops == 1) { | |
1348 | log_module(MAIN_LOG, LOG_ERROR, "Server %s claims to have booted at time "FMT_TIME_T". This is absurd.", srv->name, srv->boot); | |
1349 | } | |
1350 | } else if ((str = conf_get_data("server/reliable_clock", RECDB_QSTRING)) | |
1351 | && enabled_string(str)) { | |
1352 | /* If we have a reliable clock, we just keep our current time. */ | |
1353 | } else { | |
1354 | if (srv->boot <= self->boot) { | |
1355 | /* The other server is older than us. Accept their timestamp. | |
1356 | * Alternately, we are same age, but we accept their time | |
1357 | * since we are linking to them. */ | |
1358 | self->boot = srv->boot; | |
1136f709 | 1359 | ioset_set_time(srv->link_time |
1360 | ); | |
d76ed9a9 AS |
1361 | } |
1362 | } | |
1363 | if (srv == self->uplink) { | |
1364 | extern time_t burst_begin; | |
1365 | burst_begin = now; | |
1366 | } | |
1367 | return 1; | |
1368 | } | |
1369 | ||
47956fc5 | 1370 | |
d76ed9a9 AS |
1371 | static CMD_FUNC(cmd_eob) |
1372 | { | |
1373 | struct server *sender; | |
1374 | dict_iterator_t it; | |
d76ed9a9 AS |
1375 | |
1376 | if (!(sender = GetServerH(origin))) | |
1377 | return 0; | |
1378 | if (sender == self->uplink) { | |
1379 | cManager.uplink->state = CONNECTED; | |
1380 | for (it = dict_first(unbursted_channels); it; it = iter_next(it)) | |
1381 | irc_burst(iter_data(it)); | |
1382 | dict_delete(unbursted_channels); | |
1383 | unbursted_channels = NULL; | |
1384 | irc_eob(); | |
1385 | irc_eob_ack(); | |
47956fc5 AS |
1386 | |
1387 | /* now that we know who our uplink is, | |
1388 | * we can center the routing map and activate auto-routing. | |
1389 | */ | |
9079d26c AS |
1390 | //activate_routing(NULL, NULL, NULL); |
1391 | routing_init(); | |
d76ed9a9 AS |
1392 | } |
1393 | sender->self_burst = 0; | |
1394 | recalc_bursts(sender); | |
9d59f196 | 1395 | call_server_link_funcs(sender); |
47956fc5 AS |
1396 | /* let auto-routing figure out if we were |
1397 | * wating on this server to link a child to it */ | |
1398 | /* DONT call this if uplink is _US_ */ | |
1399 | if(sender->uplink != self) | |
1400 | routing_handle_connect(sender->name, sender->uplink->name); | |
d76ed9a9 AS |
1401 | return 1; |
1402 | } | |
1403 | ||
1404 | static CMD_FUNC(cmd_eob_ack) | |
1405 | { | |
1406 | extern time_t burst_begin; | |
1407 | ||
1408 | if (GetServerH(origin) == self->uplink) { | |
1409 | burst_length = now - burst_begin; | |
1410 | self->self_burst = self->burst = 0; | |
1411 | } | |
1412 | cManager.uplink->state = CONNECTED; | |
1413 | return 1; | |
1414 | } | |
1415 | ||
956ee72d | 1416 | static CMD_FUNC(cmd_rping) |
1417 | { | |
1418 | struct server *dest; | |
1419 | ||
1420 | if (!(dest = GetServerN(argv[1]))) | |
74ac2349 | 1421 | return 1; /* if its a jupe or something, return 1 so its silently ignored */ |
956ee72d | 1422 | |
1423 | if (dest == self) | |
1424 | irc_rpong(argv[2], argv[3], argv[4], argv[5]); | |
1425 | ||
1426 | return 1; | |
1427 | } | |
1428 | ||
d76ed9a9 AS |
1429 | static CMD_FUNC(cmd_ping) |
1430 | { | |
1431 | struct server *srv; | |
1432 | struct userNode *un; | |
1433 | ||
2f61d1d7 | 1434 | if (argc > 3) |
1435 | irc_pong_asll(argv[2], argv[3]); | |
d76ed9a9 AS |
1436 | else if ((srv = GetServerH(origin))) |
1437 | irc_pong(self->name, srv->numeric); | |
1438 | else if ((un = GetUserH(origin))) | |
1439 | irc_pong(self->name, un->numeric); | |
1440 | else | |
1441 | irc_pong(self->name, origin); | |
1442 | ||
1443 | timeq_del(0, timed_send_ping, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA); | |
1444 | timeq_del(0, timed_ping_timeout, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA); | |
1445 | timeq_add(now + ping_freq, timed_send_ping, 0); | |
1446 | received_ping(); | |
1447 | return 1; | |
1448 | } | |
1449 | ||
1450 | static CMD_FUNC(cmd_error_nick) | |
1451 | { | |
1452 | /* Go back to original IRC length .. and try to reconnect :/ */ | |
1453 | change_nicklen(9); | |
1454 | irc_squit(self, "Got erroneous nickname, truncating nicks.", NULL); | |
1455 | return 1; | |
1456 | } | |
1457 | ||
1458 | struct create_desc { | |
1459 | struct userNode *user; | |
1460 | time_t when; | |
1461 | }; | |
1462 | ||
1463 | static void | |
1464 | join_helper(struct chanNode *chan, void *data) | |
1465 | { | |
1466 | struct create_desc *cd = data; | |
1467 | AddChannelUser(cd->user, chan); | |
1468 | } | |
1469 | ||
1470 | static void | |
1471 | create_helper(char *name, void *data) | |
1472 | { | |
1473 | struct create_desc *cd = data; | |
1474 | ||
1475 | if (!strcmp(name, "0")) { | |
1476 | while (cd->user->channels.used > 0) | |
1477 | DelChannelUser(cd->user, cd->user->channels.list[0]->channel, 0, 0); | |
1478 | return; | |
1479 | } | |
1480 | ||
2aef5f4b | 1481 | AddChannelUser(cd->user, AddChannel(name, cd->when, NULL, NULL, NULL)); |
d76ed9a9 AS |
1482 | } |
1483 | ||
1484 | static CMD_FUNC(cmd_create) | |
1485 | { | |
1486 | struct create_desc cd; | |
1487 | struct userNode *user; | |
1488 | ||
1489 | if ((argc < 3) || !(user = GetUserH(origin))) | |
1490 | return 0; | |
1491 | cd.user = user; | |
1492 | cd.when = atoi(argv[2]); | |
1493 | parse_foreach(argv[1], join_helper, create_helper, NULL, NULL, &cd); | |
1494 | return 1; | |
1495 | } | |
1496 | ||
1497 | static CMD_FUNC(cmd_join) | |
1498 | { | |
1499 | struct create_desc cd; | |
1500 | ||
1501 | if (!(cd.user = GetUserH(origin))) | |
1502 | return 0; | |
1503 | if (argc < 2) | |
1504 | return 0; | |
1505 | else if (argc < 3) | |
1506 | cd.when = now; | |
1507 | else | |
1508 | cd.when = atoi(argv[2]); | |
1509 | parse_foreach(argv[1], join_helper, create_helper, NULL, NULL, &cd); | |
1510 | return 1; | |
1511 | } | |
1512 | ||
cd25f2e9 | 1513 | static CMD_FUNC(cmd_svsjoin) |
1514 | { | |
1515 | struct create_desc cd; | |
1516 | ||
1517 | if (!(cd.user = GetUserH(argv[1]))) | |
1518 | return 0; | |
1519 | if (argc < 3) | |
1520 | return 0; | |
1521 | else if (argc < 4) | |
1522 | cd.when = now; | |
1523 | else | |
1524 | cd.when = atoi(argv[3]); | |
1525 | parse_foreach(argv[2], join_helper, create_helper, NULL, NULL, &cd); | |
1526 | return 1; | |
1527 | } | |
1528 | ||
d76ed9a9 AS |
1529 | static CMD_FUNC(cmd_pong) |
1530 | { | |
1531 | if (argc < 3) | |
1532 | return 0; | |
1533 | if (!strcmp(argv[2], self->name)) { | |
1534 | timeq_del(0, timed_send_ping, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA); | |
1535 | timeq_del(0, timed_ping_timeout, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA); | |
1536 | timeq_add(now + ping_freq, timed_send_ping, 0); | |
1537 | received_ping(); | |
1538 | } | |
1539 | return 1; | |
1540 | } | |
1541 | ||
1542 | static CMD_FUNC(cmd_nick) | |
1543 | { | |
1544 | struct userNode *user; | |
1545 | if ((user = GetUserH(origin))) { | |
1546 | /* nick change (since the source is a user numeric) */ | |
1547 | if (argc < 2) | |
1548 | return 0; | |
1549 | NickChange(user, argv[1], 1); | |
1550 | } else { | |
1551 | struct server *serv; | |
08895577 | 1552 | struct userNode *nuser; |
d76ed9a9 AS |
1553 | char modes[MAXLEN]; |
1554 | /* new nick */ | |
1555 | if (argc < 9) | |
1556 | return 0; | |
1557 | serv = GetServerH(origin); | |
1558 | if (argc > 9) | |
1559 | unsplit_string(argv+6, argc-9, modes); | |
1560 | else | |
1561 | strcpy(modes, "+"); | |
08895577 | 1562 | nuser = AddUser(serv, argv[1], argv[4], argv[5], modes, argv[argc-2], argv[argc-1], atoi(argv[3]), argv[argc-3]); |
d76ed9a9 AS |
1563 | } |
1564 | return 1; | |
1565 | } | |
1566 | ||
1567 | static CMD_FUNC(cmd_account) | |
1568 | { | |
1569 | struct userNode *user; | |
d9cd0e9d | 1570 | struct server *server; |
b21e2cfe | 1571 | struct handle_info *hi; |
d76ed9a9 | 1572 | |
d9cd0e9d | 1573 | if ((argc < 3) || !origin || !(server = GetServerH(origin))) |
d76ed9a9 | 1574 | return 0; /* Origin must be server. */ |
d9cd0e9d AS |
1575 | |
1576 | /* This next line appears to tremple origin.. why? */ | |
d76ed9a9 AS |
1577 | user = GetUserN(argv[1]); |
1578 | if (!user) | |
1579 | return 1; /* A QUIT probably passed the ACCOUNT. */ | |
805e7c7a AS |
1580 | |
1581 | if(!extended_accounts) /* any need for this function without? */ | |
1582 | return 1; | |
d9cd0e9d AS |
1583 | |
1584 | if(!strcmp(argv[2],"C")) | |
1585 | { | |
1679a283 | 1586 | if((hi = loc_auth(NULL, argv[4], argv[5], NULL))) |
7dd05763 AS |
1587 | { |
1588 | /* Return a AC A */ | |
a837dcf5 | 1589 | putsock("%s " P10_ACCOUNT " %s A %s "FMT_TIME_T, self->numeric, server->numeric , argv[3], hi->registered); |
7dd05763 | 1590 | |
50220e57 | 1591 | log_module(MAIN_LOG, LOG_DEBUG, "loc_auth: %s\n", user->nick); |
50220e57 | 1592 | } |
7dd05763 AS |
1593 | else |
1594 | { | |
1595 | /* Return a AC D */ | |
1596 | putsock("%s " P10_ACCOUNT " %s D %s", self->numeric, server->numeric , argv[3]); | |
1597 | } | |
1598 | return 1; | |
1599 | } | |
1600 | else if(!strcmp(argv[2],"H")) /* New enhanced (host) version of C */ | |
1601 | { | |
1679a283 | 1602 | if((hi = loc_auth(NULL, argv[5], argv[6], argv[4] ))) |
1603 | { | |
1604 | /* Return a AC A */ | |
1605 | putsock("%s " P10_ACCOUNT " %s A %s "FMT_TIME_T, self->numeric, server->numeric , argv[3], hi->registered); | |
1606 | } | |
1607 | else | |
1608 | { | |
1609 | /* Return a AC D */ | |
1610 | putsock("%s " P10_ACCOUNT " %s D %s", self->numeric, server->numeric , argv[3]); | |
1611 | } | |
1612 | return 1; | |
1613 | } | |
1614 | else if(!strcmp(argv[2],"S")) | |
1615 | { | |
1616 | if((hi = loc_auth(argv[5], argv[6], argv[7], argv[4]))) | |
d9cd0e9d AS |
1617 | { |
1618 | /* Return a AC A */ | |
a837dcf5 | 1619 | putsock("%s " P10_ACCOUNT " %s A %s "FMT_TIME_T, self->numeric, server->numeric , argv[3], hi->registered); |
d9cd0e9d AS |
1620 | } |
1621 | else | |
1622 | { | |
1623 | /* Return a AC D */ | |
1624 | putsock("%s " P10_ACCOUNT " %s D %s", self->numeric, server->numeric , argv[3]); | |
1625 | } | |
1626 | return 1; | |
1627 | } | |
1628 | else if(!strcmp(argv[2],"R")) | |
1629 | call_account_func(user, argv[3]); | |
1630 | else | |
1631 | call_account_func(user, argv[2]); /* For backward compatability */ | |
d76ed9a9 AS |
1632 | return 1; |
1633 | } | |
1634 | ||
1635 | static CMD_FUNC(cmd_fakehost) | |
1636 | { | |
1637 | struct userNode *user; | |
1638 | ||
1639 | if ((argc < 3) || !origin || !GetServerH(origin)) | |
1640 | return 0; | |
1641 | if (!(user = GetUserN(argv[1]))) | |
1642 | return 1; | |
1643 | assign_fakehost(user, argv[2], 0); | |
1644 | return 1; | |
1645 | } | |
1646 | ||
89d871d8 | 1647 | static struct { |
1648 | char *name; | |
1649 | unsigned int priv; | |
1650 | } privtab[] = { | |
1651 | #define P(priv) { #priv, PRIV_ ## priv } | |
1652 | P(CHAN_LIMIT), P(MODE_LCHAN), P(WALK_LCHAN), P(DEOP_LCHAN), | |
1653 | P(SHOW_INVIS), P(SHOW_ALL_INVIS), P(UNLIMIT_QUERY), P(KILL), | |
1654 | P(LOCAL_KILL), P(REHASH), P(RESTART), P(DIE), | |
1655 | P(GLINE), P(LOCAL_GLINE), P(JUPE), P(LOCAL_JUPE), | |
1656 | P(OPMODE), P(LOCAL_OPMODE), P(SET), P(WHOX), | |
1657 | P(BADCHAN), P(LOCAL_BADCHAN), P(SEE_CHAN), P(PROPAGATE), | |
1658 | P(DISPLAY), P(SEE_OPERS), P(WIDE_GLINE), P(FORCE_OPMODE), | |
1659 | P(FORCE_LOCAL_OPMODE), P(REMOTEREHASH), P(CHECK), P(SEE_SECRET_CHAN), | |
625ccd4e | 1660 | P(SHUN), P(LOCAL_SHUN), P(WIDE_SHUN), P(ZLINE), |
055f3f30 | 1661 | P(LOCAL_ZLINE), P(WIDE_ZLINE), P(LIST_CHAN), P(WHOIS_NOTICE), |
c9aeceb5 | 1662 | P(HIDE_IDLE), P(XTRAOP), P(HIDE_CHANNELS), P(DISPLAY_MODE), |
1663 | P(FREEFORM), P(REMOVE), P(SPAMFILTER), | |
89d871d8 | 1664 | #undef P |
1665 | { 0, 0 } | |
1666 | }; | |
1667 | ||
1668 | char *client_report_privs(struct userNode *client) | |
1669 | { | |
1670 | int i; | |
1671 | ||
1672 | privbuf[0] = '\0'; | |
1673 | for (i = 0; privtab[i].name; i++) { | |
1674 | if (HasPriv(client, privtab[i].priv)) { | |
1675 | strcat(privbuf, privtab[i].name); | |
1676 | strcat(privbuf, " "); | |
1677 | } | |
1678 | } | |
1679 | ||
1680 | privbuf[strlen(privbuf)] = 0; | |
1681 | ||
1682 | return privbuf; | |
1683 | } | |
1684 | ||
9c88eebe | 1685 | int clear_privs(struct userNode *who) { |
1686 | int i = 0; | |
1687 | assert(0 != who); | |
1688 | ||
1689 | for (i = 0; privtab[i].name; i++) | |
1690 | RevokePriv(who, privtab[i].priv); | |
1691 | ||
1692 | return 0; | |
1693 | } | |
1694 | ||
89d871d8 | 1695 | int client_modify_priv_by_name(struct userNode *who, char *priv, int what) { |
1696 | int i = 0; | |
1697 | assert(0 != priv); | |
1698 | assert(0 != who); | |
1699 | ||
1700 | for (i = 0; privtab[i].name; i++) { | |
1701 | if (0 == strcmp(privtab[i].name, priv)) { | |
1702 | if (what == PRIV_ADD) | |
1703 | GrantPriv(who, privtab[i].priv); | |
1704 | else if (what == PRIV_DEL) { | |
1705 | RevokePriv(who, privtab[i].priv); | |
1706 | } | |
1707 | } | |
1708 | } | |
1709 | return 0; | |
1710 | } | |
1711 | ||
6c34bb5a | 1712 | int check_priv(char *priv) |
1713 | { | |
1714 | int i; | |
1715 | ||
1716 | for (i = 0; privtab[i].name; i++) { | |
1717 | if (0 == strcmp(privtab[i].name, priv)) { | |
1718 | return 1; | |
1719 | } | |
1720 | } | |
1721 | return 0; | |
1722 | } | |
1723 | ||
1724 | void | |
1725 | irc_privs(struct userNode *target, char *flag, int add) | |
1726 | { | |
1727 | client_modify_priv_by_name(target, flag, add); | |
1728 | putsock("%s " P10_PRIVS " %s %s%s", self->numeric, target->numeric, (add == PRIV_ADD) ? "+" : "-", flag); | |
1729 | } | |
1730 | ||
69517d70 | 1731 | void |
6ae87c77 | 1732 | irc_raw_privs(struct userNode *target, const char *privs) |
69517d70 | 1733 | { |
1734 | putsock("%s " P10_PRIVS " %s %s", self->numeric, target->numeric, privs); | |
1735 | } | |
1736 | ||
89d871d8 | 1737 | static CMD_FUNC(cmd_privs) |
1738 | { | |
9c88eebe | 1739 | char *tstr = NULL; |
1740 | char buf[512] = ""; | |
1741 | char *p = 0; | |
1742 | char *tmp; | |
89d871d8 | 1743 | |
9c88eebe | 1744 | int what = PRIV_ADD; |
1745 | int type = 0; | |
89d871d8 | 1746 | |
9c88eebe | 1747 | unsigned int i; |
89d871d8 | 1748 | |
9c88eebe | 1749 | struct server *sender; |
1750 | struct userNode *user; | |
89d871d8 | 1751 | |
89d871d8 | 1752 | |
9c88eebe | 1753 | tstr = conf_get_data("server/type", RECDB_QSTRING); |
1754 | if(tstr) | |
1755 | type = atoi(tstr); | |
89d871d8 | 1756 | |
89d871d8 | 1757 | |
9c88eebe | 1758 | if (!(sender = GetServerH(origin))) { /* from oper */ |
1759 | return 1; /* ignore as no services have privs set */ | |
1760 | } else { /* from server */ | |
1761 | if (type < 5) | |
1762 | return 1; /* silently ignore */ | |
1763 | ||
1764 | user = argc > 1 ? GetUserN(argv[1]) : NULL; | |
1765 | ||
1766 | if (!user) | |
1767 | return 0; | |
1768 | ||
1769 | for (i=1; i<argc; i++) { | |
1770 | strcat(buf, argv[i]); | |
1771 | strcat(buf, " "); | |
1772 | } | |
1773 | ||
1774 | for (i = 2; i < argc; i++) { | |
1775 | if (*argv[i] == '+') { what = PRIV_ADD; argv[i]++; } | |
1776 | if (*argv[i] == '-') { what = PRIV_DEL; argv[i]++; } | |
1777 | for (tmp = x3_strtok(&p, argv[i], ","); tmp; | |
1778 | tmp = x3_strtok(&p, NULL, ",")) { | |
1779 | if (!strcmp(tmp, "PRIV_NONE")) { | |
c3915bdc | 1780 | if (now > user->timestamp+5) |
1781 | clear_privs(user); | |
9c88eebe | 1782 | break; |
1783 | } else | |
1784 | client_modify_priv_by_name(user, tmp, what); | |
1785 | } | |
1786 | } | |
89d871d8 | 1787 | } |
9c88eebe | 1788 | return 1; |
89d871d8 | 1789 | } |
1790 | ||
d76ed9a9 AS |
1791 | static CMD_FUNC(cmd_burst) |
1792 | { | |
1793 | extern int rel_age; | |
2aef5f4b | 1794 | char modes[MAXLEN], *members = ""; |
1795 | static char exemptlist[MAXLEN], banlist[MAXLEN]; | |
a32da4c7 | 1796 | unsigned int next = 3, res = 1; |
2aef5f4b | 1797 | int ctype = 0, echeck = 0, bcheck = 0; |
fa86a9e7 | 1798 | struct chanData *cData; |
d76ed9a9 AS |
1799 | struct chanNode *cNode; |
1800 | struct userNode *un; | |
1801 | struct modeNode *mNode; | |
1802 | long mode; | |
2f61d1d7 | 1803 | int oplevel = -1; |
3e06ac80 | 1804 | int type = 0; |
d76ed9a9 | 1805 | char *user, *end, sep; |
3e06ac80 | 1806 | char *tstr; |
d76ed9a9 | 1807 | time_t in_timestamp; |
2aef5f4b | 1808 | char* parm = NULL; |
d76ed9a9 AS |
1809 | |
1810 | if (argc < 3) | |
1811 | return 0; | |
1812 | modes[0] = 0; | |
2aef5f4b | 1813 | |
3e06ac80 MB |
1814 | tstr = conf_get_data("server/type", RECDB_QSTRING); |
1815 | if(tstr) { | |
1816 | type = atoi(tstr); | |
1817 | } | |
1818 | ||
2aef5f4b | 1819 | exemptlist[0] = 0; |
1820 | banlist[0] = 0; | |
1821 | ||
d76ed9a9 AS |
1822 | while (next < argc) { |
1823 | switch (argv[next][0]) { | |
1824 | case '+': { | |
1825 | const char *pos; | |
1826 | int n_modes; | |
a32da4c7 | 1827 | for (pos=argv[next], n_modes = 1; *pos; pos++) |
2f61d1d7 | 1828 | if ((*pos == 'k') || (*pos == 'l') || (*pos == 'A') |
3e06ac80 | 1829 | || (*pos == 'U') || ((type > 7) && (*pos == 'L'))) |
d76ed9a9 | 1830 | n_modes++; |
1136f709 | 1831 | if (next + n_modes > argc) |
1832 | n_modes = argc - next; | |
d76ed9a9 AS |
1833 | unsplit_string(argv+next, n_modes, modes); |
1834 | next += n_modes; | |
1835 | break; | |
1836 | } | |
2aef5f4b | 1837 | case '%': { |
1838 | for(parm = mysep(&argv[next], " "); /* parm = first param */ | |
1839 | parm; /* While param is not null */ | |
1840 | parm = mysep(&argv[next], " ") /* parm = next param */ | |
1841 | ) | |
1842 | { | |
1843 | switch (parm[0]) { | |
1844 | case '%': { | |
1845 | ctype = 1; | |
1846 | break; | |
1847 | } | |
1848 | case '~': { | |
1849 | ctype = 2; | |
1850 | break; | |
1851 | } | |
1852 | default: { | |
1853 | break; | |
1854 | } | |
1855 | } | |
1856 | if (ctype == 1) { | |
1857 | if (bcheck == 0) { | |
1858 | /* strip % char off start of very first ban */ | |
23475fc6 | 1859 | if (strlen(parm) > 1) { |
1860 | strncat(banlist, strtok(parm, "%"), sizeof(banlist) - 1 - strlen(banlist)); | |
1861 | strncat(banlist, " ", sizeof(banlist) - 1 - strlen(banlist)); | |
1862 | } | |
2aef5f4b | 1863 | bcheck = 1; |
1864 | } else { | |
1865 | strncat(banlist, parm, sizeof(banlist) - 1 - strlen(banlist)); | |
1866 | strncat(banlist, " ", sizeof(banlist) - 1 - strlen(banlist)); | |
1867 | } | |
1868 | } else if (ctype == 2) { | |
1869 | if (echeck == 0) { | |
1870 | echeck = 1; | |
1871 | } else { | |
1872 | strncat(exemptlist, parm, sizeof(exemptlist) - 1 - strlen(exemptlist)); | |
1873 | strncat(exemptlist, " ", sizeof(exemptlist) - 1 - strlen(exemptlist)); | |
1874 | } | |
1875 | } | |
1876 | } | |
1877 | next++; | |
1878 | break; | |
1879 | } | |
a32da4c7 | 1880 | default: members = argv[next++]; break; |
2aef5f4b | 1881 | } |
d76ed9a9 AS |
1882 | } |
1883 | ||
1884 | in_timestamp = atoi(argv[2]); | |
1885 | if ((cNode = dict_find(unbursted_channels, argv[1], NULL))) { | |
1886 | cNode->timestamp = in_timestamp; | |
1887 | dict_remove(unbursted_channels, cNode->name); | |
1888 | irc_burst(cNode); | |
1889 | } | |
2aef5f4b | 1890 | cNode = AddChannel(argv[1], in_timestamp, modes, banlist, exemptlist); |
fa86a9e7 | 1891 | cData = cNode->channel_info; |
1892 | ||
1893 | if (!cData) { | |
1894 | if (cNode->modes & MODE_REGISTERED) { | |
1895 | irc_join(opserv, cNode); | |
1896 | irc_mode(opserv, cNode, "-z"); | |
1897 | irc_part(opserv, cNode, ""); | |
1898 | } | |
1899 | } | |
2aef5f4b | 1900 | |
a32da4c7 | 1901 | /* Burst channel members in now. */ |
d76ed9a9 AS |
1902 | for (user = members, sep = *members, mode = 0; sep; user = end) { |
1903 | for (end = user + 3; isalnum(*end) || *end == '[' || *end == ']'; end++) ; | |
1904 | sep = *end++; end[-1] = 0; | |
1905 | if (sep == ':') { | |
1906 | mode = 0; | |
1907 | while ((sep = *end++)) { | |
2f61d1d7 | 1908 | if (sep == 'o') { |
d76ed9a9 | 1909 | mode |= MODE_CHANOP; |
2f61d1d7 | 1910 | oplevel = -1; |
1911 | } else if (sep == 'h') { | |
55342ce8 | 1912 | mode |= MODE_HALFOP; |
2f61d1d7 | 1913 | oplevel = -1; |
1914 | } else if (sep == 'v') { | |
d76ed9a9 | 1915 | mode |= MODE_VOICE; |
2f61d1d7 | 1916 | oplevel = -1; |
1917 | } else if (isdigit(sep)) { | |
1117fc5a | 1918 | mode |= MODE_CHANOP; |
2f61d1d7 | 1919 | if (oplevel >= 0) |
1920 | oplevel += parse_oplevel(end); | |
1921 | else | |
1922 | oplevel = parse_oplevel(end); | |
1117fc5a | 1923 | while (isdigit(*end)) end++; |
1924 | } else | |
d76ed9a9 AS |
1925 | break; |
1926 | } | |
1927 | if (rel_age < 0) | |
1928 | mode = 0; | |
1929 | } | |
1930 | if (!(un = GetUserN(user))) { | |
1931 | res = 0; | |
1932 | continue; | |
1933 | } | |
2f61d1d7 | 1934 | if ((mNode = AddChannelUser(un, cNode))) { |
d76ed9a9 | 1935 | mNode->modes = mode; |
2f61d1d7 | 1936 | mNode->oplevel = oplevel; |
1937 | } | |
d76ed9a9 AS |
1938 | } |
1939 | ||
1940 | return res; | |
1941 | } | |
1942 | ||
d82cf2f0 AS |
1943 | /* TODO: |
1944 | * This is a stub that doesn't actually do anything. It should be completed | |
1945 | * so that bans on *!*@markname.* match users as it does in nefarious | |
1946 | */ | |
1947 | static CMD_FUNC(cmd_mark) | |
1948 | { | |
1949 | struct userNode *target; | |
1950 | /* | |
1951 | * log_module(MAIN_LOG, LOG_ERROR, "DEBUG: mark, user %s, type %s, arg %s", argv[1], argv[2], argv[3]); | |
1952 | */ | |
1953 | ||
1954 | if(argc < 4) | |
1955 | return 0; | |
d82cf2f0 AS |
1956 | if(!strcasecmp(argv[2], "DNSBL")) { |
1957 | /* DNSBL <modes> */ | |
1958 | return 1; | |
1959 | } | |
1960 | else if(!strcasecmp(argv[2], "DNSBL_DATA")) { | |
1961 | /* DNSBL_DATA name */ | |
bc06f607 | 1962 | target = GetUserH(argv[1]); |
1963 | if(!target) { | |
6d58d26f | 1964 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s whose dnsbl mark is changing.", argv[1]); |
bc06f607 | 1965 | return 0; |
1966 | } | |
2c00fbc2 | 1967 | target->mark = strdup(argv[3]); |
d82cf2f0 AS |
1968 | return 1; |
1969 | ||
1970 | } | |
6d58d26f | 1971 | else if(!strcasecmp(argv[2], "CVERSION")) { |
ba4b4d51 | 1972 | /* CTCP VERSION mark */ |
6d58d26f | 1973 | target = GetUserH(argv[1]); |
1974 | if(!target) { | |
1975 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s whose version mark is changing.", argv[1]); | |
1976 | return 0; | |
1977 | } | |
1978 | ||
fa3c07bb | 1979 | char *version = unsplit_string(argv + 3, argc - 3, NULL); |
1980 | if(!version) | |
1981 | version = ""; | |
1982 | ||
1983 | target->version_reply = strdup(version); | |
1984 | ||
1985 | if(match_ircglob(version, "WebTV;*")) | |
1986 | target->no_notice = true; /* webbies cant see notices */ | |
1987 | ||
6d58d26f | 1988 | return 1; |
1989 | } | |
ba4b4d51 MB |
1990 | else if(!strcasecmp(argv[2], "SSLCLIFP")) { |
1991 | /* SSL fingerprint mark */ | |
1992 | target = GetUserH(argv[1]); | |
1993 | if(!target) { | |
1994 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s whose SSL fingerprint mark is changing.", argv[1]); | |
1995 | return 0; | |
1996 | } | |
1997 | ||
1998 | char *sslfp = unsplit_string(argv + 3, argc - 3, NULL); | |
1999 | if(!sslfp) | |
2000 | sslfp = ""; | |
2001 | ||
2002 | target->sslfp = strdup(sslfp); | |
2003 | ||
2004 | return 1; | |
2005 | } | |
d82cf2f0 AS |
2006 | /* unknown type of mark */ |
2007 | return 1; | |
2008 | } | |
2009 | ||
d76ed9a9 AS |
2010 | static CMD_FUNC(cmd_mode) |
2011 | { | |
2012 | struct chanNode *cn; | |
2013 | struct userNode *un; | |
182dd032 AS |
2014 | char *sethost; // sethost - reed/apples |
2015 | int i; // sethost - reed/apples | |
d76ed9a9 AS |
2016 | |
2017 | if (argc < 3) | |
2018 | return 0; | |
2019 | if (!IsChannelName(argv[1])) { | |
2020 | un = GetUserH(argv[1]); | |
2021 | if (!un) { | |
2022 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s whose mode is changing.", argv[1]); | |
2023 | return 0; | |
2024 | } | |
182dd032 AS |
2025 | // sethost - reed/apples |
2026 | if (argc == 3) | |
d76ed9a9 | 2027 | mod_usermode(un, argv[2]); |
182dd032 AS |
2028 | else { |
2029 | sethost = malloc(strlen(argv[2]) + 1 + strlen(argv[3]) + 1); | |
2030 | i = 0; | |
2031 | while((sethost[i++] = *argv[2]++)); | |
2032 | i--; | |
2033 | sethost[i++] = ' '; | |
2034 | while((sethost[i++] = *argv[3]++)); | |
2035 | mod_usermode(un, sethost); // sethost - reed/apples | |
2036 | } | |
2037 | ||
d76ed9a9 AS |
2038 | return 1; |
2039 | } | |
2040 | ||
2041 | if (!(cn = GetChannel(argv[1]))) { | |
2042 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose mode is changing.", argv[1]); | |
2043 | return 0; | |
2044 | } | |
2045 | if ((un = GetUserH(origin))) { | |
2046 | struct modeNode *mn; | |
2047 | /* Update idle time for person setting the mode */ | |
2048 | if ((mn = GetUserMode(cn, un))) | |
2049 | mn->idle_since = now; | |
2050 | } else { | |
2051 | /* If it came from a server, reset timestamp to re-sync. */ | |
2052 | cn->timestamp = atoi(argv[argc-1]); | |
2053 | } | |
2054 | ||
08895577 | 2055 | if (checkDefCon(DEFCON_NO_MODE_CHANGE) && !IsOper(un)) { |
2056 | const char *str; | |
2057 | str = conf_get_data("services/opserv/nick", RECDB_QSTRING); | |
2058 | if (str) { | |
2059 | char modes[MODELEN]; | |
2060 | struct userNode *opserv = GetUserH(str); | |
2061 | ||
2062 | send_message_type(4, un, opserv, "Channel modes cannot be changed due to DefCon level %d in effect, please try again soon", DefConLevel); | |
2063 | irc_make_chanmode(cn, modes); | |
2064 | irc_mode(opserv, cn, modes); | |
2065 | irc_mode(opserv, cn, DefConChanModes); | |
2066 | } | |
2067 | return 1; | |
2068 | } | |
2069 | ||
2070 | ||
d76ed9a9 AS |
2071 | return mod_chanmode(un, cn, argv+2, argc-2, MCP_ALLOW_OVB|MCP_FROM_SERVER|(un ? MC_NOTIFY : 0)); |
2072 | } | |
2073 | ||
2074 | static CMD_FUNC(cmd_opmode) | |
2075 | { | |
2076 | struct chanNode *cn; | |
2077 | struct userNode *un; | |
2078 | ||
2079 | if (argc < 3) | |
2080 | return 0; | |
2081 | ||
2082 | if (!(cn = GetChannel(argv[1]))) { | |
2083 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose mode is changing.", argv[1]); | |
2084 | return 0; | |
2085 | } | |
2086 | if (!(un = GetUserH(origin))) { | |
2087 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s requesting OPMODE.", origin); | |
2088 | return 0; | |
2089 | } | |
2090 | if (!IsOper(un)) { | |
2091 | log_module(MAIN_LOG, LOG_ERROR, "Non-privileged user %s using OPMODE.", un->nick); | |
2092 | return 0; | |
2093 | } | |
2094 | ||
2095 | return mod_chanmode(un, cn, argv+2, argc-2, MCP_ALLOW_OVB|MCP_FROM_SERVER); /* do NOT announce opmode locally */ | |
2096 | } | |
2097 | ||
2098 | static int clear_chanmode(struct chanNode *channel, const char *modes); | |
2099 | ||
2100 | static CMD_FUNC(cmd_clearmode) | |
2101 | { | |
2102 | struct chanNode *cn; | |
2103 | struct userNode *un; | |
2104 | ||
2105 | if (argc < 3) | |
2106 | return 0; | |
2107 | ||
2108 | if (!(cn = GetChannel(argv[1]))) { | |
2109 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose mode is changing.", argv[1]); | |
2110 | return 0; | |
2111 | } | |
2112 | if (!(un = GetUserH(origin))) { | |
2113 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find user %s requesting CLEARMODE.", origin); | |
2114 | return 0; | |
2115 | } | |
2116 | if (!IsOper(un)) { | |
2117 | log_module(MAIN_LOG, LOG_ERROR, "Non-privileged user %s using CLEARMODE.", un->nick); | |
2118 | return 0; | |
2119 | } | |
2120 | ||
2121 | return clear_chanmode(cn, argv[2]); | |
2122 | } | |
2123 | ||
2124 | static CMD_FUNC(cmd_topic) | |
2125 | { | |
2126 | struct chanNode *cn; | |
2127 | time_t chan_ts, topic_ts; | |
7fda2b52 | 2128 | struct userNode *user; |
d76ed9a9 AS |
2129 | |
2130 | if (argc < 3) | |
2131 | return 0; | |
2132 | if (!(cn = GetChannel(argv[1]))) { | |
2133 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s whose topic is being set", argv[1]); | |
2134 | return 0; | |
2135 | } | |
7fda2b52 | 2136 | |
2137 | ||
2138 | if (argc == 5) { /* Asuka / Topic Bursting IRCu's */ | |
2139 | user = GetUserH(origin); | |
d76ed9a9 AS |
2140 | chan_ts = atoi(argv[2]); |
2141 | topic_ts = atoi(argv[3]); | |
7fda2b52 | 2142 | } else if (argc >= 6) { /* Nefarious 0.5.0 */ |
2143 | user = GetUserH(strtok(argv[2], "!")); | |
2144 | chan_ts = atoi(argv[3]); | |
2145 | topic_ts = atoi(argv[4]); | |
2146 | } else { /* Regular IRCu (No Topic Bursting)*/ | |
2147 | user = GetUserH(origin); | |
d76ed9a9 AS |
2148 | chan_ts = cn->timestamp; |
2149 | topic_ts = now; | |
2150 | } | |
7fda2b52 | 2151 | |
2152 | SetChannelTopic(cn, user, user, argv[argc-1], 0); | |
d76ed9a9 AS |
2153 | cn->topic_time = topic_ts; |
2154 | return 1; | |
2155 | } | |
2156 | ||
2157 | static CMD_FUNC(cmd_num_topic) | |
2158 | { | |
2159 | struct chanNode *cn; | |
2160 | ||
2161 | if (!argv[0]) | |
2162 | return 0; /* huh? */ | |
2163 | if (argv[2]) { | |
2164 | cn = GetChannel(argv[2]); | |
2165 | if (!cn) { | |
2166 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find channel %s in topic reply", argv[2]); | |
2167 | return 0; | |
2168 | } | |
2169 | } else | |
2170 | return 0; | |
2171 | ||
2172 | switch (atoi(argv[0])) { | |
2173 | case 331: | |
2174 | cn->topic_time = 0; | |
2175 | break; /* no topic */ | |
2176 | case 332: | |
2177 | if (argc < 4) | |
2178 | return 0; | |
2179 | safestrncpy(cn->topic, unsplit_string(argv+3, argc-3, NULL), sizeof(cn->topic)); | |
2180 | break; | |
2181 | case 333: | |
2182 | if (argc < 5) | |
2183 | return 0; | |
2184 | safestrncpy(cn->topic_nick, argv[3], sizeof(cn->topic_nick)); | |
2185 | cn->topic_time = atoi(argv[4]); | |
2186 | break; | |
2187 | default: | |
2188 | return 0; /* should never happen */ | |
2189 | } | |
2190 | return 1; | |
2191 | } | |
2192 | ||
2193 | static CMD_FUNC(cmd_num_gline) | |
2194 | { | |
cad8f3a7 | 2195 | if (argc < 7) { |
2196 | if (argc < 6) | |
2197 | return 0; | |
995043b4 | 2198 | else |
2199 | gline_add(origin, argv[3], atoi(argv[4])-now, argv[5], now, 0, 0); | |
cad8f3a7 | 2200 | } else { |
995043b4 | 2201 | if (!strcmp(argv[5], "+")) |
2202 | gline_add(origin, argv[3], atoi(argv[4])-now, argv[6], now, 0, 0); | |
cad8f3a7 | 2203 | } |
d76ed9a9 AS |
2204 | return 1; |
2205 | } | |
2206 | ||
d914d1cb | 2207 | static CMD_FUNC(cmd_num_shun) |
2208 | { | |
cad8f3a7 | 2209 | if (argc < 7) { |
2210 | if (argc < 6) | |
2211 | return 0; | |
2212 | else | |
995043b4 | 2213 | shun_add(origin, argv[3], atoi(argv[4])-now, argv[5], now, 0); |
cad8f3a7 | 2214 | } else { |
4cb36ef0 | 2215 | if (!strcmp(argv[5], "+")) |
995043b4 | 2216 | shun_add(origin, argv[3], atoi(argv[4])-now, argv[6], now, 0); |
cad8f3a7 | 2217 | } |
d914d1cb | 2218 | return 1; |
2219 | } | |
2220 | ||
d76ed9a9 AS |
2221 | static CMD_FUNC(cmd_quit) |
2222 | { | |
2223 | struct userNode *user; | |
2224 | if (argc < 2) | |
2225 | return 0; | |
2226 | /* Sometimes we get a KILL then a QUIT or the like, so we don't want to | |
2227 | * call DelUser unless we have the user in our grasp. */ | |
2228 | if ((user = GetUserH(origin))) | |
2229 | DelUser(user, NULL, false, argv[1]); | |
2230 | return 1; | |
2231 | } | |
2232 | ||
2233 | static CMD_FUNC(cmd_kill) | |
2234 | { | |
2235 | struct userNode *user; | |
2236 | if (argc < 2) | |
2237 | return 0; | |
2238 | user = GetUserN(argv[1]); | |
2239 | if (!user) { | |
2240 | /* If we get a KILL for a non-existent user, it could be a | |
2241 | * Ghost response to a KILL we sent out earlier. So we only | |
2242 | * whine if the target is local. | |
2243 | */ | |
2244 | if (!strncmp(argv[1], self->numeric, strlen(self->numeric))) | |
2245 | log_module(MAIN_LOG, LOG_ERROR, "Unable to find kill victim %s", argv[1]); | |
2246 | return 0; | |
2247 | } | |
2248 | ||
2249 | if (IsLocal(user) && IsService(user)) { | |
2250 | /* TODO: rate limit this so silly things don't happen. */ | |
2251 | ReintroduceUser(user); | |
2252 | return 1; | |
2253 | } | |
2254 | ||
2255 | DelUser(user, NULL, false, argv[2]); | |
2256 | return 1; | |
2257 | } | |
2258 | ||
cd25f2e9 | 2259 | static CMD_FUNC(cmd_svspart) |
2260 | { | |
2261 | struct userNode *user; | |
2262 | ||
2263 | if (argc < 3) | |
2264 | return 0; | |
c9ec8867 | 2265 | user = GetUserN(argv[1]); |
cd25f2e9 | 2266 | if (!user) |
2267 | return 0; | |
2268 | parse_foreach(argv[2], part_helper, NULL, NULL, NULL, user); | |
2269 | return 1; | |
2270 | } | |
2271 | ||
a6a4707e | 2272 | static CMD_FUNC(cmd_silence) |
2273 | { | |
2274 | struct userNode *user; | |
2275 | char *mask; | |
f0b5157b | 2276 | char *new_mask; |
a6a4707e | 2277 | unsigned int i; |
2278 | ||
2279 | if (argc < 2) | |
2280 | return 0; | |
2281 | ||
2282 | user = GetUserN(argv[1]); | |
2283 | ||
2284 | /* Sanity, go nuts if this happens */ | |
2285 | if (!user) | |
2286 | return 0; | |
2287 | ||
2288 | /* We can safely ignore this if a user adding a silence is not | |
2289 | * ignored. However this brings up a TODO. If a user logs in and | |
2290 | * they have silences on the IRCd then we need to set them here | |
2291 | * somehow | |
2292 | */ | |
2293 | if (!user->handle_info) | |
2294 | return 1; | |
2295 | ||
b6599cc2 | 2296 | mask = argv[2]; |
a6a4707e | 2297 | |
2298 | if (*mask == '-') { | |
2299 | for (i=0; i<user->handle_info->ignores->used; i++) { | |
2300 | if (!irccasecmp(mask+1, user->handle_info->ignores->list[i])) | |
2301 | user->handle_info->ignores->list[i] = user->handle_info->ignores->list[--user->handle_info->ignores->used]; | |
2302 | } | |
2303 | } else { | |
2304 | for (i=0; i<user->handle_info->ignores->used; i++) { | |
2305 | if (!strcmp(mask+1, user->handle_info->ignores->list[i])) | |
2306 | return 1; /* Already on the users NickServ ignore list, safely ignore */ | |
2307 | } | |
2308 | ||
f0b5157b | 2309 | new_mask = strdup(mask+1); |
b6599cc2 | 2310 | string_list_append(user->handle_info->ignores, new_mask); |
a6a4707e | 2311 | } |
a6a4707e | 2312 | return 1; |
2313 | } | |
2314 | ||
d76ed9a9 AS |
2315 | static CMD_FUNC(cmd_kick) |
2316 | { | |
2317 | if (argc < 3) | |
2318 | return 0; | |
2319 | ChannelUserKicked(GetUserH(origin), GetUserN(argv[2]), GetChannel(argv[1])); | |
2320 | return 1; | |
2321 | } | |
2322 | ||
2323 | static CMD_FUNC(cmd_squit) | |
2324 | { | |
2325 | struct server *server; | |
47956fc5 | 2326 | char *uplink; |
d76ed9a9 AS |
2327 | |
2328 | if (argc < 4) | |
2329 | return 0; | |
2330 | if (!(server = GetServerH(argv[1]))) | |
2331 | return 0; | |
2332 | ||
2333 | if (server == self->uplink) { | |
2334 | /* Force a reconnect to the currently selected server. */ | |
2335 | cManager.uplink->tries = 0; | |
2336 | log_module(MAIN_LOG, LOG_INFO, "Squitting from uplink: %s", argv[3]); | |
2337 | close_socket(); | |
2338 | return 1; | |
2339 | } | |
2340 | ||
47956fc5 | 2341 | uplink = strdup(server->uplink->name); |
d76ed9a9 | 2342 | DelServer(server, 0, argv[3]); |
47956fc5 AS |
2343 | /* if its a pingout and pingout connecting is enabled |
2344 | or its a read error and readerror connecting is enabled | |
2345 | or were doing a "N" and i need to connect that server somewhere */ | |
2346 | routing_handle_squit(argv[1], uplink, argv[3]); | |
2347 | free(uplink); | |
d76ed9a9 AS |
2348 | return 1; |
2349 | } | |
2350 | ||
2351 | static CMD_FUNC(cmd_privmsg) | |
2352 | { | |
2353 | struct privmsg_desc pd; | |
1136f709 | 2354 | if (argc < 3) |
d76ed9a9 AS |
2355 | return 0; |
2356 | pd.user = GetUserH(origin); | |
2357 | if (!pd.user || (IsGagged(pd.user) && !IsOper(pd.user))) | |
2358 | return 1; | |
08895577 | 2359 | |
2360 | if (checkDefCon(DEFCON_OPER_ONLY) && !IsOper(pd.user)) { | |
2361 | const char *str; | |
2362 | str = conf_get_data("services/opserv/nick", RECDB_QSTRING); | |
2363 | if (str) | |
2364 | send_message_type(4, pd.user, GetUserH(str), "Services are currently not available, please try again soon"); | |
2365 | return 1; | |
2366 | } | |
2367 | ||
2368 | if (checkDefCon(DEFCON_SILENT_OPER_ONLY) && !IsOper(pd.user)) | |
2369 | return 1; /* Silently Ignore */ | |
2370 | ||
d76ed9a9 | 2371 | pd.is_notice = 0; |
1136f709 | 2372 | pd.text = argv[argc - 1]; |
d76ed9a9 | 2373 | parse_foreach(argv[1], privmsg_chan_helper, NULL, privmsg_user_helper, privmsg_invalid, &pd); |
c99dcaf6 | 2374 | |
d76ed9a9 AS |
2375 | return 1; |
2376 | } | |
2377 | ||
2378 | static CMD_FUNC(cmd_notice) | |
2379 | { | |
2380 | struct privmsg_desc pd; | |
47956fc5 AS |
2381 | struct server *srv; |
2382 | int nuser = 0; | |
2383 | ||
0f6fe38c | 2384 | if (argc != 3) |
d76ed9a9 | 2385 | return 0; |
47956fc5 | 2386 | |
d76ed9a9 | 2387 | pd.user = GetUserH(origin); |
47956fc5 AS |
2388 | if(!pd.user) |
2389 | nuser = 1; | |
2390 | if (!pd.user || (IsGagged(pd.user) && !IsOper(pd.user))) { | |
2391 | } | |
2392 | else { | |
2393 | pd.is_notice = 1; | |
0f6fe38c | 2394 | pd.text = argv[2]; |
47956fc5 AS |
2395 | parse_foreach(argv[1], privmsg_chan_helper, NULL, privmsg_user_helper, privmsg_invalid, &pd); |
2396 | } | |
2397 | ||
2398 | srv = GetServerH(origin); | |
2399 | if(srv) { | |
2400 | char *sargv[MAXNUMPARAMS]; | |
2401 | int sargc; | |
2402 | ||
2403 | sargc = split_line(argv[2], true, MAXNUMPARAMS, sargv); | |
2404 | ||
2405 | if(!strcasecmp(sargv[0], "Connect:")) { | |
2406 | /* :Connect: Host shoe.loxxin.net not listed in ircd.conf */ | |
2407 | if(!strcasecmp(sargv[3], "not") && !strcasecmp(sargv[4], "listed")) { | |
2408 | routing_handle_connect_failure(srv, sargv[2], unsplit_string(sargv+3, sargc-3, NULL)); | |
2409 | } | |
2410 | } | |
2411 | else if(!strcasecmp(sargv[0], "Link")) { | |
2412 | /* :Link with mephisto.etheria.cx cancelled: Server mephisto.etheria.cx[216.46.33.71] | |
2413 | * | |
2414 | * :Link with laptop.afternet.org cancelled: Connection refused | |
2415 | */ | |
2416 | if(!strcasecmp(sargv[3], "cancelled:")) { | |
2417 | routing_handle_connect_failure(srv, sargv[2], unsplit_string(sargv+4, sargc-4, NULL)); | |
2418 | } | |
2419 | } | |
2420 | } | |
d76ed9a9 AS |
2421 | return 1; |
2422 | } | |
2423 | ||
2424 | static CMD_FUNC(cmd_away) | |
2425 | { | |
2426 | struct userNode *uNode; | |
2427 | ||
2428 | uNode = GetUserH(origin); | |
2429 | if (!uNode) | |
2430 | return 1; | |
2431 | if (argc < 2) | |
2432 | uNode->modes &= ~FLAGS_AWAY; | |
2433 | else | |
2434 | uNode->modes |= FLAGS_AWAY; | |
2435 | return 1; | |
2436 | } | |
2437 | ||
2438 | static CMD_FUNC(cmd_gline) | |
2439 | { | |
2440 | if (argc < 3) | |
2441 | return 0; | |
2442 | if (argv[2][0] == '+') { | |
2443 | if (argc < 5) | |
2444 | return 0; | |
995043b4 | 2445 | gline_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, 0, 0); |
d76ed9a9 AS |
2446 | return 1; |
2447 | } else if (argv[2][0] == '-') { | |
2448 | gline_remove(argv[2]+1, 0); | |
2449 | return 1; | |
2450 | } else | |
2451 | return 0; | |
2452 | } | |
2453 | ||
59b38cc0 | 2454 | static CMD_FUNC(cmd_sgline) |
2455 | { | |
2456 | struct server *sender; | |
2457 | ||
2458 | if (argc < 4) | |
2459 | return 0; | |
2460 | ||
2461 | if (!(sender = GetServerH(origin))) | |
2462 | return 0; | |
2463 | ||
995043b4 | 2464 | gline_add(origin, argv[1], strtoul(argv[2], NULL, 0), argv[argc-1], now, 1, 0); |
59b38cc0 | 2465 | return 1; |
2466 | } | |
2467 | ||
2468 | static CMD_FUNC(cmd_sshun) | |
2469 | { | |
2470 | struct server *sender; | |
2471 | ||
2472 | if (argc < 4) | |
2473 | return 0; | |
2474 | ||
2475 | if (!(sender = GetServerH(origin))) | |
2476 | return 0; | |
2477 | ||
995043b4 | 2478 | shun_add(origin, argv[1], strtoul(argv[2], NULL, 0), argv[argc-1], now, 1); |
59b38cc0 | 2479 | return 1; |
2480 | } | |
2481 | ||
d914d1cb | 2482 | static CMD_FUNC(cmd_shun) |
2483 | { | |
2484 | if (argc < 3) | |
2485 | return 0; | |
2486 | if (argv[2][0] == '+') { | |
2487 | if (argc < 5) | |
2488 | return 0; | |
995043b4 | 2489 | shun_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, 0); |
d914d1cb | 2490 | return 1; |
2491 | } else if (argv[2][0] == '-') { | |
2492 | shun_remove(argv[2]+1, 0); | |
2493 | return 1; | |
2494 | } else | |
2495 | return 0; | |
2496 | } | |
2497 | ||
d76ed9a9 AS |
2498 | static CMD_FUNC(cmd_svsnick) |
2499 | { | |
2500 | struct userNode *target, *dest; | |
2501 | if ((argc < 4) | |
2502 | || !(target = GetUserN(argv[1])) | |
2503 | || !IsLocal(target) | |
2504 | || (dest = GetUserH(argv[2]))) | |
2505 | return 0; | |
2506 | NickChange(target, argv[2], 0); | |
2507 | return 1; | |
2508 | } | |
2509 | ||
d76ed9a9 AS |
2510 | void |
2511 | free_user(struct userNode *user) | |
2512 | { | |
2513 | free(user->nick); | |
2514 | free(user); | |
2515 | } | |
2516 | ||
2517 | static void | |
30874d66 | 2518 | parse_cleanup(UNUSED_ARG(void *extra)) |
d76ed9a9 AS |
2519 | { |
2520 | unsigned int nn; | |
2521 | free(of_list); | |
e9b00805 | 2522 | free(of_list_extra); |
d76ed9a9 | 2523 | free(privmsg_funcs); |
1136f709 | 2524 | num_privmsg_funcs = 0; |
d76ed9a9 | 2525 | free(notice_funcs); |
1136f709 | 2526 | num_notice_funcs = 0; |
d76ed9a9 AS |
2527 | free(mcf_list); |
2528 | dict_delete(irc_func_dict); | |
2529 | for (nn=0; nn<dead_users.used; nn++) | |
2530 | free_user(dead_users.list[nn]); | |
2531 | userList_clean(&dead_users); | |
2532 | } | |
2533 | ||
2534 | static void | |
2535 | p10_conf_reload(void) { | |
2536 | hidden_host_suffix = conf_get_data("server/hidden_host", RECDB_QSTRING); | |
1136f709 | 2537 | his_servername = conf_get_data("server/his_servername", RECDB_QSTRING); |
2538 | his_servercomment = conf_get_data("server/his_servercomment", RECDB_QSTRING); | |
d76ed9a9 AS |
2539 | } |
2540 | ||
2541 | static void | |
1898d8ea | 2542 | remove_unbursted_channel(struct chanNode *cNode, UNUSED_ARG(void *extra)) { |
d76ed9a9 AS |
2543 | if (unbursted_channels) |
2544 | dict_remove(unbursted_channels, cNode->name); | |
2545 | } | |
2546 | ||
2547 | void | |
2548 | init_parse(void) | |
2549 | { | |
2550 | const char *str, *desc; | |
2551 | int numnick, usermask, max_users; | |
2552 | char numer[COMBO_NUMERIC_LEN+1]; | |
2553 | ||
2554 | /* read config items */ | |
805e7c7a AS |
2555 | str = conf_get_data("server/extended_accounts", RECDB_QSTRING); |
2556 | extended_accounts = str ? enabled_string(str) : 1; | |
d76ed9a9 AS |
2557 | str = conf_get_data("server/ping_freq", RECDB_QSTRING); |
2558 | ping_freq = str ? ParseInterval(str) : 120; | |
2559 | str = conf_get_data("server/ping_timeout", RECDB_QSTRING); | |
2560 | ping_timeout = str ? ParseInterval(str) : 30; | |
2561 | str = conf_get_data("server/force_n2k", RECDB_QSTRING); | |
2562 | force_n2k = str ? enabled_string(str) : 1; | |
2563 | str = conf_get_data("server/numeric", RECDB_QSTRING); | |
2564 | if (!str) { | |
2565 | log_module(MAIN_LOG, LOG_ERROR, "No server/numeric entry in config file."); | |
2566 | exit(1); | |
2567 | } | |
2568 | numnick = atoi(str); | |
2569 | str = conf_get_data("server/max_users", RECDB_QSTRING); | |
2570 | max_users = str ? atoi(str) : 4096; | |
2571 | for (usermask = 4; usermask < max_users; usermask <<= 1) ; | |
2572 | usermask--; | |
2573 | if ((numnick < 64) && (usermask < 4096) && !force_n2k) | |
2574 | inttobase64(numer, (numnick << 12) + (usermask & 0x00fff), 3); | |
2575 | else | |
2576 | inttobase64(numer, (numnick << 18) + (usermask & 0x3ffff), 5); | |
2577 | ||
d76ed9a9 AS |
2578 | str = conf_get_data("server/hostname", RECDB_QSTRING); |
2579 | desc = conf_get_data("server/description", RECDB_QSTRING); | |
2580 | if (!str || !desc) { | |
2581 | log_module(MAIN_LOG, LOG_ERROR, "No server/hostname entry in config file."); | |
2582 | exit(1); | |
2583 | } | |
2584 | self = AddServer(NULL, str, 0, boot_time, now, numer, desc); | |
2585 | conf_register_reload(p10_conf_reload); | |
2586 | ||
2587 | irc_func_dict = dict_new(); | |
2588 | dict_insert(irc_func_dict, CMD_BURST, cmd_burst); | |
2589 | dict_insert(irc_func_dict, TOK_BURST, cmd_burst); | |
2590 | dict_insert(irc_func_dict, CMD_CREATE, cmd_create); | |
2591 | dict_insert(irc_func_dict, TOK_CREATE, cmd_create); | |
2592 | dict_insert(irc_func_dict, CMD_EOB, cmd_eob); | |
2593 | dict_insert(irc_func_dict, TOK_EOB, cmd_eob); | |
2594 | dict_insert(irc_func_dict, CMD_EOB_ACK, cmd_eob_ack); | |
2595 | dict_insert(irc_func_dict, TOK_EOB_ACK, cmd_eob_ack); | |
2596 | dict_insert(irc_func_dict, CMD_MODE, cmd_mode); | |
2597 | dict_insert(irc_func_dict, TOK_MODE, cmd_mode); | |
d82cf2f0 AS |
2598 | dict_insert(irc_func_dict, CMD_MARK, cmd_mark); |
2599 | dict_insert(irc_func_dict, TOK_MARK, cmd_mark); | |
d76ed9a9 AS |
2600 | dict_insert(irc_func_dict, CMD_NICK, cmd_nick); |
2601 | dict_insert(irc_func_dict, TOK_NICK, cmd_nick); | |
2602 | dict_insert(irc_func_dict, CMD_ACCOUNT, cmd_account); | |
2603 | dict_insert(irc_func_dict, TOK_ACCOUNT, cmd_account); | |
2604 | dict_insert(irc_func_dict, CMD_FAKEHOST, cmd_fakehost); | |
2605 | dict_insert(irc_func_dict, TOK_FAKEHOST, cmd_fakehost); | |
2606 | dict_insert(irc_func_dict, CMD_PASS, cmd_pass); | |
2607 | dict_insert(irc_func_dict, TOK_PASS, cmd_pass); | |
2608 | dict_insert(irc_func_dict, CMD_PING, cmd_ping); | |
2609 | dict_insert(irc_func_dict, TOK_PING, cmd_ping); | |
2610 | dict_insert(irc_func_dict, CMD_PRIVMSG, cmd_privmsg); | |
2611 | dict_insert(irc_func_dict, TOK_PRIVMSG, cmd_privmsg); | |
2612 | dict_insert(irc_func_dict, CMD_PONG, cmd_pong); | |
2613 | dict_insert(irc_func_dict, TOK_PONG, cmd_pong); | |
2614 | dict_insert(irc_func_dict, CMD_QUIT, cmd_quit); | |
2615 | dict_insert(irc_func_dict, TOK_QUIT, cmd_quit); | |
2616 | dict_insert(irc_func_dict, CMD_SERVER, cmd_server); | |
2617 | dict_insert(irc_func_dict, TOK_SERVER, cmd_server); | |
2618 | dict_insert(irc_func_dict, CMD_JOIN, cmd_join); | |
2619 | dict_insert(irc_func_dict, TOK_JOIN, cmd_join); | |
2620 | dict_insert(irc_func_dict, CMD_PART, cmd_part); | |
2621 | dict_insert(irc_func_dict, TOK_PART, cmd_part); | |
2622 | dict_insert(irc_func_dict, CMD_ERROR, cmd_error); | |
2623 | dict_insert(irc_func_dict, TOK_ERROR, cmd_error); | |
2624 | dict_insert(irc_func_dict, CMD_TOPIC, cmd_topic); | |
2625 | dict_insert(irc_func_dict, TOK_TOPIC, cmd_topic); | |
2626 | dict_insert(irc_func_dict, CMD_AWAY, cmd_away); | |
2627 | dict_insert(irc_func_dict, TOK_AWAY, cmd_away); | |
a6a4707e | 2628 | dict_insert(irc_func_dict, CMD_SILENCE, cmd_silence); |
2629 | dict_insert(irc_func_dict, TOK_SILENCE, cmd_silence); | |
d76ed9a9 AS |
2630 | dict_insert(irc_func_dict, CMD_KICK, cmd_kick); |
2631 | dict_insert(irc_func_dict, TOK_KICK, cmd_kick); | |
2632 | dict_insert(irc_func_dict, CMD_SQUIT, cmd_squit); | |
2633 | dict_insert(irc_func_dict, TOK_SQUIT, cmd_squit); | |
2634 | dict_insert(irc_func_dict, CMD_KILL, cmd_kill); | |
2635 | dict_insert(irc_func_dict, TOK_KILL, cmd_kill); | |
2636 | dict_insert(irc_func_dict, CMD_NOTICE, cmd_notice); | |
2637 | dict_insert(irc_func_dict, TOK_NOTICE, cmd_notice); | |
2638 | dict_insert(irc_func_dict, CMD_STATS, cmd_stats); | |
2639 | dict_insert(irc_func_dict, TOK_STATS, cmd_stats); | |
cd25f2e9 | 2640 | dict_insert(irc_func_dict, CMD_SVSJOIN, cmd_svsjoin); |
2641 | dict_insert(irc_func_dict, TOK_SVSJOIN, cmd_svsjoin); | |
d76ed9a9 AS |
2642 | dict_insert(irc_func_dict, CMD_SVSNICK, cmd_svsnick); |
2643 | dict_insert(irc_func_dict, TOK_SVSNICK, cmd_svsnick); | |
cd25f2e9 | 2644 | dict_insert(irc_func_dict, CMD_SVSPART, cmd_svspart); |
2645 | dict_insert(irc_func_dict, TOK_SVSPART, cmd_svspart); | |
56958740 | 2646 | dict_insert(irc_func_dict, CMD_SWHOIS, cmd_dummy); |
2647 | dict_insert(irc_func_dict, TOK_SWHOIS, cmd_dummy); | |
d76ed9a9 AS |
2648 | dict_insert(irc_func_dict, CMD_WHOIS, cmd_whois); |
2649 | dict_insert(irc_func_dict, TOK_WHOIS, cmd_whois); | |
2650 | dict_insert(irc_func_dict, CMD_GLINE, cmd_gline); | |
2651 | dict_insert(irc_func_dict, TOK_GLINE, cmd_gline); | |
59b38cc0 | 2652 | dict_insert(irc_func_dict, CMD_SGLINE, cmd_sgline); |
2653 | dict_insert(irc_func_dict, TOK_SGLINE, cmd_sgline); | |
d914d1cb | 2654 | dict_insert(irc_func_dict, CMD_SHUN, cmd_shun); |
2655 | dict_insert(irc_func_dict, TOK_SHUN, cmd_shun); | |
59b38cc0 | 2656 | dict_insert(irc_func_dict, CMD_SSHUN, cmd_sshun); |
2657 | dict_insert(irc_func_dict, TOK_SSHUN, cmd_sshun); | |
d76ed9a9 AS |
2658 | dict_insert(irc_func_dict, CMD_OPMODE, cmd_opmode); |
2659 | dict_insert(irc_func_dict, TOK_OPMODE, cmd_opmode); | |
2660 | dict_insert(irc_func_dict, CMD_CLEARMODE, cmd_clearmode); | |
2661 | dict_insert(irc_func_dict, TOK_CLEARMODE, cmd_clearmode); | |
2662 | dict_insert(irc_func_dict, CMD_VERSION, cmd_version); | |
2663 | dict_insert(irc_func_dict, TOK_VERSION, cmd_version); | |
2664 | dict_insert(irc_func_dict, CMD_ADMIN, cmd_admin); | |
2665 | dict_insert(irc_func_dict, TOK_ADMIN, cmd_admin); | |
56b83e80 | 2666 | dict_insert(irc_func_dict, CMD_SMO, cmd_dummy); |
2667 | dict_insert(irc_func_dict, TOK_SMO, cmd_dummy); | |
1c76f1b4 | 2668 | dict_insert(irc_func_dict, CMD_SNO, cmd_dummy); |
2669 | dict_insert(irc_func_dict, TOK_SNO, cmd_dummy); | |
d76ed9a9 | 2670 | |
956ee72d | 2671 | dict_insert(irc_func_dict, CMD_RPING, cmd_rping); |
2672 | dict_insert(irc_func_dict, TOK_RPING, cmd_rping); | |
8f9e3388 | 2673 | dict_insert(irc_func_dict, CMD_RPONG, cmd_dummy); |
2674 | dict_insert(irc_func_dict, TOK_RPONG, cmd_dummy); | |
2675 | ||
d76ed9a9 AS |
2676 | /* In P10, DESTRUCT doesn't do anything except be broadcast to servers. |
2677 | * Apparently to obliterate channels from any servers that think they | |
2678 | * exist? | |
2679 | */ | |
2680 | dict_insert(irc_func_dict, CMD_DESTRUCT, cmd_dummy); | |
2681 | dict_insert(irc_func_dict, TOK_DESTRUCT, cmd_dummy); | |
2682 | /* Ignore invites */ | |
2683 | dict_insert(irc_func_dict, CMD_INVITE, cmd_dummy); | |
2684 | dict_insert(irc_func_dict, TOK_INVITE, cmd_dummy); | |
2685 | /* DESYNCH is just informational, so ignore it */ | |
2686 | dict_insert(irc_func_dict, CMD_DESYNCH, cmd_dummy); | |
2687 | dict_insert(irc_func_dict, TOK_DESYNCH, cmd_dummy); | |
2688 | /* Ignore channel operator notices. */ | |
2689 | dict_insert(irc_func_dict, CMD_WALLCHOPS, cmd_dummy); | |
2690 | dict_insert(irc_func_dict, TOK_WALLCHOPS, cmd_dummy); | |
2691 | dict_insert(irc_func_dict, CMD_WALLVOICES, cmd_dummy); | |
2692 | dict_insert(irc_func_dict, TOK_WALLVOICES, cmd_dummy); | |
55342ce8 | 2693 | dict_insert(irc_func_dict, CMD_WALLHOPS, cmd_dummy); |
2694 | dict_insert(irc_func_dict, TOK_WALLHOPS, cmd_dummy); | |
d76ed9a9 AS |
2695 | /* Ignore opers being silly. */ |
2696 | dict_insert(irc_func_dict, CMD_WALLOPS, cmd_dummy); | |
2697 | dict_insert(irc_func_dict, TOK_WALLOPS, cmd_dummy); | |
55342ce8 | 2698 | dict_insert(irc_func_dict, CMD_WALLHOPS, cmd_dummy); |
2699 | dict_insert(irc_func_dict, TOK_WALLHOPS, cmd_dummy); | |
41fadebe | 2700 | dict_insert(irc_func_dict, TOK_WALLUSERS, cmd_dummy); |
850bf0cf AS |
2701 | /* Ignore dnsbl exemptions */ |
2702 | dict_insert(irc_func_dict, TOK_EXEMPT, cmd_dummy); | |
89d871d8 | 2703 | dict_insert(irc_func_dict, CMD_PRIVS, cmd_privs); |
2704 | dict_insert(irc_func_dict, TOK_PRIVS, cmd_privs); | |
763de701 AS |
2705 | /* ignore ALIST for now */ |
2706 | dict_insert(irc_func_dict, TOK_ALIST, cmd_dummy); | |
2707 | dict_insert(irc_func_dict, CMD_ALIST, cmd_dummy); | |
4b2dcc0d MB |
2708 | /* ignore SPAMFILTER */ |
2709 | dict_insert(irc_func_dict, TOK_SPAMFILTER, cmd_dummy); | |
2710 | dict_insert(irc_func_dict, CMD_SPAMFILTER, cmd_dummy); | |
a74c9eac | 2711 | /* Ignore remote luser */ |
0c835e0f | 2712 | dict_insert(irc_func_dict, TOK_LUSERS, cmd_dummy); |
d76ed9a9 AS |
2713 | /* We have reliable clock! Always! Wraaa! */ |
2714 | dict_insert(irc_func_dict, CMD_SETTIME, cmd_dummy); | |
2715 | dict_insert(irc_func_dict, TOK_SETTIME, cmd_dummy); | |
e10feb7a MB |
2716 | /* Ignore ZLINE/ZL/REMOVE/RM */ |
2717 | dict_insert(irc_func_dict, CMD_ZLINE, cmd_dummy); | |
2718 | dict_insert(irc_func_dict, TOK_ZLINE, cmd_dummy); | |
2719 | dict_insert(irc_func_dict, CMD_REMOVE, cmd_dummy); | |
2720 | dict_insert(irc_func_dict, TOK_REMOVE, cmd_dummy); | |
b34a7505 AS |
2721 | |
2722 | /* ignore /trace and /motd commands targetted at us */ | |
2723 | dict_insert(irc_func_dict, TOK_TRACE, cmd_dummy); | |
2724 | dict_insert(irc_func_dict, TOK_MOTD, cmd_dummy); | |
74ac2349 | 2725 | dict_insert(irc_func_dict, TOK_UPING, cmd_dummy); |
b34a7505 | 2726 | |
d76ed9a9 AS |
2727 | /* handle topics */ |
2728 | dict_insert(irc_func_dict, "331", cmd_num_topic); | |
2729 | dict_insert(irc_func_dict, "332", cmd_num_topic); | |
2730 | dict_insert(irc_func_dict, "333", cmd_num_topic); | |
2731 | dict_insert(irc_func_dict, "345", cmd_dummy); /* blah has been invited to blah */ | |
2732 | dict_insert(irc_func_dict, "432", cmd_error_nick); /* Erroneus [sic] nickname */ | |
2733 | /* ban list resetting */ | |
2734 | /* "stats g" responses */ | |
39b3b541 | 2735 | dict_insert(irc_func_dict, "230", cmd_dummy); /* ignore stats headers */ |
d76ed9a9 | 2736 | dict_insert(irc_func_dict, "247", cmd_num_gline); |
d914d1cb | 2737 | dict_insert(irc_func_dict, "542", cmd_num_shun); |
d76ed9a9 AS |
2738 | dict_insert(irc_func_dict, "219", cmd_dummy); /* "End of /STATS report" */ |
2739 | /* other numeric responses we might get */ | |
2740 | dict_insert(irc_func_dict, "401", cmd_dummy); /* target left network */ | |
2741 | dict_insert(irc_func_dict, "403", cmd_dummy); /* no such channel */ | |
2742 | dict_insert(irc_func_dict, "404", cmd_dummy); /* cannot send to channel */ | |
0d16e639 | 2743 | dict_insert(irc_func_dict, "439", cmd_dummy); /* target change too fast */ |
d76ed9a9 AS |
2744 | dict_insert(irc_func_dict, "441", cmd_dummy); /* target isn't on that channel */ |
2745 | dict_insert(irc_func_dict, "442", cmd_dummy); /* you aren't on that channel */ | |
2746 | dict_insert(irc_func_dict, "443", cmd_dummy); /* is already on channel (after invite?) */ | |
2747 | dict_insert(irc_func_dict, "461", cmd_dummy); /* Not enough parameters (after TOPIC w/ 0 args) */ | |
2748 | dict_insert(irc_func_dict, "467", cmd_dummy); /* Channel key already set */ | |
2749 | ||
2750 | num_privmsg_funcs = 16; | |
2751 | privmsg_funcs = malloc(sizeof(privmsg_func_t)*num_privmsg_funcs); | |
2752 | memset(privmsg_funcs, 0, sizeof(privmsg_func_t)*num_privmsg_funcs); | |
2753 | ||
2754 | num_notice_funcs = 16; | |
2755 | notice_funcs = malloc(sizeof(privmsg_func_t)*num_notice_funcs); | |
2756 | memset(notice_funcs, 0, sizeof(privmsg_func_t)*num_notice_funcs); | |
2757 | ||
2758 | userList_init(&dead_users); | |
1898d8ea | 2759 | reg_del_channel_func(remove_unbursted_channel, NULL); |
30874d66 | 2760 | reg_exit_func(parse_cleanup, NULL); |
da5b7dfc | 2761 | // reg_notice_func(opserv, check_ctcp); |
d76ed9a9 AS |
2762 | } |
2763 | ||
2764 | int | |
2765 | parse_line(char *line, int recursive) | |
2766 | { | |
2767 | char *argv[MAXNUMPARAMS], *origin; | |
2768 | int argc, cmd, res=0; | |
2769 | cmd_func_t *func; | |
2770 | ||
2771 | argc = split_line(line, true, MAXNUMPARAMS, argv); | |
2772 | cmd = self->uplink || !argv[0][1] || !argv[0][2]; | |
2773 | if (argc > cmd) { | |
2774 | if (cmd) { | |
2775 | if (argv[0][0] == ':') { | |
2776 | origin = argv[0]+1; | |
2777 | } else if (!argv[0][1] || !argv[0][2]) { | |
2778 | struct server *sNode = GetServerN(argv[0]); | |
2779 | origin = sNode ? sNode->name : 0; | |
2780 | } else { | |
2781 | struct userNode *uNode = GetUserN(argv[0]); | |
2782 | origin = uNode ? uNode->nick : 0; | |
2783 | } | |
2784 | } else | |
2785 | origin = 0; | |
2786 | if ((func = dict_find(irc_func_dict, argv[cmd], NULL))) | |
2787 | res = func(origin, argc-cmd, argv+cmd); | |
2788 | } | |
2789 | if (!res) { | |
2790 | log_module(MAIN_LOG, LOG_ERROR, "PARSE ERROR on line: %s", unsplit_string(argv, argc, NULL)); | |
2791 | } else if (!recursive) { | |
2792 | unsigned int i; | |
2793 | for (i=0; i<dead_users.used; i++) | |
2794 | free_user(dead_users.list[i]); | |
2795 | dead_users.used = 0; | |
2796 | } | |
2797 | return res; | |
2798 | } | |
2799 | ||
2800 | static void | |
2801 | parse_foreach(char *target_list, foreach_chanfunc cf, foreach_nonchan nc, foreach_userfunc uf, foreach_nonuser nu, void *data) | |
2802 | { | |
2803 | char *j, old; | |
2f61d1d7 | 2804 | |
d76ed9a9 AS |
2805 | do { |
2806 | j = target_list; | |
2807 | while (*j != 0 && *j != ',') | |
2808 | j++; | |
2809 | old = *j; | |
2810 | *j = 0; | |
2f61d1d7 | 2811 | |
d76ed9a9 AS |
2812 | if (IsChannelName(target_list) |
2813 | || (target_list[0] == '0' && target_list[1] == '\0')) { | |
2814 | struct chanNode *chan = GetChannel(target_list); | |
2f61d1d7 | 2815 | |
d76ed9a9 AS |
2816 | if (chan) { |
2817 | if (cf) | |
2818 | cf(chan, data); | |
2819 | } else { | |
2820 | if (nc) | |
2821 | nc(target_list, data); | |
2822 | } | |
2823 | } else { | |
2824 | struct userNode *user; | |
2825 | struct privmsg_desc *pd = data; | |
2826 | ||
2827 | pd->is_qualified = 0; | |
2828 | if (*target_list == '@') { | |
2829 | user = NULL; | |
2830 | } else if (strchr(target_list, '@')) { | |
2831 | struct server *server; | |
2832 | ||
2833 | pd->is_qualified = 1; | |
2834 | user = GetUserH(strtok(target_list, "@")); | |
2835 | server = GetServerH(strtok(NULL, "@")); | |
2836 | ||
2837 | if (user && (user->uplink != server)) { | |
2838 | /* Don't attempt to index into any arrays | |
2839 | using a user's numeric on another server. */ | |
2840 | user = NULL; | |
2841 | } | |
2842 | } else { | |
2843 | user = GetUserN(target_list); | |
2844 | } | |
2845 | ||
2846 | if (user) { | |
2847 | if (uf) | |
2848 | uf(user, data); | |
2849 | } else { | |
2850 | if (nu) | |
2851 | nu(target_list, data); | |
2852 | } | |
2853 | } | |
2854 | target_list = j+1; | |
2855 | } while (old == ','); | |
2856 | } | |
2857 | ||
2858 | static int | |
2859 | get_local_numeric(void) | |
2860 | { | |
2861 | static unsigned int next_numeric = 0; | |
2862 | if (self->clients > self->num_mask) | |
2863 | return -1; | |
2864 | while (self->users[next_numeric]) | |
2865 | if (++next_numeric > self->num_mask) | |
2866 | next_numeric = 0; | |
2867 | return next_numeric; | |
2868 | } | |
2869 | ||
2870 | static void | |
2871 | make_numeric(struct server *svr, int local_num, char *outbuf) | |
2872 | { | |
2873 | int slen, llen; | |
2874 | ||
2875 | if (force_n2k || svr->numeric[1]) { | |
2876 | slen = 2; | |
2877 | llen = 3; | |
2878 | } else { | |
2879 | slen = 1; | |
2880 | llen = (local_num < 64*64) ? 2 : 3; | |
2881 | } | |
2882 | strncpy(outbuf, svr->numeric, slen); | |
2883 | inttobase64(outbuf+slen, local_num, llen); | |
2884 | outbuf[slen+llen] = 0; | |
2885 | } | |
2886 | ||
2887 | struct server * | |
1136f709 | 2888 | AddServer(struct server *uplink, const char *name, int hops, time_t boot, time_t link_time, const char *numeric, const char *description) |
d76ed9a9 AS |
2889 | { |
2890 | struct server* sNode; | |
2891 | int slen, mlen; | |
2892 | ||
2893 | if ((sNode = GetServerN(numeric))) { | |
2894 | /* This means we're trying to re-add an existant server. | |
2895 | * To be safe, we should forget the previous incarnation. | |
2896 | * (And all its linked servers.) | |
2897 | * | |
2898 | * It usually only happens in replays when the original | |
2899 | * had a ping timeout and the replay didn't (because | |
2900 | * replaying a ping timeout invariably gets things wrong). | |
2901 | */ | |
2902 | DelServer(sNode, 0, NULL); | |
2903 | } | |
2904 | ||
2905 | switch (strlen(numeric)) { | |
2906 | case 5: slen = 2; mlen = 3; break; | |
2907 | case 4: slen = 1; mlen = 3; break; | |
2908 | case 3: slen = 1; mlen = 2; break; | |
2909 | default: | |
2910 | log_module(MAIN_LOG, LOG_ERROR, "AddServer(\"%s\", \"%s\", ...): Numeric %s has invalid length.", uplink->name, name, numeric); | |
2911 | return NULL; | |
2912 | } | |
2913 | ||
2914 | sNode = calloc(1, sizeof(*sNode)); | |
2915 | sNode->uplink = uplink; | |
2916 | safestrncpy(sNode->name, name, sizeof(sNode->name)); | |
2917 | sNode->num_mask = base64toint(numeric+slen, mlen); | |
2918 | sNode->hops = hops; | |
2919 | sNode->boot = boot; | |
1136f709 | 2920 | sNode->link_time = link_time; |
d76ed9a9 AS |
2921 | strncpy(sNode->numeric, numeric, slen); |
2922 | safestrncpy(sNode->description, description, sizeof(sNode->description)); | |
2923 | sNode->users = calloc(sNode->num_mask+1, sizeof(*sNode->users)); | |
2924 | serverList_init(&sNode->children); | |
2925 | if (sNode->uplink) { | |
2926 | /* uplink may be NULL if we're just building ourself */ | |
2927 | serverList_append(&sNode->uplink->children, sNode); | |
2928 | } | |
2929 | servers_num[base64toint(numeric, slen)] = sNode; | |
2930 | dict_insert(servers, sNode->name, sNode); | |
2931 | return sNode; | |
2932 | } | |
2933 | ||
2934 | void DelServer(struct server* serv, int announce, const char *message) | |
2935 | { | |
2936 | unsigned int i; | |
2937 | ||
2938 | /* If we receive an ERROR command before the SERVER | |
2939 | * command a NULL server can be passed */ | |
2940 | if (!serv) | |
2941 | return; | |
2942 | ||
2943 | /* Hrm, what's the right way to SQUIT some other server? | |
2944 | * (This code is only to handle killing juped servers.) */ | |
2945 | if (announce && (serv->uplink == self) && (serv != self->uplink)) | |
2946 | irc_squit(serv, message, NULL); | |
2947 | ||
2948 | /* must recursively remove servers linked to this one first */ | |
2949 | for (i=serv->children.used;i>0;) | |
2950 | if (serv->children.list[--i] != self) | |
2951 | DelServer(serv->children.list[i], false, NULL); | |
2952 | ||
2953 | /* clean up server's user hash tables */ | |
2954 | for (i=0;i<=serv->num_mask;i++) | |
2955 | if (serv->users[i]) | |
2956 | DelUser(serv->users[i], NULL, false, "server delinked"); | |
2957 | ||
2958 | /* delete server */ | |
2959 | if (serv->uplink) | |
2960 | serverList_remove(&serv->uplink->children, serv); | |
2961 | if (serv == self->uplink) | |
2962 | self->uplink = NULL; | |
2963 | servers_num[base64toint(serv->numeric, strlen(serv->numeric))] = NULL; | |
2964 | dict_remove(servers, serv->name); | |
2965 | serverList_clean(&serv->children); | |
2966 | free(serv->users); | |
2967 | free(serv); | |
2968 | } | |
2969 | ||
2970 | struct userNode * | |
1136f709 | 2971 | AddLocalUser(const char *nick, const char *ident, const char *hostname, const char *desc, const char *modes) |
d76ed9a9 AS |
2972 | { |
2973 | char numeric[COMBO_NUMERIC_LEN+1]; | |
2974 | int local_num = get_local_numeric(); | |
2975 | time_t timestamp = now; | |
2976 | struct userNode *old_user = GetUserH(nick); | |
2977 | ||
1136f709 | 2978 | if (!modes) |
2979 | modes = "+oik"; | |
2980 | ||
d76ed9a9 AS |
2981 | if (old_user) { |
2982 | if (IsLocal(old_user)) | |
2983 | return old_user; | |
2984 | timestamp = old_user->timestamp - 1; | |
2985 | } | |
2986 | if (local_num == -1) { | |
2987 | log_module(MAIN_LOG, LOG_ERROR, "Unable to allocate numnick for service %s", nick); | |
2988 | return 0; | |
2989 | } | |
2990 | if (!hostname) | |
2991 | hostname = self->name; | |
2992 | make_numeric(self, local_num, numeric); | |
1136f709 | 2993 | return AddUser(self, nick, ident, hostname, modes, numeric, desc, now, "AAAAAA"); |
d76ed9a9 AS |
2994 | } |
2995 | ||
2996 | struct userNode * | |
2997 | AddClone(const char *nick, const char *ident, const char *hostname, const char *desc) | |
2998 | { | |
2999 | char numeric[COMBO_NUMERIC_LEN+1]; | |
3000 | int local_num = get_local_numeric(); | |
3001 | time_t timestamp = now; | |
3002 | struct userNode *old_user = GetUserH(nick); | |
3003 | ||
3004 | if (old_user) { | |
3005 | if (IsLocal(old_user)) | |
3006 | return old_user; | |
3007 | timestamp = old_user->timestamp - 1; | |
3008 | } | |
3009 | if (local_num == -1) { | |
3010 | log_module(MAIN_LOG, LOG_ERROR, "Unable to allocate numnick for clone %s", nick); | |
3011 | return 0; | |
3012 | } | |
3013 | make_numeric(self, local_num, numeric); | |
3014 | return AddUser(self, nick, ident, hostname, "+i", numeric, desc, timestamp, "AAAAAA"); | |
3015 | } | |
3016 | ||
3017 | int | |
3018 | is_valid_nick(const char *nick) { | |
ec1a68c8 | 3019 | unsigned int ii; |
d76ed9a9 AS |
3020 | /* IRC has some of The Most Fucked-Up ideas about character sets |
3021 | * in the world.. */ | |
3022 | if (!isalpha(*nick) && !strchr("{|}~[\\]^_`", *nick)) | |
3023 | return 0; | |
ec1a68c8 | 3024 | for (ii = 0; nick[ii]; ++ii) |
3025 | if (!isalnum(nick[ii]) && !strchr("{|}~[\\]^-_`", nick[ii])) | |
d76ed9a9 AS |
3026 | return 0; |
3027 | if (strlen(nick) > nicklen) | |
3028 | return 0; | |
3029 | return 1; | |
3030 | } | |
3031 | ||
3032 | static struct userNode* | |
3033 | AddUser(struct server* uplink, const char *nick, const char *ident, const char *hostname, const char *modes, const char *numeric, const char *userinfo, time_t timestamp, const char *realip) | |
3034 | { | |
3035 | struct userNode *oldUser, *uNode; | |
f0fb2e2d | 3036 | unsigned int ignore_user, dummy; |
412b1e16 | 3037 | char *tstr; |
3038 | int type; | |
d76ed9a9 AS |
3039 | |
3040 | if ((strlen(numeric) < 3) || (strlen(numeric) > 5)) { | |
1136f709 | 3041 | log_module(MAIN_LOG, LOG_WARNING, "AddUser(%p, %s, ...): numeric %s wrong length!", (void*)uplink, nick, numeric); |
d76ed9a9 AS |
3042 | return NULL; |
3043 | } | |
3044 | ||
3045 | if (!uplink) { | |
1136f709 | 3046 | log_module(MAIN_LOG, LOG_WARNING, "AddUser(%p, %s, ...): server for numeric %s doesn't exist!", (void*)uplink, nick, numeric); |
d76ed9a9 AS |
3047 | return NULL; |
3048 | } | |
3049 | ||
3050 | if (uplink != GetServerN(numeric)) { | |
1136f709 | 3051 | log_module(MAIN_LOG, LOG_WARNING, "AddUser(%p, %s, ...): server for numeric %s differs from nominal uplink %s.", (void*)uplink, nick, numeric, uplink->name); |
d76ed9a9 AS |
3052 | return NULL; |
3053 | } | |
3054 | ||
1136f709 | 3055 | dummy = modes && modes[0] == '*'; |
3056 | if (dummy) { | |
3057 | ++modes; | |
3058 | } else if (!is_valid_nick(nick)) { | |
3059 | log_module(MAIN_LOG, LOG_WARNING, "AddUser(%p, %s, ...): invalid nickname detected.", (void*)uplink, nick); | |
d76ed9a9 AS |
3060 | return NULL; |
3061 | } | |
3062 | ||
3063 | ignore_user = 0; | |
3064 | if ((oldUser = GetUserH(nick))) { | |
1136f709 | 3065 | if (IsLocal(oldUser) |
3066 | && (IsService(oldUser) || IsPersistent(oldUser))) { | |
3067 | /* The service should collide the new user off - but not | |
3068 | * if the new user is coming in during a burst. (During a | |
3069 | * burst, the bursting server will kill either our user -- | |
3070 | * triggering a ReintroduceUser() -- or its own.) | |
3071 | */ | |
d76ed9a9 | 3072 | oldUser->timestamp = timestamp - 1; |
1136f709 | 3073 | ignore_user = 1; |
3074 | if (!uplink->burst) | |
3075 | irc_user(oldUser); | |
3076 | } else if (oldUser->timestamp > timestamp) { | |
d76ed9a9 AS |
3077 | /* "Old" user is really newer; remove them */ |
3078 | DelUser(oldUser, 0, 1, "Overruled by older nick"); | |
3079 | } else { | |
3080 | /* User being added is too new; do not add them to | |
3081 | * clients, but do add them to the server's list, since it | |
3082 | * will send a KILL and QUIT soon. */ | |
3083 | ignore_user = 1; | |
3084 | } | |
3085 | } | |
3086 | ||
3087 | /* create new usernode and set all values */ | |
3088 | uNode = calloc(1, sizeof(*uNode)); | |
3089 | uNode->nick = strdup(nick); | |
3090 | safestrncpy(uNode->ident, ident, sizeof(uNode->ident)); | |
3091 | safestrncpy(uNode->info, userinfo, sizeof(uNode->info)); | |
3092 | safestrncpy(uNode->hostname, hostname, sizeof(uNode->hostname)); | |
3093 | safestrncpy(uNode->numeric, numeric, sizeof(uNode->numeric)); | |
2f61d1d7 | 3094 | irc_p10_pton(&uNode->ip, realip); |
37ef8ee3 | 3095 | |
412b1e16 | 3096 | tstr = conf_get_data("server/type", RECDB_QSTRING); |
3097 | type = atoi(tstr); | |
1dfca92d | 3098 | if (type == 7) { |
412b1e16 | 3099 | if (irc_in_addr_is_ipv4(uNode->ip)) { |
3100 | make_virtip((char*)irc_ntoa(&uNode->ip), (char*)irc_ntoa(&uNode->ip), uNode->cryptip); | |
3101 | make_virthost((char*)irc_ntoa(&uNode->ip), uNode->hostname, uNode->crypthost); | |
3102 | } else if (irc_in_addr_is_ipv6(uNode->ip)) { | |
3103 | make_ipv6virthost((char*)irc_ntoa(&uNode->ip), uNode->hostname, uNode->crypthost); | |
3104 | } | |
68b75482 | 3105 | } |
37ef8ee3 | 3106 | |
f16ad9e7 | 3107 | if (!uNode->crypthost && uNode->cryptip) |
3108 | snprintf(uNode->crypthost, sizeof(uNode->crypthost), "%s", strdup(uNode->cryptip)); | |
1136f709 | 3109 | uNode->idle_since = timestamp; |
d76ed9a9 AS |
3110 | uNode->timestamp = timestamp; |
3111 | modeList_init(&uNode->channels); | |
3112 | uNode->uplink = uplink; | |
3113 | if (++uNode->uplink->clients > uNode->uplink->max_clients) { | |
3114 | uNode->uplink->max_clients = uNode->uplink->clients; | |
3115 | } | |
3116 | uNode->num_local = base64toint(numeric+strlen(uNode->uplink->numeric), 3) & uNode->uplink->num_mask; | |
3117 | uNode->uplink->users[uNode->num_local] = uNode; | |
3118 | mod_usermode(uNode, modes); | |
1136f709 | 3119 | if (dummy) |
3120 | uNode->modes |= FLAGS_DUMMY; | |
21f6caee | 3121 | |
3122 | set_geoip_info(uNode); | |
3123 | ||
d76ed9a9 AS |
3124 | if (ignore_user) |
3125 | return uNode; | |
3126 | ||
3127 | dict_insert(clients, uNode->nick, uNode); | |
3128 | if (dict_size(clients) > max_clients) { | |
3129 | max_clients = dict_size(clients); | |
3130 | max_clients_time = now; | |
3131 | } | |
3132 | if (IsLocal(uNode)) | |
3133 | irc_user(uNode); | |
63189c10 | 3134 | call_new_user_funcs(uNode); |
3fdd6a74 | 3135 | |
3136 | if ((uNode->loc == 1) && (uNode->handle_info)) | |
3137 | send_func_list(uNode); | |
3138 | ||
d76ed9a9 AS |
3139 | return uNode; |
3140 | } | |
3141 | ||
3142 | /* removes user from it's server's hash table and nick hash table */ | |
3143 | void | |
3144 | DelUser(struct userNode* user, struct userNode *killer, int announce, const char *why) | |
3145 | { | |
d76ed9a9 | 3146 | |
ec1a68c8 | 3147 | verify(user); |
3148 | ||
d76ed9a9 AS |
3149 | /* mark them as dead, in case anybody cares */ |
3150 | user->dead = 1; | |
3151 | ||
ac3bdc8d AS |
3152 | /* remove pending adduser commands */ |
3153 | wipe_adduser_pending(NULL, user); | |
3154 | ||
d76ed9a9 AS |
3155 | /* remove user from all channels */ |
3156 | while (user->channels.used > 0) | |
1136f709 | 3157 | DelChannelUser(user, user->channels.list[user->channels.used-1]->channel, NULL, 0); |
d76ed9a9 AS |
3158 | |
3159 | /* Call these in reverse order so ChanServ can update presence | |
3160 | information before NickServ nukes the handle_info. */ | |
a6bcc929 | 3161 | call_del_user_funcs(user, killer, why); |
d76ed9a9 AS |
3162 | |
3163 | user->uplink->clients--; | |
3164 | user->uplink->users[user->num_local] = NULL; | |
3165 | if (IsOper(user)) | |
3166 | userList_remove(&curr_opers, user); | |
3167 | /* remove from global dictionary, but not if after a collide */ | |
3168 | if (user == dict_find(clients, user->nick, NULL)) | |
3169 | dict_remove(clients, user->nick); | |
3170 | ||
3171 | if (IsInvisible(user)) | |
3172 | invis_clients--; | |
3173 | ||
3174 | if (announce) { | |
3175 | if (IsLocal(user)) | |
3176 | irc_quit(user, why); | |
3177 | else | |
3178 | irc_kill(killer, user, why); | |
3179 | } | |
3180 | ||
1136f709 | 3181 | if (IsLocal(user)) { |
3182 | unsigned int num = user->num_local; | |
3183 | if (num < num_privmsg_funcs) | |
3184 | privmsg_funcs[num] = NULL; | |
3185 | if (num < num_notice_funcs) | |
3186 | notice_funcs[num] = NULL; | |
3187 | } | |
3188 | ||
d76ed9a9 | 3189 | modeList_clean(&user->channels); |
0e08a8e0 AS |
3190 | |
3191 | /* Clean up version data */ | |
3192 | if(user->version_reply) { | |
3193 | free(user->version_reply); | |
3194 | user->version_reply = NULL; | |
3195 | } | |
3196 | ||
ba4b4d51 MB |
3197 | /* Clean up SSL fingerprint data */ |
3198 | if(user->sslfp) { | |
3199 | free(user->sslfp); | |
3200 | user->sslfp = NULL; | |
3201 | } | |
3202 | ||
2c00fbc2 AS |
3203 | /* clean up mark */ |
3204 | if(user->mark) { | |
3205 | free(user->mark); | |
3206 | user->mark = NULL; | |
3207 | } | |
3208 | ||
0e08a8e0 AS |
3209 | /* clean up geoip data if any */ |
3210 | if(user->country_code) free(user->country_code); | |
3211 | if(user->city) free(user->city); | |
3212 | if(user->region) free(user->region); | |
3213 | if(user->postal_code) free(user->postal_code); | |
3214 | ||
d76ed9a9 AS |
3215 | /* We don't free them, in case we try to privmsg them or something |
3216 | * (like when a stupid oper kills themself). We just put them onto | |
3217 | * a list of clients that get freed after processing each line. | |
3218 | */ | |
3219 | if (dead_users.size) | |
3220 | userList_append(&dead_users, user); | |
3221 | else | |
3222 | free_user(user); | |
3223 | } | |
3224 | ||
697f4c9a | 3225 | static void call_oper_funcs(struct userNode *user); |
3226 | ||
d76ed9a9 | 3227 | void mod_usermode(struct userNode *user, const char *mode_change) { |
d76ed9a9 AS |
3228 | int add = 1; |
3229 | const char *word = mode_change; | |
3230 | ||
3231 | if (!user || !mode_change) | |
3232 | return; | |
ec311f39 | 3233 | |
3234 | call_user_mode_funcs(user, mode_change); | |
3235 | ||
a32da4c7 | 3236 | while (*word != ' ' && *word) word++; |
3237 | while (*word == ' ') word++; | |
d76ed9a9 AS |
3238 | while (1) { |
3239 | #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0) | |
3240 | switch (*mode_change++) { | |
3241 | case 0: case ' ': return; | |
3242 | case '+': add = 1; break; | |
3243 | case '-': add = 0; break; | |
3244 | case 'o': | |
3d0b24ce | 3245 | do_user_mode(FLAGS_OPER); |
1136f709 | 3246 | if (!add) { |
3247 | userList_remove(&curr_opers, user); | |
3248 | } else if (!userList_contains(&curr_opers, user)) { | |
3249 | userList_append(&curr_opers, user); | |
3250 | call_oper_funcs(user); | |
3251 | } | |
d76ed9a9 AS |
3252 | break; |
3253 | case 'O': do_user_mode(FLAGS_LOCOP); break; | |
3254 | case 'i': do_user_mode(FLAGS_INVISIBLE); | |
3255 | if (add) | |
3256 | invis_clients++; | |
3257 | else | |
3258 | invis_clients--; | |
3259 | break; | |
3260 | case 'w': do_user_mode(FLAGS_WALLOP); break; | |
d76ed9a9 AS |
3261 | case 'd': do_user_mode(FLAGS_DEAF); break; |
3262 | case 'k': do_user_mode(FLAGS_SERVICE); break; | |
3263 | case 'g': do_user_mode(FLAGS_GLOBAL); break; | |
cf8bedff | 3264 | case 'B': do_user_mode(FLAGS_BOT); break; |
3265 | case 'n': do_user_mode(FLAGS_HIDECHANS); break; | |
3266 | case 'I': do_user_mode(FLAGS_HIDEIDLE); break; | |
3267 | case 'X': do_user_mode(FLAGS_XTRAOP); break; | |
412b1e16 | 3268 | case 'C': do_user_mode(FLAGS_CLOAKHOST); |
3269 | if (*word) { | |
3270 | char cloakhost[MAXLEN]; | |
3271 | unsigned int ii; | |
3272 | for (ii=0; (*word != ' ') && (*word != '\0'); ) | |
3273 | cloakhost[ii++] = *word++; | |
3274 | cloakhost[ii] = 0; | |
3275 | while (*word == ' ') | |
3276 | word++; | |
3277 | safestrncpy(user->crypthost, cloakhost, sizeof(user->crypthost)); | |
3278 | } | |
3279 | break; | |
3280 | case 'c': do_user_mode(FLAGS_CLOAKIP); | |
3281 | if (*word) { | |
3282 | char cloakip[MAXLEN]; | |
3283 | unsigned int ii; | |
3284 | for (ii=0; (*word != ' ') && (*word != '\0'); ) | |
3285 | cloakip[ii++] = *word++; | |
3286 | cloakip[ii] = 0; | |
3287 | while (*word == ' ') | |
3288 | word++; | |
3289 | safestrncpy(user->cryptip, cloakip, sizeof(user->cryptip)); | |
3290 | } | |
3291 | break; | |
cf8bedff | 3292 | // sethost - reed/apples |
3293 | // case 'h': do_user_mode(FLAGS_HELPER); break; | |
3294 | // I check if there's an 'h' in the first part, and if there, | |
3295 | // then everything after the space becomes their new host. | |
182dd032 AS |
3296 | case 'h': do_user_mode(FLAGS_SETHOST); |
3297 | if (*word) { | |
3298 | char sethost[MAXLEN]; | |
3299 | unsigned int ii; | |
3300 | for (ii=0; (*word != ' ') && (*word != '\0'); ) | |
3301 | sethost[ii++] = *word++; | |
3302 | sethost[ii] = 0; | |
3303 | while (*word == ' ') | |
3304 | word++; | |
3305 | safestrncpy(user->sethost, sethost, sizeof(user->sethost)); | |
3306 | } | |
3307 | break; | |
d76ed9a9 AS |
3308 | case 'x': do_user_mode(FLAGS_HIDDEN_HOST); break; |
3309 | case 'r': | |
3310 | if (*word) { | |
3311 | char tag[MAXLEN]; | |
3312 | unsigned int ii; | |
3313 | for (ii=0; (*word != ' ') && (*word != '\0'); ) | |
3314 | tag[ii++] = *word++; | |
3315 | tag[ii] = 0; | |
3316 | while (*word == ' ') | |
3317 | word++; | |
3318 | call_account_func(user, tag); | |
3319 | } | |
3320 | break; | |
3321 | case 'f': | |
3322 | if (*word) { | |
3323 | char host[MAXLEN]; | |
3324 | unsigned int ii; | |
3325 | for (ii=0; (*word != ' ') && (*word != '\0'); ) | |
3326 | host[ii++] = *word++; | |
3327 | host[ii] = 0; | |
3328 | while (*word == ' ') | |
3329 | word++; | |
3330 | assign_fakehost(user, host, 0); | |
3331 | } | |
3332 | break; | |
fc55e757 MB |
3333 | case 'a': do_user_mode(FLAGS_ADMIN); break; |
3334 | case 'z': do_user_mode(FLAGS_SSL); break; | |
8d882965 MB |
3335 | case 'D': do_user_mode(FLAGS_PRIVDEAF); break; |
3336 | case 'R': do_user_mode(FLAGS_ACCOUNTONLY); break; | |
3337 | case 'W': do_user_mode(FLAGS_WHOIS); break; | |
3338 | case 'H': do_user_mode(FLAGS_HIDEOPER); break; | |
3339 | case 'L': do_user_mode(FLAGS_NOLINK); break; | |
3340 | case 'q': do_user_mode(FLAGS_COMMONCHANSONLY); break; | |
d76ed9a9 AS |
3341 | } |
3342 | #undef do_user_mode | |
3343 | } | |
3344 | } | |
3345 | ||
1136f709 | 3346 | static int |
3347 | keyncpy(char output[], char input[], size_t output_size) | |
3348 | { | |
3349 | size_t ii; | |
3350 | ||
3351 | if (input[0] == ':') | |
3352 | { | |
3353 | output[0] = '\0'; | |
3354 | return 1; | |
3355 | } | |
3356 | ||
3357 | for (ii = 0; (ii + 1 < output_size) && (input[ii] != '\0'); ++ii) | |
3358 | { | |
3359 | output[ii] = input[ii]; | |
3360 | } | |
3361 | ||
3362 | output[ii] = '\0'; | |
3363 | return 0; | |
3364 | } | |
3365 | ||
d76ed9a9 | 3366 | struct mod_chanmode * |
2f61d1d7 | 3367 | mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags, short base_oplevel) |
d76ed9a9 AS |
3368 | { |
3369 | struct mod_chanmode *change; | |
3370 | unsigned int ii, in_arg, ch_arg, add; | |
3371 | ||
3372 | if (argc == 0) | |
3373 | return NULL; | |
3374 | if (!(change = mod_chanmode_alloc(argc - 1))) | |
3375 | return NULL; | |
3376 | ||
3377 | for (ii = ch_arg = 0, in_arg = add = 1; | |
3378 | (modes[0][ii] != '\0') && (modes[0][ii] != ' '); | |
3379 | ++ii) { | |
3380 | switch (modes[0][ii]) { | |
3381 | case '+': | |
3382 | add = 1; | |
3383 | break; | |
3384 | case '-': | |
3385 | add = 0; | |
3386 | break; | |
3387 | #define do_chan_mode(FLAG) do { if (add) change->modes_set |= (FLAG), change->modes_clear &= ~(FLAG); else change->modes_clear |= (FLAG), change->modes_set &= ~(FLAG); } while(0) | |
3388 | case 'C': do_chan_mode(MODE_NOCTCPS); break; | |
3389 | case 'D': do_chan_mode(MODE_DELAYJOINS); break; | |
3390 | case 'c': do_chan_mode(MODE_NOCOLORS); break; | |
3391 | case 'i': do_chan_mode(MODE_INVITEONLY); break; | |
3392 | case 'm': do_chan_mode(MODE_MODERATED); break; | |
3393 | case 'n': do_chan_mode(MODE_NOPRIVMSGS); break; | |
3394 | case 'p': do_chan_mode(MODE_PRIVATE); break; | |
3395 | case 'r': do_chan_mode(MODE_REGONLY); break; | |
3396 | case 's': do_chan_mode(MODE_SECRET); break; | |
3397 | case 't': do_chan_mode(MODE_TOPICLIMIT); break; | |
d0cb2fb6 AS |
3398 | case 'S': do_chan_mode(MODE_STRIPCOLOR); break; |
3399 | case 'M': do_chan_mode(MODE_MODUNREG); break; | |
3400 | case 'N': do_chan_mode(MODE_NONOTICE); break; | |
3401 | case 'Q': do_chan_mode(MODE_NOQUITMSGS); break; | |
3402 | case 'T': do_chan_mode(MODE_NOAMSG); break; | |
3403 | case 'O': do_chan_mode(MODE_OPERSONLY); break; | |
4648ded2 | 3404 | case 'a': do_chan_mode(MODE_ADMINSONLY); break; |
c8ca69a0 | 3405 | case 'Z': do_chan_mode(MODE_SSLONLY); break; |
88c7cb10 | 3406 | case 'L': do_chan_mode(MODE_HIDEMODE); break; |
ec1a68c8 | 3407 | case 'z': |
3408 | if (!(flags & MCP_REGISTERED)) { | |
1136f709 | 3409 | do_chan_mode(MODE_REGISTERED); |
ec1a68c8 | 3410 | } else { |
1136f709 | 3411 | mod_chanmode_free(change); |
3412 | return NULL; | |
ec1a68c8 | 3413 | } |
3414 | break; | |
d76ed9a9 AS |
3415 | #undef do_chan_mode |
3416 | case 'l': | |
3417 | if (add) { | |
3418 | if (in_arg >= argc) | |
3419 | goto error; | |
3420 | change->modes_set |= MODE_LIMIT; | |
3421 | change->new_limit = atoi(modes[in_arg++]); | |
3422 | } else { | |
3423 | change->modes_set &= ~MODE_LIMIT; | |
3424 | change->modes_clear |= MODE_LIMIT; | |
3425 | } | |
3426 | break; | |
3427 | case 'k': | |
3428 | if (add) { | |
1136f709 | 3429 | if ((in_arg >= argc) |
3430 | || keyncpy(change->new_key, modes[in_arg++], sizeof(change->new_key))) | |
d76ed9a9 AS |
3431 | goto error; |
3432 | change->modes_set |= MODE_KEY; | |
d76ed9a9 AS |
3433 | } else { |
3434 | change->modes_clear |= MODE_KEY; | |
3435 | if (!(flags & MCP_KEY_FREE)) { | |
3436 | if (in_arg >= argc) | |
3437 | goto error; | |
3438 | in_arg++; | |
3439 | } | |
3440 | } | |
3441 | break; | |
2f61d1d7 | 3442 | case 'U': |
3443 | if (add) | |
3444 | { | |
1136f709 | 3445 | if ((in_arg >= argc) |
3446 | || keyncpy(change->new_upass, modes[in_arg++], sizeof(change->new_upass))) | |
3447 | goto error; | |
3448 | change->modes_set |= MODE_UPASS; | |
2f61d1d7 | 3449 | } else { |
3450 | change->modes_clear |= MODE_UPASS; | |
3451 | if (!(flags & MCP_UPASS_FREE)) { | |
3452 | if (in_arg >= argc) | |
3453 | goto error; | |
3454 | in_arg++; | |
3455 | } | |
3456 | } | |
3457 | break; | |
3458 | case 'A': | |
3459 | if (add) { | |
1136f709 | 3460 | if ((in_arg >= argc) |
3461 | || keyncpy(change->new_upass, modes[in_arg++], sizeof(change->new_upass))) | |
2f61d1d7 | 3462 | change->modes_set |= MODE_APASS; |
2f61d1d7 | 3463 | } else { |
3464 | change->modes_clear |= MODE_APASS; | |
3465 | if (!(flags & MCP_APASS_FREE)) { | |
3466 | if (in_arg >= argc) | |
3467 | goto error; | |
3468 | in_arg++; | |
3469 | } | |
3470 | } | |
3471 | break; | |
d76ed9a9 AS |
3472 | case 'b': |
3473 | if (!(flags & MCP_ALLOW_OVB)) | |
3474 | goto error; | |
3475 | if (in_arg >= argc) | |
3476 | goto error; | |
3477 | change->args[ch_arg].mode = MODE_BAN; | |
3478 | if (!add) | |
3479 | change->args[ch_arg].mode |= MODE_REMOVE; | |
a32da4c7 | 3480 | change->args[ch_arg++].u.hostmask = modes[in_arg++]; |
d76ed9a9 | 3481 | break; |
2aef5f4b | 3482 | case 'e': |
3483 | if (!(flags & MCP_ALLOW_OVB)) | |
3484 | goto error; | |
3485 | if (in_arg >= argc) | |
3486 | goto error; | |
3487 | change->args[ch_arg].mode = MODE_EXEMPT; | |
3488 | if (!add) | |
3489 | change->args[ch_arg].mode |= MODE_REMOVE; | |
a32da4c7 | 3490 | change->args[ch_arg++].u.hostmask = modes[in_arg++]; |
2aef5f4b | 3491 | break; |
55342ce8 | 3492 | case 'o': case 'h': case 'v': |
d76ed9a9 AS |
3493 | { |
3494 | struct userNode *victim; | |
2f61d1d7 | 3495 | char *oplevel_str; |
3496 | int oplevel; | |
3497 | ||
3498 | if (in_arg >= argc) | |
3499 | goto error; | |
3500 | oplevel_str = strchr(modes[in_arg], ':'); | |
3501 | if (oplevel_str) | |
3502 | { | |
3503 | /* XXYYY M #channel +o XXYYY:<oplevel> */ | |
3504 | *oplevel_str++ = '\0'; | |
3505 | oplevel = parse_oplevel(oplevel_str); | |
3506 | if (oplevel <= base_oplevel && !(flags & MCP_FROM_SERVER)) | |
3507 | oplevel = base_oplevel + 1; | |
3508 | } | |
3509 | else if (channel->modes & MODE_UPASS) | |
3510 | oplevel = base_oplevel + 1; | |
3511 | else | |
3512 | oplevel = -1; | |
3513 | ||
3514 | /* Check that oplevel is within bounds. */ | |
3515 | if (oplevel > MAXOPLEVEL) | |
3516 | oplevel = MAXOPLEVEL; | |
3517 | ||
d76ed9a9 AS |
3518 | if (!(flags & MCP_ALLOW_OVB)) |
3519 | goto error; | |
3520 | if (in_arg >= argc) | |
3521 | goto error; | |
55342ce8 | 3522 | |
3523 | if (modes[0][ii] == 'o') | |
3524 | change->args[ch_arg].mode = MODE_CHANOP; | |
3525 | else if (modes[0][ii] == 'h') | |
3526 | change->args[ch_arg].mode = MODE_HALFOP; | |
3527 | else if (modes[0][ii] == 'v') | |
3528 | change->args[ch_arg].mode = MODE_VOICE; | |
3529 | ||
d76ed9a9 AS |
3530 | if (!add) |
3531 | change->args[ch_arg].mode |= MODE_REMOVE; | |
3532 | if (flags & MCP_FROM_SERVER) | |
3533 | victim = GetUserN(modes[in_arg++]); | |
3534 | else | |
3535 | victim = GetUserH(modes[in_arg++]); | |
3536 | if (!victim) | |
3537 | continue; | |
a32da4c7 | 3538 | if ((change->args[ch_arg].u.member = GetUserMode(channel, victim))) |
2f61d1d7 | 3539 | { |
3540 | /* Apply the oplevel change */ | |
3541 | change->args[ch_arg].u.member->oplevel = oplevel; | |
d76ed9a9 | 3542 | ch_arg++; |
2f61d1d7 | 3543 | } |
d76ed9a9 AS |
3544 | break; |
3545 | } | |
3546 | default: | |
3547 | if (!(flags & MCP_FROM_SERVER)) | |
3548 | goto error; | |
3549 | break; | |
3550 | } | |
3551 | } | |
3552 | change->argc = ch_arg; /* in case any turned out to be ignored */ | |
3553 | if (change->modes_set & MODE_SECRET) { | |
3554 | change->modes_set &= ~(MODE_PRIVATE); | |
3555 | change->modes_clear |= MODE_PRIVATE; | |
3556 | } else if (change->modes_set & MODE_PRIVATE) { | |
3557 | change->modes_set &= ~(MODE_SECRET); | |
3558 | change->modes_clear |= MODE_SECRET; | |
3559 | } | |
3560 | return change; | |
3561 | error: | |
3562 | mod_chanmode_free(change); | |
3563 | return NULL; | |
3564 | } | |
3565 | ||
3566 | struct chanmode_buffer { | |
3567 | char modes[MAXLEN]; | |
3568 | char args[MAXLEN]; | |
3569 | struct chanNode *channel; | |
3570 | struct userNode *actor; | |
3571 | unsigned int modes_used; | |
3572 | unsigned int args_used; | |
3573 | size_t chname_len; | |
3574 | unsigned int is_add : 1; | |
3575 | unsigned int is_chanop : 1; | |
3576 | }; | |
3577 | ||
3578 | static void | |
3579 | mod_chanmode_append(struct chanmode_buffer *buf, char ch, const char *arg) | |
3580 | { | |
3581 | size_t arg_len = strlen(arg); | |
3582 | if (buf->modes_used > (MAXMODEPARAMS) || | |
3583 | buf->modes_used + buf->args_used + buf->chname_len + arg_len > 450) { | |
3584 | memcpy(buf->modes + buf->modes_used, buf->args, buf->args_used); | |
3585 | buf->modes[buf->modes_used + buf->args_used] = '\0'; | |
3586 | irc_mode((buf->is_chanop ? buf->actor : NULL), buf->channel, buf->modes); | |
3587 | buf->modes[0] = buf->is_add ? '+' : '-'; | |
3588 | buf->modes_used = 1; | |
3589 | buf->args_used = 0; | |
3590 | } | |
3591 | buf->modes[buf->modes_used++] = ch; | |
3592 | buf->args[buf->args_used++] = ' '; | |
3593 | memcpy(buf->args + buf->args_used, arg, arg_len); | |
3594 | buf->args_used += arg_len; | |
3595 | } | |
3596 | ||
3597 | void | |
3598 | mod_chanmode_announce(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change) | |
3599 | { | |
3600 | struct chanmode_buffer chbuf; | |
3601 | unsigned int arg; | |
3602 | struct modeNode *mn; | |
3603 | char int_buff[32], mode = '\0'; | |
3604 | ||
3605 | assert(change->argc <= change->alloc_argc); | |
3606 | memset(&chbuf, 0, sizeof(chbuf)); | |
3607 | chbuf.channel = channel; | |
3608 | chbuf.actor = who; | |
3609 | chbuf.chname_len = strlen(channel->name); | |
3610 | ||
3611 | mn = GetUserMode(channel, who); | |
3612 | if ((mn && (mn->modes & MODE_CHANOP)) || off_channel) | |
3613 | chbuf.is_chanop = 1; | |
3614 | ||
3615 | /* First remove modes */ | |
3616 | chbuf.is_add = 0; | |
3617 | if (change->modes_clear) { | |
3618 | if (mode != '-') | |
3619 | chbuf.modes[chbuf.modes_used++] = mode = '-'; | |
3620 | #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR | |
3621 | DO_MODE_CHAR(PRIVATE, 'p'); | |
3622 | DO_MODE_CHAR(SECRET, 's'); | |
3623 | DO_MODE_CHAR(MODERATED, 'm'); | |
3624 | DO_MODE_CHAR(TOPICLIMIT, 't'); | |
3625 | DO_MODE_CHAR(INVITEONLY, 'i'); | |
3626 | DO_MODE_CHAR(NOPRIVMSGS, 'n'); | |
3627 | DO_MODE_CHAR(LIMIT, 'l'); | |
3628 | DO_MODE_CHAR(DELAYJOINS, 'D'); | |
3629 | DO_MODE_CHAR(REGONLY, 'r'); | |
3630 | DO_MODE_CHAR(NOCOLORS, 'c'); | |
3631 | DO_MODE_CHAR(NOCTCPS, 'C'); | |
d0cb2fb6 AS |
3632 | DO_MODE_CHAR(STRIPCOLOR, 'S'); |
3633 | DO_MODE_CHAR(MODUNREG, 'M'); | |
3634 | DO_MODE_CHAR(NONOTICE, 'N'); | |
3635 | DO_MODE_CHAR(NOQUITMSGS, 'Q'); | |
3636 | DO_MODE_CHAR(NOAMSG, 'T'); | |
3637 | DO_MODE_CHAR(OPERSONLY, 'O'); | |
238102e1 | 3638 | DO_MODE_CHAR(ADMINSONLY, 'a'); |
ec1a68c8 | 3639 | DO_MODE_CHAR(REGISTERED, 'z'); |
c8ca69a0 | 3640 | DO_MODE_CHAR(SSLONLY, 'Z'); |
88c7cb10 | 3641 | DO_MODE_CHAR(HIDEMODE, 'L'); |
d76ed9a9 AS |
3642 | #undef DO_MODE_CHAR |
3643 | if (change->modes_clear & channel->modes & MODE_KEY) | |
3644 | mod_chanmode_append(&chbuf, 'k', channel->key); | |
2f61d1d7 | 3645 | if (change->modes_clear & channel->modes & MODE_UPASS) |
3646 | mod_chanmode_append(&chbuf, 'U', channel->upass); | |
1136f709 | 3647 | if (change->modes_clear & channel->modes & MODE_APASS) |
2f61d1d7 | 3648 | mod_chanmode_append(&chbuf, 'A', channel->apass); |
d76ed9a9 AS |
3649 | } |
3650 | for (arg = 0; arg < change->argc; ++arg) { | |
3651 | if (!(change->args[arg].mode & MODE_REMOVE)) | |
3652 | continue; | |
3653 | if (mode != '-') | |
3654 | chbuf.modes[chbuf.modes_used++] = mode = '-'; | |
3655 | switch (change->args[arg].mode & ~MODE_REMOVE) { | |
3656 | case MODE_BAN: | |
a32da4c7 | 3657 | mod_chanmode_append(&chbuf, 'b', change->args[arg].u.hostmask); |
d76ed9a9 | 3658 | break; |
2aef5f4b | 3659 | case MODE_EXEMPT: |
a32da4c7 | 3660 | mod_chanmode_append(&chbuf, 'e', change->args[arg].u.hostmask); |
2aef5f4b | 3661 | break; |
d76ed9a9 AS |
3662 | default: |
3663 | if (change->args[arg].mode & MODE_CHANOP) | |
a32da4c7 | 3664 | mod_chanmode_append(&chbuf, 'o', change->args[arg].u.member->user->numeric); |
55342ce8 | 3665 | if (change->args[arg].mode & MODE_HALFOP) |
a32da4c7 | 3666 | mod_chanmode_append(&chbuf, 'h', change->args[arg].u.member->user->numeric); |
d76ed9a9 | 3667 | if (change->args[arg].mode & MODE_VOICE) |
a32da4c7 | 3668 | mod_chanmode_append(&chbuf, 'v', change->args[arg].u.member->user->numeric); |
d76ed9a9 AS |
3669 | break; |
3670 | } | |
3671 | } | |
3672 | ||
3673 | /* Then set them */ | |
3674 | chbuf.is_add = 1; | |
3675 | if (change->modes_set) { | |
3676 | if (mode != '+') | |
3677 | chbuf.modes[chbuf.modes_used++] = mode = '+'; | |
3678 | #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) chbuf.modes[chbuf.modes_used++] = CHAR | |
3679 | DO_MODE_CHAR(PRIVATE, 'p'); | |
3680 | DO_MODE_CHAR(SECRET, 's'); | |
3681 | DO_MODE_CHAR(MODERATED, 'm'); | |
3682 | DO_MODE_CHAR(TOPICLIMIT, 't'); | |
3683 | DO_MODE_CHAR(INVITEONLY, 'i'); | |
3684 | DO_MODE_CHAR(NOPRIVMSGS, 'n'); | |
3685 | DO_MODE_CHAR(DELAYJOINS, 'D'); | |
3686 | DO_MODE_CHAR(REGONLY, 'r'); | |
3687 | DO_MODE_CHAR(NOCOLORS, 'c'); | |
3688 | DO_MODE_CHAR(NOCTCPS, 'C'); | |
d0cb2fb6 AS |
3689 | DO_MODE_CHAR(STRIPCOLOR, 'S'); |
3690 | DO_MODE_CHAR(MODUNREG, 'M'); | |
3691 | DO_MODE_CHAR(NONOTICE, 'N'); | |
3692 | DO_MODE_CHAR(NOQUITMSGS, 'Q'); | |
3693 | DO_MODE_CHAR(NOAMSG, 'T'); | |
3694 | DO_MODE_CHAR(OPERSONLY, 'O'); | |
238102e1 | 3695 | DO_MODE_CHAR(ADMINSONLY, 'a'); |
ec1a68c8 | 3696 | DO_MODE_CHAR(REGISTERED, 'z'); |
c8ca69a0 | 3697 | DO_MODE_CHAR(SSLONLY, 'Z'); |
88c7cb10 | 3698 | DO_MODE_CHAR(HIDEMODE, 'L'); |
d76ed9a9 AS |
3699 | #undef DO_MODE_CHAR |
3700 | if(change->modes_set & MODE_KEY) | |
3701 | mod_chanmode_append(&chbuf, 'k', change->new_key); | |
2f61d1d7 | 3702 | if (change->modes_set & MODE_UPASS) |
3703 | mod_chanmode_append(&chbuf, 'U', change->new_upass); | |
3704 | if (change->modes_set & MODE_APASS) | |
3705 | mod_chanmode_append(&chbuf, 'A', change->new_apass); | |
d76ed9a9 AS |
3706 | if(change->modes_set & MODE_LIMIT) { |
3707 | sprintf(int_buff, "%d", change->new_limit); | |
3708 | mod_chanmode_append(&chbuf, 'l', int_buff); | |
3709 | } | |
3710 | } | |
3711 | for (arg = 0; arg < change->argc; ++arg) { | |
3712 | if (change->args[arg].mode & MODE_REMOVE) | |
3713 | continue; | |
3714 | if (mode != '+') | |
3715 | chbuf.modes[chbuf.modes_used++] = mode = '+'; | |
3716 | switch (change->args[arg].mode) { | |
3717 | case MODE_BAN: | |
a32da4c7 | 3718 | mod_chanmode_append(&chbuf, 'b', change->args[arg].u.hostmask); |
d76ed9a9 | 3719 | break; |
2aef5f4b | 3720 | case MODE_EXEMPT: |
a32da4c7 | 3721 | mod_chanmode_append(&chbuf, 'e', change->args[arg].u.hostmask); |
2aef5f4b | 3722 | break; |
d76ed9a9 AS |
3723 | default: |
3724 | if (change->args[arg].mode & MODE_CHANOP) | |
a32da4c7 | 3725 | mod_chanmode_append(&chbuf, 'o', change->args[arg].u.member->user->numeric); |
55342ce8 | 3726 | if (change->args[arg].mode & MODE_HALFOP) |
a32da4c7 | 3727 | mod_chanmode_append(&chbuf, 'h', change->args[arg].u.member->user->numeric); |
d76ed9a9 | 3728 | if (change->args[arg].mode & MODE_VOICE) |
a32da4c7 | 3729 | mod_chanmode_append(&chbuf, 'v', change->args[arg].u.member->user->numeric); |
d76ed9a9 AS |
3730 | break; |
3731 | } | |
3732 | } | |
3733 | ||
3734 | /* Flush the buffer and apply changes locally */ | |
3735 | if (chbuf.modes_used > 0) { | |
3736 | memcpy(chbuf.modes + chbuf.modes_used, chbuf.args, chbuf.args_used); | |
3737 | chbuf.modes[chbuf.modes_used + chbuf.args_used] = '\0'; | |
3738 | irc_mode((chbuf.is_chanop ? chbuf.actor : NULL), chbuf.channel, chbuf.modes); | |
3739 | } | |
3740 | mod_chanmode_apply(who, channel, change); | |
3741 | } | |
3742 | ||
3743 | char * | |
3744 | mod_chanmode_format(struct mod_chanmode *change, char *outbuff) | |
3745 | { | |
3746 | unsigned int used = 0; | |
3747 | assert(change->argc <= change->alloc_argc); | |
3748 | if (change->modes_clear) { | |
3749 | outbuff[used++] = '-'; | |
3750 | #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_clear & MODE_##BIT) outbuff[used++] = CHAR | |
3751 | DO_MODE_CHAR(PRIVATE, 'p'); | |
3752 | DO_MODE_CHAR(SECRET, 's'); | |
3753 | DO_MODE_CHAR(MODERATED, 'm'); | |
3754 | DO_MODE_CHAR(TOPICLIMIT, 't'); | |
3755 | DO_MODE_CHAR(INVITEONLY, 'i'); | |
3756 | DO_MODE_CHAR(NOPRIVMSGS, 'n'); | |
3757 | DO_MODE_CHAR(LIMIT, 'l'); | |
3758 | DO_MODE_CHAR(KEY, 'k'); | |
2f61d1d7 | 3759 | DO_MODE_CHAR(UPASS, 'U'); |
3760 | DO_MODE_CHAR(APASS, 'A'); | |
d76ed9a9 AS |
3761 | DO_MODE_CHAR(DELAYJOINS, 'D'); |
3762 | DO_MODE_CHAR(REGONLY, 'r'); | |
3763 | DO_MODE_CHAR(NOCOLORS, 'c'); | |
3764 | DO_MODE_CHAR(NOCTCPS, 'C'); | |
d0cb2fb6 AS |
3765 | DO_MODE_CHAR(STRIPCOLOR, 'S'); |
3766 | DO_MODE_CHAR(MODUNREG, 'M'); | |
3767 | DO_MODE_CHAR(NONOTICE, 'N'); | |
3768 | DO_MODE_CHAR(NOQUITMSGS, 'Q'); | |
3769 | DO_MODE_CHAR(NOAMSG, 'T'); | |
3770 | DO_MODE_CHAR(OPERSONLY, 'O'); | |
238102e1 | 3771 | DO_MODE_CHAR(ADMINSONLY, 'a'); |
ec1a68c8 | 3772 | DO_MODE_CHAR(REGISTERED, 'z'); |
c8ca69a0 | 3773 | DO_MODE_CHAR(SSLONLY, 'Z'); |
88c7cb10 | 3774 | DO_MODE_CHAR(HIDEMODE, 'L'); |
d76ed9a9 AS |
3775 | #undef DO_MODE_CHAR |
3776 | } | |
3777 | if (change->modes_set) { | |
3778 | outbuff[used++] = '+'; | |
3779 | #define DO_MODE_CHAR(BIT, CHAR) if (change->modes_set & MODE_##BIT) outbuff[used++] = CHAR | |
3780 | DO_MODE_CHAR(PRIVATE, 'p'); | |
3781 | DO_MODE_CHAR(SECRET, 's'); | |
3782 | DO_MODE_CHAR(MODERATED, 'm'); | |
3783 | DO_MODE_CHAR(TOPICLIMIT, 't'); | |
3784 | DO_MODE_CHAR(INVITEONLY, 'i'); | |
3785 | DO_MODE_CHAR(NOPRIVMSGS, 'n'); | |
3786 | DO_MODE_CHAR(DELAYJOINS, 'D'); | |
3787 | DO_MODE_CHAR(REGONLY, 'r'); | |
3788 | DO_MODE_CHAR(NOCOLORS, 'c'); | |
3789 | DO_MODE_CHAR(NOCTCPS, 'C'); | |
d0cb2fb6 AS |
3790 | DO_MODE_CHAR(STRIPCOLOR, 'S'); |
3791 | DO_MODE_CHAR(MODUNREG, 'M'); | |
3792 | DO_MODE_CHAR(NONOTICE, 'N'); | |
3793 | DO_MODE_CHAR(NOQUITMSGS, 'Q'); | |
3794 | DO_MODE_CHAR(NOAMSG, 'T'); | |
3795 | DO_MODE_CHAR(OPERSONLY, 'O'); | |
238102e1 | 3796 | DO_MODE_CHAR(ADMINSONLY, 'a'); |
ec1a68c8 | 3797 | DO_MODE_CHAR(REGISTERED, 'z'); |
c8ca69a0 | 3798 | DO_MODE_CHAR(SSLONLY, 'Z'); |
88c7cb10 | 3799 | DO_MODE_CHAR(HIDEMODE, 'L'); |
d76ed9a9 | 3800 | #undef DO_MODE_CHAR |
2f61d1d7 | 3801 | switch (change->modes_set & (MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS)) { |
3802 | /* Doing this implementation has been a pain in the arse, I hope I didn't forget a possible combination */ | |
3803 | case MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS: | |
3804 | used += sprintf(outbuff+used, "lkAU %d %s %s %s", change->new_limit, change->new_key,change->new_apass, change->new_upass); | |
3805 | break; | |
3806 | ||
3807 | case MODE_KEY|MODE_LIMIT|MODE_APASS: | |
3808 | used += sprintf(outbuff+used, "lkA %d %s %s", change->new_limit, change->new_key, change->new_apass); | |
3809 | break; | |
3810 | case MODE_KEY|MODE_LIMIT|MODE_UPASS: | |
3811 | used += sprintf(outbuff+used, "lkU %d %s %s", change->new_limit, change->new_key, change->new_upass); | |
3812 | break; | |
3813 | case MODE_KEY|MODE_APASS|MODE_UPASS: | |
3814 | used += sprintf(outbuff+used, "kAU %s %s %s", change->new_key, change->new_apass, change->new_upass); | |
3815 | break; | |
3816 | ||
3817 | case MODE_KEY|MODE_APASS: | |
3818 | used += sprintf(outbuff+used, "kA %s %s", change->new_key, change->new_apass); | |
3819 | break; | |
3820 | case MODE_KEY|MODE_UPASS: | |
3821 | used += sprintf(outbuff+used, "kU %s %s", change->new_key, change->new_upass); | |
3822 | break; | |
d76ed9a9 AS |
3823 | case MODE_KEY|MODE_LIMIT: |
3824 | used += sprintf(outbuff+used, "lk %d %s", change->new_limit, change->new_key); | |
3825 | break; | |
2f61d1d7 | 3826 | |
3827 | case MODE_LIMIT|MODE_UPASS: | |
3828 | used += sprintf(outbuff+used, "lU %d %s", change->new_limit, change->new_upass); | |
3829 | break; | |
3830 | case MODE_LIMIT|MODE_APASS: | |
3831 | used += sprintf(outbuff+used, "lA %d %s", change->new_limit, change->new_apass); | |
3832 | break; | |
3833 | case MODE_APASS|MODE_UPASS: | |
3834 | used += sprintf(outbuff+used, "AU %s %s", change->new_apass, change->new_upass); | |
3835 | ||
3836 | case MODE_LIMIT|MODE_APASS|MODE_UPASS: | |
3837 | used += sprintf(outbuff+used, "lAU %d %s %s", change->new_limit, change->new_apass, change->new_upass); | |
3838 | break; | |
3839 | ||
3840 | case MODE_APASS: | |
3841 | used += sprintf(outbuff+used, "A %s", change->new_apass); | |
3842 | break; | |
3843 | case MODE_UPASS: | |
3844 | used += sprintf(outbuff+used, "U %s", change->new_upass); | |
3845 | break; | |
d76ed9a9 AS |
3846 | case MODE_KEY: |
3847 | used += sprintf(outbuff+used, "k %s", change->new_key); | |
3848 | break; | |
3849 | case MODE_LIMIT: | |
3850 | used += sprintf(outbuff+used, "l %d", change->new_limit); | |
3851 | break; | |
3852 | } | |
3853 | } | |
3854 | outbuff[used] = 0; | |
3855 | return outbuff; | |
3856 | } | |
3857 | ||
3858 | static int | |
3859 | clear_chanmode(struct chanNode *channel, const char *modes) | |
3860 | { | |
1136f709 | 3861 | unsigned int cleared; |
d76ed9a9 | 3862 | |
1136f709 | 3863 | for (cleared = 0; *modes; modes++) { |
d76ed9a9 | 3864 | switch (*modes) { |
1136f709 | 3865 | case 'o': cleared |= MODE_CHANOP; break; |
3866 | case 'h': cleared |= MODE_HALFOP; break; | |
3867 | case 'v': cleared |= MODE_VOICE; break; | |
3868 | case 'p': cleared |= MODE_PRIVATE; break; | |
3869 | case 's': cleared |= MODE_SECRET; break; | |
3870 | case 'm': cleared |= MODE_MODERATED; break; | |
3871 | case 't': cleared |= MODE_TOPICLIMIT; break; | |
3872 | case 'i': cleared |= MODE_INVITEONLY; break; | |
3873 | case 'n': cleared |= MODE_NOPRIVMSGS; break; | |
d76ed9a9 | 3874 | case 'k': |
1136f709 | 3875 | cleared |= MODE_KEY; |
d76ed9a9 AS |
3876 | channel->key[0] = '\0'; |
3877 | break; | |
2f61d1d7 | 3878 | case 'A': |
1136f709 | 3879 | cleared |= MODE_APASS; |
2f61d1d7 | 3880 | channel->apass[0] = '\0'; |
3881 | break; | |
3882 | case 'U': | |
1136f709 | 3883 | cleared |= MODE_UPASS; |
2f61d1d7 | 3884 | channel->upass[0] = '\0'; |
3885 | break; | |
d76ed9a9 | 3886 | case 'l': |
1136f709 | 3887 | cleared |= MODE_LIMIT; |
d76ed9a9 AS |
3888 | channel->limit = 0; |
3889 | break; | |
1136f709 | 3890 | case 'b': cleared |= MODE_BAN; break; |
3891 | case 'e': cleared |= MODE_EXEMPT; break; | |
3892 | case 'D': cleared |= MODE_DELAYJOINS; break; | |
3893 | case 'r': cleared |= MODE_REGONLY; break; | |
3894 | case 'c': cleared |= MODE_NOCOLORS; break; | |
3895 | case 'C': cleared |= MODE_NOCTCPS; break; | |
3896 | case 'S': cleared |= MODE_STRIPCOLOR; break; | |
3897 | case 'M': cleared |= MODE_MODUNREG; break; | |
3898 | case 'N': cleared |= MODE_NONOTICE; break; | |
3899 | case 'Q': cleared |= MODE_NOQUITMSGS; break; | |
3900 | case 'T': cleared |= MODE_NOAMSG; break; | |
3901 | case 'O': cleared |= MODE_OPERSONLY; break; | |
3902 | case 'a': cleared |= MODE_ADMINSONLY; break; | |
3903 | case 'z': cleared |= MODE_REGISTERED; break; | |
3904 | case 'Z': cleared |= MODE_SSLONLY; break; | |
3905 | case 'L': cleared |= MODE_HIDEMODE; break; | |
d76ed9a9 AS |
3906 | } |
3907 | } | |
3908 | ||
1136f709 | 3909 | if (!cleared) |
d76ed9a9 AS |
3910 | return 1; |
3911 | ||
3912 | /* Remove simple modes. */ | |
1136f709 | 3913 | channel->modes &= ~cleared; |
d76ed9a9 AS |
3914 | |
3915 | /* If removing bans, kill 'em all. */ | |
1136f709 | 3916 | if ((cleared & MODE_BAN) && channel->banlist.used) { |
d76ed9a9 AS |
3917 | unsigned int i; |
3918 | for (i=0; i<channel->banlist.used; i++) | |
3919 | free(channel->banlist.list[i]); | |
3920 | channel->banlist.used = 0; | |
3921 | } | |
3922 | ||
2aef5f4b | 3923 | /* If removing exempts, kill 'em all. */ |
1136f709 | 3924 | if ((cleared & MODE_EXEMPT) && channel->exemptlist.used) { |
2aef5f4b | 3925 | unsigned int i; |
3926 | for (i=0; i<channel->exemptlist.used; i++) | |
3927 | free(channel->exemptlist.list[i]); | |
3928 | channel->exemptlist.used = 0; | |
3929 | } | |
3930 | ||
1136f709 | 3931 | /* Removed member modes. */ |
3932 | if ((cleared & (MODE_CHANOP | MODE_HALFOP | MODE_VOICE)) && channel->members.used) { | |
3933 | int mask = ~(cleared & (MODE_CHANOP | MODE_HALFOP | MODE_VOICE)); | |
d76ed9a9 AS |
3934 | unsigned int i; |
3935 | ||
3936 | for (i = 0; i < channel->members.used; i++) | |
3937 | channel->members.list[i]->modes &= mask; | |
3938 | } | |
3939 | ||
3940 | return 1; | |
3941 | } | |
3942 | ||
3943 | void | |
3944 | reg_privmsg_func(struct userNode *user, privmsg_func_t handler) | |
3945 | { | |
3946 | unsigned int numeric = user->num_local; | |
3947 | if (numeric >= num_privmsg_funcs) { | |
1136f709 | 3948 | int newnum = numeric + 8, ii; |
d76ed9a9 | 3949 | privmsg_funcs = realloc(privmsg_funcs, newnum*sizeof(privmsg_func_t)); |
1136f709 | 3950 | for (ii = num_privmsg_funcs; ii < newnum; ++ii) |
3951 | privmsg_funcs[ii] = NULL; | |
d76ed9a9 AS |
3952 | num_privmsg_funcs = newnum; |
3953 | } | |
3954 | if (privmsg_funcs[numeric]) | |
3955 | log_module(MAIN_LOG, LOG_WARNING, "re-registering new privmsg handler for numeric %d", numeric); | |
3956 | privmsg_funcs[numeric] = handler; | |
3957 | } | |
3958 | ||
3959 | void | |
1136f709 | 3960 | unreg_privmsg_func(struct userNode *user) |
d76ed9a9 | 3961 | { |
1136f709 | 3962 | if (!IsLocal(user) || user->num_local >= num_privmsg_funcs) |
3963 | return; /* this really only works with users */ | |
d76ed9a9 | 3964 | |
1136f709 | 3965 | privmsg_funcs[user->num_local] = NULL; |
d76ed9a9 AS |
3966 | } |
3967 | ||
3968 | ||
3969 | void | |
3970 | reg_notice_func(struct userNode *user, privmsg_func_t handler) | |
3971 | { | |
3972 | unsigned int numeric = user->num_local; | |
3973 | if (numeric >= num_notice_funcs) { | |
1136f709 | 3974 | int newnum = numeric + 8, ii; |
d76ed9a9 | 3975 | notice_funcs = realloc(notice_funcs, newnum*sizeof(privmsg_func_t)); |
1136f709 | 3976 | for (ii = num_privmsg_funcs; ii < newnum; ++ii) |
3977 | privmsg_funcs[ii] = NULL; | |
d76ed9a9 AS |
3978 | num_notice_funcs = newnum; |
3979 | } | |
3980 | if (notice_funcs[numeric]) | |
3981 | log_module(MAIN_LOG, LOG_WARNING, "re-registering new notice handler for numeric %d", numeric); | |
3982 | notice_funcs[numeric] = handler; | |
3983 | } | |
3984 | ||
3985 | void | |
1136f709 | 3986 | unreg_notice_func(struct userNode *user) |
d76ed9a9 | 3987 | { |
1136f709 | 3988 | if (!IsLocal(user) || user->num_local >= num_privmsg_funcs) |
3989 | return; /* this really only works with users */ | |
d76ed9a9 | 3990 | |
1136f709 | 3991 | notice_funcs[user->num_local] = NULL; |
d76ed9a9 AS |
3992 | } |
3993 | ||
3994 | static void | |
3995 | send_burst(void) | |
3996 | { | |
3997 | unsigned int i, hop, max_hop=1; | |
3998 | dict_iterator_t it; | |
3999 | ||
4000 | /* burst (juped) servers, closest first (except self, which is sent already) */ | |
4001 | for (i=0; i<ArrayLength(servers_num); i++) | |
4002 | if (servers_num[i] && servers_num[i]->hops > max_hop) | |
4003 | max_hop = servers_num[i]->hops; | |
4004 | for (hop=1; hop<=max_hop; hop++) { | |
4005 | for (i=0;i<ArrayLength(servers_num);i++) { | |
4006 | if (servers_num[i] | |
4007 | && (servers_num[i]->hops == hop) | |
4008 | && (servers_num[i] != self->uplink)) | |
4009 | irc_server(servers_num[i]); | |
4010 | } | |
4011 | } | |
4012 | ||
4013 | /* burst local nicks */ | |
4014 | for (i=0; i<=self->num_mask; i++) | |
4015 | if (self->users[i]) | |
4016 | irc_user(self->users[i]); | |
4017 | ||
4018 | /* build dict of unbursted channel names (just copy existing channels) */ | |
4019 | unbursted_channels = dict_new(); | |
4020 | for (it = dict_first(channels); it; it = iter_next(it)) | |
4021 | dict_insert(unbursted_channels, iter_key(it), iter_data(it)); | |
4022 | } | |
2f61d1d7 | 4023 | |
4024 | /* | |
4025 | * Oplevel parsing | |
4026 | */ | |
4027 | static int | |
4028 | parse_oplevel(char *str) | |
4029 | { | |
4030 | int oplevel = 0; | |
4031 | while (isdigit(*str)) | |
4032 | oplevel = oplevel * 10 + *str++ - '0'; | |
4033 | return oplevel; | |
4034 | } | |
4035 |