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 | if( g_slist_find( irc->users, iu ) ) |
---|
647 | bee_user_free( irc->b, bu ); |
---|
648 | |
---|
649 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
650 | g_free( s ); |
---|
651 | |
---|
652 | return; |
---|
653 | } |
---|
654 | |
---|
655 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
656 | { |
---|
657 | struct im_connection *ic; |
---|
658 | account_t *a; |
---|
659 | |
---|
660 | if( !cmd[2] ) |
---|
661 | { |
---|
662 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
663 | if( !iu || !iu->bu ) |
---|
664 | { |
---|
665 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
666 | return; |
---|
667 | } |
---|
668 | ic = iu->bu->ic; |
---|
669 | cmd[2] = iu->bu->handle; |
---|
670 | } |
---|
671 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
672 | { |
---|
673 | irc_usermsg( irc, "Invalid account" ); |
---|
674 | return; |
---|
675 | } |
---|
676 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
677 | { |
---|
678 | irc_usermsg( irc, "That account is not on-line" ); |
---|
679 | return; |
---|
680 | } |
---|
681 | |
---|
682 | if( !ic->acc->prpl->get_info ) |
---|
683 | { |
---|
684 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
685 | } |
---|
686 | else |
---|
687 | { |
---|
688 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
689 | } |
---|
690 | } |
---|
691 | |
---|
692 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
693 | { |
---|
694 | irc_user_t *iu, *old; |
---|
695 | |
---|
696 | iu = irc_user_by_name( irc, cmd[1] ); |
---|
697 | |
---|
698 | if( iu == NULL ) |
---|
699 | { |
---|
700 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
701 | } |
---|
702 | else if( iu == irc->user ) |
---|
703 | { |
---|
704 | irc_usermsg( irc, "Use /nick to change your own nickname" ); |
---|
705 | } |
---|
706 | else if( !nick_ok( cmd[2] ) ) |
---|
707 | { |
---|
708 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
709 | } |
---|
710 | else if( ( old = irc_user_by_name( irc, cmd[2] ) ) && old != iu ) |
---|
711 | { |
---|
712 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
713 | } |
---|
714 | else |
---|
715 | { |
---|
716 | if( !irc_user_set_nick( iu, cmd[2] ) ) |
---|
717 | { |
---|
718 | irc_usermsg( irc, "Error while changing nick" ); |
---|
719 | return; |
---|
720 | } |
---|
721 | |
---|
722 | if( iu == irc->root ) |
---|
723 | { |
---|
724 | /* If we're called internally (user did "set root_nick"), |
---|
725 | let's not go O(INF). :-) */ |
---|
726 | if( strcmp( cmd[0], "set_rename" ) != 0 ) |
---|
727 | set_setstr( &irc->b->set, "root_nick", cmd[2] ); |
---|
728 | } |
---|
729 | else if( iu->bu ) |
---|
730 | { |
---|
731 | nick_set( iu->bu, cmd[2] ); |
---|
732 | } |
---|
733 | |
---|
734 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
735 | } |
---|
736 | } |
---|
737 | |
---|
738 | char *set_eval_root_nick( set_t *set, char *new_nick ) |
---|
739 | { |
---|
740 | irc_t *irc = set->data; |
---|
741 | |
---|
742 | if( strcmp( irc->root->nick, new_nick ) != 0 ) |
---|
743 | { |
---|
744 | char *cmd[] = { "set_rename", irc->root->nick, new_nick, NULL }; |
---|
745 | |
---|
746 | cmd_rename( irc, cmd ); |
---|
747 | } |
---|
748 | |
---|
749 | return strcmp( irc->root->nick, new_nick ) == 0 ? new_nick : SET_INVALID; |
---|
750 | } |
---|
751 | |
---|
752 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
753 | { |
---|
754 | struct im_connection *ic; |
---|
755 | account_t *a; |
---|
756 | |
---|
757 | if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) |
---|
758 | { |
---|
759 | char *format; |
---|
760 | GSList *l; |
---|
761 | |
---|
762 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
763 | format = "%s\t%s"; |
---|
764 | else |
---|
765 | format = "%-32.32s %-16.16s"; |
---|
766 | |
---|
767 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
768 | for( l = a->ic->deny; l; l = l->next ) |
---|
769 | { |
---|
770 | bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); |
---|
771 | irc_user_t *iu = bu ? bu->ui_data : NULL; |
---|
772 | irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); |
---|
773 | } |
---|
774 | irc_usermsg( irc, "End of list." ); |
---|
775 | |
---|
776 | return; |
---|
777 | } |
---|
778 | else if( !cmd[2] ) |
---|
779 | { |
---|
780 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
781 | if( !iu || !iu->bu ) |
---|
782 | { |
---|
783 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
784 | return; |
---|
785 | } |
---|
786 | ic = iu->bu->ic; |
---|
787 | cmd[2] = iu->bu->handle; |
---|
788 | } |
---|
789 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
790 | { |
---|
791 | irc_usermsg( irc, "Invalid account" ); |
---|
792 | return; |
---|
793 | } |
---|
794 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
795 | { |
---|
796 | irc_usermsg( irc, "That account is not on-line" ); |
---|
797 | return; |
---|
798 | } |
---|
799 | |
---|
800 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
801 | { |
---|
802 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
803 | } |
---|
804 | else |
---|
805 | { |
---|
806 | imc_rem_allow( ic, cmd[2] ); |
---|
807 | imc_add_block( ic, cmd[2] ); |
---|
808 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
809 | } |
---|
810 | } |
---|
811 | |
---|
812 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
813 | { |
---|
814 | struct im_connection *ic; |
---|
815 | account_t *a; |
---|
816 | |
---|
817 | if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) |
---|
818 | { |
---|
819 | char *format; |
---|
820 | GSList *l; |
---|
821 | |
---|
822 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
823 | format = "%s\t%s"; |
---|
824 | else |
---|
825 | format = "%-32.32s %-16.16s"; |
---|
826 | |
---|
827 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
828 | for( l = a->ic->permit; l; l = l->next ) |
---|
829 | { |
---|
830 | bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); |
---|
831 | irc_user_t *iu = bu ? bu->ui_data : NULL; |
---|
832 | irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); |
---|
833 | } |
---|
834 | irc_usermsg( irc, "End of list." ); |
---|
835 | |
---|
836 | return; |
---|
837 | } |
---|
838 | else if( !cmd[2] ) |
---|
839 | { |
---|
840 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
841 | if( !iu || !iu->bu ) |
---|
842 | { |
---|
843 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
844 | return; |
---|
845 | } |
---|
846 | ic = iu->bu->ic; |
---|
847 | cmd[2] = iu->bu->handle; |
---|
848 | } |
---|
849 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
850 | { |
---|
851 | irc_usermsg( irc, "Invalid account" ); |
---|
852 | return; |
---|
853 | } |
---|
854 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
855 | { |
---|
856 | irc_usermsg( irc, "That account is not on-line" ); |
---|
857 | return; |
---|
858 | } |
---|
859 | |
---|
860 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
861 | { |
---|
862 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
863 | } |
---|
864 | else |
---|
865 | { |
---|
866 | imc_rem_block( ic, cmd[2] ); |
---|
867 | imc_add_allow( ic, cmd[2] ); |
---|
868 | |
---|
869 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
870 | } |
---|
871 | } |
---|
872 | |
---|
873 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
874 | { |
---|
875 | query_t *q = NULL; |
---|
876 | int numq = 0; |
---|
877 | |
---|
878 | if( irc->queries == NULL ) |
---|
879 | { |
---|
880 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
881 | return; |
---|
882 | } |
---|
883 | |
---|
884 | /* If there's an argument, the user seems to want to answer another question than the |
---|
885 | first/last (depending on the query_order setting) one. */ |
---|
886 | if( cmd[1] ) |
---|
887 | { |
---|
888 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
889 | { |
---|
890 | irc_usermsg( irc, "Invalid query number" ); |
---|
891 | return; |
---|
892 | } |
---|
893 | |
---|
894 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
895 | if( numq == 0 ) |
---|
896 | break; |
---|
897 | |
---|
898 | if( !q ) |
---|
899 | { |
---|
900 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
901 | return; |
---|
902 | } |
---|
903 | } |
---|
904 | |
---|
905 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
906 | query_answer( irc, q, 1 ); |
---|
907 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
908 | query_answer( irc, q, 0 ); |
---|
909 | } |
---|
910 | |
---|
911 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
912 | { |
---|
913 | cmd_set_real( irc, cmd, &irc->b->set, NULL ); |
---|
914 | } |
---|
915 | |
---|
916 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
917 | { |
---|
918 | int online = 0, away = 0, offline = 0; |
---|
919 | GSList *l; |
---|
920 | char s[256]; |
---|
921 | char *format; |
---|
922 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
923 | |
---|
924 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
925 | online = offline = away = 1; |
---|
926 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
927 | offline = 1; |
---|
928 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
929 | away = 1; |
---|
930 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
931 | online = 1; |
---|
932 | else |
---|
933 | online = away = 1; |
---|
934 | |
---|
935 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
936 | format = "%s\t%s\t%s"; |
---|
937 | else |
---|
938 | format = "%-16.16s %-40.40s %s"; |
---|
939 | |
---|
940 | irc_usermsg( irc, format, "Nick", "Handle/Account", "Status" ); |
---|
941 | |
---|
942 | for( l = irc->users; l; l = l->next ) |
---|
943 | { |
---|
944 | irc_user_t *iu = l->data; |
---|
945 | bee_user_t *bu = iu->bu; |
---|
946 | |
---|
947 | if( !bu || ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) != BEE_USER_ONLINE ) |
---|
948 | continue; |
---|
949 | |
---|
950 | if( online == 1 ) |
---|
951 | { |
---|
952 | char st[256] = "Online"; |
---|
953 | |
---|
954 | if( bu->status_msg ) |
---|
955 | g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg ); |
---|
956 | |
---|
957 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
958 | irc_usermsg( irc, format, iu->nick, s, st ); |
---|
959 | } |
---|
960 | |
---|
961 | n_online ++; |
---|
962 | } |
---|
963 | |
---|
964 | for( l = irc->users; l; l = l->next ) |
---|
965 | { |
---|
966 | irc_user_t *iu = l->data; |
---|
967 | bee_user_t *bu = iu->bu; |
---|
968 | |
---|
969 | if( !bu || !( bu->flags & BEE_USER_ONLINE ) || !( bu->flags & BEE_USER_AWAY ) ) |
---|
970 | continue; |
---|
971 | |
---|
972 | if( away == 1 ) |
---|
973 | { |
---|
974 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
975 | irc_usermsg( irc, format, iu->nick, s, irc_user_get_away( iu ) ); |
---|
976 | } |
---|
977 | n_away ++; |
---|
978 | } |
---|
979 | |
---|
980 | for( l = irc->users; l; l = l->next ) |
---|
981 | { |
---|
982 | irc_user_t *iu = l->data; |
---|
983 | bee_user_t *bu = iu->bu; |
---|
984 | |
---|
985 | if( !bu || bu->flags & BEE_USER_ONLINE ) |
---|
986 | continue; |
---|
987 | |
---|
988 | if( offline == 1 ) |
---|
989 | { |
---|
990 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
991 | irc_usermsg( irc, format, iu->nick, s, "Offline" ); |
---|
992 | } |
---|
993 | n_offline ++; |
---|
994 | } |
---|
995 | |
---|
996 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
997 | } |
---|
998 | |
---|
999 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
1000 | { |
---|
1001 | query_t *q = irc->queries; |
---|
1002 | int num; |
---|
1003 | |
---|
1004 | if( !q ) |
---|
1005 | { |
---|
1006 | irc_usermsg( irc, "There are no pending questions." ); |
---|
1007 | return; |
---|
1008 | } |
---|
1009 | |
---|
1010 | irc_usermsg( irc, "Pending queries:" ); |
---|
1011 | |
---|
1012 | for( num = 0; q; q = q->next, num ++ ) |
---|
1013 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
1014 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
1015 | else |
---|
1016 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
1017 | } |
---|
1018 | |
---|
1019 | static void cmd_chat( irc_t *irc, char **cmd ) |
---|
1020 | { |
---|
1021 | account_t *acc; |
---|
1022 | |
---|
1023 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
1024 | { |
---|
1025 | char *channel, *s; |
---|
1026 | struct irc_channel *ic; |
---|
1027 | |
---|
1028 | MIN_ARGS( 3 ); |
---|
1029 | |
---|
1030 | if( !( acc = account_get( irc->b, cmd[2] ) ) ) |
---|
1031 | { |
---|
1032 | irc_usermsg( irc, "Invalid account" ); |
---|
1033 | return; |
---|
1034 | } |
---|
1035 | else if( !acc->prpl->chat_join ) |
---|
1036 | { |
---|
1037 | irc_usermsg( irc, "Named chatrooms not supported on that account." ); |
---|
1038 | return; |
---|
1039 | } |
---|
1040 | |
---|
1041 | if( cmd[4] == NULL ) |
---|
1042 | { |
---|
1043 | channel = g_strdup( cmd[3] ); |
---|
1044 | if( ( s = strchr( channel, '@' ) ) ) |
---|
1045 | *s = 0; |
---|
1046 | } |
---|
1047 | else |
---|
1048 | { |
---|
1049 | channel = g_strdup( cmd[4] ); |
---|
1050 | } |
---|
1051 | |
---|
1052 | if( strchr( CTYPES, channel[0] ) == NULL ) |
---|
1053 | { |
---|
1054 | s = g_strdup_printf( "#%s", channel ); |
---|
1055 | g_free( channel ); |
---|
1056 | channel = s; |
---|
1057 | |
---|
1058 | irc_channel_name_strip( channel ); |
---|
1059 | } |
---|
1060 | |
---|
1061 | if( ( ic = irc_channel_new( irc, channel ) ) && |
---|
1062 | set_setstr( &ic->set, "type", "chat" ) && |
---|
1063 | set_setstr( &ic->set, "chat_type", "room" ) && |
---|
1064 | set_setstr( &ic->set, "account", cmd[2] ) && |
---|
1065 | set_setstr( &ic->set, "room", cmd[3] ) ) |
---|
1066 | { |
---|
1067 | irc_usermsg( irc, "Chatroom successfully added." ); |
---|
1068 | } |
---|
1069 | else |
---|
1070 | { |
---|
1071 | if( ic ) |
---|
1072 | irc_channel_free( ic ); |
---|
1073 | |
---|
1074 | irc_usermsg( irc, "Could not add chatroom." ); |
---|
1075 | } |
---|
1076 | g_free( channel ); |
---|
1077 | } |
---|
1078 | else if( g_strcasecmp( cmd[1], "with" ) == 0 ) |
---|
1079 | { |
---|
1080 | irc_user_t *iu; |
---|
1081 | |
---|
1082 | MIN_ARGS( 2 ); |
---|
1083 | |
---|
1084 | if( ( iu = irc_user_by_name( irc, cmd[2] ) ) && |
---|
1085 | iu->bu && iu->bu->ic->acc->prpl->chat_with ) |
---|
1086 | { |
---|
1087 | if( !iu->bu->ic->acc->prpl->chat_with( iu->bu->ic, iu->bu->handle ) ) |
---|
1088 | { |
---|
1089 | irc_usermsg( irc, "(Possible) failure while trying to open " |
---|
1090 | "a groupchat with %s.", iu->nick ); |
---|
1091 | } |
---|
1092 | } |
---|
1093 | else |
---|
1094 | { |
---|
1095 | irc_usermsg( irc, "Can't open a groupchat with %s.", cmd[2] ); |
---|
1096 | } |
---|
1097 | } |
---|
1098 | else if( g_strcasecmp( cmd[1], "list" ) == 0 || |
---|
1099 | g_strcasecmp( cmd[1], "set" ) == 0 || |
---|
1100 | g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
1101 | { |
---|
1102 | irc_usermsg( irc, "Warning: The \002chat\002 command was mostly replaced with the \002channel\002 command." ); |
---|
1103 | cmd_channel( irc, cmd ); |
---|
1104 | } |
---|
1105 | else |
---|
1106 | { |
---|
1107 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] ); |
---|
1108 | } |
---|
1109 | } |
---|
1110 | |
---|
1111 | static void cmd_transfer( irc_t *irc, char **cmd ) |
---|
1112 | { |
---|
1113 | GSList *files = irc->file_transfers; |
---|
1114 | enum { LIST, REJECT, CANCEL }; |
---|
1115 | int subcmd = LIST; |
---|
1116 | int fid; |
---|
1117 | |
---|
1118 | if( !files ) |
---|
1119 | { |
---|
1120 | irc_usermsg( irc, "No pending transfers" ); |
---|
1121 | return; |
---|
1122 | } |
---|
1123 | |
---|
1124 | if( cmd[1] && ( strcmp( cmd[1], "reject" ) == 0 ) ) |
---|
1125 | { |
---|
1126 | subcmd = REJECT; |
---|
1127 | } |
---|
1128 | else if( cmd[1] && ( strcmp( cmd[1], "cancel" ) == 0 ) && |
---|
1129 | cmd[2] && ( sscanf( cmd[2], "%d", &fid ) == 1 ) ) |
---|
1130 | { |
---|
1131 | subcmd = CANCEL; |
---|
1132 | } |
---|
1133 | |
---|
1134 | for( ; files; files = g_slist_next( files ) ) |
---|
1135 | { |
---|
1136 | file_transfer_t *file = files->data; |
---|
1137 | |
---|
1138 | switch( subcmd ) { |
---|
1139 | case LIST: |
---|
1140 | if ( file->status == FT_STATUS_LISTENING ) |
---|
1141 | irc_usermsg( irc, |
---|
1142 | "Pending file(id %d): %s (Listening...)", file->local_id, file->file_name); |
---|
1143 | else |
---|
1144 | { |
---|
1145 | int kb_per_s = 0; |
---|
1146 | time_t diff = time( NULL ) - file->started ? : 1; |
---|
1147 | if ( ( file->started > 0 ) && ( file->bytes_transferred > 0 ) ) |
---|
1148 | kb_per_s = file->bytes_transferred / 1024 / diff; |
---|
1149 | |
---|
1150 | irc_usermsg( irc, |
---|
1151 | "Pending file(id %d): %s (%10zd/%zd kb, %d kb/s)", file->local_id, file->file_name, |
---|
1152 | file->bytes_transferred/1024, file->file_size/1024, kb_per_s); |
---|
1153 | } |
---|
1154 | break; |
---|
1155 | case REJECT: |
---|
1156 | if( file->status == FT_STATUS_LISTENING ) |
---|
1157 | { |
---|
1158 | irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name ); |
---|
1159 | imcb_file_canceled( file->ic, file, "Denied by user" ); |
---|
1160 | } |
---|
1161 | break; |
---|
1162 | case CANCEL: |
---|
1163 | if( file->local_id == fid ) |
---|
1164 | { |
---|
1165 | irc_usermsg( irc, "Canceling file transfer for %s", file->file_name ); |
---|
1166 | imcb_file_canceled( file->ic, file, "Canceled by user" ); |
---|
1167 | } |
---|
1168 | break; |
---|
1169 | } |
---|
1170 | } |
---|
1171 | } |
---|
1172 | |
---|
1173 | /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ |
---|
1174 | const command_t commands[] = { |
---|
1175 | { "account", 1, cmd_account, 0 }, |
---|
1176 | { "add", 2, cmd_add, 0 }, |
---|
1177 | { "allow", 1, cmd_allow, 0 }, |
---|
1178 | { "blist", 0, cmd_blist, 0 }, |
---|
1179 | { "block", 1, cmd_block, 0 }, |
---|
1180 | { "channel", 1, cmd_channel, 0 }, |
---|
1181 | { "chat", 1, cmd_chat, 0 }, |
---|
1182 | { "drop", 1, cmd_drop, 0 }, |
---|
1183 | { "ft", 0, cmd_transfer, 0 }, |
---|
1184 | { "help", 0, cmd_help, 0 }, |
---|
1185 | { "identify", 1, cmd_identify, 0 }, |
---|
1186 | { "info", 1, cmd_info, 0 }, |
---|
1187 | { "no", 0, cmd_yesno, 0 }, |
---|
1188 | { "qlist", 0, cmd_qlist, 0 }, |
---|
1189 | { "register", 1, cmd_register, 0 }, |
---|
1190 | { "remove", 1, cmd_remove, 0 }, |
---|
1191 | { "rename", 2, cmd_rename, 0 }, |
---|
1192 | { "save", 0, cmd_save, 0 }, |
---|
1193 | { "set", 0, cmd_set, 0 }, |
---|
1194 | { "transfer", 0, cmd_transfer, 0 }, |
---|
1195 | { "yes", 0, cmd_yesno, 0 }, |
---|
1196 | { NULL } |
---|
1197 | }; |
---|