From 018ee63853966b41c5cb5ea656ba629bac294baa Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 19 Dec 2024 17:52:35 +0700 Subject: [PATCH] Message base configuration now stored in page 99999 of zone --- load/msgbases.js | 137 ++++++++++++++++++++++++++++++++++++------- load/page.js | 9 ++- tools/frames_list.js | 3 + 3 files changed, 122 insertions(+), 27 deletions(-) diff --git a/load/msgbases.js b/load/msgbases.js index 7a07af5..295ff50 100644 --- a/load/msgbases.js +++ b/load/msgbases.js @@ -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,26 @@ 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; + } + } + + this.areas.push(ma); + } } } @@ -98,14 +143,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 +175,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 +200,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 +270,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 +462,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 +520,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 +733,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); diff --git a/load/page.js b/load/page.js index 0b6fc87..6a16ed7 100644 --- a/load/page.js +++ b/load/page.js @@ -288,7 +288,7 @@ function Page(debug) { Object.defineProperty(this,'date',{ get: function() { if (this.__properties__.date !== undefined) - return strftime("%a, %d %b %Y %I:%M:%S %z",this.__properties__.date); + return strftime("%a, %d %b %Y %H:%M:%S %z",this.__properties__.date); }, set: function(int) { @@ -375,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': @@ -1319,7 +1319,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+']'); @@ -1344,9 +1344,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; diff --git a/tools/frames_list.js b/tools/frames_list.js index d7cd035..d60745a 100644 --- a/tools/frames_list.js +++ b/tools/frames_list.js @@ -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;