From 36715a76824a5acd2251e89ca7f68014f1428707 Mon Sep 17 00:00:00 2001 From: tgpethan Date: Mon, 7 Sep 2020 17:35:37 +0100 Subject: [PATCH] Remove userManager and all usages of it --- Binato.js | 3 +- server/Packets/SendPublicMessage.js | 3 +- server/Packets/UserPresenceBundle.js | 3 +- server/loginHandler.js | 7 ++-- server/serverHandler.js | 4 +- server/userManager.js | 55 ---------------------------- server/util/getUserByToken.js | 10 +++++ 7 files changed, 19 insertions(+), 66 deletions(-) delete mode 100644 server/userManager.js create mode 100644 server/util/getUserByToken.js diff --git a/Binato.js b/Binato.js index ccdc13f..aadf178 100644 --- a/Binato.js +++ b/Binato.js @@ -9,8 +9,7 @@ const debugMode = true; global.consoleHelper = require("./consoleHelper.js"); -const serverHandler = require("./server/serverHandler.js"), - userManager = require("./server/userManager.js"); +const serverHandler = require("./server/serverHandler.js"); app.use(busboy()); diff --git a/server/Packets/SendPublicMessage.js b/server/Packets/SendPublicMessage.js index 4b0ebf2..73a344e 100644 --- a/server/Packets/SendPublicMessage.js +++ b/server/Packets/SendPublicMessage.js @@ -1,5 +1,4 @@ -const osu = require("osu-packet"), - userManager = require("../userManager.js"); +const osu = require("osu-packet"); module.exports = function(CurrentPacket, CurrentUser) { const osuPacketWriter = new osu.Bancho.Writer; diff --git a/server/Packets/UserPresenceBundle.js b/server/Packets/UserPresenceBundle.js index ef74fed..6782b47 100644 --- a/server/Packets/UserPresenceBundle.js +++ b/server/Packets/UserPresenceBundle.js @@ -1,5 +1,4 @@ -const osu = require("osu-packet"), - userManager = require("../userManager.js"); +const osu = require("osu-packet"); module.exports = function(currentUser) { const osuPacketWriter = new osu.Bancho.Writer; diff --git a/server/loginHandler.js b/server/loginHandler.js index 90af5fb..6d025a7 100644 --- a/server/loginHandler.js +++ b/server/loginHandler.js @@ -3,8 +3,9 @@ const osu = require("osu-packet"), { v4: uuid } = require('uuid'), request = require("sync-request"), - userManager = require("./userManager.js"), DatabaseHelper = require("./DatabaseHelper.js"), + getUserByUsername = require("./util/getUserByUsername.js"), + getUserByToken = require("./util/getUserByToken.js"), countryHelper = require("./countryHelper.js"), loginHelper = require("./loginHelper.js"); @@ -43,7 +44,7 @@ module.exports = function(req, res, loginInfo) { const newClientToken = uuid(); // Make sure user is not already connected, kick off if so. - const checkForPreexistingUser = userManager.getUserFromUsername(loginInfo.username); + const checkForPreexistingUser = getUserByUsername(loginInfo.username); if (checkForPreexistingUser != null) { if (checkForPreexistingUser.uuid != newClientToken) { let userCurrentIndex; @@ -63,7 +64,7 @@ module.exports = function(req, res, loginInfo) { global.users.push(new User(userDB.id, loginInfo.username, newClientToken, new Date().getTime())); // Retreive the newly created user - const userClass = userManager.getUserFromToken(newClientToken); + const userClass = getUserByToken(newClientToken); // Get user's data from the database userClass.getNewUserInformationFromDatabase(); diff --git a/server/serverHandler.js b/server/serverHandler.js index 5ddb611..423847d 100644 --- a/server/serverHandler.js +++ b/server/serverHandler.js @@ -3,8 +3,8 @@ const osu = require("osu-packet"), packetIDs = require("./packetIDs.json"), loginHandler = require("./loginHandler.js"), parseUserData = require("./util/parseUserData.js"), - userManager = require("./userManager.js"), User = require("./User.js"), + getUserFromToken = require("./util/getUserByToken.js"), bakedResponses = require("./bakedResponses.js"), Streams = require("./Streams.js"); @@ -116,7 +116,7 @@ module.exports = function(req, res) { // Client has a token, let's see what they want. try { // Get the current user - const userClass = userManager.getUserFromToken(requestTokenString); + const userClass = getUserFromToken(requestTokenString); // Make sure the client's token isn't invalid if (userClass != null) { diff --git a/server/userManager.js b/server/userManager.js deleted file mode 100644 index 20e33f0..0000000 --- a/server/userManager.js +++ /dev/null @@ -1,55 +0,0 @@ -module.exports = { - getUserFromID:function(id) { - let userToReturn; - for (let i = 0; i < global.users.length; i++) { - if (global.users[i].id == id) { - userToReturn = global.users[i]; - i = global.users.length; - } else { - continue; - } - } - return userToReturn; - }, - - getUserFromUsername:function(username) { - let userToReturn; - for (let i = 0; i < global.users.length; i++) { - if (global.users[i].username == username) { - userToReturn = global.users[i]; - break; - } else { - continue; - } - } - return userToReturn; - }, - - getUserFromToken:function(token) { - let userToReturn; - for (let i = 0; i < global.users.length; i++) { - if (global.users[i].uuid == token) { - userToReturn = global.users[i]; - i = global.users.length; - } else { - continue; - } - } - return userToReturn; - }, - - queueActionForAll:function(action) { - for (let i = 0; i < global.users.length; i++) { - global.users[i].addActionToQueue(action); - } - }, - - queueActionForAllWithoutCallingUser:function(action, token) { - for (let i = 0; i < global.users.length; i++) { - if (global.users[i].uuid == token) { - continue; - } - global.users[i].addActionToQueue(action); - } - } -} \ No newline at end of file diff --git a/server/util/getUserByToken.js b/server/util/getUserByToken.js new file mode 100644 index 0000000..e3348ec --- /dev/null +++ b/server/util/getUserByToken.js @@ -0,0 +1,10 @@ +module.exports = function(token) { + let user = null; + for (let i = 0; i < global.users.length; i++) { + if (global.users[i].uuid == token) { + user = global.users[i]; + break; + } + } + return user; +} \ No newline at end of file