Browse Source

Add restricted mode

master
Causal Agent 2 months ago
parent
commit
c5718dd82f
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 39 additions and 24 deletions
  1. +10
    -2
      catgirl.1
  2. +2
    -1
      chat.c
  3. +1
    -0
      chat.h
  4. +26
    -21
      input.c

+ 10
- 2
catgirl.1 View File

@@ -1,4 +1,4 @@
.Dd July 2, 2019
.Dd September 16, 2019
.Dt CATGIRL 1
.Os
.
@@ -8,7 +8,7 @@
.
.Sh SYNOPSIS
.Nm
.Op Fl Nv
.Op Fl NRv
.Op Fl W Ar pass
.Op Fl a Ar auth
.Op Fl h Ar host
@@ -33,6 +33,14 @@ The arguments are as follows:
Send notifications with
.Xr notify-send 1 .
.
.It Fl R
Restrict the use of the
.Ic /join ,
.Ic /query ,
.Ic /quote ,
.Ic /raw
commands.
.
.It Fl W Ar pass
Send
.Cm WEBIRC

+ 2
- 1
chat.c View File

@@ -53,9 +53,10 @@ int main(int argc, char *argv[]) {
setlocale(LC_CTYPE, "");

int opt;
while (0 < (opt = getopt(argc, argv, "NW:a:h:j:k:l:n:p:r:u:vw:"))) {
while (0 < (opt = getopt(argc, argv, "NRW:a:h:j:k:l:n:p:r:u:vw:"))) {
switch (opt) {
break; case 'N': self.notify = true;
break; case 'R': self.limit = true;
break; case 'W': self.webp = dupe(optarg);
break; case 'a': self.auth = dupe(optarg);
break; case 'h': self.host = dupe(optarg);

+ 1
- 0
chat.h View File

@@ -44,6 +44,7 @@ struct {
char *real;
char *join;
char *keys;
bool limit;
bool raw;
bool notify;
bool quit;

+ 26
- 21
input.c View File

@@ -195,28 +195,29 @@ static void inputWindow(struct Tag tag, char *params) {
static const struct {
const char *command;
Handler *handler;
bool limit;
} Commands[] = {
{ "/close", inputClose },
{ "/help", inputMan },
{ "/join", inputJoin },
{ "/list", inputList },
{ "/man", inputMan },
{ "/me", inputMe },
{ "/move", inputMove },
{ "/names", inputWho },
{ "/nick", inputNick },
{ "/open", inputOpen },
{ "/part", inputPart },
{ "/query", inputQuery },
{ "/quit", inputQuit },
{ "/quote", inputQuote },
{ "/raw", inputRaw },
{ "/topic", inputTopic },
{ "/url", inputURL },
{ "/who", inputWho },
{ "/whois", inputWhois },
{ "/window", inputWindow },
{ "/znc", inputZNC },
{ "/close", .handler = inputClose },
{ "/help", .handler = inputMan },
{ "/join", .handler = inputJoin, .limit = true },
{ "/list", .handler = inputList },
{ "/man", .handler = inputMan },
{ "/me", .handler = inputMe },
{ "/move", .handler = inputMove },
{ "/names", .handler = inputWho },
{ "/nick", .handler = inputNick },
{ "/open", .handler = inputOpen },
{ "/part", .handler = inputPart },
{ "/query", .handler = inputQuery, .limit = true },
{ "/quit", .handler = inputQuit },
{ "/quote", .handler = inputQuote, .limit = true },
{ "/raw", .handler = inputRaw, .limit = true },
{ "/topic", .handler = inputTopic },
{ "/url", .handler = inputURL },
{ "/who", .handler = inputWho },
{ "/whois", .handler = inputWhois },
{ "/window", .handler = inputWindow },
{ "/znc", .handler = inputZNC },
};
static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]);

@@ -264,6 +265,10 @@ void input(struct Tag tag, char *input) {

for (size_t i = 0; i < CommandsLen; ++i) {
if (strcasecmp(command, Commands[i].command)) continue;
if (self.limit && Commands[i].limit) {
uiFmt(tag, UIHot, "%s isn't available in restricted mode", command);
return;
}
Commands[i].handler(tag, input);
return;
}

Loading…
Cancel
Save