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 | struct prpl *prpl; |
---|
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 | prpl = find_protocol(cmd[2]); |
---|
196 | |
---|
197 | if( prpl == NULL ) |
---|
198 | { |
---|
199 | irc_usermsg( irc, "Unknown protocol" ); |
---|
200 | return( 0 ); |
---|
201 | } |
---|
202 | |
---|
203 | a = account_add( irc, prpl, cmd[3], cmd[4] ); |
---|
204 | |
---|
205 | if( cmd[5] ) |
---|
206 | a->server = g_strdup( cmd[5] ); |
---|
207 | |
---|
208 | irc_usermsg( irc, "Account successfully added" ); |
---|
209 | } |
---|
210 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
211 | { |
---|
212 | if( !cmd[2] ) |
---|
213 | { |
---|
214 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
215 | } |
---|
216 | else if( !( a = account_get( irc, cmd[2] ) ) ) |
---|
217 | { |
---|
218 | irc_usermsg( irc, "Invalid account" ); |
---|
219 | } |
---|
220 | else if( a->gc ) |
---|
221 | { |
---|
222 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
223 | } |
---|
224 | else |
---|
225 | { |
---|
226 | account_del( irc, a ); |
---|
227 | irc_usermsg( irc, "Account deleted" ); |
---|
228 | } |
---|
229 | } |
---|
230 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
231 | { |
---|
232 | int i = 0; |
---|
233 | |
---|
234 | for( a = irc->accounts; a; a = a->next ) |
---|
235 | { |
---|
236 | char *con; |
---|
237 | |
---|
238 | if( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) |
---|
239 | con = " (connected)"; |
---|
240 | else if( a->gc ) |
---|
241 | con = " (connecting)"; |
---|
242 | else if( a->reconnect ) |
---|
243 | con = " (awaiting reconnect)"; |
---|
244 | else |
---|
245 | con = ""; |
---|
246 | |
---|
247 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
248 | |
---|
249 | i ++; |
---|
250 | } |
---|
251 | irc_usermsg( irc, "End of account list" ); |
---|
252 | } |
---|
253 | else if( g_strcasecmp( cmd[1], "on" ) == 0 ) |
---|
254 | { |
---|
255 | if( cmd[2] ) |
---|
256 | { |
---|
257 | if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
258 | { |
---|
259 | if( a->gc ) |
---|
260 | { |
---|
261 | irc_usermsg( irc, "Account already online" ); |
---|
262 | return( 0 ); |
---|
263 | } |
---|
264 | else |
---|
265 | { |
---|
266 | account_on( irc, a ); |
---|
267 | } |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | irc_usermsg( irc, "Invalid account" ); |
---|
272 | return( 0 ); |
---|
273 | } |
---|
274 | } |
---|
275 | else |
---|
276 | { |
---|
277 | if ( irc->accounts ) { |
---|
278 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
279 | |
---|
280 | for( a = irc->accounts; a; a = a->next ) |
---|
281 | if( !a->gc ) |
---|
282 | account_on( irc, a ); |
---|
283 | } |
---|
284 | else |
---|
285 | { |
---|
286 | irc_usermsg( irc, "No accounts known. Use 'account add' to add one." ); |
---|
287 | } |
---|
288 | } |
---|
289 | } |
---|
290 | else if( g_strcasecmp( cmd[1], "off" ) == 0 ) |
---|
291 | { |
---|
292 | if( !cmd[2] ) |
---|
293 | { |
---|
294 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
295 | |
---|
296 | for( a = irc->accounts; a; a = a->next ) |
---|
297 | { |
---|
298 | if( a->gc ) |
---|
299 | account_off( irc, a ); |
---|
300 | else if( a->reconnect ) |
---|
301 | cancel_auto_reconnect( a ); |
---|
302 | } |
---|
303 | } |
---|
304 | else if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
305 | { |
---|
306 | if( a->gc ) |
---|
307 | { |
---|
308 | account_off( irc, a ); |
---|
309 | } |
---|
310 | else if( a->reconnect ) |
---|
311 | { |
---|
312 | cancel_auto_reconnect( a ); |
---|
313 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
314 | } |
---|
315 | else |
---|
316 | { |
---|
317 | irc_usermsg( irc, "Account already offline" ); |
---|
318 | return( 0 ); |
---|
319 | } |
---|
320 | } |
---|
321 | else |
---|
322 | { |
---|
323 | irc_usermsg( irc, "Invalid account" ); |
---|
324 | return( 0 ); |
---|
325 | } |
---|
326 | } |
---|
327 | else |
---|
328 | { |
---|
329 | irc_usermsg( irc, "Unknown command: account %s. Please use help commands to get a list of available commands.", cmd[1] ); |
---|
330 | } |
---|
331 | |
---|
332 | return( 1 ); |
---|
333 | } |
---|
334 | |
---|
335 | int cmd_add( irc_t *irc, char **cmd ) |
---|
336 | { |
---|
337 | account_t *a; |
---|
338 | |
---|
339 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
340 | { |
---|
341 | irc_usermsg( irc, "Invalid account" ); |
---|
342 | return( 1 ); |
---|
343 | } |
---|
344 | else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
345 | { |
---|
346 | irc_usermsg( irc, "That account is not on-line" ); |
---|
347 | return( 1 ); |
---|
348 | } |
---|
349 | |
---|
350 | if( cmd[3] ) |
---|
351 | { |
---|
352 | if( !nick_ok( cmd[3] ) ) |
---|
353 | { |
---|
354 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
355 | return( 0 ); |
---|
356 | } |
---|
357 | else if( user_find( irc, cmd[3] ) ) |
---|
358 | { |
---|
359 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
360 | return( 0 ); |
---|
361 | } |
---|
362 | else |
---|
363 | { |
---|
364 | nick_set( irc, cmd[2], a->gc->prpl, cmd[3] ); |
---|
365 | } |
---|
366 | } |
---|
367 | a->gc->prpl->add_buddy( a->gc, cmd[2] ); |
---|
368 | add_buddy( a->gc, NULL, cmd[2], cmd[2] ); |
---|
369 | |
---|
370 | irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->gc, cmd[2] )->nick ); |
---|
371 | |
---|
372 | return( 0 ); |
---|
373 | } |
---|
374 | |
---|
375 | int cmd_info( irc_t *irc, char **cmd ) |
---|
376 | { |
---|
377 | struct gaim_connection *gc; |
---|
378 | account_t *a; |
---|
379 | |
---|
380 | if( !cmd[2] ) |
---|
381 | { |
---|
382 | user_t *u = user_find( irc, cmd[1] ); |
---|
383 | if( !u || !u->gc ) |
---|
384 | { |
---|
385 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
386 | return( 1 ); |
---|
387 | } |
---|
388 | gc = u->gc; |
---|
389 | cmd[2] = u->handle; |
---|
390 | } |
---|
391 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
392 | { |
---|
393 | irc_usermsg( irc, "Invalid account" ); |
---|
394 | return( 1 ); |
---|
395 | } |
---|
396 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
397 | { |
---|
398 | irc_usermsg( irc, "That account is not on-line" ); |
---|
399 | return( 1 ); |
---|
400 | } |
---|
401 | |
---|
402 | if( !gc->prpl->get_info ) |
---|
403 | { |
---|
404 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
405 | return( 1 ); |
---|
406 | } |
---|
407 | gc->prpl->get_info( gc, cmd[2] ); |
---|
408 | |
---|
409 | return( 0 ); |
---|
410 | } |
---|
411 | |
---|
412 | int cmd_rename( irc_t *irc, char **cmd ) |
---|
413 | { |
---|
414 | user_t *u; |
---|
415 | |
---|
416 | if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
417 | { |
---|
418 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
419 | return( 1 ); |
---|
420 | } |
---|
421 | if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) |
---|
422 | { |
---|
423 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
424 | return( 1 ); |
---|
425 | } |
---|
426 | if( !nick_ok( cmd[2] ) ) |
---|
427 | { |
---|
428 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
429 | return( 1 ); |
---|
430 | } |
---|
431 | if( !( u = user_find( irc, cmd[1] ) ) ) |
---|
432 | { |
---|
433 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
434 | return( 1 ); |
---|
435 | } |
---|
436 | user_rename( irc, cmd[1], cmd[2] ); |
---|
437 | irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); |
---|
438 | if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) |
---|
439 | { |
---|
440 | g_free( irc->mynick ); |
---|
441 | irc->mynick = g_strdup( cmd[2] ); |
---|
442 | } |
---|
443 | else if( u->send_handler == buddy_send_handler ) |
---|
444 | { |
---|
445 | nick_set( irc, u->handle, u->gc->prpl, cmd[2] ); |
---|
446 | } |
---|
447 | |
---|
448 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
449 | |
---|
450 | return( 0 ); |
---|
451 | } |
---|
452 | |
---|
453 | int cmd_remove( irc_t *irc, char **cmd ) |
---|
454 | { |
---|
455 | user_t *u; |
---|
456 | char *s; |
---|
457 | |
---|
458 | if( !( u = user_find( irc, cmd[1] ) ) || !u->gc ) |
---|
459 | { |
---|
460 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
461 | return( 1 ); |
---|
462 | } |
---|
463 | s = g_strdup( u->handle ); |
---|
464 | |
---|
465 | u->gc->prpl->remove_buddy( u->gc, u->handle, NULL ); |
---|
466 | user_del( irc, cmd[1] ); |
---|
467 | nick_del( irc, cmd[1] ); |
---|
468 | |
---|
469 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
470 | g_free( s ); |
---|
471 | |
---|
472 | return( 0 ); |
---|
473 | } |
---|
474 | |
---|
475 | int cmd_block( irc_t *irc, char **cmd ) |
---|
476 | { |
---|
477 | struct gaim_connection *gc; |
---|
478 | account_t *a; |
---|
479 | |
---|
480 | if( !cmd[2] ) |
---|
481 | { |
---|
482 | user_t *u = user_find( irc, cmd[1] ); |
---|
483 | if( !u || !u->gc ) |
---|
484 | { |
---|
485 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
486 | return( 1 ); |
---|
487 | } |
---|
488 | gc = u->gc; |
---|
489 | cmd[2] = u->handle; |
---|
490 | } |
---|
491 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
492 | { |
---|
493 | irc_usermsg( irc, "Invalid account" ); |
---|
494 | return( 1 ); |
---|
495 | } |
---|
496 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
497 | { |
---|
498 | irc_usermsg( irc, "That account is not on-line" ); |
---|
499 | return( 1 ); |
---|
500 | } |
---|
501 | |
---|
502 | if( !gc->prpl->add_deny || !gc->prpl->rem_permit ) |
---|
503 | { |
---|
504 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
505 | } |
---|
506 | else |
---|
507 | { |
---|
508 | gc->prpl->rem_permit( gc, cmd[2] ); |
---|
509 | gc->prpl->add_deny( gc, cmd[2] ); |
---|
510 | irc_usermsg( irc, "Buddy `%s' moved from your permit- to your deny-list", cmd[2] ); |
---|
511 | } |
---|
512 | |
---|
513 | return( 0 ); |
---|
514 | } |
---|
515 | |
---|
516 | int cmd_allow( irc_t *irc, char **cmd ) |
---|
517 | { |
---|
518 | struct gaim_connection *gc; |
---|
519 | account_t *a; |
---|
520 | |
---|
521 | if( !cmd[2] ) |
---|
522 | { |
---|
523 | user_t *u = user_find( irc, cmd[1] ); |
---|
524 | if( !u || !u->gc ) |
---|
525 | { |
---|
526 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
527 | return( 1 ); |
---|
528 | } |
---|
529 | gc = u->gc; |
---|
530 | cmd[2] = u->handle; |
---|
531 | } |
---|
532 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
533 | { |
---|
534 | irc_usermsg( irc, "Invalid account" ); |
---|
535 | return( 1 ); |
---|
536 | } |
---|
537 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
538 | { |
---|
539 | irc_usermsg( irc, "That account is not on-line" ); |
---|
540 | return( 1 ); |
---|
541 | } |
---|
542 | |
---|
543 | if( !gc->prpl->rem_deny || !gc->prpl->add_permit ) |
---|
544 | { |
---|
545 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
546 | } |
---|
547 | else |
---|
548 | { |
---|
549 | gc->prpl->rem_deny( gc, cmd[2] ); |
---|
550 | gc->prpl->add_permit( gc, cmd[2] ); |
---|
551 | |
---|
552 | irc_usermsg( irc, "Buddy `%s' moved from your deny- to your permit-list", cmd[2] ); |
---|
553 | } |
---|
554 | |
---|
555 | return( 0 ); |
---|
556 | } |
---|
557 | |
---|
558 | int cmd_yesno( irc_t *irc, char **cmd ) |
---|
559 | { |
---|
560 | query_t *q = NULL; |
---|
561 | int numq = 0; |
---|
562 | |
---|
563 | if( irc->queries == NULL ) |
---|
564 | { |
---|
565 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
566 | return( 0 ); |
---|
567 | } |
---|
568 | |
---|
569 | /* If there's an argument, the user seems to want to answer another question than the |
---|
570 | first/last (depending on the query_order setting) one. */ |
---|
571 | if( cmd[1] ) |
---|
572 | { |
---|
573 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
574 | { |
---|
575 | irc_usermsg( irc, "Invalid query number" ); |
---|
576 | return( 0 ); |
---|
577 | } |
---|
578 | |
---|
579 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
580 | if( numq == 0 ) |
---|
581 | break; |
---|
582 | |
---|
583 | if( !q ) |
---|
584 | { |
---|
585 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
586 | return( 0 ); |
---|
587 | } |
---|
588 | } |
---|
589 | |
---|
590 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
591 | query_answer( irc, q, 1 ); |
---|
592 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
593 | query_answer( irc, q, 0 ); |
---|
594 | |
---|
595 | return( 1 ); |
---|
596 | } |
---|
597 | |
---|
598 | int cmd_set( irc_t *irc, char **cmd ) |
---|
599 | { |
---|
600 | if( cmd[1] && cmd[2] ) |
---|
601 | { |
---|
602 | set_setstr( irc, cmd[1], cmd[2] ); |
---|
603 | } |
---|
604 | if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
605 | { |
---|
606 | char *s = set_getstr( irc, cmd[1] ); |
---|
607 | if( s ) |
---|
608 | irc_usermsg( irc, "%s = `%s'", cmd[1], s ); |
---|
609 | } |
---|
610 | else |
---|
611 | { |
---|
612 | set_t *s = irc->set; |
---|
613 | while( s ) |
---|
614 | { |
---|
615 | if( s->value || s->def ) |
---|
616 | irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def ); |
---|
617 | s = s->next; |
---|
618 | } |
---|
619 | } |
---|
620 | |
---|
621 | return( 0 ); |
---|
622 | } |
---|
623 | |
---|
624 | int cmd_save( irc_t *irc, char **cmd ) |
---|
625 | { |
---|
626 | if( bitlbee_save( irc ) ) |
---|
627 | irc_usermsg( irc, "Configuration saved" ); |
---|
628 | else |
---|
629 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
630 | |
---|
631 | return( 0 ); |
---|
632 | } |
---|
633 | |
---|
634 | int cmd_blist( irc_t *irc, char **cmd ) |
---|
635 | { |
---|
636 | int online = 0, away = 0, offline = 0; |
---|
637 | user_t *u; |
---|
638 | char s[64]; |
---|
639 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
640 | |
---|
641 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
642 | online = offline = away = 1; |
---|
643 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
644 | offline = 1; |
---|
645 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
646 | away = 1; |
---|
647 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
648 | online = 1; |
---|
649 | else |
---|
650 | online = away = 1; |
---|
651 | |
---|
652 | irc_usermsg( irc, "%-16.16s %-40.40s %s", "Nick", "User/Host/Network", "Status" ); |
---|
653 | |
---|
654 | if( online == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away ) |
---|
655 | { |
---|
656 | g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name ); |
---|
657 | irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, "Online" ); |
---|
658 | n_online ++; |
---|
659 | } |
---|
660 | |
---|
661 | if( away == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away ) |
---|
662 | { |
---|
663 | g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name ); |
---|
664 | irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, u->away ); |
---|
665 | n_away ++; |
---|
666 | } |
---|
667 | |
---|
668 | if( offline == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && !u->online ) |
---|
669 | { |
---|
670 | g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name ); |
---|
671 | irc_usermsg( irc, "%-16.16s %-40.40s %s", u->nick, s, "Offline" ); |
---|
672 | n_offline ++; |
---|
673 | } |
---|
674 | |
---|
675 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
676 | |
---|
677 | return( 0 ); |
---|
678 | } |
---|
679 | |
---|
680 | int cmd_nick( irc_t *irc, char **cmd ) |
---|
681 | { |
---|
682 | account_t *a; |
---|
683 | |
---|
684 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
685 | { |
---|
686 | irc_usermsg( irc, "Invalid account"); |
---|
687 | } |
---|
688 | else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
689 | { |
---|
690 | irc_usermsg( irc, "That account is not on-line" ); |
---|
691 | } |
---|
692 | else if ( !cmd[2] ) |
---|
693 | { |
---|
694 | irc_usermsg( irc, "Your name is `%s'" , a->gc->displayname ? a->gc->displayname : "NULL" ); |
---|
695 | } |
---|
696 | else if ( !a->gc->prpl->set_info ) |
---|
697 | { |
---|
698 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
699 | } |
---|
700 | else |
---|
701 | { |
---|
702 | char utf8[1024]; |
---|
703 | |
---|
704 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
705 | |
---|
706 | if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 && |
---|
707 | do_iconv( set_getstr( irc, "charset" ), "UTF-8", cmd[2], utf8, 0, 1024 ) != -1 ) |
---|
708 | a->gc->prpl->set_info( a->gc, utf8 ); |
---|
709 | else |
---|
710 | a->gc->prpl->set_info( a->gc, cmd[2] ); |
---|
711 | } |
---|
712 | |
---|
713 | return( 1 ); |
---|
714 | } |
---|
715 | |
---|
716 | int cmd_qlist( irc_t *irc, char **cmd ) |
---|
717 | { |
---|
718 | query_t *q = irc->queries; |
---|
719 | int num; |
---|
720 | |
---|
721 | if( !q ) |
---|
722 | { |
---|
723 | irc_usermsg( irc, "There are no pending questions." ); |
---|
724 | return( 0 ); |
---|
725 | } |
---|
726 | |
---|
727 | irc_usermsg( irc, "Pending queries:" ); |
---|
728 | |
---|
729 | for( num = 0; q; q = q->next, num ++ ) |
---|
730 | irc_usermsg( irc, "%d, %s", num, q->question ); |
---|
731 | |
---|
732 | return( 0 ); |
---|
733 | } |
---|
734 | |
---|
735 | int cmd_import_buddies( irc_t *irc, char **cmd ) |
---|
736 | { |
---|
737 | struct gaim_connection *gc; |
---|
738 | account_t *a; |
---|
739 | nick_t *n; |
---|
740 | |
---|
741 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
742 | { |
---|
743 | irc_usermsg( irc, "Invalid account" ); |
---|
744 | return( 0 ); |
---|
745 | } |
---|
746 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
747 | { |
---|
748 | irc_usermsg( irc, "That account is not on-line" ); |
---|
749 | return( 0 ); |
---|
750 | } |
---|
751 | |
---|
752 | if( cmd[2] ) |
---|
753 | { |
---|
754 | if( g_strcasecmp( cmd[2], "clear" ) == 0 ) |
---|
755 | { |
---|
756 | user_t *u; |
---|
757 | |
---|
758 | for( u = irc->users; u; u = u->next ) |
---|
759 | if( u->gc == gc ) |
---|
760 | { |
---|
761 | u->gc->prpl->remove_buddy( u->gc, u->handle, NULL ); |
---|
762 | user_del( irc, u->nick ); |
---|
763 | } |
---|
764 | |
---|
765 | irc_usermsg( irc, "Old buddy list cleared." ); |
---|
766 | } |
---|
767 | else |
---|
768 | { |
---|
769 | irc_usermsg( irc, "Invalid argument: %s", cmd[2] ); |
---|
770 | return( 0 ); |
---|
771 | } |
---|
772 | } |
---|
773 | |
---|
774 | for( n = gc->irc->nicks; n; n = n->next ) |
---|
775 | { |
---|
776 | if( n->proto == gc->prpl && !user_findhandle( gc, n->handle ) ) |
---|
777 | { |
---|
778 | gc->prpl->add_buddy( gc, n->handle ); |
---|
779 | add_buddy( gc, NULL, n->handle, NULL ); |
---|
780 | } |
---|
781 | } |
---|
782 | |
---|
783 | irc_usermsg( irc, "Sent all add requests. Please wait for a while, the server needs some time to handle all the adds." ); |
---|
784 | |
---|
785 | return( 0 ); |
---|
786 | } |
---|
787 | |
---|
788 | int cmd_dump( irc_t *irc, char **cmd ) { |
---|
789 | write_io_activity(); |
---|
790 | irc_usermsg(irc, "Wrote GIO activity log to disk."); |
---|
791 | |
---|
792 | return( 0 ); |
---|
793 | } |
---|