diff --git a/load/control/echomail.js b/load/control/echomail.js index 850dde6..e540f79 100644 --- a/load/control/echomail.js +++ b/load/control/echomail.js @@ -10,27 +10,27 @@ * (Tags are added to the messages via an external process.) */ +// All controls need a unique variable so that require() can know if the control has already been loaded var CONTROL_ECHOMAIL = '1'; -//load('frame.js'); -//load('graphic.js'); - +// Optional debug message so we can see that it is loaded log(LOG_DEBUG,'+ Control ECHOMAIL loaded'); -function echomail(page) { +// A unique method name (same as the control name that is called as new method() on initialisation +function echomail(pagenum,session) { + log(LOG_DEBUG,' - Loading echomail page:'+pagenum); + + // has this control completed var complete = false; - var pageframe = undefined; - log(LOG_DEBUG,'Loading echomail page:'+page); + var ready = false; - // Setup our frame - fo = viewdata ? new FrameViewdata() : new FrameAnsi(); - fo.loadMessage(page,viewdata ? 'vtx' : 'tex'); + function init(pagenum,session) { + log(LOG_DEBUG,'- init()'); - if (fo.content) - pageframe = fo.render(); + ready = session.loadMessage(pagenum); + } - // Called before processing for a field Object.defineProperty(this, 'getName', { get: function () { return 'ECHOMAIL'; @@ -44,40 +44,39 @@ function echomail(page) { }); // Handle the keyboard responses as we receive them. - this.handle=function(read) { + this.handle = function(read) { log(LOG_DEBUG,'Control ECHOMAIL handle() start. ('+read+')'); switch(read) { case KEY_DOWN: - log(LOG_DEBUG,' - Control TEST scroll 0,1'); - pageframe.scroll(0,1); + session.page.scroll(0,1); read = ''; break; case KEY_UP: - log(LOG_DEBUG,' - Control TEST scroll 0,-1'); - pageframe.scroll(0,-1); + session.page.scroll(0,-1); read = ''; break; } - pageframe.cycle(); + so.render(); return read; } - // @todo Does this need to be defined? - this.prefield=function() {}; - - this.ready=function() { - //log(LOG_DEBUG,' - pageframe:'+pageframe+',typeof:'+(typeof pageframe)); - if ((typeof pageframe) === 'undefined') - log(LOG_DEBUG,'+ Control ECHOMAIL page doesnt exist ['+page+']'); - else - log(LOG_DEBUG,'+ Control ECHOMAIL ready'); - - return (typeof pageframe) !== 'undefined'; + /** + * ready() is called after a control has been initialised, to determine if the control will take the input + * or if it is unable to do so + * + * If ready() returns: + * + false, the main programming will return ERR_ROUTE to the user, + * + true, the main programming will continue to load the frame, and then pass input to on the next loop handle() + * + * @returns {boolean} + */ + this.ready = function() { + return ready; } -} -this; + init.apply(this,arguments); +} diff --git a/load/funcs.js b/load/funcs.js index a40cc8d..8a121be 100644 --- a/load/funcs.js +++ b/load/funcs.js @@ -321,7 +321,7 @@ function atcode(field,length,pad,context) { else if (result.length > Math.abs(length)) result = result.substr(0,Math.abs(length)); - log(LOG_DEBUG,'- ATCODE ['+field+'] ('+length+'|"'+pad+'") returns ['+result+']'); + log(LOG_DEBUG,'* ATCODE ['+field+'] ('+length+'|"'+pad+'") returns ['+result+']'); return result; } diff --git a/load/page.js b/load/page.js index 8e8e3ab..add93a9 100644 --- a/load/page.js +++ b/load/page.js @@ -129,9 +129,21 @@ function Page(debug) { dynamic_fields: [], // Array of our dynamic fields isAccessible: undefined, // Is this page visible to all users + // If FALSE, only the SP can view/edit the frame isPublic: undefined, // Is this page visible to public (not CUG) users + // If FALSE user must be a member of the CUG to view the frame + // All users, including unauthenticated, are members of 'system' (owner = 0) + // Frame's owned by the system where: + // isPublic is FALSE - the user must be logged in to view it + // isPublic is TRUE - can be viewed by non-logged in users + + // Frame's owned by Service Providers where: + // isPublic is FALSE - can only be viewed if a user is + // a member of the Service Providers CUG + // isPublic is TRUE - can be viewed by users (if logged in) key: [], // Key actions + raw: undefined, // Page raw content }; this.__defaults__ = { @@ -190,11 +202,11 @@ function Page(debug) { * Determine if this frame is accessible to the current user */ Page.prototype.__defineGetter__('accessible',function() { - log(LOG_DEBUG,'- Checking if user can access frame: '+this.name.toString()); - log(LOG_DEBUG,' - User: '+JSON.stringify(user.number)); - log(LOG_DEBUG,' - Frame Owner: '+JSON.stringify(this.pageowner)+', System Frame: '+(this.pageowner === SYSTEM_OWNER)); - log(LOG_DEBUG,' - Accessible: '+JSON.stringify(this.isAccessible)); - log(LOG_DEBUG,' - Public: '+JSON.stringify(this.isPublic)); + log(LOG_DEBUG,'- Checking if user ['+user.number+'] can access frame: '+this.name.toString()); + log(LOG_DEBUG,'|* Frame Owner: '+JSON.stringify(this.pageowner)+', System Frame: '+(this.pageowner === SYSTEM_OWNER)); + log(LOG_DEBUG,'|* Accessible: '+JSON.stringify(this.__properties__.isAccessible)); + log(LOG_DEBUG,'|* Public: '+JSON.stringify(this.__properties__.isPublic)); + log(LOG_DEBUG,'|* Member: '+JSON.stringify(this.isMember)); // user.number 0 is unidentified user. if (user.number) { @@ -268,6 +280,14 @@ function Page(debug) { this.__properties__.isAccessible = bool; }); + /** + * Check if the user is already a member of the CUG + */ + Page.prototype.__defineGetter__('isMember',function() { + // @todo Implement CUGs, this would be "=== SERVICE_PROVIDER" and user is a member of SERVICE_PROVIDER + return user.number && (this.pageowner === SYSTEM_OWNER); + }); + Page.prototype.__defineSetter__('isPublic',function(bool) { if (typeof bool !== 'boolean') throw new Error('isPublic must be a boolean'); @@ -321,8 +341,6 @@ function Page(debug) { * Determine who the owner of a page is */ Page.prototype.__defineGetter__('pageowner',function() { - log(LOG_DEBUG,'Getting page owner for:'+this.__properties__.name.frame); - return pageOwner(this.__properties__.name.frame).prefix; }); @@ -353,6 +371,10 @@ function Page(debug) { this.__window__.provider.__properties__.content = provider; }); + Page.prototype.__defineGetter__('raw',function() { + return this.__properties__.raw; + }); + Page.prototype.__defineSetter__('showHeader',function(bool) { if (typeof bool !== 'boolean') throw new Error('showHeader expected a true/false'); @@ -380,6 +402,8 @@ function Page(debug) { * @returns {*} */ this.build = function(force) { + log(LOG_DEBUG,'* Building frame...'); + if (this.__compiled__.build && ! force) throw new Error('Refusing to build without force.'); @@ -388,14 +412,14 @@ function Page(debug) { // Add our dynamic values var fields = this.dynamic_fields.filter(function(item) { return item.value !== undefined; }); - log(LOG_DEBUG,'We have DF fields:'+fields.length); + log(LOG_DEBUG,'|* We have DF fields:'+fields.length); if (fields.length) insert_fields(fields,this.__compiled__.build); // Add our dynamic values fields = this.input_fields.filter(function(item) { return item.value !== undefined; }); - log(LOG_DEBUG,'We have INPUT fields:'+fields.length); + log(LOG_DEBUG,'|* We have INPUT fields:'+fields.length); if (fields.length) insert_fields(fields,this.__compiled__.build); @@ -420,10 +444,7 @@ function Page(debug) { /** * Build in our dynamic_fields that can be populated automatically */ - this.build_system_fields = function() { - // Fields we can process automatically - const auto = ['nodeid','DATETIME','TIME','REALNAME','BBS','STATS.LTODAY','BYTESLEFT','MAILW','STATS.TTODAY','ON','STATS.NUSERS']; - + this.build_system_fields = function(context) { var df = this.dynamic_fields.filter(function(item) { return item.value === undefined; }); if (! df.length) @@ -432,8 +453,7 @@ function Page(debug) { var that = this; df.forEach(function(field) { - if (auto.indexOf(field.name) >= 0) - that.dynamic_field(field.name,atcode(field.name,field.length,field.pad,undefined)); + that.dynamic_field(field.name,atcode(field.name,field.length,field.pad,context)); }); } @@ -445,7 +465,6 @@ function Page(debug) { */ this.display = function(last,color) { var debug = false; - log(LOG_DEBUG,'DISPLAY CALLED:'+last); if (! this.__compiled__.build) this.build(); @@ -484,7 +503,7 @@ function Page(debug) { // If our dynamic fields havent been filled in if (df.length > 0) - throw new Error('Dynamic fields without values:'+(df.map(function(item) { return item.name; }).join('|'))); + throw new Error('Dynamic fields ['+df.length+'] without values:'+(df.map(function(item) { return item.name; }).join('|'))); // Render the display for (y=1;y<=this.height;y++) { @@ -834,7 +853,7 @@ function Page(debug) { * @todo Dont allow load() to load a Viewdata frame for an ANSItex session and visa-versa. */ this.import = function(filename,width,height) { - log(LOG_DEBUG,' - Importing frame: ['+filename+']'); + log(LOG_DEBUG,'|- Importing frame: ['+filename+']'); var f = new File(filename); if (! f.exists || ! f.open('rb',true)) { @@ -910,7 +929,6 @@ function Page(debug) { contents = contents.substr(0, sauceless_size); } - log(LOG_DEBUG,'*** ['+ext+'].'); return this.preload((['vtx','tex'].indexOf(ext) !== -1) ? JSON.parse(contents) : contents,ext,width,height); } @@ -925,6 +943,14 @@ function Page(debug) { */ this.preload = function(contents,ext,width,height) { switch (ext) { + // Messages + case 'txt': + log(LOG_DEBUG,'Processing txt'); + var page = rawtoattrs(contents,this.width,this.__window__.body.y,this.__window__.body.x,debug); + + this.__window__.body.__properties__.content = page.content; + this.__properties__.raw = contents; + // ANSI files case 'ans': // ViewData files @@ -937,32 +963,28 @@ function Page(debug) { // Our fields are sorted in x descending order this.input_fields = page.input_fields.sort(function(a,b) { return a.x < b.x ? 1 : -1; }); + this.__properties__.raw = contents; + break; // ANSItex files case 'tex': case 'vtx': - log(LOG_DEBUG,'Processing FRAME file'); + log(LOG_DEBUG,'|-- Processing FRAME file'); try { - //var load = JSON.parse(contents); - var load = contents; - - log(LOG_DEBUG,'*** ['+JSON.stringify(Object.keys(contents))+']['+(typeof contents)+'].'); for (var index in contents) { if (FRAME_SAVE_ATTRS.indexOf(index) === -1) { - log(LOG_ERROR,'- Unknown index ['+index+'] in input.'); + log(LOG_ERROR,'|-! Unknown index ['+index+'] in input.'); continue; } - log(LOG_DEBUG,'* Processing ['+index+'] with value ['+JSON.stringify(contents[index])+'].'); + log(LOG_DEBUG,'|-* Processing ['+index+'] with value ['+JSON.stringify(contents[index])+'].'); switch (index) { case 'content': - log(LOG_INFO,'- Parsing content'); - - if (ext === 'tex') - var page = rawtoattrs(base64_decode(contents[index]).replace("\x0a\x0d\x0a\x0d","\x0a\x0d"),this.width,this.__window__.body.y,this.__window__.body.x); - else if (ext === 'vtx') + //if (ext === 'tex') + // var page = rawtoattrs(base64_decode(contents[index]).replace("\x0a\x0d\x0a\x0d","\x0a\x0d"),this.width,this.__window__.body.y,this.__window__.body.x); + //else if (ext === 'vtx') var page = rawtoattrs(base64_decode(contents[index]),this.width,this.__window__.body.y,this.__window__.body.x); this.__window__.body.__properties__.content = page.content; @@ -972,7 +994,7 @@ function Page(debug) { if (page.input_fields.length) this.input_fields = page.input_fields.sort(function(a,b) { return a.x < b.x ? 1 : -1; }); - log(LOG_INFO,'- Parsing content complete'); + this.__properties__.raw = base64_decode(contents[index]); break; @@ -981,7 +1003,7 @@ function Page(debug) { break; case 'date': - log(LOG_INFO,'- Frame date : '+contents[index]); + log(LOG_INFO,'|-/ Frame date : '+contents[index]); break; case 'dynamic_fields': @@ -989,12 +1011,10 @@ function Page(debug) { break; case 'frame': - log(LOG_INFO,'- Frame ID : '+contents[index]); this.name.frame = ''+contents[index]; break; case 'index': - log(LOG_INFO,'- Frame Index : '+contents[index]); this.name.index = contents[index]; break; @@ -1019,7 +1039,7 @@ function Page(debug) { break; case 'version': - log(LOG_INFO,'- Frame version : '+contents[index]); + log(LOG_INFO,'|-/ Frame version : '+contents[index]); break; case 'window': @@ -1044,12 +1064,12 @@ function Page(debug) { break; default: - log(LOG_ERROR,'! Frame property not handled: '+index+', value:'+contents[index]); + log(LOG_ERROR,'|-! Frame property not handled: '+index+', value:'+contents[index]); } } } catch (error) { - log(LOG_ERROR,'! Frame error : '+error); + log(LOG_ERROR,'|-! Frame error : '+error); // Load our system error frame. // @todo If our system error page errors, then we go into a loop @@ -1058,11 +1078,9 @@ function Page(debug) { return null; } - log(LOG_DEBUG,'= Loaded frame : '+this.name.toString()); - this.loadcomplete(); - log(LOG_DEBUG,'= Frame complete : '+this.name.toString()); + log(LOG_DEBUG,'|= Frame complete : '+this.name.toString()); break; @@ -1104,11 +1122,11 @@ function Page(debug) { } if (msg === undefined) { - log(LOG_DEBUG,' - Frame not found: ['+page.toString()+'] to ['+FRAMES_MSG_BASE+']'); + log(LOG_DEBUG,'|- Frame not found: ['+page.toString()+'] in ['+FRAMES_MSG_BASE+']'); return false; } else { - log(LOG_DEBUG,' - LOADING frame: ['+page.toString()+'] from ['+msg.number+']'); + log(LOG_DEBUG,'|- LOADING frame: ['+page.toString()+'] from ['+msg.number+']'); var contents = JSON.parse(mb.get_msg_body(false,msg.number,false,false,true,true)); @@ -1261,6 +1279,13 @@ function Page(debug) { mb.close(); } + this.scroll = function(x,y) { + this.__compiled__.build = null; + + // @todo Check that we can scroll and if we are out of bounds. + this.__window__.body.scroll(x,y); + } + init.apply(this,arguments); } diff --git a/load/session.js b/load/session.js index 12745ca..b3c4f41 100644 --- a/load/session.js +++ b/load/session.js @@ -13,80 +13,12 @@ function Session() { /* Frame type settings */ this.settings = {}; - /* Frame Version */ - this.version = 1; - - /* Frame Number [0-9] */ - this.frame = null; - - /* Frame Index [a-z] */ - this.index = null; - - /* The Service Provider owning the frame. */ - this.owner = 0; - - /* The cost to view the frame @todo to implement */ - this.cost = 0; - - /* The frame content, base64 encoded */ - this.content = ''; - - // Frame's owned by the system where: - // isPublic is FALSE - the user must be logged in to view it - // isPublic is TRUE - can be viewed by non-logged in users - - // Frame's owned by Service Providers where: - // isPublic is FALSE - can only be viewed if a user is - // a member of the Service Providers CUG - // isPublic is TRUE - can be viewed by users (if logged in) - - this.isPublic = false; // Is this frame accessible to non CUG users - // If FALSE user must be a member of the CUG to view the frame - // All users, including unauthenticated, are members of 'system' (owner = 0) - this.isAccessible = false; // Is this frame available to be accessed - // If FALSE, only the SP can view/edit the frame - - 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] - - /** - * Return the frames fields - */ - Object.defineProperty(this,'fields', { - get: function() { - return this.frame_fields; - } - }); - - /** - * Check if the user is already a member of the CUG - */ - Object.defineProperty(this,'isMember',{ - get: function() { - log(LOG_DEBUG,'- Checking if user is a member of frame: '+this.page); - - if (user.number) { - return ( - (this.pageowner === SYSTEM_OWNER) - ); - - } else { - return false; - } - } - }) - - Object.defineProperty(this,'pageownerlogo', { - get: function() { - return base64_decode(this.settings.ext === 'tex' ? pageOwner(this.frame).logoans : pageOwner(this.frame).logovtx); - } - }) - /** * Enable pulling out submitted value by its name * * @param key * @returns {null|string|*} + * @deprecated I think this has been superseded, by page.js, but I need to investigate */ this.fieldValue = function(key) { for each (var k in this.frame_fields) { @@ -113,37 +45,26 @@ function Session() { /** * Load a message frame * - * @param page + * @param pagenum */ - this.loadMessage = function(page,ext) { - this.frame = ''+page; - this.index = 'a'; - this.owner = 1; - this.isPublic = true; - this.isAccessible = true; - // @todo Keys should map to next/previous/send, etc as indicated in the template frame. - this.key = [this.frame.substr(0,7)+'1',null,null,null,null,null,null,null,null,null]; - // @todo validate that FRAME_TYPE_MESSAGE is a message template - this.type = FRAME_TYPE_MESSAGE; + this.loadMessage = function(pagenum,ext) { + log(LOG_ERROR,'Loading Message :['+pagenum+']'); // Load our message var ma = new MsgAreas() - var area = ma.getArea(this.frame); - var msg = ma.getMessage(this.frame); + var area = ma.getArea(pagenum); + var msg = ma.getMessage(pagenum); var msg_header; if (! msg) - return undefined; + return false; // @todo Search 1zzzzEE..., 1zzzz... - var to = viewdata ? new FrameViewdata() : new FrameAnsi(); - to.load(MAIL_TEMPLATE_FRAME,ext); - // @todo Check that this is a frame of type "m" and report error if not - // @todo Take the cost from the template - this.cost = 5; + this.get(new PageObject(MAIL_TEMPLATE_FRAME),ext); + + if (this.page.name.toString() === null) { + log(LOG_ERROR,'Echomail template missing :['+JSON.stringify(MAIL_TEMPLATE_FRAME)+'] ?'); - if (! to) { - log(LOG_ERROR,'Echomail template missing :['+MAIL_TEMPLATE_FRAME+'] ?'); msg_header = 'TO: '+msg.to.substr(0,72)+"\n\r"; msg_header += 'FROM: '+msg.from.substr(0,72)+"\n\r"; msg_header += 'DATE: '+msg.date.substr(0,72)+"\n\r"; @@ -151,7 +72,7 @@ function Session() { } else { // @todo change this to use atcode() - msg_header = base64_decode(to.content).replace(/@(.*)@/g, + msg_header = this.page.raw.replace(/@(.*)@/g, function (str, code, offset, s) { var length = code.split(':')[1]; switch(code.split(':')[0]) { @@ -164,11 +85,22 @@ function Session() { ); } - //log(LOG_DEBUG,'Loaded message: '+msg_header+msg.content); - this.content = base64_encode(msg_header+msg.content); + this.page.name = new PageObject(pagenum,'a'); + this.page.owner = 1; + // @todo Keys should map to next/previous/send, etc as indicated in the template frame. + this.page.key = [this.page.name.frame.substr(0,7)+'1',null,null,null,null,null,null,null,null,null]; + // @todo validate that FRAME_TYPE_MESSAGE is a message template + this.page.type = FRAME_TYPE_MESSAGE; + // @todo Take the cost from the template + this.page.cost = 5; + // @todo Take the key values from the template + this.page.__properties__.isAccessible = true; + this.page.__properties__.isPublic = true; + + this.page.preload(msg_header+msg.content,'txt'); // Update the user's pointers - var stats = ma.getUserStats(this.frame); + var stats = ma.getUserStats(this.page.name.frame); // if this message is to the user, and the msg number > scan_ptr and it is the next message on the user's new mail list var newmsgs = area.newMsgsToMe(); @@ -176,7 +108,7 @@ function Session() { log(LOG_DEBUG,'User has: '+newmsgs.length-1+' msgs to read to ME'); if (newmsgs.length) { next = newmsgs[1]; - //log(LOG_DEBUG,'- NEXT is: '+next.tags+', this is: '+msg.tags); + log(LOG_DEBUG,'- NEXT is: '+next.tags+', this is: '+msg.tags); if (next && (next.tags === msg.tags)) { log(LOG_DEBUG,'- Updating scan_ptr to: '+next.number); @@ -187,14 +119,14 @@ function Session() { next = newmsgs[0]; if (next !== undefined) { log(LOG_DEBUG,'- LAST TO ME is: '+next.tags); - this.key[1] = area.page(next.tags); + this.page.key[1] = area.page(next.tags); } // Next new message next = newmsgs[2]; if (next !== undefined) { log(LOG_DEBUG,'- NEXT TO ME is: '+next.tags); - this.key[2] = area.page(next.tags); + this.page.key[2] = area.page(next.tags); } } @@ -212,16 +144,18 @@ function Session() { } // Previous Message - x = area.MessagePrev(this.frame); + x = area.MessagePrev(this.page.name.frame); if (x) - this.key[4] = area.page(x.tags); + this.page.key[4] = area.page(x.tags); // Next Message - x = area.MessageNext(this.frame); + x = area.MessageNext(this.page.name.frame); if (x) - this.key[6] = area.page(x.tags); + this.page.key[6] = area.page(x.tags); - log(LOG_DEBUG,'Built frame: ['+this.frame+']['+this.index+'] ('+this.page+')'); + log(LOG_DEBUG,'Built frame: ['+this.page.name.frame+']['+this.page.name.index+'] ('+this.page.name.toString()+')'); + + return true; } // Render the page @@ -232,10 +166,11 @@ function Session() { } /** - * Return the message for a index + * Return a system message for a index * * @param index * @returns {string|*} + * @see SessionProtocol() */ Session.prototype.getMessage = function(index) { eval('var msg = this.settings.'+index); diff --git a/load/session/ansitex.js b/load/session/ansitex.js index 4c78464..72b2d30 100644 --- a/load/session/ansitex.js +++ b/load/session/ansitex.js @@ -371,7 +371,7 @@ function rawtoattrs(contents,width,yoffset,xoffset,debug) { // We are interested in our field match var df = m.shift().split(';'); - log(LOG_DEBUG,'- DF found at ['+x+'x'+y+'], Field: '+df[0]+', Length: '+df[1]+', Pad:'+df[2]); + log(LOG_DEBUG,'|--* DF found at ['+x+'x'+y+'], Field: '+df[0]+', Length: '+df[1]+', Pad:'+df[2]); // If we are padding our field with a char, we need to add that back to line // @todo validate if this goes beyond our width (and if scrolling not enabled) line = (df[2] ? df[2] : '_').repeat(Math.abs(df[1]))+line; diff --git a/load/session/viewdata.js b/load/session/viewdata.js index 9bcd947..c407ada 100644 --- a/load/session/viewdata.js +++ b/load/session/viewdata.js @@ -6,7 +6,7 @@ const FRAME_HEIGHT = 22; const FRAME_PROVIDER_LENGTH = 23; const FRAME_PAGE_LENGTH = 11; const FRAME_COST_LENGTH = 6; -const FRAME_ATTR_LENGTH = 0; // Space that an attribute takes +const FRAME_ATTR_LENGTH = 1; // Space that an attribute takes const VIEWDATA_LEFT = '\x08'; const VIEWDATA_RIGHT = '\x09'; @@ -552,34 +552,6 @@ function SessionProtocol() { return str.replace(/\x1b/g,'').length; }; - /* - // Render the frame to the user - this.render=function(withHeader) { - log(LOG_DEBUG,'- VIEWDATA FRAME'); - owner = base64_decode(this.owner); - - header = VIEWDATA_DOWN; - - //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 && FRAMES_NO_HISTORY.indexOf(this.page) === -1)) { - log(LOG_DEBUG,' - Owner: ['+this.pageowner+'] ('+this.strlen(videotex(this.pageownerlogo))+')'); - - cost = (this.isAccessible ? this.cost+FRAME_COSTUNIT : ' -'); - - header = videotex(this.pageownerlogo)+' '.repeat(this.settings.FRAME_HEADER-this.strlen(videotex(this.pageownerlogo)))+ - (this.isAccessible ? ascii(27)+'G' : ascii(27)+'A')+this.page+' '.repeat(this.settings.FRAME_PAGENUM-this.page.length)+ - ascii(27)+'B'+' '.repeat(this.settings.FRAME_COST-cost.toString().length+1)+cost; - } - - //console.status |= CON_RAW_IN; - write_raw(VIEWDATA_CLS); - write_raw(header); - return write_raw(videotex(base64_decode(this.content))); - }; - */ - this.qrcode = function(qr) { // Render the body var qrcode = VIEWDATA_HOME+VIEWDATA_DOWN.repeat(5); diff --git a/load/windows.js b/load/windows.js index 7946cd6..6a56e4b 100644 --- a/load/windows.js +++ b/load/windows.js @@ -777,6 +777,18 @@ function Window(x,y,width,height,name,parent,debug) { return { content: content, x: endx-startx+1 }; } + Window.prototype.scroll = function(x,y) { + this.__properties__.ox += x; + + if (this.__properties__.ox < 0) + this.__properties__.ox = 0; + + this.__properties__.oy += y; + + if (this.__properties__.oy < 0) + this.__properties__.oy = 0; + } + // Return the visible children (child should have sort by z) Window.prototype.visibleChildren = function() { return this.child.filter(function(child) { diff --git a/main.js b/main.js index fa1d54b..9cc40f1 100644 --- a/main.js +++ b/main.js @@ -7,6 +7,7 @@ */ log(LOG_DEBUG,'* INIT: ANSItex'); +var debug_mode = 'ansitex/at0593/10010011'; // eg: 'user/password/10010010001'; // SBBS Key definitions require('key_defs.js','KEY_ESC'); @@ -721,6 +722,20 @@ while (bbs.online) { case 'login': log(LOG_DEBUG,' - User: '+so.page.input_fields[0].value+'/'+so.page.input_fields[1].value); + // In debug mode, we'll authenticate for the user + if (debug_mode) { + log(LOG_DEBUG,' - Debug mode user'+debug_mode.split('/')[0]); + log(LOG_DEBUG,' - Debug mode pass'+debug_mode.split('/')[1]); + if (bbs.login(debug_mode.split('/')[0],'',debug_mode.split('/')[1])) { + log(LOG_DEBUG,' - User: '+JSON.stringify(user.number)); + bbs.logon(); + log(LOG_DEBUG,' - SEND TO EXIT:'); + + action = ACTION_EXIT; + break; + } + } + // If login is successful, we'll exit here if (bbs.login(so.page.input_fields[0].value,'',so.page.input_fields[1].value)) { log(LOG_DEBUG,' - User: '+JSON.stringify(user.number)); @@ -731,7 +746,6 @@ while (bbs.online) { break; } - log(LOG_DEBUG,'***:'+JSON.stringify(bbs)); log(LOG_DEBUG,' ! Login failed for User:'+JSON.stringify(so.page.input_fields[0].value)); action = ACTION_GOTO; next_page = new PageObject(FRAME_LOGIN_FAILED); @@ -931,8 +945,8 @@ while (bbs.online) { // If we are editing a specific frame, attempt to load it if (next_page) { + // In case we need to fall back. var current = so; - //so = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex(); so.get(next_page); // If the frame doesnt exist, check that the parent frame exists in case we are creating a new one @@ -941,12 +955,12 @@ while (bbs.online) { // We can always create an 'a' frame if (next_page.index !== 'a') { - so = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex(); so.get(pageStr({frame: next_page.frame, index: String.fromCharCode(next_page.index.charCodeAt(0)-1)})); log(LOG_DEBUG,'- ACTION_EDIT: check index: '+JSON.stringify(so)+' ('+String.fromCharCode(next_page.index.charCodeAt(0)-1)+')'); if (so.page.name.toString() === null) { so = current; + current = undefined; // sendbaseline ERR_PAGE so.baselineSend('ERR_NO_PARENT',false); action = mode = null; @@ -955,12 +969,10 @@ while (bbs.online) { } // New frame - //so = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex(); - so.frame = next_page.frame; - so.index = next_page.index; - so.cost = 0; - so.owner = base64_decode(pageOwner(pageStr(next_page)).logo); - so.content = base64_encode('Start your new page...'); + so.page.name = new PageObject({frame: next_page.frame, index: next_page.index}); + so.page.cost = 0; + so.page.owner = base64_decode(pageOwner(pageStr(next_page)).logo); + so.page.content = base64_encode('Start your new page...'); } } @@ -1004,31 +1016,30 @@ while (bbs.online) { if (/^1[0-9]{6}1$/.test(next_page.frame)) { log(LOG_DEBUG,'- ACTION_GOTO - load echoarea summary: ['+next_page.frame+']'); - //to = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex(); + current = so; + // @todo look for a template in the area or group first - to.get(new PageObject(MAIL_TEMPLATE_AREA_SUMMARY)); + so.get(new PageObject(MAIL_TEMPLATE_AREA_SUMMARY)); var ma = new MsgAreas(); var area = ma.getArea(next_page.frame); // If the template page doesnt exist - if ((! to.content) || (! area)) { + if ((! so.page.raw) || (! area)) { + so = current; + current = undefined; so.baselineSend('ERR_ROUTE',false); action = mode = null; break; } - current = so; - - //so = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex(); - so.frame = next_page.frame; - so.index = next_page.index; - so.content = to.content; - so.isPublic = true; - so.isAccessible = to.isAccessible; - so.owner = to.owner; - so.page.type = to.type; + // @todo Update the page details from the template // Parent + so.page.name = new PageObject({frame: next_page.frame, index: next_page.index}); + so.page.__properties__.isAccessible = true; + so.page.__properties__.isPublic = true; + so.page.build_system_fields(area); + so.page.key[0] = (''+next_page.frame).substr(0,7); // First to me @@ -1083,10 +1094,7 @@ while (bbs.online) { if (next_page !== null) { current = so; - //so = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex(); - log(LOG_DEBUG,'**** Got: ['+JSON.stringify(next_page)+']'); so.get(next_page); - log(LOG_DEBUG,' - Got: ['+so.page.name.toString()+']'); if (so.page.name.toString() === null) { log(LOG_DEBUG,'- Next Page: ['+(next_page.toString()+'] doesnt exist?')); @@ -1139,6 +1147,8 @@ while (bbs.online) { cf = null; log(LOG_DEBUG,'- ACTION_RELOAD: ['+(next_page ? pageStr(next_page) : '')+']'); + if (debug_mode && so.page.name.toString() === '98b') + so.page.key[1] = debug_mode.split('/')[2]; console.line_counter = 0; // @todo fix to suppress a pause that is occurring before clear() so.cursorOff(); @@ -1152,7 +1162,7 @@ while (bbs.online) { // Terminate frame case FRAME_TYPE_MAIL_TEMPLATE: log(LOG_DEBUG,'- MAIL_TEMPLATE: ['+so.frame+']'); - so.render(ma.getArea(so.frame)); + so.render(); action = mode = null; break; @@ -1168,7 +1178,7 @@ while (bbs.online) { // External Frame // @todo returning from the frame, go to the 0 key if it is set case FRAME_TYPE_EXTERNAL: - var content = base64_decode(so.content); + var content = base64_decode(so.page.raw); log(LOG_DEBUG,'- ACTION_GOTO: EXTERNAL ['+JSON.stringify(content)+']'); switch(content.replace(/\n/,'')) {