diff --git a/.gitignore b/.gitignore index ceaea36..836e1f4 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,4 @@ dist .yarn/install-state.gz .pnp.* +data/gameFiles/* \ No newline at end of file diff --git a/controllers/db.js b/controllers/db.js index a82edf7..648c2e4 100644 --- a/controllers/db.js +++ b/controllers/db.js @@ -23,6 +23,12 @@ function initDB() { delivered_at TEXT DEFAULT CURRENT_TIMESTAMP ) `) + db.exec(` + CREATE TABLE IF NOT EXISTS launchers ( + hardware_id TEXT NOT NULL, + last_minecraft_uuid TEXT NOT NULL + ) + `) } function banLauncher(last_minecraft_uuid, hardware_id, banned_by, remote_ip, reason) { @@ -124,6 +130,22 @@ function regenerateToken(oldKey, newKey) { } } +function setLastUUIDForLauncher(hardware_id, last_minecraft_uuid) { + const query = ` + INSERT INTO launchers (hardware_id, last_minecraft_uuid) + VALUES (?, ?) + ` + try { + const stmt = db.prepare(query) + const result = stmt.run(hardware_id, last_minecraft_uuid) + return true + } catch (error) { + logger.error("[DATABASE] ") + logger.error(error) + return false + } +} + module.exports = { initDB, getBan, @@ -132,5 +154,6 @@ module.exports = { isTokenValid, createToken, revokeToken, - regenerateToken + regenerateToken, + setLastUUIDForLauncher } \ No newline at end of file diff --git a/data/main.db b/data/main.db index b7972b7..2d095a0 100644 Binary files a/data/main.db and b/data/main.db differ diff --git a/routes/api/v1/ban/index.js b/routes/api/v1/ban/index.js index 918405c..94cfb74 100644 --- a/routes/api/v1/ban/index.js +++ b/routes/api/v1/ban/index.js @@ -12,7 +12,6 @@ router.post("/iam", (req, res) => { logger.log(`{Route:"/api/v1/ban/iam"} Strange request from ip<${ip}>`) } else { const potentialBan = controller.getBan(req.body.hwid) - console.log(potentialBan) if (potentialBan != undefined) { delete potentialBan.remote_ip delete potentialBan.hardware_id diff --git a/routes/api/v1/file/game.js b/routes/api/v1/file/game.js new file mode 100644 index 0000000..cefebb3 --- /dev/null +++ b/routes/api/v1/file/game.js @@ -0,0 +1,21 @@ +const fs = require("node:fs") +const path = require("node:path") +const utils = require("../../../../modules/utils") +const express = require("express") +const router = express() + +router.use("", (req, res) => { + const gameFiles = path.join(__dirname, "..", "..", "..", "..", "data", "gameFiles") + if (fs.existsSync(finalPath)) { + try { + res.status(200).json(fs.readdirSync(gameFiles, { recursive: true })) + } catch (error) { + console.error(error) + utils.handleError(req, res, 500, "Erreur interne du serveur.") + } + } else { + utils.handleError(req, res, 404, "Fichier introuvable.") + } +}) + +module.exports = router \ No newline at end of file diff --git a/routes/api/v1/telemetry.js b/routes/api/v1/telemetry.js new file mode 100644 index 0000000..4af6215 --- /dev/null +++ b/routes/api/v1/telemetry.js @@ -0,0 +1,12 @@ +const utils = require("../../../modules/utils") +const logger = require("../../../modules/logger") +const controller = require("../../../controllers/db") +const express = require("express") +const router = express() + +router.get("/:hwid/:uuid", (req, res) => { + const { hwid, uuid } = req.params + controller.setLastUUIDForLauncher(hwid, uuid) +}) + +module.exports = router \ No newline at end of file diff --git a/test.js b/test.js index 090a265..a513c78 100644 --- a/test.js +++ b/test.js @@ -1,3 +1,3 @@ -const x = require("./controllers/db") +const db = require("./controllers/db") -console.log(x.getBan("a")) \ No newline at end of file +db.createToken("907946d6-2ecc-4aec-bf63-413d717ac1fd", "azures04") \ No newline at end of file