summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/nicklist.c29
-rw-r--r--src/core/nicklist.h6
2 files changed, 33 insertions, 2 deletions
diff --git a/src/core/nicklist.c b/src/core/nicklist.c
index 1fc15139..d5841b45 100644
--- a/src/core/nicklist.c
+++ b/src/core/nicklist.c
@@ -67,7 +67,7 @@ static void nicklist_destroy(CHANNEL_REC *channel, NICK_REC *nick)
g_free(nick);
}
-/* remove nick from list */
+/* Remove nick from list */
void nicklist_remove(CHANNEL_REC *channel, NICK_REC *nick)
{
g_return_if_fail(IS_CHANNEL(channel));
@@ -77,6 +77,33 @@ void nicklist_remove(CHANNEL_REC *channel, NICK_REC *nick)
nicklist_destroy(channel, nick);
}
+/* Change nick */
+void nicklist_rename(SERVER_REC *server, const char *old_nick,
+ const char *new_nick)
+{
+ CHANNEL_REC *channel;
+ NICK_REC *nickrec;
+ GSList *nicks, *tmp;
+
+ nicks = nicklist_get_same(server, old_nick);
+ for (tmp = nicks; tmp != NULL; tmp = tmp->next->next) {
+ channel = tmp->data;
+ nickrec = tmp->next->data;
+
+ /* remove old nick from hash table */
+ g_hash_table_remove(channel->nicks, nickrec->nick);
+
+ g_free(nickrec->nick);
+ nickrec->nick = g_strdup(new_nick);
+
+ /* add new nick to hash table */
+ g_hash_table_insert(channel->nicks, nickrec->nick, nickrec);
+
+ signal_emit("nicklist changed", 3, channel, nickrec, old_nick);
+ }
+ g_slist_free(nicks);
+}
+
static NICK_REC *nicklist_find_wildcards(CHANNEL_REC *channel,
const char *mask)
{
diff --git a/src/core/nicklist.h b/src/core/nicklist.h
index 6d278a2e..e1deb154 100644
--- a/src/core/nicklist.h
+++ b/src/core/nicklist.h
@@ -15,8 +15,12 @@ struct _NICK_REC {
/* Add new nick to list */
NICK_REC *nicklist_insert(CHANNEL_REC *channel, const char *nick,
int op, int voice, int send_massjoin);
-/* remove nick from list */
+/* Remove nick from list */
void nicklist_remove(CHANNEL_REC *channel, NICK_REC *nick);
+/* Change nick */
+void nicklist_rename(SERVER_REC *server, const char *old_nick,
+ const char *new_nick);
+
/* Find nick record from list */
NICK_REC *nicklist_find(CHANNEL_REC *channel, const char *mask);
/* Get list of nicks that match the mask */