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