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