updates
[silc.git] / lib / silcclient / idlist.c
index 19c917d13c00ee41caf84834741b589f326934cf..0dd94e4ae9cc364d5c23bc20c4ad92733f047119 100644 (file)
@@ -649,6 +649,7 @@ void silc_client_del_client_entry(SilcClient client,
   silc_free(client_entry->nickname);
   silc_free(client_entry->username);
   silc_free(client_entry->realname);
+  silc_free(client_entry->hostname);
   silc_free(client_entry->server);
   silc_free(client_entry->id);
   silc_free(client_entry->fingerprint);
@@ -915,6 +916,7 @@ void silc_client_nickname_format(SilcClient client,
   int i, off = 0, len;
   SilcClientEntry *clients;
   uint32 clients_count = 0;
+  SilcClientEntry unformatted = NULL;
 
   SILC_LOG_DEBUG(("Start"));
 
@@ -999,10 +1001,15 @@ void silc_client_nickname_format(SilcClient client,
        char tmp[6];
        int num, max = 1;
 
-       if (clients_count == 1)
+       if (clients_count == 1) {
+         unformatted = clients[0];
          break;
+       }
 
        for (i = 0; i < clients_count; i++) {
+         if (!strncasecmp(clients[i]->nickname, client_entry->nickname,
+                          strlen(clients[i]->nickname)))
+           unformatted = clients[i];
          if (strncasecmp(clients[i]->nickname, newnick, off))
            continue;
          if (strlen(clients[i]->nickname) <= off)
@@ -1011,7 +1018,7 @@ void silc_client_nickname_format(SilcClient client,
          if (num > max)
            max = num;
        }
-       
+
        memset(tmp, 0, sizeof(tmp));
        snprintf(tmp, sizeof(tmp) - 1, "%d", ++max);
        len = strlen(tmp);
@@ -1034,6 +1041,12 @@ void silc_client_nickname_format(SilcClient client,
   newnick = silc_realloc(newnick, sizeof(*newnick) * (off + 1));
   newnick[off] = 0;
 
+  /* If we are changing nickname of our local entry we'll enforce
+     that we will always get the unformatted nickname.  Give our
+     format number to the one that is not formatted now. */
+  if (unformatted && client_entry == conn->local_entry)
+    client_entry = unformatted;
+
   silc_free(client_entry->nickname);
   client_entry->nickname = newnick;
   silc_free(clients);