Improved inactivity timeout and function key detection

This commit is contained in:
Deon George 2020-07-24 23:00:35 +10:00
parent 17ddda1cd5
commit 5293c8cb33
3 changed files with 71 additions and 21 deletions

View File

@ -49,6 +49,9 @@ var INACTIVE ='\1n\1h\1RINACTIVITY DISCONNECT';
var NO_HISTORY_FRAMES =['980a','98b','981a'];
var SYSTEM_OWNER =9;
var INKEY_TIMEOUT =10000;
var INACTIVE_NOLOGIN =1000;
var INACTIVE_LOGIN =5*60000;
// Our frame object
function TexFrame() {

View File

@ -218,7 +218,7 @@ function pageEditor(page) {
log(LOG_DEBUG,' - pageEditor: p='+p+'('+p.length+') user ['+JSON.stringify(frameusers)+'] - :'+frameusers.indexOf(user.number.toString()));
var re = new RegExp('^' + p, 'g');
if (page.toString().match(re) && (frameusers.indexOf(user.number.toString()) == 1)) {
if (page.toString().match(re) && (frameusers.indexOf(user.number.toString()) !== -1)) {
pageditor = true;
throw BreakException;
}

87
main.js
View File

@ -26,7 +26,7 @@ while(bbs.online) {
var next_page = user.number ? { frame: 98,index: 'b' } : { frame: 980,index: 'a' }; // Start Frame
var action = ACTION_GOTO; // Initial action
var inkey_timeout = 60000; // Timeout waiting for input
var inkey_timeout = INKEY_TIMEOUT; // Timeout waiting for input
var fo = null; // Current Frame
var fn = null; // Current Field Number for an Input Frame
var fe = null; // Frame to edit
@ -38,40 +38,87 @@ while(bbs.online) {
var timeout = false; // Track our inactivity timeout
var timer = time();
var control = []; // Methods that need to process input
var extendedkey = ''; // Current Extended Key being captured
ansi.send('ext_mode','clear','cursor');
while (action != ACTION_TERMINATE && action !=ACTION_EXIT) {
bbs.nodesync(false); // @todo Stop the display of telegrams
read = '';
var read = '';
var esc = false;
// If we have no action, read from the terminal
if (action == false) {
read = console.inkey(K_NONE,inkey_timeout);
if (read == '' && ! (user.security.exemptions&UFLAG_H) ) {
if (time() > timer+inkey_timeout/1000) {
sendBaseline(INACTIVE,false);
bbs.hangup();
while (esc || ! read) {
log(LOG_DEBUG,'- READ START');
read = console.inkey(K_NONE,inkey_timeout);
// We are intering a special keyboard char.
if (read == KEY_ESC) {
log(LOG_DEBUG,'- READ SPECIAL KEY COMING');
esc = true;
inkey_timeout = 200;
} else if (esc && ! extendedkey && read != '[') {
log(LOG_DEBUG,'- READ SPECIAL KEY ABANDONED: ['+read+'] ('+read.charCodeAt(0)+')');
esc = false;
inkey_timeout = INKEY_TIMEOUT;
read = KEY_ESC;
} else if (esc && extendedkey && (read == '~' || read == ';')) {
switch (extendedkey) {
case '[15': read = false; break; // F5
case '[17': read = false; break; // F6
case '[18': read = false; break; // F7
case '[19': read = false; break; // F8
case '[20': read = false; break; // F9
case '[21': read = false; break; // F10
case '[23': read = false; break; // F11
case '[24': read = false; break; // F12
default:
log(LOG_DEBUG,'- READ UNKNOWN KEY: ['+extendedkey+']');
read = '';
}
esc = false;
extendedkey = '';
inkey_timeout = INKEY_TIMEOUT;
} else if (esc) {
log(LOG_DEBUG,'- READ SPECIAL KEY ['+read+'] ('+read.charCodeAt(0)+')');
extendedkey += read;
read = false;
}
if (read === '' && ! (user.security.exemptions&UFLAG_H) ) {
if (time() > timer+((user.number ? INACTIVE_LOGIN : INACTIVE_NOLOGIN)+INKEY_TIMEOUT)/1000) {
sendBaseline(INACTIVE,false);
bbs.hangup();
} else if (time() > timer+(user.number ? INACTIVE_LOGIN : INACTIVE_NOLOGIN)/1000) {
timeout = true;
sendBaseline(INACTIVITY,false);
if (cf)
console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m');
}
} else {
timeout = true;
sendBaseline(INACTIVITY,false);
if (timeout) {
sendBaseline('',false);
if (cf)
console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m');
if (cf)
console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m');
}
timer = time();
timeout = false;
}
} else {
if (timeout) {
sendBaseline('',false);
if (cf)
console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m');
if (esc) {
log(LOG_DEBUG,'- READ SHOULD LOOP');
}
timer = time();
timeout = false;
}
}
log(LOG_DEBUG,'READ: ['+read+'] ('+read.charCodeAt(0)+')');