diff --git a/core/dropfile.js b/core/dropfile.js index 40bfd3b8..de57d841 100644 --- a/core/dropfile.js +++ b/core/dropfile.js @@ -16,9 +16,7 @@ const stringFormat = require('./string_format'); const fs = require('graceful-fs'); const _ = require('lodash'); const moment = require('moment'); -const iconv = require('iconv-lite'); const { mkdirs } = require('fs-extra'); -const { stripMciColorCodes } = require('./color_codes.js'); const parseFullName = require('parse-full-name').parseFullName; @@ -43,6 +41,7 @@ module.exports = class DropFile { this.dropFileFormatDirectory = paths.join( __dirname, + '..', 'dropfile_formats' ); } @@ -86,7 +85,7 @@ module.exports = class DropFile { // 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 - const fileName = this.fileName(); + const fileName = this.fileName; if (!fileName) { Log.info({fileType: this.fileType}, 'Dropfile format not supported.'); return undefined; @@ -105,28 +104,39 @@ module.exports = class DropFile { getContents() { const handler = this.getHandler().bind(this); - return handler(); + const contents = handler(); + return contents; } getDropfile() { // 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 - fs.readFile(fileName, (err, data) => { - if (err) { - Log.warn({filename: fileName}, 'Error reading dropfile format file.'); - return ''; - } - let text = data; - // Format the data with string_format and predefined_mci - const formatObj = getPredefinedMCIFormatObject(this.client, data); - if (formatObj) { - // Expand the text - text = stringFormat(text, formatObj, true); - } - return text; - }); + let text = fs.readFileSync(fileName); + + // Format the data with string_format and predefined_mci + let formatObj = getPredefinedMCIFormatObject(this.client, text); + + const additionalFormatObj = { + 'getSysopFirstName': this.getSysopFirstName(), + 'getSysopLastName': this.getSysopLastName(), + 'getUserFirstName': this.getUserFirstName(), + 'getUserLastName': this.getUserLastName(), + 'getUserTotalDownloadK': this.getUserTotalDownloadK(), + 'getUserTotalUploadK': this.getUserTotalUploadK(), + 'getCurrentDateMMDDYY': this.getCurrentDateMMDDYY(), + '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; } + 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() { let x; const node = this.client.node; @@ -179,13 +207,14 @@ module.exports = class DropFile { return 'DORINFO' + x + '.DEF'; } - createFile(cb) { mkdirs(paths.dirname(this.fullPath), err => { if (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); }); } }; diff --git a/core/predefined_mci.js b/core/predefined_mci.js index 1018c890..53620f9b 100644 --- a/core/predefined_mci.js +++ b/core/predefined_mci.js @@ -127,9 +127,6 @@ const PREDEFINED_MCI_GENERATORS = { UZ: function sanitizedUserName(client) { return client.user.getSanitizedName(); }, - UM: function userComment(client) { - return userStatAsString(client, UserProps.UserComment, ''); - }, LL: function legacyUserLevel(client) { return client.user.getLegacySecurityLevel().toString(); }, diff --git a/dropfile_formats/CHAIN.TXT b/dropfile_formats/CHAIN.TXT index dae3243d..2e47e75b 100644 --- a/dropfile_formats/CHAIN.TXT +++ b/dropfile_formats/CHAIN.TXT @@ -5,7 +5,7 @@ {UA} M {AP} -{DT} +{getCurrentDateMMDDYY} {SW} {SH} {LL} @@ -24,8 +24,8 @@ C:\DATA\BBS.LOG {SR} 1 0 -0 +{getUserTotalUploadK} {UP} -0 +{getUserTotalDownloadK} {DN} 8N1 \ No newline at end of file diff --git a/dropfile_formats/DOOR.SYS b/dropfile_formats/DOOR.SYS index 0fc038d4..a81540ef 100644 --- a/dropfile_formats/DOOR.SYS +++ b/dropfile_formats/DOOR.SYS @@ -14,7 +14,7 @@ N NOT PROVIDED {LL} {UC} -{DT} +{getCurrentDateMMDDYY} 9999 999 GR @@ -27,9 +27,9 @@ N Y {UP} {DN} -0 +{getSystemDailyDownloadK} 9999999 -{BD} +{getUserBirthDateMMDDYY} C:\DATA C:\DATA {SR} @@ -40,13 +40,13 @@ Y Y 7 32767 -{DT} +{getCurrentDateMMDDYY} {CT} {CT} 9999 {DD} -0 -0 -{UM} +{getUserTotalUploadK} +{getUserTotalDownloadK} + {DR} 32767 \ No newline at end of file diff --git a/dropfile_formats/DORINFO1.DEF b/dropfile_formats/DORINFO1.DEF index 2fcc900e..a127156e 100644 --- a/dropfile_formats/DORINFO1.DEF +++ b/dropfile_formats/DORINFO1.DEF @@ -1,11 +1,11 @@ {BN} -UNKNOWN -UNKNOWN +{getSysopFirstName} +{getSysopLastName} COM1 19200 BAUD,N,8,1 0 -UNKNOWN -UNKNOWN +{getUserFirstName} +{getUserLastName} {LO} 1 {LL} diff --git a/dropfile_formats/TRIBBS.SYS b/dropfile_formats/TRIBBS.SYS index 8b419844..69dad1e3 100644 --- a/dropfile_formats/TRIBBS.SYS +++ b/dropfile_formats/TRIBBS.SYS @@ -7,7 +7,7 @@ Y 999 555-555-1212 {LO} -{BD} +{getUserBirthDateMMDDYY} {ND} 1 19200