2022-04-20 11:19:01 +00:00
|
|
|
const PAGE_LENGTH = 4; // The size of our page tag.
|
|
|
|
const PAGE_LAST_KEY = 'last_page';
|
|
|
|
const MAX_PAGE_NUM = 9999;
|
|
|
|
|
2022-04-18 11:27:25 +00:00
|
|
|
// Our message bases
|
|
|
|
function MsgAreas() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
this.areas = [];
|
|
|
|
this.areas_excluded = [];
|
|
|
|
var zone_id;
|
|
|
|
var zone_name;
|
|
|
|
var ma;
|
|
|
|
|
|
|
|
for(var g in msg_area.grp_list) {
|
|
|
|
if (msg_area.grp_list[g].name.indexOf(':') !== -1) {
|
|
|
|
zone_id = msg_area.grp_list[g].name.split(':')[0];
|
|
|
|
zone_name = msg_area.grp_list[g].name.split(':')[1];
|
|
|
|
|
|
|
|
for (var a in msg_area.grp_list[g].sub_list) {
|
|
|
|
if (msg_area.grp_list[g].sub_list[a].name.indexOf(':') !== -1) {
|
|
|
|
ma = new MsgArea();
|
|
|
|
ma.zone_id = zone_id;
|
|
|
|
ma.zone_name = zone_name;
|
|
|
|
ma.area_id = msg_area.grp_list[g].sub_list[a].name.split(':')[0];
|
|
|
|
ma.area_name = msg_area.grp_list[g].sub_list[a].name.split(':')[1];
|
|
|
|
ma.code = msg_area.grp_list[g].sub_list[a].code;
|
|
|
|
|
|
|
|
this.areas.push(ma);
|
|
|
|
} else {
|
|
|
|
this.areas_excluded.push(zone_name+':'+msg_area.grp_list[g].sub_list[a].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
zone_name = msg_area.grp_list[g].name;
|
|
|
|
|
|
|
|
for (var a in msg_area.grp_list[g].sub_list) {
|
|
|
|
this.areas_excluded.push(zone_name+':'+msg_area.grp_list[g].sub_list[a].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function MsgArea() {
|
|
|
|
this.zone_id = undefined;
|
|
|
|
this.zone_name = undefined;
|
|
|
|
this.area_id = undefined;
|
|
|
|
this.area_name = undefined;
|
|
|
|
this.msgbase = undefined;
|
|
|
|
this.headers = undefined;
|
|
|
|
this.tagged_list = undefined;
|
|
|
|
this.untagged_list = undefined;
|
2022-04-22 12:42:20 +00:00
|
|
|
this.grp_number = undefined;
|
|
|
|
this.subnum = undefined;
|
2022-04-18 11:27:25 +00:00
|
|
|
|
|
|
|
Object.defineProperty(this,'code',{
|
|
|
|
set: function(code) {
|
|
|
|
this.msgbase = new MsgBase(code);
|
|
|
|
|
|
|
|
if (! this.msgbase.open()) {
|
|
|
|
writeln(code+' cannot be opened:'+this.msgbase.error);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.headers = this.msgbase.get_all_msg_headers(false,false);
|
|
|
|
this.msgbase.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get Area's full name
|
|
|
|
Object.defineProperty(this,'full_name',{
|
|
|
|
get: function() {
|
|
|
|
return this.zone_name+':'+this.area_name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Total Messages
|
|
|
|
Object.defineProperty(this,'list',{
|
|
|
|
get: function() {
|
|
|
|
return this.headers ? Object.keys(this.headers) : [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Total tagged messages
|
|
|
|
Object.defineProperty(this,'list_tagged',{
|
|
|
|
get: function() {
|
|
|
|
if (this.tagged_list === undefined) {
|
|
|
|
this.tagged_list = [];
|
|
|
|
|
|
|
|
if (! this.headers)
|
|
|
|
return this.tagged_list;
|
|
|
|
|
|
|
|
for(var x in this.headers) {
|
|
|
|
if (this.headers[x].tags && (this.headers[x].tags.length === PAGE_LENGTH)) {
|
|
|
|
this.tagged_list.push(this.headers[x]);
|
|
|
|
write(); // @todo This is needed for this to work?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.tagged_list;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// List untagged messages
|
|
|
|
Object.defineProperty(this,'list_untagged',{
|
|
|
|
get: function() {
|
|
|
|
if (this.untagged_list === undefined) {
|
|
|
|
this.untagged_list = [];
|
|
|
|
|
|
|
|
if (! this.headers)
|
|
|
|
return this.untagged_list;
|
|
|
|
|
|
|
|
for(var x in this.headers) {
|
|
|
|
if ((! this.headers[x].tags) || (this.headers[x].tags.length !== PAGE_LENGTH)) {
|
|
|
|
this.untagged_list.push(this.headers[x]);
|
|
|
|
write(); // @todo This is needed for this to work?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-24 12:36:47 +00:00
|
|
|
return this.untagged_list;
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get Next page number
|
|
|
|
Object.defineProperty(this,'page_next',{
|
|
|
|
get: function() {
|
|
|
|
var f = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
|
|
|
if (! f.open('r')) {
|
|
|
|
writeln('Unable to open ini file');
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2022-04-26 11:54:34 +00:00
|
|
|
var page = f.iniGetValue('prefix:'+this.page_prefix,PAGE_LAST_KEY)
|
2022-04-18 11:27:25 +00:00
|
|
|
f.close();
|
|
|
|
|
|
|
|
return page ? page : '0'.repeat(PAGE_LENGTH);
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(page) {
|
|
|
|
var f = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
|
|
|
if (! f.open('r+')) {
|
|
|
|
writeln('Unable to open ini file');
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2022-04-26 11:54:34 +00:00
|
|
|
f.iniSetValue('prefix:'+this.page_prefix,PAGE_LAST_KEY,(''+page).padStart(4,'0'));
|
2022-04-18 11:27:25 +00:00
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Our page prefix for this msg area
|
|
|
|
Object.defineProperty(this,'page_prefix',{
|
|
|
|
get: function() {
|
|
|
|
return ''+this.zone_id+this.area_id;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a specific message with a tag
|
|
|
|
*/
|
|
|
|
MsgArea.prototype.getMessage = function(page) {
|
|
|
|
var msg = undefined;
|
|
|
|
|
|
|
|
for(var x in this.headers) {
|
|
|
|
if (this.headers[x].tags === page) {
|
|
|
|
msg = this.headers[x];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
write(); // @todo This is needed for this to work?
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! msg)
|
|
|
|
return undefined;
|
|
|
|
|
2022-04-20 11:19:01 +00:00
|
|
|
if (! this.msgbase.open()) {
|
|
|
|
writeln(code+' cannot be opened:'+this.msgbase.error);
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2022-04-22 12:42:20 +00:00
|
|
|
msg.grp_number = this.msgbase.cfg.grp_number;
|
|
|
|
var cfg = this.msgbase.cfg;
|
|
|
|
msg.subnum = msg_area.grp_list[cfg.grp_number].sub_list.filter(function(x) { return x.number === cfg.number; }).pop().index;
|
2022-04-18 11:27:25 +00:00
|
|
|
msg.content = this.msgbase.get_msg_body(false,msg.number,false,false,true,true);
|
|
|
|
this.msgbase.close();
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tag messages with a frame number
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
MsgArea.prototype.tag_msgs = function() {
|
2022-04-22 12:42:20 +00:00
|
|
|
const MAX_PAGE_NUM = 9999;
|
|
|
|
|
2022-04-18 11:27:25 +00:00
|
|
|
var msgs = this.list_untagged;
|
|
|
|
|
|
|
|
// See if we need to something
|
|
|
|
if (! msgs.length)
|
|
|
|
return;
|
|
|
|
|
2022-04-20 11:19:01 +00:00
|
|
|
if (! this.msgbase.open()) {
|
|
|
|
writeln(code+' cannot be opened:'+this.msgbase.error);
|
2022-04-18 11:27:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var page_next = this.page_next;
|
2022-04-22 12:42:20 +00:00
|
|
|
|
2022-04-18 11:27:25 +00:00
|
|
|
for(var x in msgs) {
|
2022-04-22 12:42:20 +00:00
|
|
|
msgs[x].tags = (''+(page_next)).padStart(4,'0');
|
|
|
|
|
|
|
|
if(! this.msgbase.put_msg_header(msgs[x].number,msgs[x])) {
|
2022-04-18 11:27:25 +00:00
|
|
|
writeln('ERROR:'+this.msgbase.error);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
page_next++;
|
2022-04-22 12:42:20 +00:00
|
|
|
if (page_next > MAX_PAGE_NUM)
|
|
|
|
page_next = 0;
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.msgbase.close();
|
|
|
|
this.page_next = page_next;
|
2022-04-20 11:19:01 +00:00
|
|
|
|
2022-04-18 11:27:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-01 07:42:19 +00:00
|
|
|
MsgAreas.prototype.getArea = function(area) {
|
|
|
|
log(LOG_DEBUG,'- AREA:'+JSON.stringify(area));
|
|
|
|
if (area === undefined)
|
2022-04-20 11:19:01 +00:00
|
|
|
return undefined;
|
|
|
|
|
2022-05-01 07:42:19 +00:00
|
|
|
var zone = (''+area).substr(1,4);
|
|
|
|
var echo = (''+area).substr(5,2);
|
|
|
|
log(LOG_DEBUG,' - zone:'+JSON.stringify(zone));
|
|
|
|
log(LOG_DEBUG,' - echo:'+JSON.stringify(echo));
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2022-05-01 07:42:19 +00:00
|
|
|
return this.areas.filter(function(x) {
|
2022-04-18 11:27:25 +00:00
|
|
|
return x.zone_id === zone && x.area_id === echo;
|
|
|
|
})[0]
|
2022-05-01 07:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MsgAreas.prototype.getMessage = function(page) {
|
|
|
|
var area = this.getArea(page);
|
|
|
|
log(LOG_DEBUG,' - msg:'+JSON.stringify(page.substr(7,4)));
|
|
|
|
|
|
|
|
return area ? area.getMessage(page.substr(7,4)) : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgAreas.prototype.getUserStats = function(page) {
|
|
|
|
var area = this.getArea(page);
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2022-05-01 07:42:19 +00:00
|
|
|
return area ? msg_area.grp_list[area.msgbase.cfg.grp_number].sub_list[msg_area.sub[area.msgbase.cfg.code].index] : undefined;
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|