From ea040dc4f7b00f6b254c392ee44a1a6e59132632 Mon Sep 17 00:00:00 2001 From: PARGSoft Date: Fri, 27 May 2022 11:58:52 +0100 Subject: [PATCH] additional checks and fixes to account creation --- README.md | 14 +++++++-- _CreateBuildDir.bat | 12 ++++---- src/Controllers/AccountController.js | 43 ++++++++++++++++++++++------ user/configs/server_base.json | 2 +- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 47ce5ec0..0ff74069 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# Server Readme.md +# Tarkov Emulated Central Server -## Current Tarkov Version (working) -- 0.12.12.15.17861 +## Current known working Tarkov Version +- 0.12.12.15.* ## Debugging - Download and Install [Visual Studio Code](https://code.visualstudio.com/) @@ -25,6 +25,11 @@ Zip the following folders & files - user - Server.exe +## How to use (if not compiling yourself or using a release) +- Download the latest release +- Ensure the code and the Server.exe are in the same folder +- Run Server.exe + ## How to host this server to others (this may change soon) - Open port 7777 on your router - Open user/configs/server.json and change port value to 7777 (this can anything but this is a good easily memorable open one to use) @@ -32,4 +37,7 @@ Zip the following folders & files - Open user/configs/server.json and change ip_backend value to your external IP (google to find out how to find it) - Run the Server - Provide your friends with your external IP address and port + +## Known usable 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. \ No newline at end of file diff --git a/_CreateBuildDir.bat b/_CreateBuildDir.bat index 3199b419..9d9fa107 100644 --- a/_CreateBuildDir.bat +++ b/_CreateBuildDir.bat @@ -1,3 +1,4 @@ +rmdir Build /s/q mkdir Build copy "Server.exe" "Build/Server.exe" @@ -8,14 +9,13 @@ xcopy "src" "Build/src/" /s/i/y xcopy "user" "Build/user/" /s/i/y -del "Build/user/cache/" /s/q -del "Build/user/certs/" /s/q -del "Build/user/logs/" /s/q +rmdir "Build/user/cache/" /s/q +rmdir "Build/user/events/" /s/q +rmdir "Build/user/logs/" /s/q rmdir "Build/user/profiles/" /s/q -mkdir "Build/user/profiles/" /q rmdir "Build/user/mods" /s/q -del "Build/user/config/gameplay.json" /q -del "Build/user/config/server.json" /q +del "Build\user\configs\gameplay.json" /q +del "Build\user\configs\server.json" /q pause \ No newline at end of file diff --git a/src/Controllers/AccountController.js b/src/Controllers/AccountController.js index 55de444e..4b9f6d87 100644 --- a/src/Controllers/AccountController.js +++ b/src/Controllers/AccountController.js @@ -1,5 +1,6 @@ const fs = require('fs'); -const {AccountServer} = require('./../classes/account') +const {AccountServer} = require('./../classes/account'); +const utility = require('./../../core/util/utility'); /** * Account Controller. @@ -7,12 +8,22 @@ const {AccountServer} = require('./../classes/account') */ class AccountController { + + static Instance = new AccountController(); + constructor() { + if(!fs.existsSync(`user/profiles/`)) { + fs.mkdirSync(`user/profiles/`); + } + } /** * Gets ALL of the account data from every profile in the user/profiles directory * @returns all the Account data neccessary to process accounts in the server & client */ static getAllAccounts() { let fullyLoadedAccounts = []; + if(!fs.existsSync(`user/profiles/`)) { + fs.mkdirSync(`user/profiles/`); + } const profileFolders = fs.readdirSync(`user/profiles/`); // console.log(profileFolders); @@ -60,17 +71,24 @@ class AccountController static findAccountIdByUsernameAndPassword(username, password) { - const profileFolders = fs.readdirSync(`user/profiles/`); - for (const id of profileFolders) { - if (!fileIO.exist(`user/profiles/${id}/account.json`)) continue; - let account = JSON.parse(fs.readFileSync(`user/profiles/${id}/account.json`)); - if(account.email == username && account.password == password) - return id; - } - return undefined; + if(!fs.existsSync(`user/profiles/`)) { + fs.mkdirSync(`user/profiles/`); + } + + const profileFolders = fs.readdirSync(`user/profiles/`); + for (const id of profileFolders) { + if (!fileIO.exist(`user/profiles/${id}/account.json`)) continue; + let account = JSON.parse(fs.readFileSync(`user/profiles/${id}/account.json`)); + if(account.email == username && account.password == password) + return id; + } + return undefined; } static isEmailAlreadyInUse(username) { + if(!fs.existsSync(`user/profiles/`)) { + fs.mkdirSync(`user/profiles/`); + } const profileFolders = fs.readdirSync(`user/profiles/`); for (const id of profileFolders) { @@ -92,6 +110,10 @@ class AccountController } static register(info) { + if(!fs.existsSync(`user/profiles/`)) { + fs.mkdirSync(`user/profiles/`); + } + // Get existing account from memory or cache a new one. let accountID = AccountServer.reloadAccountByLogin(info) if (accountID !== undefined) { @@ -104,6 +126,9 @@ class AccountController if(accountID === undefined) { accountID = utility.generateNewAccountId(); + if(accountID === undefined || accountID === "") { + return "FAILED"; + } AccountServer.accounts[accountID] = { id: accountID, diff --git a/user/configs/server_base.json b/user/configs/server_base.json index 976d5f04..38f4af28 100644 --- a/user/configs/server_base.json +++ b/user/configs/server_base.json @@ -4,7 +4,7 @@ "port": 443, "eventPollIntervalSec": 60, "rebuildCache": true, - "name": "JustEmuTarkov", + "name": "JET Server (SIT Fork)", "discord": "", "website": "", "runSimpleHttpServer": false,