summary refs log tree commit diff
path: root/command.c
diff options
context:
space:
mode:
authorC. McEnroe2020-02-19 21:47:16 -0500
committerC. McEnroe2020-02-19 21:47:16 -0500
commit56de4668acf0c18e4cd0e2a9c53bc4fc2db98306 (patch)
treec68f60818fb436ed8f73c3d1a158b88547ca957e /command.c
parent2a33ee68dd6dc201eb37828f109f02371daa1e80 (diff)
Add /ban, /unban and handle ban list replies
Diffstat (limited to 'command.c')
-rw-r--r--command.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/command.c b/command.c
index cc650da..c0b2ea2 100644
--- a/command.c
+++ b/command.c
@@ -143,6 +143,30 @@ static void commandKick(uint id, char *params) {
 	}
 }
 
+static void commandBan(uint id, char *params) {
+	if (params) {
+		int count = 1;
+		for (char *ch = params; *ch; ++ch) {
+			if (*ch == ' ') count++;
+		}
+		char b[ParamCap - 2] = "bbbbbbbbbbbbb";
+		ircFormat("MODE %s +%.*s %s\r\n", idNames[id], count, b, params);
+	} else {
+		ircFormat("MODE %s +b\r\n", idNames[id]);
+		replies.ban++;
+	}
+}
+
+static void commandUnban(uint id, char *params) {
+	if (!params) return;
+	int count = 1;
+	for (char *ch = params; *ch; ++ch) {
+		if (*ch == ' ') count++;
+	}
+	char b[ParamCap - 2] = "bbbbbbbbbbbbb";
+	ircFormat("MODE %s -%.*s %s\r\n", idNames[id], count, b, params);
+}
+
 static void commandList(uint id, char *params) {
 	(void)id;
 	if (params) {
@@ -264,6 +288,7 @@ static const struct Handler {
 	bool restricted;
 } Commands[] = {
 	{ "/away", .fn = commandAway },
+	{ "/ban", .fn = commandBan },
 	{ "/close", .fn = commandClose },
 	{ "/copy", .fn = commandCopy, .restricted = true },
 	{ "/cs", .fn = commandCS },
@@ -287,6 +312,7 @@ static const struct Handler {
 	{ "/quit", .fn = commandQuit },
 	{ "/quote", .fn = commandQuote, .restricted = true },
 	{ "/topic", .fn = commandTopic },
+	{ "/unban", .fn = commandUnban },
 	{ "/whois", .fn = commandWhois },
 	{ "/window", .fn = commandWindow },
 };