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