Mirror Gitea instance

This commit is contained in:
Ethan Stubbs 2021-05-15 00:24:39 +01:00
parent 9fd0209063
commit f264e40eb7
15 changed files with 1921 additions and 90 deletions

View file

@ -1,6 +1,3 @@
### This repo has been moved to a personal Gitea instance and can be found here: [Binato](https://git.eusv.ml/holly/Binato)
This repo will stay up as a irregularly updated mirror
# Binato [![CodeFactor](https://www.codefactor.io/repository/github/tgpethan/binato/badge/master)](https://www.codefactor.io/repository/github/tgpethan/binato/overview/master)
An implementation of osu!bancho in Javascript

View file

@ -112,7 +112,7 @@ ALTER TABLE `web_titles`
ALTER TABLE `users_info`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
ALTER TABLE `users_modes_info`
MODIFY `n` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0;

1831
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,9 +3,7 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"scripts": {},
"keywords": [],
"author": "",
"license": "MIT",

View file

@ -1,7 +1,6 @@
const osu = require("osu-packet"),
maths = require("./util/Maths.js"),
OsuBattleRoyale = require("./MultiplayerExtras/OsuBattleRoyale.js");
//Multiplayer = require("./Multiplayer.js");
module.exports = function(User, Message, Stream, IsCalledFromMultiplayer = false) {
if (Message[0] != "!") return;
@ -85,18 +84,18 @@ module.exports = function(User, Message, Stream, IsCalledFromMultiplayer = false
if (countdown != 0 && countdown > 0) countdown--;
if (countdown <= 10 && countdown > 0) {
local_osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: "Starting in " + countdown,
target: "#multiplayer",
senderId: global.users[0].id
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, local_osuPacketWriter.toBuffer, null);
} else if (countdown == 0) {
local_osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: "Good luck, have fun!",
target: "#multiplayer",
senderId: global.users[0].id
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, local_osuPacketWriter.toBuffer, null);
User.currentMatch.matchStartCountdownActive = false;
@ -120,10 +119,10 @@ module.exports = function(User, Message, Stream, IsCalledFromMultiplayer = false
if (User.currentMatch.multiplayerExtras.name == "osu! Battle Royale") {
commandBanchoPacketWriter = new osu.Bancho.Writer;
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: "osu! Battle Royale has been disabled!",
target: "#multiplayer",
senderId: global.users[0].id
senderId: global.users["bot"].id
});
User.currentMatch.multiplayerExtras = null;
global.StreamsHandler.sendToStream(Stream, commandBanchoPacketWriter.toBuffer, null);
@ -143,17 +142,17 @@ module.exports = function(User, Message, Stream, IsCalledFromMultiplayer = false
if (responseMessage != "") {
if (Stream.includes("#")) {
osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: responseMessage,
target: Stream,
senderId: global.users[0].id
senderId: global.users["bot"].id
});
} else {
osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: responseMessage,
target: "#multiplayer",
senderId: global.users[0].id
senderId: global.users["bot"].id
});
}
}
@ -164,16 +163,16 @@ function enableOBR(User, Stream, commandBanchoPacketWriter) {
User.currentMatch.multiplayerExtras = new OsuBattleRoyale(User.currentMatch);
commandBanchoPacketWriter = new osu.Bancho.Writer;
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: "osu! Battle Royale has been enabled!",
target: "#multiplayer",
senderId: global.users[0].id
senderId: global.users["bot"].id
});
commandBanchoPacketWriter.SendMessage({
sendingClient: global.users[0].username,
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[0].id
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(Stream, commandBanchoPacketWriter.toBuffer, null);
}

View file

@ -46,10 +46,10 @@ module.exports = class {
// Inform the kicked user's client that they were kicked
osuPacketWriter.MatchUpdate(this.MultiplayerMatch.createOsuMatchJSON());
osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: "You were eliminated from the match!",
target: global.users[0].username,
senderId: global.users[0].id
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
kickedPlayer.addActionToQueue(osuPacketWriter.toBuffer);
@ -57,10 +57,10 @@ module.exports = class {
osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: `${kickedPlayer.username} was eliminated from the match!`,
target: "#multiplayer",
senderId: global.users[0].id
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream(this.MultiplayerMatch.matchChatStreamName, osuPacketWriter.toBuffer, null);
@ -94,10 +94,10 @@ module.exports = class {
case 0:
remainingWriterContainer = new osu.Bancho.Writer;
remainingWriterContainer.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: "Everyone was eliminated from the match! Nobody wins.",
target: global.users[0].username,
senderId: global.users[0].id
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
for (i = 0; i < playerScores.length; i++) {
playerClassContainer = getUserById(playerScores[i].playerId);
@ -108,10 +108,10 @@ module.exports = class {
case 1:
remainingWriterContainer = new osu.Bancho.Writer;
remainingWriterContainer.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: "You are the last one remaining, you win!",
target: global.users[0].username,
senderId: global.users[0].id
target: global.users["bot"].username,
senderId: global.users["bot"].id
});
playerClassContainer.addActionToQueue(remainingWriterContainer.toBuffer);
break;

View file

@ -11,21 +11,15 @@ module.exports = function(CurrentUser) {
}
}
// Find the index that the user's class is at and remove the object
for (let i = 0; i < global.users.length; i++) {
if (CurrentUser.uuid == global.users[i].uuid) {
// Remove that user from the list of users
global.users.splice(i, 1);
break;
}
}
// Remove user from user list
global.removeUser(CurrentUser);
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: `User ${CurrentUser.username} has logged out.`,
target: "#userlog",
senderId: 3
senderId: global.users["bot"].id
});
global.StreamsHandler.sendToStream("#userlog", osuPacketWriter.toBuffer);

View file

@ -17,10 +17,10 @@ module.exports = function(CurrentUser, CurrentPacket) {
} else {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.SendMessage({
sendingClient: global.users[0].username,
sendingClient: global.users["bot"].username,
message: "The channel you are currently trying to send to is locked, please check back later!",
target: CurrentPacket.data.target,
senderId: global.users[0].id
senderId: global.users["bot"].id
});
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
}

View file

@ -6,9 +6,9 @@ module.exports = function(CurrentUser, MatchID) {
if (match != null) {
match.isTourneyMatch = true;
for (let i = 0; i < global.users.length; i++) {
if (global.users[i].id == CurrentUser.id) {
match.tourneyClientUsers.push(global.users[i]);
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]]);
}
}

View file

@ -5,8 +5,8 @@ module.exports = function(currentUser, sendImmidiate = true) {
let userIds = [];
for (let i = 0; i < global.users.length; i++) {
userIds.push(global.users[i].id);
for (let i = 0; i < global.userKeys.length; i++) {
userIds.push(global.users[global.userKeys[i]].id);
}
osuPacketWriter.UserPresenceBundle(userIds);

View file

@ -54,17 +54,17 @@ module.exports = async function(req, res, loginInfo) {
// 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.users.length; i++) {
const user = global.users[i];
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.users.splice(i, 1);
global.removeUser(user);
}
}
}
// Create user object
global.users.push(new User(userDB.id, loginInfo.username, newClientToken, new Date().getTime(), isTourneyClient));
global.addUser(newClientToken, new User(userDB.id, loginInfo.username, newClientToken, new Date().getTime(), isTourneyClient));
// Retreive the newly created user
const NewUser = getUserByToken(newClientToken);

View file

@ -10,14 +10,28 @@ const osu = require("osu-packet"),
DatabaseHelperClass = require("./DatabaseHelper.js"),
config = require("../config.json");
global.users = [
new User(3, "SillyBot", "SillyBot", new Date().getTime())
];
global.users = {};
global.userKeys = Object.keys(global.users);
global.addUser = function(uuid, userToAdd) {
global.users[uuid] = userToAdd;
global.refreshUserKeys();
}
global.removeUser = function(userToRemove) {
delete userToRemove;
global.refreshUserKeys();
}
global.refreshUserKeys = function() {
global.userKeys = Object.keys(global.users);
}
// Add the bot user
global.addUser("bot", new User(3, "SillyBot", "bot", new Date().getTime()));
// Set the bot's position on the map
// First user will always be the bot
global.users[0].location[0] = 50;
global.users[0].location[1] = -32;
global.users["bot"].location[0] = 50;
global.users["bot"].location[1] = -32;
global.DatabaseHelper = new DatabaseHelperClass(config.databaseAddress, config.databasePort, config.databaseUsername, config.databasePassword, config.databaseName);
@ -26,8 +40,8 @@ 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.users.length; i++) {
const User = global.users[i];
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: :(
@ -78,7 +92,7 @@ global.httpRequestsPerLogInterval = 0;
const logInterval = 10; // Secs
setInterval(() => {
global.usersOnline = (global.users.length - 1);
global.usersOnline = (global.userKeys.length - 1);
global.multiplayerMatches = [global.MultiplayerManager.matches.length, 0]; // TODO: Respect private matches
fs.appendFile(
@ -94,7 +108,7 @@ if (!fs.existsSync("tHMM.ds")) fs.writeFileSync("tHMM.ds", "0");
global.totalHistoricalMultiplayerMatches = parseInt(fs.readFileSync("tHMM.ds").toString());
global.getAndAddToHistoricalMultiplayerMatches = function() {
global.totalHistoricalMultiplayerMatches++;
fs.writeFile("tHMM.ds", global.totalHistoricalMultiplayerMatches, () => {});
fs.writeFile("tHMM.ds", `${global.totalHistoricalMultiplayerMatches}`, () => {});
return global.totalHistoricalMultiplayerMatches;
}

View file

@ -1,6 +1,6 @@
module.exports = function(id) {
for (let i = 0; i < global.users.length; i++) {
if (global.users[i].id == id)
return global.users[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,6 +1,4 @@
module.exports = function(token) {
for (let i = 0; i < global.users.length; i++) {
if (global.users[i].uuid == token)
return global.users[i];
}
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.users.length; i++) {
if (global.users[i].username == username)
return global.users[i];
for (let i = 0; i < global.userKeys.length; i++) {
if (global.users[global.userKeys[i]].username == username)
return global.users[global.userKeys[i]];
}
}