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