summary refs log tree commit diff
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
parentDisallow PRIVMSG/NOTICE before registration (diff)
downloadpounce-b639024365b8d633c944add0f914c41ce40bcbfd.tar.gz
pounce-b639024365b8d633c944add0f914c41ce40bcbfd.zip
Specify when command is allowed in Handlers list
-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;
 	}
4d1ce48346a6d3932888f900ae242bbaafbe&follow=1'>Bump version to 3.3.3p1 3.3.3p1June McEnroe 2021-05-25build: Add scripts to EXTRA_DISTJune McEnroe 2021-05-25import: Add missing scripts/wrap-compiler-for-flag-checkJune McEnroe 2021-05-08Import LibreSSL 3.3.3June McEnroe 2021-04-18build: Remove added x509_verify.3 links 3.3.2June McEnroe 2021-04-18tls: Use EC_KEY_set_ex_dataJune McEnroe 2021-04-18Import LibreSSL 3.3.2June McEnroe 2021-03-05Bump version to 3.3.1p1 3.3.1p1June McEnroe 2021-03-05build: Add OpenSSL includes to libcompatJune McEnroe Some compat sources (getentropy_linux.c for example) require OpenSSL. Reported by Robert Scheck. 2020-12-15Import LibreSSL 3.3.1June McEnroe 2020-11-24Import LibreSSL 3.3.0June McEnroe 2020-10-22Import LibreSSL 3.2.2June McEnroe 2020-09-29Import LibreSSL 3.2.1June McEnroe 2020-09-29import: Add m4/ax_add_fortify_source.m4June McEnroe 2020-08-05build: Add README.7 to EXTRA_DIST 3.2.0June McEnroe 2020-08-03doc: Indicate that only OpenSSL 1.1.1b and newer workJune McEnroe