summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2026-02-13 00:19:07 +0300
committerNakidai <nakidai@disroot.org>2026-02-13 00:19:07 +0300
commit3f2bbeda9cae1e3d3f50d984549c82a5a29d2f6f (patch)
treea116461d3102fdf2be87bd033780873f9cd55c8f
parent83c7d5f26cc3dcc93967a694b6b07447e839d6c1 (diff)
downloadlibreircd-3f2bbeda9cae1e3d3f50d984549c82a5a29d2f6f.tar.gz
libreircd-3f2bbeda9cae1e3d3f50d984549c82a5a29d2f6f.zip
Add SETHOSTNAME command
Also remove hostname argument from the cli. It'd be better to have it
in a config file rather than passing through an argument, it was like
that since times config file didn't exist, but time has changed
-rw-r--r--config.h1
-rw-r--r--config.irc1
-rw-r--r--handle.c12
-rw-r--r--ircd.h2
-rw-r--r--main.c19
5 files changed, 24 insertions, 11 deletions
diff --git a/config.h b/config.h
index ec49704..a7033a0 100644
--- a/config.h
+++ b/config.h
@@ -20,6 +20,7 @@
 
 #define INFO_MAX 64
 #define CREATION_MAX 64
+#define HOSTNAME_MAX 64
 
 #define PARAM_MAX 15
 #define MESSAGE_MAX 512
diff --git a/config.irc b/config.irc
index 54b6833..594716e 100644
--- a/config.irc
+++ b/config.irc
@@ -1,3 +1,4 @@
+sethostname irc.example.org
 setcreation :Thu Jan 1 1970 at 00:00:00 UTC
 setinfo :The best IRC server ever \o/
 setoper oper :<very secure password goes here>
diff --git a/handle.c b/handle.c
index 9c4590a..25c6875 100644
--- a/handle.c
+++ b/handle.c
@@ -518,6 +518,17 @@ setcreation(struct Message *msg, struct Peer *peer)
 }
 
 static int
+sethostname(struct Message *msg, struct Peer *peer)
+{
+	ensure(peer->type == CONFIG, reply(peer, 481, "You're not a config file"), 0);
+	ensure(msg->params[0] && *msg->params[0], reply(peer, 461, msg->command), 0);
+
+	strlcpy(hostname, msg->params[0], sizeof(hostname));
+
+	return 0;
+}
+
+static int
 setinfo(struct Message *msg, struct Peer *peer)
 {
 	ensure(peer->type == CONFIG, reply(peer, 481, "You're not a config file"), 0);
@@ -649,6 +660,7 @@ static struct Handler {
 	{ "privmsg", privmsg },
 	{ "quit", quit },
 	{ "setcreation", setcreation },
+	{ "sethostname", sethostname },
 	{ "setinfo", setinfo },
 	{ "setoper", setoper },
 	{ "user", user },
diff --git a/ircd.h b/ircd.h
index d4ed678..7b59330 100644
--- a/ircd.h
+++ b/ircd.h
@@ -98,10 +98,10 @@ typedef int Handler(struct Message *msg, struct Peer *peer);
 extern struct Channel channels[CHANNELS_MAX];
 extern struct Peer peers[PEERS_MAX];
 extern size_t channels_c, peers_c;
-extern const char *hostname;
 extern const char *host;
 extern unsigned long port;
 extern char creation[CREATION_MAX];
+extern char hostname[HOSTNAME_MAX];
 extern char info[INFO_MAX];
 
 int readcfg(const char *path);
diff --git a/main.c b/main.c
index 3c364a1..079893c 100644
--- a/main.c
+++ b/main.c
@@ -25,7 +25,7 @@
 #include <unistd.h>
 
 
-const char *hostname;
+char hostname[HOSTNAME_MAX] = "irc.example.org";
 
 int
 main(int argc, char **argv)
@@ -35,27 +35,26 @@ main(int argc, char **argv)
 
 	(void)argc;
 
-	for (i = 1; i < 4; ++i)
+	for (i = 1; i < 3; ++i)
 		if (!argv[i] || !*argv[i])
-			errx(1, "usage: %s hostname bindaddr port [config]", argv[0]);
-	hostname = argv[1];
-	host = argv[2];
-	port = strtoul(argv[3], &p, 10);
+			errx(1, "usage: %s bindaddr port [config]", argv[0]);
+	host = argv[1];
+	port = strtoul(argv[2], &p, 10);
 	if (errno || *p || !port || port > 65535)
 		errx(1, "invalid port");
 
 #ifdef __OpenBSD__
-	if (argv[4] && unveil(argv[4], "r"))
+	if (argv[3] && unveil(argv[3], "r"))
 		err(1, "unveil()");
 	if (pledge("stdio inet rpath unveil", ""))
 		err(1, "pledge()");
 #endif /* __OpenBSD__ */
 
-	if (argv[4])
-		readcfg(argv[4]);
+	if (argv[3])
+		readcfg(argv[3]);
 
 #ifdef __OpenBSD__
-	if (argv[4] && (unveil(argv[4], "") || unveil(NULL, NULL)))
+	if (argv[3] && (unveil(argv[3], "") || unveil(NULL, NULL)))
 		err(1, "unveil()");
 	if (pledge("stdio inet", ""))
 		err(1, "pledge()");