Permalink
Browse files

Reset console draft. Closes #311

* Add a resetconsole dcc and Tcl command. 
* Set default console flags in C code and eggdrop-basic.conf, fix channel parsing in .resetconsole
* Add new default logmode
  • Loading branch information...
thommey authored and vanosg committed Sep 27, 2017
1 parent b485214 commit ab40ee3d719353340be646b8e59a3df07cfe488d
Showing with 95 additions and 38 deletions.
  1. +10 −0 doc/sphinx_source/mainDocs/tcl-commands.rst
  2. +8 −0 help/cmds1.help
  3. +2 −1 src/chanprog.c
  4. +36 −16 src/cmds.c
  5. +39 −21 src/tcldcc.c
@@ -1392,6 +1392,16 @@ console <idx> [channel] [console-modes]
Module: core
^^^^^^^^^^^^^^^^^^
resetconsole <idx>
^^^^^^^^^^^^^^^^^^
Description: changes a dcc user's console mode to the default setting in the configfile.
Returns: a list containing the user's channel view and (new) console modes, or nothing if that user isn't currently on the partyline
Module: core
^^^^^^^^^^^^^^^^^^^
echo <idx> [status]
^^^^^^^^^^^^^^^^^^^
View
@@ -268,6 +268,14 @@ See also: chhandle
### %bconsole%b <user> [channel] [modes]
This is used to set the console level of another user. This can even be used
on users who normally would not be able to set their own console mode.
%{help=resetconsole}%{+to|o}
### %bresetconsole%b
Changes your console level to the default settings from the configfile.
%{+m|m}
### %bresetconsole%b <user>
This is used to reset the console level of another user to the default
setting from the configfile. This can even be used on users who normally
would not be able to set their own console mode.
%{help=dccstat}%{+m}
### %bdccstat%b
Displays a table-format list of all "dcc" connections in use on the bot.
View
@@ -450,7 +450,8 @@ void chanprog()
admin[0] = 0;
helpdir[0] = 0;
conmask = 0;
/* default mkcoblxs */
conmask = LOG_MSGS|LOG_MODES|LOG_CMDS|LOG_MISC|LOG_BOTS|LOG_BOTMSG|LOG_FILES|LOG_SERV;
for (i = 0; i < max_logs; i++)
logs[i].flags |= LF_EXPIRING;
View
@@ -641,33 +641,29 @@ static void cmd_boot(struct userrec *u, int idx, char *par)
dprintf(idx, "Who? No such person on the party line.\n");
}
static void cmd_console(struct userrec *u, int idx, char *par)
/* Make changes to user console settings */
static void do_console(struct userrec *u, int idx, char *par, int reset)
{
char *nick, s[2], s1[512];
int dest = 0, i, ok = 0, pls;
struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
module_entry *me;
if (!par[0]) {
dprintf(idx, "Your console is %s: %s (%s).\n",
dcc[idx].u.chat->con_chan,
masktype(dcc[idx].u.chat->con_flags),
maskname(dcc[idx].u.chat->con_flags));
return;
}
get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
strncpyz(s1, par, sizeof s1);
nick = newsplit(&par);
/* Don't remove '+' as someone couldn't have '+' in CHANMETA cause
/* Check if the parameter is a handle.
* Don't remove '+' as someone couldn't have '+' in CHANMETA cause
* he doesn't use IRCnet ++rtc.
*/
if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
for (i = 0; i < dcc_total; i++)
for (i = 0; i < dcc_total; i++) {
if (!egg_strcasecmp(nick, dcc[i].nick) &&
(dcc[i].type == &DCC_CHAT) && (!ok)) {
ok = 1;
dest = i;
}
}
if (!ok) {
dprintf(idx, "No such user on the party line!\n");
return;
@@ -677,9 +673,11 @@ static void cmd_console(struct userrec *u, int idx, char *par)
dest = idx;
if (!nick[0])
nick = newsplit(&par);
/* Consider modeless channels, starting with '+' */
if ((nick[0] == '+' && findchan_by_dname(nick)) ||
(nick[0] != '+' && strchr(CHANMETA "*", nick[0]))) {
/* Check if the parameter is a channel.
* Consider modeless channels, starting with '+'
*/
if (nick[0] && !reset && ((nick[0] == '+' && findchan_by_dname(nick)) ||
(nick[0] != '+' && strchr(CHANMETA "*", nick[0])))) {
if (strcmp(nick, "*") && !findchan_by_dname(nick)) {
dprintf(idx, "Invalid console channel: %s.\n", nick);
return;
@@ -690,15 +688,16 @@ static void cmd_console(struct userrec *u, int idx, char *par)
nick);
return;
}
strncpyz(dcc[dest].u.chat->con_chan, nick, 81);
strncpyz(dcc[dest].u.chat->con_chan, nick,
sizeof dcc[dest].u.chat->con_chan);
nick[0] = 0;
if (dest != idx)
get_user_flagrec(dcc[dest].user, &fr, dcc[dest].u.chat->con_chan);
}
if (!nick[0])
nick = newsplit(&par);
pls = 1;
if (nick[0]) {
if (!reset && nick[0]) {
if ((nick[0] != '+') && (nick[0] != '-'))
dcc[dest].u.chat->con_flags = 0;
for (; *nick; nick++) {
@@ -715,10 +714,12 @@ static void cmd_console(struct userrec *u, int idx, char *par)
dcc[dest].u.chat->con_flags &= ~logmodes(s);
}
}
} else if (reset) {
dcc[dest].u.chat->con_flags = (u->flags & USER_MASTER) ? conmask : 0;
}
dcc[dest].u.chat->con_flags = check_conflags(&fr,
dcc[dest].u.chat->con_flags);
putlog(LOG_CMDS, "*", "#%s# console %s", dcc[idx].nick, s1);
putlog(LOG_CMDS, "*", "#%s# %sconsole %s", dcc[idx].nick, reset ? "reset" : "", s1);
if (dest == idx) {
dprintf(idx, "Set your console to %s: %s (%s).\n",
dcc[idx].u.chat->con_chan,
@@ -742,6 +743,24 @@ static void cmd_console(struct userrec *u, int idx, char *par)
}
}
static void cmd_console(struct userrec *u, int idx, char *par)
{
if (!par[0]) {
dprintf(idx, "Your console is %s: %s (%s).\n",
dcc[idx].u.chat->con_chan,
masktype(dcc[idx].u.chat->con_flags),
maskname(dcc[idx].u.chat->con_flags));
return;
}
do_console(u, idx, par, 0);
}
/* Reset console flags to config defaults */
static void cmd_resetconsole(struct userrec *u, int idx, char *par)
{
do_console(u, idx, par, 1);
}
static void cmd_pls_bot(struct userrec *u, int idx, char *par)
{
char *handle, *addr, *port, *relay, *host;
@@ -2904,6 +2923,7 @@ cmd_t C_dcc[] = {
{"chpass", "t", (IntFunc) cmd_chpass, NULL},
{"comment", "m", (IntFunc) cmd_comment, NULL},
{"console", "to|o", (IntFunc) cmd_console, NULL},
{"resetconsole", "to|o", (IntFunc) cmd_resetconsole, NULL},
{"dccstat", "t", (IntFunc) cmd_dccstat, NULL},
{"debug", "m", (IntFunc) cmd_debug, NULL},
{"die", "n", (IntFunc) cmd_die, NULL},
View
@@ -30,7 +30,7 @@ extern Tcl_Interp *interp;
extern tcl_timer_t *timer, *utimer;
extern struct dcc_t *dcc;
extern char botnetnick[];
extern int dcc_total, backgrd, parties, make_userfile, do_restart, remote_boots, max_dcc;
extern int dcc_total, backgrd, parties, make_userfile, do_restart, remote_boots, max_dcc, conmask;
#ifdef TLS
extern int tls_vfydcc;
extern sock_list *socklist;
@@ -280,13 +280,12 @@ static int tcl_dccputchan STDVAR
return TCL_OK;
}
static int tcl_console STDVAR
static int tcl_do_console(Tcl_Interp *irp, ClientData cd, int argc,
char **argv, int reset)
{
int i, j, pls, arg;
module_entry *me;
BADARGS(2, 4, " idx ?channel? ?console-modes?");
i = findidx(atoi(argv[1]));
if (i < 0 || dcc[i].type != &DCC_CHAT) {
Tcl_AppendResult(irp, "invalid idx", NULL);
@@ -295,8 +294,8 @@ static int tcl_console STDVAR
pls = 1;
for (arg = 2; arg < argc; arg++) {
if (argv[arg][0] && ((strchr(CHANMETA, argv[arg][0]) != NULL) ||
(argv[arg][0] == '*'))) {
if (argv[arg][0] && !reset && ((strchr(CHANMETA, argv[arg][0])
!= NULL) || (argv[arg][0] == '*'))) {
if ((argv[arg][0] != '*') && (!findchan_by_dname(argv[arg]))) {
/* If we dont find the channel, and it starts with a +, assume it
* should be the console flags to set. */
@@ -307,23 +306,28 @@ static int tcl_console STDVAR
}
strncpyz(dcc[i].u.chat->con_chan, argv[arg], 81);
} else {
if ((argv[arg][0] != '+') && (argv[arg][0] != '-'))
if (!reset && (argv[arg][0] != '+') && (argv[arg][0] != '-'))
dcc[i].u.chat->con_flags = 0;
do_console_flags:
for (j = 0; j < strlen(argv[arg]); j++) {
if (argv[arg][j] == '+')
pls = 1;
else if (argv[arg][j] == '-')
pls = -1;
else {
char s[2];
s[0] = argv[arg][j];
s[1] = 0;
if (pls == 1)
dcc[i].u.chat->con_flags |= logmodes(s);
else
dcc[i].u.chat->con_flags &= ~logmodes(s);
if (reset) {
dcc[i].u.chat->con_flags =
(dcc[i].user && (dcc[i].user->flags & USER_MASTER) ? conmask : 0);
} else {
for (j = 0; j < strlen(argv[arg]); j++) {
if (argv[arg][j] == '+')
pls = 1;
else if (argv[arg][j] == '-')
pls = -1;
else {
char s[2];
s[0] = argv[arg][j];
s[1] = 0;
if (pls == 1)
dcc[i].u.chat->con_flags |= logmodes(s);
else
dcc[i].u.chat->con_flags &= ~logmodes(s);
}
}
}
}
@@ -339,6 +343,19 @@ static int tcl_console STDVAR
return TCL_OK;
}
static int tcl_console STDVAR
{
BADARGS(2, 4, " idx ?channel? ?console-modes?");
return tcl_do_console(irp, cd, argc, argv, 0);
}
static int tcl_resetconsole STDVAR
{
BADARGS(2, 2, " idx");
return tcl_do_console(irp, cd, argc, argv, 1);
}
static int tcl_strip STDVAR
{
int i, j, pls, arg;
@@ -1179,6 +1196,7 @@ tcl_cmds tcldcc_cmds[] = {
{"setchan", tcl_setchan},
{"dccputchan", tcl_dccputchan},
{"console", tcl_console},
{"resetconsole", tcl_resetconsole},
{"strip", tcl_strip},
{"echo", tcl_echo},
{"page", tcl_page},

0 comments on commit ab40ee3

Please sign in to comment.