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

Merge branch 'mlong/xtrnmenuv2' into 'master'

enhancements to external menu mod

See merge request !83
parents 44b55fc3 59a048b5
No related branches found
No related tags found
No related merge requests found
...@@ -9,11 +9,13 @@ ...@@ -9,11 +9,13 @@
"use strict"; "use strict";
load("sbbsdefs.js", "K_NONE"); require("sbbsdefs.js", "K_NONE");
/* text.dat entries */ /* text.dat entries */
require("text.js", "XtrnProgLstFmt"); require("text.js", "XtrnProgLstFmt");
var MENU_LOADED = true;
function ExternalMenus() { function ExternalMenus() {
this.options = {}; this.options = {};
this.xtrn_custommenu_options = {}; this.xtrn_custommenu_options = {};
...@@ -68,15 +70,6 @@ ExternalMenus.prototype.getOptions = function(menutype, menuid) { ...@@ -68,15 +70,6 @@ ExternalMenus.prototype.getOptions = function(menutype, menuid) {
if (this.options.singlecolumn_margin == undefined) if (this.options.singlecolumn_margin == undefined)
this.options.singlecolumn_margin = 7; this.options.singlecolumn_margin = 7;
if (typeof bbs !== "undefined") {
if (this.options.singlecolumn_height == undefined)
this.options.singlecolumn_height = console.screen_rows - this.options.singlecolumn_margin;
// override and turn off multicolumn if terminal width is less than 80
if (console.screen_columns < 80)
options.multicolumn = false;
}
if (this.options.restricted_user_msg === undefined) if (this.options.restricted_user_msg === undefined)
this.options.restricted_user_msg = system.text(R_ExternalPrograms); this.options.restricted_user_msg = system.text(R_ExternalPrograms);
...@@ -107,6 +100,10 @@ ExternalMenus.prototype.getOptions = function(menutype, menuid) { ...@@ -107,6 +100,10 @@ ExternalMenus.prototype.getOptions = function(menutype, menuid) {
if (this.options.section_which === undefined) if (this.options.section_which === undefined)
this.options.section_which = "\r\n\x01-\x01gWhich, \x01w\x01h~Q\x01n\x01guit or [1]: \x01h" this.options.section_which = "\r\n\x01-\x01gWhich, \x01w\x01h~Q\x01n\x01guit or [1]: \x01h"
if (typeof (this.options.use_xtrn_sec) == "undefined") {
this.options.use_xtrn_sec = false;
}
// if its a custom menu, then override with custommenu_options // if its a custom menu, then override with custommenu_options
if (menutype == 'custommenu') { if (menutype == 'custommenu') {
if (typeof this.xtrn_custommenu_options.multicolumn_fmt !== "undefined") { if (typeof this.xtrn_custommenu_options.multicolumn_fmt !== "undefined") {
...@@ -153,6 +150,13 @@ ExternalMenus.prototype.getOptions = function(menutype, menuid) { ...@@ -153,6 +150,13 @@ ExternalMenus.prototype.getOptions = function(menutype, menuid) {
if (typeof bbs !== "undefined") { if (typeof bbs !== "undefined") {
this.options.singlecolumn_height = (typeof this.xtrn_custommenu_options.singlecolumn_height !== "undefined") this.options.singlecolumn_height = (typeof this.xtrn_custommenu_options.singlecolumn_height !== "undefined")
? this.xtrn_custommenu_options.singlecolumn_height : this.options.singlecolumn_height; ? this.xtrn_custommenu_options.singlecolumn_height : this.options.singlecolumn_height;
if (this.options.singlecolumn_height == undefined)
this.options.singlecolumn_height = console.screen_rows - this.options.singlecolumn_margin;
// override and turn off multicolumn if terminal width is less than 80
if (console.screen_columns < 80)
options.multicolumn = false;
} }
// no need to override restricted_user_msg or no_programs_msg - these // no need to override restricted_user_msg or no_programs_msg - these
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
require("sbbsdefs.js", "K_NONE"); require("sbbsdefs.js", "K_NONE");
load("xtrnmenulib.js"); require("xtrnmenulib.js", "MENU_LOADED");
var options, xsec = -1; var options, xsec = -1;
...@@ -25,19 +25,28 @@ var options, xsec = -1; ...@@ -25,19 +25,28 @@ var options, xsec = -1;
var ExternalMenus = new ExternalMenus(); var ExternalMenus = new ExternalMenus();
const menuconfig = ExternalMenus.menuconfig; const menuconfig = ExternalMenus.menuconfig;
{
var i,j; var i,j;
if ((argv[0] == 'command') && (typeof argv[1] != "undefined")) {
docommand(argv[1]);
} else if (argv[0] == 'gamesrv') {
external_section_menu_custom('gamesrv');
} else {
for (i in argv) { for (i in argv) {
for (j in xtrn_area.sec_list) { for (j in xtrn_area.sec_list) {
if (argv[i].toLowerCase() == xtrn_area.sec_list[j].code) if (argv[i].toLowerCase() == xtrn_area.sec_list[j].code)
xsec = j; xsec = j;
} }
} }
}
if (xsec > -1) { if (xsec > -1) {
// if its the id of a standard section menu, send it to the // if its the id of a standard section menu
if (options.use_xtrn_sec) {
// stock menu // stock menu
js.exec("xtrn_sec.js", {}, xsec); js.exec("xtrn_sec.js", {}, xsec);
} else {
external_section_menu_custom(xsec);
}
} else if (typeof argv[0] !== "undefined") { } else if (typeof argv[0] !== "undefined") {
// if its not a section menu, assume it is a custom menu // if its not a section menu, assume it is a custom menu
external_section_menu_custom(argv[0]); external_section_menu_custom(argv[0]);
...@@ -45,7 +54,43 @@ if (xsec > -1) { ...@@ -45,7 +54,43 @@ if (xsec > -1) {
// main custom menu // main custom menu
external_section_menu_custom(); external_section_menu_custom();
} }
}
// Runs custom commands, for gamesrv
function docommand(command)
{
switch (command) {
case 'checkmail':
var lmsg = user.stats.mail_wait;
if (lmsg > 0) {
console.putmsg('\r\n\x01gYou have \x01c' + parseInt(lmsg) + ' \x01gMessages waiting');
} else {
console.putmsg('\r\n\x01gNo New Messages');
}
mswait(1500);
console.clear();
break;
case 'feedback':
var subject;
console.putmsg('\r\n\x01\gPlease choose \x01wYes \x01gto forward to netmail!\r\n\r\n');
bbs.email(1, subject = "Game Server Feedback\r\n");
console.putmsg('Thank you for your Feedback, @SYSOP@ will get back to you ASAP!\r\n\r\n');
break;
case 'prefs':
bbs.user_config();
break;
case 'sysop':
require("str_cmds.js", "str_cmds");
console.putmsg("\r\n\x01gCommand: ");
var commandstr;
commandstr = console.getstr();
str_cmds(commandstr);
break;
default:
doerror("Unknown command " + command);
break;
}
}
// Renders the top-level external menu // Renders the top-level external menu
function external_section_menu_custom(menuid) function external_section_menu_custom(menuid)
...@@ -55,6 +100,11 @@ function external_section_menu_custom(menuid) ...@@ -55,6 +100,11 @@ function external_section_menu_custom(menuid)
var validkeys = []; // valid chars on menu selection var validkeys = []; // valid chars on menu selection
var keymax = 0; // max integer allowed on menu selection var keymax = 0; // max integer allowed on menu selection
var gamesrv = menuid == "gamesrv" ? true : false;
if (gamesrv) {
menuid = undefined;
}
var options = ExternalMenus.getOptions('custommenu', menuid); var options = ExternalMenus.getOptions('custommenu', menuid);
menuobj = ExternalMenus.getMenu(menuid); menuobj = ExternalMenus.getMenu(menuid);
...@@ -66,10 +116,13 @@ function external_section_menu_custom(menuid) ...@@ -66,10 +116,13 @@ function external_section_menu_custom(menuid)
while (bbs.online) { while (bbs.online) {
console.aborted = false; console.aborted = false;
if (typeof menuobj === "undefined") {
menuobj = ExternalMenus.getSectionMenu(menuid);
if (typeof menuobj === "undefined") { if (typeof menuobj === "undefined") {
doerror(options.custom_menu_not_found_msg.replace('%MENUID%', menuid)); doerror(options.custom_menu_not_found_msg.replace('%MENUID%', menuid));
break; break;
} }
}
if (options.clear_screen) { if (options.clear_screen) {
console.clear(LIGHTGRAY); console.clear(LIGHTGRAY);
...@@ -85,8 +138,6 @@ function external_section_menu_custom(menuid) ...@@ -85,8 +138,6 @@ function external_section_menu_custom(menuid)
break; break;
} }
var keyin;
system.node_list[bbs.node_num-1].aux = 0; /* aux is 0, only if at menu */ system.node_list[bbs.node_num-1].aux = 0; /* aux is 0, only if at menu */
bbs.node_action = NODE_XTRN; bbs.node_action = NODE_XTRN;
bbs.node_sync(); bbs.node_sync();
...@@ -103,7 +154,6 @@ function external_section_menu_custom(menuid) ...@@ -103,7 +154,6 @@ function external_section_menu_custom(menuid)
// if no custom menu file in text/menu, create a dynamic one // if no custom menu file in text/menu, create a dynamic one
multicolumn = options.multicolumn && menuitemsfiltered.length > options.singlecolumn_height; multicolumn = options.multicolumn && menuitemsfiltered.length > options.singlecolumn_height;
printf(options.header_fmt, menuobj.title); printf(options.header_fmt, menuobj.title);
if(options.titles.trimRight() != '') if(options.titles.trimRight() != '')
write(options.titles); write(options.titles);
...@@ -204,6 +254,12 @@ function external_section_menu_custom(menuid) ...@@ -204,6 +254,12 @@ function external_section_menu_custom(menuid)
console.crlf(); console.crlf();
} }
if (gamesrv) {
if (!bbs.menu("xtrn_gamesrv_tail_" + menuid, P_NOERROR)) {
bbs.menu("xtrn_gamesrv_tail", P_NOERROR);
}
}
if (!bbs.menu("xtrnmenu_tail_" + menuid, P_NOERROR) && !bbs.menu("xtrnmenu_tail", P_NOERROR)) { if (!bbs.menu("xtrnmenu_tail_" + menuid, P_NOERROR) && !bbs.menu("xtrnmenu_tail", P_NOERROR)) {
bbs.menu("xtrn_tail", P_NOERROR); bbs.menu("xtrn_tail", P_NOERROR);
} }
...@@ -213,14 +269,54 @@ function external_section_menu_custom(menuid) ...@@ -213,14 +269,54 @@ function external_section_menu_custom(menuid)
} }
validkeys.push('q'); validkeys.push('q');
keyin = console.getkeys(validkeys, keymax, K_NONE);
var keyin, keyin2;
var maxkeylen = 0;
var maxfirstkey = 0;
var morekeys = [];
var k;
for (k in validkeys) {
if (validkeys[k].length > maxkeylen) {
maxkeylen = validkeys[k].length;
}
if (validkeys[k].length > 1) {
morekeys.push(validkeys[k].toString().toLowerCase().substring(0,1));
}
}
// get first key
keyin = console.getkey();
keyin = keyin.toString().toLowerCase(); keyin = keyin.toString().toLowerCase();
// The logic below is to make it not require enter for as
// many items as possible
// if max keys is 2 and they entered something that might have
// a second digit/char, then get the key
if (maxkeylen == 2) {
if (morekeys.indexOf(keyin) !== -1) {
write(keyin);
keyin2 = console.getkey(); // either the second digit or enter
if ((keyin2 != "\r") && (keyin2 != "\n") && (keyin2 != "\r\n")) {
keyin = keyin + keyin2.toLowerCase();
}
}
} else if (maxkeylen > 2) {
// there there are more than 99 items, then just use getkeys
// for the rest
write(keyin);
keyin2 = console.getkeys(validkeys, keymax);
keyin = keyin + keyin2.toLowerCase();
}
if (keyin) { if (keyin) {
// q for quit if (keyin == 'q') {
if (keyin == "q") { if (gamesrv && ('menuid' == 'main')) {
bbs.logoff();
} else {
console.clear(); console.clear();
break; return;
}
} }
menuitemsfiltered.some(function (menuitemfiltered) { menuitemsfiltered.some(function (menuitemfiltered) {
...@@ -235,8 +331,11 @@ function external_section_menu_custom(menuid) ...@@ -235,8 +331,11 @@ function external_section_menu_custom(menuid)
return true; return true;
// external program section // external program section
case 'xtrnmenu': case 'xtrnmenu':
if (options.use_xtrn_sec) {
js.exec("xtrn_sec.js", {}, menutarget); js.exec("xtrn_sec.js", {}, menutarget);
//js.exec(js.exec_dir + 'xtrn_sec.js ' + menutarget) } else {
external_section_menu_custom(menutarget);
}
return true; return true;
// external program // external program
case 'xtrnprog': case 'xtrnprog':
...@@ -248,6 +347,9 @@ function external_section_menu_custom(menuid) ...@@ -248,6 +347,9 @@ function external_section_menu_custom(menuid)
doerror(options.custom_menu_program_not_found_msg.replace('%PROGRAMID%', menutarget)); doerror(options.custom_menu_program_not_found_msg.replace('%PROGRAMID%', menutarget));
} }
break; break;
case 'command':
bbs.exec(menutarget);
return true;
} //switch } //switch
} // if menu item matched keyin } // if menu item matched keyin
}); // foreach menu item }); // foreach menu item
......
...@@ -383,7 +383,7 @@ var editItem = function(menuid, itemindex) { ...@@ -383,7 +383,7 @@ var editItem = function(menuid, itemindex) {
("target" in item ? item.target : ""))); ("target" in item ? item.target : "")));
displayoptionids.push("target"); displayoptionids.push("target");
if (item.type == "custommenu") { if ((item.type == "custommenu") || (item.type == "command")) {
displayoptions.push(format("%23s: %s", "access_string", displayoptions.push(format("%23s: %s", "access_string",
("access_string" in item ? item.access_string : "(default)"))); ("access_string" in item ? item.access_string : "(default)")));
displayoptionids.push("access_string"); displayoptionids.push("access_string");
...@@ -490,7 +490,8 @@ function present_select_targettype(item) ...@@ -490,7 +490,8 @@ function present_select_targettype(item)
"This is the type of target this item points to.\r\n\r\n" "This is the type of target this item points to.\r\n\r\n"
+ "custommenu is a custom menu defined in this tool.\r\n\r\n" + "custommenu is a custom menu defined in this tool.\r\n\r\n"
+ "xtrnmenu is a standard Syncrhonet External Section Menu (refer to the scfg tool).\r\n\r\n" + "xtrnmenu is a standard Syncrhonet External Section Menu (refer to the scfg tool).\r\n\r\n"
+ "xtrnprog is a direct link to an external program (refer to the scfg tool)"); + "xtrnprog is a direct link to an external program (refer to the scfg tool)"
+ "command is a synchronet command line. See http://wiki.synchro.net/config:cmdline");
var targetypectx = uifc.list.CTX(0, 0, 0, 0, 0); var targetypectx = uifc.list.CTX(0, 0, 0, 0, 0);
if (typeof item.type !== "undefined") { if (typeof item.type !== "undefined") {
...@@ -507,10 +508,14 @@ function present_select_targettype(item) ...@@ -507,10 +508,14 @@ function present_select_targettype(item)
targetypectx.cur = 2; targetypectx.cur = 2;
targetypectx.bar = 2; targetypectx.bar = 2;
break; break;
case 'command':
targetypectx.cur = 3;
targetypectx.bar = 3;
break;
} }
} }
switch (uifc.list(WIN_ORG | WIN_MID | WIN_SAV, switch (uifc.list(WIN_ORG | WIN_MID | WIN_SAV,
"Target Type", ["custommenu", "xtrnmenu", "xtrnprog"], targetypectx)) { "Target Type", ["custommenu", "xtrnmenu", "xtrnprog", "command"], targetypectx)) {
case 0: case 0:
item.type = "custommenu"; item.type = "custommenu";
break; break;
...@@ -520,6 +525,9 @@ function present_select_targettype(item) ...@@ -520,6 +525,9 @@ function present_select_targettype(item)
case 2: case 2:
item.type = "xtrnprog"; item.type = "xtrnprog";
break; break;
case 3:
item.type = "command";
break;
default: default:
// includes escape key // includes escape key
break; break;
...@@ -655,6 +663,15 @@ function present_select_target(item) ...@@ -655,6 +663,15 @@ function present_select_target(item)
} }
break; break;
command:
selection2 = uifc.input(WIN_ORG | WIN_MID, "Command", item.target, 63, K_EDIT);
if ((selection2 < 0) || (selection2 == null)) {
// escape key
break;
}
item.target = selection2;
break;
default: default:
selection2 = uifc.input(WIN_ORG | WIN_MID, "Target", item.target, 50, K_EDIT); selection2 = uifc.input(WIN_ORG | WIN_MID, "Target", item.target, 50, K_EDIT);
if ((selection2 < 0) || (selection2 == null)) { if ((selection2 < 0) || (selection2 == null)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment