aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-04-04 21:00:02 -0400
committerWilmer van der Gaast <wilmer@gaast.net>2010-04-04 21:00:02 -0400
commit57c96f7be2511a0a50015512dc03a30ba0923862 (patch)
treec3ae43a58ab269ca916e160b3b46445570bf30d5
parent0b5cc72bc7b4192ff5b474b81038c299d03721f1 (diff)
Restored the rename command.
-rw-r--r--irc.h2
-rw-r--r--irc_channel.c2
-rw-r--r--irc_user.c6
-rw-r--r--root_commands.c54
4 files changed, 28 insertions, 36 deletions
diff --git a/irc.h b/irc.h
index 4a404b2a..d9cc422a 100644
--- a/irc.h
+++ b/irc.h
@@ -204,7 +204,7 @@ void irc_send_nick( irc_user_t *iu, const char *new );
irc_user_t *irc_user_new( irc_t *irc, const char *nick );
int irc_user_free( irc_t *irc, const char *nick );
irc_user_t *irc_user_by_name( irc_t *irc, const char *nick );
-int irc_user_set_nick( irc_t *irc, const char *old, const char *new );
+int irc_user_set_nick( irc_user_t *iu, const char *new );
gint irc_user_cmp( gconstpointer a_, gconstpointer b_ );
#endif
diff --git a/irc_channel.c b/irc_channel.c
index 27216f3c..27f33619 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -81,7 +81,7 @@ int irc_channel_free( irc_channel_t *ic )
int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )
{
- if( !irc_channel_has_user( ic, iu ) )
+ if( irc_channel_has_user( ic, iu ) )
return 0;
ic->users = g_slist_insert_sorted( ic->users, iu, irc_user_cmp );
diff --git a/irc_user.c b/irc_user.c
index 7f356d8d..8ad20b54 100644
--- a/irc_user.c
+++ b/irc_user.c
@@ -82,9 +82,9 @@ irc_user_t *irc_user_by_name( irc_t *irc, const char *nick )
return NULL;
}
-int irc_user_set_nick( irc_t *irc, const char *old, const char *new )
+int irc_user_set_nick( irc_user_t *iu, const char *new )
{
- irc_user_t *iu = irc_user_by_name( irc, old );
+ irc_t *irc = iu->irc;
char key[strlen(new)+1];
GSList *cl;
@@ -99,7 +99,7 @@ int irc_user_set_nick( irc_t *irc, const char *old, const char *new )
/* Send a NICK update if we're renaming our user, or someone
who's in the same channel like our user. */
if( iu == irc->user ||
- ( irc_channel_has_user( ic, irc->user ) &&
+ ( ( ic->flags & IRC_CHANNEL_JOINED ) &&
irc_channel_has_user( ic, iu ) ) )
{
irc_send_nick( iu, new );
diff --git a/root_commands.c b/root_commands.c
index 75f3af81..7e0b16d3 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -647,65 +647,55 @@ static void cmd_info( irc_t *irc, char **cmd )
ic->acc->prpl->get_info( ic, cmd[2] );
}
}
+#endif
static void cmd_rename( irc_t *irc, char **cmd )
{
- user_t *u;
+ irc_user_t *iu;
- if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
- {
- irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
- }
- else if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
+ iu = irc_user_by_name( irc, cmd[1] );
+
+ if( iu == NULL )
{
- if( strchr( CTYPES, cmd[2][0] ) && nick_ok( cmd[2] + 1 ) )
- {
- u = user_find( irc, irc->nick );
-
- irc_part( irc, u, irc->channel );
- g_free( irc->channel );
- irc->channel = g_strdup( cmd[2] );
- irc_join( irc, u, irc->channel );
-
- if( strcmp( cmd[0], "set_rename" ) != 0 )
- set_setstr( &irc->set, "control_channel", cmd[2] );
- }
+ irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
}
- else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
+ else if( iu == irc->user )
{
- irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
+ irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
}
else if( !nick_ok( cmd[2] ) )
{
irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
}
- else if( !( u = user_find( irc, cmd[1] ) ) )
+ else if( irc_user_by_name( irc, cmd[2] ) )
{
- irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
+ irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
}
else
{
- user_rename( irc, cmd[1], cmd[2] );
- irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
- if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
+ if( !irc_user_set_nick( iu, cmd[2] ) )
+ {
+ irc_usermsg( irc, "Error while changing nick" );
+ return;
+ }
+
+ if( iu == irc->root )
{
- g_free( irc->mynick );
- irc->mynick = g_strdup( cmd[2] );
-
/* If we're called internally (user did "set root_nick"),
let's not go O(INF). :-) */
if( strcmp( cmd[0], "set_rename" ) != 0 )
- set_setstr( &irc->set, "root_nick", cmd[2] );
+ set_setstr( &irc->b->set, "root_nick", cmd[2] );
}
- else if( u->send_handler == buddy_send_handler )
+ else if( iu->bu )
{
- nick_set( u->ic->acc, u->handle, cmd[2] );
+ nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] );
}
irc_usermsg( irc, "Nick successfully changed" );
}
}
+#if 0
char *set_eval_root_nick( set_t *set, char *new_nick )
{
irc_t *irc = set->data;
@@ -1231,7 +1221,9 @@ const command_t commands[] = {
{ "drop", 1, cmd_drop, 0 },
{ "add", 2, cmd_add, 0 },
{ "info", 1, cmd_info, 0 },
+#endif
{ "rename", 2, cmd_rename, 0 },
+#if 0
{ "remove", 1, cmd_remove, 0 },
{ "block", 1, cmd_block, 0 },
{ "allow", 1, cmd_allow, 0 },