diff options
-rw-r--r-- | account.c | 2 | ||||
-rw-r--r-- | irc.c | 16 | ||||
-rw-r--r-- | root_commands.c | 75 | ||||
-rw-r--r-- | set.c | 6 | ||||
-rw-r--r-- | set.h | 2 |
5 files changed, 68 insertions, 33 deletions
@@ -54,7 +54,7 @@ account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass ) s = set_add( &a->set, "auto_reconnect", "true", set_eval_bool, a ); s = set_add( &a->set, "password", NULL, set_eval_account, a ); - s->flags |= ACC_SET_NOSAVE; + s->flags |= ACC_SET_NOSAVE | SET_NULL_OK; s = set_add( &a->set, "username", NULL, set_eval_account, a ); s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY; @@ -33,13 +33,19 @@ static gboolean irc_userping( gpointer _irc, int fd, b_input_condition cond ); GSList *irc_connection_list = NULL; -static char *passchange( set_t *set, char *value ) +static char *set_eval_password( set_t *set, char *value ) { irc_t *irc = set->data; - irc_setpass( irc, value ); - irc_usermsg( irc, "Password successfully changed" ); - return NULL; + if( irc->status & USTATUS_IDENTIFIED ) + { + irc_setpass( irc, value ); + return NULL; + } + else + { + return SET_INVALID; + } } static char *set_eval_charset( set_t *set, char *value ) @@ -149,7 +155,7 @@ irc_t *irc_new( int fd ) s = set_add( &irc->set, "handle_unknown", "root", NULL, irc ); s = set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc ); s = set_add( &irc->set, "ops", "both", set_eval_ops, irc ); - s = set_add( &irc->set, "password", NULL, passchange, irc ); + s = set_add( &irc->set, "password", NULL, set_eval_password, irc ); s->flags |= SET_NULL_OK; s = set_add( &irc->set, "private", "true", set_eval_bool, irc ); s = set_add( &irc->set, "query_order", "lifo", NULL, irc ); diff --git a/root_commands.c b/root_commands.c index 56a405a3..7e84ddf6 100644 --- a/root_commands.c +++ b/root_commands.c @@ -237,6 +237,16 @@ void cmd_account_del_no( void *data ) g_free( data ); } +static void cmd_showset( irc_t *irc, set_t *set ) +{ + char *s; + + if( set && ( s = set_getstr( &set, set->key ) ) ) /* HACK! */ + irc_usermsg( irc, "%s = `%s'", set->key, s ); + else + irc_usermsg( irc, "%s is empty", set->key ); +} + static void cmd_account( irc_t *irc, char **cmd ) { account_t *a; @@ -444,6 +454,7 @@ static void cmd_account( irc_t *irc, char **cmd ) if( cmd[3] && set_name ) { set_t *s = set_find( &a->set, set_name ); + int st; if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) { @@ -459,27 +470,32 @@ static void cmd_account( irc_t *irc, char **cmd ) } if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) - set_reset( &a->set, set_name ); + st = set_reset( &a->set, set_name ); else - set_setstr( &a->set, set_name, cmd[3] ); + st = set_setstr( &a->set, set_name, cmd[3] ); + + if( set_getstr( &a->set, set_name ) == NULL ) + { + if( st ) + irc_usermsg( irc, "Setting changed successfully" ); + else + irc_usermsg( irc, "Failed to change setting" ); + } + else + { + cmd_showset( irc, set_find( &a->set, set_name ) ); + } } - if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ + else if( set_name ) { - char *s = set_getstr( &a->set, set_name ); - if( s ) - irc_usermsg( irc, "%s = `%s'", set_name, s ); - else - irc_usermsg( irc, "%s is empty", set_name ); + cmd_showset( irc, set_find( &a->set, set_name ) ); } else { set_t *s = a->set; while( s ) { - if( s->value || s->def ) - irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def ); - else - irc_usermsg( irc, "%s is empty", s->key ); + cmd_showset( irc, s ); s = s->next; } } @@ -822,23 +838,37 @@ static void cmd_set( irc_t *irc, char **cmd ) if( cmd[1] && cmd[2] ) { + int st; + if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) { - set_reset( &irc->set, cmd[2] ); + st = set_reset( &irc->set, cmd[2] ); set_name = cmd[2]; } else { - set_setstr( &irc->set, cmd[1], cmd[2] ); + st = set_setstr( &irc->set, cmd[1], cmd[2] ); + } + + /* Normally we just show the variable's new/unchanged + value as feedback to the user, but this has always + caused confusion when changing the password. Give + other feedback instead: */ + if( set_getstr( &irc->set, set_name ) == NULL ) + { + if( st ) + irc_usermsg( irc, "Setting changed successfully" ); + else + irc_usermsg( irc, "Failed to change setting" ); + } + else + { + cmd_showset( irc, set_find( &irc->set, set_name ) ); } } - if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ + else if( set_name ) { - char *s = set_getstr( &irc->set, set_name ); - if( s ) - irc_usermsg( irc, "%s = `%s'", set_name, s ); - else - irc_usermsg( irc, "%s is empty", set_name ); + cmd_showset( irc, set_find( &irc->set, set_name ) ); if( strchr( set_name, '/' ) ) irc_usermsg( irc, "Warning: / found in setting name, you're probably looking for the `account set' command." ); @@ -848,10 +878,7 @@ static void cmd_set( irc_t *irc, char **cmd ) set_t *s = irc->set; while( s ) { - if( s->value || s->def ) - irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def ); - else - irc_usermsg( irc, "%s is empty", s->key ); + cmd_showset( irc, s ); s = s->next; } } @@ -181,13 +181,15 @@ void set_del( set_t **head, char *key ) } } -void set_reset( set_t **head, char *key ) +int set_reset( set_t **head, char *key ) { set_t *s; s = set_find( head, key ); if( s ) - set_setstr( head, key, s->def ); + return set_setstr( head, key, s->def ); + + return 0; } char *set_eval_int( set_t *set, char *value ) @@ -91,7 +91,7 @@ G_MODULE_EXPORT int set_getbool( set_t **head, char *key ); int set_setstr( set_t **head, char *key, char *value ); int set_setint( set_t **head, char *key, int value ); void set_del( set_t **head, char *key ); -void set_reset( set_t **head, char *key ); +int set_reset( set_t **head, char *key ); /* Two very useful generic evaluators. */ char *set_eval_int( set_t *set, char *value ); |