Various bug fixes

This commit is contained in:
Nathan Byrd 2023-11-04 23:38:43 +00:00
parent e2a9d35bb1
commit 9bb8277583
6 changed files with 66 additions and 40 deletions

View File

@ -16,9 +16,7 @@ const stringFormat = require('./string_format');
const fs = require('graceful-fs'); const fs = require('graceful-fs');
const _ = require('lodash'); const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
const iconv = require('iconv-lite');
const { mkdirs } = require('fs-extra'); const { mkdirs } = require('fs-extra');
const { stripMciColorCodes } = require('./color_codes.js');
const parseFullName = require('parse-full-name').parseFullName; const parseFullName = require('parse-full-name').parseFullName;
@ -43,6 +41,7 @@ module.exports = class DropFile {
this.dropFileFormatDirectory = paths.join( this.dropFileFormatDirectory = paths.join(
__dirname, __dirname,
'..',
'dropfile_formats' 'dropfile_formats'
); );
} }
@ -86,7 +85,7 @@ module.exports = class DropFile {
// TODO: Replace with a switch statement once we have binary handlers as well // TODO: Replace with a switch statement once we have binary handlers as well
// Read the directory containing the dropfile formats, and return undefined if we don't have the format // Read the directory containing the dropfile formats, and return undefined if we don't have the format
const fileName = this.fileName(); const fileName = this.fileName;
if (!fileName) { if (!fileName) {
Log.info({fileType: this.fileType}, 'Dropfile format not supported.'); Log.info({fileType: this.fileType}, 'Dropfile format not supported.');
return undefined; return undefined;
@ -105,28 +104,39 @@ module.exports = class DropFile {
getContents() { getContents() {
const handler = this.getHandler().bind(this); const handler = this.getHandler().bind(this);
return handler(); const contents = handler();
return contents;
} }
getDropfile() { getDropfile() {
// Get the filename to read // Get the filename to read
const fileName = paths.join(this.dropFileFormatDirectory, this.fileName()); const fileName = paths.join(this.dropFileFormatDirectory, this.fileName);
// Read file, or return empty string if it doesn't exist let text = fs.readFileSync(fileName);
fs.readFile(fileName, (err, data) => {
if (err) { // Format the data with string_format and predefined_mci
Log.warn({filename: fileName}, 'Error reading dropfile format file.'); let formatObj = getPredefinedMCIFormatObject(this.client, text);
return '';
} const additionalFormatObj = {
let text = data; 'getSysopFirstName': this.getSysopFirstName(),
// Format the data with string_format and predefined_mci 'getSysopLastName': this.getSysopLastName(),
const formatObj = getPredefinedMCIFormatObject(this.client, data); 'getUserFirstName': this.getUserFirstName(),
if (formatObj) { 'getUserLastName': this.getUserLastName(),
// Expand the text 'getUserTotalDownloadK': this.getUserTotalDownloadK(),
text = stringFormat(text, formatObj, true); 'getUserTotalUploadK': this.getUserTotalUploadK(),
} 'getCurrentDateMMDDYY': this.getCurrentDateMMDDYY(),
return text; 'getSystemDailyDownloadK': this.getSystemDailyDownloadK(),
}); 'getUserBirthDateMMDDYY': this.getUserBirthDateMMDDYY(),
};
// Add additional format objects to the format object
formatObj = _.merge(formatObj, additionalFormatObj);
if (formatObj) {
// Expand the text
text = stringFormat(text, formatObj, true);
}
return text;
} }
@ -166,6 +176,24 @@ module.exports = class DropFile {
return StatLog.getUserStatNum(this.client.user, UserProps.FileDlTotalBytes) / 1024; return StatLog.getUserStatNum(this.client.user, UserProps.FileDlTotalBytes) / 1024;
} }
getSystemDailyDownloadK() {
return StatLog.getSystemStatNum(SysProps.getSystemDailyDownloadK) / 1024;
}
getUserTotalUploadK() {
return StatLog.getUserStatNum(this.client.user, UserProps.FileUlTotalBytes) / 1024;
}
getCurrentDateMMDDYY() {
// Return current date in MM/DD/YY format
return moment().format('MM/DD/YY');
}
getUserBirthDateMMDDYY() {
// Return user's birthdate in MM/DD/YY format
return moment(this.client.user.properties[UserProps.Birthdate]).format('MM/DD/YY');
}
getDoorInfoFileName() { getDoorInfoFileName() {
let x; let x;
const node = this.client.node; const node = this.client.node;
@ -179,13 +207,14 @@ module.exports = class DropFile {
return 'DORINFO' + x + '.DEF'; return 'DORINFO' + x + '.DEF';
} }
createFile(cb) { createFile(cb) {
mkdirs(paths.dirname(this.fullPath), err => { mkdirs(paths.dirname(this.fullPath), err => {
if (err) { if (err) {
return cb(err); return cb(err);
} }
return fs.writeFile(this.fullPath, this.getContents(), cb); const fullPath = this.fullPath;
const contents = this.getContents();
return fs.writeFile(fullPath, contents, cb);
}); });
} }
}; };

View File

@ -127,9 +127,6 @@ const PREDEFINED_MCI_GENERATORS = {
UZ: function sanitizedUserName(client) { UZ: function sanitizedUserName(client) {
return client.user.getSanitizedName(); return client.user.getSanitizedName();
}, },
UM: function userComment(client) {
return userStatAsString(client, UserProps.UserComment, '');
},
LL: function legacyUserLevel(client) { LL: function legacyUserLevel(client) {
return client.user.getLegacySecurityLevel().toString(); return client.user.getLegacySecurityLevel().toString();
}, },

View File

@ -5,7 +5,7 @@
{UA} {UA}
M M
{AP} {AP}
{DT} {getCurrentDateMMDDYY}
{SW} {SW}
{SH} {SH}
{LL} {LL}
@ -24,8 +24,8 @@ C:\DATA\BBS.LOG
{SR} {SR}
1 1
0 0
0 {getUserTotalUploadK}
{UP} {UP}
0 {getUserTotalDownloadK}
{DN} {DN}
8N1 8N1

View File

@ -14,7 +14,7 @@ N
NOT PROVIDED NOT PROVIDED
{LL} {LL}
{UC} {UC}
{DT} {getCurrentDateMMDDYY}
9999 9999
999 999
GR GR
@ -27,9 +27,9 @@ N
Y Y
{UP} {UP}
{DN} {DN}
0 {getSystemDailyDownloadK}
9999999 9999999
{BD} {getUserBirthDateMMDDYY}
C:\DATA C:\DATA
C:\DATA C:\DATA
{SR} {SR}
@ -40,13 +40,13 @@ Y
Y Y
7 7
32767 32767
{DT} {getCurrentDateMMDDYY}
{CT} {CT}
{CT} {CT}
9999 9999
{DD} {DD}
0 {getUserTotalUploadK}
0 {getUserTotalDownloadK}
{UM}
{DR} {DR}
32767 32767

View File

@ -1,11 +1,11 @@
{BN} {BN}
UNKNOWN {getSysopFirstName}
UNKNOWN {getSysopLastName}
COM1 COM1
19200 BAUD,N,8,1 19200 BAUD,N,8,1
0 0
UNKNOWN {getUserFirstName}
UNKNOWN {getUserLastName}
{LO} {LO}
1 1
{LL} {LL}

View File

@ -7,7 +7,7 @@ Y
999 999
555-555-1212 555-555-1212
{LO} {LO}
{BD} {getUserBirthDateMMDDYY}
{ND} {ND}
1 1
19200 19200