summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--litterbox.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/litterbox.c b/litterbox.c
index aa6ca1a..4a65166 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -585,6 +585,38 @@ static void handleTopic(struct Message *msg) {
 	insertEvent(msg, Topic, msg->params[0], NULL, msg->params[1]);
 }
 
+static void handleMode(struct Message *msg) {
+	require(msg, true, 2);
+	if (!strchr(chanTypes, msg->params[0][0])) return;
+	insertContext(msg->params[0], false);
+	insertName(msg);
+
+	bool set = true;
+	size_t param = 2;
+	for (char *ch = msg->params[1]; *ch; ++ch) {
+		if (*ch == '+') {
+			set = true;
+		} else if (*ch == '-') {
+			set = false;
+		} else if (*ch == 'b') {
+			if (param >= ParamCap || !msg->params[param]) {
+				errx(EX_PROTOCOL, "MODE missing ban target");
+			}
+			insertEvent(
+				msg, (set ? Ban : Unban), msg->params[0],
+				msg->params[param++], NULL
+			);
+		} else if (
+			strchr(prefixModes, *ch) ||
+			strchr(listModes, *ch) ||
+			strchr(paramModes, *ch) ||
+			(set && strchr(setParamModes, *ch))
+		) {
+			param++;
+		}
+	}
+}
+
 static void handlePing(struct Message *msg) {
 	require(msg, false, 1);
 	format("PONG :%s\r\n", msg->params[0]);
@@ -617,6 +649,7 @@ static const struct Handler {
 	{ "ERROR", false, handleError },
 	{ "JOIN", true, handleJoin },
 	{ "KICK", true, handleKick },
+	{ "MODE", true, handleMode },
 	{ "NICK", true, handleNick },
 	{ "NOTICE", true, handlePrivmsg },
 	{ "PART", true, handlePart },
fb5b3301a20644fef207&follow=1'>Add startup GPLv3 note and URLJune McEnroe 2020-02-11Make sure -D_GNU_SOURCE ends up in CFLAGS on LinuxJune McEnroe 2020-02-11Add note about setting PKG_CONFIG_PATHJune McEnroe 2020-02-11Rename query ID on nick changeJune McEnroe 2020-02-11Call completeClear when closing a windowJune McEnroe 2020-02-11Don't insert color codes for non-mentionsJune McEnroe 2020-02-11Take first two words in colorMentionsJune McEnroe 2020-02-11Use time_t for save signatureJune McEnroe 2020-02-11Set self.nick to * initiallyJune McEnroe 2020-02-11Define ColorCap instead of hardcoding 100June McEnroe 2020-02-11Move hash to top of chat.hJune McEnroe 2020-02-11Move base64 out of chat.hJune McEnroe 2020-02-11Move XDG_SUBDIR out of chat.hJune McEnroe 2020-02-11Fix whois idle unit calculationJune McEnroe 2020-02-11Cast towupper to wchar_tJune McEnroe 2020-02-11Cast set but unused variables to voidJune McEnroe 2020-02-11Declare strlcatJune McEnroe 2020-02-11Check if VDSUSP existsJune McEnroe 2020-02-11Fix completeReplace iterationJune McEnroe 2020-02-11Use pkg(8) to configure on FreeBSDJune McEnroe 2020-02-11Remove legacy codeJune McEnroe 2020-02-11Add INSTALLING section to READMEJune McEnroe