2022-11-16 11:59:23 +00:00
|
|
|
|
import { ConsoleHelper } from "../ConsoleHelper";
|
2022-11-16 15:25:46 +00:00
|
|
|
|
import { Database } from "./objects/Database";
|
|
|
|
|
import { LatLng } from "./objects/LatLng";
|
2022-11-17 00:29:07 +00:00
|
|
|
|
import { LoginProcess } from "./LoginProcess";
|
2022-11-16 11:59:23 +00:00
|
|
|
|
import { Packets } from "./enums/Packets";
|
2022-11-16 15:25:46 +00:00
|
|
|
|
import { replaceAll } from "./Util";
|
2022-11-17 00:29:07 +00:00
|
|
|
|
import { readFileSync } from "fs";
|
|
|
|
|
import { RedisClientType, createClient } from "redis";
|
2022-11-16 15:25:46 +00:00
|
|
|
|
import { Request, Response } from "express";
|
2022-11-17 00:29:07 +00:00
|
|
|
|
import { UserArray } from "./objects/UserArray";
|
2022-11-16 15:25:46 +00:00
|
|
|
|
import { User } from "./objects/User";
|
2022-11-17 00:29:07 +00:00
|
|
|
|
const config:any = JSON.parse(readFileSync(__dirname + "/config.json").toString());
|
|
|
|
|
// TODO: Port osu-packet to TypeScript
|
|
|
|
|
const osu = require("osu-packet");
|
2022-11-16 11:59:23 +00:00
|
|
|
|
|
2022-11-16 15:25:46 +00:00
|
|
|
|
/*const
|
2022-01-04 03:39:53 +00:00
|
|
|
|
loginHandler = require("./loginHandler.js"),
|
|
|
|
|
parseUserData = require("./util/parseUserData.js"),
|
|
|
|
|
getUserFromToken = require("./util/getUserByToken.js"),
|
2022-04-20 07:29:21 +01:00
|
|
|
|
getUserById = require("./util/getUserById.js"),
|
2022-01-04 03:39:53 +00:00
|
|
|
|
bakedResponses = require("./bakedResponses.js"),
|
2022-11-16 15:25:46 +00:00
|
|
|
|
Streams = require("./Streams.js");*/
|
|
|
|
|
|
|
|
|
|
const DB:Database = new Database(config.database.address, config.database.port, config.database.username, config.database.password, config.database.name, async () => {
|
|
|
|
|
// Close any unclosed db matches on startup
|
|
|
|
|
DB.query("UPDATE mp_matches SET close_time = UNIX_TIMESTAMP() WHERE close_time IS NULL");
|
|
|
|
|
DB.query("UPDATE osu_info SET value = 0 WHERE name = 'online_now'");
|
|
|
|
|
});
|
2020-08-27 13:09:35 +01:00
|
|
|
|
|
2022-02-23 05:35:10 +00:00
|
|
|
|
// Users funkyArray for session storage
|
2022-11-16 15:25:46 +00:00
|
|
|
|
const users = new UserArray();
|
2020-08-27 13:09:35 +01:00
|
|
|
|
|
2021-05-15 00:24:39 +01:00
|
|
|
|
// Add the bot user
|
2022-11-16 15:25:46 +00:00
|
|
|
|
const botUser:User = users.add("bot", new User(3, "SillyBot", "bot", DB));
|
2020-09-07 19:23:06 +01:00
|
|
|
|
// Set the bot's position on the map
|
2022-11-16 15:25:46 +00:00
|
|
|
|
botUser.location = new LatLng(50, -32);
|
2020-09-07 19:23:06 +01:00
|
|
|
|
|
2022-11-16 15:25:46 +00:00
|
|
|
|
let redisClient:RedisClientType;
|
2020-09-07 19:23:06 +01:00
|
|
|
|
|
2022-11-16 15:25:46 +00:00
|
|
|
|
async function subscribeToChannel(channelName:string, callback:(message:string) => void) {
|
2022-04-20 07:29:21 +01:00
|
|
|
|
// Dup and connect new client for channel subscription (required)
|
2022-11-16 15:25:46 +00:00
|
|
|
|
const subscriptionClient:RedisClientType = redisClient.duplicate();
|
2022-06-28 00:27:07 +01:00
|
|
|
|
await subscriptionClient.connect();
|
2022-04-20 07:29:21 +01:00
|
|
|
|
// Subscribe to channel
|
2022-06-28 00:27:07 +01:00
|
|
|
|
await subscriptionClient.subscribe(channelName, callback);
|
2022-11-16 11:59:23 +00:00
|
|
|
|
ConsoleHelper.printRedis(`Subscribed to ${channelName} channel`);
|
2022-04-20 07:29:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-24 02:14:23 +01:00
|
|
|
|
if (config.redis.enabled) {
|
2022-04-20 07:29:21 +01:00
|
|
|
|
(async () => {
|
2022-11-16 15:25:46 +00:00
|
|
|
|
redisClient = createClient({
|
|
|
|
|
url: `redis://${replaceAll(config.redis.password, " ", "") == "" ? "" : `${config.redis.password}@`}${config.redis.address}:${config.redis.port}/${config.redis.database}`
|
2022-04-20 07:29:21 +01:00
|
|
|
|
});
|
|
|
|
|
|
2022-11-16 15:25:46 +00:00
|
|
|
|
redisClient.on('error', e => ConsoleHelper.printRedis(e));
|
2022-04-20 07:29:21 +01:00
|
|
|
|
|
|
|
|
|
const connectionStartTime = Date.now();
|
2022-11-16 15:25:46 +00:00
|
|
|
|
await redisClient.connect();
|
|
|
|
|
ConsoleHelper.printRedis(`Connected to redis server. Took ${Date.now() - connectionStartTime}ms`);
|
2022-04-20 07:29:21 +01:00
|
|
|
|
|
|
|
|
|
// Score submit update channel
|
|
|
|
|
subscribeToChannel("binato:update_user_stats", (message) => {
|
2022-11-16 15:25:46 +00:00
|
|
|
|
if (typeof(message) === "string") {
|
|
|
|
|
const user = users.getById(parseInt(message));
|
2022-11-17 00:29:07 +00:00
|
|
|
|
if (user != null) {
|
|
|
|
|
// Update user info
|
|
|
|
|
user.updateUserInfo(true);
|
2022-04-24 02:04:14 +01:00
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
ConsoleHelper.printRedis(`Score submission stats update request received for ${user.username}`);
|
|
|
|
|
}
|
2022-11-16 15:25:46 +00:00
|
|
|
|
}
|
2022-04-20 07:29:21 +01:00
|
|
|
|
});
|
|
|
|
|
})();
|
2022-11-16 15:25:46 +00:00
|
|
|
|
} else ConsoleHelper.printWarn("Redis is disabled!");
|
2022-04-20 07:29:21 +01:00
|
|
|
|
|
|
|
|
|
// User timeout interval
|
2020-08-27 13:09:35 +01:00
|
|
|
|
setInterval(() => {
|
2022-11-16 15:25:46 +00:00
|
|
|
|
for (let User of users.getIterableItems()) {
|
2022-11-17 00:29:07 +00:00
|
|
|
|
if (User.uuid == "bot") continue; // Ignore the bot
|
2020-08-27 13:09:35 +01:00
|
|
|
|
|
2022-02-23 05:35:32 +00:00
|
|
|
|
// Logout this user, they're clearly gone.
|
2022-11-17 00:29:07 +00:00
|
|
|
|
// if (Date.now() >= User.timeoutTime)
|
|
|
|
|
// Logout(User);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
}
|
2020-08-27 13:09:35 +01:00
|
|
|
|
}, 10000);
|
|
|
|
|
|
2022-08-26 12:52:00 +01:00
|
|
|
|
// Init stream class
|
2022-11-16 15:25:46 +00:00
|
|
|
|
//Streams.init();
|
2020-08-27 13:09:35 +01:00
|
|
|
|
|
|
|
|
|
// An array containing all chat channels
|
2022-11-16 15:25:46 +00:00
|
|
|
|
/*global.channels = [
|
2022-01-04 03:39:53 +00:00
|
|
|
|
{ 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 },
|
2022-11-16 15:25:46 +00:00
|
|
|
|
];*/
|
2020-08-27 13:09:35 +01:00
|
|
|
|
|
|
|
|
|
// Create a stream for each chat channel
|
2022-11-16 15:25:46 +00:00
|
|
|
|
/*for (let i = 0; i < global.channels.length; i++) {
|
2022-08-26 12:52:00 +01:00
|
|
|
|
Streams.addStream(global.channels[i].channelName, false);
|
2022-11-16 15:25:46 +00:00
|
|
|
|
}*/
|
2020-08-27 13:09:35 +01:00
|
|
|
|
|
|
|
|
|
// Add a stream for the multiplayer lobby
|
2022-11-16 15:25:46 +00:00
|
|
|
|
//Streams.addStream("multiplayer_lobby", false);
|
2021-01-26 12:26:46 +00:00
|
|
|
|
|
2020-08-27 13:09:35 +01:00
|
|
|
|
// Include packets
|
2022-11-17 00:29:07 +00:00
|
|
|
|
/*const ChangeAction = require("./Packets/ChangeAction.js"),
|
2022-01-04 03:39:53 +00:00
|
|
|
|
SendPublicMessage = require("./Packets/SendPublicMessage.js"),
|
|
|
|
|
Logout = require("./Packets/Logout.js"),
|
|
|
|
|
Spectator = require("./Spectator.js"),
|
|
|
|
|
SendPrivateMessage = require("./Packets/SendPrivateMessage.js"),
|
|
|
|
|
MultiplayerManager = require("./MultiplayerManager.js"),
|
2022-01-04 04:43:32 +00:00
|
|
|
|
SetAwayMessage = require("./Packets/SetAwayMessage.js"),
|
2022-01-04 03:39:53 +00:00
|
|
|
|
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"),
|
2022-11-17 00:29:07 +00:00
|
|
|
|
TourneyMatchLeaveChannel = require("./Packets/TourneyLeaveMatchChannel.js");*/
|
2020-08-27 13:09:35 +01:00
|
|
|
|
|
2021-01-26 12:26:46 +00:00
|
|
|
|
// A class for managing everything multiplayer
|
2022-11-17 00:29:07 +00:00
|
|
|
|
//const multiplayerManager:MultiplayerManager = new MultiplayerManager();
|
|
|
|
|
|
|
|
|
|
const EMPTY_BUFFER = Buffer.alloc(0);
|
2021-01-26 12:26:46 +00:00
|
|
|
|
|
2022-11-16 15:25:46 +00:00
|
|
|
|
export async function HandleRequest(req:Request, res:Response, packet:Buffer) {
|
2022-11-17 00:29:07 +00:00
|
|
|
|
// Remove headers we don't need for Bancho
|
|
|
|
|
res.removeHeader('X-Powered-By');
|
|
|
|
|
res.removeHeader('Date');
|
|
|
|
|
|
2022-01-04 03:39:53 +00:00
|
|
|
|
// Get the client's token string and request data
|
2022-11-17 00:29:07 +00:00
|
|
|
|
const requestTokenString:string | undefined = req.header("osu-token");
|
2022-01-04 03:39:53 +00:00
|
|
|
|
|
|
|
|
|
// Check if the user is logged in
|
|
|
|
|
if (requestTokenString == null) {
|
2022-11-17 00:29:07 +00:00
|
|
|
|
// Only do this if we're absolutely sure that we're connected to the DB
|
|
|
|
|
if (DB.connected) {
|
|
|
|
|
// Client doesn't have a token yet, let's auth them!
|
|
|
|
|
|
|
|
|
|
await LoginProcess(req, res, packet, DB, users);
|
|
|
|
|
DB.query("UPDATE osu_info SET value = ? WHERE name = 'online_now'", [users.getLength() - 1]);
|
|
|
|
|
}
|
2022-01-04 03:39:53 +00:00
|
|
|
|
} else {
|
2022-11-17 00:29:07 +00:00
|
|
|
|
let responseData:Buffer | string = EMPTY_BUFFER;
|
|
|
|
|
|
2022-01-04 03:39:53 +00:00
|
|
|
|
// Client has a token, let's see what they want.
|
|
|
|
|
try {
|
|
|
|
|
// Get the current user
|
2022-11-17 00:29:07 +00:00
|
|
|
|
const PacketUser:User | undefined = users.getByToken(requestTokenString);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
|
|
|
|
|
// Make sure the client's token isn't invalid
|
|
|
|
|
if (PacketUser != null) {
|
2022-02-23 05:35:32 +00:00
|
|
|
|
// Update the session timeout time
|
|
|
|
|
PacketUser.timeoutTime = Date.now() + 60000;
|
|
|
|
|
|
2022-01-04 03:39:53 +00:00
|
|
|
|
// Create a new osu! packet reader
|
2022-11-17 00:29:07 +00:00
|
|
|
|
const osuPacketReader = new osu.Client.Reader(packet);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
// Parse current bancho packet
|
|
|
|
|
const PacketData = osuPacketReader.Parse();
|
|
|
|
|
|
2022-01-04 04:42:26 +00:00
|
|
|
|
// Go through each packet sent by the client
|
2022-11-16 15:25:46 +00:00
|
|
|
|
for (let CurrentPacket of PacketData) {
|
2022-11-17 00:29:07 +00:00
|
|
|
|
/*switch (CurrentPacket.id) {
|
2022-11-16 11:59:23 +00:00
|
|
|
|
case Packets.Client_ChangeAction:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
ChangeAction(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-16 11:59:23 +00:00
|
|
|
|
case Packets.Client_SendPublicMessage:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
SendPublicMessage(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-16 11:59:23 +00:00
|
|
|
|
case Packets.Client_Logout:
|
2022-09-30 11:34:52 +01:00
|
|
|
|
await Logout(PacketUser);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2022-11-16 11:59:23 +00:00
|
|
|
|
case Packets.Client_RequestStatusUpdate:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
UserPresenceBundle(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-16 11:59:23 +00:00
|
|
|
|
case Packets.Client_StartSpectating:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
Spectator.startSpectatingUser(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-16 11:59:23 +00:00
|
|
|
|
case Packets.Client_SpectateFrames:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
Spectator.sendSpectatorFrames(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-16 11:59:23 +00:00
|
|
|
|
case Packets.Client_StopSpectating:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
Spectator.stopSpectatingUser(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_SendPrivateMessage:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
SendPrivateMessage(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_JoinLobby:
|
|
|
|
|
multiplayerManager.userEnterLobby(PacketUser);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_PartLobby:
|
|
|
|
|
multiplayerManager.userLeaveLobby(PacketUser);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_CreateMatch:
|
|
|
|
|
await multiplayerManager.createMultiplayerMatch(PacketUser, CurrentPacket.data);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_JoinMatch:
|
|
|
|
|
multiplayerManager.joinMultiplayerMatch(PacketUser, CurrentPacket.data);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchChangeSlot:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.moveToSlot(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchReady:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.setStateReady(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchChangeSettings:
|
2022-09-30 11:34:52 +01:00
|
|
|
|
await PacketUser.currentMatch.updateMatch(PacketUser, CurrentPacket.data);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchNotReady:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.setStateNotReady(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_PartMatch:
|
|
|
|
|
await multiplayerManager.leaveMultiplayerMatch(PacketUser);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Also handles user kick if the slot has a user
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchLock:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.lockMatchSlot(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchNoBeatmap:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.missingBeatmap(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchSkipRequest:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.matchSkip(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchHasBeatmap:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.notMissingBeatmap(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchTransferHost:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.transferHost(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchChangeMods:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.updateMods(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchStart:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.startMatch();
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchLoadComplete:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.matchPlayerLoaded(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchComplete:
|
2022-09-30 11:34:52 +01:00
|
|
|
|
await PacketUser.currentMatch.onPlayerFinishMatch(PacketUser);
|
2022-01-04 03:39:53 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchScoreUpdate:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.updatePlayerScore(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchFailed:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.matchFailed(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_MatchChangeTeam:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
PacketUser.currentMatch.changeTeam(PacketUser);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_ChannelJoin:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
ChannelJoin(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_ChannelPart:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
ChannelPart(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_SetAwayMessage:
|
2022-01-04 04:43:32 +00:00
|
|
|
|
SetAwayMessage(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_FriendAdd:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
AddFriend(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_FriendRemove:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
RemoveFriend(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_UserStatsRequest:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
UserStatsRequest(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_SpecialMatchInfoRequest:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
TourneyMatchSpecialInfo(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_SpecialJoinMatchChannel:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
TourneyMatchJoinChannel(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_SpecialLeaveMatchChannel:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
TourneyMatchLeaveChannel(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_Invite:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
MultiplayerInvite(PacketUser, CurrentPacket.data);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-17 00:29:07 +00:00
|
|
|
|
case Packets.Client_UserPresenceRequest:
|
2022-01-04 03:39:53 +00:00
|
|
|
|
UserPresence(PacketUser, PacketUser.id); // Can't really think of a way to generalize this?
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// Ignore client_beatmapInfoRequest and client_receiveUpdates
|
2022-09-30 11:38:41 +01:00
|
|
|
|
if (CurrentPacket.id == 68 || CurrentPacket.id == 79 || CurrentPacket.id == 4) break;
|
2022-01-04 03:39:53 +00:00
|
|
|
|
// Print out unimplemented packet
|
|
|
|
|
console.dir(CurrentPacket);
|
|
|
|
|
break;
|
2022-11-17 00:29:07 +00:00
|
|
|
|
}*/
|
2022-09-30 11:34:52 +01:00
|
|
|
|
}
|
2022-02-22 09:42:57 +00:00
|
|
|
|
|
2022-07-02 11:36:49 +01:00
|
|
|
|
responseData = PacketUser.queue;
|
2022-02-22 09:42:57 +00:00
|
|
|
|
PacketUser.clearQueue();
|
2022-01-04 03:39:53 +00:00
|
|
|
|
} else {
|
2022-11-17 00:29:07 +00:00
|
|
|
|
// Only do this if we're absolutely sure that we're connected to the DB
|
|
|
|
|
if (DB.connected) {
|
|
|
|
|
// User's token is invlid, force a reconnect
|
|
|
|
|
ConsoleHelper.printBancho(`Forced client re-login (Token is invalid)`);
|
|
|
|
|
responseData = "\u0005\u0000\u0000\u0004\u0000\u0000\u0000<30><30><EFBFBD><EFBFBD>\u0018\u0000\u0000\u0011\u0000\u0000\u0000\u000b\u000fReconnecting...";
|
|
|
|
|
}
|
2022-01-04 03:39:53 +00:00
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
} finally {
|
|
|
|
|
res.writeHead(200, {
|
|
|
|
|
"Connection": "keep-alive",
|
|
|
|
|
"Keep-Alive": "timeout=5, max=100",
|
|
|
|
|
});
|
2022-02-22 09:01:19 +00:00
|
|
|
|
// Send the prepared packet(s) to the client
|
2022-01-04 03:39:53 +00:00
|
|
|
|
res.end(responseData);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-17 00:29:07 +00:00
|
|
|
|
}
|