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