summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2026-02-04 12:21:47 +0300
committerNakidai <nakidai@disroot.org>2026-02-04 12:21:47 +0300
commitce0f41da41a2d97d4a8e7159747464ecef72de4c (patch)
tree7e09329f15932710eb9fc14d18053c812c55515f /handle.c
parent58a7e4a4d7449d58732e024ea07ea3623c10d8de (diff)
downloadlibreircd-ce0f41da41a2d97d4a8e7159747464ecef72de4c.tar.gz
libreircd-ce0f41da41a2d97d4a8e7159747464ecef72de4c.zip
Add WHOIS and config parsing
Now users can query each other

Plus, server info and creation date can be changed without recompiling
using configuration file in IRC message format which is loaded on
startup

TODO: since readcfg uses IRC logic, handle() now should be able to deal
with commands ending with simply \n
Diffstat (limited to 'handle.c')
-rw-r--r--handle.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/handle.c b/handle.c
index 8e91404..9e8cb5f 100644
--- a/handle.c
+++ b/handle.c
@@ -282,6 +282,28 @@ quit(struct Message *msg, struct Peer *peer)
 }
 
 static int
+setcreation(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), 0);
+
+	strlcpy(creation, msg->params[0], sizeof(creation));
+
+	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);
+	ensure(msg->params[0] && *msg->params[0], reply(peer, 461), 0);
+
+	strlcpy(info, msg->params[0], sizeof(info));
+
+	return 0;
+}
+
+static int
 user(struct Message *msg, struct Peer *peer)
 {
 	size_t i;
@@ -304,6 +326,45 @@ user(struct Message *msg, struct Peer *peer)
 }
 
 static int
+whois(struct Message *msg, struct Peer *peer)
+{
+	size_t i;
+
+	ensure(peer->type, reply(peer, 451), 0);
+	ensure(msg->params[0] && *msg->params[0], reply(peer, 431), 0);
+
+	for (i = 0; i < peers_c; ++i)
+		if (!strcmp(msg->params[0], peers[i].nick))
+			break;
+	ensure(i != peers_c, reply(peer, 401, msg->params[0]), 0);
+
+	reply(
+		peer,
+		311,
+		peers[i].nick,
+		peers[i].user,
+		peers[i].host,
+		peers[i].real
+	);
+	reply(
+		peer,
+		312,
+		peers[i].nick,
+		hostname,
+		info
+	);
+	if (peers[i].modes & OPER)
+		reply(
+			peer,
+			313,
+			peers[i].nick
+		);
+	reply(peer, 318, peer[i].nick);
+
+	return 0;
+}
+
+static int
 default_handler(struct Message *msg, struct Peer *peer)
 {
 	ensure(peer->type, (void)0, 0);
@@ -326,7 +387,10 @@ static struct Handler {
 	{ "pong", pong },
 	{ "privmsg", privmsg },
 	{ "quit", quit },
+	{ "setcreation", setcreation },
+	{ "setinfo", setinfo },
 	{ "user", user },
+	{ "whois", whois },
 };
 
 Handler *