New page/window now working

This commit is contained in:
Deon George 2023-12-27 22:24:20 +11:00
parent 7b34decb49
commit d9b056c5cd
8 changed files with 188 additions and 235 deletions

View File

@ -10,27 +10,27 @@
* (Tags are added to the messages via an external process.) * (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'; var CONTROL_ECHOMAIL = '1';
//load('frame.js'); // Optional debug message so we can see that it is loaded
//load('graphic.js');
log(LOG_DEBUG,'+ Control ECHOMAIL 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 complete = false;
var pageframe = undefined;
log(LOG_DEBUG,'Loading echomail page:'+page); var ready = false;
// Setup our frame function init(pagenum,session) {
fo = viewdata ? new FrameViewdata() : new FrameAnsi(); log(LOG_DEBUG,'- init()');
fo.loadMessage(page,viewdata ? 'vtx' : 'tex');
if (fo.content) ready = session.loadMessage(pagenum);
pageframe = fo.render(); }
// Called before processing for a field
Object.defineProperty(this, 'getName', { Object.defineProperty(this, 'getName', {
get: function () { get: function () {
return 'ECHOMAIL'; return 'ECHOMAIL';
@ -44,40 +44,39 @@ function echomail(page) {
}); });
// Handle the keyboard responses as we receive them. // Handle the keyboard responses as we receive them.
this.handle=function(read) { this.handle = function(read) {
log(LOG_DEBUG,'Control ECHOMAIL handle() start. ('+read+')'); log(LOG_DEBUG,'Control ECHOMAIL handle() start. ('+read+')');
switch(read) { switch(read) {
case KEY_DOWN: case KEY_DOWN:
log(LOG_DEBUG,' - Control TEST scroll 0,1'); session.page.scroll(0,1);
pageframe.scroll(0,1);
read = ''; read = '';
break; break;
case KEY_UP: case KEY_UP:
log(LOG_DEBUG,' - Control TEST scroll 0,-1'); session.page.scroll(0,-1);
pageframe.scroll(0,-1);
read = ''; read = '';
break; break;
} }
pageframe.cycle(); so.render();
return read; return read;
} }
// @todo Does this need to be defined? /**
this.prefield=function() {}; * 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
this.ready=function() { *
//log(LOG_DEBUG,' - pageframe:'+pageframe+',typeof:'+(typeof pageframe)); * If ready() returns:
if ((typeof pageframe) === 'undefined') * + false, the main programming will return ERR_ROUTE to the user,
log(LOG_DEBUG,'+ Control ECHOMAIL page doesnt exist ['+page+']'); * + true, the main programming will continue to load the frame, and then pass input to on the next loop handle()
else *
log(LOG_DEBUG,'+ Control ECHOMAIL ready'); * @returns {boolean}
*/
return (typeof pageframe) !== 'undefined'; this.ready = function() {
return ready;
} }
}
this; init.apply(this,arguments);
}

View File

@ -321,7 +321,7 @@ function atcode(field,length,pad,context) {
else if (result.length > Math.abs(length)) else if (result.length > Math.abs(length))
result = result.substr(0,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; return result;
} }

View File

@ -129,9 +129,21 @@ function Page(debug) {
dynamic_fields: [], // Array of our dynamic fields dynamic_fields: [], // Array of our dynamic fields
isAccessible: undefined, // Is this page visible to all users 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 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 key: [], // Key actions
raw: undefined, // Page raw content
}; };
this.__defaults__ = { this.__defaults__ = {
@ -190,11 +202,11 @@ function Page(debug) {
* Determine if this frame is accessible to the current user * Determine if this frame is accessible to the current user
*/ */
Page.prototype.__defineGetter__('accessible',function() { Page.prototype.__defineGetter__('accessible',function() {
log(LOG_DEBUG,'- Checking if user can access frame: '+this.name.toString()); log(LOG_DEBUG,'- Checking if user ['+user.number+'] 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,' - Frame Owner: '+JSON.stringify(this.pageowner)+', System Frame: '+(this.pageowner === SYSTEM_OWNER)); log(LOG_DEBUG,'|* Accessible: '+JSON.stringify(this.__properties__.isAccessible));
log(LOG_DEBUG,' - Accessible: '+JSON.stringify(this.isAccessible)); log(LOG_DEBUG,'|* Public: '+JSON.stringify(this.__properties__.isPublic));
log(LOG_DEBUG,' - Public: '+JSON.stringify(this.isPublic)); log(LOG_DEBUG,'|* Member: '+JSON.stringify(this.isMember));
// user.number 0 is unidentified user. // user.number 0 is unidentified user.
if (user.number) { if (user.number) {
@ -268,6 +280,14 @@ function Page(debug) {
this.__properties__.isAccessible = bool; 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) { Page.prototype.__defineSetter__('isPublic',function(bool) {
if (typeof bool !== 'boolean') if (typeof bool !== 'boolean')
throw new Error('isPublic must be a boolean'); throw new Error('isPublic must be a boolean');
@ -321,8 +341,6 @@ function Page(debug) {
* Determine who the owner of a page is * Determine who the owner of a page is
*/ */
Page.prototype.__defineGetter__('pageowner',function() { Page.prototype.__defineGetter__('pageowner',function() {
log(LOG_DEBUG,'Getting page owner for:'+this.__properties__.name.frame);
return pageOwner(this.__properties__.name.frame).prefix; return pageOwner(this.__properties__.name.frame).prefix;
}); });
@ -353,6 +371,10 @@ function Page(debug) {
this.__window__.provider.__properties__.content = provider; this.__window__.provider.__properties__.content = provider;
}); });
Page.prototype.__defineGetter__('raw',function() {
return this.__properties__.raw;
});
Page.prototype.__defineSetter__('showHeader',function(bool) { Page.prototype.__defineSetter__('showHeader',function(bool) {
if (typeof bool !== 'boolean') if (typeof bool !== 'boolean')
throw new Error('showHeader expected a true/false'); throw new Error('showHeader expected a true/false');
@ -380,6 +402,8 @@ function Page(debug) {
* @returns {*} * @returns {*}
*/ */
this.build = function(force) { this.build = function(force) {
log(LOG_DEBUG,'* Building frame...');
if (this.__compiled__.build && ! force) if (this.__compiled__.build && ! force)
throw new Error('Refusing to build without force.'); throw new Error('Refusing to build without force.');
@ -388,14 +412,14 @@ function Page(debug) {
// Add our dynamic values // Add our dynamic values
var fields = this.dynamic_fields.filter(function(item) { return item.value !== undefined; }); 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) if (fields.length)
insert_fields(fields,this.__compiled__.build); insert_fields(fields,this.__compiled__.build);
// Add our dynamic values // Add our dynamic values
fields = this.input_fields.filter(function(item) { return item.value !== undefined; }); 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) if (fields.length)
insert_fields(fields,this.__compiled__.build); insert_fields(fields,this.__compiled__.build);
@ -420,10 +444,7 @@ function Page(debug) {
/** /**
* Build in our dynamic_fields that can be populated automatically * Build in our dynamic_fields that can be populated automatically
*/ */
this.build_system_fields = function() { this.build_system_fields = function(context) {
// Fields we can process automatically
const auto = ['nodeid','DATETIME','TIME','REALNAME','BBS','STATS.LTODAY','BYTESLEFT','MAILW','STATS.TTODAY','ON','STATS.NUSERS'];
var df = this.dynamic_fields.filter(function(item) { return item.value === undefined; }); var df = this.dynamic_fields.filter(function(item) { return item.value === undefined; });
if (! df.length) if (! df.length)
@ -432,8 +453,7 @@ function Page(debug) {
var that = this; var that = this;
df.forEach(function(field) { df.forEach(function(field) {
if (auto.indexOf(field.name) >= 0) that.dynamic_field(field.name,atcode(field.name,field.length,field.pad,context));
that.dynamic_field(field.name,atcode(field.name,field.length,field.pad,undefined));
}); });
} }
@ -445,7 +465,6 @@ function Page(debug) {
*/ */
this.display = function(last,color) { this.display = function(last,color) {
var debug = false; var debug = false;
log(LOG_DEBUG,'DISPLAY CALLED:'+last);
if (! this.__compiled__.build) if (! this.__compiled__.build)
this.build(); this.build();
@ -484,7 +503,7 @@ function Page(debug) {
// If our dynamic fields havent been filled in // If our dynamic fields havent been filled in
if (df.length > 0) 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 // Render the display
for (y=1;y<=this.height;y++) { 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. * @todo Dont allow load() to load a Viewdata frame for an ANSItex session and visa-versa.
*/ */
this.import = function(filename,width,height) { this.import = function(filename,width,height) {
log(LOG_DEBUG,' - Importing frame: ['+filename+']'); log(LOG_DEBUG,'|- Importing frame: ['+filename+']');
var f = new File(filename); var f = new File(filename);
if (! f.exists || ! f.open('rb',true)) { if (! f.exists || ! f.open('rb',true)) {
@ -910,7 +929,6 @@ function Page(debug) {
contents = contents.substr(0, sauceless_size); 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); 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) { this.preload = function(contents,ext,width,height) {
switch (ext) { 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 // ANSI files
case 'ans': case 'ans':
// ViewData files // ViewData files
@ -937,32 +963,28 @@ function Page(debug) {
// Our fields are sorted in x descending order // 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.input_fields = page.input_fields.sort(function(a,b) { return a.x < b.x ? 1 : -1; });
this.__properties__.raw = contents;
break; break;
// ANSItex files // ANSItex files
case 'tex': case 'tex':
case 'vtx': case 'vtx':
log(LOG_DEBUG,'Processing FRAME file'); log(LOG_DEBUG,'|-- Processing FRAME file');
try { try {
//var load = JSON.parse(contents);
var load = contents;
log(LOG_DEBUG,'*** ['+JSON.stringify(Object.keys(contents))+']['+(typeof contents)+'].');
for (var index in contents) { for (var index in contents) {
if (FRAME_SAVE_ATTRS.indexOf(index) === -1) { if (FRAME_SAVE_ATTRS.indexOf(index) === -1) {
log(LOG_ERROR,'- Unknown index ['+index+'] in input.'); log(LOG_ERROR,'|-! Unknown index ['+index+'] in input.');
continue; 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) { switch (index) {
case 'content': 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);
if (ext === 'tex') //else if (ext === 'vtx')
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); var page = rawtoattrs(base64_decode(contents[index]),this.width,this.__window__.body.y,this.__window__.body.x);
this.__window__.body.__properties__.content = page.content; this.__window__.body.__properties__.content = page.content;
@ -972,7 +994,7 @@ function Page(debug) {
if (page.input_fields.length) if (page.input_fields.length)
this.input_fields = page.input_fields.sort(function(a,b) { return a.x < b.x ? 1 : -1; }); 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; break;
@ -981,7 +1003,7 @@ function Page(debug) {
break; break;
case 'date': case 'date':
log(LOG_INFO,'- Frame date : '+contents[index]); log(LOG_INFO,'|-/ Frame date : '+contents[index]);
break; break;
case 'dynamic_fields': case 'dynamic_fields':
@ -989,12 +1011,10 @@ function Page(debug) {
break; break;
case 'frame': case 'frame':
log(LOG_INFO,'- Frame ID : '+contents[index]);
this.name.frame = ''+contents[index]; this.name.frame = ''+contents[index];
break; break;
case 'index': case 'index':
log(LOG_INFO,'- Frame Index : '+contents[index]);
this.name.index = contents[index]; this.name.index = contents[index];
break; break;
@ -1019,7 +1039,7 @@ function Page(debug) {
break; break;
case 'version': case 'version':
log(LOG_INFO,'- Frame version : '+contents[index]); log(LOG_INFO,'|-/ Frame version : '+contents[index]);
break; break;
case 'window': case 'window':
@ -1044,12 +1064,12 @@ function Page(debug) {
break; break;
default: 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) { } catch (error) {
log(LOG_ERROR,'! Frame error : '+error); log(LOG_ERROR,'|-! Frame error : '+error);
// Load our system error frame. // Load our system error frame.
// @todo If our system error page errors, then we go into a loop // @todo If our system error page errors, then we go into a loop
@ -1058,11 +1078,9 @@ function Page(debug) {
return null; return null;
} }
log(LOG_DEBUG,'= Loaded frame : '+this.name.toString());
this.loadcomplete(); this.loadcomplete();
log(LOG_DEBUG,'= Frame complete : '+this.name.toString()); log(LOG_DEBUG,'|= Frame complete : '+this.name.toString());
break; break;
@ -1104,11 +1122,11 @@ function Page(debug) {
} }
if (msg === undefined) { 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; return false;
} else { } 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)); var contents = JSON.parse(mb.get_msg_body(false,msg.number,false,false,true,true));
@ -1261,6 +1279,13 @@ function Page(debug) {
mb.close(); 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); init.apply(this,arguments);
} }

View File

@ -13,80 +13,12 @@ function Session() {
/* Frame type settings */ /* Frame type settings */
this.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 * Enable pulling out submitted value by its name
* *
* @param key * @param key
* @returns {null|string|*} * @returns {null|string|*}
* @deprecated I think this has been superseded, by page.js, but I need to investigate
*/ */
this.fieldValue = function(key) { this.fieldValue = function(key) {
for each (var k in this.frame_fields) { for each (var k in this.frame_fields) {
@ -113,37 +45,26 @@ function Session() {
/** /**
* Load a message frame * Load a message frame
* *
* @param page * @param pagenum
*/ */
this.loadMessage = function(page,ext) { this.loadMessage = function(pagenum,ext) {
this.frame = ''+page; log(LOG_ERROR,'Loading Message :['+pagenum+']');
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;
// Load our message // Load our message
var ma = new MsgAreas() var ma = new MsgAreas()
var area = ma.getArea(this.frame); var area = ma.getArea(pagenum);
var msg = ma.getMessage(this.frame); var msg = ma.getMessage(pagenum);
var msg_header; var msg_header;
if (! msg) if (! msg)
return undefined; return false;
// @todo Search 1zzzzEE..., 1zzzz... // @todo Search 1zzzzEE..., 1zzzz...
var to = viewdata ? new FrameViewdata() : new FrameAnsi(); this.get(new PageObject(MAIL_TEMPLATE_FRAME),ext);
to.load(MAIL_TEMPLATE_FRAME,ext);
// @todo Check that this is a frame of type "m" and report error if not if (this.page.name.toString() === null) {
// @todo Take the cost from the template log(LOG_ERROR,'Echomail template missing :['+JSON.stringify(MAIL_TEMPLATE_FRAME)+'] ?');
this.cost = 5;
if (! to) {
log(LOG_ERROR,'Echomail template missing :['+MAIL_TEMPLATE_FRAME+'] ?');
msg_header = 'TO: '+msg.to.substr(0,72)+"\n\r"; msg_header = 'TO: '+msg.to.substr(0,72)+"\n\r";
msg_header += 'FROM: '+msg.from.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"; msg_header += 'DATE: '+msg.date.substr(0,72)+"\n\r";
@ -151,7 +72,7 @@ function Session() {
} else { } else {
// @todo change this to use atcode() // @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) { function (str, code, offset, s) {
var length = code.split(':')[1]; var length = code.split(':')[1];
switch(code.split(':')[0]) { switch(code.split(':')[0]) {
@ -164,11 +85,22 @@ function Session() {
); );
} }
//log(LOG_DEBUG,'Loaded message: '+msg_header+msg.content); this.page.name = new PageObject(pagenum,'a');
this.content = base64_encode(msg_header+msg.content); 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 // 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 // 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(); var newmsgs = area.newMsgsToMe();
@ -176,7 +108,7 @@ function Session() {
log(LOG_DEBUG,'User has: '+newmsgs.length-1+' msgs to read to ME'); log(LOG_DEBUG,'User has: '+newmsgs.length-1+' msgs to read to ME');
if (newmsgs.length) { if (newmsgs.length) {
next = newmsgs[1]; 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)) { if (next && (next.tags === msg.tags)) {
log(LOG_DEBUG,'- Updating scan_ptr to: '+next.number); log(LOG_DEBUG,'- Updating scan_ptr to: '+next.number);
@ -187,14 +119,14 @@ function Session() {
next = newmsgs[0]; next = newmsgs[0];
if (next !== undefined) { if (next !== undefined) {
log(LOG_DEBUG,'- LAST TO ME is: '+next.tags); 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 new message
next = newmsgs[2]; next = newmsgs[2];
if (next !== undefined) { if (next !== undefined) {
log(LOG_DEBUG,'- NEXT TO ME is: '+next.tags); 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 // Previous Message
x = area.MessagePrev(this.frame); x = area.MessagePrev(this.page.name.frame);
if (x) if (x)
this.key[4] = area.page(x.tags); this.page.key[4] = area.page(x.tags);
// Next Message // Next Message
x = area.MessageNext(this.frame); x = area.MessageNext(this.page.name.frame);
if (x) 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 // Render the page
@ -232,10 +166,11 @@ function Session() {
} }
/** /**
* Return the message for a index * Return a system message for a index
* *
* @param index * @param index
* @returns {string|*} * @returns {string|*}
* @see SessionProtocol()
*/ */
Session.prototype.getMessage = function(index) { Session.prototype.getMessage = function(index) {
eval('var msg = this.settings.'+index); eval('var msg = this.settings.'+index);

View File

@ -371,7 +371,7 @@ function rawtoattrs(contents,width,yoffset,xoffset,debug) {
// We are interested in our field match // We are interested in our field match
var df = m.shift().split(';'); 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 // 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) // @todo validate if this goes beyond our width (and if scrolling not enabled)
line = (df[2] ? df[2] : '_').repeat(Math.abs(df[1]))+line; line = (df[2] ? df[2] : '_').repeat(Math.abs(df[1]))+line;

View File

@ -6,7 +6,7 @@ const FRAME_HEIGHT = 22;
const FRAME_PROVIDER_LENGTH = 23; const FRAME_PROVIDER_LENGTH = 23;
const FRAME_PAGE_LENGTH = 11; const FRAME_PAGE_LENGTH = 11;
const FRAME_COST_LENGTH = 6; 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_LEFT = '\x08';
const VIEWDATA_RIGHT = '\x09'; const VIEWDATA_RIGHT = '\x09';
@ -552,34 +552,6 @@ function SessionProtocol() {
return str.replace(/\x1b/g,'').length; 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) { this.qrcode = function(qr) {
// Render the body // Render the body
var qrcode = VIEWDATA_HOME+VIEWDATA_DOWN.repeat(5); var qrcode = VIEWDATA_HOME+VIEWDATA_DOWN.repeat(5);

View File

@ -777,6 +777,18 @@ function Window(x,y,width,height,name,parent,debug) {
return { content: content, x: endx-startx+1 }; 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) // Return the visible children (child should have sort by z)
Window.prototype.visibleChildren = function() { Window.prototype.visibleChildren = function() {
return this.child.filter(function(child) { return this.child.filter(function(child) {

64
main.js
View File

@ -7,6 +7,7 @@
*/ */
log(LOG_DEBUG,'* INIT: ANSItex'); log(LOG_DEBUG,'* INIT: ANSItex');
var debug_mode = 'ansitex/at0593/10010011'; // eg: 'user/password/10010010001';
// SBBS Key definitions // SBBS Key definitions
require('key_defs.js','KEY_ESC'); require('key_defs.js','KEY_ESC');
@ -721,6 +722,20 @@ while (bbs.online) {
case 'login': case 'login':
log(LOG_DEBUG,' - User: '+so.page.input_fields[0].value+'/'+so.page.input_fields[1].value); 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 login is successful, we'll exit here
if (bbs.login(so.page.input_fields[0].value,'',so.page.input_fields[1].value)) { if (bbs.login(so.page.input_fields[0].value,'',so.page.input_fields[1].value)) {
log(LOG_DEBUG,' - User: '+JSON.stringify(user.number)); log(LOG_DEBUG,' - User: '+JSON.stringify(user.number));
@ -731,7 +746,6 @@ while (bbs.online) {
break; break;
} }
log(LOG_DEBUG,'***:'+JSON.stringify(bbs));
log(LOG_DEBUG,' ! Login failed for User:'+JSON.stringify(so.page.input_fields[0].value)); log(LOG_DEBUG,' ! Login failed for User:'+JSON.stringify(so.page.input_fields[0].value));
action = ACTION_GOTO; action = ACTION_GOTO;
next_page = new PageObject(FRAME_LOGIN_FAILED); 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 we are editing a specific frame, attempt to load it
if (next_page) { if (next_page) {
// In case we need to fall back.
var current = so; var current = so;
//so = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex();
so.get(next_page); so.get(next_page);
// If the frame doesnt exist, check that the parent frame exists in case we are creating a new one // 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 // We can always create an 'a' frame
if (next_page.index !== 'a') { 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)})); 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)+')'); log(LOG_DEBUG,'- ACTION_EDIT: check index: '+JSON.stringify(so)+' ('+String.fromCharCode(next_page.index.charCodeAt(0)-1)+')');
if (so.page.name.toString() === null) { if (so.page.name.toString() === null) {
so = current; so = current;
current = undefined;
// sendbaseline ERR_PAGE // sendbaseline ERR_PAGE
so.baselineSend('ERR_NO_PARENT',false); so.baselineSend('ERR_NO_PARENT',false);
action = mode = null; action = mode = null;
@ -955,12 +969,10 @@ while (bbs.online) {
} }
// New frame // New frame
//so = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex(); so.page.name = new PageObject({frame: next_page.frame, index: next_page.index});
so.frame = next_page.frame; so.page.cost = 0;
so.index = next_page.index; so.page.owner = base64_decode(pageOwner(pageStr(next_page)).logo);
so.cost = 0; so.page.content = base64_encode('Start your new page...');
so.owner = base64_decode(pageOwner(pageStr(next_page)).logo);
so.content = base64_encode('Start your new page...');
} }
} }
@ -1004,31 +1016,30 @@ while (bbs.online) {
if (/^1[0-9]{6}1$/.test(next_page.frame)) { if (/^1[0-9]{6}1$/.test(next_page.frame)) {
log(LOG_DEBUG,'- ACTION_GOTO - load echoarea summary: ['+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 // @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 ma = new MsgAreas();
var area = ma.getArea(next_page.frame); var area = ma.getArea(next_page.frame);
// If the template page doesnt exist // If the template page doesnt exist
if ((! to.content) || (! area)) { if ((! so.page.raw) || (! area)) {
so = current;
current = undefined;
so.baselineSend('ERR_ROUTE',false); so.baselineSend('ERR_ROUTE',false);
action = mode = null; action = mode = null;
break; break;
} }
current = so; // @todo Update the page details from the template
//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;
// Parent // 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); so.page.key[0] = (''+next_page.frame).substr(0,7);
// First to me // First to me
@ -1083,10 +1094,7 @@ while (bbs.online) {
if (next_page !== null) { if (next_page !== null) {
current = so; current = so;
//so = (SESSION_EXT === 'vtx') ? new SessionViewdata() : new SessionAnsitex();
log(LOG_DEBUG,'**** Got: ['+JSON.stringify(next_page)+']');
so.get(next_page); so.get(next_page);
log(LOG_DEBUG,' - Got: ['+so.page.name.toString()+']');
if (so.page.name.toString() === null) { if (so.page.name.toString() === null) {
log(LOG_DEBUG,'- Next Page: ['+(next_page.toString()+'] doesnt exist?')); log(LOG_DEBUG,'- Next Page: ['+(next_page.toString()+'] doesnt exist?'));
@ -1139,6 +1147,8 @@ while (bbs.online) {
cf = null; cf = null;
log(LOG_DEBUG,'- ACTION_RELOAD: ['+(next_page ? pageStr(next_page) : '')+']'); 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() console.line_counter = 0; // @todo fix to suppress a pause that is occurring before clear()
so.cursorOff(); so.cursorOff();
@ -1152,7 +1162,7 @@ while (bbs.online) {
// Terminate frame // Terminate frame
case FRAME_TYPE_MAIL_TEMPLATE: case FRAME_TYPE_MAIL_TEMPLATE:
log(LOG_DEBUG,'- MAIL_TEMPLATE: ['+so.frame+']'); log(LOG_DEBUG,'- MAIL_TEMPLATE: ['+so.frame+']');
so.render(ma.getArea(so.frame)); so.render();
action = mode = null; action = mode = null;
break; break;
@ -1168,7 +1178,7 @@ while (bbs.online) {
// External Frame // External Frame
// @todo returning from the frame, go to the 0 key if it is set // @todo returning from the frame, go to the 0 key if it is set
case FRAME_TYPE_EXTERNAL: 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)+']'); log(LOG_DEBUG,'- ACTION_GOTO: EXTERNAL ['+JSON.stringify(content)+']');
switch(content.replace(/\n/,'')) { switch(content.replace(/\n/,'')) {