General code quality/readability
This commit is contained in:
parent
04bd1e42bb
commit
93da399fa5
5 changed files with 59 additions and 54 deletions
|
@ -67,6 +67,7 @@ import AddFriend from "./packets/AddFriend";
|
||||||
import RemoveFriend from "./packets/RemoveFriend";
|
import RemoveFriend from "./packets/RemoveFriend";
|
||||||
import PrivateChannel from "./objects/PrivateChannel";
|
import PrivateChannel from "./objects/PrivateChannel";
|
||||||
import MultiplayerInvite from "./packets/MultiplayerInvite";
|
import MultiplayerInvite from "./packets/MultiplayerInvite";
|
||||||
|
import SendPublicMessage from "./packets/SendPublicMessage";
|
||||||
|
|
||||||
// User timeout interval
|
// User timeout interval
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
@ -98,12 +99,12 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
// Client has a token, let's see what they want.
|
// Client has a token, let's see what they want.
|
||||||
try {
|
try {
|
||||||
// Get the current user
|
// Get the current user
|
||||||
const PacketUser = shared.users.getByToken(requestTokenString);
|
const user = shared.users.getByToken(requestTokenString);
|
||||||
|
|
||||||
// Make sure the client's token isn't invalid
|
// Make sure the client's token isn't invalid
|
||||||
if (PacketUser != null) {
|
if (user != null) {
|
||||||
// Update the session timeout time for each request
|
// Update the session timeout time for each request
|
||||||
PacketUser.timeoutTime = Date.now() + 60000;
|
user.timeoutTime = Date.now() + 60000;
|
||||||
|
|
||||||
// Parse bancho packets
|
// Parse bancho packets
|
||||||
const osuPacketReader = osu.Client.Reader(packet);
|
const osuPacketReader = osu.Client.Reader(packet);
|
||||||
|
@ -113,131 +114,127 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
for (const packet of packets) {
|
for (const packet of packets) {
|
||||||
switch (packet.id) {
|
switch (packet.id) {
|
||||||
case Packets.Client_ChangeAction:
|
case Packets.Client_ChangeAction:
|
||||||
ChangeAction(PacketUser, packet.data);
|
ChangeAction(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SendPublicMessage:
|
case Packets.Client_SendPublicMessage:
|
||||||
const message:MessageData = packet.data;
|
SendPublicMessage(user, packet.data);
|
||||||
let channel = shared.chatManager.GetChannelByName(message.target);
|
|
||||||
if (channel instanceof Channel) {
|
|
||||||
channel.SendMessage(PacketUser, packet.data.message);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_Logout:
|
case Packets.Client_Logout:
|
||||||
await Logout(PacketUser);
|
await Logout(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_RequestStatusUpdate:
|
case Packets.Client_RequestStatusUpdate:
|
||||||
UserPresenceBundle(PacketUser);
|
UserPresenceBundle(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_StartSpectating:
|
case Packets.Client_StartSpectating:
|
||||||
spectatorManager.startSpectating(PacketUser, packet.data);
|
spectatorManager.startSpectating(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SpectateFrames:
|
case Packets.Client_SpectateFrames:
|
||||||
spectatorManager.spectatorFrames(PacketUser, packet.data);
|
spectatorManager.spectatorFrames(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_StopSpectating:
|
case Packets.Client_StopSpectating:
|
||||||
spectatorManager.stopSpectating(PacketUser);
|
spectatorManager.stopSpectating(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SendPrivateMessage:
|
case Packets.Client_SendPrivateMessage:
|
||||||
PrivateMessage(PacketUser, packet.data);
|
PrivateMessage(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_JoinLobby:
|
case Packets.Client_JoinLobby:
|
||||||
shared.multiplayerManager.JoinLobby(PacketUser);
|
shared.multiplayerManager.JoinLobby(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_PartLobby:
|
case Packets.Client_PartLobby:
|
||||||
shared.multiplayerManager.LeaveLobby(PacketUser);
|
shared.multiplayerManager.LeaveLobby(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_CreateMatch:
|
case Packets.Client_CreateMatch:
|
||||||
await shared.multiplayerManager.CreateMatch(PacketUser, packet.data);
|
await shared.multiplayerManager.CreateMatch(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_JoinMatch:
|
case Packets.Client_JoinMatch:
|
||||||
shared.multiplayerManager.JoinMatch(PacketUser, packet.data);
|
shared.multiplayerManager.JoinMatch(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchChangeSlot:
|
case Packets.Client_MatchChangeSlot:
|
||||||
PacketUser.match?.moveToSlot(PacketUser, packet.data);
|
user.match?.moveToSlot(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchReady:
|
case Packets.Client_MatchReady:
|
||||||
PacketUser.match?.setStateReady(PacketUser);
|
user.match?.setStateReady(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchChangeSettings:
|
case Packets.Client_MatchChangeSettings:
|
||||||
await PacketUser.match?.updateMatch(PacketUser, packet.data);
|
await user.match?.updateMatch(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchNotReady:
|
case Packets.Client_MatchNotReady:
|
||||||
PacketUser.match?.setStateNotReady(PacketUser);
|
user.match?.setStateNotReady(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_PartMatch:
|
case Packets.Client_PartMatch:
|
||||||
await shared.multiplayerManager.LeaveMatch(PacketUser);
|
await shared.multiplayerManager.LeaveMatch(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchLock:
|
case Packets.Client_MatchLock:
|
||||||
PacketUser.match?.lockOrKick(PacketUser, packet.data);
|
user.match?.lockOrKick(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchNoBeatmap:
|
case Packets.Client_MatchNoBeatmap:
|
||||||
PacketUser.match?.missingBeatmap(PacketUser);
|
user.match?.missingBeatmap(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchSkipRequest:
|
case Packets.Client_MatchSkipRequest:
|
||||||
PacketUser.match?.matchSkip(PacketUser);
|
user.match?.matchSkip(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchHasBeatmap:
|
case Packets.Client_MatchHasBeatmap:
|
||||||
PacketUser.match?.notMissingBeatmap(PacketUser);
|
user.match?.notMissingBeatmap(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchTransferHost:
|
case Packets.Client_MatchTransferHost:
|
||||||
PacketUser.match?.transferHost(PacketUser, packet.data);
|
user.match?.transferHost(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchChangeMods:
|
case Packets.Client_MatchChangeMods:
|
||||||
PacketUser.match?.updateMods(PacketUser, packet.data);
|
user.match?.updateMods(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchStart:
|
case Packets.Client_MatchStart:
|
||||||
PacketUser.match?.startMatch();
|
user.match?.startMatch();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchLoadComplete:
|
case Packets.Client_MatchLoadComplete:
|
||||||
PacketUser.match?.matchPlayerLoaded(PacketUser);
|
user.match?.matchPlayerLoaded(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchComplete:
|
case Packets.Client_MatchComplete:
|
||||||
await PacketUser.match?.onPlayerFinishMatch(PacketUser);
|
await user.match?.onPlayerFinishMatch(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchScoreUpdate:
|
case Packets.Client_MatchScoreUpdate:
|
||||||
PacketUser.match?.updatePlayerScore(PacketUser, packet.data);
|
user.match?.updatePlayerScore(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchFailed:
|
case Packets.Client_MatchFailed:
|
||||||
PacketUser.match?.matchFailed(PacketUser);
|
user.match?.matchFailed(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchChangeTeam:
|
case Packets.Client_MatchChangeTeam:
|
||||||
PacketUser.match?.changeTeam(PacketUser);
|
user.match?.changeTeam(user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_ChannelJoin:
|
case Packets.Client_ChannelJoin:
|
||||||
PacketUser.joinChannel(packet.data);
|
user.joinChannel(packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_ChannelPart:
|
case Packets.Client_ChannelPart:
|
||||||
PacketUser.leaveChannel(packet.data);
|
user.leaveChannel(packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SetAwayMessage:
|
case Packets.Client_SetAwayMessage:
|
||||||
|
@ -245,35 +242,35 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_FriendAdd:
|
case Packets.Client_FriendAdd:
|
||||||
AddFriend(PacketUser, packet.data);
|
AddFriend(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_FriendRemove:
|
case Packets.Client_FriendRemove:
|
||||||
RemoveFriend(PacketUser, packet.data);
|
RemoveFriend(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_UserStatsRequest:
|
case Packets.Client_UserStatsRequest:
|
||||||
UserStatsRequest(PacketUser, packet.data);
|
UserStatsRequest(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SpecialMatchInfoRequest:
|
case Packets.Client_SpecialMatchInfoRequest:
|
||||||
TourneyMatchSpecialInfo(PacketUser, packet.data);
|
TourneyMatchSpecialInfo(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SpecialJoinMatchChannel:
|
case Packets.Client_SpecialJoinMatchChannel:
|
||||||
TourneyMatchJoinChannel(PacketUser, packet.data);
|
TourneyMatchJoinChannel(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SpecialLeaveMatchChannel:
|
case Packets.Client_SpecialLeaveMatchChannel:
|
||||||
TourneyMatchLeaveChannel(PacketUser, packet.data);
|
TourneyMatchLeaveChannel(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_Invite:
|
case Packets.Client_Invite:
|
||||||
MultiplayerInvite(PacketUser, packet.data);
|
MultiplayerInvite(user, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_UserPresenceRequest:
|
case Packets.Client_UserPresenceRequest:
|
||||||
UserPresence(PacketUser, PacketUser.id);
|
UserPresence(user, user.id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Ignored packets
|
// Ignored packets
|
||||||
|
@ -290,8 +287,8 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
responseData = PacketUser.queue;
|
responseData = user.queue;
|
||||||
PacketUser.clearQueue();
|
user.clearQueue();
|
||||||
} else {
|
} else {
|
||||||
// User's token is invlid, force a reconnect
|
// User's token is invlid, force a reconnect
|
||||||
ConsoleHelper.printBancho(`Forced client re-connect (Token is invalid)`);
|
ConsoleHelper.printBancho(`Forced client re-connect (Token is invalid)`);
|
||||||
|
|
|
@ -249,7 +249,7 @@ enum CountryCodes {
|
||||||
UY = 226,
|
UY = 226,
|
||||||
SI = 194,
|
SI = 194,
|
||||||
AI = 7
|
AI = 7
|
||||||
};
|
}
|
||||||
|
|
||||||
const keys = Object.keys(CountryCodes);
|
const keys = Object.keys(CountryCodes);
|
||||||
const values = Object.values(CountryCodes);
|
const values = Object.values(CountryCodes);
|
||||||
|
|
10
server/packets/SendPublicMessage.ts
Normal file
10
server/packets/SendPublicMessage.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { Channel } from "diagnostics_channel";
|
||||||
|
import MessageData from "../interfaces/MessageData";
|
||||||
|
import User from "../objects/User";
|
||||||
|
|
||||||
|
export default function SendPublicMessage(user:User, message:MessageData) {
|
||||||
|
const channel = user.shared.chatManager.GetChannelByName(message.target);
|
||||||
|
if (channel instanceof Channel) {
|
||||||
|
channel.SendMessage(user, message.message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ export default function StatusUpdate(arg0:User | Shared, id:number) {
|
||||||
|
|
||||||
if (userData == null) return;
|
if (userData == null) return;
|
||||||
|
|
||||||
let UserStatusObject = {
|
osuPacketWriter.HandleOsuUpdate({
|
||||||
userId: userData.id,
|
userId: userData.id,
|
||||||
status: userData.actionID,
|
status: userData.actionID,
|
||||||
statusText: userData.actionText,
|
statusText: userData.actionText,
|
||||||
|
@ -34,9 +34,7 @@ export default function StatusUpdate(arg0:User | Shared, id:number) {
|
||||||
totalScore: userData.totalScore,
|
totalScore: userData.totalScore,
|
||||||
rank: userData.rank,
|
rank: userData.rank,
|
||||||
performance: (userData.rankingMode == RankingModes.PP ? userData.pp : 0)
|
performance: (userData.rankingMode == RankingModes.PP ? userData.pp : 0)
|
||||||
};
|
});
|
||||||
|
|
||||||
osuPacketWriter.HandleOsuUpdate(UserStatusObject);
|
|
||||||
|
|
||||||
// Send data to user's queue
|
// Send data to user's queue
|
||||||
if (arg0 instanceof User) {
|
if (arg0 instanceof User) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ export default function UserPresenceBundle(arg0:User | Shared) : Buffer {
|
||||||
shared = arg0;
|
shared = arg0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let userIds:Array<number> = new Array<number>();
|
const userIds:Array<number> = new Array<number>();
|
||||||
|
|
||||||
for (const userData of shared.users.getIterableItems()) {
|
for (const userData of shared.users.getIterableItems()) {
|
||||||
userIds.push(userData.id);
|
userIds.push(userData.id);
|
||||||
|
|
Loading…
Reference in a new issue