summary refs log tree commit diff
path: root/client.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-25 18:24:47 -0400
committerJune McEnroe <june@causal.agency>2019-10-25 18:24:47 -0400
commit1b41af31351ed0dd4bcdceda5efbbae3e38c3fca (patch)
tree50765e0e28cf0675757ba38ac91b658137b043a6 /client.c
parentClean up event loop (diff)
downloadpounce-1b41af31351ed0dd4bcdceda5efbbae3e38c3fca.tar.gz
pounce-1b41af31351ed0dd4bcdceda5efbbae3e38c3fca.zip
Send PRIVMSG and NOTICE to other clients
Diffstat (limited to '')
-rw-r--r--client.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/client.c b/client.c
index 7079d7a..2bfe7db 100644
--- a/client.c
+++ b/client.c
@@ -169,13 +169,31 @@ static void handleQuit(struct Client *client, struct Message *msg) {
 	client->error = true;
 }
 
+static void handlePrivmsg(struct Client *client, struct Message *msg) {
+	if (!msg->params[0] || !msg->params[1]) return;
+	// FIXME: Check against ISUPPORT CHANTYPES?
+	if (msg->params[0][0] == '#') {
+		char line[1024];
+		snprintf(
+			line, sizeof(line), ":%s %s %s :%s",
+			stateSelf(), msg->cmd, msg->params[0], msg->params[1]
+		);
+		size_t diff = ringDiff(client->consumer);
+		ringProduce(line);
+		if (!diff) ringConsume(NULL, client->consumer);
+	}
+	serverFormat("%s %s :%s\r\n", msg->cmd, msg->params[0], msg->params[1]);
+}
+
 static const struct {
 	const char *cmd;
 	Handler *fn;
 } Handlers[] = {
 	{ "CAP", handleCap },
 	{ "NICK", handleNick },
+	{ "NOTICE", handlePrivmsg },
 	{ "PASS", handlePass },
+	{ "PRIVMSG", handlePrivmsg },
 	{ "QUIT", handleQuit },
 	{ "USER", handleUser },
 };
@@ -193,7 +211,8 @@ static void clientParse(struct Client *client, char *line) {
 static bool intercept(const char *line, size_t len) {
 	if (len >= 4 && !memcmp(line, "CAP ", 4)) return true;
 	if (len >= 5 && !memcmp(line, "QUIT ", 5)) return true;
-	// TODO: Intercept PRIVMSG and NOTICE to send to other clients.
+	if (len >= 7 && !memcmp(line, "NOTICE ", 7)) return true;
+	if (len >= 8 && !memcmp(line, "PRIVMSG ", 8)) return true;
 	return false;
 }