]> PatchyGit - patchyircd.git/commitdiff
add HELP command
authorEgor <egor@patchysicp.xyz>
Fri, 27 May 2022 19:50:14 +0000 (22:50 +0300)
committerEgor <egor@patchysicp.xyz>
Fri, 27 May 2022 21:01:00 +0000 (00:01 +0300)
.gitignore
irc.c

index 12e498f..0c8d1bb 100644 (file)
@@ -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 (file)
--- 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;