diff --git a/client/resource/verified_mods.json b/client/resource/verified_mods.json new file mode 100644 index 0000000..ceeca2c --- /dev/null +++ b/client/resource/verified_mods.json @@ -0,0 +1,12 @@ +{ + "Mod Settings": + { + "DependencyPrefix": "EladNLG-ModSettings", + "Versions": [ "1.0.0", "1.1.0" ] + }, + "Moblin.Archon": + { + "DependencyPrefix": "GalacticMoblin-MoblinArchon", + "Versions": [ "1.3.0", "1.3.1" ] + } +} \ No newline at end of file diff --git a/client/verified_mods.js b/client/verified_mods.js new file mode 100644 index 0000000..e300d8f --- /dev/null +++ b/client/verified_mods.js @@ -0,0 +1,86 @@ +const path = require( "path" ) +const fs = require( "fs" ) + +// Checks if a mod entry is an object, has "DependencyPrefix" and "Versions" properties, +// and also checks if both fields have correct format. +function checkModEntry ( modContent ) +{ + if ( typeof modContent !== "object" || Array.isArray( modContent ) || modContent === null ) + return false + if ( !Object.prototype.hasOwnProperty.call( modContent, "DependencyPrefix" ) || !Object.prototype.hasOwnProperty.call( modContent, "Versions" ) ) + return false + + // Checking TeamName-ModName format. + const dependencyPrefix = modContent["DependencyPrefix"] + if ( !/^[a-zA-Z0-9_]+-[a-zA-Z0-9_]+$/.test( dependencyPrefix ) ) + return false + + // Checking x.y.z versions format. + const versions = modContent["Versions"] + for ( const version of versions ) + { + if ( Object.prototype.toString.call( version ) !== "[object String]" || !/[0-9]+\.[0-9]+\.[0-9]$/.test( version ) ) + return false + } + + return true +} + +// Remove mod entries that do not match formatting convention from exposed mods list. +function checkAllMods() +{ + const mods = Object.keys( verifiedMods ) + + for ( let i=0; i +{ + try + { + verifiedMods = JSON.parse( fs.readFileSync( verifiedModsPath ).toString() ) + checkAllMods() + console.log( "Updated verified mods list successfully!" ) + } + catch ( ex ) + { + console.log( `Encountered error updating verified mods list: ${ ex }` ) + } +} ) + +let verifiedMods = {} +if ( fs.existsSync( verifiedModsPath ) ) +{ + verifiedMods = JSON.parse( fs.readFileSync( verifiedModsPath ).toString() ) + checkAllMods() +} + +module.exports = ( fastify, opts, done ) => +{ + // exported routes + + // GET /client/verifiedmods + // returns a list of manually-verified mods + fastify.get( "/client/verifiedmods", + { + config: { rateLimit: getRatelimit( "REQ_PER_MINUTE__CLIENT_VERIFIEDMODS" ) }, // ratelimit + }, + async ( ) => + { + return verifiedMods + } ) + + done() +} diff --git a/dev.env b/dev.env index cfae9c0..85722b6 100644 --- a/dev.env +++ b/dev.env @@ -22,6 +22,7 @@ REQ_PER_MINUTE__CLIENT_ORIGINAUTH=5 REQ_PER_MINUTE__CLIENT_AUTHWITHSERVER=10 REQ_PER_MINUTE__CLIENT_AUTHWITHSELF=25 REQ_PER_MINUTE__CLIENT_MAINMENUPROMOS=20 +REQ_PER_MINUTE__CLIENT_VERIFIEDMODS=1 REQ_PER_MINUTE__CLIENT_SERVERS=100 REQ_PER_MINUTE__SERVER_ADDSERVER=5 REQ_PER_MINUTE__SERVER_HEARTBEAT=60