From cde3a909225a680f7f15a9dd8f2eff2e04e442e9 Mon Sep 17 00:00:00 2001 From: tgpethan Date: Fri, 12 Feb 2021 23:36:35 +0000 Subject: [PATCH] Codefactor refactor --- README.md | 2 ++ server/MultiplayerManager.js | 1 - server/MultiplayerMatch.js | 4 +++- server/Streams.js | 34 ++++++++++++++++++---------------- server/loginHandler.js | 2 +- server/loginHelper.js | 2 +- server/serverHandler.js | 9 ++++----- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index c280242..8156630 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Binato An implementation of osu!bancho in Javascript + +[![CodeFactor](https://www.codefactor.io/repository/github/tgpethan/binato/badge/master)](https://www.codefactor.io/repository/github/tgpethan/binato/overview/master)
### Features: diff --git a/server/MultiplayerManager.js b/server/MultiplayerManager.js index 1e2652d..7bb028c 100644 --- a/server/MultiplayerManager.js +++ b/server/MultiplayerManager.js @@ -1,5 +1,4 @@ const osu = require("osu-packet"), - getUserById = require("./util/getUserById.js"), UserPresenceBundle = require("./Packets/UserPresenceBundle.js"), UserPresence = require("./Packets/UserPresence.js"), StatusUpdate = require("./Packets/StatusUpdate.js"), diff --git a/server/MultiplayerMatch.js b/server/MultiplayerMatch.js index 77a4437..ec61f53 100644 --- a/server/MultiplayerMatch.js +++ b/server/MultiplayerMatch.js @@ -137,7 +137,9 @@ module.exports = class { MatchUser.addActionToQueue(osuPacketWriter.toBuffer); return this; - } catch (e) { } + } catch (e) { + console.error(e); + } } updateMatch(MatchData) { diff --git a/server/Streams.js b/server/Streams.js index 5aa203a..d0fb3a2 100644 --- a/server/Streams.js +++ b/server/Streams.js @@ -41,27 +41,29 @@ module.exports = class { } sendToStream(streamName, streamData, initUser = null) { + // Make sure the stream we are attempting to send to even exists + if (!this.doesStreamExist(streamName)) + return global.consoleHelper.printBancho(`Did not send to stream [${streamName}] because it does not exist!`); + // Get the stream to send the data to const currentStream = this.avaliableStreams[streamName]; - try { - // Loop through the users in this stream - for (let i = 0; i < currentStream.streamUsers.length; i++) { - // Get the user token of the user in the queue - const currentUserToken = currentStream.streamUsers[i]; - // Make sure we don't send this data back to the user requesting this data to be sent - if (initUser != null && currentUserToken == initUser && (streamName[0] == "#" || streamName.includes("mp_"))) continue; - if (currentUserToken == 3) continue; // Skip if user is bot + // Loop through the users in this stream + for (let i = 0; i < currentStream.streamUsers.length; i++) { + // Get the user token of the user in the queue + const currentUserToken = currentStream.streamUsers[i]; + // Make sure we don't send this data back to the user requesting this data to be sent + if (initUser != null && currentUserToken == initUser && (streamName[0] == "#" || streamName.includes("mp_"))) continue; + if (currentUserToken == 3) continue; // Skip if user is bot - // Get user object - const currentUser = getUserByToken(currentUserToken); - // Skip if user is nonexistant - if (currentUser == null) continue; + // Get user object + const currentUser = getUserByToken(currentUserToken); + // Skip if user is nonexistant + if (currentUser == null) continue; - // Send stream data to user's own queue - currentUser.addActionToQueue(streamData); - } - } catch (e) {} + // Send stream data to user's own queue + currentUser.addActionToQueue(streamData); + } } addUserToStream(streamName, userToken) { diff --git a/server/loginHandler.js b/server/loginHandler.js index 0e7189c..96d11ca 100644 --- a/server/loginHandler.js +++ b/server/loginHandler.js @@ -141,7 +141,7 @@ module.exports = function(req, res, loginInfo) { // Complete login res.writeHead(200, { "cho-token": NewUser.uuid, - "cho-protocol": 19, + "cho-protocol": global.protocolVersion, "Connection": "keep-alive", "Keep-Alive": "timeout=5, max=100", "Content-Type": "text/html; charset=UTF-8" diff --git a/server/loginHelper.js b/server/loginHelper.js index 32ff74b..263bf9b 100644 --- a/server/loginHelper.js +++ b/server/loginHelper.js @@ -27,7 +27,7 @@ function incorrectLoginResponse() { osuPacketWriter.toBuffer, { 'cho-token': 'No', - 'cho-protocol': 19, + 'cho-protocol': global.protocolVersion, 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=5, max=100', 'Content-Type': 'text/html; charset=UTF-8' diff --git a/server/serverHandler.js b/server/serverHandler.js index 9e6c039..59e3f70 100644 --- a/server/serverHandler.js +++ b/server/serverHandler.js @@ -84,7 +84,7 @@ setInterval(() => { fs.appendFile( "server-stats.log", `${global.usersOnline}|${global.multiplayerMatches[0]},${global.multiplayerMatches[1]}|${global.httpRequestsPerLogInterval}|${new Date().getTime()}@`, - () => { } + () => {} ); global.httpRequestsPerLogInterval = 0; @@ -94,7 +94,7 @@ if (!fs.existsSync("tHMM.ds")) fs.writeFileSync("tHMM.ds", "0"); global.totalHistoricalMultiplayerMatches = parseInt(fs.readFileSync("tHMM.ds").toString()); global.getAndAddToHistoricalMultiplayerMatches = function() { global.totalHistoricalMultiplayerMatches++; - fs.writeFile("tHMM.ds", global.totalHistoricalMultiplayerMatches, (e) => {}); + fs.writeFile("tHMM.ds", global.totalHistoricalMultiplayerMatches, () => {}); return global.totalHistoricalMultiplayerMatches; } @@ -129,8 +129,7 @@ module.exports = function(req, res) { requestData = req.packet; // Server's response & new client token - let responseTokenString = "", - responseData = new Buffer.alloc(0); + let responseData = new Buffer.alloc(0); // Check if the user is logged in if (requestTokenString == null) { @@ -341,7 +340,7 @@ module.exports = function(req, res) { } finally { // Send the prepared packet to the client res.writeHead(200, { - "cho-protocol": 19, + "cho-protocol": global.protocolVersion, "Connection": "keep-alive", "Keep-Alive": "timeout=5, max=100", "Content-Type": "text/html; charset=UTF-8"