From: Egor Date: Fri, 27 May 2022 19:50:14 +0000 (+0300) Subject: add HELP command X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=3961957a273539b2d0835520ed2df78c18084b3f;p=patchyircd.git add HELP command --- diff --git a/.gitignore b/.gitignore index 12e498f..0c8d1bb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ cert.pem key.pem users.txt newusers.txt +help.txt diff --git a/irc.c b/irc.c index a5e86ff..f1a1b88 100644 --- a/irc.c +++ b/irc.c @@ -498,6 +498,24 @@ int processPacket(struct client_data *client, char *source, char *command, int a return err_nosuchserver(client, args[0]), sendbuf(client), 0; // Send welcome sendMOTD(client); + } else if(strcmp(command, "HELP") == 0) { + if (!is_registered(client)) + return err_notregistered(client), sendbuf(client), 0; + char line[512]; + FILE *f = fopen("help.txt", "r"); + if (f) { + copy_strf(&databuf, ":%s 704 %s * :** /HELP **\r\n", hostname, client->nick), sendbuf(client); + while (fgets(line, 512, f)) { + char *c = strchr(line, '\n'); + if (*c) + *c = '\0'; + copy_strf(&databuf, ":%s 705 %s * :%s\r\n", hostname, client->nick, line), sendbuf(client); + } + fclose(f); + copy_strf(&databuf, ":%s 706 %s * :End of /HELP\r\n", hostname, client->nick), sendbuf(client); + } else { + copy_strf(&databuf, ":%s 524 %s * :No help available on this topic\r\n", hostname, client->nick), sendbuf(client); + } } else if(strcmp(command, "VERSION") == 0) { if (!is_registered(client)) return err_notregistered(client), sendbuf(client), 0;