]> PatchyGit - patchyircd.git/commitdiff
improve USERHOST and WHO
authorEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 13:57:55 +0000 (16:57 +0300)
committerEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 13:57:55 +0000 (16:57 +0300)
irc.c

diff --git a/irc.c b/irc.c
index 26820be..a0bb24c 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -257,18 +257,37 @@ int processPacket(struct client_data *client) {
                        return 0;
                if (argc == 0) // FIXME: error message
                        return 0;
-               // TODO: actual host
-               copy_strf(&databuf, ":%s 302 %s :%s=+~user@localhost\n", hostname, client->nick, args[0]);
+               copy_strf(&databuf, ":%s 302 %s", hostname, client->nick);
+               int has_output = 0;
+               for (int i = 0; i < 5; i++) {
+                       if (!args[i])
+                               break;
+                       struct client_data *cl = findClient(args[i]);
+                       if (cl) {
+                               append_strf(&databuf, " %s%s%s=%s%s",
+                                               has_output ? "" : ":",
+                                               cl->nick,
+                                               cl->umode&UMODE_OPER ? "*" : "",
+                                               cl->away ? "-" : "+",
+                                               cl->hostname);
+                               has_output = 1;
+                       }
+                       append_str(&databuf, "\n");
+               }
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if(strcmp(command, "WHO") == 0) {
                if (!client->nick) // FIXME: error message
                        return 0;
                if (argc == 0) // FIXME: error message
                        return 0;
-               // TODO: actual host info
                struct client_data *cl = findClient(args[0]);
-               if (cl)
-                       copy_strf(&databuf, ":%s 352 %s * ~user localhost %s %s H :1 Patchouli Knowledge\n", hostname, client->nick, hostname, args[0]);
+               // TODO: mask and channel modes
+               if (cl) {
+                       copy_strf(&databuf, ":%s 352 %s * %s %s %s %s %s%s :1 %s\n",
+                                       hostname, client->nick, cl->username, cl->hostname, hostname, cl->nick,
+                                       cl->away ? "G" : "H", cl->umode&UMODE_OPER ? "*" : "", cl->realname);
+                       send_log(client->FD, databuf.buf, databuf.len, 0);
+               }
                copy_strf(&databuf, ":%s 315 %s %s :End of WHO list\n", hostname, client->nick, args[0]);
                send_log(client->FD, databuf.buf, databuf.len, 0);
        } else if(strcmp(command, "WHOIS") == 0) {