From: Egor Date: Thu, 19 Oct 2023 13:10:42 +0000 (+0300) Subject: add motd.txt support X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=30e4b7da7407ea29f65c2978eb8cf53bad75caca;p=patchyircd.git add motd.txt support --- diff --git a/.gitignore b/.gitignore index 0c8d1bb..3c6d701 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ key.pem users.txt newusers.txt help.txt +motd.txt diff --git a/README.md b/README.md index 30057c4..e8f7769 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ and some constants defined in `src/config.h`. For TLS you gonna need to place your certificate and private key in `cert.pem` and `key.pem` respectively. -`ops.txt` `users.txt` and `newusers.txt` contain hashed passwords. `ops.txt` is +`ops.txt`, `users.txt` and `newusers.txt` contain hashed passwords. `ops.txt` is used for OPER command, `users.txt` is used for PASS command (which we use for our bespoke user account system). NEWACC command adds lines to `newusers.txt`. To verify a registration, simply copy lines from `newusers.txt` to `users.txt`. @@ -23,7 +23,7 @@ You can set password from command line like so `./setpass username file.txt` (the file must already exist). `help.txt` file contains the text for the HELP command. You can use the provided -`help.example.txt` file. +`help.example.txt` file. Similarly, `motd.txt` contains the MOTD text. When the server starts, it reads the `init.txt` file. A fake oper connection performs the actions specified in the file. This allows initializing permanent diff --git a/src/irc.c b/src/irc.c index 71164b3..db166fd 100644 --- a/src/irc.c +++ b/src/irc.c @@ -1169,10 +1169,21 @@ void sendLUSERS(struct client_data *client) } void sendMOTD(struct client_data *client) { - rpl_motdstart(client), sendbuf(client); - rpl_motd(client, "Welcome to Montreal!"), sendbuf(client); - rpl_motd(client, "You are retarded and I will have cybersex with your mom."), sendbuf(client); - rpl_endofmotd(client), sendbuf(client); + char line[512]; + FILE *f = fopen("motd.txt", "r"); + if (f) { + rpl_motdstart(client), sendbuf(client); + while (fgets(line, 512, f)) { + char *c = strchr(line, '\n'); + if (*c) + *c = '\0'; + rpl_motd(client, line), sendbuf(client); + } + fclose(f); + rpl_endofmotd(client), sendbuf(client); + } else { + err_nomotd(client), sendbuf(client); + } } void setNick(struct client_data *client, char* nickname) { diff --git a/src/ircfmt.c b/src/ircfmt.c index a89a579..ef84f3a 100644 --- a/src/ircfmt.c +++ b/src/ircfmt.c @@ -502,12 +502,10 @@ void err_unknowncommand(struct client_data *client, const char *command) // 421 { copy_strf(&databuf, ":%s 421 %s %s :Unknown command\r\n", hostname, client->nick ? client->nick : "*", command); } -#if 0 void err_nomotd(struct client_data *client) // 422 { copy_strf(&databuf, ":%s 422 %s :MOTD File is missing\r\n", hostname, client->nick); } -#endif void err_erroneusnickname(struct client_data *client, const char *nick) // 432 { copy_strf(&databuf, ":%s 432 %s %s :Erroneus nickname\r\n", hostname, client->nick, nick);