Compare commits

...

4 Commits

9 changed files with 229 additions and 71 deletions

View File

@ -1,7 +1,8 @@
'use strict';
require('ansitex/load/defs.js','ANSITEX_HOME'); // ANSITEX definitions
// Array of page owners
pageowners = [];
var pageowners = [];
// String repeat.
if (!String.prototype.repeat) {
@ -81,10 +82,8 @@ function ans2bin(ansi,frame) {
* @note bbs.atcodes() cannot process modifiers, so this function is a replacement.
*/
function atcode(field,length,pad,context) {
'use strict';
pad = pad ? pad : ' ';
var result = '';
var result = {};
var args = [];
if (field.search(/:/)) {
@ -92,27 +91,44 @@ function atcode(field,length,pad,context) {
field = args.shift();
}
//log(LOG_DEBUG,'Field:'+field,'Args:'+JSON.stringify(args));
log(LOG_DEBUG,'Field:'+field,'Args:'+JSON.stringify(args));
switch(field) {
// Get the ECHOAREA FTN AREA_TAG
case 'msg_area_areatag':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
// Work out the key for the message area
case 'msg_area_key':
var index = args.shift();
log(LOG_DEBUG,'Context:'+context+', Index:'+index);
// If the message area exists, we'll return a key and a index
if (new MsgAreas().getArea(context+index.padStart(2,'0'))) {
result.value = index;
result.key = '1'+context+index.padStart(2,'0');
}
result = context.msgbase.cfg.area_tag;
break;
// Get the ECHOAREA Description
case 'msg_area_desc':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
// Get the ECHOAREA Internal Code
case 'msg_area_tag':
var index = args.shift();
var area = new MsgAreas().getArea(context+index.padStart(2,'0'));
log(LOG_DEBUG,'Context:'+context+', Index:'+index+', Area:'+JSON.stringify(area));
// If the message area exists
if (area)
result.value = area.code.toUpperCase();
break;
// Get the ECHOAREA Name
case 'msg_area_name':
var index = args.shift();
var area = new MsgAreas().getArea(context+index.padStart(2,'0'));
if (area)
result.value = area.area_name;
result = context.msgbase.cfg.description;
break;
// Oldest message in msgarea
@ -125,7 +141,7 @@ function atcode(field,length,pad,context) {
var x = context.list_tagged[0];
result = x ? x.date : '';
result.value = x ? x.date : '';
break;
case 'msg_area_msgoldest_page':
@ -148,7 +164,7 @@ function atcode(field,length,pad,context) {
var x = context.list_tagged[context.list_tagged.length-1];
result = x ? x.date : '';
result.value = x ? x.date : '';
break;
case 'msg_area_msgnewest_page':
@ -170,7 +186,7 @@ function atcode(field,length,pad,context) {
var x = context.newMsgs();
result = x.length ? x.shift().date : '';
result.value = x.length ? x.shift().date : '';
break;
case 'msg_area_msgunread_page':
@ -191,7 +207,7 @@ function atcode(field,length,pad,context) {
var x = context.newMsgsToMe();
result = x.length > 1 ? x[1].date : '';
result.value = x.length > 1 ? x[1].date : '';
break;
case 'msg_area_msgtome_page':
@ -215,7 +231,7 @@ function atcode(field,length,pad,context) {
break;
}
result = ''+context.newMsgs().length;
result.value = ''+context.newMsgs().length;
break;
// Count of unread messages to me
@ -225,7 +241,7 @@ function atcode(field,length,pad,context) {
break;
}
result = ''+(context.newMsgsToMe().length > 1 ? context.newMsgsToMe().length-1 : 0);
result.value = ''+(context.newMsgsToMe().length > 1 ? context.newMsgsToMe().length-1 : 0);
break;
// Is this message area in my new scan list
@ -235,7 +251,7 @@ function atcode(field,length,pad,context) {
break;
}
result = (context.getUserStats().scan_ptr & SCAN_CFG_TOYOU) ? 'YES' : 'NO';
result.value = (context.getUserStats().scan_ptr & SCAN_CFG_TOYOU) ? 'YES' : 'NO';
break;
// Is this message area in my new scan list
@ -245,7 +261,7 @@ function atcode(field,length,pad,context) {
break;
}
result = ''+context.list_untagged.length;
result.value = ''+context.list_untagged.length;
break;
// Get the ECHOAREA Total Number of Messages
@ -255,7 +271,7 @@ function atcode(field,length,pad,context) {
break;
}
result = ''+context.msgbase.total_msgs;
result.value = ''+context.msgbase.total_msgs;
break;
// Get the ECHOAREA Group Name
@ -265,29 +281,29 @@ function atcode(field,length,pad,context) {
break;
}
result = context.zone_name;
result.value = context.zone_name;
break;
case 'nodeid':
result = getNodeID();
result.value = getNodeID();
break;
default:
result = (typeof bbs === 'undefined') ? '*'.repeat(Math.abs(length)) : bbs.atcode(field+(args.length ? ':'+args : ''));
result.value = (typeof bbs === 'undefined') ? '*'.repeat(Math.abs(length)) : bbs.atcode(field+(args.length ? ':'+args : ''));
}
if ((result === null) || (typeof result === 'undefined'))
result = '';
if ((result.value === null) || (result.value === undefined))
result.value = '';
length = length ? length : result.length;
length = length ? length : result.value.length;
//log(LOG_DEBUG,' - result length ['+result.length+'] desired ('+length+')');
if (result.length < Math.abs(length))
result = (length < 0) ? padright(result,Math.abs(length),pad) : padleft(result,length,pad);
else if (result.length > Math.abs(length))
result = result.substr(0,Math.abs(length));
if (result.value.length < Math.abs(length))
result.value = (length < 0) ? padright(result.value,Math.abs(length),pad) : padleft(result.value,length,pad);
else if (result.value.length > Math.abs(length))
result.value = result.value.substr(0,Math.abs(length));
log(LOG_DEBUG,'* ATCODE ['+field+'] ('+length+'|"'+pad+'") returns ['+result+']');
log(LOG_DEBUG,'* ATCODE ['+field+'] ('+length+'|"'+pad+'") returns ['+result.value+'] key ['+result.key+']');
return result;
}

View File

@ -12,6 +12,7 @@ function MsgAreas() {
var zone_id;
var zone_name;
var ma;
var cfg = [];
// Load the message areas
for (var g in msg_area.grp_list) {
@ -22,6 +23,7 @@ function MsgAreas() {
ma.group_id = g;
ma.sub_id = a;
// Work out the zone by the FTN address of the area
if (msg_area.grp_list[g].name.indexOf(':') === -1) {
// If the sub is enabled for FTN, and the zone < 9999, then we'll us that if zone_id is undefined
if ((msg_area.grp_list[g].sub_list[a].settings & SUB_FIDO) && msg_area.grp_list[g].sub_list[a].fidonet_addr) {
@ -29,22 +31,49 @@ function MsgAreas() {
if ((x > 0) && (x < 9999)) {
zone_id = x.padStart(4,'0');
zone_name = msg_area.grp_list[g].name;
} else {
zone_id = undefined;
zone_name = undefined;
}
} else {
zone_id = undefined;
zone_name = undefined;
}
// Work out the zone by the name, where name is zone_id:name
} else {
zone_id = msg_area.grp_list[g].name.split(':')[0];
zone_name = msg_area.grp_list[g].name.split(':')[1];
}
if (zone_id) {
if (cfg[zone_id] === undefined) {
log(LOG_DEBUG,'Opening internal:'+FRAMES_MSG_BASE+' to work out subs for zone: '+zone_id);
var internal = new MsgArea();
internal.code = FRAMES_MSG_BASE;
var conf = internal.get('1'+zone_id+'99999a');
// @todo Quick hack for scripts
if (SESSION_EXT === undefined)
var SESSION_EXT = 'tex';
if (conf !== undefined)
cfg[zone_id] = conf.content[SESSION_EXT].content.map(function(item) { return item.toLowerCase(); });
else
cfg[zone_id] = [];
}
ma.zone_id = zone_id;
ma.zone_name = zone_name;
ma.code = msg_area.grp_list[g].sub_list[a].code;
// Our area_id can be embedded in the name of the area
if (msg_area.grp_list[g].sub_list[a].name.indexOf(':') !== -1) {
var sublist = msg_area.grp_list[g].sub_list[a].name.split(':');
ma.area_id = sublist[0];
ma.area_name = sublist[1];
/*
writeln(' code:'+ma.code);
@ -52,10 +81,28 @@ function MsgAreas() {
writeln(' pageprefix:'+ma.page_prefix)
writeln();
*/
}
}
log(LOG_DEBUG,'Hard set index to ['+ma.area_id+'] for: '+ma.code);
this.areas.push(ma);
// Otherwise we get our area_id from the configuration - page 999 of the zone
} else {
var index = (cfg[zone_id].indexOf(msg_area.grp_list[g].sub_list[a].code)+1).toString().padStart(2,'0');
// Make sure that index isnt already defined
if (this.areas.filter(function(item) { return (item.zone_id === zone_id) && (item.area_id === index); }).length) {
log(LOG_ERROR,'! ERROR: Prefix ['+index+'] already defined in ['+zone_id+'], ignoring ['+ma.code+']');
} else if ((cfg[zone_id] !== undefined) && cfg[zone_id].length) {
if (index === '00')
ma.area_id = undefined;
else
ma.area_id = index;
}
}
ma.area_name = msg_area.grp_list[g].sub_list[a].description;
this.areas.push(ma);
}
}
}
@ -98,14 +145,14 @@ function MsgAreas() {
if (area === undefined)
return undefined;
return this.areas.filter(function(x) {
// If the area is a 6 digits, then its a page prefix, otherwise its an area code name
if ((area.length === 6) && (NUMERIC_REGEX.test(area)))
return x.page_prefix === area;
return (((area.length === 6) && (NUMERIC_REGEX.test(area)))
? this.areas.filter(function(x) {
return x.page_prefix === area;
})
else
return x.code === area;
}).pop();
: this.areas.filter(function(x) {
return x.code === area;
})).pop();
}
// @todo review
@ -130,13 +177,18 @@ function MsgArea() {
this.area_id = undefined; // Sub Area ID for this message area, eg: 01
this.area_name = undefined; // Sub Area Name for this message area, eg: CHAT
this.group_id = undefined; // SBBS Message Group ID
this.sub_id = undefined; // SBBS Message Sub ID
this.__properties__ = {
code: undefined, // SBBS Message Sub Internal Code
};
// MSG Base Code
Object.defineProperty(this,'code',{
get: function() {
//writeln('group_id:'+this.group_id+' sub_id:'+this.sub_id);
return msg_area.grp_list[this.group_id].sub_list[this.sub_id].code;
return this.__properties__.code;
},
set: function(code) {
this.__properties__.code = code;
}
});
@ -150,7 +202,7 @@ function MsgArea() {
msgbase = this.msgbase;
} else if (this.managed) {
msgbase = new MsgAreas().getArea(FRAMES_MSG_BASE).msgbase;
msgbase = new MsgBase(FRAMES_MSG_BASE);
regex = this.page_prefix_regex;
} else
@ -220,16 +272,15 @@ function MsgArea() {
Object.defineProperty(this,'last_tagged_message',{
get: function() {
var last_tag = this.frames.sort(function(a,b) {
if (a.when_imported_time === b.when_imported_time)
return a.number > b.number
else
return (a.when_imported_time > b.when_imported_time);
return (a.when_imported_time !== b.when_imported_time)
? a.when_imported_time > b.when_imported_time
: a.number > b.number;
}).pop();
if (last_tag === undefined)
return undefined;
var msgbase = new MsgAreas().getArea(FRAMES_MSG_BASE).msgbase;
var msgbase = new MsgBase(FRAMES_MSG_BASE);
try {
if (msgbase.open()) {
@ -413,6 +464,48 @@ function MsgArea() {
}
});
// Get message header for page
MsgArea.prototype.get = function(page) {
if (this.code !== FRAMES_MSG_BASE)
return undefined;
var msgbase = this.msgbase;
var msgs = [];
try {
if (msgbase.open()) {
log(LOG_DEBUG,'Looking for ['+page+'] in ['+this.code+']');
var index = msgbase
.get_all_msg_headers();
for (var x in index)
if ((index[x].from === 'SYSTEM') && (index[x].to === page))
msgs.push(index[x]);
if (msgs.length) {
var msg = msgs.sort(function(a,b) {
return (a.when_imported_time !== b.when_imported_time)
? a.when_imported_time > b.when_imported_time
: a.number > b.number;
}).pop();
return this.getContent(msg.number);
} else {
return undefined;
}
}
} catch (e) {
log(LOG_ERROR,this.code+' cannot be opened (frames):'+e.message);
return undefined;
}
return content;
}
// Get frame content
MsgArea.prototype.getContent = function(id) {
// @todo If this is for a echomail/netmail content, then we need to switch message bases
@ -429,8 +522,10 @@ function MsgArea() {
// Our messages are terminated with FRAMES_EOF_MARKER
var regex = new RegExp('^(.*)'+FRAMES_EOF_MARKER);
//log(LOG_DEBUG,'MARKER:'+regex.test(raw));
if (! regex.test(raw))
if (! regex.test(raw)) {
msgbase.close();
return undefined;
}
var regex = new RegExp(FRAMES_EOF_MARKER+'[.\\s\\S]*$');
@ -640,7 +735,7 @@ function MsgArea() {
*/
MsgArea.prototype.tag_msgs = function() {
var msgs = this.untagged;
var msgbase = new MsgAreas().getArea(FRAMES_MSG_BASE).msgbase;
var msgbase = new MsgBase(FRAMES_MSG_BASE);
var page_next = this.page_next;
writeln('* We have '+msgs.length+' messages to tag, starting at '+page_next);

View File

@ -145,6 +145,7 @@ function Page(debug) {
key: [], // Key actions
raw: {}, // Page raw content for each session type
date: undefined, // Date of frame
};
this.__defaults__ = {
@ -284,6 +285,20 @@ function Page(debug) {
}
});
Object.defineProperty(this,'date',{
get: function() {
if (this.__properties__.date !== undefined)
return strftime("%a, %d %b %Y %H:%M:%S %z",this.__properties__.date);
},
set: function(int) {
if (typeof int !== 'number')
throw new Error('DATE must be a epoch');
return this.__properties__.date = int;
}
});
Page.prototype.__defineGetter__('dimensions',function() {
return this.__properties__.width+' X '+this.__properties__.height;
});
@ -360,7 +375,7 @@ function Page(debug) {
this.__properties__.name = object;
if ((''+this.__properties__.name.frame).length > FRAME_PAGE_LENGTH-1-FRAME_ATTR_LENGTH)
throw new Error('Pagenum too large');
throw new Error('Pagenum too large - '+(''+this.__properties__.name.frame).length+'|'+(FRAME_PAGE_LENGTH-1-FRAME_ATTR_LENGTH));
switch (SESSION_EXT) {
case 'tex':
@ -492,7 +507,7 @@ function Page(debug) {
// Insert our *_field data (if it is set)
function insert_fields(fields,build) {
for (var i in fields) {
//log(LOG_DEBUG,'|-- Adding:'+fields[i].name+', with value:'+fields[i].value);
log(LOG_DEBUG,'|-- Adding:'+fields[i].name+', with value:'+fields[i].value);
var content = fields[i].value.split('');
@ -530,12 +545,20 @@ function Page(debug) {
* Build in our dynamic_fields that can be populated automatically
*/
this.build_system_fields = function(context) {
log(LOG_DEBUG,'Building system fields with context:'+context);
var that = this;
var f = this.dynamic_fields.filter(function(item) { return item.value === undefined; });
if (f.length) {
f.forEach(function(field) {
that.dynamic_field(field.name,atcode(field.name,field.length,field.pad,context));
f.forEach(function(field,key) {
log(LOG_DEBUG,'Key is:'+key);
var ac = atcode(field.name,field.length,field.pad,context);
that.dynamic_field(field.name,ac.value);
if (ac.key) {
log(LOG_DEBUG,'ATCODE sets key for ['+field.name+'] using ['+ac.key+']');
that.__properties__.key[ac.value] = ac.key;
}
});
}
}
@ -1304,7 +1327,7 @@ function Page(debug) {
* Save the frame to the message base
*/
this.save = function() {
var msgbase = new MsgAreas().getArea(FRAMES_MSG_BASE).msgbase;
var msgbase = new MsgBase(FRAMES_MSG_BASE);
if (! msgbase.open()) {
log(LOG_ERROR,'! Message Base cannot be opened (save): ['+msgbase.error+']');
@ -1315,7 +1338,7 @@ function Page(debug) {
to: this.name,
from: 'SYSTEM',
tags: this.name,
date: strftime("%a, %d %b %Y, %I:%M:%S %Z",this.date),
date: this.date,
subject: 'Content',
};
@ -1329,9 +1352,8 @@ function Page(debug) {
var body = LZString.compressToBase64(JSON.stringify(page))+FRAMES_EOF_MARKER;
if (! msgbase.save_msg(hdr,body)) {
if (! msgbase.save_msg(hdr,body))
log(LOG_ERROR,' ! Error saving frame: ['+this.name.toString()+']');
}
msgbase.close();
return true;

23
main.js
View File

@ -488,6 +488,10 @@ while (bbs.online) {
if (read === '*') {
log(LOG_DEBUG,'- MODE_BL: Abort ['+cmd+'])');
// 695 = NodeActionMain
bbs.replace_text(695,'\1h%s \1nViewing \1h*'+so.page.name.toString()+'#\1n');
bbs.node_action=NODE_MAIN;
action = mode = null;
cmd = '';
so.cursorOff();
@ -1015,7 +1019,22 @@ while (bbs.online) {
// @todo consider how we do mail security.
// Echoarea mail summary
if (/^1[0-9]{6}1$/.test(next_page.frame)) {
if (/^1[0-9]{4}1$/.test(next_page.frame)) {
log(LOG_DEBUG,'- ACTION_GOTO - load echoarea list: ['+next_page.frame.toString().slice(1,5)+']');
if (! so.get(new PageObject({frame: next_page.frame, index: next_page.index}))) {
so.baselineSend('ERR_ROUTE',false);
action = mode = null;
break;
}
// @todo trigger page load, it isnt loaded yet so build_system_fields does nothing
so.page.build_system_fields(next_page.frame.toString().slice(1,5));
next_page = null;
// Echoarea list
} else if (/^1[0-9]{6}1$/.test(next_page.frame)) {
log(LOG_DEBUG,'- ACTION_GOTO - load echoarea summary: ['+next_page.frame+']');
var ma = new MsgAreas();
@ -1138,6 +1157,8 @@ while (bbs.online) {
cf = null;
log(LOG_DEBUG,'- ACTION_RELOAD: ['+(next_page ? pageStr(next_page) : '')+']');
// If we have configured debug_mode auto login, jump to the debug_mode page
if (debug_mode && so.page.name.toString() === '98b')
so.page.key[1] = debug_mode.split('/')[2];

View File

@ -1 +1 @@
{"version":2,"cost":0,"key":[null,11,2,null,null,null,null,null,5162,516],"dynamic_fields":[{"name":"DATE:%Y-%b-%d","length":11,"pad":" ","x":30,"y":6},{"name":"nodeid","length":8,"pad":" ","x":33,"y":7}]}
{"version":2,"cost":0,"key":[null,11,2,null,null,null,null,97,5162,516],"dynamic_fields":[{"name":"DATE:%Y-%b-%d","length":11,"pad":" ","x":30,"y":6},{"name":"nodeid","length":8,"pad":" ","x":33,"y":7}]}

Binary file not shown.

View File

@ -1 +1 @@
7ccks3w{#35 ,l|l|,,7k#37k#55jjj 45j 55 kj/|5ho <=$,5uzzzpquzpu5 /./*,//upzpquzp5 Videotex *0_To get back here DATE........... NODE ........$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$ 1Fido Message Networks 8Navigating AnsiTEX 9About AnsiTEX *95_ Help *99_ Log off 
7ccks3w{#35 ,l|l|,,7k#37k#55jjj 45j 55 kj/|5ho <=$,5uzzzpquzpu5 /./*,//upzpquzp5 Videotex *0_To get back here DATE........... NODE ........$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$0$ 1Fido Message Networks 8Navigating AnsiTEX 9About AnsiTEX *95_ Help *99_ Log off 

View File

@ -32,6 +32,7 @@ var po = new PageObject(argv[0]);
if (p.get(po)) {
writeln('Page : '+p.name);
writeln('- Date : '+p.date);
writeln('- Cost : '+p.cost);
writeln('- Owner : '+p.owner);
writeln('- Key : '+p.key);

View File

@ -12,6 +12,9 @@ if (argv.length !== 1) {
var ma = new MsgAreas();
var area = ma.getArea(argv[0]);
if (area === undefined)
throw Error('Area:'+argv[0]+' is not defined.');
writeln('Opening ['+argv[0]+'] - ('+area.code+')');
var msgbase = area.msgbase;