Thu Nov 14 19:33:28 CET 2002 Jochen Eisinger <c0ffee@penguin-breeder.org>
authorJochen Eisinger <coffee@silcnet.org>
Thu, 14 Nov 2002 18:36:54 +0000 (18:36 +0000)
committerJochen Eisinger <coffee@silcnet.org>
Thu, 14 Nov 2002 18:36:54 +0000 (18:36 +0000)
* Print "nick now appears as newnick" and update Irssi's nicklist
  when you change your nick to "nick". Closes #62

apps/irssi/src/fe-common/silc/module-formats.c
apps/irssi/src/fe-common/silc/module-formats.h
apps/irssi/src/silc/core/client_ops.c

index ecd8fafd22c046461ec1316bad802a6cbb537d0f..cf0632a68f57de46fe8e5d26e3e4346f0669dc46 100644 (file)
@@ -48,6 +48,7 @@ FORMAT_REC fecommon_silc_formats[] = {
        { "killed_you", "You have been killed from the SILC Network by {nick $0} ($1)", 2, { 0, 0 } },
        { "killed", "{nick $0} has been killed from the SILC Network by {nick $1} ($2)", 3, { 0, 0, 0 } },
        { "quieted", "You have been queited and cannot talk on {channel $0}", 1, { 0 } },
+       { "appears", "{channick $0} now appears as {channick_hilight $1}", 4, { 0, 0, 0, 0 } },
 
        /* WHOIS, WHOWAS and USERS (alias WHO) messages */
        { NULL, "Who Queries", 0 },
index 73d66a8e8f65e21f05f67cc317732506beb8107e..035b8cbc48797711412787767a896c2d3c01d2ad 100644 (file)
@@ -45,6 +45,7 @@ enum {
   SILCTXT_CHANNEL_KILLED_YOU,
   SILCTXT_CHANNEL_KILLED,
   SILCTXT_CHANNEL_QUIETED,
+  SILCTXT_CHANNEL_APPEARS,
 
   SILCTXT_FILL_2,
 
index f8e0897193ea8f2d0773981c8a3fd7ffee44d564..e20179041af060a475325077a8b70d1509bfd4a2 100644 (file)
@@ -36,6 +36,7 @@
 #include "fe-common/core/printtext.h"
 #include "fe-common/core/fe-channels.h"
 #include "fe-common/core/keyboard.h"
+#include "fe-common/core/window-items.h"
 #include "fe-common/silc/module-formats.h"
 
 #include "core.h"
@@ -81,6 +82,48 @@ static void silc_get_umode_string(SilcUInt32 mode, char *buf,
     strcat(buf, " [blocks invites]");
 }
 
+/* print "nick appears as" message to every channel of a server */
+static void 
+silc_print_nick_change_channel(SILC_SERVER_REC *server, const char *channel,
+                             const char *newnick, const char *oldnick,
+                             const char *address)
+{
+    if (ignore_check(server, oldnick, address,
+                    channel, newnick, MSGLEVEL_NICKS))
+       return;
+
+    printformat_module("fe-common/silc", server, channel, MSGLEVEL_NICKS,
+               SILCTXT_CHANNEL_APPEARS,
+               oldnick, newnick, channel, address);
+}
+
+static void
+silc_print_nick_change(SILC_SERVER_REC *server, const char *newnick,
+                      const char *oldnick, const char *address)
+{
+    GSList *tmp, *windows;
+
+    /* Print to each channel/query where the nick is.
+       Don't print more than once to the same window. */
+    windows = NULL;
+    
+    for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
+       CHANNEL_REC *channel = tmp->data;
+       WINDOW_REC *window = window_item_window((WI_ITEM_REC *) channel);
+
+       if (nicklist_find(channel, newnick) == NULL ||
+           g_slist_find(windows, window) != NULL)
+           continue;
+
+       windows = g_slist_append(windows, window);
+       silc_print_nick_change_channel(server, channel->visible_name,
+                                      newnick, oldnick, address);
+    }
+
+    g_slist_free(windows);
+
+}
+
 void silc_say(SilcClient client, SilcClientConnection conn,
              SilcClientMessageType type, char *msg, ...)
 {
@@ -1346,10 +1389,33 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
     {
       char *old;
       SilcClientEntry client = va_arg(vp, SilcClientEntry);
+      GSList *nicks;
       
       if (!success)
        return;
 
+      nicks = nicklist_get_same(SERVER(server), client->nickname);
+      if (nicks != NULL) {
+       char buf[512];
+       SilcClientEntry collider, old;
+
+       old = ((SILC_NICK_REC *)(nicks->next->data))->silc_user->client;
+       collider = silc_client_get_client_by_id(client, conn,
+                       old->id);
+       
+        memset(buf, 0, sizeof(buf));
+        snprintf(buf, sizeof(buf) - 1, "%s@%s",
+                collider->username, collider->hostname);
+       nicklist_rename_unique(SERVER(server),
+                              old, old->nickname,
+                              collider, collider->nickname);
+       silc_print_nick_change(server, collider->nickname, client->nickname,
+                              buf);
+
+       g_slist_free(nicks);
+
+      }
+
       old = g_strdup(server->nick);
       server_change_nick(SERVER(server), client->nickname);
       nicklist_rename_unique(SERVER(server),