irssi-import / bugs.irssi.org

bugs.irssi.org archive
https://github.com/irssi/irssi/issues
0 stars 0 forks source link

Undesirable behaviour when multiple clients are connected to irssi_proxy #832

Open irssibot opened 12 years ago

irssibot commented 12 years ago

Irssi proxy is great; I have been using it for many years without problem. There has always been one thing that annoyed me though. Consider the following: I have a copy of Irssi running permanently on a server, another proxy IRC client connected to it that runs on my home machine and a second proxy IRC client running on my machine at work. For the most part, this works just fine. Where things go a bit awry is when I enter into a /query with another user. On the local client (let's say it's my work one) and Irssi itself, the conversation might look as follows:

Hi, how's it going? Not bad, what are you up to? Just reporting this bug in Irssi that I've patched... Hopefully they'll commit it then? Yes that would be lovely! * me grins :D Unfortunately on other proxy clients (e.g. the home one), the conversation looks like this: window 1: Hi, how's it going? Just reporting this bug in Irssi that I've patched... Yes that would be lovely! * me grins :D window 2: Not bad, what are you up to? Hopefully they'll commit it then? In other words the conversation is split up into separate parts, my half and the reply half. This isn't really a big deal since you don't care about a conversation you've already had right? I guess so but it's annoying having to clean up the non-sensical windows on the other client, and if you want to continue the conversation on said client it's difficult to refer back to the previous conversation. The reason it happens is that you can't cause an arbitrary IRC client (Irssi included) to display the correct UI as if it had sent the PRIVMSG itself. The other clients receive PRIVMSGs of your lines from the proxy but display them as if the messages are coming TO you, not FROM you. This makes perfect sense in a channel context since in that case to and from are the same thing. My solution is when you're sending a PRIVMSG to an individual, the other proxy clients receive your lines FROM the person you sent them TO, prefixed with your nick. In case that doesn't make any sense (believe me, it didn't to me to begin with), here's how the conversation looks on the other proxy clients: Hi, how's it going? Not bad, what are you up to? Just reporting this bug in Irssi that I've patched... Hopefully they'll commit it then? Yes that would be lovely! * me grins :D Now, I fully accept this isn't exactly ideal, but I think it's the best solution available, and the behaviour is certainly better than what happens right now. I guess how you display your nick on the other clients might be a bit contentious? e.g. should it say " Hi, how's it going?" or " me> Hi, how's it going?" or just " > Hi, how's it going?" etc. You can't really second guess how arbitrary IRC clients display things so I just settled on the usual IRC defaults. For what it's worth, I've been using the attached patch for a few weeks now without any obvious problems. Thanks for the great client! :)
irssibot commented 12 years ago

irssi-svn-improve-multi-client-proxy-behaviour.diff

Index: src/irc/proxy/listen.c
===================================================================
--- src/irc/proxy/listen.c  (revision 5212)
+++ src/irc/proxy/listen.c  (working copy)
@@ -257,7 +257,17 @@

        params = event_get_params(args, 2 | PARAM_FLAG_GETREST,
                      &target, &msg);
-       proxy_outserver_all_except(client, "PRIVMSG %s", args);
+       if (ischannel(*target))
+           proxy_outserver_all_except(client, NULL, "PRIVMSG %s :%s", target, msg);
+       else {
+           if (strncmp(msg+1, "ACTION ", 7) == 0) {
+               msg[strlen(msg)-1] = '\0';
+               proxy_outserver_all_except(client, target, "PRIVMSG %s :* %s %s",
+                       target, client->nick, msg+8);
+           } else
+               proxy_outserver_all_except(client, target, "PRIVMSG %s :<%s> %s",
+                       target, client->nick, msg);
+       }

        ignore_next = TRUE;
        if (*msg != '\001' || msg[strlen(msg)-1] != '\001') {
@@ -544,8 +554,23 @@
    if (!IS_IRC_SERVER(server))
        return;

-   if (!ignore_next)
-       proxy_outserver_all(server, "PRIVMSG %s :%s", target, msg);
+   if (!ignore_next) {
+       GSList *i;
+
+       for (i = proxy_clients; i != NULL; i = i->next) {
+           CLIENT_REC *rec = i->data;
+
+           if (rec->connected && rec->server == server) {
+               if(ischannel(*target)) {
+                   proxy_outdata(rec, ":%s!%s@proxy PRIVMSG %s :%s\n", rec->nick,
+                           settings_get_str("user_name"), target, msg);
+               } else {
+                   proxy_outdata(rec, ":%s!%s@proxy PRIVMSG %s :<%s> %s\n", target,
+                           settings_get_str("user_name"), target, rec->nick, msg);
+               }
+           }
+       }
+   }
 }

 static void sig_message_own_action(IRC_SERVER_REC *server, const char *msg,
@@ -554,8 +579,23 @@
    if (!IS_IRC_SERVER(server))
        return;

-   if (!ignore_next)
-       proxy_outserver_all(server, "PRIVMSG %s :\001ACTION %s\001", target, msg);
+   if (!ignore_next) {
+       GSList *i;
+
+       for (i = proxy_clients; i != NULL; i = i->next) {
+           CLIENT_REC *rec = i->data;
+
+           if (rec->connected && rec->server == server) {
+               if(ischannel(*target)) {
+                   proxy_outdata(rec, ":%s!%s@proxy PRIVMSG %s :\001ACTION %s\001", rec->nick,
+                           settings_get_str("user_name"), target, msg);
+               } else {
+                   proxy_outdata(rec, ":%s!%s@proxy PRIVMSG %s :* %s %s\n", target,
+                           settings_get_str("user_name"), target, rec->nick, msg);
+               }
+           }
+       }
+   }
 }

 static LISTEN_REC *find_listen(const char *ircnet, int port)
Index: src/irc/proxy/dump.c
===================================================================
--- src/irc/proxy/dump.c    (revision 5212)
+++ src/irc/proxy/dump.c    (working copy)
@@ -115,7 +115,7 @@
    va_end(args);
 }

-void proxy_outserver_all_except(CLIENT_REC *client, const char *data, ...)
+void proxy_outserver_all_except(CLIENT_REC *client, const char *source, const char *data, ...)
 {
    va_list args;
    GSList *tmp;
@@ -132,7 +132,10 @@

        if (rec->connected && rec != client &&
            rec->server == client->server) {
-           proxy_outdata(rec, ":%s!%s@proxy %s\n", rec->nick,
+           if (source == NULL) {
+               source = rec->nick;
+           }
+           proxy_outdata(rec, ":%s!%s@proxy %s\n", source,
                      settings_get_str("user_name"), str);
        }
    }
Index: src/irc/proxy/module.h
===================================================================
--- src/irc/proxy/module.h  (revision 5212)
+++ src/irc/proxy/module.h  (working copy)
@@ -23,4 +23,4 @@
 void proxy_outdata_all(IRC_SERVER_REC *server, const char *data, ...);
 void proxy_outserver(CLIENT_REC *client, const char *data, ...);
 void proxy_outserver_all(IRC_SERVER_REC *server, const char *data, ...);
-void proxy_outserver_all_except(CLIENT_REC *client, const char *data, ...);
+void proxy_outserver_all_except(CLIENT_REC *client, const char *source, const char *data, ...);