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