From: Egor Date: Thu, 27 Mar 2025 07:56:58 +0000 (+0200) Subject: irc: make ADMIN info configurable X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=621d9054a938f676eadb04b3774bf7b2713ce715;p=patchyircd.git irc: make ADMIN info configurable --- diff --git a/README.md b/README.md index 99dccd5..f9650a6 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,7 @@ cp config.example.mk config.mk make ``` -Some things are configurable via compile-time flags. In particular, `-DHAS_TLS` -and some constants defined in `src/config.h`. See the section on paths for -additional flags. +Some things are configurable via compile-time flags. See the section on paths. ## Config files These have to go in datadir (see below). @@ -40,6 +38,12 @@ Additional nicks can be added via `nicks.txt` (`account:nick`). `help.txt` file contains the text for the HELP command. You can use the provided `help.example.txt` file. Similarly, `motd.txt` contains the MOTD text. +`admin.txt` file contains info displayed by the ADMIN command. First line is +supposed to be the geographical location of the server. Second line is the +organization running the server. Third line is a contact email address. +You can set these to whatever you want, though setting a contact email is +recommended. + 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 channels. If you specify source (i.e. `:nick!user@host` before the command), @@ -71,7 +75,7 @@ actual hostname ## Paths Data directory can be configured with `--datadir` argument. The default can be -configured at compile time via `IRCDDATADIR` define. Otherwise it deafults to +configured at compile time via `IRCDDATADIR` define. Otherwise it defaults to `LOCALSTATEDIR/lib/patchyircd` if `LOCALSTATEDIR` is defined. Otherwise it's `data` in the working directory. diff --git a/src/irc.cpp b/src/irc.cpp index c11efc7..bc14d23 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -825,10 +825,31 @@ saslcleanup: return err_notregistered(client), sendbuf(client), 0; if (args[0] && strcmp(args[0], hostname) != 0) return err_nosuchserver(client, args[0]), sendbuf(client), 0; - rpl_adminme(client), sendbuf(client); - rpl_adminloc1(client, ADMINLOC1), sendbuf(client); - rpl_adminloc2(client, ADMINLOC2), sendbuf(client); - rpl_adminemail(client, ADMINEMAIL), sendbuf(client); + char line[512]; + FILE *f = fopen(getdatafile("admin.txt"), "r" FOPEN_CLOEXEC); + if (f) { + auto nextline = [f, &line]()->bool{ + if (fgets(line, 512, f)) { + char *c = strchr(line, '\n'); + if (*c) + *c = '\0'; + return true; + } + return false; + }; + rpl_adminme(client), sendbuf(client); + if (nextline()) { + rpl_adminloc1(client, line), sendbuf(client); + if (nextline()) { + rpl_adminloc2(client, line), sendbuf(client); + if (nextline()) + rpl_adminemail(client, line), sendbuf(client); + } + } + fclose(f); + } else { + goto unknown; + } } else if(strcmp(command, "LUSERS") == 0) { if (!is_registered(client)) return err_notregistered(client), sendbuf(client), 0;