diff --git a/server/BanchoServer.ts b/server/BanchoServer.ts index 5cfda62..932c43f 100644 --- a/server/BanchoServer.ts +++ b/server/BanchoServer.ts @@ -70,7 +70,7 @@ import MultiplayerInvite from "./packets/MultiplayerInvite"; // User timeout interval setInterval(() => { - for (let User of shared.users.getIterableItems()) { + for (const User of shared.users.getIterableItems()) { if (User.uuid == "bot") continue; // Ignore the bot // Logout this user, they're clearly gone. @@ -102,26 +102,25 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo // Make sure the client's token isn't invalid if (PacketUser != null) { - // Update the session timeout time + // Update the session timeout time for each request PacketUser.timeoutTime = Date.now() + 60000; - // Create a new osu! packet reader + // Parse bancho packets const osuPacketReader = osu.Client.Reader(packet); - // Parse current bancho packet - const PacketData = osuPacketReader.Parse(); + const packets = osuPacketReader.Parse(); // Go through each packet sent by the client - for (let CurrentPacket of PacketData) { - switch (CurrentPacket.id) { + for (const packet of packets) { + switch (packet.id) { case Packets.Client_ChangeAction: - ChangeAction(PacketUser, CurrentPacket.data); + ChangeAction(PacketUser, packet.data); break; case Packets.Client_SendPublicMessage: - const message:MessageData = CurrentPacket.data; + const message:MessageData = packet.data; let channel = shared.chatManager.GetChannelByName(message.target); if (channel instanceof Channel) { - channel.SendMessage(PacketUser, CurrentPacket.data.message); + channel.SendMessage(PacketUser, packet.data.message); } break; @@ -134,11 +133,11 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_StartSpectating: - spectatorManager.startSpectating(PacketUser, CurrentPacket.data); + spectatorManager.startSpectating(PacketUser, packet.data); break; case Packets.Client_SpectateFrames: - spectatorManager.spectatorFrames(PacketUser, CurrentPacket.data); + spectatorManager.spectatorFrames(PacketUser, packet.data); break; case Packets.Client_StopSpectating: @@ -146,7 +145,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_SendPrivateMessage: - PrivateMessage(PacketUser, CurrentPacket.data); + PrivateMessage(PacketUser, packet.data); break; case Packets.Client_JoinLobby: @@ -158,15 +157,15 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_CreateMatch: - await shared.multiplayerManager.CreateMatch(PacketUser, CurrentPacket.data); + await shared.multiplayerManager.CreateMatch(PacketUser, packet.data); break; case Packets.Client_JoinMatch: - shared.multiplayerManager.JoinMatch(PacketUser, CurrentPacket.data); + shared.multiplayerManager.JoinMatch(PacketUser, packet.data); break; case Packets.Client_MatchChangeSlot: - PacketUser.match?.moveToSlot(PacketUser, CurrentPacket.data); + PacketUser.match?.moveToSlot(PacketUser, packet.data); break; case Packets.Client_MatchReady: @@ -174,7 +173,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_MatchChangeSettings: - await PacketUser.match?.updateMatch(PacketUser, CurrentPacket.data); + await PacketUser.match?.updateMatch(PacketUser, packet.data); break; case Packets.Client_MatchNotReady: @@ -186,7 +185,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_MatchLock: - PacketUser.match?.lockOrKick(PacketUser, CurrentPacket.data); + PacketUser.match?.lockOrKick(PacketUser, packet.data); break; case Packets.Client_MatchNoBeatmap: @@ -202,11 +201,11 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_MatchTransferHost: - PacketUser.match?.transferHost(PacketUser, CurrentPacket.data); + PacketUser.match?.transferHost(PacketUser, packet.data); break; case Packets.Client_MatchChangeMods: - PacketUser.match?.updateMods(PacketUser, CurrentPacket.data); + PacketUser.match?.updateMods(PacketUser, packet.data); break; case Packets.Client_MatchStart: @@ -222,7 +221,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_MatchScoreUpdate: - PacketUser.match?.updatePlayerScore(PacketUser, CurrentPacket.data); + PacketUser.match?.updatePlayerScore(PacketUser, packet.data); break; case Packets.Client_MatchFailed: @@ -234,11 +233,11 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_ChannelJoin: - PacketUser.joinChannel(CurrentPacket.data); + PacketUser.joinChannel(packet.data); break; case Packets.Client_ChannelPart: - PacketUser.leaveChannel(CurrentPacket.data); + PacketUser.leaveChannel(packet.data); break; case Packets.Client_SetAwayMessage: @@ -246,31 +245,31 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_FriendAdd: - AddFriend(PacketUser, CurrentPacket.data); + AddFriend(PacketUser, packet.data); break; case Packets.Client_FriendRemove: - RemoveFriend(PacketUser, CurrentPacket.data); + RemoveFriend(PacketUser, packet.data); break; case Packets.Client_UserStatsRequest: - UserStatsRequest(PacketUser, CurrentPacket.data); + UserStatsRequest(PacketUser, packet.data); break; case Packets.Client_SpecialMatchInfoRequest: - TourneyMatchSpecialInfo(PacketUser, CurrentPacket.data); + TourneyMatchSpecialInfo(PacketUser, packet.data); break; case Packets.Client_SpecialJoinMatchChannel: - TourneyMatchJoinChannel(PacketUser, CurrentPacket.data); + TourneyMatchJoinChannel(PacketUser, packet.data); break; case Packets.Client_SpecialLeaveMatchChannel: - TourneyMatchLeaveChannel(PacketUser, CurrentPacket.data); + TourneyMatchLeaveChannel(PacketUser, packet.data); break; case Packets.Client_Invite: - MultiplayerInvite(PacketUser, CurrentPacket.data); + MultiplayerInvite(PacketUser, packet.data); break; case Packets.Client_UserPresenceRequest: @@ -286,7 +285,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo default: // Print out unimplemented packet - console.dir(CurrentPacket); + console.dir(packet); break; } } diff --git a/server/ChatManager.ts b/server/ChatManager.ts index 6b64502..b5a92d5 100644 --- a/server/ChatManager.ts +++ b/server/ChatManager.ts @@ -69,7 +69,7 @@ export default class ChatManager { } public ForceJoinChannels(user:User) { - for (let channel of this.forceJoinChannels.getIterableItems()) { + for (const channel of this.forceJoinChannels.getIterableItems()) { channel.Join(user); } } @@ -77,7 +77,7 @@ export default class ChatManager { public SendChannelListing(user:User) { const osuPacketWriter = osu.Bancho.Writer(); - for (let channel of this.chatChannels.getIterableItems()) { + for (const channel of this.chatChannels.getIterableItems()) { if (channel.isSpecial) { continue; } diff --git a/server/LoginProcess.ts b/server/LoginProcess.ts index 009030c..a8ab24e 100644 --- a/server/LoginProcess.ts +++ b/server/LoginProcess.ts @@ -81,7 +81,7 @@ export default async function LoginProcess(req:IncomingMessage, res:ServerRespon } const loginResult:LoginResult = await TestLogin(loginInfo, shared); - let osuPacketWriter = osu.Bancho.Writer(); + const osuPacketWriter = osu.Bancho.Writer(); let newUser:User | undefined; let friendsPresence:Buffer = Buffer.alloc(0); @@ -169,10 +169,10 @@ export default async function LoginProcess(req:IncomingMessage, res:ServerRespon shared.chatManager.SendChannelListing(newUser); // Construct & send user's friends list - const userFriends = await shared.database.query("SELECT friendsWith FROM friends WHERE user = ?", [newUser.id]); + const friends = await shared.database.query("SELECT friendsWith FROM friends WHERE user = ?", [newUser.id]); const friendsArray:Array = new Array(); - for (let useFriend of userFriends) { - const friendId:number = useFriend.friendsWith; + for (const friend of friends) { + const friendId:number = friend.friendsWith; friendsArray.push(friendId); // Also fetch presence for friend if they are online diff --git a/server/MultiplayerManager.ts b/server/MultiplayerManager.ts index 4a59690..488e837 100644 --- a/server/MultiplayerManager.ts +++ b/server/MultiplayerManager.ts @@ -62,7 +62,7 @@ export default class MultiplayerManager { } let matchFull = true; - for (let slot of match.slots) { + for (const slot of match.slots) { if (slot.player instanceof User || slot.status === SlotStatus.Locked) { continue; } @@ -111,8 +111,8 @@ export default class MultiplayerManager { const osuPacketWriter = osu.Bancho.Writer(); let bufferToSend = UserPresenceBundle(this.shared); - for (let match of this.matches.getIterableItems()) { - for (let slot of match.slots) { + for (const match of this.matches.getIterableItems()) { + for (const slot of match.slots) { if (!(slot.player instanceof User) || slot.status === SlotStatus.Locked) { continue; } diff --git a/server/commands/Help.ts b/server/commands/Help.ts index b354c61..935c7a7 100644 --- a/server/commands/Help.ts +++ b/server/commands/Help.ts @@ -23,7 +23,7 @@ export default class HelpCommand extends BaseCommand { // All commands if (args.length === 0) { let constructedHelp = "Help:\n"; - for (let key of this.commandKeys) { + for (const key of this.commandKeys) { constructedHelp += ` !${key} - ${this.commandList[key].helpDescription}\n`; } channel.SendBotMessage(constructedHelp.slice(0, constructedHelp.length - 1)); diff --git a/server/objects/DataStream.ts b/server/objects/DataStream.ts index 7665764..99301a5 100644 --- a/server/objects/DataStream.ts +++ b/server/objects/DataStream.ts @@ -74,7 +74,7 @@ export default class DataStream { public Send(data:Buffer) { this.checkInactive(); - for (let user of this.users.getIterableItems()) { + for (const user of this.users.getIterableItems()) { user.addActionToQueue(data); } if (Constants.DEBUG) { @@ -85,7 +85,7 @@ export default class DataStream { public SendWithExclusion(data:Buffer, exclude:User) { this.checkInactive(); - for (let user of this.users.getIterableItems()) { + for (const user of this.users.getIterableItems()) { if (user.uuid !== exclude.uuid) { user.addActionToQueue(data); } diff --git a/server/objects/DataStreamArray.ts b/server/objects/DataStreamArray.ts index 76e907a..bb550c4 100644 --- a/server/objects/DataStreamArray.ts +++ b/server/objects/DataStreamArray.ts @@ -26,7 +26,7 @@ export default class DataStreamArray extends FunkyArray { } public RemoveUserFromAllStreams(user:User) { - for (let stream of this.getIterableItems()) { + for (const stream of this.getIterableItems()) { stream.RemoveUser(user); } } diff --git a/server/objects/FunkyArray.ts b/server/objects/FunkyArray.ts index cbecedd..cf2127c 100644 --- a/server/objects/FunkyArray.ts +++ b/server/objects/FunkyArray.ts @@ -30,7 +30,7 @@ export default class FunkyArray { public regenerateIterableArray() : void { this.iterableArray = new Array(); - for (let itemKey of this.itemKeys) { + for (const itemKey of this.itemKeys) { this.iterableArray.push(this.items[itemKey]); } this.itemKeys = Object.keys(this.items); diff --git a/server/objects/Match.ts b/server/objects/Match.ts index bf29664..619fad1 100644 --- a/server/objects/Match.ts +++ b/server/objects/Match.ts @@ -522,7 +522,7 @@ export default class Match { // All players have loaded the beatmap, start playing. if (allLoaded) { - let osuPacketWriter = osu.Bancho.Writer(); + const osuPacketWriter = osu.Bancho.Writer(); osuPacketWriter.MatchAllPlayersLoaded(); this.matchStream.Send(osuPacketWriter.toBuffer); @@ -591,7 +591,7 @@ export default class Match { this.matchLoadSlots = undefined; this.inProgress = false; - let osuPacketWriter = osu.Bancho.Writer(); + const osuPacketWriter = osu.Bancho.Writer(); let queryData:Array = [ this.matchId, diff --git a/server/objects/MatchArray.ts b/server/objects/MatchArray.ts index ab477d5..bf01c6e 100644 --- a/server/objects/MatchArray.ts +++ b/server/objects/MatchArray.ts @@ -3,7 +3,7 @@ import Match from "./Match"; export default class MatchArray extends FunkyArray { public getById(id:number) : Match | undefined { - for (let match of this.getIterableItems()) { + for (const match of this.getIterableItems()) { if (match.matchId === id) { return match; } diff --git a/server/objects/UserArray.ts b/server/objects/UserArray.ts index 21fb33b..e96f135 100644 --- a/server/objects/UserArray.ts +++ b/server/objects/UserArray.ts @@ -3,7 +3,7 @@ import User from "./User"; export default class UserArray extends FunkyArray { public getById(id:number) : User | undefined { - for (let user of this.getIterableItems()) { + for (const user of this.getIterableItems()) { if (user.id == id) return user; } @@ -12,7 +12,7 @@ export default class UserArray extends FunkyArray { } public getByUsername(username:string) : User | undefined { - for (let user of this.getIterableItems()) { + for (const user of this.getIterableItems()) { if (user.username === username) return user; } diff --git a/server/packets/UserPresenceBundle.ts b/server/packets/UserPresenceBundle.ts index a644ec3..22fecf0 100644 --- a/server/packets/UserPresenceBundle.ts +++ b/server/packets/UserPresenceBundle.ts @@ -13,7 +13,7 @@ export default function UserPresenceBundle(arg0:User | Shared) : Buffer { let userIds:Array = new Array(); - for (let userData of shared.users.getIterableItems()) { + for (const userData of shared.users.getIterableItems()) { userIds.push(userData.id); } diff --git a/server/packets/UserStatsRequest.ts b/server/packets/UserStatsRequest.ts index 978a711..492cb49 100644 --- a/server/packets/UserStatsRequest.ts +++ b/server/packets/UserStatsRequest.ts @@ -6,7 +6,7 @@ import UserPresenceBundle from "./UserPresenceBundle"; export default function UserStatsRequest(user:User, data:Array) { UserPresenceBundle(user); - for (let id of data) { + for (const id of data) { UserPresence(user, id); StatusUpdate(user, id); }