summary refs log tree commit diff
path: root/client.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-28 01:43:37 -0400
committerJune McEnroe <june@causal.agency>2019-10-28 01:43:37 -0400
commitb639024365b8d633c944add0f914c41ce40bcbfd (patch)
tree085c2eda9e2c39355774047e131ab122b369f966 /client.c
parentDisallow PRIVMSG/NOTICE before registration (diff)
downloadpounce-b639024365b8d633c944add0f914c41ce40bcbfd.tar.gz
pounce-b639024365b8d633c944add0f914c41ce40bcbfd.zip
Specify when command is allowed in Handlers list
Diffstat (limited to 'client.c')
-rw-r--r--client.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/client.c b/client.c
index cd9d008..a191f42 100644
--- a/client.c
+++ b/client.c
@@ -172,11 +172,7 @@ static void handleQuit(struct Client *client, struct Message *msg) {
 }
 
 static void handlePrivmsg(struct Client *client, struct Message *msg) {
-	if (client->need || !msg->params[0] || !msg->params[1]) {
-		client->error = true;
-		return;
-	}
-
+	if (!msg->params[0] || !msg->params[1]) return;
 	char line[1024];
 	snprintf(
 		line, sizeof(line), ":%s %s %s :%s",
@@ -192,14 +188,15 @@ static void handlePrivmsg(struct Client *client, struct Message *msg) {
 static const struct {
 	const char *cmd;
 	Handler *fn;
+	bool need;
 } Handlers[] = {
-	{ "CAP", handleCap },
-	{ "NICK", handleNick },
-	{ "NOTICE", handlePrivmsg },
-	{ "PASS", handlePass },
-	{ "PRIVMSG", handlePrivmsg },
-	{ "QUIT", handleQuit },
-	{ "USER", handleUser },
+	{ "CAP", handleCap, false },
+	{ "NICK", handleNick, false },
+	{ "NOTICE", handlePrivmsg, true },
+	{ "PASS", handlePass, false },
+	{ "PRIVMSG", handlePrivmsg, true },
+	{ "QUIT", handleQuit, true },
+	{ "USER", handleUser, false },
 };
 
 static void clientParse(struct Client *client, char *line) {
@@ -207,6 +204,7 @@ static void clientParse(struct Client *client, char *line) {
 	if (!msg.cmd) return;
 	for (size_t i = 0; i < ARRAY_LEN(Handlers); ++i) {
 		if (strcmp(msg.cmd, Handlers[i].cmd)) continue;
+		if (Handlers[i].need && client->need) break;
 		Handlers[i].fn(client, &msg);
 		return;
 	}