summary refs log tree commit diff
path: root/command.c
diff options
context:
space:
mode:
authorC. McEnroe2020-02-11 22:39:29 -0500
committerC. McEnroe2020-02-11 22:39:29 -0500
commit10ae7bedbd1dac946ee97c3fb27676cde2237621 (patch)
tree9d9f3123d94681ffb9aa90b9c79211343609f1a8 /command.c
parent252428f97aa6a8f4e5b612757ce96d2d0d37e2f3 (diff)
Add -R restricted flag
Diffstat (limited to 'command.c')
-rw-r--r--command.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/command.c b/command.c
index 5cb43cf..3505a5e 100644
--- a/command.c
+++ b/command.c
@@ -194,25 +194,26 @@ static void commandHelp(size_t id, char *params) {
 static const struct Handler {
 	const char *cmd;
 	Command *fn;
+	bool restricted;
 } Commands[] = {
-	{ "/close", commandClose },
-	{ "/copy", commandCopy },
-	{ "/debug", commandDebug },
-	{ "/help", commandHelp },
-	{ "/join", commandJoin },
-	{ "/me", commandMe },
-	{ "/msg", commandMsg },
-	{ "/names", commandNames },
-	{ "/nick", commandNick },
-	{ "/notice", commandNotice },
-	{ "/open", commandOpen },
-	{ "/part", commandPart },
-	{ "/query", commandQuery },
-	{ "/quit", commandQuit },
-	{ "/quote", commandQuote },
-	{ "/topic", commandTopic },
-	{ "/whois", commandWhois },
-	{ "/window", commandWindow },
+	{ "/close", .fn = commandClose },
+	{ "/copy", .fn = commandCopy, .restricted = true },
+	{ "/debug", .fn = commandDebug, .restricted = true },
+	{ "/help", .fn = commandHelp },
+	{ "/join", .fn = commandJoin, .restricted = true },
+	{ "/me", .fn = commandMe },
+	{ "/msg", .fn = commandMsg, .restricted = true },
+	{ "/names", .fn = commandNames },
+	{ "/nick", .fn = commandNick },
+	{ "/notice", .fn = commandNotice },
+	{ "/open", .fn = commandOpen, .restricted = true },
+	{ "/part", .fn = commandPart },
+	{ "/query", .fn = commandQuery, .restricted = true },
+	{ "/quit", .fn = commandQuit },
+	{ "/quote", .fn = commandQuote, .restricted = true },
+	{ "/topic", .fn = commandTopic },
+	{ "/whois", .fn = commandWhois },
+	{ "/window", .fn = commandWindow },
 };
 
 static int compar(const void *cmd, const void *_handler) {
@@ -258,6 +259,9 @@ void command(size_t id, char *input) {
 		const struct Handler *handler = bsearch(
 			cmd, Commands, ARRAY_LEN(Commands), sizeof(*handler), compar
 		);
+		if (self.restricted && handler && handler->restricted) {
+			handler = NULL;
+		}
 		if (handler) {
 			if (input) {
 				input += strspn(input, " ");