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 | |
---|
32 | #include <string.h> |
---|
33 | |
---|
34 | void root_command_string( irc_t *irc, user_t *u, char *command, int flags ) |
---|
35 | { |
---|
36 | char *cmd[IRC_MAX_ARGS]; |
---|
37 | char *s; |
---|
38 | int k; |
---|
39 | char q = 0; |
---|
40 | |
---|
41 | memset( cmd, 0, sizeof( cmd ) ); |
---|
42 | cmd[0] = command; |
---|
43 | k = 1; |
---|
44 | for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) |
---|
45 | if( *s == ' ' && !q ) |
---|
46 | { |
---|
47 | *s = 0; |
---|
48 | while( *++s == ' ' ); |
---|
49 | if( *s == '"' || *s == '\'' ) |
---|
50 | { |
---|
51 | q = *s; |
---|
52 | s ++; |
---|
53 | } |
---|
54 | if( *s ) |
---|
55 | { |
---|
56 | cmd[k++] = s; |
---|
57 | s --; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | break; |
---|
62 | } |
---|
63 | } |
---|
64 | else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) ) |
---|
65 | { |
---|
66 | char *cpy; |
---|
67 | |
---|
68 | for( cpy = s; *cpy; cpy ++ ) |
---|
69 | cpy[0] = cpy[1]; |
---|
70 | } |
---|
71 | else if( *s == q ) |
---|
72 | { |
---|
73 | q = *s = 0; |
---|
74 | } |
---|
75 | cmd[k] = NULL; |
---|
76 | |
---|
77 | root_command( irc, cmd ); |
---|
78 | } |
---|
79 | |
---|
80 | void root_command( irc_t *irc, char *cmd[] ) |
---|
81 | { |
---|
82 | int i; |
---|
83 | |
---|
84 | if( !cmd[0] ) |
---|
85 | return; |
---|
86 | |
---|
87 | for( i = 0; commands[i].command; i++ ) |
---|
88 | if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) |
---|
89 | { |
---|
90 | if( !cmd[commands[i].required_parameters] ) |
---|
91 | { |
---|
92 | irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters ); |
---|
93 | return; |
---|
94 | } |
---|
95 | commands[i].execute( irc, cmd ); |
---|
96 | return; |
---|
97 | } |
---|
98 | |
---|
99 | irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); |
---|
100 | } |
---|
101 | |
---|
102 | static void cmd_help( irc_t *irc, char **cmd ) |
---|
103 | { |
---|
104 | char param[80]; |
---|
105 | int i; |
---|
106 | char *s; |
---|
107 | |
---|
108 | memset( param, 0, sizeof(param) ); |
---|
109 | for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { |
---|
110 | if ( i != 1 ) // prepend space except for the first parameter |
---|
111 | strcat(param, " "); |
---|
112 | strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); |
---|
113 | } |
---|
114 | |
---|
115 | s = help_get( &(global.help), param ); |
---|
116 | if( !s ) s = help_get( &(global.help), "" ); |
---|
117 | |
---|
118 | if( s ) |
---|
119 | { |
---|
120 | irc_usermsg( irc, "%s", s ); |
---|
121 | g_free( s ); |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | irc_usermsg( irc, "Error opening helpfile." ); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | static void cmd_identify( irc_t *irc, char **cmd ) |
---|
130 | { |
---|
131 | storage_status_t status = storage_load( irc->nick, cmd[1], irc ); |
---|
132 | |
---|
133 | switch (status) { |
---|
134 | case STORAGE_INVALID_PASSWORD: |
---|
135 | irc_usermsg( irc, "Incorrect password" ); |
---|
136 | break; |
---|
137 | case STORAGE_NO_SUCH_USER: |
---|
138 | irc_usermsg( irc, "The nick is (probably) not registered" ); |
---|
139 | break; |
---|
140 | case STORAGE_OK: |
---|
141 | irc_usermsg( irc, "Password accepted" ); |
---|
142 | irc_umode_set( irc, "+R", 1 ); |
---|
143 | break; |
---|
144 | case STORAGE_OTHER_ERROR: |
---|
145 | default: |
---|
146 | irc_usermsg( irc, "Unknown error while loading configuration" ); |
---|
147 | break; |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | static void cmd_register( irc_t *irc, char **cmd ) |
---|
152 | { |
---|
153 | if( global.conf->authmode == AUTHMODE_REGISTERED ) |
---|
154 | { |
---|
155 | irc_usermsg( irc, "This server does not allow registering new accounts" ); |
---|
156 | return; |
---|
157 | } |
---|
158 | |
---|
159 | irc_setpass( irc, cmd[1] ); |
---|
160 | switch( storage_save( irc, FALSE )) { |
---|
161 | case STORAGE_ALREADY_EXISTS: |
---|
162 | irc_usermsg( irc, "Nick is already registered" ); |
---|
163 | break; |
---|
164 | |
---|
165 | case STORAGE_OK: |
---|
166 | irc->status |= USTATUS_IDENTIFIED; |
---|
167 | irc_umode_set( irc, "+R", 1 ); |
---|
168 | break; |
---|
169 | |
---|
170 | default: |
---|
171 | irc_usermsg( irc, "Error registering" ); |
---|
172 | break; |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | static void cmd_drop( irc_t *irc, char **cmd ) |
---|
177 | { |
---|
178 | storage_status_t status; |
---|
179 | |
---|
180 | status = storage_remove (irc->nick, cmd[1]); |
---|
181 | switch (status) { |
---|
182 | case STORAGE_NO_SUCH_USER: |
---|
183 | irc_usermsg( irc, "That account does not exist" ); |
---|
184 | break; |
---|
185 | case STORAGE_INVALID_PASSWORD: |
---|
186 | irc_usermsg( irc, "Password invalid" ); |
---|
187 | break; |
---|
188 | case STORAGE_OK: |
---|
189 | irc_setpass( irc, NULL ); |
---|
190 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
191 | irc_umode_set( irc, "-R", 1 ); |
---|
192 | irc_usermsg( irc, "Account `%s' removed", irc->nick ); |
---|
193 | break; |
---|
194 | default: |
---|
195 | irc_usermsg( irc, "Error: '%d'", status ); |
---|
196 | break; |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
201 | { |
---|
202 | account_t *a; |
---|
203 | |
---|
204 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
205 | { |
---|
206 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
207 | return; |
---|
208 | } |
---|
209 | |
---|
210 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
211 | { |
---|
212 | struct prpl *prpl; |
---|
213 | |
---|
214 | if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL ) |
---|
215 | { |
---|
216 | irc_usermsg( irc, "Not enough parameters" ); |
---|
217 | return; |
---|
218 | } |
---|
219 | |
---|
220 | prpl = find_protocol(cmd[2]); |
---|
221 | |
---|
222 | if( prpl == NULL ) |
---|
223 | { |
---|
224 | irc_usermsg( irc, "Unknown protocol" ); |
---|
225 | return; |
---|
226 | } |
---|
227 | |
---|
228 | a = account_add( irc, prpl, cmd[3], cmd[4] ); |
---|
229 | |
---|
230 | if( cmd[5] ) |
---|
231 | a->server = g_strdup( cmd[5] ); |
---|
232 | |
---|
233 | irc_usermsg( irc, "Account successfully added" ); |
---|
234 | } |
---|
235 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
236 | { |
---|
237 | if( !cmd[2] ) |
---|
238 | { |
---|
239 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
240 | } |
---|
241 | else if( !( a = account_get( irc, cmd[2] ) ) ) |
---|
242 | { |
---|
243 | irc_usermsg( irc, "Invalid account" ); |
---|
244 | } |
---|
245 | else if( a->gc ) |
---|
246 | { |
---|
247 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
248 | } |
---|
249 | else |
---|
250 | { |
---|
251 | account_del( irc, a ); |
---|
252 | irc_usermsg( irc, "Account deleted" ); |
---|
253 | } |
---|
254 | } |
---|
255 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
256 | { |
---|
257 | int i = 0; |
---|
258 | |
---|
259 | if( strchr( irc->umode, 'b' ) ) |
---|
260 | irc_usermsg( irc, "Account list:" ); |
---|
261 | |
---|
262 | for( a = irc->accounts; a; a = a->next ) |
---|
263 | { |
---|
264 | char *con; |
---|
265 | |
---|
266 | if( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) |
---|
267 | con = " (connected)"; |
---|
268 | else if( a->gc ) |
---|
269 | con = " (connecting)"; |
---|
270 | else if( a->reconnect ) |
---|
271 | con = " (awaiting reconnect)"; |
---|
272 | else |
---|
273 | con = ""; |
---|
274 | |
---|
275 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
276 | |
---|
277 | i ++; |
---|
278 | } |
---|
279 | irc_usermsg( irc, "End of account list" ); |
---|
280 | } |
---|
281 | else if( g_strcasecmp( cmd[1], "on" ) == 0 ) |
---|
282 | { |
---|
283 | if( cmd[2] ) |
---|
284 | { |
---|
285 | if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
286 | { |
---|
287 | if( a->gc ) |
---|
288 | { |
---|
289 | irc_usermsg( irc, "Account already online" ); |
---|
290 | return; |
---|
291 | } |
---|
292 | else |
---|
293 | { |
---|
294 | account_on( irc, a ); |
---|
295 | } |
---|
296 | } |
---|
297 | else |
---|
298 | { |
---|
299 | irc_usermsg( irc, "Invalid account" ); |
---|
300 | return; |
---|
301 | } |
---|
302 | } |
---|
303 | else |
---|
304 | { |
---|
305 | if ( irc->accounts ) { |
---|
306 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
307 | |
---|
308 | for( a = irc->accounts; a; a = a->next ) |
---|
309 | if( !a->gc && a->auto_connect ) |
---|
310 | account_on( irc, a ); |
---|
311 | } |
---|
312 | else |
---|
313 | { |
---|
314 | irc_usermsg( irc, "No accounts known. Use 'account add' to add one." ); |
---|
315 | } |
---|
316 | } |
---|
317 | } |
---|
318 | else if( g_strcasecmp( cmd[1], "off" ) == 0 ) |
---|
319 | { |
---|
320 | if( !cmd[2] ) |
---|
321 | { |
---|
322 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
323 | |
---|
324 | for( a = irc->accounts; a; a = a->next ) |
---|
325 | { |
---|
326 | if( a->gc ) |
---|
327 | account_off( irc, a ); |
---|
328 | else if( a->reconnect ) |
---|
329 | cancel_auto_reconnect( a ); |
---|
330 | } |
---|
331 | } |
---|
332 | else if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
333 | { |
---|
334 | if( a->gc ) |
---|
335 | { |
---|
336 | account_off( irc, a ); |
---|
337 | } |
---|
338 | else if( a->reconnect ) |
---|
339 | { |
---|
340 | cancel_auto_reconnect( a ); |
---|
341 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
342 | } |
---|
343 | else |
---|
344 | { |
---|
345 | irc_usermsg( irc, "Account already offline" ); |
---|
346 | return; |
---|
347 | } |
---|
348 | } |
---|
349 | else |
---|
350 | { |
---|
351 | irc_usermsg( irc, "Invalid account" ); |
---|
352 | return; |
---|
353 | } |
---|
354 | } |
---|
355 | else |
---|
356 | { |
---|
357 | irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] ); |
---|
358 | } |
---|
359 | } |
---|
360 | |
---|
361 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
362 | { |
---|
363 | account_t *a; |
---|
364 | int add_for_real = 1; |
---|
365 | |
---|
366 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
367 | { |
---|
368 | add_for_real = 0; |
---|
369 | cmd ++; /* So evil... :-D */ |
---|
370 | } |
---|
371 | |
---|
372 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
373 | { |
---|
374 | irc_usermsg( irc, "Invalid account" ); |
---|
375 | return; |
---|
376 | } |
---|
377 | else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
378 | { |
---|
379 | irc_usermsg( irc, "That account is not on-line" ); |
---|
380 | return; |
---|
381 | } |
---|
382 | |
---|
383 | if( cmd[3] ) |
---|
384 | { |
---|
385 | if( !nick_ok( cmd[3] ) ) |
---|
386 | { |
---|
387 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
388 | return; |
---|
389 | } |
---|
390 | else if( user_find( irc, cmd[3] ) ) |
---|
391 | { |
---|
392 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
393 | return; |
---|
394 | } |
---|
395 | else |
---|
396 | { |
---|
397 | nick_set( irc, cmd[2], a->gc->prpl, cmd[3] ); |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | /* By making this optional, you can talk to people without having to |
---|
402 | add them to your *real* (server-side) contact list. */ |
---|
403 | if( add_for_real ) |
---|
404 | a->gc->prpl->add_buddy( a->gc, cmd[2] ); |
---|
405 | |
---|
406 | add_buddy( a->gc, NULL, cmd[2], cmd[2] ); |
---|
407 | |
---|
408 | irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->gc, cmd[2] )->nick ); |
---|
409 | } |
---|
410 | |
---|
411 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
412 | { |
---|
413 | struct gaim_connection *gc; |
---|
414 | account_t *a; |
---|
415 | |
---|
416 | if( !cmd[2] ) |
---|
417 | { |
---|
418 | user_t *u = user_find( irc, cmd[1] ); |
---|
419 | if( !u || !u->gc ) |
---|
420 | { |
---|
421 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
422 | return; |
---|
423 | } |
---|
424 | gc = u->gc; |
---|
425 | cmd[2] = u->handle; |
---|
426 | } |
---|
427 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
428 | { |
---|
429 | irc_usermsg( irc, "Invalid account" ); |
---|
430 | return; |
---|
431 | } |
---|
432 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
433 | { |
---|
434 | irc_usermsg( irc, "That account is not on-line" ); |
---|
435 | return; |
---|
436 | } |
---|
437 | |
---|
438 | if( !gc->prpl->get_info ) |
---|
439 | { |
---|
440 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
441 | } |
---|
442 | else |
---|
443 | { |
---|
444 | gc->prpl->get_info( gc, cmd[2] ); |
---|
445 | } |
---|
446 | } |
---|
447 | |
---|
448 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
449 | { |
---|
450 | user_t *u; |
---|
451 | |
---|
452 | if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
453 | { |
---|
454 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
455 | } |
---|
456 | else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) |
---|
457 | { |
---|
458 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
459 | } |
---|
460 | else if( !nick_ok( cmd[2] ) ) |
---|
461 | { |
---|
462 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
463 | } |
---|
464 | else if( !( u = user_find( irc, cmd[1] ) ) ) |
---|
465 | { |
---|
466 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
467 | } |
---|
468 | else |
---|
469 | { |
---|
470 | user_rename( irc, cmd[1], cmd[2] ); |
---|
471 | irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); |
---|
472 | if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) |
---|
473 | { |
---|
474 | g_free( irc->mynick ); |
---|
475 | irc->mynick = g_strdup( cmd[2] ); |
---|
476 | } |
---|
477 | else if( u->send_handler == buddy_send_handler ) |
---|
478 | { |
---|
479 | nick_set( irc, u->handle, u->gc->prpl, cmd[2] ); |
---|
480 | } |
---|
481 | |
---|
482 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
487 | { |
---|
488 | user_t *u; |
---|
489 | char *s; |
---|
490 | |
---|
491 | if( !( u = user_find( irc, cmd[1] ) ) || !u->gc ) |
---|
492 | { |
---|
493 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
494 | return; |
---|
495 | } |
---|
496 | s = g_strdup( u->handle ); |
---|
497 | |
---|
498 | u->gc->prpl->remove_buddy( u->gc, u->handle, NULL ); |
---|
499 | user_del( irc, cmd[1] ); |
---|
500 | nick_del( irc, cmd[1] ); |
---|
501 | |
---|
502 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
503 | g_free( s ); |
---|
504 | |
---|
505 | return; |
---|
506 | } |
---|
507 | |
---|
508 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
509 | { |
---|
510 | struct gaim_connection *gc; |
---|
511 | account_t *a; |
---|
512 | |
---|
513 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->gc ) |
---|
514 | { |
---|
515 | char *format; |
---|
516 | GSList *l; |
---|
517 | |
---|
518 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
519 | format = "%s\t%s"; |
---|
520 | else |
---|
521 | format = "%-32.32s %-16.16s"; |
---|
522 | |
---|
523 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
524 | for( l = a->gc->deny; l; l = l->next ) |
---|
525 | { |
---|
526 | user_t *u = user_findhandle( a->gc, l->data ); |
---|
527 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
528 | } |
---|
529 | irc_usermsg( irc, "End of list." ); |
---|
530 | |
---|
531 | return; |
---|
532 | } |
---|
533 | else if( !cmd[2] ) |
---|
534 | { |
---|
535 | user_t *u = user_find( irc, cmd[1] ); |
---|
536 | if( !u || !u->gc ) |
---|
537 | { |
---|
538 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
539 | return; |
---|
540 | } |
---|
541 | gc = u->gc; |
---|
542 | cmd[2] = u->handle; |
---|
543 | } |
---|
544 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
545 | { |
---|
546 | irc_usermsg( irc, "Invalid account" ); |
---|
547 | return; |
---|
548 | } |
---|
549 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
550 | { |
---|
551 | irc_usermsg( irc, "That account is not on-line" ); |
---|
552 | return; |
---|
553 | } |
---|
554 | |
---|
555 | if( !gc->prpl->add_deny || !gc->prpl->rem_permit ) |
---|
556 | { |
---|
557 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
558 | } |
---|
559 | else |
---|
560 | { |
---|
561 | bim_rem_allow( gc, cmd[2] ); |
---|
562 | bim_add_block( gc, cmd[2] ); |
---|
563 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
564 | } |
---|
565 | } |
---|
566 | |
---|
567 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
568 | { |
---|
569 | struct gaim_connection *gc; |
---|
570 | account_t *a; |
---|
571 | |
---|
572 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->gc ) |
---|
573 | { |
---|
574 | char *format; |
---|
575 | GSList *l; |
---|
576 | |
---|
577 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
578 | format = "%s\t%s"; |
---|
579 | else |
---|
580 | format = "%-32.32s %-16.16s"; |
---|
581 | |
---|
582 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
583 | for( l = a->gc->deny; l; l = l->next ) |
---|
584 | { |
---|
585 | user_t *u = user_findhandle( a->gc, l->data ); |
---|
586 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
587 | } |
---|
588 | irc_usermsg( irc, "End of list." ); |
---|
589 | |
---|
590 | return; |
---|
591 | } |
---|
592 | else if( !cmd[2] ) |
---|
593 | { |
---|
594 | user_t *u = user_find( irc, cmd[1] ); |
---|
595 | if( !u || !u->gc ) |
---|
596 | { |
---|
597 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
598 | return; |
---|
599 | } |
---|
600 | gc = u->gc; |
---|
601 | cmd[2] = u->handle; |
---|
602 | } |
---|
603 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
604 | { |
---|
605 | irc_usermsg( irc, "Invalid account" ); |
---|
606 | return; |
---|
607 | } |
---|
608 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
609 | { |
---|
610 | irc_usermsg( irc, "That account is not on-line" ); |
---|
611 | return; |
---|
612 | } |
---|
613 | |
---|
614 | if( !gc->prpl->rem_deny || !gc->prpl->add_permit ) |
---|
615 | { |
---|
616 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
617 | } |
---|
618 | else |
---|
619 | { |
---|
620 | bim_rem_block( gc, cmd[2] ); |
---|
621 | bim_add_allow( gc, cmd[2] ); |
---|
622 | |
---|
623 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
624 | } |
---|
625 | } |
---|
626 | |
---|
627 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
628 | { |
---|
629 | query_t *q = NULL; |
---|
630 | int numq = 0; |
---|
631 | |
---|
632 | if( irc->queries == NULL ) |
---|
633 | { |
---|
634 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
635 | return; |
---|
636 | } |
---|
637 | |
---|
638 | /* If there's an argument, the user seems to want to answer another question than the |
---|
639 | first/last (depending on the query_order setting) one. */ |
---|
640 | if( cmd[1] ) |
---|
641 | { |
---|
642 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
643 | { |
---|
644 | irc_usermsg( irc, "Invalid query number" ); |
---|
645 | return; |
---|
646 | } |
---|
647 | |
---|
648 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
649 | if( numq == 0 ) |
---|
650 | break; |
---|
651 | |
---|
652 | if( !q ) |
---|
653 | { |
---|
654 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
655 | return; |
---|
656 | } |
---|
657 | } |
---|
658 | |
---|
659 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
660 | query_answer( irc, q, 1 ); |
---|
661 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
662 | query_answer( irc, q, 0 ); |
---|
663 | } |
---|
664 | |
---|
665 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
666 | { |
---|
667 | if( cmd[1] && cmd[2] ) |
---|
668 | { |
---|
669 | set_setstr( irc, cmd[1], cmd[2] ); |
---|
670 | |
---|
671 | if( ( strcmp( cmd[2], "=" ) ) == 0 && cmd[3] ) |
---|
672 | irc_usermsg( irc, "Warning: Correct syntax: \002set <variable> <value>\002 (without =)" ); |
---|
673 | } |
---|
674 | if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
675 | { |
---|
676 | char *s = set_getstr( irc, cmd[1] ); |
---|
677 | if( s ) |
---|
678 | irc_usermsg( irc, "%s = `%s'", cmd[1], s ); |
---|
679 | } |
---|
680 | else |
---|
681 | { |
---|
682 | set_t *s = irc->set; |
---|
683 | while( s ) |
---|
684 | { |
---|
685 | if( s->value || s->def ) |
---|
686 | irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def ); |
---|
687 | s = s->next; |
---|
688 | } |
---|
689 | } |
---|
690 | } |
---|
691 | |
---|
692 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
693 | { |
---|
694 | if( storage_save( irc, TRUE ) == STORAGE_OK ) |
---|
695 | irc_usermsg( irc, "Configuration saved" ); |
---|
696 | else |
---|
697 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
698 | } |
---|
699 | |
---|
700 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
701 | { |
---|
702 | int online = 0, away = 0, offline = 0; |
---|
703 | user_t *u; |
---|
704 | char s[256]; |
---|
705 | char *format; |
---|
706 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
707 | |
---|
708 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
709 | online = offline = away = 1; |
---|
710 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
711 | offline = 1; |
---|
712 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
713 | away = 1; |
---|
714 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
715 | online = 1; |
---|
716 | else |
---|
717 | online = away = 1; |
---|
718 | |
---|
719 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
720 | format = "%s\t%s\t%s"; |
---|
721 | else |
---|
722 | format = "%-16.16s %-40.40s %s"; |
---|
723 | |
---|
724 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
725 | |
---|
726 | for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away ) |
---|
727 | { |
---|
728 | if( online == 1 ) |
---|
729 | { |
---|
730 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name ); |
---|
731 | irc_usermsg( irc, format, u->nick, s, "Online" ); |
---|
732 | } |
---|
733 | |
---|
734 | n_online ++; |
---|
735 | } |
---|
736 | |
---|
737 | for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away ) |
---|
738 | { |
---|
739 | if( away == 1 ) |
---|
740 | { |
---|
741 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name ); |
---|
742 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
743 | } |
---|
744 | n_away ++; |
---|
745 | } |
---|
746 | |
---|
747 | for( u = irc->users; u; u = u->next ) if( u->gc && !u->online ) |
---|
748 | { |
---|
749 | if( offline == 1 ) |
---|
750 | { |
---|
751 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name ); |
---|
752 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
753 | } |
---|
754 | n_offline ++; |
---|
755 | } |
---|
756 | |
---|
757 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
758 | } |
---|
759 | |
---|
760 | static void cmd_nick( irc_t *irc, char **cmd ) |
---|
761 | { |
---|
762 | account_t *a; |
---|
763 | |
---|
764 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
765 | { |
---|
766 | irc_usermsg( irc, "Invalid account"); |
---|
767 | } |
---|
768 | else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
769 | { |
---|
770 | irc_usermsg( irc, "That account is not on-line" ); |
---|
771 | } |
---|
772 | else if ( !cmd[2] ) |
---|
773 | { |
---|
774 | irc_usermsg( irc, "Your name is `%s'" , a->gc->displayname ? a->gc->displayname : "NULL" ); |
---|
775 | } |
---|
776 | else if ( !a->gc->prpl->set_info ) |
---|
777 | { |
---|
778 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
779 | } |
---|
780 | else |
---|
781 | { |
---|
782 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
783 | |
---|
784 | a->gc->prpl->set_info( a->gc, cmd[2] ); |
---|
785 | } |
---|
786 | } |
---|
787 | |
---|
788 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
789 | { |
---|
790 | query_t *q = irc->queries; |
---|
791 | int num; |
---|
792 | |
---|
793 | if( !q ) |
---|
794 | { |
---|
795 | irc_usermsg( irc, "There are no pending questions." ); |
---|
796 | return; |
---|
797 | } |
---|
798 | |
---|
799 | irc_usermsg( irc, "Pending queries:" ); |
---|
800 | |
---|
801 | for( num = 0; q; q = q->next, num ++ ) |
---|
802 | if( q->gc ) /* Not necessary yet, but it might come later */ |
---|
803 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->gc->prpl->name, q->gc->username, q->question ); |
---|
804 | else |
---|
805 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
806 | } |
---|
807 | |
---|
808 | static void cmd_import_buddies( irc_t *irc, char **cmd ) |
---|
809 | { |
---|
810 | struct gaim_connection *gc; |
---|
811 | account_t *a; |
---|
812 | nick_t *n; |
---|
813 | |
---|
814 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
815 | { |
---|
816 | irc_usermsg( irc, "Invalid account" ); |
---|
817 | return; |
---|
818 | } |
---|
819 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
820 | { |
---|
821 | irc_usermsg( irc, "That account is not on-line" ); |
---|
822 | return; |
---|
823 | } |
---|
824 | |
---|
825 | if( cmd[2] ) |
---|
826 | { |
---|
827 | if( g_strcasecmp( cmd[2], "clear" ) == 0 ) |
---|
828 | { |
---|
829 | user_t *u; |
---|
830 | |
---|
831 | for( u = irc->users; u; u = u->next ) |
---|
832 | if( u->gc == gc ) |
---|
833 | { |
---|
834 | u->gc->prpl->remove_buddy( u->gc, u->handle, NULL ); |
---|
835 | user_del( irc, u->nick ); |
---|
836 | } |
---|
837 | |
---|
838 | irc_usermsg( irc, "Old buddy list cleared." ); |
---|
839 | } |
---|
840 | else |
---|
841 | { |
---|
842 | irc_usermsg( irc, "Invalid argument: %s", cmd[2] ); |
---|
843 | return; |
---|
844 | } |
---|
845 | } |
---|
846 | |
---|
847 | for( n = gc->irc->nicks; n; n = n->next ) |
---|
848 | { |
---|
849 | if( n->proto == gc->prpl && !user_findhandle( gc, n->handle ) ) |
---|
850 | { |
---|
851 | gc->prpl->add_buddy( gc, n->handle ); |
---|
852 | add_buddy( gc, NULL, n->handle, NULL ); |
---|
853 | } |
---|
854 | } |
---|
855 | |
---|
856 | irc_usermsg( irc, "Sent all add requests. Please wait for a while, the server needs some time to handle all the adds." ); |
---|
857 | } |
---|
858 | |
---|
859 | const command_t commands[] = { |
---|
860 | { "help", 0, cmd_help, 0 }, |
---|
861 | { "identify", 1, cmd_identify, 0 }, |
---|
862 | { "register", 1, cmd_register, 0 }, |
---|
863 | { "drop", 1, cmd_drop, 0 }, |
---|
864 | { "account", 1, cmd_account, 0 }, |
---|
865 | { "add", 2, cmd_add, 0 }, |
---|
866 | { "info", 1, cmd_info, 0 }, |
---|
867 | { "rename", 2, cmd_rename, 0 }, |
---|
868 | { "remove", 1, cmd_remove, 0 }, |
---|
869 | { "block", 1, cmd_block, 0 }, |
---|
870 | { "allow", 1, cmd_allow, 0 }, |
---|
871 | { "save", 0, cmd_save, 0 }, |
---|
872 | { "set", 0, cmd_set, 0 }, |
---|
873 | { "yes", 0, cmd_yesno, 0 }, |
---|
874 | { "no", 0, cmd_yesno, 0 }, |
---|
875 | { "blist", 0, cmd_blist, 0 }, |
---|
876 | { "nick", 1, cmd_nick, 0 }, |
---|
877 | { "import_buddies", 1, cmd_import_buddies, 0 }, |
---|
878 | { "qlist", 0, cmd_qlist, 0 }, |
---|
879 | { NULL } |
---|
880 | }; |
---|