Skip to content

Commit

Permalink
fix chanset to accept multiple args
Browse files Browse the repository at this point in the history
  • Loading branch information
vanosg committed Jan 13, 2024
1 parent b774e92 commit e0b6a6a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/mod/channels.mod/channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static Function *global = NULL;
static char chanfile[121], glob_chanmode[65];
static char *lastdeletedmask;

static p_tcl_bind_list H_chanset;

static struct udef_struct *udef;

static int use_info, chan_hack, quiet_save, global_revenge_mode,
Expand Down Expand Up @@ -241,6 +243,32 @@ static void get_mode_protect(struct chanset_t *chan, char *s)
}
}

static int builtin_chanset STDVAR
{
Function F = (Function) cd;

BADARGS(4, 4, " chan, setting, type, value");

CHECKVALIDITY(builtin_chanset);
F(argv[1], argv[2], argv[3]);
return TCL_OK;
}

int check_tcl_chanset(const char *chan, const char *setting, const char *type, const char *value)
{
int x;

Tcl_SetVar(interp, "_chanset1", (char *) chan, 0);
Tcl_SetVar(interp, "_chanset2", (char *) setting, 0);
Tcl_SetVar(interp, "_chanset3", (char *) type, 0);
Tcl_SetVar(interp, "_chanset4", (char *) value, 0);

x = check_tcl_bind(H_chanset, chan, 0, " $_chanset1 $_chanset2 $_chanset3 $_chanset4",
BIND_STACKABLE | BIND_WANTRET);

return 0;
}

/* Returns true if this is one of the channel masks
*/
static int ismodeline(masklist *m, char *user)
Expand Down
19 changes: 14 additions & 5 deletions src/mod/channels.mod/cmdschan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ static void cmd_chaninfo(struct userrec *u, int idx, char *par)

static void cmd_chanset(struct userrec *u, int idx, char *par)
{
char *chname = NULL, answers[512], *parcpy;
char *chname = NULL, answers[1024], *parcpy;
char *list[2], *bak, *buf;
struct chanset_t *chan = NULL;
int all = 0;
Expand Down Expand Up @@ -1555,6 +1555,14 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
return;
}
list[1] = par;
/* Don't send any follow-on arguments if this is an integer value */
list[1] = newsplit(&par);
/*
ptr = strchr(list[1], ' ');
if (ptr != NULL) {
*ptr = '\0';
}
*/
/* Par gets modified in tcl_channel_modify under some
* circumstances, so save it now.
*/
Expand All @@ -1563,18 +1571,19 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
irp = Tcl_CreateInterp();
if (tcl_channel_modify(irp, chan, 2, list) == TCL_OK) {
int len = strlen(answers);
egg_snprintf(answers + len, (sizeof answers) - len, "%s { %s }", list[0], parcpy); /* Concatenation */
egg_snprintf(answers + len, (sizeof answers) - len, "%s { %s } ", list[0], list[1]); /* Concatenation */
} else if (!all || !chan->next)
dprintf(idx, "Error trying to set %s for %s, %s\n",
list[0], all ? "all channels" : chname, Tcl_GetStringResult(irp));
Tcl_ResetResult(irp);
Tcl_DeleteInterp(irp);
nfree(parcpy);
list[0] = newsplit(&par);
list[1] = '\0';
}
break;
}
if (!all && answers[0]) {
dprintf(idx, "Successfully set modes { %s } on %s.\n", answers,
dprintf(idx, "Successfully set modes { %s} on %s.\n", answers,
chname);
putlog(LOG_CMDS, "*", "#%s# chanset %s %s", dcc[idx].nick, chname,
answers);
Expand All @@ -1585,7 +1594,7 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
chan = chan->next;
}
if (all && answers[0]) {
dprintf(idx, "Successfully set modes { %s } on all channels.\n",
dprintf(idx, "Successfully set modes { %s} on all channels.\n",
answers);
putlog(LOG_CMDS, "*", "#%s# chanset * %s", dcc[idx].nick, answers);
}
Expand Down

0 comments on commit e0b6a6a

Please sign in to comment.