1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2006 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* IRC commands */ |
---|
8 | |
---|
9 | /* |
---|
10 | This program is free software; you can redistribute it and/or modify |
---|
11 | it under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 2 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License with |
---|
21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
23 | Suite 330, Boston, MA 02111-1307 USA |
---|
24 | */ |
---|
25 | |
---|
26 | #define BITLBEE_CORE |
---|
27 | #include "bitlbee.h" |
---|
28 | #include "ipc.h" |
---|
29 | |
---|
30 | static void irc_cmd_pass( irc_t *irc, char **cmd ) |
---|
31 | { |
---|
32 | if( global.conf->auth_pass && |
---|
33 | ( strncmp( global.conf->auth_pass, "md5:", 4 ) == 0 ? |
---|
34 | md5_verify_password( cmd[1], global.conf->auth_pass + 4 ) == 0 : |
---|
35 | strcmp( cmd[1], global.conf->auth_pass ) == 0 ) ) |
---|
36 | { |
---|
37 | irc->status |= USTATUS_AUTHORIZED; |
---|
38 | irc_check_login( irc ); |
---|
39 | } |
---|
40 | else |
---|
41 | { |
---|
42 | irc_reply( irc, 464, ":Incorrect password" ); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | static void irc_cmd_user( irc_t *irc, char **cmd ) |
---|
47 | { |
---|
48 | irc->user = g_strdup( cmd[1] ); |
---|
49 | irc->realname = g_strdup( cmd[4] ); |
---|
50 | |
---|
51 | irc_check_login( irc ); |
---|
52 | } |
---|
53 | |
---|
54 | static void irc_cmd_nick( irc_t *irc, char **cmd ) |
---|
55 | { |
---|
56 | if( irc->nick ) |
---|
57 | { |
---|
58 | irc_reply( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" ); |
---|
59 | } |
---|
60 | /* This is not clean, but for now it'll have to be like this... */ |
---|
61 | else if( ( nick_cmp( cmd[1], irc->mynick ) == 0 ) || ( nick_cmp( cmd[1], NS_NICK ) == 0 ) ) |
---|
62 | { |
---|
63 | irc_reply( irc, 433, ":This nick is already in use" ); |
---|
64 | } |
---|
65 | else if( !nick_ok( cmd[1] ) ) |
---|
66 | { |
---|
67 | /* [SH] Invalid characters. */ |
---|
68 | irc_reply( irc, 432, ":This nick contains invalid characters" ); |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | irc->nick = g_strdup( cmd[1] ); |
---|
73 | |
---|
74 | irc_check_login( irc ); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | static void irc_cmd_quit( irc_t *irc, char **cmd ) |
---|
79 | { |
---|
80 | if( cmd[1] && *cmd[1] ) |
---|
81 | irc_abort( irc, 0, "Quit: %s", cmd[1] ); |
---|
82 | else |
---|
83 | irc_abort( irc, 0, "Leaving..." ); |
---|
84 | } |
---|
85 | |
---|
86 | static void irc_cmd_ping( irc_t *irc, char **cmd ) |
---|
87 | { |
---|
88 | irc_write( irc, ":%s PONG %s :%s", irc->myhost, irc->myhost, cmd[1]?cmd[1]:irc->myhost ); |
---|
89 | } |
---|
90 | |
---|
91 | static void irc_cmd_oper( irc_t *irc, char **cmd ) |
---|
92 | { |
---|
93 | if( global.conf->oper_pass && |
---|
94 | ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ? |
---|
95 | md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 : |
---|
96 | strcmp( cmd[2], global.conf->oper_pass ) == 0 ) ) |
---|
97 | { |
---|
98 | irc_umode_set( irc, "+o", 1 ); |
---|
99 | irc_reply( irc, 381, ":Password accepted" ); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | irc_reply( irc, 432, ":Incorrect password" ); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | static void irc_cmd_mode( irc_t *irc, char **cmd ) |
---|
108 | { |
---|
109 | if( *cmd[1] == '#' || *cmd[1] == '&' ) |
---|
110 | { |
---|
111 | if( cmd[2] ) |
---|
112 | { |
---|
113 | if( *cmd[2] == '+' || *cmd[2] == '-' ) |
---|
114 | irc_reply( irc, 477, "%s :Can't change channel modes", cmd[1] ); |
---|
115 | else if( *cmd[2] == 'b' ) |
---|
116 | irc_reply( irc, 368, "%s :No bans possible", cmd[1] ); |
---|
117 | } |
---|
118 | else |
---|
119 | irc_reply( irc, 324, "%s +%s", cmd[1], CMODE ); |
---|
120 | } |
---|
121 | else |
---|
122 | { |
---|
123 | if( nick_cmp( cmd[1], irc->nick ) == 0 ) |
---|
124 | { |
---|
125 | if( cmd[2] ) |
---|
126 | irc_umode_set( irc, cmd[2], 0 ); |
---|
127 | else |
---|
128 | irc_reply( irc, 221, "+%s", irc->umode ); |
---|
129 | } |
---|
130 | else |
---|
131 | irc_reply( irc, 502, ":Don't touch their modes" ); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | static void irc_cmd_names( irc_t *irc, char **cmd ) |
---|
136 | { |
---|
137 | irc_names( irc, cmd[1]?cmd[1]:irc->channel ); |
---|
138 | } |
---|
139 | |
---|
140 | static void irc_cmd_part( irc_t *irc, char **cmd ) |
---|
141 | { |
---|
142 | struct groupchat *c; |
---|
143 | |
---|
144 | if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) |
---|
145 | { |
---|
146 | user_t *u = user_find( irc, irc->nick ); |
---|
147 | |
---|
148 | /* Not allowed to leave control channel */ |
---|
149 | irc_part( irc, u, irc->channel ); |
---|
150 | irc_join( irc, u, irc->channel ); |
---|
151 | } |
---|
152 | else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) ) |
---|
153 | { |
---|
154 | user_t *u = user_find( irc, irc->nick ); |
---|
155 | |
---|
156 | irc_part( irc, u, c->channel ); |
---|
157 | |
---|
158 | if( c->ic ) |
---|
159 | { |
---|
160 | c->joined = 0; |
---|
161 | c->ic->acc->prpl->chat_leave( c ); |
---|
162 | } |
---|
163 | } |
---|
164 | else |
---|
165 | { |
---|
166 | irc_reply( irc, 403, "%s :No such channel", cmd[1] ); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | static void irc_cmd_join( irc_t *irc, char **cmd ) |
---|
171 | { |
---|
172 | if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) |
---|
173 | ; /* Dude, you're already there... |
---|
174 | RFC doesn't have any reply for that though? */ |
---|
175 | else if( cmd[1] ) |
---|
176 | { |
---|
177 | if( ( cmd[1][0] == '#' || cmd[1][0] == '&' ) && cmd[1][1] ) |
---|
178 | { |
---|
179 | user_t *u = user_find( irc, cmd[1] + 1 ); |
---|
180 | |
---|
181 | if( u && u->ic && u->ic->acc->prpl->chat_with ) |
---|
182 | { |
---|
183 | irc_reply( irc, 403, "%s :Initializing groupchat in a different channel", cmd[1] ); |
---|
184 | |
---|
185 | if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) ) |
---|
186 | { |
---|
187 | irc_usermsg( irc, "Could not open a groupchat with %s.", u->nick ); |
---|
188 | } |
---|
189 | } |
---|
190 | else if( u ) |
---|
191 | { |
---|
192 | irc_reply( irc, 403, "%s :Groupchats are not possible with %s", cmd[1], cmd[1]+1 ); |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | irc_reply( irc, 403, "%s :No such nick", cmd[1] ); |
---|
197 | } |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | irc_reply( irc, 403, "%s :No such channel", cmd[1] ); |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | static void irc_cmd_invite( irc_t *irc, char **cmd ) |
---|
207 | { |
---|
208 | char *nick = cmd[1], *channel = cmd[2]; |
---|
209 | struct groupchat *c = irc_chat_by_channel( irc, channel ); |
---|
210 | user_t *u = user_find( irc, nick ); |
---|
211 | |
---|
212 | if( u && c && ( u->ic == c->ic ) ) |
---|
213 | if( c->ic && c->ic->acc->prpl->chat_invite ) |
---|
214 | { |
---|
215 | c->ic->acc->prpl->chat_invite( c, u->handle, NULL ); |
---|
216 | irc_reply( irc, 341, "%s %s", nick, channel ); |
---|
217 | return; |
---|
218 | } |
---|
219 | |
---|
220 | irc_reply( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel ); |
---|
221 | } |
---|
222 | |
---|
223 | static void irc_cmd_privmsg( irc_t *irc, char **cmd ) |
---|
224 | { |
---|
225 | if ( !cmd[2] ) |
---|
226 | { |
---|
227 | irc_reply( irc, 412, ":No text to send" ); |
---|
228 | } |
---|
229 | else if ( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
230 | { |
---|
231 | irc_write( irc, ":%s!%s@%s %s %s :%s", irc->nick, irc->user, irc->host, cmd[0], cmd[1], cmd[2] ); |
---|
232 | } |
---|
233 | else |
---|
234 | { |
---|
235 | if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) |
---|
236 | { |
---|
237 | unsigned int i; |
---|
238 | char *t = set_getstr( &irc->set, "default_target" ); |
---|
239 | |
---|
240 | if( g_strcasecmp( t, "last" ) == 0 && irc->last_target ) |
---|
241 | cmd[1] = irc->last_target; |
---|
242 | else if( g_strcasecmp( t, "root" ) == 0 ) |
---|
243 | cmd[1] = irc->mynick; |
---|
244 | |
---|
245 | for( i = 0; i < strlen( cmd[2] ); i ++ ) |
---|
246 | { |
---|
247 | if( cmd[2][i] == ' ' ) break; |
---|
248 | if( cmd[2][i] == ':' || cmd[2][i] == ',' ) |
---|
249 | { |
---|
250 | cmd[1] = cmd[2]; |
---|
251 | cmd[2] += i; |
---|
252 | *cmd[2] = 0; |
---|
253 | while( *(++cmd[2]) == ' ' ); |
---|
254 | break; |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | irc->is_private = 0; |
---|
259 | |
---|
260 | if( cmd[1] != irc->last_target ) |
---|
261 | { |
---|
262 | if( irc->last_target ) |
---|
263 | g_free( irc->last_target ); |
---|
264 | irc->last_target = g_strdup( cmd[1] ); |
---|
265 | } |
---|
266 | } |
---|
267 | else |
---|
268 | { |
---|
269 | irc->is_private = 1; |
---|
270 | } |
---|
271 | irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 ); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | static void irc_cmd_who( irc_t *irc, char **cmd ) |
---|
276 | { |
---|
277 | char *channel = cmd[1]; |
---|
278 | user_t *u = irc->users; |
---|
279 | struct groupchat *c; |
---|
280 | GList *l; |
---|
281 | |
---|
282 | if( !channel || *channel == '0' || *channel == '*' || !*channel ) |
---|
283 | while( u ) |
---|
284 | { |
---|
285 | irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", u->online ? irc->channel : "*", u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname ); |
---|
286 | u = u->next; |
---|
287 | } |
---|
288 | else if( g_strcasecmp( channel, irc->channel ) == 0 ) |
---|
289 | while( u ) |
---|
290 | { |
---|
291 | if( u->online ) |
---|
292 | irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname ); |
---|
293 | u = u->next; |
---|
294 | } |
---|
295 | else if( ( c = irc_chat_by_channel( irc, channel ) ) ) |
---|
296 | for( l = c->in_room; l; l = l->next ) |
---|
297 | { |
---|
298 | if( ( u = user_findhandle( c->ic, l->data ) ) ) |
---|
299 | irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname ); |
---|
300 | } |
---|
301 | else if( ( u = user_find( irc, channel ) ) ) |
---|
302 | irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname ); |
---|
303 | |
---|
304 | irc_reply( irc, 315, "%s :End of /WHO list", channel?channel:"**" ); |
---|
305 | } |
---|
306 | |
---|
307 | static void irc_cmd_userhost( irc_t *irc, char **cmd ) |
---|
308 | { |
---|
309 | user_t *u; |
---|
310 | int i; |
---|
311 | |
---|
312 | /* [TV] Usable USERHOST-implementation according to |
---|
313 | RFC1459. Without this, mIRC shows an error |
---|
314 | while connecting, and the used way of rejecting |
---|
315 | breaks standards. |
---|
316 | */ |
---|
317 | |
---|
318 | for( i = 1; cmd[i]; i ++ ) |
---|
319 | if( ( u = user_find( irc, cmd[i] ) ) ) |
---|
320 | { |
---|
321 | if( u->online && u->away ) |
---|
322 | irc_reply( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host ); |
---|
323 | else |
---|
324 | irc_reply( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host ); |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | static void irc_cmd_ison( irc_t *irc, char **cmd ) |
---|
329 | { |
---|
330 | user_t *u; |
---|
331 | char buff[IRC_MAX_LINE]; |
---|
332 | int lenleft, i; |
---|
333 | |
---|
334 | buff[0] = '\0'; |
---|
335 | |
---|
336 | /* [SH] Leave room for : and \0 */ |
---|
337 | lenleft = IRC_MAX_LINE - 2; |
---|
338 | |
---|
339 | for( i = 1; cmd[i]; i ++ ) |
---|
340 | { |
---|
341 | char *this, *next; |
---|
342 | |
---|
343 | this = cmd[i]; |
---|
344 | while( *this ) |
---|
345 | { |
---|
346 | if( ( next = strchr( this, ' ' ) ) ) |
---|
347 | *next = 0; |
---|
348 | |
---|
349 | if( ( u = user_find( irc, this ) ) && u->online ) |
---|
350 | { |
---|
351 | lenleft -= strlen( u->nick ) + 1; |
---|
352 | |
---|
353 | if( lenleft < 0 ) |
---|
354 | break; |
---|
355 | |
---|
356 | strcat( buff, u->nick ); |
---|
357 | strcat( buff, " " ); |
---|
358 | } |
---|
359 | |
---|
360 | if( next ) |
---|
361 | { |
---|
362 | *next = ' '; |
---|
363 | this = next + 1; |
---|
364 | } |
---|
365 | else |
---|
366 | { |
---|
367 | break; |
---|
368 | } |
---|
369 | } |
---|
370 | |
---|
371 | /* *sigh* */ |
---|
372 | if( lenleft < 0 ) |
---|
373 | break; |
---|
374 | } |
---|
375 | |
---|
376 | if( strlen( buff ) > 0 ) |
---|
377 | buff[strlen(buff)-1] = '\0'; |
---|
378 | |
---|
379 | irc_reply( irc, 303, ":%s", buff ); |
---|
380 | } |
---|
381 | |
---|
382 | static void irc_cmd_watch( irc_t *irc, char **cmd ) |
---|
383 | { |
---|
384 | int i; |
---|
385 | |
---|
386 | /* Obviously we could also mark a user structure as being |
---|
387 | watched, but what if the WATCH command is sent right |
---|
388 | after connecting? The user won't exist yet then... */ |
---|
389 | for( i = 1; cmd[i]; i ++ ) |
---|
390 | { |
---|
391 | char *nick; |
---|
392 | user_t *u; |
---|
393 | |
---|
394 | if( !cmd[i][0] || !cmd[i][1] ) |
---|
395 | break; |
---|
396 | |
---|
397 | nick = g_strdup( cmd[i] + 1 ); |
---|
398 | nick_lc( nick ); |
---|
399 | |
---|
400 | u = user_find( irc, nick ); |
---|
401 | |
---|
402 | if( cmd[i][0] == '+' ) |
---|
403 | { |
---|
404 | if( !g_hash_table_lookup( irc->watches, nick ) ) |
---|
405 | g_hash_table_insert( irc->watches, nick, nick ); |
---|
406 | |
---|
407 | if( u && u->online ) |
---|
408 | irc_reply( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "is online" ); |
---|
409 | else |
---|
410 | irc_reply( irc, 605, "%s %s %s %d :%s", nick, "*", "*", (int) time( NULL ), "is offline" ); |
---|
411 | } |
---|
412 | else if( cmd[i][0] == '-' ) |
---|
413 | { |
---|
414 | gpointer okey, ovalue; |
---|
415 | |
---|
416 | if( g_hash_table_lookup_extended( irc->watches, nick, &okey, &ovalue ) ) |
---|
417 | { |
---|
418 | g_free( okey ); |
---|
419 | g_hash_table_remove( irc->watches, okey ); |
---|
420 | |
---|
421 | irc_reply( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" ); |
---|
422 | } |
---|
423 | } |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | static void irc_cmd_topic( irc_t *irc, char **cmd ) |
---|
428 | { |
---|
429 | char *channel = cmd[1]; |
---|
430 | char *topic = cmd[2]; |
---|
431 | |
---|
432 | if( topic ) |
---|
433 | { |
---|
434 | /* Send the topic */ |
---|
435 | struct groupchat *c = irc_chat_by_channel( irc, channel ); |
---|
436 | if( c && c->ic && c->ic->acc->prpl->chat_topic ) |
---|
437 | c->ic->acc->prpl->chat_topic( c, topic ); |
---|
438 | } |
---|
439 | else |
---|
440 | { |
---|
441 | /* Get the topic */ |
---|
442 | irc_topic( irc, channel ); |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | static void irc_cmd_away( irc_t *irc, char **cmd ) |
---|
447 | { |
---|
448 | user_t *u = user_find( irc, irc->nick ); |
---|
449 | char *away = cmd[1]; |
---|
450 | account_t *a; |
---|
451 | |
---|
452 | if( !u ) return; |
---|
453 | |
---|
454 | if( away && *away ) |
---|
455 | { |
---|
456 | int i, j; |
---|
457 | |
---|
458 | /* Copy away string, but skip control chars. Mainly because |
---|
459 | Jabber really doesn't like them. */ |
---|
460 | u->away = g_malloc( strlen( away ) + 1 ); |
---|
461 | for( i = j = 0; away[i]; i ++ ) |
---|
462 | if( ( u->away[j] = away[i] ) >= ' ' ) |
---|
463 | j ++; |
---|
464 | u->away[j] = 0; |
---|
465 | |
---|
466 | irc_reply( irc, 306, ":You're now away: %s", u->away ); |
---|
467 | /* irc_umode_set( irc, irc->myhost, "+a" ); */ |
---|
468 | } |
---|
469 | else |
---|
470 | { |
---|
471 | if( u->away ) g_free( u->away ); |
---|
472 | u->away = NULL; |
---|
473 | /* irc_umode_set( irc, irc->myhost, "-a" ); */ |
---|
474 | irc_reply( irc, 305, ":Welcome back" ); |
---|
475 | } |
---|
476 | |
---|
477 | for( a = irc->accounts; a; a = a->next ) |
---|
478 | { |
---|
479 | struct im_connection *ic = a->ic; |
---|
480 | |
---|
481 | if( ic && ic->flags & OPT_LOGGED_IN ) |
---|
482 | imc_set_away( ic, u->away ); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | static void irc_cmd_whois( irc_t *irc, char **cmd ) |
---|
487 | { |
---|
488 | char *nick = cmd[1]; |
---|
489 | user_t *u = user_find( irc, nick ); |
---|
490 | |
---|
491 | if( u ) |
---|
492 | { |
---|
493 | irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname ); |
---|
494 | |
---|
495 | if( u->ic ) |
---|
496 | irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user, |
---|
497 | u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "", |
---|
498 | u->ic->acc->prpl->name ); |
---|
499 | else |
---|
500 | irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO ); |
---|
501 | |
---|
502 | if( !u->online ) |
---|
503 | irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" ); |
---|
504 | else if( u->away ) |
---|
505 | irc_reply( irc, 301, "%s :%s", u->nick, u->away ); |
---|
506 | |
---|
507 | irc_reply( irc, 318, "%s :End of /WHOIS list", nick ); |
---|
508 | } |
---|
509 | else |
---|
510 | { |
---|
511 | irc_reply( irc, 401, "%s :Nick does not exist", nick ); |
---|
512 | } |
---|
513 | } |
---|
514 | |
---|
515 | static void irc_cmd_whowas( irc_t *irc, char **cmd ) |
---|
516 | { |
---|
517 | /* For some reason irssi tries a whowas when whois fails. We can |
---|
518 | ignore this, but then the user never gets a "user not found" |
---|
519 | message from irssi which is a bit annoying. So just respond |
---|
520 | with not-found and irssi users will get better error messages */ |
---|
521 | |
---|
522 | irc_reply( irc, 406, "%s :Nick does not exist", cmd[1] ); |
---|
523 | irc_reply( irc, 369, "%s :End of WHOWAS", cmd[1] ); |
---|
524 | } |
---|
525 | |
---|
526 | static void irc_cmd_nickserv( irc_t *irc, char **cmd ) |
---|
527 | { |
---|
528 | /* [SH] This aliases the NickServ command to PRIVMSG root */ |
---|
529 | /* [TV] This aliases the NS command to PRIVMSG root as well */ |
---|
530 | root_command( irc, cmd + 1 ); |
---|
531 | } |
---|
532 | |
---|
533 | static void irc_cmd_motd( irc_t *irc, char **cmd ) |
---|
534 | { |
---|
535 | irc_motd( irc ); |
---|
536 | } |
---|
537 | |
---|
538 | static void irc_cmd_pong( irc_t *irc, char **cmd ) |
---|
539 | { |
---|
540 | /* We could check the value we get back from the user, but in |
---|
541 | fact we don't care, we're just happy he's still alive. */ |
---|
542 | irc->last_pong = gettime(); |
---|
543 | irc->pinging = 0; |
---|
544 | } |
---|
545 | |
---|
546 | static void irc_cmd_version( irc_t *irc, char **cmd ) |
---|
547 | { |
---|
548 | irc_reply( irc, 351, "bitlbee-%s. %s :%s/%s ", BITLBEE_VERSION, irc->myhost, ARCH, CPU ); |
---|
549 | } |
---|
550 | |
---|
551 | static void irc_cmd_completions( irc_t *irc, char **cmd ) |
---|
552 | { |
---|
553 | user_t *u = user_find( irc, irc->mynick ); |
---|
554 | help_t *h; |
---|
555 | set_t *s; |
---|
556 | int i; |
---|
557 | |
---|
558 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "OK" ); |
---|
559 | |
---|
560 | for( i = 0; commands[i].command; i ++ ) |
---|
561 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", commands[i].command ); |
---|
562 | |
---|
563 | for( h = global.help; h; h = h->next ) |
---|
564 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->title ); |
---|
565 | |
---|
566 | for( s = irc->set; s; s = s->next ) |
---|
567 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS set ", s->key ); |
---|
568 | |
---|
569 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "END" ); |
---|
570 | } |
---|
571 | |
---|
572 | static void irc_cmd_rehash( irc_t *irc, char **cmd ) |
---|
573 | { |
---|
574 | if( global.conf->runmode == RUNMODE_INETD ) |
---|
575 | ipc_master_cmd_rehash( NULL, NULL ); |
---|
576 | else |
---|
577 | ipc_to_master( cmd ); |
---|
578 | |
---|
579 | irc_reply( irc, 382, "%s :Rehashing", global.conf_file ); |
---|
580 | } |
---|
581 | |
---|
582 | static const command_t irc_commands[] = { |
---|
583 | { "pass", 1, irc_cmd_pass, IRC_CMD_PRE_LOGIN }, |
---|
584 | { "user", 4, irc_cmd_user, IRC_CMD_PRE_LOGIN }, |
---|
585 | { "nick", 1, irc_cmd_nick, 0 }, |
---|
586 | { "quit", 0, irc_cmd_quit, 0 }, |
---|
587 | { "ping", 0, irc_cmd_ping, 0 }, |
---|
588 | { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN }, |
---|
589 | { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN }, |
---|
590 | { "names", 0, irc_cmd_names, IRC_CMD_LOGGED_IN }, |
---|
591 | { "part", 1, irc_cmd_part, IRC_CMD_LOGGED_IN }, |
---|
592 | { "join", 1, irc_cmd_join, IRC_CMD_LOGGED_IN }, |
---|
593 | { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN }, |
---|
594 | { "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
595 | { "notice", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
596 | { "who", 0, irc_cmd_who, IRC_CMD_LOGGED_IN }, |
---|
597 | { "userhost", 1, irc_cmd_userhost, IRC_CMD_LOGGED_IN }, |
---|
598 | { "ison", 1, irc_cmd_ison, IRC_CMD_LOGGED_IN }, |
---|
599 | { "watch", 1, irc_cmd_watch, IRC_CMD_LOGGED_IN }, |
---|
600 | { "topic", 1, irc_cmd_topic, IRC_CMD_LOGGED_IN }, |
---|
601 | { "away", 0, irc_cmd_away, IRC_CMD_LOGGED_IN }, |
---|
602 | { "whois", 1, irc_cmd_whois, IRC_CMD_LOGGED_IN }, |
---|
603 | { "whowas", 1, irc_cmd_whowas, IRC_CMD_LOGGED_IN }, |
---|
604 | { "nickserv", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
605 | { "ns", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
606 | { "motd", 0, irc_cmd_motd, IRC_CMD_LOGGED_IN }, |
---|
607 | { "pong", 0, irc_cmd_pong, IRC_CMD_LOGGED_IN }, |
---|
608 | { "version", 0, irc_cmd_version, IRC_CMD_LOGGED_IN }, |
---|
609 | { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN }, |
---|
610 | { "die", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
611 | { "wallops", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
612 | { "wall", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
613 | { "rehash", 0, irc_cmd_rehash, IRC_CMD_OPER_ONLY }, |
---|
614 | { "restart", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
615 | { "kill", 2, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
616 | { NULL } |
---|
617 | }; |
---|
618 | |
---|
619 | void irc_exec( irc_t *irc, char *cmd[] ) |
---|
620 | { |
---|
621 | int i, n_arg; |
---|
622 | |
---|
623 | if( !cmd[0] ) |
---|
624 | return; |
---|
625 | |
---|
626 | for( i = 0; irc_commands[i].command; i++ ) |
---|
627 | if( g_strcasecmp( irc_commands[i].command, cmd[0] ) == 0 ) |
---|
628 | { |
---|
629 | /* There should be no typo in the next line: */ |
---|
630 | for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --; |
---|
631 | |
---|
632 | if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN ) |
---|
633 | { |
---|
634 | irc_reply( irc, 462, ":Only allowed before logging in" ); |
---|
635 | } |
---|
636 | else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) ) |
---|
637 | { |
---|
638 | irc_reply( irc, 451, ":Register first" ); |
---|
639 | } |
---|
640 | else if( irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr( irc->umode, 'o' ) ) |
---|
641 | { |
---|
642 | irc_reply( irc, 481, ":Permission denied - You're not an IRC operator" ); |
---|
643 | } |
---|
644 | else if( n_arg < irc_commands[i].required_parameters ) |
---|
645 | { |
---|
646 | irc_reply( irc, 461, "%s :Need more parameters", cmd[0] ); |
---|
647 | } |
---|
648 | else if( irc_commands[i].flags & IRC_CMD_TO_MASTER ) |
---|
649 | { |
---|
650 | /* IPC doesn't make sense in inetd mode, |
---|
651 | but the function will catch that. */ |
---|
652 | ipc_to_master( cmd ); |
---|
653 | } |
---|
654 | else |
---|
655 | { |
---|
656 | irc_commands[i].execute( irc, cmd ); |
---|
657 | } |
---|
658 | |
---|
659 | return; |
---|
660 | } |
---|
661 | |
---|
662 | if( irc->status >= USTATUS_LOGGED_IN ) |
---|
663 | irc_reply( irc, 421, "%s :Unknown command", cmd[0] ); |
---|
664 | } |
---|