1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

added server_change_nick() function for servers.[ch]. Lots of fixes for

support to multiple identical nicks. Should work now properly :)


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1351 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-03-04 10:30:41 +00:00 committed by cras
parent f167516d23
commit 484f62f757
6 changed files with 86 additions and 25 deletions

View File

@ -34,6 +34,8 @@ static void nick_hash_add(CHANNEL_REC *channel, NICK_REC *nick)
{ {
NICK_REC *list; NICK_REC *list;
nick->next = NULL;
list = g_hash_table_lookup(channel->nicks, nick->nick); list = g_hash_table_lookup(channel->nicks, nick->nick);
if (list == NULL) if (list == NULL)
g_hash_table_insert(channel->nicks, nick->nick, nick); g_hash_table_insert(channel->nicks, nick->nick, nick);
@ -43,6 +45,11 @@ static void nick_hash_add(CHANNEL_REC *channel, NICK_REC *nick)
list = list->next; list = list->next;
list->next = nick; list->next = nick;
} }
if (nick == channel->ownnick) {
/* move our own nick to beginning of the nick list.. */
nicklist_set_own(channel, nick);
}
} }
static void nick_hash_remove(CHANNEL_REC *channel, NICK_REC *nick) static void nick_hash_remove(CHANNEL_REC *channel, NICK_REC *nick)
@ -110,8 +117,9 @@ void nicklist_remove(CHANNEL_REC *channel, NICK_REC *nick)
nicklist_destroy(channel, nick); nicklist_destroy(channel, nick);
} }
static void nicklist_rename_list(SERVER_REC *server, const char *old_nick, static void nicklist_rename_list(SERVER_REC *server, void *new_nick_id,
const char *new_nick, GSList *nicks) const char *old_nick, const char *new_nick,
GSList *nicks)
{ {
CHANNEL_REC *channel; CHANNEL_REC *channel;
NICK_REC *nickrec; NICK_REC *nickrec;
@ -124,6 +132,9 @@ static void nicklist_rename_list(SERVER_REC *server, const char *old_nick,
/* remove old nick from hash table */ /* remove old nick from hash table */
nick_hash_remove(channel, nickrec); nick_hash_remove(channel, nickrec);
if (new_nick_id != NULL)
nickrec->unique_id = new_nick_id;
g_free(nickrec->nick); g_free(nickrec->nick);
nickrec->nick = g_strdup(new_nick); nickrec->nick = g_strdup(new_nick);
@ -138,14 +149,15 @@ static void nicklist_rename_list(SERVER_REC *server, const char *old_nick,
void nicklist_rename(SERVER_REC *server, const char *old_nick, void nicklist_rename(SERVER_REC *server, const char *old_nick,
const char *new_nick) const char *new_nick)
{ {
nicklist_rename_list(server, old_nick, new_nick, nicklist_rename_list(server, NULL, old_nick, new_nick,
nicklist_get_same(server, old_nick)); nicklist_get_same(server, old_nick));
} }
void nicklist_rename_unique(SERVER_REC *server, void *old_nick_id, void nicklist_rename_unique(SERVER_REC *server,
const char *old_nick, const char *new_nick) void *old_nick_id, const char *old_nick,
void *new_nick_id, const char *new_nick)
{ {
nicklist_rename_list(server, old_nick, new_nick, nicklist_rename_list(server, new_nick_id, old_nick, new_nick,
nicklist_get_same_unique(server, old_nick_id)); nicklist_get_same_unique(server, old_nick_id));
} }
@ -273,10 +285,14 @@ typedef struct {
static void get_nicks_same_hash(gpointer key, NICK_REC *nick, static void get_nicks_same_hash(gpointer key, NICK_REC *nick,
NICKLIST_GET_SAME_REC *rec) NICKLIST_GET_SAME_REC *rec)
{ {
while (nick != NULL) {
if (g_strcasecmp(nick->nick, rec->nick) == 0) { if (g_strcasecmp(nick->nick, rec->nick) == 0) {
rec->list = g_slist_append(rec->list, rec->channel); rec->list = g_slist_append(rec->list, rec->channel);
rec->list = g_slist_append(rec->list, nick); rec->list = g_slist_append(rec->list, nick);
} }
nick = nick->next;
}
} }
GSList *nicklist_get_same(SERVER_REC *server, const char *nick) GSList *nicklist_get_same(SERVER_REC *server, const char *nick)
@ -305,9 +321,14 @@ typedef struct {
static void get_nicks_same_hash_unique(gpointer key, NICK_REC *nick, static void get_nicks_same_hash_unique(gpointer key, NICK_REC *nick,
NICKLIST_GET_SAME_UNIQUE_REC *rec) NICKLIST_GET_SAME_UNIQUE_REC *rec)
{ {
while (nick != NULL) {
if (nick->unique_id == rec->id) { if (nick->unique_id == rec->id) {
rec->list = g_slist_append(rec->list, rec->channel); rec->list = g_slist_append(rec->list, rec->channel);
rec->list = g_slist_append(rec->list, nick); rec->list = g_slist_append(rec->list, nick);
break;
}
nick = nick->next;
} }
} }
@ -404,6 +425,9 @@ void nicklist_set_own(CHANNEL_REC *channel, NICK_REC *nick)
next = nick->next; next = nick->next;
nick->next = first; nick->next = first;
while (first->next != nick)
first = first->next;
first->next = next; first->next = next;
g_hash_table_insert(channel->nicks, nick->nick, nick); g_hash_table_insert(channel->nicks, nick->nick, nick);

View File

@ -21,8 +21,9 @@ void nicklist_remove(CHANNEL_REC *channel, NICK_REC *nick);
/* Change nick */ /* Change nick */
void nicklist_rename(SERVER_REC *server, const char *old_nick, void nicklist_rename(SERVER_REC *server, const char *old_nick,
const char *new_nick); const char *new_nick);
void nicklist_rename_unique(SERVER_REC *server, void *old_nick_id, void nicklist_rename_unique(SERVER_REC *server,
const char *old_nick, const char *new_nick); void *old_nick_id, const char *old_nick,
void *new_nick_id, const char *new_nick);
/* Find nick */ /* Find nick */
NICK_REC *nicklist_find(CHANNEL_REC *channel, const char *nick); NICK_REC *nicklist_find(CHANNEL_REC *channel, const char *nick);

View File

@ -428,6 +428,16 @@ void server_connect_free(SERVER_CONNECT_REC *conn)
g_free(conn); g_free(conn);
} }
void server_change_nick(SERVER_REC *server, const char *nick)
{
g_free(server->connrec->nick);
g_free(server->nick);
server->connrec->nick = g_strdup(nick);
server->nick = g_strdup(nick);
signal_emit("server nick changed", 1, server);
}
/* Update own IPv4 and IPv6 records */ /* Update own IPv4 and IPv6 records */
void server_connect_own_ip_save(SERVER_CONNECT_REC *conn, void server_connect_own_ip_save(SERVER_CONNECT_REC *conn,
IPADDR *ip4, IPADDR *ip6) IPADDR *ip4, IPADDR *ip6)

View File

@ -50,6 +50,9 @@ void server_connect_finished(SERVER_REC *server);
/* connection to server failed */ /* connection to server failed */
void server_connect_failed(SERVER_REC *server, const char *msg); void server_connect_failed(SERVER_REC *server, const char *msg);
/* Change your nick */
void server_change_nick(SERVER_REC *server, const char *nick);
/* Update own IPv4 and IPv6 records */ /* Update own IPv4 and IPv6 records */
void server_connect_own_ip_save(SERVER_CONNECT_REC *conn, void server_connect_own_ip_save(SERVER_CONNECT_REC *conn,
IPADDR *ip4, IPADDR *ip6); IPADDR *ip4, IPADDR *ip6);

View File

@ -501,15 +501,33 @@ static void sig_message_topic(SERVER_REC *server, const char *channel,
static int printnick_exists(NICK_REC *first, NICK_REC *ignore, static int printnick_exists(NICK_REC *first, NICK_REC *ignore,
const char *nick) const char *nick)
{ {
char *printnick;
while (first != NULL) { while (first != NULL) {
if (first != ignore && strcmp(first->nick, nick) == 0) if (first != ignore) {
printnick = g_hash_table_lookup(printnicks, first);
if (printnick != NULL && strcmp(printnick, nick) == 0)
return TRUE; return TRUE;
}
first = first->next; first = first->next;
} }
return FALSE; return FALSE;
} }
static NICK_REC *printnick_find_original(NICK_REC *nick)
{
while (nick != NULL) {
if (g_hash_table_lookup(printnicks, nick) == NULL)
return nick;
nick = nick->next;
}
return NULL;
}
static void sig_nicklist_new(CHANNEL_REC *channel, NICK_REC *nick) static void sig_nicklist_new(CHANNEL_REC *channel, NICK_REC *nick)
{ {
NICK_REC *firstnick; NICK_REC *firstnick;
@ -517,13 +535,21 @@ static void sig_nicklist_new(CHANNEL_REC *channel, NICK_REC *nick)
char *nickhost, *p; char *nickhost, *p;
int n; int n;
if (nick->host == NULL || nick == channel->ownnick) if (nick->host == NULL)
return; return;
firstnick = g_hash_table_lookup(channel->nicks, nick->nick); firstnick = g_hash_table_lookup(channel->nicks, nick->nick);
if (firstnick->next == NULL) if (firstnick->next == NULL)
return; return;
if (nick == channel->ownnick) {
/* own nick is being added, might be a nick change and
someone else having the original nick already in use.. */
nick = printnick_find_original(firstnick->next);
if (nick == NULL)
return; /* nope, we have it */
}
/* identical nick already exists, have to change it somehow.. */ /* identical nick already exists, have to change it somehow.. */
p = strchr(nick->host, '@'); p = strchr(nick->host, '@');
if (p == NULL) p = nick->host; else p++; if (p == NULL) p = nick->host; else p++;
@ -547,6 +573,7 @@ static void sig_nicklist_new(CHANNEL_REC *channel, NICK_REC *nick)
g_hash_table_insert(printnicks, nick, newnick->str); g_hash_table_insert(printnicks, nick, newnick->str);
g_string_free(newnick, FALSE); g_string_free(newnick, FALSE);
g_free(nickhost);
} }
static void sig_nicklist_remove(CHANNEL_REC *channel, NICK_REC *nick) static void sig_nicklist_remove(CHANNEL_REC *channel, NICK_REC *nick)

View File

@ -300,11 +300,7 @@ static void event_nick(SERVER_REC *server, const char *data,
if (g_strcasecmp(orignick, server->nick) == 0) { if (g_strcasecmp(orignick, server->nick) == 0) {
/* You changed your nick */ /* You changed your nick */
g_free(server->connrec->nick); server_change_nick(server, nick);
g_free(server->nick);
server->connrec->nick = g_strdup(nick);
server->nick = g_strdup(nick);
signal_emit("server nick changed", 1, server);
} }
nicklist_rename(server, orignick, nick); nicklist_rename(server, orignick, nick);