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