From 056215fd14628f044250597b8a1cbebcfe11d64f Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 8 May 2022 12:34:45 +0300 Subject: [PATCH] add WHO #channel --- irc.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/irc.c b/irc.c index 9aa92f2..807097b 100644 --- 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); -- 2.56.0