Codefactor refactor

This commit is contained in:
tgpethan 2021-02-12 23:36:35 +00:00
parent 69de312cf0
commit cde3a90922
7 changed files with 29 additions and 25 deletions

View file

@ -1,5 +1,7 @@
# Binato # Binato
An implementation of osu!bancho in Javascript 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)
<hr> <hr>
### Features: ### Features:

View file

@ -1,5 +1,4 @@
const osu = require("osu-packet"), const osu = require("osu-packet"),
getUserById = require("./util/getUserById.js"),
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"), UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"), UserPresence = require("./Packets/UserPresence.js"),
StatusUpdate = require("./Packets/StatusUpdate.js"), StatusUpdate = require("./Packets/StatusUpdate.js"),

View file

@ -137,7 +137,9 @@ module.exports = class {
MatchUser.addActionToQueue(osuPacketWriter.toBuffer); MatchUser.addActionToQueue(osuPacketWriter.toBuffer);
return this; return this;
} catch (e) { } } catch (e) {
console.error(e);
}
} }
updateMatch(MatchData) { updateMatch(MatchData) {

View file

@ -41,27 +41,29 @@ module.exports = class {
} }
sendToStream(streamName, streamData, initUser = null) { 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 // Get the stream to send the data to
const currentStream = this.avaliableStreams[streamName]; const currentStream = this.avaliableStreams[streamName];
try { // Loop through the users in this stream
// Loop through the users in this stream for (let i = 0; i < currentStream.streamUsers.length; i++) {
for (let i = 0; i < currentStream.streamUsers.length; i++) { // Get the user token of the user in the queue
// Get the user token of the user in the queue const currentUserToken = currentStream.streamUsers[i];
const currentUserToken = currentStream.streamUsers[i]; // Make sure we don't send this data back to the user requesting this data to be sent
// 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 (initUser != null && currentUserToken == initUser && (streamName[0] == "#" || streamName.includes("mp_"))) continue; if (currentUserToken == 3) continue; // Skip if user is bot
if (currentUserToken == 3) continue; // Skip if user is bot
// Get user object // Get user object
const currentUser = getUserByToken(currentUserToken); const currentUser = getUserByToken(currentUserToken);
// Skip if user is nonexistant // Skip if user is nonexistant
if (currentUser == null) continue; if (currentUser == null) continue;
// Send stream data to user's own queue // Send stream data to user's own queue
currentUser.addActionToQueue(streamData); currentUser.addActionToQueue(streamData);
} }
} catch (e) {}
} }
addUserToStream(streamName, userToken) { addUserToStream(streamName, userToken) {

View file

@ -141,7 +141,7 @@ module.exports = function(req, res, loginInfo) {
// Complete login // Complete login
res.writeHead(200, { res.writeHead(200, {
"cho-token": NewUser.uuid, "cho-token": NewUser.uuid,
"cho-protocol": 19, "cho-protocol": global.protocolVersion,
"Connection": "keep-alive", "Connection": "keep-alive",
"Keep-Alive": "timeout=5, max=100", "Keep-Alive": "timeout=5, max=100",
"Content-Type": "text/html; charset=UTF-8" "Content-Type": "text/html; charset=UTF-8"

View file

@ -27,7 +27,7 @@ function incorrectLoginResponse() {
osuPacketWriter.toBuffer, osuPacketWriter.toBuffer,
{ {
'cho-token': 'No', 'cho-token': 'No',
'cho-protocol': 19, 'cho-protocol': global.protocolVersion,
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Keep-Alive': 'timeout=5, max=100', 'Keep-Alive': 'timeout=5, max=100',
'Content-Type': 'text/html; charset=UTF-8' 'Content-Type': 'text/html; charset=UTF-8'

View file

@ -84,7 +84,7 @@ setInterval(() => {
fs.appendFile( fs.appendFile(
"server-stats.log", "server-stats.log",
`${global.usersOnline}|${global.multiplayerMatches[0]},${global.multiplayerMatches[1]}|${global.httpRequestsPerLogInterval}|${new Date().getTime()}@`, `${global.usersOnline}|${global.multiplayerMatches[0]},${global.multiplayerMatches[1]}|${global.httpRequestsPerLogInterval}|${new Date().getTime()}@`,
() => { } () => {}
); );
global.httpRequestsPerLogInterval = 0; 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.totalHistoricalMultiplayerMatches = parseInt(fs.readFileSync("tHMM.ds").toString());
global.getAndAddToHistoricalMultiplayerMatches = function() { global.getAndAddToHistoricalMultiplayerMatches = function() {
global.totalHistoricalMultiplayerMatches++; global.totalHistoricalMultiplayerMatches++;
fs.writeFile("tHMM.ds", global.totalHistoricalMultiplayerMatches, (e) => {}); fs.writeFile("tHMM.ds", global.totalHistoricalMultiplayerMatches, () => {});
return global.totalHistoricalMultiplayerMatches; return global.totalHistoricalMultiplayerMatches;
} }
@ -129,8 +129,7 @@ module.exports = function(req, res) {
requestData = req.packet; requestData = req.packet;
// Server's response & new client token // Server's response & new client token
let responseTokenString = "", let responseData = new Buffer.alloc(0);
responseData = new Buffer.alloc(0);
// Check if the user is logged in // Check if the user is logged in
if (requestTokenString == null) { if (requestTokenString == null) {
@ -341,7 +340,7 @@ module.exports = function(req, res) {
} finally { } finally {
// Send the prepared packet to the client // Send the prepared packet to the client
res.writeHead(200, { res.writeHead(200, {
"cho-protocol": 19, "cho-protocol": global.protocolVersion,
"Connection": "keep-alive", "Connection": "keep-alive",
"Keep-Alive": "timeout=5, max=100", "Keep-Alive": "timeout=5, max=100",
"Content-Type": "text/html; charset=UTF-8" "Content-Type": "text/html; charset=UTF-8"