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