]> PatchyGit - patchyircd.git/commitdiff
add WHO #channel
authorEgor <egor@patchysicp.xyz>
Sun, 8 May 2022 09:34:45 +0000 (12:34 +0300)
committerEgor <egor@patchysicp.xyz>
Sun, 8 May 2022 09:34:45 +0000 (12:34 +0300)
irc.c

diff --git a/irc.c b/irc.c
index 9aa92f2..807097b 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -657,13 +657,34 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                        return err_notregistered(client), sendbuf(client), 0;
                if (argc == 0) // FIXME: error message
                        return 0;
-               struct client_data *cl = findClient(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);
-                       sendbuf(client);
+               // TODO: masks
+               if (strchr("#&", args[0][0])) {
+                       struct channel *chan = findChannel(args[0]);
+                       // TODO: handle chanmode +s, umode +i
+                       if (chan) {
+                               struct trie_find *f = NULL;
+                               if (trie_findfirst(&f, &chan->members) == 1)
+                                       do {
+                                               struct client_data *cl = f->n->value;
+                                               char prefix[2] = {0,0};
+                                               if (trie_get(&chan->o, cl->key))
+                                                       prefix[0] = '@';
+                                               else if (trie_get(&chan->v, cl->key))
+                                                       prefix[0] = '+';
+                                               copy_strf(&databuf, ":%s 352 %s %s %s %s %s %s %s%s%s :1 %s\n",
+                                                               hostname, client->nick, chan->name, cl->username, cl->hostname, hostname, cl->nick,
+                                                               cl->away ? "G" : "H", cl->umode&UMODE_OPER ? "*" : "", prefix, cl->realname);
+                                               sendbuf(client);
+                                       } while(trie_findnext(&f) == 1);
+                       }
+               } else {
+                       struct client_data *cl = findClient(args[0]);
+                       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);
+                               sendbuf(client);
+                       }
                }
                copy_strf(&databuf, ":%s 315 %s %s :End of WHO list\n", hostname, client->nick, args[0]);
                sendbuf(client);