2020-07-17 14:36:49 +00:00
|
|
|
// Array of page owners
|
|
|
|
pageowners = [];
|
|
|
|
|
2020-03-27 05:14:33 +00:00
|
|
|
// String repeat.
|
2019-10-03 04:08:48 +00:00
|
|
|
if (!String.prototype.repeat) {
|
2019-10-15 10:48:16 +00:00
|
|
|
String.prototype.repeat = function(count) {
|
|
|
|
'use strict';
|
|
|
|
if (this == null) {
|
|
|
|
throw new TypeError('can\'t convert ' + this + ' to object');
|
|
|
|
}
|
|
|
|
var str = '' + this;
|
|
|
|
count = +count;
|
|
|
|
if (count != count) {
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
if (count < 0) {
|
|
|
|
throw new RangeError('repeat count must be non-negative');
|
|
|
|
}
|
|
|
|
if (count == Infinity) {
|
|
|
|
throw new RangeError('repeat count must be less than infinity');
|
|
|
|
}
|
|
|
|
count = Math.floor(count);
|
|
|
|
if (str.length == 0 || count == 0) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
// Ensuring count is a 31-bit integer allows us to heavily optimize the
|
|
|
|
// main part. But anyway, most current (August 2014) browsers can't handle
|
|
|
|
// strings 1 << 28 chars or longer, so:
|
|
|
|
if (str.length * count >= 1 << 28) {
|
|
|
|
throw new RangeError('repeat count must not overflow maximum string size');
|
|
|
|
}
|
|
|
|
var rpt = '';
|
|
|
|
for (;;) {
|
|
|
|
if ((count & 1) == 1) {
|
|
|
|
rpt += str;
|
|
|
|
}
|
|
|
|
count >>>= 1;
|
|
|
|
if (count == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
str += str;
|
|
|
|
}
|
|
|
|
return rpt;
|
|
|
|
};
|
2019-10-03 04:08:48 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 11:56:12 +00:00
|
|
|
/**
|
|
|
|
* Turn off the cursor
|
|
|
|
*/
|
2019-10-03 04:08:48 +00:00
|
|
|
function cursorOff() {
|
2020-03-26 06:22:46 +00:00
|
|
|
ansi.send('ext_mode','clear','cursor');
|
2019-10-15 10:48:16 +00:00
|
|
|
console.gotoxy(0,24);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a message base by code
|
|
|
|
*
|
|
|
|
* @param code
|
|
|
|
* @returns {number | string|boolean}
|
|
|
|
*/
|
2020-03-27 05:14:33 +00:00
|
|
|
function findMsgBase(code) {
|
2019-10-15 10:48:16 +00:00
|
|
|
if (! code)
|
|
|
|
code = "tex_data";
|
|
|
|
|
|
|
|
// Find the actual sub-code
|
|
|
|
var sub_code;
|
|
|
|
|
|
|
|
for (var s in msg_area.sub) {
|
|
|
|
var sub = msg_area.sub[s];
|
|
|
|
|
|
|
|
if (sub.code.substr(-code.length).toLowerCase() == code)
|
|
|
|
return sub.code;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-10-03 04:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an argument from argv, or an error if it doesnt exit
|
|
|
|
*
|
|
|
|
* @param key
|
|
|
|
* @param error
|
|
|
|
*/
|
|
|
|
function getArg(key,error,abort) {
|
2019-10-15 10:48:16 +00:00
|
|
|
index = argv.indexOf(key);
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
if ((index !== -1) && (! (argv[index+1] === undefined || argv[index+1].match(/^-/)))) {
|
|
|
|
return argv[index+1];
|
|
|
|
}
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
if (abort) {
|
|
|
|
log(LOG_ERROR,error);
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-10-03 04:08:48 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 11:56:57 +00:00
|
|
|
function getPageOwners() {
|
|
|
|
// Load the owner configuration into memory
|
|
|
|
if (! pageowners.length) {
|
|
|
|
var f = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
|
|
|
|
|
|
|
if (f.open("r")) {
|
|
|
|
var logo = f.iniGetValue('prefix','logo');
|
|
|
|
var users = f.iniGetValue('prefix','user');
|
|
|
|
log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users));
|
|
|
|
pageowners.push({prefix: 0,logo: logo,user:users});
|
|
|
|
|
|
|
|
f.iniGetSections('prefix:').forEach(function (prefix) {
|
|
|
|
var p = parseInt(prefix.substr(7));
|
|
|
|
var logo = f.iniGetValue(prefix,'logo','');
|
|
|
|
var users = f.iniGetValue(prefix,'user','');
|
|
|
|
log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users));
|
|
|
|
pageowners.push({prefix: p,logo: logo,user: users});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
// Sort the pageowners ascending
|
|
|
|
pageowners.sort(compare);
|
|
|
|
|
|
|
|
log(LOG_DEBUG,'+ pageOwner: pageowners='+JSON.stringify(pageowners));
|
|
|
|
}
|
|
|
|
|
|
|
|
return pageowners;
|
|
|
|
}
|
|
|
|
|
2019-10-20 11:31:15 +00:00
|
|
|
function loadOptions() {
|
2020-02-26 11:54:39 +00:00
|
|
|
ini = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
2019-10-20 11:31:15 +00:00
|
|
|
|
|
|
|
if (!ini.open("r")) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = ini.iniGetObject(null);
|
|
|
|
|
|
|
|
ini.close();
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
function msgBaseImport(msgbase,page,text) {
|
2019-10-15 10:48:16 +00:00
|
|
|
var msgbase = new MsgBase(findMsgBase(msgbase));
|
|
|
|
|
|
|
|
log(LOG_DEBUG,'Sending ['+page+'] to message base ['+msgbase.cfg.code+']');
|
|
|
|
|
|
|
|
var hdr = { to:'All', from:'Videotex', subject:'Frame: '+page };
|
|
|
|
|
|
|
|
var body = '';
|
|
|
|
body += text+"\r\n";
|
|
|
|
body += "--- " + js.exec_file + " " + '1.0' + "\r\n";
|
|
|
|
|
|
|
|
return msgbase.save_msg(hdr, body);
|
|
|
|
}
|
|
|
|
|
2019-10-03 04:08:48 +00:00
|
|
|
/**
|
|
|
|
* Return the frame as a string
|
|
|
|
*/
|
|
|
|
function pageStr(page) {
|
2020-03-26 06:22:46 +00:00
|
|
|
if (page.frame==null)
|
|
|
|
return null;
|
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
if (! page.index)
|
|
|
|
page.index = 'a';
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2020-07-17 14:36:49 +00:00
|
|
|
return page.frame.toString()+page.index;
|
2019-10-03 04:08:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 10:57:25 +00:00
|
|
|
/**
|
2020-07-17 14:36:49 +00:00
|
|
|
* Read our videotex.ini configuration and determine who owns a page.
|
|
|
|
* If there is no prefix for the page, it is owned by the system '0'
|
2019-10-22 10:57:25 +00:00
|
|
|
*
|
2020-07-17 14:36:49 +00:00
|
|
|
* @param page
|
|
|
|
* @returns {undefined}
|
2019-10-22 10:57:25 +00:00
|
|
|
*/
|
2020-07-17 14:36:49 +00:00
|
|
|
function pageOwner(page) {
|
2020-07-21 11:56:57 +00:00
|
|
|
var BreakException = {};
|
|
|
|
var o = null;
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-21 11:56:57 +00:00
|
|
|
try {
|
|
|
|
getPageOwners().forEach(function(owner) {
|
|
|
|
var p = owner.prefix.toString();
|
|
|
|
o = owner;
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-21 11:56:57 +00:00
|
|
|
var re = new RegExp('^' + p, 'g');
|
|
|
|
if (page.toString().match(re)) {
|
|
|
|
//log(LOG_DEBUG,'= pageOwner: p='+p+',o: '+o);
|
|
|
|
throw BreakException;
|
|
|
|
}
|
|
|
|
});
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-21 11:56:57 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (e !== BreakException) throw e;
|
|
|
|
}
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-21 11:56:57 +00:00
|
|
|
//log(LOG_DEBUG,'+ pageOwner: page='+page+', owner: '+JSON.stringify(o));
|
|
|
|
return o;
|
|
|
|
}
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-21 11:56:57 +00:00
|
|
|
/**
|
|
|
|
* Can the user edit the frame
|
|
|
|
*
|
|
|
|
* @param page
|
|
|
|
* @param user
|
|
|
|
*/
|
|
|
|
function pageEditor(page) {
|
|
|
|
//log(LOG_DEBUG,'+ pageEditor: page='+page+', user #'+user.number);
|
2019-10-22 10:57:25 +00:00
|
|
|
|
2020-07-18 13:48:51 +00:00
|
|
|
var BreakException = {};
|
2020-07-21 11:56:57 +00:00
|
|
|
var pageditor = false;
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-18 13:48:51 +00:00
|
|
|
try {
|
2020-07-21 11:56:57 +00:00
|
|
|
getPageOwners().forEach(function(owner) {
|
2020-07-18 13:48:51 +00:00
|
|
|
var p = owner.prefix.toString();
|
2020-07-21 11:56:57 +00:00
|
|
|
//log(LOG_DEBUG,' - pageEditor: '+JSON.stringify(owner));
|
|
|
|
frameusers = owner.user ? owner.user.toString().split(',') : [1];
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-21 11:56:57 +00:00
|
|
|
log(LOG_DEBUG,' - pageEditor: p='+p+'('+p.length+') user ['+JSON.stringify(frameusers)+'] - :'+frameusers.indexOf(user.number.toString()));
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-18 13:48:51 +00:00
|
|
|
var re = new RegExp('^' + p, 'g');
|
2020-07-21 11:56:57 +00:00
|
|
|
if (page.toString().match(re) && (frameusers.indexOf(user.number.toString()) == 1)) {
|
|
|
|
pageditor = true;
|
2020-07-18 13:48:51 +00:00
|
|
|
throw BreakException;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
if (e !== BreakException) throw e;
|
|
|
|
}
|
2020-07-17 14:36:49 +00:00
|
|
|
|
2020-07-21 11:56:57 +00:00
|
|
|
//log(LOG_DEBUG,'+ pageEditor: page='+page+', editor: '+JSON.stringify(pageditor));
|
|
|
|
return pageditor;
|
2020-07-17 14:36:49 +00:00
|
|
|
}
|
2019-10-22 10:57:25 +00:00
|
|
|
|
2020-07-17 14:36:49 +00:00
|
|
|
function compare(a,b) {
|
|
|
|
return (a.prefix < b.prefix) ? 1 : ((b.prefix < a.prefix) ? -1 : 0);
|
2019-10-22 10:57:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 11:56:12 +00:00
|
|
|
/**
|
|
|
|
* Send a message to the baseline.
|
|
|
|
*
|
|
|
|
* @param text
|
|
|
|
* @param reposition
|
|
|
|
*/
|
2019-10-03 04:08:48 +00:00
|
|
|
function sendBaseline(text,reposition) {
|
|
|
|
console.pushxy();
|
|
|
|
console.gotoxy(0,24);
|
|
|
|
console.print(text);
|
|
|
|
console.cleartoeol();
|
|
|
|
|
|
|
|
if (! reposition) {
|
|
|
|
console.popxy();
|
|
|
|
}
|
2020-05-27 11:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this;
|