From: Egor Date: Tue, 3 May 2022 12:42:53 +0000 (+0300) Subject: add WHOIS command X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=55079fbc41718d2b1210aa020c88df92e9ca05be;p=patchyircd.git add WHOIS command --- diff --git a/irc.c b/irc.c index 4b4660d..e84c38e 100644 --- a/irc.c +++ b/irc.c @@ -256,6 +256,28 @@ int processPacket(struct client_data *client) { copy_strf(&databuf, ":%s 352 %s * ~user localhost %s %s H :1 Patchouli Knowledge\n", hostname, client->nick, hostname, args[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) { + if (!client->nick) // FIXME: error message + return 0; + if (argc == 0) // FIXME: error message + return 0; + char *nick = args[1] ? args[1] : args[0]; + struct client_data *cl = findClient(nick); + if (cl) { + copy_strf(&databuf, ":%s 311 %s %s %s %s * :%s\n", hostname, client->nick, cl->nick, cl->username, cl->hostname, cl->realname); + send_log(client->FD, databuf.buf, databuf.len, 0); + copy_strf(&databuf, ":%s 312 %s %s %s :Patchy server\n", hostname, client->nick, cl->nick, hostname); + send_log(client->FD, databuf.buf, databuf.len, 0); + if (cl->umode & UMODE_OPER) { + copy_strf(&databuf, ":%s 313 %s %s :is an IRC operator\n", hostname, client->nick, cl->nick); + send_log(client->FD, databuf.buf, databuf.len, 0); + } + copy_strf(&databuf, ":%s 318 %s %s :End of /WHOIS list\n", hostname, client->nick, cl->nick); + send_log(client->FD, databuf.buf, databuf.len, 0); + } else { + copy_strf(&databuf, ":%s 401 %s %s :No such nick/channel\n", hostname, client->nick, cl->nick); + send_log(client->FD, databuf.buf, databuf.len, 0); + } } else { unknown: // Inform user of error