From b639024365b8d633c944add0f914c41ce40bcbfd Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 28 Oct 2019 01:43:37 -0400 Subject: Specify when command is allowed in Handlers list --- client.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'client.c') 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; } -- cgit 1.4.1