Change all for(each) blocks to use const instead of let.

This commit is contained in:
Holly Stubbs 2023-10-03 09:57:35 +01:00
parent 25105537ea
commit 04bd1e42bb
13 changed files with 51 additions and 52 deletions

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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<number> = new Array<number>();
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

View file

@ -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;
}

View file

@ -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));

View file

@ -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);
}

View file

@ -26,7 +26,7 @@ export default class DataStreamArray extends FunkyArray<DataStream> {
}
public RemoveUserFromAllStreams(user:User) {
for (let stream of this.getIterableItems()) {
for (const stream of this.getIterableItems()) {
stream.RemoveUser(user);
}
}

View file

@ -30,7 +30,7 @@ export default class FunkyArray<T> {
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);

View file

@ -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<any> = [
this.matchId,

View file

@ -3,7 +3,7 @@ import Match from "./Match";
export default class MatchArray extends FunkyArray<Match> {
public getById(id:number) : Match | undefined {
for (let match of this.getIterableItems()) {
for (const match of this.getIterableItems()) {
if (match.matchId === id) {
return match;
}

View file

@ -3,7 +3,7 @@ import User from "./User";
export default class UserArray extends FunkyArray<User> {
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<User> {
}
public getByUsername(username:string) : User | undefined {
for (let user of this.getIterableItems()) {
for (const user of this.getIterableItems()) {
if (user.username === username)
return user;
}

View file

@ -13,7 +13,7 @@ export default function UserPresenceBundle(arg0:User | Shared) : Buffer {
let userIds:Array<number> = new Array<number>();
for (let userData of shared.users.getIterableItems()) {
for (const userData of shared.users.getIterableItems()) {
userIds.push(userData.id);
}

View file

@ -6,7 +6,7 @@ import UserPresenceBundle from "./UserPresenceBundle";
export default function UserStatsRequest(user:User, data:Array<number>) {
UserPresenceBundle(user);
for (let id of data) {
for (const id of data) {
UserPresence(user, id);
StatusUpdate(user, id);
}