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