From d57311e935cb9db7537341e7202107a182a4a2ca Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 30 Jul 2020 00:15:48 +1000 Subject: [PATCH] Move more functions that are ansi specific to ANSIFrame --- load/ansiframe.js | 72 ++++++++++++++++++++++-- load/defs.js | 13 ----- load/funcs.js | 33 ++--------- main.js | 139 +++++++++++++++++++++++----------------------- 4 files changed, 138 insertions(+), 119 deletions(-) diff --git a/load/ansiframe.js b/load/ansiframe.js index 9632973..1fa4e17 100644 --- a/load/ansiframe.js +++ b/load/ansiframe.js @@ -1,11 +1,26 @@ var FRAME_ANSI=(1<<1); var ANSI_FRAME_LENGTH =22; /* Length of a frame */ -var ANSI_FRAME_WIDTH =80; /* Width of a frame */ +var ANSI_FRAME_WIDTH =80; /* Width of a frame */ var ANSI_FRAME_HEADER =56; /* Size of page owner (length) */ var ANSI_FRAME_PAGENUM =12; /* Size of page number (length with a-z) */ var ANSI_FRAME_COST = 9; /* Size of cost (length without unit) */ +var ANSI_MSG_SENDORNOT ='\1n\1h\1GKEY 1 TO SEND, 2 NOT TO SEND'; +var ANSI_MSG_LOGON ='\1n\1h\1GKEY 1 TO LOGON, 2 TO RETURN'; +var ANSI_MSG_SENT ='\1n\1h\1GMESSAGE SENT - KEY # TO CONTINUE'; +var ANSI_MSG_NOTSENT ='\1n\1h\1GMESSAGE NOT SENT - KEY # TO CONTINUE'; +var ANSI_ERR_NO_PARENT ='\1n\1h\1RPARENT FRAME DOESNT EXIST'; +var ANSI_ERR_NOT_IMPLEMENTED ='\1n\1h\1RNOT IMPLEMENTED YET?'; +var ANSI_ERR_ROUTE ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08'; +var ANSI_ERR_METHOD_NOT_EXIST ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08'; +var ANSI_ACCESS_DENIED ='\1n\1h\1RACCESS DENIED. \1RMISTAKE? TRY AGAIN OR TELL US *08'; +var ANSI_ALREADY_MEMBER ='\1n\1h\1RALREADY MEMBER OF CUG' +var ANSI_INACTIVITY ='\1n\1h\1RINACTIVITY ALERT, DISCONNECT PENDING...'; +var ANSI_INACTIVE ='\1n\1h\1RINACTIVITY DISCONNECT'; +var ANSI_NOACTION ='\1n\1h\1RNO ACTION PERFORMED'; +var ANSI_BASESTAR ='\1N\1G\1H*'; + // Our frame object function ANSIFrame() { this.version=1; // The version of this frame - in case we update functionality and we need to be @@ -34,17 +49,31 @@ function ANSIFrame() { this.type = FRAME_TYPE_INFO; // The frame type - see FRAME_TYPES above this.key=[ null,null,null,null,null,null,null,null,null,null ]; // Key actions [0-9] + /** + * Turn off the cursor + */ + this.cursorOff=function() { + ansi.send('ext_mode','clear','cursor'); + console.gotoxy(0,24); + } + + this.cursorOn=function(x,y) { + ansi.send('ext_mode','set','cursor'); + console.gotoxy(x,y); + } + // Render the frame to the user this.render=function(withHeader) { + log(LOG_DEBUG,'- ANSI FRAME'); owner = base64_decode(this.owner); header = '\n\r'; - log(LOG_DEBUG,'- FRAME User: ['+JSON.stringify(user)+']'); + log(LOG_DEBUG,' - FRAME User: ['+JSON.stringify(user)+']'); // Dont show the page number on system login page if (user.number || (this.type != FRAME_TYPE_LOGIN && NO_HISTORY_FRAMES.indexOf(this.page) == -1)) { - log(LOG_DEBUG,'- Owner: ['+this.pageowner+']'); + log(LOG_DEBUG,' - Owner: ['+this.pageowner+']'); cost = (this.isAccessible ? this.cost+FRAME_COSTUNIT : ' -') @@ -54,10 +83,12 @@ function ANSIFrame() { (console.screen_columns > 80 ? '\n\r' : ''); } + console.clear(); + if ((this.type == FRAME_TYPE_LOGIN) || (this.type == FRAME_TYPE_RESPONSE)) { - return header+this.parse(base64_decode(this.content)); + return console.putmsg(header+this.parse(base64_decode(this.content))); } else { - return header+base64_decode(this.content); + return console.putmsg(header+base64_decode(this.content)); } }; @@ -75,7 +106,7 @@ function ANSIFrame() { // Load a frame from disk (.tex file) this.load = function(filename) { - log(LOG_DEBUG,'Loading frame from: '+filename); + log(LOG_DEBUG,'Loading ANSI frame from: '+filename); f = new File(system.mods_dir+'ansitex/text/'+filename+'.tex'); if (! f.exists || ! f.open('r')) { @@ -349,6 +380,35 @@ function ANSIFrame() { log(LOG_DEBUG,'Saved file: '+this.page+'.tex'); } + /** + * Send a message to the baseline. + * + * @param text + * @param reposition + */ + this.sendBaseline=function(text,reposition) { + eval('var msg = ANSI_'+text+';'); + console.pushxy(); + console.gotoxy(0,24); + console.print(msg); + console.cleartoeol(); + + if (! reposition) { + console.popxy(); + } + } + + this.clearBaseline=function(reposition) { + console.pushxy(); + console.gotoxy(0,24); + console.print(''); + console.cleartoeol(); + + if (! reposition) { + console.popxy(); + } + } + Object.defineProperty(this,'accessible',{ get: function() { log(LOG_DEBUG,'- Checking if user can access frame: '+this.page); diff --git a/load/defs.js b/load/defs.js index 2a7fbda..fbc8174 100644 --- a/load/defs.js +++ b/load/defs.js @@ -29,19 +29,6 @@ var FRAME_TYPE_RESPONSE ='r'; // Response frame, input fields are embedded in t // response will be submitted to the Service Provider, or to a method var FRAME_TYPE_LOGIN ='l'; // Login frame, enables the user to authenticate to the system, or to a CUG -var MSG_SENDORNOT ='\1n\1h\1GKEY 1 TO SEND, 2 NOT TO SEND'; -var MSG_LOGON ='\1n\1h\1GKEY 1 TO LOGON, 2 TO RETURN'; -var MSG_SENT ='\1n\1h\1GMESSAGE SENT - KEY # TO CONTINUE'; -var MSG_NOTSENT ='\1n\1h\1GMESSAGE NOT SENT - KEY # TO CONTINUE'; -var ERR_NO_PARENT ='\1n\1h\1RPARENT FRAME DOESNT EXIST'; -var ERR_NOT_IMPLEMENTED ='\1n\1h\1RNOT IMPLEMENTED YET?'; -var ERR_ROUTE ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08'; -var ERR_METHOD_NOT_EXIST ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08'; -var ACCESS_DENIED ='\1n\1h\1RACCESS DENIED. \1RMISTAKE? TRY AGAIN OR TELL US *08'; -var ALREADY_MEMBER ='\1n\1h\1RALREADY MEMBER OF CUG' -var INACTIVITY ='\1n\1h\1RINACTIVITY ALERT, DISCONNECT PENDING...'; -var INACTIVE ='\1n\1h\1RINACTIVITY DISCONNECT'; - var NO_HISTORY_FRAMES =['980a','98b','981a']; var SYSTEM_OWNER =9; var INKEY_TIMEOUT =10000; diff --git a/load/funcs.js b/load/funcs.js index b715869..99f1cf8 100644 --- a/load/funcs.js +++ b/load/funcs.js @@ -44,14 +44,6 @@ if (!String.prototype.repeat) { }; } -/** - * Turn off the cursor - */ -function cursorOff() { - ansi.send('ext_mode','clear','cursor'); - console.gotoxy(0,24); -} - /** * Find a message base by code * @@ -102,14 +94,14 @@ function getPageOwners() { if (f.open("r")) { var logo = f.iniGetValue('prefix','logo'); var users = f.iniGetValue('prefix','user'); - log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users)); + //log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users)); pageowners.push({prefix: 0,logo: logo,user:users}); f.iniGetSections('prefix:').forEach(function (prefix) { var p = parseInt(prefix.substr(7)); var logo = f.iniGetValue(prefix,'logo',''); var users = f.iniGetValue(prefix,'user',''); - log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users)); + //log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users)); pageowners.push({prefix: p,logo: logo,user: users}); }); } @@ -119,7 +111,7 @@ function getPageOwners() { // Sort the pageowners ascending pageowners.sort(compare); - log(LOG_DEBUG,'+ pageOwner: pageowners='+JSON.stringify(pageowners)); + //log(LOG_DEBUG,'+ pageOwner: pageowners='+JSON.stringify(pageowners)); } return pageowners; @@ -193,7 +185,7 @@ function pageOwner(page) { if (e !== BreakException) throw e; } - log(LOG_DEBUG,'+ pageOwner: page='+page+', owner: '+JSON.stringify(o)); + //log(LOG_DEBUG,'+ pageOwner: page='+page+', owner: '+JSON.stringify(o)); return o; } @@ -236,21 +228,4 @@ function compare(a,b) { return (a.prefix < b.prefix) ? 1 : ((b.prefix < a.prefix) ? -1 : 0); } -/** - * Send a message to the baseline. - * - * @param text - * @param reposition - */ -function sendBaseline(text,reposition) { - console.pushxy(); - console.gotoxy(0,24); - console.print(text); - console.cleartoeol(); - - if (! reposition) { - console.popxy(); - } -} - this; \ No newline at end of file diff --git a/main.js b/main.js index f88dc8e..d299153 100644 --- a/main.js +++ b/main.js @@ -42,10 +42,8 @@ while(bbs.online) { 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 + bbs.nodesync(); // @todo Stop the display of telegrams var read = ''; var esc = false; @@ -95,12 +93,12 @@ while(bbs.online) { if (read === '' && ! (user.security.exemptions&UFLAG_H) ) { if (time() > timer+((user.number ? INACTIVE_LOGIN : INACTIVE_NOLOGIN)+INKEY_TIMEOUT)/1000) { - sendBaseline(INACTIVE,false); + fo.sendBaseline('INACTIVE',false); bbs.hangup(); } else if (time() > timer+(user.number ? INACTIVE_LOGIN : INACTIVE_NOLOGIN)/1000) { timeout = true; - sendBaseline(INACTIVITY,false); + fo.sendBaseline('INACTIVITY',false); if (cf) console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m'); @@ -108,7 +106,7 @@ while(bbs.online) { } else { if (timeout) { - sendBaseline('',false); + fo.clearBaseline(false); if (cf) console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m'); @@ -176,7 +174,7 @@ while(bbs.online) { log(LOG_DEBUG,'- false: Key ['+read+'] ['+pageStr(next_page)+']'); } else { - sendBaseline(ERR_ROUTE,false); + fo.sendBaseline('ERR_ROUTE',false); } break; @@ -188,7 +186,7 @@ while(bbs.online) { action = ACTION_GOTO; } else { - sendBaseline(ERR_ROUTE,false); + fo.sendBaseline('ERR_ROUTE',false); } break; } @@ -212,14 +210,14 @@ while(bbs.online) { if (cmd == '00') { action = ACTION_RELOAD; cmd = ''; - cursorOff(); + fo.cursorOff(); break; } // Invalid system pages. if (cmd.match(/^0[2367]/)) { - cursorOff(); - sendBaseline(ERR_ROUTE, false); + fo.cursorOff(); + fo.sendBaseline('ERR_ROUTE',false); mode = action = false; cmd = ''; } @@ -230,13 +228,13 @@ while(bbs.online) { // If we are not a user if (! user.number) { - cursorOff(); - sendBaseline(ERR_ROUTE,false); + fo.cursorOff(); + fo.sendBaseline('ERR_ROUTE',false); action = false; } else { fe = { frame: page, index: read }; - cursorOff(); + fo.cursorOff(); action = ACTION_EDIT; log(LOG_DEBUG,'- MODE_BL: EDIT ['+JSON.stringify(fe)+']'); @@ -251,15 +249,15 @@ while(bbs.online) { // Bookmark frame if (cmd == '05') { if (! user.number) { - cursorOff(); - sendBaseline(ERR_ROUTE, false); + fo.cursorOff(); + fo.sendBaseline('ERR_ROUTE',false); mode = action = false; cmd = ''; } else { // @todo - cursorOff(); - sendBaseline(ERR_NOT_IMPLEMENTED,false); + fo.cursorOff(); + fo.sendBaseline('ERR_NOT_IMPLEMENTED',false); mode = action = false; cmd = ''; } @@ -270,15 +268,15 @@ while(bbs.online) { // Report Problem if (cmd == '08') { if (! user.number) { - cursorOff(); - sendBaseline(ERR_ROUTE, false); + fo.cursorOff(); + fo.sendBaseline('ERR_ROUTE',false); mode = action = false; cmd = ''; } else { // @todo - cursorOff(); - sendBaseline(ERR_NOT_IMPLEMENTED,false); + fo.cursorOff(); + fo.sendBaseline('ERR_NOT_IMPLEMENTED',false); mode = action = false; cmd = ''; } @@ -288,7 +286,7 @@ while(bbs.online) { // Reload frame if (cmd == '09') { - cursorOff(); + fo.cursorOff(); action = ACTION_GOTO; cmd = ''; next_page = { frame: fo.frame, index: fo.index}; @@ -298,8 +296,8 @@ while(bbs.online) { // Another star aborts the command if (read == '*') { - sendBaseline('',false); - cursorOff(); + fo.clearBaseline(false); + fo.cursorOff(); mode = action = false; cmd = ''; @@ -312,8 +310,7 @@ while(bbs.online) { console.gotoxy(cf.c,cf.r); console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m'); console.write(cf.fchar.repeat(cf.fvalue.length)); - console.gotoxy(cf.c,cf.r); - ansi.send('ext_mode','set','cursor'); + fo.cursorOn(cf.c,cf.r); cf.fvalue = ''; } } @@ -322,7 +319,7 @@ while(bbs.online) { // Nothing typed between * and # // *# means go back if (cmd == '') { - sendBaseline('',false); + fo.clearBaseline(false); action = ACTION_BACKUP; } else if (cmd == '0') { @@ -333,7 +330,7 @@ while(bbs.online) { } else if (cmd == '04') { // If we are not a user if (! user.number) { - sendBaseline(ERR_ROUTE,false); + fo.sendBaseline('ERR_ROUTE',false); action = false; } else { @@ -346,7 +343,7 @@ while(bbs.online) { } // Clear the command we are finished processing... - cursorOff(); + fo.cursorOff(); cmd = ''; mode = false; } @@ -513,7 +510,7 @@ while(bbs.online) { control[control.length-1].process(); } else if (fo.key[1] == '*' || fo.key[1].match(/[0-9]/)) { - sendBaseline('\1n\1h\1RNO ACTION PERFORMED',false); + fo.sendBaseline('NOACTION',false); mode = MODE_RFSENT; } else { @@ -554,7 +551,7 @@ while(bbs.online) { $next_page = $ao->page; } else { - sendBaseline(ERR_METHOD_NOT_EXIST,false); + fo.sendBaseline('ERR_METHOD_NOT_EXIST',false); mode = MODE_RFSENT; } @@ -572,7 +569,7 @@ while(bbs.online) { mode = false; } else { - sendBaseline(MSG_NOTSENT,false); + fo.sendBaseline('MSG_NOTSENT',false); mode = MODE_RFNOTSENT; } @@ -607,7 +604,7 @@ while(bbs.online) { // Response form after Sent processing case MODE_RFSENT: - ansi.send('ext_mode','clear','cursor'); + fo.cursorOff(); switch (read) { case '*': @@ -643,7 +640,7 @@ while(bbs.online) { // Response form ERROR case MODE_RFERROR: - cursorOff(); + fo.cursorOff(); if (read == '#') { /* @@ -688,8 +685,8 @@ while(bbs.online) { // @todo If something on the baseline preserve it - ansi.send('ext_mode','set','cursor'); - sendBaseline('\1N\1G\1H*',true); + fo.cursorOn(0,24); + fo.sendBaseline('BASESTAR',true); action = false; mode = MODE_BL; @@ -701,38 +698,20 @@ while(bbs.online) { // Submitting forms case ACTION_SUBMITRF: action = false; - cursorOff(); + fo.cursorOff(); log(LOG_DEBUG,'- ACTION_SUBMITRF: ['+fo.type+']'); - sendBaseline((fo.type == 'l' ? MSG_LOGON : MSG_SENDORNOT),true); + fo.sendBaseline((fo.type == 'l' ? 'MSG_LOGON' : 'MSG_SENDORNOT'),true); mode = MODE_SUBMITRF; break; - // GO Backwards - case ACTION_BACKUP: - // Do we have anywhere to go, drop the current page from the history. - if (history.length > 1) - history.pop(); - - // @todo If in control... - - next_page = (history.length > 0) ? history[history.length-1] : null; - - log(LOG_DEBUG,'- ACTION_BACKUP: Backing up to ['+(next_page ? pageStr(next_page) : '')+'] current ['+fo.page+']'); - - // If there is no next page, we'll ignore the request. - if (! next_page || (pageStr(next_page) == fo.page)) { - action = false; - break; - } - // Edit a frame case ACTION_EDIT: log(LOG_DEBUG,'- ACTION_EDIT: ['+JSON.stringify(fe)+']'); if (! pageEditor(fe ? fe.frame : fo.frame)) { - cursorOff(); - sendBaseline(ACCESS_DENIED,false); + fo.cursorOff(); + fo.sendBaseline('ACCESS_DENIED',false); action = false; break; } @@ -758,7 +737,7 @@ while(bbs.online) { if (fo.page == null) { fo = current; // sendbaseline ERR_PAGE - sendBaseline(ERR_NO_PARENT,false); + fo.sendBaseline('ERR_NO_PARENT',false); mode = action = false; break; } @@ -780,6 +759,24 @@ while(bbs.online) { action = false; break; + // GO Backwards + case ACTION_BACKUP: + // Do we have anywhere to go, drop the current page from the history. + if (history.length > 1) + history.pop(); + + // @todo If in control... + + next_page = (history.length > 0) ? history[history.length-1] : null; + + log(LOG_DEBUG,'- ACTION_BACKUP: Backing up to ['+(next_page ? pageStr(next_page) : '')+'] current ['+fo.page+']'); + + // If there is no next page, we'll ignore the request. + if (! next_page || (pageStr(next_page) == fo.page)) { + action = false; + break; + } + // Goto specific page case ACTION_GOTO: log(LOG_DEBUG,'- ACTION_GOTO: ['+(next_page ? pageStr(next_page) : '')+']'); @@ -792,7 +789,7 @@ while(bbs.online) { if (fo.page == null) { fo = current; // sendbaseline ERR_PAGE - sendBaseline(ERR_ROUTE,false); + fo.sendBaseline('ERR_ROUTE',false); mode = action = false; break; } @@ -801,14 +798,14 @@ while(bbs.online) { // If the user has access to the frame if (fo.accessible) { if (fo.isMember && fo.type == FRAME_TYPE_LOGIN) { - sendBaseline(ALREADY_MEMBER,false); + fo.sendBaseline(ALREADY_MEMBER,false); mode = action = false; break; } // Check if the frame exists, and the user is the Service Provider } else { - sendBaseline(ACCESS_DENIED,false); + fo.sendBaseline('ACCESS_DENIED',false); mode = action = false; // Reset the current frame to what it was. fo = current; @@ -837,7 +834,8 @@ while(bbs.online) { // $this->sendBaseline($client,''); // $current['baseline'] = ''; console.line_counter=0; // @todo fix to suppress a pause that is occurring before clear() - console.clear(); + fo.cursorOff(); + // Clear any controls control = []; bbs.replace_text(NodeActionMain,'\1h%s \1nViewing \1h*'+fo.frame+'#\1n ['+fo.index+']'); @@ -847,7 +845,7 @@ while(bbs.online) { switch(fo.type) { // Terminate frame case FRAME_TYPE_TERMINATE: - console.putmsg(fo.render()); + fo.render(); mode = false; action = ACTION_TERMINATE; @@ -877,7 +875,7 @@ while(bbs.online) { default: console.putmsg(JSON.stringify(content)); - sendBaseline(ERR_ROUTE,false); + fo.sendBaseline('ERR_ROUTE',false); action = false; break; } @@ -892,7 +890,7 @@ while(bbs.online) { //log(LOG_DEBUG,'FRAME_TYPE_RESPONSE :'+fo.page+', FIELDS: '+fo.frame_fields.count); fn = 0; cf = null; - console.putmsg(fo.render()); + fo.render(); if (fo.frame_fields.length) { cf = fo.frame_fields[fn]; @@ -900,14 +898,13 @@ while(bbs.online) { if (cf) { mode = MODE_FIELD; - ansi.send('ext_mode','set','cursor'); - console.gotoxy(cf.c,cf.r); + fo.cursorOn(cf.c,cf.r); console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m'); // There were no editable fields. } else { mode = MODE_COMPLETE; - cursorOff(); + fo.cursorOff(); } } else { @@ -927,7 +924,7 @@ while(bbs.online) { // Standard Frame case FRAME_TYPE_INFO: default: - console.putmsg(fo.render()); + fo.render(); mode = action = false; break;