1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2004 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* User manager (root) 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 "commands.h" |
---|
28 | #include "crypting.h" |
---|
29 | #include "bitlbee.h" |
---|
30 | #include "help.h" |
---|
31 | #include "chat.h" |
---|
32 | |
---|
33 | #include <string.h> |
---|
34 | |
---|
35 | void root_command_string( irc_t *irc, user_t *u, char *command, int flags ) |
---|
36 | { |
---|
37 | char *cmd[IRC_MAX_ARGS]; |
---|
38 | char *s; |
---|
39 | int k; |
---|
40 | char q = 0; |
---|
41 | |
---|
42 | memset( cmd, 0, sizeof( cmd ) ); |
---|
43 | cmd[0] = command; |
---|
44 | k = 1; |
---|
45 | for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) |
---|
46 | if( *s == ' ' && !q ) |
---|
47 | { |
---|
48 | *s = 0; |
---|
49 | while( *++s == ' ' ); |
---|
50 | if( *s == '"' || *s == '\'' ) |
---|
51 | { |
---|
52 | q = *s; |
---|
53 | s ++; |
---|
54 | } |
---|
55 | if( *s ) |
---|
56 | { |
---|
57 | cmd[k++] = s; |
---|
58 | s --; |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | break; |
---|
63 | } |
---|
64 | } |
---|
65 | else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) ) |
---|
66 | { |
---|
67 | char *cpy; |
---|
68 | |
---|
69 | for( cpy = s; *cpy; cpy ++ ) |
---|
70 | cpy[0] = cpy[1]; |
---|
71 | } |
---|
72 | else if( *s == q ) |
---|
73 | { |
---|
74 | q = *s = 0; |
---|
75 | } |
---|
76 | cmd[k] = NULL; |
---|
77 | |
---|
78 | root_command( irc, cmd ); |
---|
79 | } |
---|
80 | |
---|
81 | #define MIN_ARGS( x, y... ) \ |
---|
82 | do \ |
---|
83 | { \ |
---|
84 | int blaat; \ |
---|
85 | for( blaat = 0; blaat <= x; blaat ++ ) \ |
---|
86 | if( cmd[blaat] == NULL ) \ |
---|
87 | { \ |
---|
88 | irc_usermsg( irc, "Not enough parameters given (need %d).", x ); \ |
---|
89 | return y; \ |
---|
90 | } \ |
---|
91 | } while( 0 ) |
---|
92 | |
---|
93 | void root_command( irc_t *irc, char *cmd[] ) |
---|
94 | { |
---|
95 | int i; |
---|
96 | |
---|
97 | if( !cmd[0] ) |
---|
98 | return; |
---|
99 | |
---|
100 | for( i = 0; commands[i].command; i++ ) |
---|
101 | if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) |
---|
102 | { |
---|
103 | MIN_ARGS( commands[i].required_parameters ); |
---|
104 | |
---|
105 | commands[i].execute( irc, cmd ); |
---|
106 | return; |
---|
107 | } |
---|
108 | |
---|
109 | irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); |
---|
110 | } |
---|
111 | |
---|
112 | static void cmd_help( irc_t *irc, char **cmd ) |
---|
113 | { |
---|
114 | char param[80]; |
---|
115 | int i; |
---|
116 | char *s; |
---|
117 | |
---|
118 | memset( param, 0, sizeof(param) ); |
---|
119 | for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { |
---|
120 | if ( i != 1 ) // prepend space except for the first parameter |
---|
121 | strcat(param, " "); |
---|
122 | strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); |
---|
123 | } |
---|
124 | |
---|
125 | s = help_get( &(global.help), param ); |
---|
126 | if( !s ) s = help_get( &(global.help), "" ); |
---|
127 | |
---|
128 | if( s ) |
---|
129 | { |
---|
130 | irc_usermsg( irc, "%s", s ); |
---|
131 | g_free( s ); |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | irc_usermsg( irc, "Error opening helpfile." ); |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | static void cmd_account( irc_t *irc, char **cmd ); |
---|
140 | |
---|
141 | static void cmd_identify( irc_t *irc, char **cmd ) |
---|
142 | { |
---|
143 | storage_status_t status = storage_load( irc, cmd[1] ); |
---|
144 | char *account_on[] = { "account", "on", NULL }; |
---|
145 | |
---|
146 | switch (status) { |
---|
147 | case STORAGE_INVALID_PASSWORD: |
---|
148 | irc_usermsg( irc, "Incorrect password" ); |
---|
149 | break; |
---|
150 | case STORAGE_NO_SUCH_USER: |
---|
151 | irc_usermsg( irc, "The nick is (probably) not registered" ); |
---|
152 | break; |
---|
153 | case STORAGE_OK: |
---|
154 | irc_usermsg( irc, "Password accepted, settings and accounts loaded" ); |
---|
155 | irc_setpass( irc, cmd[1] ); |
---|
156 | irc->status |= USTATUS_IDENTIFIED; |
---|
157 | irc_umode_set( irc, "+R", 1 ); |
---|
158 | if( set_getbool( &irc->set, "auto_connect" ) ) |
---|
159 | cmd_account( irc, account_on ); |
---|
160 | break; |
---|
161 | case STORAGE_OTHER_ERROR: |
---|
162 | default: |
---|
163 | irc_usermsg( irc, "Unknown error while loading configuration" ); |
---|
164 | break; |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | static void cmd_register( irc_t *irc, char **cmd ) |
---|
169 | { |
---|
170 | if( global.conf->authmode == AUTHMODE_REGISTERED ) |
---|
171 | { |
---|
172 | irc_usermsg( irc, "This server does not allow registering new accounts" ); |
---|
173 | return; |
---|
174 | } |
---|
175 | |
---|
176 | switch( storage_save( irc, cmd[1], FALSE ) ) { |
---|
177 | case STORAGE_ALREADY_EXISTS: |
---|
178 | irc_usermsg( irc, "Nick is already registered" ); |
---|
179 | break; |
---|
180 | |
---|
181 | case STORAGE_OK: |
---|
182 | irc_usermsg( irc, "Account successfully created" ); |
---|
183 | irc_setpass( irc, cmd[1] ); |
---|
184 | irc->status |= USTATUS_IDENTIFIED; |
---|
185 | irc_umode_set( irc, "+R", 1 ); |
---|
186 | break; |
---|
187 | |
---|
188 | default: |
---|
189 | irc_usermsg( irc, "Error registering" ); |
---|
190 | break; |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | static void cmd_drop( irc_t *irc, char **cmd ) |
---|
195 | { |
---|
196 | storage_status_t status; |
---|
197 | |
---|
198 | status = storage_remove (irc->nick, cmd[1]); |
---|
199 | switch (status) { |
---|
200 | case STORAGE_NO_SUCH_USER: |
---|
201 | irc_usermsg( irc, "That account does not exist" ); |
---|
202 | break; |
---|
203 | case STORAGE_INVALID_PASSWORD: |
---|
204 | irc_usermsg( irc, "Password invalid" ); |
---|
205 | break; |
---|
206 | case STORAGE_OK: |
---|
207 | irc_setpass( irc, NULL ); |
---|
208 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
209 | irc_umode_set( irc, "-R", 1 ); |
---|
210 | irc_usermsg( irc, "Account `%s' removed", irc->nick ); |
---|
211 | break; |
---|
212 | default: |
---|
213 | irc_usermsg( irc, "Error: `%d'", status ); |
---|
214 | break; |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | struct cmd_account_del_data |
---|
219 | { |
---|
220 | account_t *a; |
---|
221 | irc_t *irc; |
---|
222 | }; |
---|
223 | |
---|
224 | void cmd_account_del_yes( void *data ) |
---|
225 | { |
---|
226 | struct cmd_account_del_data *cad = data; |
---|
227 | account_t *a; |
---|
228 | |
---|
229 | for( a = cad->irc->accounts; a && a != cad->a; a = a->next ); |
---|
230 | |
---|
231 | if( a == NULL ) |
---|
232 | { |
---|
233 | irc_usermsg( cad->irc, "Account already deleted" ); |
---|
234 | } |
---|
235 | else if( a->ic ) |
---|
236 | { |
---|
237 | irc_usermsg( cad->irc, "Account is still logged in, can't delete" ); |
---|
238 | } |
---|
239 | else |
---|
240 | { |
---|
241 | account_del( cad->irc, a ); |
---|
242 | irc_usermsg( cad->irc, "Account deleted" ); |
---|
243 | } |
---|
244 | g_free( data ); |
---|
245 | } |
---|
246 | |
---|
247 | void cmd_account_del_no( void *data ) |
---|
248 | { |
---|
249 | g_free( data ); |
---|
250 | } |
---|
251 | |
---|
252 | static void cmd_showset( irc_t *irc, set_t **head, char *key ) |
---|
253 | { |
---|
254 | char *val; |
---|
255 | |
---|
256 | if( ( val = set_getstr( head, key ) ) ) |
---|
257 | irc_usermsg( irc, "%s = `%s'", key, val ); |
---|
258 | else |
---|
259 | irc_usermsg( irc, "%s is empty", key ); |
---|
260 | } |
---|
261 | |
---|
262 | typedef set_t** (*cmd_set_findhead)( irc_t*, char* ); |
---|
263 | typedef int (*cmd_set_checkflags)( irc_t*, set_t *set ); |
---|
264 | |
---|
265 | static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead, cmd_set_checkflags checkflags ) |
---|
266 | { |
---|
267 | char *set_full = NULL, *set_name = NULL, *tmp; |
---|
268 | set_t **head; |
---|
269 | |
---|
270 | if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
271 | { |
---|
272 | MIN_ARGS( 2, 0 ); |
---|
273 | set_full = cmd[2]; |
---|
274 | } |
---|
275 | else |
---|
276 | set_full = cmd[1]; |
---|
277 | |
---|
278 | if( findhead == NULL ) |
---|
279 | { |
---|
280 | set_name = set_full; |
---|
281 | |
---|
282 | head = &irc->set; |
---|
283 | } |
---|
284 | else |
---|
285 | { |
---|
286 | char *id; |
---|
287 | |
---|
288 | if( ( tmp = strchr( set_full, '/' ) ) ) |
---|
289 | { |
---|
290 | id = g_strndup( set_full, ( tmp - set_full ) ); |
---|
291 | set_name = tmp + 1; |
---|
292 | } |
---|
293 | else |
---|
294 | { |
---|
295 | id = g_strdup( set_full ); |
---|
296 | } |
---|
297 | |
---|
298 | if( ( head = findhead( irc, id ) ) == NULL ) |
---|
299 | { |
---|
300 | g_free( id ); |
---|
301 | irc_usermsg( irc, "Could not find setting." ); |
---|
302 | return 0; |
---|
303 | } |
---|
304 | g_free( id ); |
---|
305 | } |
---|
306 | |
---|
307 | if( cmd[1] && cmd[2] && set_name ) |
---|
308 | { |
---|
309 | set_t *s = set_find( head, set_name ); |
---|
310 | int st; |
---|
311 | |
---|
312 | if( s && checkflags && checkflags( irc, s ) == 0 ) |
---|
313 | return 0; |
---|
314 | |
---|
315 | if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
316 | st = set_reset( head, set_name ); |
---|
317 | else |
---|
318 | st = set_setstr( head, set_name, cmd[2] ); |
---|
319 | |
---|
320 | if( set_getstr( head, set_name ) == NULL ) |
---|
321 | { |
---|
322 | if( st ) |
---|
323 | irc_usermsg( irc, "Setting changed successfully" ); |
---|
324 | else |
---|
325 | irc_usermsg( irc, "Failed to change setting" ); |
---|
326 | } |
---|
327 | else |
---|
328 | { |
---|
329 | cmd_showset( irc, head, set_name ); |
---|
330 | } |
---|
331 | } |
---|
332 | else if( set_name ) |
---|
333 | { |
---|
334 | cmd_showset( irc, head, set_name ); |
---|
335 | } |
---|
336 | else |
---|
337 | { |
---|
338 | set_t *s = *head; |
---|
339 | while( s ) |
---|
340 | { |
---|
341 | cmd_showset( irc, &s, s->key ); |
---|
342 | s = s->next; |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | return 1; |
---|
347 | } |
---|
348 | |
---|
349 | static set_t **cmd_account_set_findhead( irc_t *irc, char *id ) |
---|
350 | { |
---|
351 | account_t *a; |
---|
352 | |
---|
353 | if( ( a = account_get( irc, id ) ) ) |
---|
354 | return &a->set; |
---|
355 | else |
---|
356 | return NULL; |
---|
357 | } |
---|
358 | |
---|
359 | static int cmd_account_set_checkflags( irc_t *irc, set_t *s ) |
---|
360 | { |
---|
361 | account_t *a = s->data; |
---|
362 | |
---|
363 | if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) |
---|
364 | { |
---|
365 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); |
---|
366 | return 0; |
---|
367 | } |
---|
368 | else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) |
---|
369 | { |
---|
370 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); |
---|
371 | return 0; |
---|
372 | } |
---|
373 | |
---|
374 | return 1; |
---|
375 | } |
---|
376 | |
---|
377 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
378 | { |
---|
379 | account_t *a; |
---|
380 | |
---|
381 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
382 | { |
---|
383 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
384 | return; |
---|
385 | } |
---|
386 | |
---|
387 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
388 | { |
---|
389 | struct prpl *prpl; |
---|
390 | |
---|
391 | MIN_ARGS( 4 ); |
---|
392 | |
---|
393 | prpl = find_protocol( cmd[2] ); |
---|
394 | |
---|
395 | if( prpl == NULL ) |
---|
396 | { |
---|
397 | irc_usermsg( irc, "Unknown protocol" ); |
---|
398 | return; |
---|
399 | } |
---|
400 | |
---|
401 | a = account_add( irc, prpl, cmd[3], cmd[4] ); |
---|
402 | if( cmd[5] ) |
---|
403 | { |
---|
404 | irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' " |
---|
405 | "is now deprecated. Use `account set' instead." ); |
---|
406 | set_setstr( &a->set, "server", cmd[5] ); |
---|
407 | } |
---|
408 | |
---|
409 | irc_usermsg( irc, "Account successfully added" ); |
---|
410 | } |
---|
411 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
412 | { |
---|
413 | MIN_ARGS( 2 ); |
---|
414 | |
---|
415 | if( !( a = account_get( irc, cmd[2] ) ) ) |
---|
416 | { |
---|
417 | irc_usermsg( irc, "Invalid account" ); |
---|
418 | } |
---|
419 | else if( a->ic ) |
---|
420 | { |
---|
421 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
422 | } |
---|
423 | else |
---|
424 | { |
---|
425 | struct cmd_account_del_data *cad; |
---|
426 | char *msg; |
---|
427 | |
---|
428 | cad = g_malloc( sizeof( struct cmd_account_del_data ) ); |
---|
429 | cad->a = a; |
---|
430 | cad->irc = irc; |
---|
431 | |
---|
432 | msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will " |
---|
433 | "also forget all your saved nicknames. If you want " |
---|
434 | "to change your username/password, use the `account " |
---|
435 | "set' command. Are you sure you want to delete this " |
---|
436 | "account?", a->prpl->name, a->user ); |
---|
437 | query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad ); |
---|
438 | g_free( msg ); |
---|
439 | } |
---|
440 | } |
---|
441 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
442 | { |
---|
443 | int i = 0; |
---|
444 | |
---|
445 | if( strchr( irc->umode, 'b' ) ) |
---|
446 | irc_usermsg( irc, "Account list:" ); |
---|
447 | |
---|
448 | for( a = irc->accounts; a; a = a->next ) |
---|
449 | { |
---|
450 | char *con; |
---|
451 | |
---|
452 | if( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) |
---|
453 | con = " (connected)"; |
---|
454 | else if( a->ic ) |
---|
455 | con = " (connecting)"; |
---|
456 | else if( a->reconnect ) |
---|
457 | con = " (awaiting reconnect)"; |
---|
458 | else |
---|
459 | con = ""; |
---|
460 | |
---|
461 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
462 | |
---|
463 | i ++; |
---|
464 | } |
---|
465 | irc_usermsg( irc, "End of account list" ); |
---|
466 | } |
---|
467 | else if( g_strcasecmp( cmd[1], "on" ) == 0 ) |
---|
468 | { |
---|
469 | if( cmd[2] ) |
---|
470 | { |
---|
471 | if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
472 | { |
---|
473 | if( a->ic ) |
---|
474 | { |
---|
475 | irc_usermsg( irc, "Account already online" ); |
---|
476 | return; |
---|
477 | } |
---|
478 | else |
---|
479 | { |
---|
480 | account_on( irc, a ); |
---|
481 | } |
---|
482 | } |
---|
483 | else |
---|
484 | { |
---|
485 | irc_usermsg( irc, "Invalid account" ); |
---|
486 | return; |
---|
487 | } |
---|
488 | } |
---|
489 | else |
---|
490 | { |
---|
491 | if ( irc->accounts ) { |
---|
492 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
493 | |
---|
494 | for( a = irc->accounts; a; a = a->next ) |
---|
495 | if( !a->ic && a->auto_connect ) |
---|
496 | account_on( irc, a ); |
---|
497 | } |
---|
498 | else |
---|
499 | { |
---|
500 | irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); |
---|
501 | } |
---|
502 | } |
---|
503 | } |
---|
504 | else if( g_strcasecmp( cmd[1], "off" ) == 0 ) |
---|
505 | { |
---|
506 | if( !cmd[2] ) |
---|
507 | { |
---|
508 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
509 | |
---|
510 | for( a = irc->accounts; a; a = a->next ) |
---|
511 | { |
---|
512 | if( a->ic ) |
---|
513 | account_off( irc, a ); |
---|
514 | else if( a->reconnect ) |
---|
515 | cancel_auto_reconnect( a ); |
---|
516 | } |
---|
517 | } |
---|
518 | else if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
519 | { |
---|
520 | if( a->ic ) |
---|
521 | { |
---|
522 | account_off( irc, a ); |
---|
523 | } |
---|
524 | else if( a->reconnect ) |
---|
525 | { |
---|
526 | cancel_auto_reconnect( a ); |
---|
527 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
528 | } |
---|
529 | else |
---|
530 | { |
---|
531 | irc_usermsg( irc, "Account already offline" ); |
---|
532 | return; |
---|
533 | } |
---|
534 | } |
---|
535 | else |
---|
536 | { |
---|
537 | irc_usermsg( irc, "Invalid account" ); |
---|
538 | return; |
---|
539 | } |
---|
540 | } |
---|
541 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
542 | { |
---|
543 | MIN_ARGS( 2 ); |
---|
544 | |
---|
545 | cmd_set_real( irc, cmd + 1, cmd_account_set_findhead, cmd_account_set_checkflags ); |
---|
546 | } |
---|
547 | else |
---|
548 | { |
---|
549 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[1] ); |
---|
550 | } |
---|
551 | } |
---|
552 | |
---|
553 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
554 | { |
---|
555 | account_t *a; |
---|
556 | int add_on_server = 1; |
---|
557 | |
---|
558 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
559 | { |
---|
560 | MIN_ARGS( 3 ); |
---|
561 | add_on_server = 0; |
---|
562 | cmd ++; |
---|
563 | } |
---|
564 | |
---|
565 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
566 | { |
---|
567 | irc_usermsg( irc, "Invalid account" ); |
---|
568 | return; |
---|
569 | } |
---|
570 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
571 | { |
---|
572 | irc_usermsg( irc, "That account is not on-line" ); |
---|
573 | return; |
---|
574 | } |
---|
575 | |
---|
576 | if( cmd[3] ) |
---|
577 | { |
---|
578 | if( !nick_ok( cmd[3] ) ) |
---|
579 | { |
---|
580 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
581 | return; |
---|
582 | } |
---|
583 | else if( user_find( irc, cmd[3] ) ) |
---|
584 | { |
---|
585 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
586 | return; |
---|
587 | } |
---|
588 | else |
---|
589 | { |
---|
590 | nick_set( a, cmd[2], cmd[3] ); |
---|
591 | } |
---|
592 | } |
---|
593 | |
---|
594 | if( add_on_server ) |
---|
595 | a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); |
---|
596 | else |
---|
597 | /* Yeah, officially this is a call-*back*... So if we just |
---|
598 | called add_buddy, we'll wait for the IM server to respond |
---|
599 | before we do this. */ |
---|
600 | imcb_add_buddy( a->ic, cmd[2], NULL ); |
---|
601 | |
---|
602 | irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] ); |
---|
603 | } |
---|
604 | |
---|
605 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
606 | { |
---|
607 | struct im_connection *ic; |
---|
608 | account_t *a; |
---|
609 | |
---|
610 | if( !cmd[2] ) |
---|
611 | { |
---|
612 | user_t *u = user_find( irc, cmd[1] ); |
---|
613 | if( !u || !u->ic ) |
---|
614 | { |
---|
615 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
616 | return; |
---|
617 | } |
---|
618 | ic = u->ic; |
---|
619 | cmd[2] = u->handle; |
---|
620 | } |
---|
621 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
622 | { |
---|
623 | irc_usermsg( irc, "Invalid account" ); |
---|
624 | return; |
---|
625 | } |
---|
626 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
627 | { |
---|
628 | irc_usermsg( irc, "That account is not on-line" ); |
---|
629 | return; |
---|
630 | } |
---|
631 | |
---|
632 | if( !ic->acc->prpl->get_info ) |
---|
633 | { |
---|
634 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
635 | } |
---|
636 | else |
---|
637 | { |
---|
638 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
639 | } |
---|
640 | } |
---|
641 | |
---|
642 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
643 | { |
---|
644 | user_t *u; |
---|
645 | |
---|
646 | if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
647 | { |
---|
648 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
649 | } |
---|
650 | else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) |
---|
651 | { |
---|
652 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
653 | } |
---|
654 | else if( !nick_ok( cmd[2] ) ) |
---|
655 | { |
---|
656 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
657 | } |
---|
658 | else if( !( u = user_find( irc, cmd[1] ) ) ) |
---|
659 | { |
---|
660 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
661 | } |
---|
662 | else |
---|
663 | { |
---|
664 | user_rename( irc, cmd[1], cmd[2] ); |
---|
665 | irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); |
---|
666 | if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) |
---|
667 | { |
---|
668 | g_free( irc->mynick ); |
---|
669 | irc->mynick = g_strdup( cmd[2] ); |
---|
670 | |
---|
671 | /* If we're called internally (user did "set root_nick"), |
---|
672 | let's not go O(INF). :-) */ |
---|
673 | if( strcmp( cmd[0], "set_rename" ) != 0 ) |
---|
674 | set_setstr( &irc->set, "root_nick", cmd[2] ); |
---|
675 | } |
---|
676 | else if( u->send_handler == buddy_send_handler ) |
---|
677 | { |
---|
678 | nick_set( u->ic->acc, u->handle, cmd[2] ); |
---|
679 | } |
---|
680 | |
---|
681 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
682 | } |
---|
683 | } |
---|
684 | |
---|
685 | char *set_eval_root_nick( set_t *set, char *new_nick ) |
---|
686 | { |
---|
687 | irc_t *irc = set->data; |
---|
688 | |
---|
689 | if( strcmp( irc->mynick, new_nick ) != 0 ) |
---|
690 | { |
---|
691 | char *cmd[] = { "set_rename", irc->mynick, new_nick, NULL }; |
---|
692 | |
---|
693 | cmd_rename( irc, cmd ); |
---|
694 | } |
---|
695 | |
---|
696 | return strcmp( irc->mynick, new_nick ) == 0 ? new_nick : SET_INVALID; |
---|
697 | } |
---|
698 | |
---|
699 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
700 | { |
---|
701 | user_t *u; |
---|
702 | char *s; |
---|
703 | |
---|
704 | if( !( u = user_find( irc, cmd[1] ) ) || !u->ic ) |
---|
705 | { |
---|
706 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
707 | return; |
---|
708 | } |
---|
709 | s = g_strdup( u->handle ); |
---|
710 | |
---|
711 | u->ic->acc->prpl->remove_buddy( u->ic, u->handle, NULL ); |
---|
712 | nick_del( u->ic->acc, u->handle ); |
---|
713 | user_del( irc, cmd[1] ); |
---|
714 | |
---|
715 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
716 | g_free( s ); |
---|
717 | |
---|
718 | return; |
---|
719 | } |
---|
720 | |
---|
721 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
722 | { |
---|
723 | struct im_connection *ic; |
---|
724 | account_t *a; |
---|
725 | |
---|
726 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
727 | { |
---|
728 | char *format; |
---|
729 | GSList *l; |
---|
730 | |
---|
731 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
732 | format = "%s\t%s"; |
---|
733 | else |
---|
734 | format = "%-32.32s %-16.16s"; |
---|
735 | |
---|
736 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
737 | for( l = a->ic->deny; l; l = l->next ) |
---|
738 | { |
---|
739 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
740 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
741 | } |
---|
742 | irc_usermsg( irc, "End of list." ); |
---|
743 | |
---|
744 | return; |
---|
745 | } |
---|
746 | else if( !cmd[2] ) |
---|
747 | { |
---|
748 | user_t *u = user_find( irc, cmd[1] ); |
---|
749 | if( !u || !u->ic ) |
---|
750 | { |
---|
751 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
752 | return; |
---|
753 | } |
---|
754 | ic = u->ic; |
---|
755 | cmd[2] = u->handle; |
---|
756 | } |
---|
757 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
758 | { |
---|
759 | irc_usermsg( irc, "Invalid account" ); |
---|
760 | return; |
---|
761 | } |
---|
762 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
763 | { |
---|
764 | irc_usermsg( irc, "That account is not on-line" ); |
---|
765 | return; |
---|
766 | } |
---|
767 | |
---|
768 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
769 | { |
---|
770 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
771 | } |
---|
772 | else |
---|
773 | { |
---|
774 | imc_rem_allow( ic, cmd[2] ); |
---|
775 | imc_add_block( ic, cmd[2] ); |
---|
776 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
777 | } |
---|
778 | } |
---|
779 | |
---|
780 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
781 | { |
---|
782 | struct im_connection *ic; |
---|
783 | account_t *a; |
---|
784 | |
---|
785 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
786 | { |
---|
787 | char *format; |
---|
788 | GSList *l; |
---|
789 | |
---|
790 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
791 | format = "%s\t%s"; |
---|
792 | else |
---|
793 | format = "%-32.32s %-16.16s"; |
---|
794 | |
---|
795 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
796 | for( l = a->ic->permit; l; l = l->next ) |
---|
797 | { |
---|
798 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
799 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
800 | } |
---|
801 | irc_usermsg( irc, "End of list." ); |
---|
802 | |
---|
803 | return; |
---|
804 | } |
---|
805 | else if( !cmd[2] ) |
---|
806 | { |
---|
807 | user_t *u = user_find( irc, cmd[1] ); |
---|
808 | if( !u || !u->ic ) |
---|
809 | { |
---|
810 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
811 | return; |
---|
812 | } |
---|
813 | ic = u->ic; |
---|
814 | cmd[2] = u->handle; |
---|
815 | } |
---|
816 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
817 | { |
---|
818 | irc_usermsg( irc, "Invalid account" ); |
---|
819 | return; |
---|
820 | } |
---|
821 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
822 | { |
---|
823 | irc_usermsg( irc, "That account is not on-line" ); |
---|
824 | return; |
---|
825 | } |
---|
826 | |
---|
827 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
828 | { |
---|
829 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
830 | } |
---|
831 | else |
---|
832 | { |
---|
833 | imc_rem_block( ic, cmd[2] ); |
---|
834 | imc_add_allow( ic, cmd[2] ); |
---|
835 | |
---|
836 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
837 | } |
---|
838 | } |
---|
839 | |
---|
840 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
841 | { |
---|
842 | query_t *q = NULL; |
---|
843 | int numq = 0; |
---|
844 | |
---|
845 | if( irc->queries == NULL ) |
---|
846 | { |
---|
847 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
848 | return; |
---|
849 | } |
---|
850 | |
---|
851 | /* If there's an argument, the user seems to want to answer another question than the |
---|
852 | first/last (depending on the query_order setting) one. */ |
---|
853 | if( cmd[1] ) |
---|
854 | { |
---|
855 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
856 | { |
---|
857 | irc_usermsg( irc, "Invalid query number" ); |
---|
858 | return; |
---|
859 | } |
---|
860 | |
---|
861 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
862 | if( numq == 0 ) |
---|
863 | break; |
---|
864 | |
---|
865 | if( !q ) |
---|
866 | { |
---|
867 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
868 | return; |
---|
869 | } |
---|
870 | } |
---|
871 | |
---|
872 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
873 | query_answer( irc, q, 1 ); |
---|
874 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
875 | query_answer( irc, q, 0 ); |
---|
876 | } |
---|
877 | |
---|
878 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
879 | { |
---|
880 | cmd_set_real( irc, cmd, NULL, NULL ); |
---|
881 | } |
---|
882 | |
---|
883 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
884 | { |
---|
885 | if( ( irc->status & USTATUS_IDENTIFIED ) == 0 ) |
---|
886 | irc_usermsg( irc, "Please create an account first" ); |
---|
887 | else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK ) |
---|
888 | irc_usermsg( irc, "Configuration saved" ); |
---|
889 | else |
---|
890 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
891 | } |
---|
892 | |
---|
893 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
894 | { |
---|
895 | int online = 0, away = 0, offline = 0; |
---|
896 | user_t *u; |
---|
897 | char s[256]; |
---|
898 | char *format; |
---|
899 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
900 | |
---|
901 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
902 | online = offline = away = 1; |
---|
903 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
904 | offline = 1; |
---|
905 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
906 | away = 1; |
---|
907 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
908 | online = 1; |
---|
909 | else |
---|
910 | online = away = 1; |
---|
911 | |
---|
912 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
913 | format = "%s\t%s\t%s"; |
---|
914 | else |
---|
915 | format = "%-16.16s %-40.40s %s"; |
---|
916 | |
---|
917 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
918 | |
---|
919 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) |
---|
920 | { |
---|
921 | if( online == 1 ) |
---|
922 | { |
---|
923 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
924 | irc_usermsg( irc, format, u->nick, s, "Online" ); |
---|
925 | } |
---|
926 | |
---|
927 | n_online ++; |
---|
928 | } |
---|
929 | |
---|
930 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) |
---|
931 | { |
---|
932 | if( away == 1 ) |
---|
933 | { |
---|
934 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
935 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
936 | } |
---|
937 | n_away ++; |
---|
938 | } |
---|
939 | |
---|
940 | for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) |
---|
941 | { |
---|
942 | if( offline == 1 ) |
---|
943 | { |
---|
944 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
945 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
946 | } |
---|
947 | n_offline ++; |
---|
948 | } |
---|
949 | |
---|
950 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
951 | } |
---|
952 | |
---|
953 | static void cmd_nick( irc_t *irc, char **cmd ) |
---|
954 | { |
---|
955 | account_t *a; |
---|
956 | |
---|
957 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
958 | { |
---|
959 | irc_usermsg( irc, "Invalid account"); |
---|
960 | } |
---|
961 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
962 | { |
---|
963 | irc_usermsg( irc, "That account is not on-line" ); |
---|
964 | } |
---|
965 | else if ( !cmd[2] ) |
---|
966 | { |
---|
967 | irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" ); |
---|
968 | } |
---|
969 | else if ( !a->prpl->set_my_name ) |
---|
970 | { |
---|
971 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
972 | } |
---|
973 | else |
---|
974 | { |
---|
975 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
976 | |
---|
977 | a->prpl->set_my_name( a->ic, cmd[2] ); |
---|
978 | } |
---|
979 | } |
---|
980 | |
---|
981 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
982 | { |
---|
983 | query_t *q = irc->queries; |
---|
984 | int num; |
---|
985 | |
---|
986 | if( !q ) |
---|
987 | { |
---|
988 | irc_usermsg( irc, "There are no pending questions." ); |
---|
989 | return; |
---|
990 | } |
---|
991 | |
---|
992 | irc_usermsg( irc, "Pending queries:" ); |
---|
993 | |
---|
994 | for( num = 0; q; q = q->next, num ++ ) |
---|
995 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
996 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
997 | else |
---|
998 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
999 | } |
---|
1000 | |
---|
1001 | static void cmd_join_chat( irc_t *irc, char **cmd ) |
---|
1002 | { |
---|
1003 | irc_usermsg( irc, "This command is now obsolete. " |
---|
1004 | "Please try the `chat' command instead." ); |
---|
1005 | } |
---|
1006 | |
---|
1007 | static set_t **cmd_chat_set_findhead( irc_t *irc, char *id ) |
---|
1008 | { |
---|
1009 | struct chat *c; |
---|
1010 | |
---|
1011 | if( ( c = chat_get( irc, id ) ) ) |
---|
1012 | return &c->set; |
---|
1013 | else |
---|
1014 | return NULL; |
---|
1015 | } |
---|
1016 | |
---|
1017 | static void cmd_chat( irc_t *irc, char **cmd ) |
---|
1018 | { |
---|
1019 | account_t *acc; |
---|
1020 | struct chat *c; |
---|
1021 | |
---|
1022 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
1023 | { |
---|
1024 | char *channel, *s; |
---|
1025 | |
---|
1026 | MIN_ARGS( 3 ); |
---|
1027 | |
---|
1028 | if( !( acc = account_get( irc, cmd[2] ) ) ) |
---|
1029 | { |
---|
1030 | irc_usermsg( irc, "Invalid account" ); |
---|
1031 | return; |
---|
1032 | } |
---|
1033 | |
---|
1034 | if( cmd[4] == NULL ) |
---|
1035 | { |
---|
1036 | channel = g_strdup( cmd[3] ); |
---|
1037 | if( ( s = strchr( channel, '@' ) ) ) |
---|
1038 | *s = 0; |
---|
1039 | } |
---|
1040 | else |
---|
1041 | { |
---|
1042 | channel = g_strdup( cmd[4] ); |
---|
1043 | } |
---|
1044 | |
---|
1045 | if( strchr( CTYPES, channel[0] ) == NULL ) |
---|
1046 | { |
---|
1047 | s = g_strdup_printf( "%c%s", CTYPES[0], channel ); |
---|
1048 | g_free( channel ); |
---|
1049 | channel = s; |
---|
1050 | } |
---|
1051 | |
---|
1052 | if( ( c = chat_add( irc, acc, cmd[3], channel ) ) ) |
---|
1053 | irc_usermsg( irc, "Chatroom added successfully." ); |
---|
1054 | else |
---|
1055 | irc_usermsg( irc, "Could not add chatroom." ); |
---|
1056 | |
---|
1057 | g_free( channel ); |
---|
1058 | } |
---|
1059 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
1060 | { |
---|
1061 | int i = 0; |
---|
1062 | |
---|
1063 | if( strchr( irc->umode, 'b' ) ) |
---|
1064 | irc_usermsg( irc, "Chatroom list:" ); |
---|
1065 | |
---|
1066 | for( c = irc->chatrooms; c; c = c->next ) |
---|
1067 | { |
---|
1068 | irc_usermsg( irc, "%2d. %s(%s) %s, %s", i, c->acc->prpl->name, |
---|
1069 | c->acc->user, c->handle, c->channel ); |
---|
1070 | |
---|
1071 | i ++; |
---|
1072 | } |
---|
1073 | irc_usermsg( irc, "End of chatroom list" ); |
---|
1074 | } |
---|
1075 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
1076 | { |
---|
1077 | MIN_ARGS( 2 ); |
---|
1078 | |
---|
1079 | cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead, NULL ); |
---|
1080 | } |
---|
1081 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
1082 | { |
---|
1083 | MIN_ARGS( 2 ); |
---|
1084 | |
---|
1085 | if( ( c = chat_get( irc, cmd[2] ) ) ) |
---|
1086 | { |
---|
1087 | chat_del( irc, c ); |
---|
1088 | } |
---|
1089 | else |
---|
1090 | { |
---|
1091 | irc_usermsg( irc, "Could not remove chat." ); |
---|
1092 | } |
---|
1093 | } |
---|
1094 | else if( g_strcasecmp( cmd[1], "with" ) == 0 ) |
---|
1095 | { |
---|
1096 | user_t *u; |
---|
1097 | |
---|
1098 | MIN_ARGS( 2 ); |
---|
1099 | |
---|
1100 | if( ( u = user_find( irc, cmd[2] ) ) && u->ic && u->ic->acc->prpl->chat_with ) |
---|
1101 | { |
---|
1102 | if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) ) |
---|
1103 | { |
---|
1104 | irc_usermsg( irc, "(Possible) failure while trying to open " |
---|
1105 | "a groupchat with %s.", u->nick ); |
---|
1106 | } |
---|
1107 | } |
---|
1108 | else |
---|
1109 | { |
---|
1110 | irc_usermsg( irc, "Can't open a groupchat with %s.", cmd[2] ); |
---|
1111 | } |
---|
1112 | } |
---|
1113 | else |
---|
1114 | { |
---|
1115 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] ); |
---|
1116 | } |
---|
1117 | |
---|
1118 | |
---|
1119 | |
---|
1120 | #if 0 |
---|
1121 | account_t *a; |
---|
1122 | struct im_connection *ic; |
---|
1123 | char *chat, *channel, *nick = NULL, *password = NULL; |
---|
1124 | struct groupchat *c; |
---|
1125 | |
---|
1126 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
1127 | { |
---|
1128 | irc_usermsg( irc, "Invalid account" ); |
---|
1129 | return; |
---|
1130 | } |
---|
1131 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
1132 | { |
---|
1133 | irc_usermsg( irc, "That account is not on-line" ); |
---|
1134 | return; |
---|
1135 | } |
---|
1136 | else if( a->prpl->chat_join == NULL ) |
---|
1137 | { |
---|
1138 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
1139 | return; |
---|
1140 | } |
---|
1141 | ic = a->ic; |
---|
1142 | |
---|
1143 | chat = cmd[2]; |
---|
1144 | if( cmd[3] ) |
---|
1145 | { |
---|
1146 | if( strchr( CTYPES, cmd[3][0] ) == NULL ) |
---|
1147 | channel = g_strdup_printf( "&%s", cmd[3] ); |
---|
1148 | else |
---|
1149 | channel = g_strdup( cmd[3] ); |
---|
1150 | } |
---|
1151 | else |
---|
1152 | { |
---|
1153 | char *s; |
---|
1154 | |
---|
1155 | channel = g_strdup_printf( "&%s", chat ); |
---|
1156 | if( ( s = strchr( channel, '@' ) ) ) |
---|
1157 | *s = 0; |
---|
1158 | } |
---|
1159 | if( cmd[3] && cmd[4] ) |
---|
1160 | nick = cmd[4]; |
---|
1161 | else |
---|
1162 | nick = irc->nick; |
---|
1163 | if( cmd[3] && cmd[4] && cmd[5] ) |
---|
1164 | password = cmd[5]; |
---|
1165 | |
---|
1166 | if( !nick_ok( channel + 1 ) ) |
---|
1167 | { |
---|
1168 | irc_usermsg( irc, "Invalid channel name: %s", channel ); |
---|
1169 | g_free( channel ); |
---|
1170 | return; |
---|
1171 | } |
---|
1172 | else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) ) |
---|
1173 | { |
---|
1174 | irc_usermsg( irc, "Channel already exists: %s", channel ); |
---|
1175 | g_free( channel ); |
---|
1176 | return; |
---|
1177 | } |
---|
1178 | |
---|
1179 | if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) ) |
---|
1180 | { |
---|
1181 | g_free( c->channel ); |
---|
1182 | c->channel = channel; |
---|
1183 | } |
---|
1184 | else |
---|
1185 | { |
---|
1186 | irc_usermsg( irc, "Tried to join chat, not sure if this was successful" ); |
---|
1187 | g_free( channel ); |
---|
1188 | } |
---|
1189 | #endif |
---|
1190 | } |
---|
1191 | |
---|
1192 | const command_t commands[] = { |
---|
1193 | { "help", 0, cmd_help, 0 }, |
---|
1194 | { "identify", 1, cmd_identify, 0 }, |
---|
1195 | { "register", 1, cmd_register, 0 }, |
---|
1196 | { "drop", 1, cmd_drop, 0 }, |
---|
1197 | { "account", 1, cmd_account, 0 }, |
---|
1198 | { "add", 2, cmd_add, 0 }, |
---|
1199 | { "info", 1, cmd_info, 0 }, |
---|
1200 | { "rename", 2, cmd_rename, 0 }, |
---|
1201 | { "remove", 1, cmd_remove, 0 }, |
---|
1202 | { "block", 1, cmd_block, 0 }, |
---|
1203 | { "allow", 1, cmd_allow, 0 }, |
---|
1204 | { "save", 0, cmd_save, 0 }, |
---|
1205 | { "set", 0, cmd_set, 0 }, |
---|
1206 | { "yes", 0, cmd_yesno, 0 }, |
---|
1207 | { "no", 0, cmd_yesno, 0 }, |
---|
1208 | { "blist", 0, cmd_blist, 0 }, |
---|
1209 | { "nick", 1, cmd_nick, 0 }, |
---|
1210 | { "qlist", 0, cmd_qlist, 0 }, |
---|
1211 | { "join_chat", 2, cmd_join_chat, 0 }, |
---|
1212 | { "chat", 1, cmd_chat, 0 }, |
---|
1213 | { NULL } |
---|
1214 | }; |
---|