Changeset e7bc722
- Timestamp:
- 2008-08-31T00:04:53Z (16 years ago)
- Branches:
- master
- Children:
- 0e639f5
- Parents:
- 131c6b6
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
chat.c
r131c6b6 re7bc722 29 29 { 30 30 struct chat *c, *l; 31 set_t *s; 31 32 32 33 if( !chat_chanok( channel ) ) … … 53 54 c->channel = g_strdup( channel ); 54 55 55 set_add( &c->set, "auto_join", "false", set_eval_bool, c ); 56 set_add( &c->set, "auto_rejoin", "false", set_eval_bool, c ); 57 set_add( &c->set, "nick", NULL, NULL, c ); 56 s = set_add( &c->set, "auto_join", "false", set_eval_bool, c ); 57 s = set_add( &c->set, "auto_rejoin", "false", set_eval_bool, c ); 58 s = set_add( &c->set, "nick", NULL, NULL, c ); 59 s->flags |= SET_NULL_OK; 58 60 59 61 return c; -
root_commands.c
r131c6b6 re7bc722 248 248 } 249 249 250 typedef set_t** (*cmd_set_findhead)( irc_t*, char* ); 251 252 static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead ) 253 { 254 char *set_full = NULL, *set_name = NULL, *tmp; 255 set_t **head; 256 257 if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) 258 set_full = cmd[2]; 259 else 260 set_full = cmd[1]; 261 262 if( findhead == NULL ) 263 { 264 set_name = set_full; 265 266 head = &irc->set; 267 } 268 else 269 { 270 char *id; 271 272 if( !set_full ) 273 { 274 /* FIXME: Broken # */ 275 irc_usermsg( irc, "Not enough parameters given (need %d)", 3 ); 276 return 0; 277 } 278 279 if( ( tmp = strchr( set_full, '/' ) ) ) 280 { 281 id = g_strndup( set_full, ( tmp - set_full ) ); 282 set_name = tmp + 1; 283 } 284 else 285 { 286 id = g_strdup( set_full ); 287 } 288 289 if( ( head = findhead( irc, id ) ) == NULL ) 290 { 291 g_free( id ); 292 irc_usermsg( irc, "Could not find setting." ); 293 return 0; 294 } 295 g_free( id ); 296 } 297 298 if( cmd[1] && cmd[2] && set_name ) 299 { 300 set_t *s = set_find( head, set_name ); 301 int st; 302 303 /* 304 if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) 305 { 306 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); 307 return 0; 308 } 309 else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) 310 { 311 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); 312 return 0; 313 } 314 */ 315 316 if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) 317 st = set_reset( head, set_name ); 318 else 319 st = set_setstr( head, set_name, cmd[2] ); 320 321 if( set_getstr( head, set_name ) == NULL ) 322 { 323 if( st ) 324 irc_usermsg( irc, "Setting changed successfully" ); 325 else 326 irc_usermsg( irc, "Failed to change setting" ); 327 } 328 else 329 { 330 cmd_showset( irc, head, set_name ); 331 } 332 } 333 else if( set_name ) 334 { 335 cmd_showset( irc, head, set_name ); 336 } 337 else 338 { 339 set_t *s = *head; 340 while( s ) 341 { 342 cmd_showset( irc, &s, s->key ); 343 s = s->next; 344 } 345 } 346 347 return 1; 348 } 349 350 static set_t **cmd_account_set_findhead( irc_t *irc, char *id ) 351 { 352 account_t *a; 353 354 if( ( a = account_get( irc, id ) ) ) 355 return &a->set; 356 else 357 return NULL; 358 } 359 250 360 static void cmd_account( irc_t *irc, char **cmd ) 251 361 { … … 420 530 else if( g_strcasecmp( cmd[1], "set" ) == 0 ) 421 531 { 422 char *acc_handle, *set_name = NULL, *tmp;423 424 532 if( !cmd[2] ) 425 533 { … … 428 536 } 429 537 430 if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) 431 acc_handle = g_strdup( cmd[3] ); 432 else 433 acc_handle = g_strdup( cmd[2] ); 434 435 if( !acc_handle ) 436 { 437 irc_usermsg( irc, "Not enough parameters given (need %d)", 3 ); 438 return; 439 } 440 441 if( ( tmp = strchr( acc_handle, '/' ) ) ) 442 { 443 *tmp = 0; 444 set_name = tmp + 1; 445 } 446 447 if( ( a = account_get( irc, acc_handle ) ) == NULL ) 448 { 449 g_free( acc_handle ); 450 irc_usermsg( irc, "Invalid account" ); 451 return; 452 } 453 454 if( cmd[3] && set_name ) 455 { 456 set_t *s = set_find( &a->set, set_name ); 457 int st; 458 459 if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) 460 { 461 g_free( acc_handle ); 462 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); 463 return; 464 } 465 else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) 466 { 467 g_free( acc_handle ); 468 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); 469 return; 470 } 471 472 if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) 473 st = set_reset( &a->set, set_name ); 474 else 475 st = set_setstr( &a->set, set_name, cmd[3] ); 476 477 if( set_getstr( &a->set, set_name ) == NULL ) 478 { 479 if( st ) 480 irc_usermsg( irc, "Setting changed successfully" ); 481 else 482 irc_usermsg( irc, "Failed to change setting" ); 483 } 484 else 485 { 486 cmd_showset( irc, &a->set, set_name ); 487 } 488 } 489 else if( set_name ) 490 { 491 cmd_showset( irc, &a->set, set_name ); 492 } 493 else 494 { 495 set_t *s = a->set; 496 while( s ) 497 { 498 cmd_showset( irc, &s, s->key ); 499 s = s->next; 500 } 501 } 502 503 g_free( acc_handle ); 538 cmd_set_real( irc, cmd + 1, cmd_account_set_findhead ); 504 539 } 505 540 else … … 835 870 static void cmd_set( irc_t *irc, char **cmd ) 836 871 { 837 char *set_name = cmd[1]; 838 839 if( cmd[1] && cmd[2] ) 840 { 841 int st; 842 843 if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) 844 { 845 st = set_reset( &irc->set, cmd[2] ); 846 set_name = cmd[2]; 847 } 848 else 849 { 850 st = set_setstr( &irc->set, cmd[1], cmd[2] ); 851 } 852 853 /* Normally we just show the variable's new/unchanged 854 value as feedback to the user, but this has always 855 caused confusion when changing the password. Give 856 other feedback instead: */ 857 if( set_getstr( &irc->set, set_name ) == NULL ) 858 { 859 if( st ) 860 irc_usermsg( irc, "Setting changed successfully" ); 861 else 862 irc_usermsg( irc, "Failed to change setting" ); 863 } 864 else 865 { 866 cmd_showset( irc, &irc->set, set_name ); 867 } 868 } 869 else if( set_name ) 870 { 871 cmd_showset( irc, &irc->set, set_name ); 872 873 if( strchr( set_name, '/' ) ) 874 irc_usermsg( irc, "Warning: / found in setting name, you're probably looking for the `account set' command." ); 875 } 876 else 877 { 878 set_t *s = irc->set; 879 while( s ) 880 { 881 cmd_showset( irc, &s, s->key ); 882 s = s->next; 883 } 884 } 872 cmd_set_real( irc, cmd, NULL ); 885 873 } 886 874 … … 1007 995 } 1008 996 997 static set_t **cmd_chat_set_findhead( irc_t *irc, char *id ) 998 { 999 struct chat *c; 1000 1001 if( ( c = chat_get( irc, id ) ) ) 1002 return &c->set; 1003 else 1004 return NULL; 1005 } 1006 1009 1007 static void cmd_chat( irc_t *irc, char **cmd ) 1010 1008 { … … 1046 1044 } 1047 1045 irc_usermsg( irc, "End of chatroom list" ); 1046 } 1047 else if( g_strcasecmp( cmd[1], "set" ) == 0 ) 1048 { 1049 cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead ); 1048 1050 } 1049 1051 else
Note: See TracChangeset
for help on using the changeset viewer.