Skip to content
Snippets Groups Projects
Commit 57760c92 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add a configurable 'user list' module

Also modifying the existing (sample) userlist.js to mimic the hard-coded
sbbs_t::userlist() function (from str.cpp), suitable as a user list
module. Also added sort-by-laston-date functionality to this module,
thus fixing issue #518.
parent 67fdd8dc
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3831 passed
// userlist.js
// A sample user listing script for Synchronet v3.1+
// $Id: userlist.js,v 1.6 2019/01/11 09:37:25 rswindell Exp $
// A user listing module for Synchronet v3.1+
"use strict";
require("sbbsdefs.js", 'USER_DELETED');
require("text.js", 'UserListFmt');
var lastuser = system.lastuser;
var u = new User;
var list = [];
var mode = Number(argv[0]);
function aborted()
{
return js.global.console != undefined && console.aborted == true;
}
function print_user(u)
{
var name = format("%s #%u", u.alias, u.number);
console.print(format(bbs.text(UserListFmt)
,name
,system.settings & SYS_LISTLOC ? u.location : u.note
,system.datestr(u.stats.laston_date)
,u.connection
));
}
console.mnemonics("Sort by User ~Name, ~Last-on Date or [#]: ");
var sort = console.getkeys("NL#");
if(sort != 'N' && sort != 'L')
sort = false;
else
console.putmsg(bbs.text(CheckingSlots));
var users = 0;
for(var i = 1; i <= lastuser; i++) {
if(aborted())
exit(0);
if(sort)
console.print(format("%-4d\b\b\b\b", i));
u.number = i;
if(u.settings&USER_DELETED)
if(u.settings & (USER_DELETED | USER_INACTIVE))
continue;
printf("%d/%d ",i,lastuser);
printf("%-30s %-30s %s\r\n"
,u.alias
,u.location
,u.connection
);
if(js.global.console != undefined && console.aborted == true)
++users;
switch(mode) {
case UL_SUB:
var sub = msg_area.sub[bbs.cursub_code];
if(!u.compare_ars(msg_area.grp[sub.grp_name].ars))
continue;
if(!u.compare_ars(sub.ars))
continue;
break;
case UL_DIR:
var dir = file_area.dir[bbs.curdir_code];
if(!u.compare_ars(file_area.lib[dir.lib_name].ars))
continue;
if(!u.compare_ars(dir.ars))
continue;
break;
}
if(sort)
list.push( { number: u.number
, alias: u.alias
, location: u.location
, note: u.note
, connection: u.connection
, stats: { laston_date: u.stats.laston_date }
});
else
print_user(u);
}
if(!sort)
console.crlf();
console.print(format(bbs.text(NTotalUsers), users));
if(mode == UL_SUB)
console.print(format(bbs.text(NUsersOnCurSub), list.length));
else if(mode == UL_DIR)
console.print(format(bbs.text(NUsersOnCurDir), list.length));
if(!sort)
exit(0);
switch(sort) {
case 'L':
list.sort(function(a, b) { return a.stats.laston_date - b.stats.laston_date; });
break;
case 'N':
list.sort(function(a, b) { if(a.alias.toLowerCase() > b.alias.toLowerCase()) return 1; return -1; });
break;
}
\ No newline at end of file
}
for(var i in list) {
if(aborted())
break;
print_user(list[i]);
}
......@@ -2612,6 +2612,7 @@ void sys_cfg(void)
sprintf(opt[i++],"%-16.16s%s","List Msgs",cfg.listmsgs_mod);
sprintf(opt[i++],"%-16.16s%s","List Logons",cfg.logonlist_mod);
sprintf(opt[i++],"%-16.16s%s","List Nodes",cfg.nodelist_mod);
sprintf(opt[i++],"%-16.16s%s","List Users",cfg.userlist_mod);
sprintf(opt[i++],"%-16.16s%s","Who's Online",cfg.whosonline_mod);
sprintf(opt[i++],"%-16.16s%s","Private Msg",cfg.privatemsg_mod);
sprintf(opt[i++],"%-16.16s%s","Temp Transfer",cfg.tempxfer_mod);
......@@ -2642,6 +2643,7 @@ void sys_cfg(void)
"`List Msgs` Executed when a user lists msgs from the msg read prompt\n"
"`List Logons` Executed when a user lists logons ('-y' for yesterday)\n"
"`List Nodes` Executed when a user lists all nodes\n"
"`List Users` Executed when a user lists the users of the system\n"
"`Who's Online` Executed when a user lists the nodes in-use (e.g. `^U`)\n"
"`Private Msg` Executed when a user sends a private node msg (e.g. `^P`)\n"
"\n"
......@@ -2728,14 +2730,18 @@ void sys_cfg(void)
,cfg.nodelist_mod,sizeof(cfg.nodelist_mod)-1,K_EDIT);
break;
case 18:
uifc.input(WIN_MID|WIN_SAV,0,0,"List Users"
,cfg.userlist_mod,sizeof(cfg.userlist_mod)-1,K_EDIT);
break;
case 19:
uifc.input(WIN_MID|WIN_SAV,0,0,"Who's Online Module"
,cfg.whosonline_mod,sizeof(cfg.whosonline_mod)-1,K_EDIT);
break;
case 19:
case 20:
uifc.input(WIN_MID|WIN_SAV,0,0,"Private Message Module"
,cfg.privatemsg_mod,sizeof(cfg.privatemsg_mod)-1,K_EDIT);
break;
case 20:
case 21:
uifc.input(WIN_MID|WIN_SAV,0,0,"Temporary File Transfer Module"
,cfg.tempxfer_mod, sizeof(cfg.tempxfer_mod)-1, K_EDIT);
break;
......
......@@ -612,6 +612,7 @@ typedef struct
char whosonline_mod[LEN_CMD+1];
char privatemsg_mod[LEN_CMD+1];
char logonlist_mod[LEN_CMD+1];
char userlist_mod[LEN_CMD+1];
char prextrn_mod[LEN_CMD+1]; /* External Program pre-execution module */
char postxtrn_mod[LEN_CMD+1]; /* External Program post-execution module */
char tempxfer_mod[LEN_CMD+1];
......
......@@ -243,6 +243,7 @@ BOOL read_main_cfg(scfg_t* cfg, char* error, size_t maxerrlen)
SAFECOPY(cfg->automsg_mod, iniGetString(section, NULL, "automsg", "automsg", value));
SAFECOPY(cfg->xtrnsec_mod, iniGetString(section, NULL, "xtrnsec", "xtrn_sec", value));
SAFECOPY(cfg->nodelist_mod, iniGetString(section, NULL, "nodelist", "nodelist", value));
SAFECOPY(cfg->userlist_mod, iniGetString(section, NULL, "userlist", "", value));
SAFECOPY(cfg->whosonline_mod, iniGetString(section, NULL, "whosonline", "nodelist -active", value));
SAFECOPY(cfg->privatemsg_mod, iniGetString(section, NULL, "privatemsg", "privatemsg", value));
SAFECOPY(cfg->logonlist_mod, iniGetString(section, NULL, "logonlist", "logonlist", value));
......
......@@ -248,12 +248,13 @@ BOOL write_main_cfg(scfg_t* cfg, int backup_level)
iniSetString(&ini, name, "textsec", cfg->textsec_mod, NULL);
iniSetString(&ini, name, "automsg", cfg->automsg_mod, NULL);
iniSetString(&ini, name, "xtrnsec", cfg->xtrnsec_mod, NULL);
iniSetString(&ini, name, "userlist", cfg->userlist_mod, NULL);
iniSetString(&ini, name, "nodelist", cfg->nodelist_mod, NULL);
iniSetString(&ini, name, "whosonline", cfg->whosonline_mod, NULL);
iniSetString(&ini, name, "privatemsg", cfg->privatemsg_mod, NULL);
iniSetString(&ini, name, "logonlist", cfg->logonlist_mod, NULL);
iniSetString(&ini, name, "prextrn", cfg->prextrn_mod, NULL);
iniSetString(&ini, name, "postxtrn", cfg->postxtrn_mod, NULL);
......
......@@ -33,6 +33,12 @@ void sbbs_t::userlist(int mode)
char * line[2500];
user_t user;
if(cfg.userlist_mod[0] != '\0') {
char str[128];
SAFEPRINTF2(str, "%s %d", cfg.userlist_mod, mode);
exec_bin(str, &main_csi);
return;
}
if(lastuser(&cfg)<=(int)(sizeof(line)/sizeof(line[0])))
sort=yesno(text[SortAlphaQ]);
if(sort) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment