Make everything tabs instead of spaces & don't rely on a global consoleHelper

This commit is contained in:
Holly Stubbs 2022-01-04 03:39:53 +00:00
parent 26806438b7
commit e65fc13419
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
38 changed files with 2432 additions and 2422 deletions

133
Binato.js
View file

@ -1,86 +1,87 @@
console.clear();
// Globals
global.consoleHelper = require("./consoleHelper.js");
global.protocolVersion = 19;
const app = require("express")(),
prometheusApp = require("express")(),
compression = require("compression"),
fs = require("fs"),
prom = require("prom-client"),
serverHandler = require("./server/serverHandler.js"),
config = require("./config.json");
consoleHelper = require("./consoleHelper.js"),
prometheusApp = require("express")(),
fs = require("fs"),
serverHandler = require("./server/serverHandler.js"),
config = require("./config.json");
const debugMode = true;
if (config.prometheusEnabled) {
const register = new prom.Registry();
// We only need to require this if prom metrics are on.
const prom = require("prom-client");
register.setDefaultLabels({ app: "nodejs_binato" });
prom.collectDefaultMetrics({ register });
prometheusApp.get("*", async (req, res) => {
if (req.url.split("?")[0] != "/metrics") return res.status(404).end("");
res.end(await register.metrics());
});
prometheusApp.listen(config.prometheusPort, () => global.consoleHelper.printBancho(`Prometheus metrics listening at port ${config.prometheusPort}`));
} else global.consoleHelper.printWarn("Prometheus is disabled!");
const register = new prom.Registry();
register.setDefaultLabels({ app: "nodejs_binato" });
prom.collectDefaultMetrics({ register });
prometheusApp.get("*", async (req, res) => {
if (req.url.split("?")[0] != "/metrics") return res.status(404).end("");
res.end(await register.metrics());
});
prometheusApp.listen(config.prometheusPort, () => consoleHelper.printBancho(`Prometheus metrics listening at port ${config.prometheusPort}`));
} else consoleHelper.printWarn("Prometheus is disabled!");
if (config.compression) {
app.use(compression());
global.consoleHelper.printBancho("Gzip Compression is enabled.");
} else global.consoleHelper.printWarn("Gzip Compression is disabled!");
app.use(require("compression")());
consoleHelper.printBancho("Gzip Compression is enabled.");
} else consoleHelper.printWarn("Gzip Compression is disabled!");
app.use((req, res) => {
req.packet = new Buffer.alloc(0);
req.on("data", (chunk) => req.packet = Buffer.concat([req.packet, chunk], req.packet.length + chunk.length));
req.on("end", () => {
switch (req.method) {
case "GET":
if (req.url == "/" || req.url == "/index.html" || req.url == "/index.html") {
fs.readFile("./web/serverPage.html", (err, data) => {
if (err) throw err;
if (debugMode) data = data.toString().replace("|isdebug?|", '<b style="color:red;">DEBUG</b>');
else data = data.toString().replace("|isdebug?|", '');
res.send(data);
});
} else if (req.url == "/chat") {
fs.readFile("./web/chatPageTemplate.html", (err, data) => {
if (err) throw err;
req.packet = new Buffer.alloc(0);
req.on("data", (chunk) => req.packet = Buffer.concat([req.packet, chunk], req.packet.length + chunk.length));
req.on("end", () => {
switch (req.method) {
case "GET":
if (req.url == "/" || req.url == "/index.html" || req.url == "/index.html") {
fs.readFile("./web/serverPage.html", (err, data) => {
if (err) throw err;
if (debugMode) data = data.toString().replace("|isdebug?|", '<b style="color:red;">DEBUG</b>');
else data = data.toString().replace("|isdebug?|", '');
res.send(data);
});
} else if (req.url == "/chat") {
fs.readFile("./web/chatPageTemplate.html", (err, data) => {
if (err) throw err;
let lines = "", flip = false;
const limit = global.chatHistory.length < 10 ? 10 : global.chatHistory.length;
for (let i = global.chatHistory.length - 10; i < limit; i++) {
if (i < 0) i = 0;
lines += `<div class="line line${flip ? 1 : 0}">${global.chatHistory[i] == null ? "<hidden>blank</hidden>" : global.chatHistory[i]}</div>`
flip = !flip;
}
res.send(data.toString().replace("|content|", lines));
});
}
break;
let lines = "", flip = false;
const limit = global.chatHistory.length < 10 ? 10 : global.chatHistory.length;
for (let i = global.chatHistory.length - 10; i < limit; i++) {
if (i < 0) i = 0;
lines += `<div class="line line${flip ? 1 : 0}">${global.chatHistory[i] == null ? "<hidden>blank</hidden>" : global.chatHistory[i]}</div>`
flip = !flip;
}
res.send(data.toString().replace("|content|", lines));
});
}
break;
case "POST":
// Make sure this address should respond to bancho requests
// Bancho addresses: c, c1, c2, c3, c4, c5, c6, ce
// Just looking for the first character being "c" *should* be enough
if (req.headers["host"].split(".")[0][0] == "c")
serverHandler(req, res);
else
res.status(400).send("400 | Bad Request!<br>Binato only accepts post requests on bancho subdomains.<hr>Binato");
break;
case "POST":
// Make sure this address should respond to bancho requests
// Bancho addresses: c, c1, c2, c3, c4, c5, c6, ce
// Just looking for the first character being "c" *should* be enough
if (req.headers["host"].split(".")[0][0] == "c")
serverHandler(req, res);
else
res.status(400).send("400 | Bad Request!<br>Binato only accepts post requests on bancho subdomains.<hr>Binato");
break;
default:
res.status(405).send("405 | Method not allowed!<hr>Binato");
break;
}
});
default:
res.status(405).send("405 | Method not allowed!<hr>Binato");
break;
}
});
});
app.listen(config.port, () => global.consoleHelper.printBancho(`Binato is up! Listening at port ${config.port}`));
app.listen(config.port, () => consoleHelper.printBancho(`Binato is up! Listening at port ${config.port}`));

View file

@ -1,33 +1,33 @@
const chalk = require("chalk");
module.exports = {
printWebReq:function(s) {
console.log(`${this.getTime()} ${chalk.bgGreen(chalk.black(" WEBREQ "))} ${s}`);
},
printBancho:function(s) {
console.log(`${this.getTime()} ${chalk.bgMagenta(chalk.black(" BANCHO "))} ${s}`);
},
printWebReq:function(s) {
console.log(`${this.getTime()} ${chalk.bgGreen(chalk.black(" WEBREQ "))} ${s}`);
},
printBancho:function(s) {
console.log(`${this.getTime()} ${chalk.bgMagenta(chalk.black(" BANCHO "))} ${s}`);
},
printChat:function(s) {
console.log(`${this.getTime()} ${chalk.bgCyan(chalk.black(" CHATTO "))} ${s}`);
},
printChat:function(s) {
console.log(`${this.getTime()} ${chalk.bgCyan(chalk.black(" CHATTO "))} ${s}`);
},
printWarn:function(s) {
console.warn(`${this.getTime()} ${chalk.bgYellow(chalk.black(" WARNIN "))} ${chalk.yellow(s)}`);
},
printError:function(s) {
console.error(`${this.getTime()} ${chalk.bgRed((" ERROR! "))} ${chalk.red(s)}`);
},
printWarn:function(s) {
console.warn(`${this.getTime()} ${chalk.bgYellow(chalk.black(" WARNIN "))} ${chalk.yellow(s)}`);
},
printError:function(s) {
console.error(`${this.getTime()} ${chalk.bgRed((" ERROR! "))} ${chalk.red(s)}`);
},
getTime:function() {
const time = new Date();
return chalk.green(`[${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}]`);
}
getTime:function() {
const time = new Date();
return chalk.green(`[${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}]`);
}
}
function correctValue(i) {
if (i <= 9) return "0"+i;
else return i;
if (i <= 9) return "0"+i;
else return i;
}

View file

@ -1,211 +1,211 @@
const osu = require("osu-packet"),
maths = require("./util/Maths.js"),
OsuBattleRoyale = require("./MultiplayerExtras/OsuBattleRoyale.js");
maths = require("./util/Maths.js"),
OsuBattleRoyale = require("./MultiplayerExtras/OsuBattleRoyale.js");
module.exports = function(User, Message, Stream, IsCalledFromMultiplayer = false) {
if (Message[0] != "!") return;
const command = Message.split(" ")[0];
const args = Message.split(" ");
if (Message[0] != "!") return;
const command = Message.split(" ")[0];
const args = Message.split(" ");
let responseMessage = "";
let responseMessage = "";
let commandBanchoPacketWriter = null;
let commandBanchoPacketWriter = null;
switch (command) {
case "!help":
// This is terrible
if (args.length == 1) {
responseMessage = "Commands with an * next to them have a sub help section" +
"\n!help - Shows this message" +
"\n!roll - Rolls a random number or a number between 0 and a given number" +
"\n!ranking* - Sets your perfered ranking type" +
"\n!mp* - Shows information about all multiplayer commands" +
"\n!admin* - Shows information about all admin commands";
} else {
switch (args[1]) {
case "ranking":
responseMessage = "Ranking Commands:" +
"\n!ranking pp - Sets your ranking type to pp" +
"\n!ranking score - Sets your ranking type to score" +
"\n!ranking acc - Sets your ranking type to accuracy";
break;
switch (command) {
case "!help":
// This is terrible
if (args.length == 1) {
responseMessage = "Commands with an * next to them have a sub help section" +
"\n!help - Shows this message" +
"\n!roll - Rolls a random number or a number between 0 and a given number" +
"\n!ranking* - Sets your perfered ranking type" +
"\n!mp* - Shows information about all multiplayer commands" +
"\n!admin* - Shows information about all admin commands";
} else {
switch (args[1]) {
case "ranking":
responseMessage = "Ranking Commands:" +
"\n!ranking pp - Sets your ranking type to pp" +
"\n!ranking score - Sets your ranking type to score" +
"\n!ranking acc - Sets your ranking type to accuracy";
break;
case "mp":
responseMessage = "Multiplayer Commands:" +
"\n!mp start - Starts a multiplayer match with a delay" +
"\n!mp abort - Aborts the currently running multiplayer match" +
"\n!mp obr - Enables Battle Royale mode";
break;
case "mp":
responseMessage = "Multiplayer Commands:" +
"\n!mp start - Starts a multiplayer match with a delay" +
"\n!mp abort - Aborts the currently running multiplayer match" +
"\n!mp obr - Enables Battle Royale mode";
break;
case "admin":
responseMessage = "Admin Commands:" +
"\n!lock - Locks/Unlocks a channel and limits conversation to mods and above only";
break;
case "admin":
responseMessage = "Admin Commands:" +
"\n!lock - Locks/Unlocks a channel and limits conversation to mods and above only";
break;
default:
break;
}
}
break;
default:
break;
}
}
break;
case "!ranking":
if (args.length == 1) {
responseMessage = "You need to select a ranking mode! use \"!help ranking\" to see the options.";
} else {
switch (args[1]) {
case "pp":
responseMessage = "Set ranking mode to pp";
User.rankingMode = 0;
User.getNewUserInformationFromDatabase();
break;
case "!ranking":
if (args.length == 1) {
responseMessage = "You need to select a ranking mode! use \"!help ranking\" to see the options.";
} else {
switch (args[1]) {
case "pp":
responseMessage = "Set ranking mode to pp";
User.rankingMode = 0;
User.getNewUserInformationFromDatabase();
break;
case "score":
responseMessage = "Set ranking mode to score";
User.rankingMode = 1;
User.getNewUserInformationFromDatabase();
break;
case "score":
responseMessage = "Set ranking mode to score";
User.rankingMode = 1;
User.getNewUserInformationFromDatabase();
break;
case "acc":
responseMessage = "Set ranking mode to accuracy";
User.rankingMode = 2;
User.getNewUserInformationFromDatabase();
break;
}
}
break;
case "acc":
responseMessage = "Set ranking mode to accuracy";
User.rankingMode = 2;
User.getNewUserInformationFromDatabase();
break;
}
}
break;
case "!roll":
if (args.length == 1) {
responseMessage = User.username + " rolled " + maths.randInt(0, 65535);
} else {
if (`${parseInt(args[1])}` == "NaN") responseMessage = User.username + " rolled " + maths.randInt(0, 65535);
else responseMessage = User.username + " rolled " + maths.randInt(0, parseInt(args[1]));
}
break;
case "!roll":
if (args.length == 1) {
responseMessage = User.username + " rolled " + maths.randInt(0, 65535);
} else {
if (`${parseInt(args[1])}` == "NaN") responseMessage = User.username + " rolled " + maths.randInt(0, 65535);
else responseMessage = User.username + " rolled " + maths.randInt(0, parseInt(args[1]));
}
break;
case "!lock":
if (!Stream.includes("#")) responseMessage = "Multiplayer channels and private channels cannot be locked!";
else {
for (let i = 0; i < global.channels.length; i++) {
// Find the channel that pertains to this stream
if (global.channels[i].channelName == Stream) {
if (global.channels[i].locked) {
global.channels[i].locked = false;
responseMessage = "Channel is now unlocked.";
} else {
global.channels[i].locked = true;
responseMessage = "Channel is now locked, chat restricted to mods and above.";
}
break;
}
}
}
break;
case "!lock":
if (!Stream.includes("#")) responseMessage = "Multiplayer channels and private channels cannot be locked!";
else {
for (let i = 0; i < global.channels.length; i++) {
// Find the channel that pertains to this stream
if (global.channels[i].channelName == Stream) {
if (global.channels[i].locked) {
global.channels[i].locked = false;
responseMessage = "Channel is now unlocked.";
} else {
global.channels[i].locked = true;
responseMessage = "Channel is now locked, chat restricted to mods and above.";
}
break;
}
}
}
break;
case "!mp":
if (!IsCalledFromMultiplayer) return;
if (User.currentMatch.matchStartCountdownActive) return;
if (args.length == 1) return;
switch (args[1]) {
case "start":
if (args.length > 3) return;
if (`${parseInt(args[2])}` != "NaN") {
User.currentMatch.matchStartCountdownActive = true;
let countdown = parseInt(args[2]);
let intervalRef = setInterval(() => {
let local_osuPacketWriter = new osu.Bancho.Writer;
if (countdown != 0 && countdown > 0) countdown--;
if (countdown <= 10 && countdown > 0) {
local_osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "Starting in " + countdown,
target: "#multiplayer",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, local_osuPacketWriter.toBuffer, null);
} else if (countdown == 0) {
local_osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "Good luck, have fun!",
target: "#multiplayer",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, local_osuPacketWriter.toBuffer, null);
User.currentMatch.matchStartCountdownActive = false;
setTimeout(() => User.currentMatch.startMatch(), 1000);
clearInterval(intervalRef);
}
}, 1000);
} else {
responseMessage = "Good luck, have fun!";
setTimeout(() => User.currentMatch.startMatch(), 1000);
}
break;
case "!mp":
if (!IsCalledFromMultiplayer) return;
if (User.currentMatch.matchStartCountdownActive) return;
if (args.length == 1) return;
switch (args[1]) {
case "start":
if (args.length > 3) return;
if (`${parseInt(args[2])}` != "NaN") {
User.currentMatch.matchStartCountdownActive = true;
let countdown = parseInt(args[2]);
let intervalRef = setInterval(() => {
let local_osuPacketWriter = new osu.Bancho.Writer;
if (countdown != 0 && countdown > 0) countdown--;
if (countdown <= 10 && countdown > 0) {
local_osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "Starting in " + countdown,
target: "#multiplayer",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, local_osuPacketWriter.toBuffer, null);
} else if (countdown == 0) {
local_osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "Good luck, have fun!",
target: "#multiplayer",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, local_osuPacketWriter.toBuffer, null);
User.currentMatch.matchStartCountdownActive = false;
setTimeout(() => User.currentMatch.startMatch(), 1000);
clearInterval(intervalRef);
}
}, 1000);
} else {
responseMessage = "Good luck, have fun!";
setTimeout(() => User.currentMatch.startMatch(), 1000);
}
break;
case "abort":
//if (args.length > 2) return;
User.currentMatch.finishMatch();
break;
case "abort":
//if (args.length > 2) return;
User.currentMatch.finishMatch();
break;
case "obr":
if (User.currentMatch.multiplayerExtras != null) {
if (User.currentMatch.multiplayerExtras.name == "osu! Battle Royale") {
commandBanchoPacketWriter = new osu.Bancho.Writer;
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "osu! Battle Royale has been disabled!",
target: "#multiplayer",
senderId: global.users["bot"].id
});
User.currentMatch.multiplayerExtras = null;
global.StreamsHandler.sendToStream(Stream, commandBanchoPacketWriter.toBuffer, null);
}
else enableOBR(User, Stream, commandBanchoPacketWriter);
}
else enableOBR(User, Stream, commandBanchoPacketWriter);
break;
case "obr":
if (User.currentMatch.multiplayerExtras != null) {
if (User.currentMatch.multiplayerExtras.name == "osu! Battle Royale") {
commandBanchoPacketWriter = new osu.Bancho.Writer;
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "osu! Battle Royale has been disabled!",
target: "#multiplayer",
senderId: global.users["bot"].id
});
User.currentMatch.multiplayerExtras = null;
global.StreamsHandler.sendToStream(Stream, commandBanchoPacketWriter.toBuffer, null);
}
else enableOBR(User, Stream, commandBanchoPacketWriter);
}
else enableOBR(User, Stream, commandBanchoPacketWriter);
break;
default:
break;
}
break;
}
default:
break;
}
break;
}
const osuPacketWriter = new osu.Bancho.Writer;
if (responseMessage != "") {
if (Stream.includes("#")) {
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: responseMessage,
target: Stream,
senderId: global.users["bot"].id
});
} else {
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: responseMessage,
target: "#multiplayer",
senderId: global.users["bot"].id
});
}
}
global.StreamsHandler.sendToStream(Stream, osuPacketWriter.toBuffer, null);
const osuPacketWriter = new osu.Bancho.Writer;
if (responseMessage != "") {
if (Stream.includes("#")) {
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: responseMessage,
target: Stream,
senderId: global.users["bot"].id
});
} else {
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: responseMessage,
target: "#multiplayer",
senderId: global.users["bot"].id
});
}
}
global.StreamsHandler.sendToStream(Stream, osuPacketWriter.toBuffer, null);
}
function enableOBR(User, Stream, commandBanchoPacketWriter) {
User.currentMatch.multiplayerExtras = new OsuBattleRoyale(User.currentMatch);
commandBanchoPacketWriter = new osu.Bancho.Writer;
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "osu! Battle Royale has been enabled!",
target: "#multiplayer",
senderId: global.users["bot"].id
});
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "New Multiplayer Rules Added:\n - Players that are in a failed state by the end of the map get eliminated\n - The player(s) with the lowest score get eliminated",
target: "#multiplayer",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, commandBanchoPacketWriter.toBuffer, null);
User.currentMatch.multiplayerExtras = new OsuBattleRoyale(User.currentMatch);
commandBanchoPacketWriter = new osu.Bancho.Writer;
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "osu! Battle Royale has been enabled!",
target: "#multiplayer",
senderId: global.users["bot"].id
});
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "New Multiplayer Rules Added:\n - Players that are in a failed state by the end of the map get eliminated\n - The player(s) with the lowest score get eliminated",
target: "#multiplayer",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, commandBanchoPacketWriter.toBuffer, null);
}

View file

@ -1,36 +1,36 @@
const mysql = require("mysql");
module.exports = class {
constructor(databaseAddress, databasePort = 3306, databaseUsername, databasePassword, databaseName) {
this.connectionPool = mysql.createPool({
connectionLimit: 128,
host: databaseAddress,
port: databasePort,
user: databaseUsername,
password: databasePassword,
database: databaseName
});
}
constructor(databaseAddress, databasePort = 3306, databaseUsername, databasePassword, databaseName) {
this.connectionPool = mysql.createPool({
connectionLimit: 128,
host: databaseAddress,
port: databasePort,
user: databaseUsername,
password: databasePassword,
database: databaseName
});
}
async query(sqlQuery) {
return new Promise((resolve, reject) => {
this.connectionPool.getConnection((err, connection) => {
if (err) {
reject(err);
connection.release();
} else {
connection.query(sqlQuery, (err, data) => {
if (err) {
reject(err);
connection.release();
} else {
if (sqlQuery.includes("LIMIT 1")) resolve(data[0]);
else resolve(data);
connection.release();
}
});
}
});
});
}
async query(sqlQuery) {
return new Promise((resolve, reject) => {
this.connectionPool.getConnection((err, connection) => {
if (err) {
reject(err);
connection.release();
} else {
connection.query(sqlQuery, (err, data) => {
if (err) {
reject(err);
connection.release();
} else {
if (sqlQuery.includes("LIMIT 1")) resolve(data[0]);
else resolve(data);
connection.release();
}
});
}
});
});
}
}

View file

@ -1,130 +1,130 @@
const osu = require("osu-packet"),
MultiplayerMatch = require("../MultiplayerMatch.js"),
getUserById = require("../util/getUserById.js");
MultiplayerMatch = require("../MultiplayerMatch.js"),
getUserById = require("../util/getUserById.js");
module.exports = class {
constructor(MultiplayerMatchClass = new MultiplayerMatch()) {
this.name = "osu! Battle Royale";
this.MultiplayerMatch = MultiplayerMatchClass;
}
constructor(MultiplayerMatchClass = new MultiplayerMatch()) {
this.name = "osu! Battle Royale";
this.MultiplayerMatch = MultiplayerMatchClass;
}
onMatchFinished(playerScores = [{playerId:0,slotId:0,score:0,isCurrentlyFailed:false}]) {
let lowestScore = 9999999999999999;
for (let i = 0; i < playerScores.length; i++) {
const playerScore = playerScores[i];
if (playerScore.score < lowestScore) lowestScore = playerScore.score;
}
onMatchFinished(playerScores = [{playerId:0,slotId:0,score:0,isCurrentlyFailed:false}]) {
let lowestScore = 9999999999999999;
for (let i = 0; i < playerScores.length; i++) {
const playerScore = playerScores[i];
if (playerScore.score < lowestScore) lowestScore = playerScore.score;
}
let everyoneHasTheSameScore = true;
for (let i = 0; i < playerScores.length; i++) {
if (playerScores[i].score != lowestScore) {
everyoneHasTheSameScore = false;
break;
}
}
let everyoneHasTheSameScore = true;
for (let i = 0; i < playerScores.length; i++) {
if (playerScores[i].score != lowestScore) {
everyoneHasTheSameScore = false;
break;
}
}
// Everyone has the same score, we don't need to kick anyone
if (everyoneHasTheSameScore) return;
// Everyone has the same score, we don't need to kick anyone
if (everyoneHasTheSameScore) return;
// Kick everyone with the lowest score
for (let i = 0; i < playerScores.length; i++) {
// Kick players if they have the lowest score or they are in a failed state
if (playerScores[i].score == lowestScore || playerScores[i].isCurrentlyFailed) {
let osuPacketWriter = new osu.Bancho.Writer;
// Get the slot this player is in
const slot = this.MultiplayerMatch.slots[playerScores[i].slotId];
// Get the kicked player's user class
const kickedPlayer = getUserById(slot.playerId);
// Remove the kicked player's referance to the slot they were in
kickedPlayer.matchSlotId = -1;
// Lock the slot the kicked player was in
slot.playerId = -1;
slot.status = 2;
// Remove the kicked player from the match's stream
global.StreamsHandler.removeUserFromStream(this.MultiplayerMatch.matchStreamName, kickedPlayer.uuid);
global.StreamsHandler.removeUserFromStream(this.MultiplayerMatch.matchChatStreamName, kickedPlayer.uuid);
// Remove the kicked player's referance this this match
kickedPlayer.currentMatch = null;
// Kick everyone with the lowest score
for (let i = 0; i < playerScores.length; i++) {
// Kick players if they have the lowest score or they are in a failed state
if (playerScores[i].score == lowestScore || playerScores[i].isCurrentlyFailed) {
let osuPacketWriter = new osu.Bancho.Writer;
// Get the slot this player is in
const slot = this.MultiplayerMatch.slots[playerScores[i].slotId];
// Get the kicked player's user class
const kickedPlayer = getUserById(slot.playerId);
// Remove the kicked player's referance to the slot they were in
kickedPlayer.matchSlotId = -1;
// Lock the slot the kicked player was in
slot.playerId = -1;
slot.status = 2;
// Remove the kicked player from the match's stream
global.StreamsHandler.removeUserFromStream(this.MultiplayerMatch.matchStreamName, kickedPlayer.uuid);
global.StreamsHandler.removeUserFromStream(this.MultiplayerMatch.matchChatStreamName, kickedPlayer.uuid);
// Remove the kicked player's referance this this match
kickedPlayer.currentMatch = null;
// Inform the kicked user's client that they were kicked
osuPacketWriter.MatchUpdate(this.MultiplayerMatch.createOsuMatchJSON());
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "You were eliminated from the match!",
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
// Inform the kicked user's client that they were kicked
osuPacketWriter.MatchUpdate(this.MultiplayerMatch.createOsuMatchJSON());
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "You were eliminated from the match!",
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
kickedPlayer.addActionToQueue(osuPacketWriter.toBuffer);
kickedPlayer.addActionToQueue(osuPacketWriter.toBuffer);
osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: `${kickedPlayer.username} was eliminated from the match!`,
target: "#multiplayer",
senderId: global.users["bot"].id
});
osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: `${kickedPlayer.username} was eliminated from the match!`,
target: "#multiplayer",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(this.MultiplayerMatch.matchChatStreamName, osuPacketWriter.toBuffer, null);
}
}
global.StreamsHandler.sendToStream(this.MultiplayerMatch.matchChatStreamName, osuPacketWriter.toBuffer, null);
}
}
let numberOfPlayersRemaining = 0;
for (let i = 0; i < playerScores.length; i++) {
const slot = this.MultiplayerMatch.slots[playerScores[i].slotId];
let numberOfPlayersRemaining = 0;
for (let i = 0; i < playerScores.length; i++) {
const slot = this.MultiplayerMatch.slots[playerScores[i].slotId];
if (slot.playerId !== -1 && slot.status !== 2) {
numberOfPlayersRemaining++;
}
}
if (slot.playerId !== -1 && slot.status !== 2) {
numberOfPlayersRemaining++;
}
}
let playerClassContainer = null;
let remainingWriterContainer = null;
let i = 0;
let playerClassContainer = null;
let remainingWriterContainer = null;
let i = 0;
if (numberOfPlayersRemaining == 1) {
for (let i1 = 0; i1 < playerScores.length; i++) {
const slot = this.MultiplayerMatch.slots[playerScores[i].slotId];
if (slot.playerId !== -1 && slot.status !== 2) {
playerClassContainer = getUserById(slot.playerId);
break;
}
}
}
if (numberOfPlayersRemaining == 1) {
for (let i1 = 0; i1 < playerScores.length; i++) {
const slot = this.MultiplayerMatch.slots[playerScores[i].slotId];
if (slot.playerId !== -1 && slot.status !== 2) {
playerClassContainer = getUserById(slot.playerId);
break;
}
}
}
switch (numberOfPlayersRemaining) {
case 0:
remainingWriterContainer = new osu.Bancho.Writer;
remainingWriterContainer.SendMessage({
sendingClient: global.users["bot"].username,
message: "Everyone was eliminated from the match! Nobody wins.",
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
for (i = 0; i < playerScores.length; i++) {
playerClassContainer = getUserById(playerScores[i].playerId);
playerClassContainer.addActionToQueue(remainingWriterContainer.toBuffer);
}
break;
switch (numberOfPlayersRemaining) {
case 0:
remainingWriterContainer = new osu.Bancho.Writer;
remainingWriterContainer.SendMessage({
sendingClient: global.users["bot"].username,
message: "Everyone was eliminated from the match! Nobody wins.",
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
for (i = 0; i < playerScores.length; i++) {
playerClassContainer = getUserById(playerScores[i].playerId);
playerClassContainer.addActionToQueue(remainingWriterContainer.toBuffer);
}
break;
case 1:
remainingWriterContainer = new osu.Bancho.Writer;
remainingWriterContainer.SendMessage({
sendingClient: global.users["bot"].username,
message: "You are the last one remaining, you win!",
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
playerClassContainer.addActionToQueue(remainingWriterContainer.toBuffer);
break;
case 1:
remainingWriterContainer = new osu.Bancho.Writer;
remainingWriterContainer.SendMessage({
sendingClient: global.users["bot"].username,
message: "You are the last one remaining, you win!",
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
playerClassContainer.addActionToQueue(remainingWriterContainer.toBuffer);
break;
default:
break;
}
default:
break;
}
this.MultiplayerMatch.sendMatchUpdate();
// Update the match listing for users in the multiplayer lobby
global.MultiplayerManager.updateMatchListing();
}
this.MultiplayerMatch.sendMatchUpdate();
// Update the match listing for users in the multiplayer lobby
global.MultiplayerManager.updateMatchListing();
}
}

View file

@ -1,220 +1,220 @@
const osu = require("osu-packet"),
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"),
StatusUpdate = require("./Packets/StatusUpdate.js"),
MultiplayerMatch = require("./MultiplayerMatch.js");
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"),
StatusUpdate = require("./Packets/StatusUpdate.js"),
MultiplayerMatch = require("./MultiplayerMatch.js");
module.exports = class {
constructor() {
this.matches = [];
}
constructor() {
this.matches = [];
}
userEnterLobby(currentUser) {
// If the user is currently already in a match force them to leave
if (currentUser.currentMatch != null)
currentUser.currentMatch.leaveMatch(currentUser);
userEnterLobby(currentUser) {
// If the user is currently already in a match force them to leave
if (currentUser.currentMatch != null)
currentUser.currentMatch.leaveMatch(currentUser);
// Add user to the stream for the lobby
global.StreamsHandler.addUserToStream("multiplayer_lobby", currentUser.uuid);
// Add user to the stream for the lobby
global.StreamsHandler.addUserToStream("multiplayer_lobby", currentUser.uuid);
// Send user ids of all online users to all users in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", UserPresenceBundle(currentUser, false), null);
// Send user ids of all online users to all users in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", UserPresenceBundle(currentUser, false), null);
// Loop through all matches
for (let i = 0; i < this.matches.length; i++) {
// Loop through all the users in this match
for (let i1 = 0; i1 < this.matches[i].slots.length; i1++) {
const slot = this.matches[i].slots[i1];
// Make sure there is a player / the slot is not locked
if (slot.playerId == -1 || slot.status == 2) continue;
// Loop through all matches
for (let i = 0; i < this.matches.length; i++) {
// Loop through all the users in this match
for (let i1 = 0; i1 < this.matches[i].slots.length; i1++) {
const slot = this.matches[i].slots[i1];
// Make sure there is a player / the slot is not locked
if (slot.playerId == -1 || slot.status == 2) continue;
// Send information for this user to all users in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", UserPresence(currentUser, slot.playerId, false), null);
global.StreamsHandler.sendToStream("multiplayer_lobby", StatusUpdate(currentUser, slot.playerId, false), null);
}
const osuPacketWriter = new osu.Bancho.Writer;
// Send information for this user to all users in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", UserPresence(currentUser, slot.playerId, false), null);
global.StreamsHandler.sendToStream("multiplayer_lobby", StatusUpdate(currentUser, slot.playerId, false), null);
}
const osuPacketWriter = new osu.Bancho.Writer;
// List the match on the client
osuPacketWriter.MatchNew(this.matches[i].createOsuMatchJSON());
// List the match on the client
osuPacketWriter.MatchNew(this.matches[i].createOsuMatchJSON());
currentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
const osuPacketWriter = new osu.Bancho.Writer;
currentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
const osuPacketWriter = new osu.Bancho.Writer;
// Add the user to the #lobby channel
if (!global.StreamsHandler.isUserInStream("#lobby", currentUser.uuid)) {
global.StreamsHandler.addUserToStream("#lobby", currentUser.uuid);
osuPacketWriter.ChannelJoinSuccess("#lobby");
}
currentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
// Add the user to the #lobby channel
if (!global.StreamsHandler.isUserInStream("#lobby", currentUser.uuid)) {
global.StreamsHandler.addUserToStream("#lobby", currentUser.uuid);
osuPacketWriter.ChannelJoinSuccess("#lobby");
}
currentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
userLeaveLobby(currentUser) {
// Remove user from the stream for the multiplayer lobby if they are a part of it
if (global.StreamsHandler.isUserInStream("multiplayer_lobby", currentUser.uuid))
global.StreamsHandler.removeUserFromStream("multiplayer_lobby", currentUser.uuid);
}
updateMatchListing() {
// Send user ids of all online users to all users in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", UserPresenceBundle(null, false), null);
userLeaveLobby(currentUser) {
// Remove user from the stream for the multiplayer lobby if they are a part of it
if (global.StreamsHandler.isUserInStream("multiplayer_lobby", currentUser.uuid))
global.StreamsHandler.removeUserFromStream("multiplayer_lobby", currentUser.uuid);
}
updateMatchListing() {
// Send user ids of all online users to all users in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", UserPresenceBundle(null, false), null);
// List through all matches
for (let i = 0; i < this.matches.length; i++) {
// List through all users in the match
for (let i1 = 0; i1 < this.matches[i].slots.length; i1++) {
const slot = this.matches[i].slots[i1];
// Make sure the slot has a user in it / isn't locked
if (slot.playerId == -1 || slot.status == 2) continue;
// List through all matches
for (let i = 0; i < this.matches.length; i++) {
// List through all users in the match
for (let i1 = 0; i1 < this.matches[i].slots.length; i1++) {
const slot = this.matches[i].slots[i1];
// Make sure the slot has a user in it / isn't locked
if (slot.playerId == -1 || slot.status == 2) continue;
// Send information for this user to all users in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", UserPresence(null, slot.playerId, false), null);
global.StreamsHandler.sendToStream("multiplayer_lobby", StatusUpdate(null, slot.playerId, false), null);
}
const osuPacketWriter = new osu.Bancho.Writer;
// Send information for this user to all users in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", UserPresence(null, slot.playerId, false), null);
global.StreamsHandler.sendToStream("multiplayer_lobby", StatusUpdate(null, slot.playerId, false), null);
}
const osuPacketWriter = new osu.Bancho.Writer;
// List the match on the client
osuPacketWriter.MatchNew(this.matches[i].createOsuMatchJSON());
// List the match on the client
osuPacketWriter.MatchNew(this.matches[i].createOsuMatchJSON());
// Send this data back to every user in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", osuPacketWriter.toBuffer, null);
}
}
// Send this data back to every user in the lobby
global.StreamsHandler.sendToStream("multiplayer_lobby", osuPacketWriter.toBuffer, null);
}
}
createMultiplayerMatch(MatchHost, MatchData) {
let matchClass = null;
this.matches.push(matchClass = new MultiplayerMatch(MatchHost, MatchData));
createMultiplayerMatch(MatchHost, MatchData) {
let matchClass = null;
this.matches.push(matchClass = new MultiplayerMatch(MatchHost, MatchData));
// Join the user to the newly created match
this.joinMultiplayerMatch(MatchHost, {
matchId: matchClass.matchId,
gamePassword: matchClass.gamePassword
});
}
// Join the user to the newly created match
this.joinMultiplayerMatch(MatchHost, {
matchId: matchClass.matchId,
gamePassword: matchClass.gamePassword
});
}
joinMultiplayerMatch(JoiningUser, JoinInfo) {
try {
let osuPacketWriter = new osu.Bancho.Writer;
const osuPacketWriter1 = new osu.Bancho.Writer;
joinMultiplayerMatch(JoiningUser, JoinInfo) {
try {
let osuPacketWriter = new osu.Bancho.Writer;
const osuPacketWriter1 = new osu.Bancho.Writer;
let matchIndex = 0;
for (let i = 0; i < this.matches.length; i++) {
if (this.matches[i].matchId == JoinInfo.matchId) {
matchIndex = i;
break;
}
}
let matchIndex = 0;
for (let i = 0; i < this.matches.length; i++) {
if (this.matches[i].matchId == JoinInfo.matchId) {
matchIndex = i;
break;
}
}
const streamName = this.matches[matchIndex].matchStreamName;
const chatStreamName = this.matches[matchIndex].matchChatStreamName;
const match = this.matches[matchIndex];
const streamName = this.matches[matchIndex].matchStreamName;
const chatStreamName = this.matches[matchIndex].matchChatStreamName;
const match = this.matches[matchIndex];
let full = true;
// Loop through all slots to find an empty one
for (let i = 0; i < match.slots.length; i++) {
const slot = match.slots[i];
// Make sure the slot doesn't have a player in it / the slot is locked
if (slot.playerId !== -1 || slot.status === 2) continue;
let full = true;
// Loop through all slots to find an empty one
for (let i = 0; i < match.slots.length; i++) {
const slot = match.slots[i];
// Make sure the slot doesn't have a player in it / the slot is locked
if (slot.playerId !== -1 || slot.status === 2) continue;
// Slot is empty and not locked, we can join the match!
full = false;
slot.playerId = JoiningUser.id;
JoiningUser.matchSlotId = i;
slot.status = 4;
break;
}
// Slot is empty and not locked, we can join the match!
full = false;
slot.playerId = JoiningUser.id;
JoiningUser.matchSlotId = i;
slot.status = 4;
break;
}
const matchJSON = match.createOsuMatchJSON();
osuPacketWriter1.MatchUpdate(matchJSON);
osuPacketWriter.MatchJoinSuccess(matchJSON);
const matchJSON = match.createOsuMatchJSON();
osuPacketWriter1.MatchUpdate(matchJSON);
osuPacketWriter.MatchJoinSuccess(matchJSON);
if (full) {
throw "MatchFullException";
}
if (full) {
throw "MatchFullException";
}
// Set the user's current match to this match
JoiningUser.currentMatch = match;
// Set the user's current match to this match
JoiningUser.currentMatch = match;
// Add user to the stream for the match
global.StreamsHandler.addUserToStream(streamName, JoiningUser.uuid);
global.StreamsHandler.addUserToStream(chatStreamName, JoiningUser.uuid);
// Add user to the stream for the match
global.StreamsHandler.addUserToStream(streamName, JoiningUser.uuid);
global.StreamsHandler.addUserToStream(chatStreamName, JoiningUser.uuid);
// Inform all users in the match that a new user has joined
global.StreamsHandler.sendToStream(streamName, osuPacketWriter1.toBuffer, null);
// Inform all users in the match that a new user has joined
global.StreamsHandler.sendToStream(streamName, osuPacketWriter1.toBuffer, null);
osuPacketWriter.ChannelJoinSuccess("#multiplayer");
osuPacketWriter.ChannelJoinSuccess("#multiplayer");
// Inform joining client they they have joined the match
JoiningUser.addActionToQueue(osuPacketWriter.toBuffer);
// Inform joining client they they have joined the match
JoiningUser.addActionToQueue(osuPacketWriter.toBuffer);
// Update the match listing for all users in the lobby since
// A user has joined a match
this.updateMatchListing();
} catch (e) {
// Inform the client that there was an issue joining the match
const osuPacketWriter = new osu.Bancho.Writer;
// Update the match listing for all users in the lobby since
// A user has joined a match
this.updateMatchListing();
} catch (e) {
// Inform the client that there was an issue joining the match
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.MatchJoinFail();
osuPacketWriter.MatchJoinFail();
JoiningUser.addActionToQueue(osuPacketWriter.toBuffer);
JoiningUser.addActionToQueue(osuPacketWriter.toBuffer);
this.updateMatchListing();
}
}
this.updateMatchListing();
}
}
leaveMultiplayerMatch(MatchUser) {
// Make sure the user is in a match
if (MatchUser.currentMatch == null) return;
leaveMultiplayerMatch(MatchUser) {
// Make sure the user is in a match
if (MatchUser.currentMatch == null) return;
const mpLobby = MatchUser.currentMatch.leaveMatch(MatchUser);
const mpLobby = MatchUser.currentMatch.leaveMatch(MatchUser);
let empty = true;
// Check if the match is empty
for (let i = 0; i < mpLobby.slots.length; i++) {
const slot = mpLobby.slots[i];
// Check if the slot is avaliable
if (slot.playerId === -1) continue;
// There is a user in the match
empty = false;
break;
}
let empty = true;
// Check if the match is empty
for (let i = 0; i < mpLobby.slots.length; i++) {
const slot = mpLobby.slots[i];
// Check if the slot is avaliable
if (slot.playerId === -1) continue;
// There is a user in the match
empty = false;
break;
}
// The match is empty, proceed to remove it.
if (empty) {
let matchIndex;
// Loop through all matches
for (let i = 0; i < this.matches.length; i++) {
// If the match matches the match the user has left
if (this.matches[i].matchStreamName == MatchUser.currentMatch.matchStreamName) {
matchIndex = i;
break;
}
}
// The match is empty, proceed to remove it.
if (empty) {
let matchIndex;
// Loop through all matches
for (let i = 0; i < this.matches.length; i++) {
// If the match matches the match the user has left
if (this.matches[i].matchStreamName == MatchUser.currentMatch.matchStreamName) {
matchIndex = i;
break;
}
}
// Make sure we got a match index
if (matchIndex == null) return;
// Make sure we got a match index
if (matchIndex == null) return;
// Remove this match from the list of active matches
this.matches.splice(matchIndex, 1);
}
// Remove this match from the list of active matches
this.matches.splice(matchIndex, 1);
}
MatchUser.currentMatch = null;
MatchUser.currentMatch = null;
// Update the match listing to reflect this change (either removal or user leaving)
this.updateMatchListing();
// Update the match listing to reflect this change (either removal or user leaving)
this.updateMatchListing();
// Delay a 2nd match listing update
setTimeout(() => {
this.updateMatchListing();
}, 1000);
}
// Delay a 2nd match listing update
setTimeout(() => {
this.updateMatchListing();
}, 1000);
}
getMatch(MatchID) {
for (let match in this.matches) {
if (match.matchId == MatchID) return match;
}
return null;
}
getMatch(MatchID) {
for (let match in this.matches) {
if (match.matchId == MatchID) return match;
}
return null;
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,3 @@
module.exports = function(CurrentUser, FriendToAdd) {
global.DatabaseHelper.query(`INSERT INTO friends (user, friendsWith) VALUES (${CurrentUser.id}, ${FriendToAdd});`);
global.DatabaseHelper.query(`INSERT INTO friends (user, friendsWith) VALUES (${CurrentUser.id}, ${FriendToAdd});`);
}

View file

@ -1,10 +1,10 @@
const StatusUpdate = require("./StatusUpdate.js");
module.exports = function(currentUser, data) {
currentUser.updatePresence(data);
currentUser.updatePresence(data);
if (global.StreamsHandler.doesStreamExist(`sp_${currentUser.username}`)) {
const statusUpdate = StatusUpdate(currentUser, currentUser.id, false);
global.StreamsHandler.sendToStream(`sp_${currentUser.username}`, statusUpdate, null);
}
if (global.StreamsHandler.doesStreamExist(`sp_${currentUser.username}`)) {
const statusUpdate = StatusUpdate(currentUser, currentUser.id, false);
global.StreamsHandler.sendToStream(`sp_${currentUser.username}`, statusUpdate, null);
}
}

View file

@ -1,15 +1,16 @@
const osu = require("osu-packet");
const osu = require("osu-packet"),
consoleHelper = require("../../consoleHelper.js");
module.exports = function(CurrentUser, channelName = "") {
// Make sure the user is not already in the channel
if (global.StreamsHandler.isUserInStream(channelName, CurrentUser.uuid))
return global.consoleHelper.printBancho(`Did not add user to channel ${channelName} because they are already in it`);
// Make sure the user is not already in the channel
if (global.StreamsHandler.isUserInStream(channelName, CurrentUser.uuid))
return consoleHelper.printBancho(`Did not add user to channel ${channelName} because they are already in it`);
const osuPacketWriter = new osu.Bancho.Writer;
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.ChannelJoinSuccess(channelName);
if (!global.StreamsHandler.isUserInStream(channelName, CurrentUser.uuid))
global.StreamsHandler.addUserToStream(channelName, CurrentUser.uuid);
osuPacketWriter.ChannelJoinSuccess(channelName);
if (!global.StreamsHandler.isUserInStream(channelName, CurrentUser.uuid))
global.StreamsHandler.addUserToStream(channelName, CurrentUser.uuid);
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}

View file

@ -1,5 +1,5 @@
module.exports = function(CurrentUser, data) {
if (data == "#multiplayer") return; // Ignore requests for multiplayer
if (data == "#multiplayer") return; // Ignore requests for multiplayer
global.StreamsHandler.removeUserFromStream(data, CurrentUser.uuid);
global.StreamsHandler.removeUserFromStream(data, CurrentUser.uuid);
}

View file

@ -1,27 +1,28 @@
const osu = require("osu-packet");
const osu = require("osu-packet"),
consoleHelper = require("../../consoleHelper.js");
module.exports = function(CurrentUser) {
const logoutStartTime = new Date().getTime();
const logoutStartTime = Date.now();
const streamList = global.StreamsHandler.getStreams();
const streamList = global.StreamsHandler.getStreams();
for (let i = 0; i < streamList.length; i++) {
if (global.StreamsHandler.isUserInStream(streamList[i], CurrentUser.uuid)) {
global.StreamsHandler.removeUserFromStream(streamList[i], CurrentUser.uuid);
}
}
for (let i = 0; i < streamList.length; i++) {
if (global.StreamsHandler.isUserInStream(streamList[i], CurrentUser.uuid)) {
global.StreamsHandler.removeUserFromStream(streamList[i], CurrentUser.uuid);
}
}
// Remove user from user list
global.removeUser(CurrentUser);
// Remove user from user list
global.removeUser(CurrentUser);
const osuPacketWriter = new osu.Bancho.Writer();
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: `User ${CurrentUser.username} has logged out.`,
target: "#userlog",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream("#userlog", osuPacketWriter.toBuffer);
const osuPacketWriter = new osu.Bancho.Writer();
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: `User ${CurrentUser.username} has logged out.`,
target: "#userlog",
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream("#userlog", osuPacketWriter.toBuffer);
global.consoleHelper.printBancho(`User logged out, took ${new Date().getTime() - logoutStartTime}ms. [User: ${CurrentUser.username}]`);
consoleHelper.printBancho(`User logged out, took ${Date.now() - logoutStartTime}ms. [User: ${CurrentUser.username}]`);
}

View file

@ -1,17 +1,17 @@
const osu = require("osu-packet"),
getUserById = require("../util/getUserById.js");
getUserById = require("../util/getUserById.js");
module.exports = function(CurrentUser, InvitedUser) {
let osuPacketWriter = new osu.Bancho.Writer;
let osuPacketWriter = new osu.Bancho.Writer;
const InvitedUserClass = getUserById(InvitedUser);
const InvitedUserClass = getUserById(InvitedUser);
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
message: `Come join my multiplayer match: [osump://${CurrentUser.currentMatch.matchId}/ ${CurrentUser.currentMatch.gameName}]`,
target: CurrentUser.username,
senderId: CurrentUser.id
});
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
message: `Come join my multiplayer match: [osump://${CurrentUser.currentMatch.matchId}/ ${CurrentUser.currentMatch.gameName}]`,
target: CurrentUser.username,
senderId: CurrentUser.id
});
InvitedUserClass.addActionToQueue(osuPacketWriter.toBuffer);
InvitedUserClass.addActionToQueue(osuPacketWriter.toBuffer);
}

View file

@ -1,3 +1,3 @@
module.exports = function(CurrentUser, FriendToRemove) {
global.DatabaseHelper.query(`DELETE FROM friends WHERE user = ${CurrentUser.id} AND friendsWith = ${FriendToRemove} LIMIT 1`);
}
global.DatabaseHelper.query(`DELETE FROM friends WHERE user = ${CurrentUser.id} AND friendsWith = ${FriendToRemove} LIMIT 1`);
}

View file

@ -1,19 +1,19 @@
const osu = require("osu-packet"),
getUserByUsername = require("../util/getUserByUsername.js");
getUserByUsername = require("../util/getUserByUsername.js");
module.exports = function(CurrentUser, CurrentPacket) {
const osuPacketWriter = new osu.Bancho.Writer;
const userSentTo = getUserByUsername(CurrentPacket.target);
const osuPacketWriter = new osu.Bancho.Writer;
const userSentTo = getUserByUsername(CurrentPacket.target);
if (userSentTo == null) return;
if (userSentTo == null) return;
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
message: CurrentPacket.message,
target: CurrentUser.username,
senderId: CurrentUser.id
});
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
message: CurrentPacket.message,
target: CurrentUser.username,
senderId: CurrentUser.id
});
// Write chat message to stream asociated with chat channel
return userSentTo.addActionToQueue(osuPacketWriter.toBuffer);
// Write chat message to stream asociated with chat channel
return userSentTo.addActionToQueue(osuPacketWriter.toBuffer);
}

View file

@ -1,56 +1,57 @@
const osu = require("osu-packet"),
botCommandHandler = require("../BotCommandHandler.js");
botCommandHandler = require("../BotCommandHandler.js"),
consoleHelper = require("../../consoleHelper.js");
module.exports = function(CurrentUser, CurrentPacket) {
let isSendingChannelLocked = false;
for (let i = 0; i < global.channels.length; i++) {
if (!CurrentPacket.target.includes("#")) break;
if (global.channels[i].channelName == CurrentPacket.target) {
isSendingChannelLocked = global.channels[i].locked;
break;
}
}
let isSendingChannelLocked = false;
for (let i = 0; i < global.channels.length; i++) {
if (!CurrentPacket.target.includes("#")) break;
if (global.channels[i].channelName == CurrentPacket.target) {
isSendingChannelLocked = global.channels[i].locked;
break;
}
}
if (isSendingChannelLocked) {
if (CurrentPacket.message.includes("!")) {
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
} else {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "The channel you are currently trying to send to is locked, please check back later!",
target: CurrentPacket.target,
senderId: global.users["bot"].id
});
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
return;
}
if (isSendingChannelLocked) {
if (CurrentPacket.message.includes("!")) {
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
} else {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.users["bot"].username,
message: "The channel you are currently trying to send to is locked, please check back later!",
target: CurrentPacket.target,
senderId: global.users["bot"].id
});
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
return;
}
global.consoleHelper.printChat(`${CurrentUser.username} in ${CurrentPacket.target} sent: ${CurrentPacket.message}`);
consoleHelper.printChat(`${CurrentUser.username} in ${CurrentPacket.target} sent: ${CurrentPacket.message}`);
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
message: CurrentPacket.message,
target: CurrentPacket.target,
senderId: CurrentUser.id
});
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: CurrentUser.username,
message: CurrentPacket.message,
target: CurrentPacket.target,
senderId: CurrentUser.id
});
if (CurrentPacket.target == "#multiplayer") {
global.StreamsHandler.sendToStream(CurrentUser.currentMatch.matchChatStreamName, osuPacketWriter.toBuffer, CurrentUser.uuid);
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentUser.currentMatch.matchChatStreamName, true);
return;
}
if (CurrentPacket.target == "#multiplayer") {
global.StreamsHandler.sendToStream(CurrentUser.currentMatch.matchChatStreamName, osuPacketWriter.toBuffer, CurrentUser.uuid);
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentUser.currentMatch.matchChatStreamName, true);
return;
}
// Check the stream that we're sending to even exists
if (!global.StreamsHandler.doesStreamExist(CurrentPacket.target)) return;
// Check the stream that we're sending to even exists
if (!global.StreamsHandler.doesStreamExist(CurrentPacket.target)) return;
// Write chat message to stream asociated with chat channel
global.StreamsHandler.sendToStream(CurrentPacket.target, osuPacketWriter.toBuffer, CurrentUser.uuid);
if (CurrentPacket.target == "#osu")
global.addChatMessage(`${CurrentUser.username}: ${CurrentPacket.message}`);
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
return;
// Write chat message to stream asociated with chat channel
global.StreamsHandler.sendToStream(CurrentPacket.target, osuPacketWriter.toBuffer, CurrentUser.uuid);
if (CurrentPacket.target == "#osu")
global.addChatMessage(`${CurrentUser.username}: ${CurrentPacket.message}`);
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
return;
}

View file

@ -1,36 +1,36 @@
const osu = require("osu-packet"),
getUserById = require("../util/getUserById.js");
getUserById = require("../util/getUserById.js");
module.exports = function(currentUser, id = 0, sendImmidiate = true) {
if (id == 3) return; // Ignore Bot
if (id == 3) return; // Ignore Bot
// Create new osu packet writer
const osuPacketWriter = new osu.Bancho.Writer;
// Create new osu packet writer
const osuPacketWriter = new osu.Bancho.Writer;
// Get user's class
const User = getUserById(id);
// Get user's class
const User = getUserById(id);
if (User == null) return;
if (User == null) return;
let UserStatusObject = {
userId: User.id,
status: User.actionID,
statusText: User.actionText,
beatmapChecksum: User.beatmapChecksum,
currentMods: User.currentMods,
playMode: User.playMode,
beatmapId: User.beatmapID,
rankedScore: User.rankedScore,
accuracy: User.accuracy / 100, // Scale of 0 to 1
playCount: User.playCount,
totalScore: User.totalScore,
rank: User.rank,
performance: (User.rankingMode == 0 ? User.pp : 0)
};
let UserStatusObject = {
userId: User.id,
status: User.actionID,
statusText: User.actionText,
beatmapChecksum: User.beatmapChecksum,
currentMods: User.currentMods,
playMode: User.playMode,
beatmapId: User.beatmapID,
rankedScore: User.rankedScore,
accuracy: User.accuracy / 100, // Scale of 0 to 1
playCount: User.playCount,
totalScore: User.totalScore,
rank: User.rank,
performance: (User.rankingMode == 0 ? User.pp : 0)
};
osuPacketWriter.HandleOsuUpdate(UserStatusObject);
osuPacketWriter.HandleOsuUpdate(UserStatusObject);
// Send data to user's queue
if (sendImmidiate) currentUser.addActionToQueue(osuPacketWriter.toBuffer);
else return osuPacketWriter.toBuffer;
// Send data to user's queue
if (sendImmidiate) currentUser.addActionToQueue(osuPacketWriter.toBuffer);
else return osuPacketWriter.toBuffer;
}

View file

@ -1,26 +1,27 @@
const osu = require("osu-packet");
const osu = require("osu-packet"),
consoleHelper = require("./consoleHelper.js");
module.exports = function(CurrentUser, MatchID) {
const match = global.MultiplayerManager.getMatch(MatchID);
const match = global.MultiplayerManager.getMatch(MatchID);
if (match != null) {
if (match != null) {
match.isTourneyMatch = true;
for (let i = 0; i < global.userKeys.length; i++) {
if (global.users[global.userKeys[i]].id == CurrentUser.id) {
match.tourneyClientUsers.push(global.users[global.userKeys[i]]);
}
}
match.isTourneyMatch = true;
for (let i = 0; i < global.userKeys.length; i++) {
if (global.users[global.userKeys[i]].id == CurrentUser.id) {
match.tourneyClientUsers.push(global.users[global.userKeys[i]]);
}
}
if (global.StreamsHandler.isUserInStream(match.matchChatStreamName, CurrentUser.uuid))
return global.consoleHelper.printBancho(`Did not add user to channel ${match.matchChatStreamName} because they are already in it`);
if (global.StreamsHandler.isUserInStream(match.matchChatStreamName, CurrentUser.uuid))
return consoleHelper.printBancho(`Did not add user to channel ${match.matchChatStreamName} because they are already in it`);
const osuPacketWriter = new osu.Bancho.Writer;
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.ChannelJoinSuccess("#multiplayer");
if (!global.StreamsHandler.isUserInStream(match.matchChatStreamName, CurrentUser.uuid))
global.StreamsHandler.addUserToStream(match.matchChatStreamName, CurrentUser.uuid);
osuPacketWriter.ChannelJoinSuccess("#multiplayer");
if (!global.StreamsHandler.isUserInStream(match.matchChatStreamName, CurrentUser.uuid))
global.StreamsHandler.addUserToStream(match.matchChatStreamName, CurrentUser.uuid);
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
}

View file

@ -1,30 +1,31 @@
const osu = require("osu-packet");
const osu = require("osu-packet"),
consoleHelper = require("../../consoleHelper.js");
module.exports = function(CurrentUser, MatchID) {
const match = global.MultiplayerManager.getMatch(MatchID);
const match = global.MultiplayerManager.getMatch(MatchID);
if (match != null) {
if (match != null) {
match.isTourneyMatch = false;
match.tourneyClientUsers = [];
match.isTourneyMatch = false;
match.tourneyClientUsers = [];
if (global.StreamsHandler.isUserInStream(match.matchChatStreamName, CurrentUser.uuid))
return global.consoleHelper.printBancho(`Did not add user to channel ${match.matchChatStreamName} because they are already in it`);
if (global.StreamsHandler.isUserInStream(match.matchChatStreamName, CurrentUser.uuid))
return consoleHelper.printBancho(`Did not add user to channel ${match.matchChatStreamName} because they are already in it`);
const osuPacketWriter = new osu.Bancho.Writer;
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.ChannelRevoked("#multiplayer");
if (!global.StreamsHandler.isUserInStream(match.matchChatStreamName, CurrentUser.uuid))
global.StreamsHandler.removeUserFromStream(match.matchChatStreamName, CurrentUser.uuid);
osuPacketWriter.ChannelRevoked("#multiplayer");
if (!global.StreamsHandler.isUserInStream(match.matchChatStreamName, CurrentUser.uuid))
global.StreamsHandler.removeUserFromStream(match.matchChatStreamName, CurrentUser.uuid);
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
} else {
// Still provide feedback just in case
// TODO: Check if this has any effect, if not then remove this.
const osuPacketWriter = new osu.Bancho.Writer;
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
} else {
// Still provide feedback just in case
// TODO: Check if this has any effect, if not then remove this.
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.ChannelRevoked("#multiplayer");
osuPacketWriter.ChannelRevoked("#multiplayer");
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
}

View file

@ -1,22 +1,22 @@
const osu = require("osu-packet"),
UserPresence = require("./UserPresence.js"),
StatusUpdate = require("./StatusUpdate.js");
UserPresence = require("./UserPresence.js"),
StatusUpdate = require("./StatusUpdate.js");
module.exports = function(CurrentUser, MatchID) {
const matchData = global.MultiplayerManager.getMatch(MatchID);
const matchData = global.MultiplayerManager.getMatch(MatchID);
if (matchData != null) {
const osuPacketWriter = new osu.Bancho.Writer();
if (matchData != null) {
const osuPacketWriter = new osu.Bancho.Writer();
osuPacketWriter.MatchUpdate(matchData.createOsuMatchJSON());
osuPacketWriter.MatchUpdate(matchData.createOsuMatchJSON());
// Queue info on all the users in the match to the client
for (let slot in matchData.slots) {
CurrentUser.addActionToQueue(UserPresence(CurrentUser, slot.playerId, false));
CurrentUser.addActionToQueue(StatusUpdate(CurrentUser, slot.playerId, false));
}
// Queue info on all the users in the match to the client
for (let slot in matchData.slots) {
CurrentUser.addActionToQueue(UserPresence(CurrentUser, slot.playerId, false));
CurrentUser.addActionToQueue(StatusUpdate(CurrentUser, slot.playerId, false));
}
// Queue data
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
// Queue data
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}
}

View file

@ -1,24 +1,24 @@
const osu = require("osu-packet"),
getUserById = require("../util/getUserById.js");
getUserById = require("../util/getUserById.js");
module.exports = function(currentUser, id = 0, sendImmidiate = true) {
const osuPacketWriter = new osu.Bancho.Writer;
const osuPacketWriter = new osu.Bancho.Writer;
const User = getUserById(id);
const User = getUserById(id);
if (User == null) return;
if (User == null) return;
osuPacketWriter.UserPresence({
userId: id,
username: User.username,
timezone: 0,
countryId: User.countryID,
permissions: 4,
longitude: User.location[1],
latitude: User.location[0],
rank: User.rank
});
osuPacketWriter.UserPresence({
userId: id,
username: User.username,
timezone: 0,
countryId: User.countryID,
permissions: 4,
longitude: User.location[1],
latitude: User.location[0],
rank: User.rank
});
if (sendImmidiate) currentUser.addActionToQueue(osuPacketWriter.toBuffer);
else return osuPacketWriter.toBuffer;
if (sendImmidiate) currentUser.addActionToQueue(osuPacketWriter.toBuffer);
else return osuPacketWriter.toBuffer;
}

View file

@ -1,16 +1,16 @@
const osu = require("osu-packet");
module.exports = function(currentUser, sendImmidiate = true) {
const osuPacketWriter = new osu.Bancho.Writer;
const osuPacketWriter = new osu.Bancho.Writer;
let userIds = [];
let userIds = [];
for (let i = 0; i < global.userKeys.length; i++) {
userIds.push(global.users[global.userKeys[i]].id);
}
for (let i = 0; i < global.userKeys.length; i++) {
userIds.push(global.users[global.userKeys[i]].id);
}
osuPacketWriter.UserPresenceBundle(userIds);
osuPacketWriter.UserPresenceBundle(userIds);
if (sendImmidiate) currentUser.addActionToQueue(osuPacketWriter.toBuffer);
else return osuPacketWriter.toBuffer;
if (sendImmidiate) currentUser.addActionToQueue(osuPacketWriter.toBuffer);
else return osuPacketWriter.toBuffer;
}

View file

@ -1,14 +1,14 @@
const UserPresenceBundle = require("./UserPresenceBundle.js"),
UserPresence = require("./UserPresence.js"),
StatusUpdate = require("./StatusUpdate.js");
UserPresence = require("./UserPresence.js"),
StatusUpdate = require("./StatusUpdate.js");
module.exports = function (currentUser, data = [0]) {
UserPresenceBundle(currentUser);
UserPresenceBundle(currentUser);
for (let i1 = 0; i1 < data.length; i1++) {
const CurrentUserID = data[i1];
for (let i1 = 0; i1 < data.length; i1++) {
const CurrentUserID = data[i1];
UserPresence(currentUser, CurrentUserID);
StatusUpdate(currentUser, CurrentUserID);
}
UserPresence(currentUser, CurrentUserID);
StatusUpdate(currentUser, CurrentUserID);
}
}

View file

@ -1,75 +1,75 @@
const osu = require("osu-packet"),
getUserById = require("./util/getUserById.js");
getUserById = require("./util/getUserById.js");
module.exports = {
startSpectatingUser:function(currentUser, spectatedId) {
// Get the user this user is trying to spectate
const User = getUserById(spectatedId);
if (global.StreamsHandler.doesStreamExist(`sp_${User.id}`)) {
// Just add user to stream since it already exists
global.StreamsHandler.addUserToStream(`sp_${User.id}`, currentUser.uuid);
} else {
// Stream doesn't exist, create it and add the spectator
global.StreamsHandler.addStream(`sp_${User.id}`, true, spectatedId);
global.StreamsHandler.addUserToStream(`sp_${User.id}`, currentUser.uuid);
}
startSpectatingUser:function(currentUser, spectatedId) {
// Get the user this user is trying to spectate
const User = getUserById(spectatedId);
if (global.StreamsHandler.doesStreamExist(`sp_${User.id}`)) {
// Just add user to stream since it already exists
global.StreamsHandler.addUserToStream(`sp_${User.id}`, currentUser.uuid);
} else {
// Stream doesn't exist, create it and add the spectator
global.StreamsHandler.addStream(`sp_${User.id}`, true, spectatedId);
global.StreamsHandler.addUserToStream(`sp_${User.id}`, currentUser.uuid);
}
// We want to do this stuff regardless
// Create a new osu packet writer
let osuPacketWriter = new osu.Bancho.Writer;
// We want to do this stuff regardless
// Create a new osu packet writer
let osuPacketWriter = new osu.Bancho.Writer;
// Set the user requesting to be spectating this user
currentUser.spectating = spectatedId;
// Tell the client of the user being spectated that they are being spectated
osuPacketWriter.SpectatorJoined(currentUser.id);
// Set the user requesting to be spectating this user
currentUser.spectating = spectatedId;
// Tell the client of the user being spectated that they are being spectated
osuPacketWriter.SpectatorJoined(currentUser.id);
// Send the packet to the spectated user's queue
User.addActionToQueue(osuPacketWriter.toBuffer);
// Send the packet to the spectated user's queue
User.addActionToQueue(osuPacketWriter.toBuffer);
// Make a new clear osu packet writer
osuPacketWriter = new osu.Bancho.Writer;
// Make a new clear osu packet writer
osuPacketWriter = new osu.Bancho.Writer;
// Tell everyone spectating this user that another user has started spectating
osuPacketWriter.FellowSpectatorJoined(currentUser.id);
// Tell everyone spectating this user that another user has started spectating
osuPacketWriter.FellowSpectatorJoined(currentUser.id);
// Send this packet to all the spectators
global.StreamsHandler.sendToStream(`sp_${User.id}`, osuPacketWriter.toBuffer);
},
// Send this packet to all the spectators
global.StreamsHandler.sendToStream(`sp_${User.id}`, osuPacketWriter.toBuffer);
},
sendSpectatorFrames(currentUser, data) {
// Create new osu packet writer
const osuPacketWriter = new osu.Bancho.Writer;
sendSpectatorFrames(currentUser, data) {
// Create new osu packet writer
const osuPacketWriter = new osu.Bancho.Writer;
// Data containing the user's actions
osuPacketWriter.SpectateFrames(data);
// Data containing the user's actions
osuPacketWriter.SpectateFrames(data);
// Send the frames to all the spectators
global.StreamsHandler.sendToStream(`sp_${currentUser.id}`, osuPacketWriter.toBuffer, null);
},
// Send the frames to all the spectators
global.StreamsHandler.sendToStream(`sp_${currentUser.id}`, osuPacketWriter.toBuffer, null);
},
stopSpectatingUser(currentUser) {
// Get the user this user is spectating
const spectatedUser = getUserById(currentUser.spectating);
// Create new osu packet writer
let osuPacketWriter = new osu.Bancho.Writer;
stopSpectatingUser(currentUser) {
// Get the user this user is spectating
const spectatedUser = getUserById(currentUser.spectating);
// Create new osu packet writer
let osuPacketWriter = new osu.Bancho.Writer;
// Inform the client being spectated that this user has stopped spectating
osuPacketWriter.SpectatorLeft(currentUser.id);
// Inform the client being spectated that this user has stopped spectating
osuPacketWriter.SpectatorLeft(currentUser.id);
// Add this packet to the spectated user's queue
spectatedUser.addActionToQueue(osuPacketWriter.toBuffer);
// Add this packet to the spectated user's queue
spectatedUser.addActionToQueue(osuPacketWriter.toBuffer);
// Remove this user from the spectator stream
global.StreamsHandler.removeUserFromStream(`sp_${spectatedUser.id}`, currentUser.uuid);
// Remove this user from the spectator stream
global.StreamsHandler.removeUserFromStream(`sp_${spectatedUser.id}`, currentUser.uuid);
// Make a new clear osu packet writer
osuPacketWriter = new osu.Bancho.Writer;
// Make a new clear osu packet writer
osuPacketWriter = new osu.Bancho.Writer;
// Inform other users spectating that this spectator has left
osuPacketWriter.FellowSpectatorLeft(currentUser.id);
// Inform other users spectating that this spectator has left
osuPacketWriter.FellowSpectatorLeft(currentUser.id);
// Send this packet to all spectators
global.StreamsHandler.sendToStream(`sp_${spectatedUser.id}`, osuPacketWriter.toBuffer);
}
// Send this packet to all spectators
global.StreamsHandler.sendToStream(`sp_${spectatedUser.id}`, osuPacketWriter.toBuffer);
}
}

View file

@ -1,135 +1,136 @@
const getUserByToken = require("./util/getUserByToken.js");
const getUserByToken = require("./util/getUserByToken.js"),
consoleHelper = require("../consoleHelper.js");
module.exports = class {
constructor() {
this.avaliableStreams = {};
this.avaliableStreamKeys = [];
}
constructor() {
this.avaliableStreams = {};
this.avaliableStreamKeys = [];
}
addStream(streamName = "", removeIfEmpty = false, spectatorHostId = null) {
// Make sure a stream with the same name doesn't exist already
if (this.avaliableStreamKeys.includes(streamName))
return global.consoleHelper.printBancho(`Did not add stream [${streamName}] A stream with the same name already exists`);
// Add new stream to the list of streams
this.avaliableStreams[streamName] = {
streamUsers: [], // An array containing a list of user tokens of the users in a given stream
streamSpectatorHost: spectatorHostId, // null unless stream is for spectating
removeIfEmpty: removeIfEmpty
}
this.avaliableStreamKeys = Object.keys(this.avaliableStreams);
global.consoleHelper.printBancho(`Added stream [${streamName}]`);
}
addStream(streamName = "", removeIfEmpty = false, spectatorHostId = null) {
// Make sure a stream with the same name doesn't exist already
if (this.avaliableStreamKeys.includes(streamName))
return consoleHelper.printBancho(`Did not add stream [${streamName}] A stream with the same name already exists`);
// Add new stream to the list of streams
this.avaliableStreams[streamName] = {
streamUsers: [], // An array containing a list of user tokens of the users in a given stream
streamSpectatorHost: spectatorHostId, // null unless stream is for spectating
removeIfEmpty: removeIfEmpty
}
this.avaliableStreamKeys = Object.keys(this.avaliableStreams);
consoleHelper.printBancho(`Added stream [${streamName}]`);
}
// Checks if a stream has no users in it
streamChecker(interval = 5000) {
setInterval(() => {
// Get the names of all currently avaliable streams
const streams = global.StreamsHandler.getStreams();
// Loop through all streams
for (let i = 0; i < streams.length; i++) {
// Get the current stream
const currentStream = global.StreamsHandler.avaliableStreams[streams[i]];
// Check if the stream should be removed if there are no users in it
// And if the stream has no users in it
if (currentStream.removeIfEmpty && currentStream.streamUsers.length == 0) {
global.StreamsHandler.removeStream(streams[i]);
global.consoleHelper.printBancho(`Removed stream [${streams[i]}] There were no users in stream`);
}
}
}, interval);
global.consoleHelper.printBancho(`BinatoStream is running! Checks running at a ${interval}ms interval`);
}
// Checks if a stream has no users in it
streamChecker(interval = 5000) {
setInterval(() => {
// Get the names of all currently avaliable streams
const streams = global.StreamsHandler.getStreams();
// Loop through all streams
for (let i = 0; i < streams.length; i++) {
// Get the current stream
const currentStream = global.StreamsHandler.avaliableStreams[streams[i]];
// Check if the stream should be removed if there are no users in it
// And if the stream has no users in it
if (currentStream.removeIfEmpty && currentStream.streamUsers.length == 0) {
global.StreamsHandler.removeStream(streams[i]);
consoleHelper.printBancho(`Removed stream [${streams[i]}] There were no users in stream`);
}
}
}, interval);
consoleHelper.printBancho(`BinatoStream is running! Checks running at a ${interval}ms interval`);
}
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!`);
sendToStream(streamName, streamData, initUser = null) {
// Make sure the stream we are attempting to send to even exists
if (!this.doesStreamExist(streamName))
return 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];
// Get the stream to send the data to
const currentStream = this.avaliableStreams[streamName];
// 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);
}
}
// Send stream data to user's own queue
currentUser.addActionToQueue(streamData);
}
}
addUserToStream(streamName, userToken) {
// Make sure the stream we are attempting to add this user to even exists
if (!this.doesStreamExist(streamName))
return global.consoleHelper.printBancho(`Did not add user to stream [${streamName}] because it does not exist!`);
addUserToStream(streamName, userToken) {
// Make sure the stream we are attempting to add this user to even exists
if (!this.doesStreamExist(streamName))
return consoleHelper.printBancho(`Did not add user to stream [${streamName}] because it does not exist!`);
// Make sure the user isn't already in the stream
if (this.avaliableStreams[streamName].streamUsers.includes(userToken))
return global.consoleHelper.printBancho(`Did not add user to stream [${streamName}] because they are already in it!`);
// Make sure the user isn't already in the stream
if (this.avaliableStreams[streamName].streamUsers.includes(userToken))
return consoleHelper.printBancho(`Did not add user to stream [${streamName}] because they are already in it!`);
// Make sure this isn't an invalid user (userId can't be lower than 1)
if (userToken == "" || userToken == null)
return global.consoleHelper.printBancho(`Did not add user to stream [${streamName}] because their token is invalid!`);
// Make sure this isn't an invalid user (userId can't be lower than 1)
if (userToken == "" || userToken == null)
return consoleHelper.printBancho(`Did not add user to stream [${streamName}] because their token is invalid!`);
// Add user's token to the stream's user list
this.avaliableStreams[streamName].streamUsers.push(userToken);
global.consoleHelper.printBancho(`Added user [${userToken}] to stream ${streamName}`);
}
// Add user's token to the stream's user list
this.avaliableStreams[streamName].streamUsers.push(userToken);
consoleHelper.printBancho(`Added user [${userToken}] to stream ${streamName}`);
}
removeUserFromStream(streamName, userToken) {
// Make sure the stream we are attempting to add this user to even exists
if (!this.doesStreamExist(streamName))
return global.consoleHelper.printBancho(`Did not remove user from stream [${streamName}] because it does not exist!`);
removeUserFromStream(streamName, userToken) {
// Make sure the stream we are attempting to add this user to even exists
if (!this.doesStreamExist(streamName))
return consoleHelper.printBancho(`Did not remove user from stream [${streamName}] because it does not exist!`);
// Make sure the user isn't already in the stream
if (!this.avaliableStreams[streamName].streamUsers.includes(userToken))
return global.consoleHelper.printBancho(`Did not remove user from stream [${streamName}] because they are not in it!`);
// Make sure the user isn't already in the stream
if (!this.avaliableStreams[streamName].streamUsers.includes(userToken))
return consoleHelper.printBancho(`Did not remove user from stream [${streamName}] because they are not in it!`);
// Make sure this isn't an invalid user (userId can't be lower than 1)
if (userToken == "" || userToken == null)
return global.consoleHelper.printBancho(`Did not remove user from stream [${streamName}] because their userId is invalid!`);
try {
// Find index of user to remove
let userCurrentIndex;
for (let i = 0; i < this.avaliableStreams[streamName].streamUsers.length; i++) {
if (userToken == this.avaliableStreams[streamName].streamUsers[i]) {
userCurrentIndex = i;
break;
}
}
// Make sure this isn't an invalid user (userId can't be lower than 1)
if (userToken == "" || userToken == null)
return consoleHelper.printBancho(`Did not remove user from stream [${streamName}] because their userId is invalid!`);
try {
// Find index of user to remove
let userCurrentIndex;
for (let i = 0; i < this.avaliableStreams[streamName].streamUsers.length; i++) {
if (userToken == this.avaliableStreams[streamName].streamUsers[i]) {
userCurrentIndex = i;
break;
}
}
// Remove user from stream's user list
this.avaliableStreams[streamName].streamUsers.splice(userCurrentIndex, 1);
global.consoleHelper.printBancho(`Removed user [${userToken}] from stream ${streamName}`);
} catch (e) { global.consoleHelper.printBancho(`Can't Remove user [${userToken}] from stream ${streamName}`); }
}
// Remove user from stream's user list
this.avaliableStreams[streamName].streamUsers.splice(userCurrentIndex, 1);
consoleHelper.printBancho(`Removed user [${userToken}] from stream ${streamName}`);
} catch (e) { consoleHelper.printBancho(`Can't Remove user [${userToken}] from stream ${streamName}`); }
}
doesStreamExist(streamName) {
return this.avaliableStreamKeys.includes(streamName);
}
doesStreamExist(streamName) {
return this.avaliableStreamKeys.includes(streamName);
}
getStreams() {
// Return the names of all avaliable streams
return this.avaliableStreamKeys;
}
getStreams() {
// Return the names of all avaliable streams
return this.avaliableStreamKeys;
}
isUserInStream(streamName, userToken) {
if (this.avaliableStreams[streamName].streamUsers.includes(userToken)) return true;
else return false;
}
isUserInStream(streamName, userToken) {
if (this.avaliableStreams[streamName].streamUsers.includes(userToken)) return true;
else return false;
}
removeStream(streamName) {
try {
delete this.avaliableStreams[streamName];
this.avaliableStreamKeys = Object.keys(this.avaliableStreams);
} catch (e) { global.consoleHelper.printError(`Was not able to remove stream [${streamName}]`) }
}
removeStream(streamName) {
try {
delete this.avaliableStreams[streamName];
this.avaliableStreamKeys = Object.keys(this.avaliableStreams);
} catch (e) { consoleHelper.printError(`Was not able to remove stream [${streamName}]`) }
}
}

View file

@ -1,9 +1,9 @@
module.exports = function(s) {
switch (s) {
case "reconnect":
return "\u0005\u0000\u0000\u0004\u0000\u0000\u0000<30><30><EFBFBD><EFBFBD>\u0018\u0000\u0000\u0011\u0000\u0000\u0000\u000b\u000fReconnecting...";
switch (s) {
case "reconnect":
return "\u0005\u0000\u0000\u0004\u0000\u0000\u0000<30><30><EFBFBD><EFBFBD>\u0018\u0000\u0000\u0011\u0000\u0000\u0000\u000b\u000fReconnecting...";
default:
return Buffer.alloc(0);
}
default:
return Buffer.alloc(0);
}
}

View file

@ -1,274 +1,274 @@
const countryCodes = {
"LV": 132,
"AD": 3,
"LT": 130,
"KM": 116,
"QA": 182,
"VA": 0,
"PK": 173,
"KI": 115,
"SS": 0,
"KH": 114,
"NZ": 166,
"TO": 215,
"KZ": 122,
"GA": 76,
"BW": 35,
"AX": 247,
"GE": 79,
"UA": 222,
"CR": 50,
"AE": 0,
"NE": 157,
"ZA": 240,
"SK": 196,
"BV": 34,
"SH": 0,
"PT": 179,
"SC": 189,
"CO": 49,
"GP": 86,
"GY": 93,
"CM": 47,
"TJ": 211,
"AF": 5,
"IE": 101,
"AL": 8,
"BG": 24,
"JO": 110,
"MU": 149,
"PM": 0,
"LA": 0,
"IO": 104,
"KY": 121,
"SA": 187,
"KN": 0,
"OM": 167,
"CY": 54,
"BQ": 0,
"BT": 33,
"WS": 236,
"ES": 67,
"LR": 128,
"RW": 186,
"AQ": 12,
"PW": 180,
"JE": 250,
"TN": 214,
"ZW": 243,
"JP": 111,
"BB": 20,
"VN": 233,
"HN": 96,
"KP": 0,
"WF": 235,
"EC": 62,
"HU": 99,
"GF": 80,
"GQ": 87,
"TW": 220,
"MC": 135,
"BE": 22,
"PN": 176,
"SZ": 205,
"CZ": 55,
"LY": 0,
"IN": 103,
"FM": 0,
"PY": 181,
"PH": 172,
"MN": 142,
"GG": 248,
"CC": 39,
"ME": 242,
"DO": 60,
"KR": 0,
"PL": 174,
"MT": 148,
"MM": 141,
"AW": 17,
"MV": 150,
"BD": 21,
"NR": 164,
"AT": 15,
"GW": 92,
"FR": 74,
"LI": 126,
"CF": 41,
"DZ": 61,
"MA": 134,
"VG": 0,
"NC": 156,
"IQ": 105,
"BN": 0,
"BF": 23,
"BO": 30,
"GB": 77,
"CU": 51,
"LU": 131,
"YT": 238,
"NO": 162,
"SM": 198,
"GL": 83,
"IS": 107,
"AO": 11,
"MH": 138,
"SE": 191,
"ZM": 241,
"FJ": 70,
"SL": 197,
"CH": 43,
"RU": 0,
"CW": 0,
"CX": 53,
"TF": 208,
"NL": 161,
"AU": 16,
"FI": 69,
"MS": 147,
"GH": 81,
"BY": 36,
"IL": 102,
"VC": 0,
"NG": 159,
"HT": 98,
"LS": 129,
"MR": 146,
"YE": 237,
"MP": 144,
"SX": 0,
"RE": 183,
"RO": 184,
"NP": 163,
"CG": 0,
"FO": 73,
"CI": 0,
"TH": 210,
"HK": 94,
"TK": 212,
"XK": 0,
"DM": 59,
"LC": 0,
"ID": 100,
"MG": 137,
"JM": 109,
"IT": 108,
"CA": 38,
"TZ": 221,
"GI": 82,
"KG": 113,
"NU": 165,
"TV": 219,
"LB": 124,
"SY": 0,
"PR": 177,
"NI": 160,
"KE": 112,
"MO": 0,
"SR": 201,
"VI": 0,
"SV": 203,
"HM": 0,
"CD": 0,
"BI": 26,
"BM": 28,
"MW": 151,
"TM": 213,
"GT": 90,
"AG": 0,
"UM": 0,
"US": 225,
"AR": 13,
"DJ": 57,
"KW": 120,
"MY": 153,
"FK": 71,
"EG": 64,
"BA": 0,
"CN": 48,
"GN": 85,
"PS": 178,
"SO": 200,
"IM": 249,
"GS": 0,
"BR": 31,
"GM": 84,
"PF": 170,
"PA": 168,
"PG": 171,
"BH": 25,
"TG": 209,
"GU": 91,
"CK": 45,
"MF": 252,
"VE": 230,
"CL": 46,
"TR": 217,
"UG": 223,
"GD": 78,
"TT": 218,
"TL": 0,
"MD": 0,
"MK": 0,
"ST": 202,
"CV": 52,
"MQ": 145,
"GR": 88,
"HR": 97,
"BZ": 37,
"UZ": 227,
"DK": 58,
"SN": 199,
"ET": 68,
"VU": 234,
"ER": 66,
"BJ": 27,
"LK": 127,
"NA": 155,
"AS": 14,
"SG": 192,
"PE": 169,
"IR": 0,
"MX": 152,
"TD": 207,
"AZ": 18,
"AM": 9,
"BL": 0,
"SJ": 195,
"SB": 188,
"NF": 158,
"RS": 239,
"DE": 56,
"EH": 65,
"EE": 63,
"SD": 190,
"ML": 140,
"TC": 206,
"MZ": 154,
"BS": 32,
"UY": 226,
"SI": 194,
"AI": 7
"LV": 132,
"AD": 3,
"LT": 130,
"KM": 116,
"QA": 182,
"VA": 0,
"PK": 173,
"KI": 115,
"SS": 0,
"KH": 114,
"NZ": 166,
"TO": 215,
"KZ": 122,
"GA": 76,
"BW": 35,
"AX": 247,
"GE": 79,
"UA": 222,
"CR": 50,
"AE": 0,
"NE": 157,
"ZA": 240,
"SK": 196,
"BV": 34,
"SH": 0,
"PT": 179,
"SC": 189,
"CO": 49,
"GP": 86,
"GY": 93,
"CM": 47,
"TJ": 211,
"AF": 5,
"IE": 101,
"AL": 8,
"BG": 24,
"JO": 110,
"MU": 149,
"PM": 0,
"LA": 0,
"IO": 104,
"KY": 121,
"SA": 187,
"KN": 0,
"OM": 167,
"CY": 54,
"BQ": 0,
"BT": 33,
"WS": 236,
"ES": 67,
"LR": 128,
"RW": 186,
"AQ": 12,
"PW": 180,
"JE": 250,
"TN": 214,
"ZW": 243,
"JP": 111,
"BB": 20,
"VN": 233,
"HN": 96,
"KP": 0,
"WF": 235,
"EC": 62,
"HU": 99,
"GF": 80,
"GQ": 87,
"TW": 220,
"MC": 135,
"BE": 22,
"PN": 176,
"SZ": 205,
"CZ": 55,
"LY": 0,
"IN": 103,
"FM": 0,
"PY": 181,
"PH": 172,
"MN": 142,
"GG": 248,
"CC": 39,
"ME": 242,
"DO": 60,
"KR": 0,
"PL": 174,
"MT": 148,
"MM": 141,
"AW": 17,
"MV": 150,
"BD": 21,
"NR": 164,
"AT": 15,
"GW": 92,
"FR": 74,
"LI": 126,
"CF": 41,
"DZ": 61,
"MA": 134,
"VG": 0,
"NC": 156,
"IQ": 105,
"BN": 0,
"BF": 23,
"BO": 30,
"GB": 77,
"CU": 51,
"LU": 131,
"YT": 238,
"NO": 162,
"SM": 198,
"GL": 83,
"IS": 107,
"AO": 11,
"MH": 138,
"SE": 191,
"ZM": 241,
"FJ": 70,
"SL": 197,
"CH": 43,
"RU": 0,
"CW": 0,
"CX": 53,
"TF": 208,
"NL": 161,
"AU": 16,
"FI": 69,
"MS": 147,
"GH": 81,
"BY": 36,
"IL": 102,
"VC": 0,
"NG": 159,
"HT": 98,
"LS": 129,
"MR": 146,
"YE": 237,
"MP": 144,
"SX": 0,
"RE": 183,
"RO": 184,
"NP": 163,
"CG": 0,
"FO": 73,
"CI": 0,
"TH": 210,
"HK": 94,
"TK": 212,
"XK": 0,
"DM": 59,
"LC": 0,
"ID": 100,
"MG": 137,
"JM": 109,
"IT": 108,
"CA": 38,
"TZ": 221,
"GI": 82,
"KG": 113,
"NU": 165,
"TV": 219,
"LB": 124,
"SY": 0,
"PR": 177,
"NI": 160,
"KE": 112,
"MO": 0,
"SR": 201,
"VI": 0,
"SV": 203,
"HM": 0,
"CD": 0,
"BI": 26,
"BM": 28,
"MW": 151,
"TM": 213,
"GT": 90,
"AG": 0,
"UM": 0,
"US": 225,
"AR": 13,
"DJ": 57,
"KW": 120,
"MY": 153,
"FK": 71,
"EG": 64,
"BA": 0,
"CN": 48,
"GN": 85,
"PS": 178,
"SO": 200,
"IM": 249,
"GS": 0,
"BR": 31,
"GM": 84,
"PF": 170,
"PA": 168,
"PG": 171,
"BH": 25,
"TG": 209,
"GU": 91,
"CK": 45,
"MF": 252,
"VE": 230,
"CL": 46,
"TR": 217,
"UG": 223,
"GD": 78,
"TT": 218,
"TL": 0,
"MD": 0,
"MK": 0,
"ST": 202,
"CV": 52,
"MQ": 145,
"GR": 88,
"HR": 97,
"BZ": 37,
"UZ": 227,
"DK": 58,
"SN": 199,
"ET": 68,
"VU": 234,
"ER": 66,
"BJ": 27,
"LK": 127,
"NA": 155,
"AS": 14,
"SG": 192,
"PE": 169,
"IR": 0,
"MX": 152,
"TD": 207,
"AZ": 18,
"AM": 9,
"BL": 0,
"SJ": 195,
"SB": 188,
"NF": 158,
"RS": 239,
"DE": 56,
"EH": 65,
"EE": 63,
"SD": 190,
"ML": 140,
"TC": 206,
"MZ": 154,
"BS": 32,
"UY": 226,
"SI": 194,
"AI": 7
}
const countryCodeKeys = Object.keys(countryCodes);
module.exports = {
getCountryID:function(code = "") {
// Get id of a country from a 2 char code
code = code.toUpperCase();
if (countryCodes[code] != null) return countryCodes[code];
else return 0;
},
getCountryID:function(code = "") {
// Get id of a country from a 2 char code
code = code.toUpperCase();
if (countryCodes[code] != null) return countryCodes[code];
else return 0;
},
getCountryLetters:function(code) {
// Get country char code from id
for (var i = 0; i < countryCodes.length; i++) {
const countryId = countryCodes[countryCodeKeys[i]];
if (countryId === code) return countryId;
}
return "XX";
}
getCountryLetters:function(code) {
// Get country char code from id
for (var i = 0; i < countryCodes.length; i++) {
const countryId = countryCodes[countryCodeKeys[i]];
if (countryId === code) return countryId;
}
return "XX";
}
}
module.exports.countryCodes = countryCodes;

View file

@ -1,158 +1,160 @@
const osu = require("osu-packet"),
User = require("./User.js"),
uuid = require("./util/shortUUID.js"),
ahttp = require("./util/AsyncHttpRequest.js"),
RequestType = require("./util/RequestType.json"),
getUserByUsername = require("./util/getUserByUsername.js"),
getUserByToken = require("./util/getUserByToken.js"),
countryHelper = require("./countryHelper.js"),
loginHelper = require("./loginHelper.js"),
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"),
StatusUpdate = require("./Packets/StatusUpdate.js");
User = require("./User.js"),
uuid = require("./util/shortUUID.js"),
ahttp = require("./util/AsyncHttpRequest.js"),
RequestType = require("./util/RequestType.json"),
consoleHelper = require("../consoleHelper.js"),
// Packets
getUserByUsername = require("./util/getUserByUsername.js"),
getUserByToken = require("./util/getUserByToken.js"),
countryHelper = require("./countryHelper.js"),
loginHelper = require("./loginHelper.js"),
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"),
StatusUpdate = require("./Packets/StatusUpdate.js");
module.exports = async function(req, res, loginInfo) {
// Get time at the start of login
const loginStartTime = new Date().getTime(),
isTourneyClient = loginInfo.osuversion.includes("tourney");
// Get time at the start of login
const loginStartTime = Date.now(),
isTourneyClient = loginInfo.osuversion.includes("tourney");
// Check login
const loginCheck = await loginHelper.checkLogin(loginInfo);
if (loginCheck != null) {
res.writeHead(200, loginCheck[1]);
return res.end(loginCheck[0]);
}
// Check login
const loginCheck = await loginHelper.checkLogin(loginInfo);
if (loginCheck != null) {
res.writeHead(200, loginCheck[1]);
return res.end(loginCheck[0]);
}
// Get users IP for getting location
// Get cloudflare requestee IP first
let requestIP = req.get("cf-connecting-ip");
// Get users IP for getting location
// Get cloudflare requestee IP first
let requestIP = req.get("cf-connecting-ip");
// Get IP of requestee since we are probably behind a reverse proxy
if (requestIP == null)
requestIP = req.get("X-Real-IP");
// Get IP of requestee since we are probably behind a reverse proxy
if (requestIP == null)
requestIP = req.get("X-Real-IP");
// Just get the requestee IP (we are not behind a reverse proxy)
if (requestIP == null)
requestIP = req.remote_addr;
// Just get the requestee IP (we are not behind a reverse proxy)
if (requestIP == null)
requestIP = req.remote_addr;
// Make sure requestIP is never null
if (requestIP == null)
requestIP = "";
// Make sure requestIP is never null
if (requestIP == null)
requestIP = "";
let userLocationData = [], userLocation;
// Check if it is a local or null IP
if (requestIP.includes("192.168.") || requestIP.includes("127.0.") || requestIP == "") {
// Set location to null island
userLocationData.country = "XX";
userLocation = [0, 0];
} else {
// Get user's location using zxq
userLocationData = await ahttp(`http://ip.zxq.co/${requestIP}`, RequestType.JSON);
userLocation = userLocationData.loc.split(",");
}
let userLocationData = [], userLocation;
// Check if it is a local or null IP
if (requestIP.includes("192.168.") || requestIP.includes("127.0.") || requestIP == "") {
// Set location to null island
userLocationData.country = "XX";
userLocation = [0, 0];
} else {
// Get user's location using zxq
userLocationData = await ahttp(`http://ip.zxq.co/${requestIP}`, RequestType.JSON);
userLocation = userLocationData.loc.split(",");
}
// Get information about the user from the database
const userDB = await global.DatabaseHelper.query(`SELECT id FROM users_info WHERE username = "${loginInfo.username}" LIMIT 1`);
// Get information about the user from the database
const userDB = await global.DatabaseHelper.query(`SELECT id FROM users_info WHERE username = "${loginInfo.username}" LIMIT 1`);
// Create a token for the client
const newClientToken = uuid();
// Create a token for the client
const newClientToken = uuid();
// Make sure user is not already connected, kick off if so.
const checkForPreexistingUser = getUserByUsername(loginInfo.username);
if (checkForPreexistingUser != null && !isTourneyClient) {
for (let i = 0; i < global.userKeys.length; i++) {
const user = global.users[global.userKeys[i]];
// Make sure they are not a tourney user
if (!user.isTourneyUser && user.uuid != newClientToken) {
global.removeUser(user);
}
}
}
// Make sure user is not already connected, kick off if so.
const checkForPreexistingUser = getUserByUsername(loginInfo.username);
if (checkForPreexistingUser != null && !isTourneyClient) {
for (let i = 0; i < global.userKeys.length; i++) {
const user = global.users[global.userKeys[i]];
// Make sure they are not a tourney user
if (!user.isTourneyUser && user.uuid != newClientToken) {
global.removeUser(user);
}
}
}
// Create user object
global.addUser(newClientToken, new User(userDB.id, loginInfo.username, newClientToken, new Date().getTime(), isTourneyClient));
// Create user object
global.addUser(newClientToken, new User(userDB.id, loginInfo.username, newClientToken, Date.now(), isTourneyClient));
// Retreive the newly created user
const NewUser = getUserByToken(newClientToken);
// Retreive the newly created user
const NewUser = getUserByToken(newClientToken);
// Get user's data from the database
NewUser.getNewUserInformationFromDatabase();
// Get user's data from the database
NewUser.getNewUserInformationFromDatabase();
try {
// Save the user's location to their class for later use
NewUser.location[0] = parseFloat(userLocation[0]);
NewUser.location[1] = parseFloat(userLocation[1]);
try {
// Save the user's location to their class for later use
NewUser.location[0] = parseFloat(userLocation[0]);
NewUser.location[1] = parseFloat(userLocation[1]);
// Save the country id for the same reason as above
NewUser.countryID = countryHelper.getCountryID(userLocationData.country);
// Save the country id for the same reason as above
NewUser.countryID = countryHelper.getCountryID(userLocationData.country);
// We're ready to start putting together a login packet
// Create an osu! Packet writer
let osuPacketWriter = new osu.Bancho.Writer;
// We're ready to start putting together a login packet
// Create an osu! Packet writer
let osuPacketWriter = new osu.Bancho.Writer;
// The reply id is the user's id in any other case than an error in which case negative numbers are used
osuPacketWriter.LoginReply(NewUser.id);
// Current bancho protocol version. Defined in Binato.js
osuPacketWriter.ProtocolNegotiation(global.protocolVersion);
// Permission level 4 is osu!supporter
osuPacketWriter.LoginPermissions(4);
// The reply id is the user's id in any other case than an error in which case negative numbers are used
osuPacketWriter.LoginReply(NewUser.id);
// Current bancho protocol version. Defined in Binato.js
osuPacketWriter.ProtocolNegotiation(global.protocolVersion);
// Permission level 4 is osu!supporter
osuPacketWriter.LoginPermissions(4);
// After sending the user their friends list send them the online users
UserPresenceBundle(NewUser);
// After sending the user their friends list send them the online users
UserPresenceBundle(NewUser);
// Set title screen image
//osuPacketWriter.TitleUpdate("http://puu.sh/jh7t7/20c04029ad.png|https://osu.ppy.sh/news/123912240253");
// Set title screen image
//osuPacketWriter.TitleUpdate("http://puu.sh/jh7t7/20c04029ad.png|https://osu.ppy.sh/news/123912240253");
// Add user panel data packets
UserPresence(NewUser, NewUser.id);
StatusUpdate(NewUser, NewUser.id);
// Add user panel data packets
UserPresence(NewUser, NewUser.id);
StatusUpdate(NewUser, NewUser.id);
// peppy pls, why
osuPacketWriter.ChannelListingComplete();
// peppy pls, why
osuPacketWriter.ChannelListingComplete();
// Add user to chat channels
osuPacketWriter.ChannelJoinSuccess("#osu");
if (!global.StreamsHandler.isUserInStream("#osu", NewUser.uuid))
global.StreamsHandler.addUserToStream("#osu", NewUser.uuid);
// Add user to chat channels
osuPacketWriter.ChannelJoinSuccess("#osu");
if (!global.StreamsHandler.isUserInStream("#osu", NewUser.uuid))
global.StreamsHandler.addUserToStream("#osu", NewUser.uuid);
osuPacketWriter.ChannelJoinSuccess("#userlog");
if (!global.StreamsHandler.isUserInStream("#userlog", NewUser.uuid))
global.StreamsHandler.addUserToStream("#userlog", NewUser.uuid);
osuPacketWriter.ChannelJoinSuccess("#userlog");
if (!global.StreamsHandler.isUserInStream("#userlog", NewUser.uuid))
global.StreamsHandler.addUserToStream("#userlog", NewUser.uuid);
// List all channels out to the client
for (let i = 0; i < global.channels.length; i++) {
osuPacketWriter.ChannelAvailable({
channelName: global.channels[i].channelName,
channelTopic: global.channels[i].channelTopic,
channelUserCount: global.channels[i].channelUserCount
});
}
// List all channels out to the client
for (let i = 0; i < global.channels.length; i++) {
osuPacketWriter.ChannelAvailable({
channelName: global.channels[i].channelName,
channelTopic: global.channels[i].channelTopic,
channelUserCount: global.channels[i].channelUserCount
});
}
// Construct user's friends list
const userFriends = await global.DatabaseHelper.query(`SELECT friendsWith FROM friends WHERE user = ${NewUser.id}`);
let friendsArray = [];
for (let i = 0; i < userFriends.length; i++) {
friendsArray.push(userFriends[i].friendsWith);
}
// Send user's friends list
osuPacketWriter.FriendsList(friendsArray);
// Construct user's friends list
const userFriends = await global.DatabaseHelper.query(`SELECT friendsWith FROM friends WHERE user = ${NewUser.id}`);
let friendsArray = [];
for (let i = 0; i < userFriends.length; i++) {
friendsArray.push(userFriends[i].friendsWith);
}
// Send user's friends list
osuPacketWriter.FriendsList(friendsArray);
osuPacketWriter.Announce(`Welcome back ${loginInfo.username}!`);
osuPacketWriter.Announce(`Welcome back ${loginInfo.username}!`);
// Complete login
res.writeHead(200, {
"cho-token": NewUser.uuid,
"cho-protocol": global.protocolVersion,
"Connection": "keep-alive",
"Keep-Alive": "timeout=5, max=100",
"Content-Type": "text/html; charset=UTF-8"
});
res.end(osuPacketWriter.toBuffer, () => {
global.consoleHelper.printBancho(`User login finished, took ${new Date().getTime() - loginStartTime}ms. [User: ${loginInfo.username}]`);
});
} catch (err) {
console.error(err);
}
// Complete login
res.writeHead(200, {
"cho-token": NewUser.uuid,
"cho-protocol": global.protocolVersion,
"Connection": "keep-alive",
"Keep-Alive": "timeout=5, max=100",
"Content-Type": "text/html; charset=UTF-8"
});
res.end(osuPacketWriter.toBuffer, () => {
consoleHelper.printBancho(`User login finished, took ${Date.now() - loginStartTime}ms. [User: ${loginInfo.username}]`);
});
} catch (err) {
console.error(err);
}
}

View file

@ -1,59 +1,59 @@
const osu = require("osu-packet"),
aes256 = require("aes256"),
config = require("../config.json");
aes256 = require("aes256"),
config = require("../config.json");
module.exports = {
checkLogin:async function(loginInfo) {
// Check if there is any login information provided
if (loginInfo == null) return incorrectLoginResponse();
checkLogin:async function(loginInfo) {
// Check if there is any login information provided
if (loginInfo == null) return incorrectLoginResponse();
const userDBData = await global.DatabaseHelper.query(`SELECT * FROM users_info WHERE username = "${loginInfo.username}" LIMIT 1`);
const userDBData = await global.DatabaseHelper.query(`SELECT * FROM users_info WHERE username = "${loginInfo.username}" LIMIT 1`);
// Make sure a user was found in the database
if (Object.keys(userDBData).length < 1) return incorrectLoginResponse();
// Make sure the username is the same as the login info
if (userDBData.username !== loginInfo.username) return incorrectLoginResponse();
// If the user has an old md5 password
if (userDBData.has_old_password == 1) {
// Make sure the password is the same as the login info
if (userDBData.password !== loginInfo.password) return incorrectLoginResponse();
return requiredPWChangeResponse();
} else {
if (aes256.decrypt(config.databaseKey, userDBData.password) !== loginInfo.password) return incorrectLoginResponse();
}
// Make sure a user was found in the database
if (Object.keys(userDBData).length < 1) return incorrectLoginResponse();
// Make sure the username is the same as the login info
if (userDBData.username !== loginInfo.username) return incorrectLoginResponse();
// If the user has an old md5 password
if (userDBData.has_old_password == 1) {
// Make sure the password is the same as the login info
if (userDBData.password !== loginInfo.password) return incorrectLoginResponse();
return requiredPWChangeResponse();
} else {
if (aes256.decrypt(config.databaseKey, userDBData.password) !== loginInfo.password) return incorrectLoginResponse();
}
return null;
}
return null;
}
}
function incorrectLoginResponse() {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.LoginReply(-1);
return [
osuPacketWriter.toBuffer,
{
'cho-token': 'No',
'cho-protocol': global.protocolVersion,
'Connection': 'keep-alive',
'Keep-Alive': 'timeout=5, max=100',
'Content-Type': 'text/html; charset=UTF-8'
}
];
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.LoginReply(-1);
return [
osuPacketWriter.toBuffer,
{
'cho-token': 'No',
'cho-protocol': global.protocolVersion,
'Connection': 'keep-alive',
'Keep-Alive': 'timeout=5, max=100',
'Content-Type': 'text/html; charset=UTF-8'
}
];
}
function requiredPWChangeResponse() {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.Announce("As part of migration to a new password system you are required to change your password. Please login on the website and change your password.");
osuPacketWriter.LoginReply(-1);
return [
osuPacketWriter.toBuffer,
{
'cho-token': 'No',
'cho-protocol': global.protocolVersion,
'Connection': 'keep-alive',
'Keep-Alive': 'timeout=5, max=100',
'Content-Type': 'text/html; charset=UTF-8'
}
];
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.Announce("As part of migration to a new password system you are required to change your password. Please login on the website and change your password.");
osuPacketWriter.LoginReply(-1);
return [
osuPacketWriter.toBuffer,
{
'cho-token': 'No',
'cho-protocol': global.protocolVersion,
'Connection': 'keep-alive',
'Keep-Alive': 'timeout=5, max=100',
'Content-Type': 'text/html; charset=UTF-8'
}
];
}

View file

@ -1,111 +1,111 @@
module.exports = {
"client_changeAction":0,
"client_sendPublicMessage":1,
"client_logout":2,
"client_requestStatusUpdate":3,
"client_pong":4,
"server_userID":5,
"server_commandError":6,
"server_sendMessage":7,
"server_ping":8,
"server_handleIRCUsernameChange":9,
"server_handleIRCQuit":10,
"server_userStats":11,
"server_userLogout":12,
"server_spectatorJoined":13,
"server_spectatorLeft":14,
"server_spectateFrames":15,
"client_startSpectating":16,
"client_stopSpectating":17,
"client_spectateFrames":18,
"server_versionUpdate":19,
"client_errorReport":20,
"client_cantSpectate":21,
"server_spectatorCantSpectate":22,
"server_getAttention":23,
"server_notification":24,
"client_sendPrivateMessage":25,
"server_updateMatch":26,
"server_newMatch":27,
"server_disposeMatch":28,
"client_partLobby":29,
"client_joinLobby":30,
"client_createMatch":31,
"client_joinMatch":32,
"client_partMatch":33,
"server_lobbyJoin_obsolete":34,
"server_lobbyPart_obsolete":35,
"server_matchJoinSuccess":36,
"server_matchJoinFail":37,
"client_matchChangeSlot":38,
"client_matchReady":39,
"client_matchLock":40,
"client_matchChangeSettings":41,
"server_fellowSpectatorJoined":42,
"server_fellowSpectatorLeft":43,
"client_matchStart":44,
"AllPlayersLoaded":45,
"server_matchStart":46,
"client_matchScoreUpdate":47,
"server_matchScoreUpdate":48,
"client_matchComplete":49,
"server_matchTransferHost":50,
"client_matchChangeMods":51,
"client_matchLoadComplete":52,
"server_matchAllPlayersLoaded":53,
"client_matchNoBeatmap":54,
"client_matchNotReady":55,
"client_matchFailed":56,
"server_matchComplete":58,
"client_matchHasBeatmap":59,
"client_matchSkipRequest":60,
"server_matchSkip":61,
"server_unauthorised":62,
"client_channelJoin":63,
"server_channelJoinSuccess":64,
"server_channelInfo":65,
"server_channelKicked":66,
"server_channelAvailableAutojoin":67,
"client_beatmapInfoRequest":68,
"server_beatmapInfoReply":69,
"client_matchTransferHost":70,
"server_supporterGMT":71,
"server_friendsList":72,
"client_friendAdd":73,
"client_friendRemove":74,
"server_protocolVersion":75,
"server_mainMenuIcon":76,
"client_matchChangeTeam":77,
"client_channelPart":78,
"client_receiveUpdates":79,
"server_topBotnet":80,
"server_matchPlayerSkipped":81,
"client_setAwayMessage":82,
"server_userPanel":83,
"IRC_only":84,
"client_userStatsRequest":85,
"server_restart":86,
"client_invite":87,
"server_invite":88,
"server_channelInfoEnd":89,
"client_matchChangePassword":90,
"server_matchChangePassword":91,
"server_silenceEnd":92,
"client_specialMatchInfoRequest":93,
"server_userSilenced":94,
"server_userPresenceSingle":95,
"server_userPresenceBundle":96,
"client_userPresenceRequest":97,
"client_userPresenceRequestAll":98,
"client_userToggleBlockNonFriendPM":99,
"server_userPMBlocked":100,
"server_targetIsSilenced":101,
"server_versionUpdateForced":102,
"server_switchServer":103,
"server_accountRestricted":104,
"server_jumpscare":105,
"client_matchAbort":106,
"server_switchTourneyServer":107,
"client_specialJoinMatchChannel":108,
"client_specialLeaveMatchChannel":109
"client_changeAction":0,
"client_sendPublicMessage":1,
"client_logout":2,
"client_requestStatusUpdate":3,
"client_pong":4,
"server_userID":5,
"server_commandError":6,
"server_sendMessage":7,
"server_ping":8,
"server_handleIRCUsernameChange":9,
"server_handleIRCQuit":10,
"server_userStats":11,
"server_userLogout":12,
"server_spectatorJoined":13,
"server_spectatorLeft":14,
"server_spectateFrames":15,
"client_startSpectating":16,
"client_stopSpectating":17,
"client_spectateFrames":18,
"server_versionUpdate":19,
"client_errorReport":20,
"client_cantSpectate":21,
"server_spectatorCantSpectate":22,
"server_getAttention":23,
"server_notification":24,
"client_sendPrivateMessage":25,
"server_updateMatch":26,
"server_newMatch":27,
"server_disposeMatch":28,
"client_partLobby":29,
"client_joinLobby":30,
"client_createMatch":31,
"client_joinMatch":32,
"client_partMatch":33,
"server_lobbyJoin_obsolete":34,
"server_lobbyPart_obsolete":35,
"server_matchJoinSuccess":36,
"server_matchJoinFail":37,
"client_matchChangeSlot":38,
"client_matchReady":39,
"client_matchLock":40,
"client_matchChangeSettings":41,
"server_fellowSpectatorJoined":42,
"server_fellowSpectatorLeft":43,
"client_matchStart":44,
"AllPlayersLoaded":45,
"server_matchStart":46,
"client_matchScoreUpdate":47,
"server_matchScoreUpdate":48,
"client_matchComplete":49,
"server_matchTransferHost":50,
"client_matchChangeMods":51,
"client_matchLoadComplete":52,
"server_matchAllPlayersLoaded":53,
"client_matchNoBeatmap":54,
"client_matchNotReady":55,
"client_matchFailed":56,
"server_matchComplete":58,
"client_matchHasBeatmap":59,
"client_matchSkipRequest":60,
"server_matchSkip":61,
"server_unauthorised":62,
"client_channelJoin":63,
"server_channelJoinSuccess":64,
"server_channelInfo":65,
"server_channelKicked":66,
"server_channelAvailableAutojoin":67,
"client_beatmapInfoRequest":68,
"server_beatmapInfoReply":69,
"client_matchTransferHost":70,
"server_supporterGMT":71,
"server_friendsList":72,
"client_friendAdd":73,
"client_friendRemove":74,
"server_protocolVersion":75,
"server_mainMenuIcon":76,
"client_matchChangeTeam":77,
"client_channelPart":78,
"client_receiveUpdates":79,
"server_topBotnet":80,
"server_matchPlayerSkipped":81,
"client_setAwayMessage":82,
"server_userPanel":83,
"IRC_only":84,
"client_userStatsRequest":85,
"server_restart":86,
"client_invite":87,
"server_invite":88,
"server_channelInfoEnd":89,
"client_matchChangePassword":90,
"server_matchChangePassword":91,
"server_silenceEnd":92,
"client_specialMatchInfoRequest":93,
"server_userSilenced":94,
"server_userPresenceSingle":95,
"server_userPresenceBundle":96,
"client_userPresenceRequest":97,
"client_userPresenceRequestAll":98,
"client_userToggleBlockNonFriendPM":99,
"server_userPMBlocked":100,
"server_targetIsSilenced":101,
"server_versionUpdateForced":102,
"server_switchServer":103,
"server_accountRestricted":104,
"server_jumpscare":105,
"client_matchAbort":106,
"server_switchTourneyServer":107,
"client_specialJoinMatchChannel":108,
"client_specialLeaveMatchChannel":109
}

View file

@ -1,34 +1,35 @@
const osu = require("osu-packet"),
fs = require("fs"),
packetIDs = require("./packetIDs.js"),
loginHandler = require("./loginHandler.js"),
parseUserData = require("./util/parseUserData.js"),
User = require("./User.js"),
getUserFromToken = require("./util/getUserByToken.js"),
bakedResponses = require("./bakedResponses.js"),
Streams = require("./Streams.js"),
DatabaseHelperClass = require("./DatabaseHelper.js"),
config = require("../config.json");
fs = require("fs"),
consoleHelper = require("../consoleHelper.js"),
packetIDs = require("./packetIDs.js"),
loginHandler = require("./loginHandler.js"),
parseUserData = require("./util/parseUserData.js"),
User = require("./User.js"),
getUserFromToken = require("./util/getUserByToken.js"),
bakedResponses = require("./bakedResponses.js"),
Streams = require("./Streams.js"),
DatabaseHelperClass = require("./DatabaseHelper.js"),
config = require("../config.json");
global.users = {};
global.userKeys = Object.keys(global.users);
global.addUser = function(uuid, userToAdd) {
global.users[uuid] = userToAdd;
global.refreshUserKeys();
global.users[uuid] = userToAdd;
global.refreshUserKeys();
}
global.removeUser = function(userToRemove) {
delete userToRemove;
global.refreshUserKeys();
delete userToRemove;
global.refreshUserKeys();
}
global.refreshUserKeys = function() {
global.userKeys = Object.keys(global.users);
global.userKeys = Object.keys(global.users);
}
// Add the bot user
global.addUser("bot", new User(3, "SillyBot", "bot", new Date().getTime()));
global.addUser("bot", new User(3, "SillyBot", "bot", Date.now()));
// Set the bot's position on the map
global.users["bot"].location[0] = 50;
global.users["bot"].location[1] = -32;
@ -40,25 +41,25 @@ global.DatabaseHelper = new DatabaseHelperClass(config.databaseAddress, config.d
// TODO: Some way of informing bancho that a user has set a score so details can be pulled down quickly
// Possible solution, TCP socket between the score submit server and bancho? redis? (score submit is on a different server, redis probably wouldn't work)
setInterval(() => {
for (let i = 0; i < global.userKeys.length; i++) {
const User = global.users[global.userKeys[i]];
if (User.id == 3) continue; // Ignore the bot
// Bot: :(
for (let i = 0; i < global.userKeys.length; i++) {
const User = global.users[global.userKeys[i]];
if (User.id == 3) continue; // Ignore the bot
// Bot: :(
User.getNewUserInformationFromDatabase();
}
User.getNewUserInformationFromDatabase();
}
}, 10000);
// An array containing the last 15 messages in chat
// TODO: Bother making this
global.chatHistory = [];
global.addChatMessage = function(msg) {
if (global.chatHistory.length == 15) {
global.chatHistory.splice(0, 1);
global.chatHistory.push(msg);
} else {
global.chatHistory.push(msg);
}
if (global.chatHistory.length == 15) {
global.chatHistory.splice(0, 1);
global.chatHistory.push(msg);
} else {
global.chatHistory.push(msg);
}
}
global.StreamsHandler = new Streams();
@ -66,16 +67,16 @@ global.StreamsHandler = new Streams();
// An array containing all chat channels
// TODO: Send user chat channels and not have osu! crash
global.channels = [
{ channelName:"#osu", channelTopic:"The main channel", channelUserCount: 0, locked: false },
{ channelName:"#userlog", channelTopic:"Log about stuff doing go on yes very", channelUserCount: 0, locked: false },
{ channelName:"#lobby", channelTopic:"Talk about multiplayer stuff", channelUserCount: 0, locked: false },
{ channelName:"#english", channelTopic:"Talk in exclusively English", channelUserCount: 0, locked: false },
{ channelName:"#japanese", channelTopic:"Talk in exclusively Japanese", channelUserCount: 0, locked: false },
{ channelName:"#osu", channelTopic:"The main channel", channelUserCount: 0, locked: false },
{ channelName:"#userlog", channelTopic:"Log about stuff doing go on yes very", channelUserCount: 0, locked: false },
{ channelName:"#lobby", channelTopic:"Talk about multiplayer stuff", channelUserCount: 0, locked: false },
{ channelName:"#english", channelTopic:"Talk in exclusively English", channelUserCount: 0, locked: false },
{ channelName:"#japanese", channelTopic:"Talk in exclusively Japanese", channelUserCount: 0, locked: false },
];
// Create a stream for each chat channel
for (let i = 0; i < global.channels.length; i++) {
global.StreamsHandler.addStream(global.channels[i].channelName, false);
global.StreamsHandler.addStream(global.channels[i].channelName, false);
}
// Add a stream for the multiplayer lobby
@ -92,44 +93,44 @@ global.httpRequestsPerLogInterval = 0;
const logInterval = 10; // Secs
setInterval(() => {
global.usersOnline = (global.userKeys.length - 1);
global.multiplayerMatches = [global.MultiplayerManager.matches.length, 0]; // TODO: Respect private matches
global.usersOnline = (global.userKeys.length - 1);
global.multiplayerMatches = [global.MultiplayerManager.matches.length, 0]; // TODO: Respect private matches
fs.appendFile(
"server-stats.log",
`${global.usersOnline}|${global.multiplayerMatches[0]},${global.multiplayerMatches[1]}|${global.httpRequestsPerLogInterval}|${new Date().getTime()}@`,
() => {}
);
fs.appendFile(
"server-stats.log",
`${global.usersOnline}|${global.multiplayerMatches[0]},${global.multiplayerMatches[1]}|${global.httpRequestsPerLogInterval}|${Date.now()}@`,
() => {}
);
global.httpRequestsPerLogInterval = 0;
global.httpRequestsPerLogInterval = 0;
}, logInterval * 1000);
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}`, () => {});
return global.totalHistoricalMultiplayerMatches;
global.totalHistoricalMultiplayerMatches++;
fs.writeFile("tHMM.ds", `${global.totalHistoricalMultiplayerMatches}`, () => {});
return global.totalHistoricalMultiplayerMatches;
}
// Include packets
const ChangeAction = require("./Packets/ChangeAction.js"),
SendPublicMessage = require("./Packets/SendPublicMessage.js"),
Logout = require("./Packets/Logout.js"),
Spectator = require("./Spectator.js"),
SendPrivateMessage = require("./Packets/SendPrivateMessage.js"),
MultiplayerManager = require("./MultiplayerManager.js"),
ChannelJoin = require("./Packets/ChannelJoin.js"),
ChannelPart = require("./Packets/ChannelPart.js"),
AddFriend = require("./Packets/AddFriend.js"),
RemoveFriend = require("./Packets/RemoveFriend.js"),
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"),
UserStatsRequest = require("./Packets/UserStatsRequest.js"),
MultiplayerInvite = require("./Packets/MultiplayerInvite.js"),
TourneyMatchSpecialInfo = require("./Packets/TourneyMatchSpecialInfo.js"),
TourneyMatchJoinChannel = require("./Packets/TourneyMatchSpecialInfo.js"),
TourneyMatchLeaveChannel = require("./Packets/TourneyLeaveMatchChannel.js");
SendPublicMessage = require("./Packets/SendPublicMessage.js"),
Logout = require("./Packets/Logout.js"),
Spectator = require("./Spectator.js"),
SendPrivateMessage = require("./Packets/SendPrivateMessage.js"),
MultiplayerManager = require("./MultiplayerManager.js"),
ChannelJoin = require("./Packets/ChannelJoin.js"),
ChannelPart = require("./Packets/ChannelPart.js"),
AddFriend = require("./Packets/AddFriend.js"),
RemoveFriend = require("./Packets/RemoveFriend.js"),
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"),
UserStatsRequest = require("./Packets/UserStatsRequest.js"),
MultiplayerInvite = require("./Packets/MultiplayerInvite.js"),
TourneyMatchSpecialInfo = require("./Packets/TourneyMatchSpecialInfo.js"),
TourneyMatchJoinChannel = require("./Packets/TourneyMatchSpecialInfo.js"),
TourneyMatchLeaveChannel = require("./Packets/TourneyLeaveMatchChannel.js");
const emptyBuffer = Buffer.alloc(0);
@ -137,231 +138,231 @@ const emptyBuffer = Buffer.alloc(0);
global.MultiplayerManager = new MultiplayerManager();
module.exports = async function(req, res) {
// Add to requests for logging
global.httpRequestsPerLogInterval++;
// Add to requests for logging
global.httpRequestsPerLogInterval++;
// Get the client's token string and request data
const requestTokenString = req.header("osu-token"),
requestData = req.packet;
// Server's response & new client token
let responseData = emptyBuffer;
// Get the client's token string and request data
const requestTokenString = req.header("osu-token"),
requestData = req.packet;
// Server's response & new client token
let responseData = emptyBuffer;
// Check if the user is logged in
if (requestTokenString == null) {
// Client doesn't have a token yet, let's auth them!
const userData = parseUserData(requestData);
global.consoleHelper.printBancho(`New client connection. [User: ${userData.username}]`);
await loginHandler(req, res, userData);
} else {
// Client has a token, let's see what they want.
try {
// Get the current user
const PacketUser = getUserFromToken(requestTokenString);
// Check if the user is logged in
if (requestTokenString == null) {
// Client doesn't have a token yet, let's auth them!
const userData = parseUserData(requestData);
consoleHelper.printBancho(`New client connection. [User: ${userData.username}]`);
await loginHandler(req, res, userData);
} else {
// Client has a token, let's see what they want.
try {
// Get the current user
const PacketUser = getUserFromToken(requestTokenString);
// Make sure the client's token isn't invalid
if (PacketUser != null) {
// Create a new osu! packet reader
const osuPacketReader = new osu.Client.Reader(requestData);
// Parse current bancho packet
const PacketData = osuPacketReader.Parse();
// Loop through parsed packet data
for (let i = 0; i < PacketData.length; i++) {
// Get current packet
let CurrentPacket = PacketData[i];
// Make sure the client's token isn't invalid
if (PacketUser != null) {
// Create a new osu! packet reader
const osuPacketReader = new osu.Client.Reader(requestData);
// Parse current bancho packet
const PacketData = osuPacketReader.Parse();
// Loop through parsed packet data
for (let i = 0; i < PacketData.length; i++) {
// Get current packet
let CurrentPacket = PacketData[i];
// This is getting a little big, swap this out for mapped functions?
// Would require some standardisation
switch (CurrentPacket.id) {
case packetIDs.client_changeAction:
ChangeAction(PacketUser, CurrentPacket.data);
break;
// This is getting a little big, swap this out for mapped functions?
// Would require some standardisation
switch (CurrentPacket.id) {
case packetIDs.client_changeAction:
ChangeAction(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_sendPublicMessage:
SendPublicMessage(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_sendPublicMessage:
SendPublicMessage(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_logout:
Logout(PacketUser);
break;
case packetIDs.client_logout:
Logout(PacketUser);
break;
case packetIDs.client_requestStatusUpdate:
UserPresenceBundle(PacketUser);
break;
case packetIDs.client_requestStatusUpdate:
UserPresenceBundle(PacketUser);
break;
case packetIDs.client_pong: // Pretty sure this is just a client ping
// so we probably don't do anything here
break; // It's probably just the client wanting to pull data down.
case packetIDs.client_pong: // Pretty sure this is just a client ping
// so we probably don't do anything here
break; // It's probably just the client wanting to pull data down.
case packetIDs.client_startSpectating:
Spectator.startSpectatingUser(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_startSpectating:
Spectator.startSpectatingUser(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_spectateFrames:
Spectator.sendSpectatorFrames(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_spectateFrames:
Spectator.sendSpectatorFrames(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_stopSpectating:
Spectator.stopSpectatingUser(PacketUser);
break;
case packetIDs.client_stopSpectating:
Spectator.stopSpectatingUser(PacketUser);
break;
case packetIDs.client_sendPrivateMessage:
SendPrivateMessage(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_sendPrivateMessage:
SendPrivateMessage(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_joinLobby:
global.MultiplayerManager.userEnterLobby(PacketUser);
break;
case packetIDs.client_joinLobby:
global.MultiplayerManager.userEnterLobby(PacketUser);
break;
case packetIDs.client_partLobby:
global.MultiplayerManager.userLeaveLobby(PacketUser);
break;
case packetIDs.client_partLobby:
global.MultiplayerManager.userLeaveLobby(PacketUser);
break;
case packetIDs.client_createMatch:
global.MultiplayerManager.createMultiplayerMatch(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_createMatch:
global.MultiplayerManager.createMultiplayerMatch(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_joinMatch:
global.MultiplayerManager.joinMultiplayerMatch(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_joinMatch:
global.MultiplayerManager.joinMultiplayerMatch(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchChangeSlot:
PacketUser.currentMatch.moveToSlot(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchChangeSlot:
PacketUser.currentMatch.moveToSlot(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchReady:
PacketUser.currentMatch.setStateReady(PacketUser);
break;
case packetIDs.client_matchReady:
PacketUser.currentMatch.setStateReady(PacketUser);
break;
case packetIDs.client_matchChangeSettings:
PacketUser.currentMatch.updateMatch(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchChangeSettings:
PacketUser.currentMatch.updateMatch(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchNotReady:
PacketUser.currentMatch.setStateNotReady(PacketUser);
break;
case packetIDs.client_matchNotReady:
PacketUser.currentMatch.setStateNotReady(PacketUser);
break;
case packetIDs.client_partMatch:
global.MultiplayerManager.leaveMultiplayerMatch(PacketUser);
break;
case packetIDs.client_partMatch:
global.MultiplayerManager.leaveMultiplayerMatch(PacketUser);
break;
// Also handles user kick if the slot has a user
case packetIDs.client_matchLock:
PacketUser.currentMatch.lockMatchSlot(PacketUser, CurrentPacket.data);
break;
// Also handles user kick if the slot has a user
case packetIDs.client_matchLock:
PacketUser.currentMatch.lockMatchSlot(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchNoBeatmap:
PacketUser.currentMatch.missingBeatmap(PacketUser);
break;
case packetIDs.client_matchNoBeatmap:
PacketUser.currentMatch.missingBeatmap(PacketUser);
break;
case packetIDs.client_matchSkipRequest:
PacketUser.currentMatch.matchSkip(PacketUser);
break;
case packetIDs.client_matchHasBeatmap:
PacketUser.currentMatch.notMissingBeatmap(PacketUser);
break;
case packetIDs.client_matchSkipRequest:
PacketUser.currentMatch.matchSkip(PacketUser);
break;
case packetIDs.client_matchHasBeatmap:
PacketUser.currentMatch.notMissingBeatmap(PacketUser);
break;
case packetIDs.client_matchTransferHost:
PacketUser.currentMatch.transferHost(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchTransferHost:
PacketUser.currentMatch.transferHost(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchChangeMods:
PacketUser.currentMatch.updateMods(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchChangeMods:
PacketUser.currentMatch.updateMods(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchStart:
PacketUser.currentMatch.startMatch();
break;
case packetIDs.client_matchStart:
PacketUser.currentMatch.startMatch();
break;
case packetIDs.client_matchLoadComplete:
PacketUser.currentMatch.matchPlayerLoaded(PacketUser);
break;
case packetIDs.client_matchLoadComplete:
PacketUser.currentMatch.matchPlayerLoaded(PacketUser);
break;
case packetIDs.client_matchComplete:
PacketUser.currentMatch.onPlayerFinishMatch(PacketUser);
break;
case packetIDs.client_matchComplete:
PacketUser.currentMatch.onPlayerFinishMatch(PacketUser);
break;
case packetIDs.client_matchScoreUpdate:
PacketUser.currentMatch.updatePlayerScore(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchScoreUpdate:
PacketUser.currentMatch.updatePlayerScore(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_matchFailed:
PacketUser.currentMatch.matchFailed(PacketUser);
break;
case packetIDs.client_matchFailed:
PacketUser.currentMatch.matchFailed(PacketUser);
break;
case packetIDs.client_matchChangeTeam:
PacketUser.currentMatch.changeTeam(PacketUser);
break;
case packetIDs.client_matchChangeTeam:
PacketUser.currentMatch.changeTeam(PacketUser);
break;
case packetIDs.client_channelJoin:
ChannelJoin(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_channelJoin:
ChannelJoin(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_channelPart:
ChannelPart(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_channelPart:
ChannelPart(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_friendAdd:
AddFriend(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_friendAdd:
AddFriend(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_friendRemove:
RemoveFriend(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_friendRemove:
RemoveFriend(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_userStatsRequest:
UserStatsRequest(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_userStatsRequest:
UserStatsRequest(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_specialMatchInfoRequest:
TourneyMatchSpecialInfo(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_specialMatchInfoRequest:
TourneyMatchSpecialInfo(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_specialJoinMatchChannel:
TourneyMatchJoinChannel(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_specialJoinMatchChannel:
TourneyMatchJoinChannel(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_specialLeaveMatchChannel:
TourneyMatchLeaveChannel(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_specialLeaveMatchChannel:
TourneyMatchLeaveChannel(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_invite:
MultiplayerInvite(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_invite:
MultiplayerInvite(PacketUser, CurrentPacket.data);
break;
case packetIDs.client_userPresenceRequest:
UserPresence(PacketUser, PacketUser.id); // Can't really think of a way to generalize this?
break;
case packetIDs.client_userPresenceRequest:
UserPresence(PacketUser, PacketUser.id); // Can't really think of a way to generalize this?
break;
default:
// Ignore client_beatmapInfoRequest and client_receiveUpdates
if (CurrentPacket.id == 68 || CurrentPacket.id == 79) break;
// Print out unimplemented packet
console.dir(CurrentPacket);
break;
}
default:
// Ignore client_beatmapInfoRequest and client_receiveUpdates
if (CurrentPacket.id == 68 || CurrentPacket.id == 79) break;
// Print out unimplemented packet
console.dir(CurrentPacket);
break;
}
// Concat current user queue into response data
responseData = Buffer.concat([responseData, PacketUser.queue], responseData.length + PacketUser.queue.length);
PacketUser.clearQueue();
}
} else {
// User's token is invlid, force a reconnect
global.consoleHelper.printBancho(`Forced client re-login (Token is invalid)`);
responseData = bakedResponses("reconnect");
}
} catch (e) {
console.error(e);
} finally {
// Send the prepared packet to the client
res.writeHead(200, {
"cho-protocol": global.protocolVersion,
"Connection": "keep-alive",
"Keep-Alive": "timeout=5, max=100",
"Content-Type": "text/html; charset=UTF-8"
});
res.end(responseData);
}
}
// Concat current user queue into response data
responseData = Buffer.concat([responseData, PacketUser.queue], responseData.length + PacketUser.queue.length);
PacketUser.clearQueue();
}
} else {
// User's token is invlid, force a reconnect
consoleHelper.printBancho(`Forced client re-login (Token is invalid)`);
responseData = bakedResponses("reconnect");
}
} catch (e) {
console.error(e);
} finally {
// Send the prepared packet to the client
res.writeHead(200, {
"cho-protocol": global.protocolVersion,
"Connection": "keep-alive",
"Keep-Alive": "timeout=5, max=100",
"Content-Type": "text/html; charset=UTF-8"
});
res.end(responseData);
}
}
};

View file

@ -1,16 +1,16 @@
const request = require("request"), RequestType = require("./RequestType.json");
const functionMap = {
0: (resolve, body) => resolve(body),
1: (resolve, body) => resolve(JSON.parse(body)),
2: null
0: (resolve, body) => resolve(body),
1: (resolve, body) => resolve(JSON.parse(body)),
2: null
};
module.exports = async function(url, reqType = RequestType.Text) {
return new Promise((resolve, reject) => {
request(url, (err, res, body) => {
if (err) reject(err);
else functionMap[reqType](resolve, body);
});
});
return new Promise((resolve, reject) => {
request(url, (err, res, body) => {
if (err) reject(err);
else functionMap[reqType](resolve, body);
});
});
}

View file

@ -1,3 +1,3 @@
module.exports = function(bitwiseMods = 0) {
}

View file

@ -1,15 +1,15 @@
module.exports = {
map:function(input, inputMin, inputMax, outputMin, outputMax) {
const newv = (input - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin;
if (outputMin < outputMax) return this.constrain(newv, outputMin, outputMax);
else return this.constrain(newv, outputMax, outputMin);
},
map:function(input, inputMin, inputMax, outputMin, outputMax) {
const newv = (input - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin;
if (outputMin < outputMax) return this.constrain(newv, outputMin, outputMax);
else return this.constrain(newv, outputMax, outputMin);
},
constrain:function(input, low, high) {
return Math.max(Math.min(input, high), low);
},
constrain:function(input, low, high) {
return Math.max(Math.min(input, high), low);
},
randInt:function(from, to) {
return Math.round(this.map(Math.random(), 0, 1, from, to));
}
randInt:function(from, to) {
return Math.round(this.map(Math.random(), 0, 1, from, to));
}
}

View file

@ -1,6 +1,6 @@
module.exports = function(id) {
for (let i = 0; i < global.userKeys.length; i++) {
if (global.users[global.userKeys[i]].id == id)
return global.users[userKeys[i]];
}
for (let i = 0; i < global.userKeys.length; i++) {
if (global.users[global.userKeys[i]].id == id)
return global.users[userKeys[i]];
}
}

View file

@ -1,4 +1,4 @@
module.exports = function(token) {
if (global.userKeys.includes(token)) return global.users[token];
else return null;
if (global.userKeys.includes(token)) return global.users[token];
else return null;
}

View file

@ -1,6 +1,6 @@
module.exports = function(username) {
for (let i = 0; i < global.userKeys.length; i++) {
if (global.users[global.userKeys[i]].username == username)
return global.users[global.userKeys[i]];
}
for (let i = 0; i < global.userKeys.length; i++) {
if (global.users[global.userKeys[i]].username == username)
return global.users[global.userKeys[i]];
}
}

View file

@ -1,33 +1,33 @@
module.exports = function(packet) {
try {
const p = packet.toString(); // Convert our buffer to a String
const s = p.split('\n'); // Split our Login Data to Username Password Osuversion|blabla|bla
const n = s[2].split('|'); // Split osuversion|blablabla|blablabla to a object.
const username = s[0]; // Username ofc
const password = s[1]; // Password ofc
const osuversion = n[0]; // OsuVersion ofc.
const TimeOffset = Number(n[1]); // Comeon, i dont realy have to tell you what this is.
const clientData = n[3].split(':')[2]; // Some system information. such as MacAdress or DiskID
// If some data is not set OR is invailed throw errors
if (username == undefined) throw 'UserName';
if (password == undefined) throw 'password';
if (osuversion == undefined) throw 'osuversion';
if (TimeOffset == undefined) throw 'offset';
if (clientData == undefined) throw 'clientData';
// Everything alright? return parsed data.
const obj = {
username: String(username),
password: String(password),
osuversion: String(osuversion),
timeoffset: Number(TimeOffset),
clientdata: String(clientData)
};
// Here is the return.
return obj;
} catch (ex) {
// Else return undefined, that the login request got broke.
return undefined;
}
try {
const p = packet.toString(); // Convert our buffer to a String
const s = p.split('\n'); // Split our Login Data to Username Password Osuversion|blabla|bla
const n = s[2].split('|'); // Split osuversion|blablabla|blablabla to a object.
const username = s[0]; // Username ofc
const password = s[1]; // Password ofc
const osuversion = n[0]; // OsuVersion ofc.
const TimeOffset = Number(n[1]); // Comeon, i dont realy have to tell you what this is.
const clientData = n[3].split(':')[2]; // Some system information. such as MacAdress or DiskID
// If some data is not set OR is invailed throw errors
if (username == undefined) throw 'UserName';
if (password == undefined) throw 'password';
if (osuversion == undefined) throw 'osuversion';
if (TimeOffset == undefined) throw 'offset';
if (clientData == undefined) throw 'clientData';
// Everything alright? return parsed data.
const obj = {
username: String(username),
password: String(password),
osuversion: String(osuversion),
timeoffset: Number(TimeOffset),
clientdata: String(clientData)
};
// Here is the return.
return obj;
} catch (ex) {
// Else return undefined, that the login request got broke.
return undefined;
}
}