From 043892d8a48aa4adb6592f7fc567e5eb14f2a639 Mon Sep 17 00:00:00 2001 From: PARGSoft Date: Wed, 15 Jun 2022 11:42:51 +0100 Subject: [PATCH] DBViewer work and README improvements --- README.md | 32 +++++++++++++++++++++--- core/server/tarkovSend.js | 4 ++- core/util/utility.js | 32 +++++++++++++++++++++++- dbViewer/traders.html | 2 +- src/Controllers/ItemController.js | 4 ++- src/Controllers/ResponseController.js | 36 +++++++++++++++++++++------ src/Controllers/TradingController.js | 9 +++++++ 7 files changed, 104 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3ac5518..31a7660 100644 --- a/README.md +++ b/README.md @@ -9,17 +9,20 @@ - Press F5 to Debug ## Compiling to Windows EXE, Linux or MacOS -- Open GitBash +- Open VS Code Terminal or Open GitBash on Directory - Execute pkg . -- Wait until JustEmuTarkov-win.exe, JustEmuTarkov-linux, JustEmuTarkov-macos appear +- Wait until Server.exe appears / Process completes ## Distribution Zip the following folders & files - core (this is likely unwanted but pkg is not handling this correctly yet) - db -- docs +- dbViewer +- express - node_modules +- out +- public - res - src - user @@ -38,7 +41,30 @@ Zip the following folders & files - Run the Server - Provide your friends with your external IP address and port +## Features +- A modified Tarkov experience where you can host your own server and play alone or with others (working Client also required see [SIT.Tarkov.Launcher](https://github.com/paulov-t/SIT.Tarkov.Launcher) for details) +- A set of configurations to tailor your gameplay +- Airdrops (must have accompanying BepInEx plugin) +- AI PMCs +- Listens to extra Client Events +- JET Mod Support +- SPT-Aki Mod Support - *In Progress* +- Client sends more events to the Server - *In Progress* + ## Known working Server mods - [SIT M4](https://github.com/paulov-t/SIT-Mod-M4) - Makes the M4 actually useful and good mod to show how to make changes of your own. - [SIT AI](https://github.com/paulov-t/SIT.ServerMod.AI) - Makes all AI move around, be more aggressive and generally make the game much harder. +- [SamSwat Benelli M4-Super-90 (m1014) - New Weapon](https://hub.sp-tarkov.com/files/file/261-l85-sa80-a2-british-assault-rifle/) +- [SamSwat L85 SA80 AR - New Weapon](https://hub.sp-tarkov.com/files/file/181-benelli-m4-super-90-m1014/) +- [Nehax MagazineManiac](https://github.com/Nehaxfr/Nehax-MagazineManiac) + +## Documentation +*This is Work in Progress* +- Documentation can be auto generated using ``npm run generate-docs .`` +- You can run the server and discover the generated docs at https://localhost:443/out or https://localhost:443/docs + +## DB Viewer +*This is Work in Progress* +- You can find the DBViewer at https://localhost:443/db + \ No newline at end of file diff --git a/core/server/tarkovSend.js b/core/server/tarkovSend.js index c7e02c7..fa219e9 100644 --- a/core/server/tarkovSend.js +++ b/core/server/tarkovSend.js @@ -82,8 +82,10 @@ class TarkovSend { const _split = file.split("."); let type = TarkovSend.mimeTypes[_split[_split.length - 1]] || TarkovSend.mimeTypes["txt"]; + // console.log(process.cwd() + "/" + file); + // console.log(file); // Post 0.12.12.15.17975, it now gets stuff from files not res - if(file.indexOf("/files/") !== -1 && !fs.existsSync(process.cwd() + file)) + if(file.indexOf("/files/") !== -1 && !fs.existsSync(process.cwd() + "/" + file)) file = file.replace("/files/", "/res/"); let fileStream = fs.createReadStream(file); diff --git a/core/util/utility.js b/core/util/utility.js index df2c569..d39981c 100644 --- a/core/util/utility.js +++ b/core/util/utility.js @@ -472,4 +472,34 @@ exports.splitStack = (item) => { return stacks; } -exports.clamp = (value, min, max) => Math.min(Math.max(value, min), max); \ No newline at end of file +exports.clamp = (value, min, max) => Math.min(Math.max(value, min), max); + +/** +* This ES6(ECMAScript) function getQueryStringParameters takes url +* as parmater and returns +* parameters name and value in JSON key value format +* @parameter {String} url +* (if url is not passed it takes the current url +* from window.location.href) +* +**/ +exports.getQueryStringParameters = url => { + + var query = ""; + if (url){ + if(url.split("?").length>0){ + query = url.split("?")[1]; + } + }else{ + url = window.location.href; + query = window.location.search.substring(1); + } + return (/^[?#]/.test(query) ? query.slice(1) : query) + .split('&') + .reduce((params, param) => +{ + let [ key, value ] = param.split('='); + params[key] = value?decodeURIComponent(value.replace(/\+/g, ' ')):''; + return params; +}, { }); +}; \ No newline at end of file diff --git a/dbViewer/traders.html b/dbViewer/traders.html index b2afacb..5b96ebd 100644 --- a/dbViewer/traders.html +++ b/dbViewer/traders.html @@ -245,7 +245,7 @@

{{ item.base.nickname }}

, methods: { updateAssort(traderId) { $.ajax( { - url : `/db/getTradingAssort/${traderId}`, + url : `/db/getTradingAssort?tid=${traderId}`, type: 'POST', async: false, dataType : "json", diff --git a/src/Controllers/ItemController.js b/src/Controllers/ItemController.js index 9863513..c0d6f8e 100644 --- a/src/Controllers/ItemController.js +++ b/src/Controllers/ItemController.js @@ -7,7 +7,9 @@ const utility = require('../../core/util/utility'); class ItemController { static getDatabaseItems() { - return DatabaseController.getDatabase().items; + const dbItems = DatabaseController.getDatabase().items; + + return dbItems; } /** diff --git a/src/Controllers/ResponseController.js b/src/Controllers/ResponseController.js index f52de5b..1d4d272 100644 --- a/src/Controllers/ResponseController.js +++ b/src/Controllers/ResponseController.js @@ -445,10 +445,12 @@ class ResponseDbViewer { constructor() { // Items ---------------- - var listOfItems = ItemController.getDatabaseItems(); - for(const itemId in listOfItems) { - ResponseController.addRoute(`/db/getItemInfo/${itemId}`, (url, info, sessionID) => { return JSON.stringify(listOfItems[itemId]); }); - }; + ResponseController.addRoute(`/db/getItemInfo`, (url, info, sessionID) => { + const qsParams = utility.getQueryStringParameters(url); + var listOfItems = ItemController.getDatabaseItems(); + return JSON.stringify(listOfItems(qsParams.itemId)); + + }); ResponseController.addRoute(`/db/searchItemsByName/`, (url, info, sessionID) => { if (info.searchParams !== undefined) { for(const itemId in listOfItems) { @@ -460,19 +462,37 @@ class ResponseDbViewer { // Traders ---------------- var listOfTraders = TradingController.getAllTraders(); - ResponseController.addRoute(`/db/getTraders/`, (url, info, sessionID) => { return JSON.stringify(listOfTraders); }) + ResponseController.addRoute(`/db/getTraders/`, (url, info, sessionID) => { + // always get the database current list of traders, so recall getAllTraders here + return JSON.stringify(TradingController.getAllTraders()); + }); for(const t of listOfTraders) { ResponseController.addRoute(`/db/getTraderInfo/${t.base._id}`, (url, info, sessionID) => { - return JSON.stringify(t); - }) + return JSON.stringify(TradingController.getTrader(t.base._id)); + }); ResponseController.addRoute(`/db/getTradingAssort/${t.base._id}`, (url, info, sessionID) => { const assort = TradingController.getTraderAssort(t.base._id); assort.items.forEach(element => { element["itemInfo"] = ItemController.getDatabaseItems()[element._tpl]; }); return JSON.stringify(assort); - }) + }); }; + ResponseController.addRoute(`/db/getTraderInfo`, (url, info, sessionID) => { + const qsParams = utility.getQueryStringParameters(url); + + return JSON.stringify(TradingController.getTrader(qsParams.tid)); + + }); + ResponseController.addRoute(`/db/getTradingAssort`, (url, info, sessionID) => { + const qsParams = utility.getQueryStringParameters(url); + + const assort = TradingController.getTraderAssort(qsParams.tid); + assort.items.forEach(element => { + element["itemInfo"] = ItemController.getDatabaseItems()[element._tpl]; + }); + return JSON.stringify(assort); + }); // Users ---------------- // var listOfTraders = TradingController.getAllTraders(); diff --git a/src/Controllers/TradingController.js b/src/Controllers/TradingController.js index 72b78fd..e1a9a64 100644 --- a/src/Controllers/TradingController.js +++ b/src/Controllers/TradingController.js @@ -348,6 +348,15 @@ class TradingController { DatabaseController.getDatabase().traders[traderId] = assort; } + /** + * + * @param {*} traderId + * @returns + */ + static getTrader(traderId) { + return DatabaseController.getDatabase().traders[traderId]; + } + /** * * @param {*} traderId