Fix out of date version system

This commit is contained in:
Thomas Smyth 2020-12-08 17:16:32 +00:00
parent fb7ba533a9
commit 8a29ad043f
6 changed files with 52 additions and 19 deletions

View File

@ -10,7 +10,8 @@ class Logger {
let colorFunc = chalk[this.colors[module] || 'white']; let colorFunc = chalk[this.colors[module] || 'white'];
if (typeof colorFunc !== 'function') colorFunc = chalk.white; if (typeof colorFunc !== 'function') colorFunc = chalk.white;
if ((this.verboseness[module] || 1) >= verboseness) console.log(`[${colorFunc(module)}][${verboseness}] ${message}`, ...extras) if ((this.verboseness[module] || 1) >= verboseness)
console.log(`[${colorFunc(module)}][${verboseness}] ${message}`, ...extras);
} }
setVerboseness(module, verboseness) { setVerboseness(module, verboseness) {

View File

@ -1,6 +1,6 @@
{ {
"name": "SquadJS", "name": "SquadJS",
"version": "1.4.8", "version": "2.0.0-beta1",
"repository": "https://github.com/Thomas-Smyth/SquadJS.git", "repository": "https://github.com/Thomas-Smyth/SquadJS.git",
"author": "Thomas Smyth <https://github.com/Thomas-Smyth>", "author": "Thomas Smyth <https://github.com/Thomas-Smyth>",
"license": "BSL-1.0", "license": "BSL-1.0",

View File

@ -17,7 +17,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
export default class SquadServerFactory { export default class SquadServerFactory {
static async buildFromConfig(config) { static async buildFromConfig(config) {
for (const plugin of Object.keys(plugins)) { for (const plugin of Object.keys(plugins)) {
Logger.setColor(plugin, "magentaBright"); Logger.setColor(plugin, 'magentaBright');
} }
// setup logging levels // setup logging levels

View File

@ -130,7 +130,12 @@ export default class AutoKickUnassigned extends BasePlugin {
async updateTrackingList(forceUpdate = false) { async updateTrackingList(forceUpdate = false) {
const run = !(this.betweenRounds || this.server.players.length < this.options.playerThreshold); const run = !(this.betweenRounds || this.server.players.length < this.options.playerThreshold);
this.verbose(3, `Update Tracking List? ${run} (Between rounds: ${this.betweenRounds}, Below player threshold: ${this.server.players.length < this.options.playerThreshold})`) this.verbose(
3,
`Update Tracking List? ${run} (Between rounds: ${
this.betweenRounds
}, Below player threshold: ${this.server.players.length < this.options.playerThreshold})`
);
if (!run) { if (!run) {
for (const steamID of Object.keys(this.trackedPlayers)) this.untrackPlayer(steamID); for (const steamID of Object.keys(this.trackedPlayers)) this.untrackPlayer(steamID);
@ -152,8 +157,7 @@ export default class AutoKickUnassigned extends BasePlugin {
if (!isUnassigned) continue; if (!isUnassigned) continue;
if (isAdmin) this.verbose(2, `Admin is Unassigned: ${player.name}`); if (isAdmin) this.verbose(2, `Admin is Unassigned: ${player.name}`);
if (isWhitelist) if (isWhitelist) this.verbose(2, `Whitelist player is Unassigned: ${player.name}`);
this.verbose(2, `Whitelist player is Unassigned: ${player.name}`);
// start tracking player // start tracking player
if ( if (

View File

@ -19,7 +19,10 @@ export default class BasePlugin {
); );
} }
this.options[optionName] = typeof this.rawOptions[optionName] !== 'undefined' ? this.rawOptions[optionName] : option.default; this.options[optionName] =
typeof this.rawOptions[optionName] !== 'undefined'
? this.rawOptions[optionName]
: option.default;
} }
} }
} }

View File

@ -2,21 +2,44 @@ import axios from 'axios';
import { SQUADJS_VERSION, COPYRIGHT_MESSAGE } from './constants.js'; import { SQUADJS_VERSION, COPYRIGHT_MESSAGE } from './constants.js';
export default async function () { function versionOutOfDate(current, latest) {
const { data } = await axios.get( const cMatch = current.match(/([0-9]+)\.([0-9]+)\.([0-9]+)(?:-beta([0-9]*))?/);
'https://raw.githubusercontent.com/Thomas-Smyth/SquadJS/master/package.json' const lMatch = latest.match(/([0-9]+)\.([0-9]+)\.([0-9]+)(?:-beta([0-9]*))?/);
);
const cMatch = SQUADJS_VERSION.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/).shift(); cMatch.shift();
const lMatch = data.version.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/).shift(); lMatch.shift();
const [cMajor, cMinor, cPatch] = cMatch; const [cMajor, cMinor, cPatch, cBetaVersion] = cMatch;
const [lMajor, lMinor, lPatch] = lMatch; const [lMajor, lMinor, lPatch, lBetaVersion] = lMatch;
const outdatedVersion = return (
cMajor < lMajor || cMajor < lMajor ||
(cMajor === lMajor && cMinor < lMinor) || (cMajor === lMajor && cMinor < lMinor) ||
(cMajor === lMajor && cMinor === lMinor && cPatch < lPatch); (cMajor === lMajor && cMinor === lMinor && cPatch < lPatch) ||
(cBetaVersion &&
lBetaVersion &&
cMajor === lMajor &&
cMinor === lMinor &&
cPatch === lPatch &&
cBetaVersion < lBetaVersion)
);
}
export default async function () {
const { data: masterData } = await axios.get(
`https://raw.githubusercontent.com/Thomas-Smyth/SquadJS/master/package.json`
);
const { data: betaData } = await axios.get(
`https://raw.githubusercontent.com/Thomas-Smyth/SquadJS/beta/package.json`
);
const branch = SQUADJS_VERSION.includes('beta') ? 'beta' : 'master';
const outdated =
(branch === 'master' && versionOutOfDate(SQUADJS_VERSION, masterData.version)) ||
(branch === 'beta' &&
(versionOutOfDate(SQUADJS_VERSION, masterData.version) ||
versionOutOfDate(SQUADJS_VERSION, betaData.version)));
console.log( console.log(
` `
@ -31,9 +54,11 @@ export default async function () {
${COPYRIGHT_MESSAGE} ${COPYRIGHT_MESSAGE}
GitHub: https://github.com/Thomas-Smyth/SquadJS GitHub: https://github.com/Thomas-Smyth/SquadJS
Latest Version: ${data.version}, Installed Version: ${SQUADJS_VERSION}, Latest Version: ${
branch === 'master' ? masterData.version : betaData.version
}, Installed Version: ${SQUADJS_VERSION},
${ ${
outdatedVersion outdated
? 'Your SquadJS version is outdated, please consider updating.' ? 'Your SquadJS version is outdated, please consider updating.'
: 'Your SquadJS version is up to date.' : 'Your SquadJS version is up to date.'
} }