Change all for(each) blocks to use const instead of let.
This commit is contained in:
parent
25105537ea
commit
04bd1e42bb
13 changed files with 51 additions and 52 deletions
|
@ -70,7 +70,7 @@ import MultiplayerInvite from "./packets/MultiplayerInvite";
|
||||||
|
|
||||||
// User timeout interval
|
// User timeout interval
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
for (let User of shared.users.getIterableItems()) {
|
for (const User of shared.users.getIterableItems()) {
|
||||||
if (User.uuid == "bot") continue; // Ignore the bot
|
if (User.uuid == "bot") continue; // Ignore the bot
|
||||||
|
|
||||||
// Logout this user, they're clearly gone.
|
// 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
|
// Make sure the client's token isn't invalid
|
||||||
if (PacketUser != null) {
|
if (PacketUser != null) {
|
||||||
// Update the session timeout time
|
// Update the session timeout time for each request
|
||||||
PacketUser.timeoutTime = Date.now() + 60000;
|
PacketUser.timeoutTime = Date.now() + 60000;
|
||||||
|
|
||||||
// Create a new osu! packet reader
|
// Parse bancho packets
|
||||||
const osuPacketReader = osu.Client.Reader(packet);
|
const osuPacketReader = osu.Client.Reader(packet);
|
||||||
// Parse current bancho packet
|
const packets = osuPacketReader.Parse();
|
||||||
const PacketData = osuPacketReader.Parse();
|
|
||||||
|
|
||||||
// Go through each packet sent by the client
|
// Go through each packet sent by the client
|
||||||
for (let CurrentPacket of PacketData) {
|
for (const packet of packets) {
|
||||||
switch (CurrentPacket.id) {
|
switch (packet.id) {
|
||||||
case Packets.Client_ChangeAction:
|
case Packets.Client_ChangeAction:
|
||||||
ChangeAction(PacketUser, CurrentPacket.data);
|
ChangeAction(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SendPublicMessage:
|
case Packets.Client_SendPublicMessage:
|
||||||
const message:MessageData = CurrentPacket.data;
|
const message:MessageData = packet.data;
|
||||||
let channel = shared.chatManager.GetChannelByName(message.target);
|
let channel = shared.chatManager.GetChannelByName(message.target);
|
||||||
if (channel instanceof Channel) {
|
if (channel instanceof Channel) {
|
||||||
channel.SendMessage(PacketUser, CurrentPacket.data.message);
|
channel.SendMessage(PacketUser, packet.data.message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -134,11 +133,11 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_StartSpectating:
|
case Packets.Client_StartSpectating:
|
||||||
spectatorManager.startSpectating(PacketUser, CurrentPacket.data);
|
spectatorManager.startSpectating(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SpectateFrames:
|
case Packets.Client_SpectateFrames:
|
||||||
spectatorManager.spectatorFrames(PacketUser, CurrentPacket.data);
|
spectatorManager.spectatorFrames(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_StopSpectating:
|
case Packets.Client_StopSpectating:
|
||||||
|
@ -146,7 +145,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SendPrivateMessage:
|
case Packets.Client_SendPrivateMessage:
|
||||||
PrivateMessage(PacketUser, CurrentPacket.data);
|
PrivateMessage(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_JoinLobby:
|
case Packets.Client_JoinLobby:
|
||||||
|
@ -158,15 +157,15 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_CreateMatch:
|
case Packets.Client_CreateMatch:
|
||||||
await shared.multiplayerManager.CreateMatch(PacketUser, CurrentPacket.data);
|
await shared.multiplayerManager.CreateMatch(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_JoinMatch:
|
case Packets.Client_JoinMatch:
|
||||||
shared.multiplayerManager.JoinMatch(PacketUser, CurrentPacket.data);
|
shared.multiplayerManager.JoinMatch(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchChangeSlot:
|
case Packets.Client_MatchChangeSlot:
|
||||||
PacketUser.match?.moveToSlot(PacketUser, CurrentPacket.data);
|
PacketUser.match?.moveToSlot(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchReady:
|
case Packets.Client_MatchReady:
|
||||||
|
@ -174,7 +173,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchChangeSettings:
|
case Packets.Client_MatchChangeSettings:
|
||||||
await PacketUser.match?.updateMatch(PacketUser, CurrentPacket.data);
|
await PacketUser.match?.updateMatch(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchNotReady:
|
case Packets.Client_MatchNotReady:
|
||||||
|
@ -186,7 +185,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchLock:
|
case Packets.Client_MatchLock:
|
||||||
PacketUser.match?.lockOrKick(PacketUser, CurrentPacket.data);
|
PacketUser.match?.lockOrKick(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchNoBeatmap:
|
case Packets.Client_MatchNoBeatmap:
|
||||||
|
@ -202,11 +201,11 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchTransferHost:
|
case Packets.Client_MatchTransferHost:
|
||||||
PacketUser.match?.transferHost(PacketUser, CurrentPacket.data);
|
PacketUser.match?.transferHost(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchChangeMods:
|
case Packets.Client_MatchChangeMods:
|
||||||
PacketUser.match?.updateMods(PacketUser, CurrentPacket.data);
|
PacketUser.match?.updateMods(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchStart:
|
case Packets.Client_MatchStart:
|
||||||
|
@ -222,7 +221,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchScoreUpdate:
|
case Packets.Client_MatchScoreUpdate:
|
||||||
PacketUser.match?.updatePlayerScore(PacketUser, CurrentPacket.data);
|
PacketUser.match?.updatePlayerScore(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchFailed:
|
case Packets.Client_MatchFailed:
|
||||||
|
@ -234,11 +233,11 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_ChannelJoin:
|
case Packets.Client_ChannelJoin:
|
||||||
PacketUser.joinChannel(CurrentPacket.data);
|
PacketUser.joinChannel(packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_ChannelPart:
|
case Packets.Client_ChannelPart:
|
||||||
PacketUser.leaveChannel(CurrentPacket.data);
|
PacketUser.leaveChannel(packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SetAwayMessage:
|
case Packets.Client_SetAwayMessage:
|
||||||
|
@ -246,31 +245,31 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_FriendAdd:
|
case Packets.Client_FriendAdd:
|
||||||
AddFriend(PacketUser, CurrentPacket.data);
|
AddFriend(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_FriendRemove:
|
case Packets.Client_FriendRemove:
|
||||||
RemoveFriend(PacketUser, CurrentPacket.data);
|
RemoveFriend(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_UserStatsRequest:
|
case Packets.Client_UserStatsRequest:
|
||||||
UserStatsRequest(PacketUser, CurrentPacket.data);
|
UserStatsRequest(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SpecialMatchInfoRequest:
|
case Packets.Client_SpecialMatchInfoRequest:
|
||||||
TourneyMatchSpecialInfo(PacketUser, CurrentPacket.data);
|
TourneyMatchSpecialInfo(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SpecialJoinMatchChannel:
|
case Packets.Client_SpecialJoinMatchChannel:
|
||||||
TourneyMatchJoinChannel(PacketUser, CurrentPacket.data);
|
TourneyMatchJoinChannel(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_SpecialLeaveMatchChannel:
|
case Packets.Client_SpecialLeaveMatchChannel:
|
||||||
TourneyMatchLeaveChannel(PacketUser, CurrentPacket.data);
|
TourneyMatchLeaveChannel(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_Invite:
|
case Packets.Client_Invite:
|
||||||
MultiplayerInvite(PacketUser, CurrentPacket.data);
|
MultiplayerInvite(PacketUser, packet.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_UserPresenceRequest:
|
case Packets.Client_UserPresenceRequest:
|
||||||
|
@ -286,7 +285,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Print out unimplemented packet
|
// Print out unimplemented packet
|
||||||
console.dir(CurrentPacket);
|
console.dir(packet);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ export default class ChatManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForceJoinChannels(user:User) {
|
public ForceJoinChannels(user:User) {
|
||||||
for (let channel of this.forceJoinChannels.getIterableItems()) {
|
for (const channel of this.forceJoinChannels.getIterableItems()) {
|
||||||
channel.Join(user);
|
channel.Join(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ export default class ChatManager {
|
||||||
|
|
||||||
public SendChannelListing(user:User) {
|
public SendChannelListing(user:User) {
|
||||||
const osuPacketWriter = osu.Bancho.Writer();
|
const osuPacketWriter = osu.Bancho.Writer();
|
||||||
for (let channel of this.chatChannels.getIterableItems()) {
|
for (const channel of this.chatChannels.getIterableItems()) {
|
||||||
if (channel.isSpecial) {
|
if (channel.isSpecial) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ export default async function LoginProcess(req:IncomingMessage, res:ServerRespon
|
||||||
}
|
}
|
||||||
|
|
||||||
const loginResult:LoginResult = await TestLogin(loginInfo, shared);
|
const loginResult:LoginResult = await TestLogin(loginInfo, shared);
|
||||||
let osuPacketWriter = osu.Bancho.Writer();
|
const osuPacketWriter = osu.Bancho.Writer();
|
||||||
let newUser:User | undefined;
|
let newUser:User | undefined;
|
||||||
let friendsPresence:Buffer = Buffer.alloc(0);
|
let friendsPresence:Buffer = Buffer.alloc(0);
|
||||||
|
|
||||||
|
@ -169,10 +169,10 @@ export default async function LoginProcess(req:IncomingMessage, res:ServerRespon
|
||||||
shared.chatManager.SendChannelListing(newUser);
|
shared.chatManager.SendChannelListing(newUser);
|
||||||
|
|
||||||
// Construct & send user's friends list
|
// 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>();
|
const friendsArray:Array<number> = new Array<number>();
|
||||||
for (let useFriend of userFriends) {
|
for (const friend of friends) {
|
||||||
const friendId:number = useFriend.friendsWith;
|
const friendId:number = friend.friendsWith;
|
||||||
friendsArray.push(friendId);
|
friendsArray.push(friendId);
|
||||||
|
|
||||||
// Also fetch presence for friend if they are online
|
// Also fetch presence for friend if they are online
|
||||||
|
|
|
@ -62,7 +62,7 @@ export default class MultiplayerManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
let matchFull = true;
|
let matchFull = true;
|
||||||
for (let slot of match.slots) {
|
for (const slot of match.slots) {
|
||||||
if (slot.player instanceof User || slot.status === SlotStatus.Locked) {
|
if (slot.player instanceof User || slot.status === SlotStatus.Locked) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -111,8 +111,8 @@ export default class MultiplayerManager {
|
||||||
const osuPacketWriter = osu.Bancho.Writer();
|
const osuPacketWriter = osu.Bancho.Writer();
|
||||||
let bufferToSend = UserPresenceBundle(this.shared);
|
let bufferToSend = UserPresenceBundle(this.shared);
|
||||||
|
|
||||||
for (let match of this.matches.getIterableItems()) {
|
for (const match of this.matches.getIterableItems()) {
|
||||||
for (let slot of match.slots) {
|
for (const slot of match.slots) {
|
||||||
if (!(slot.player instanceof User) || slot.status === SlotStatus.Locked) {
|
if (!(slot.player instanceof User) || slot.status === SlotStatus.Locked) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export default class HelpCommand extends BaseCommand {
|
||||||
// All commands
|
// All commands
|
||||||
if (args.length === 0) {
|
if (args.length === 0) {
|
||||||
let constructedHelp = "Help:\n";
|
let constructedHelp = "Help:\n";
|
||||||
for (let key of this.commandKeys) {
|
for (const key of this.commandKeys) {
|
||||||
constructedHelp += ` !${key} - ${this.commandList[key].helpDescription}\n`;
|
constructedHelp += ` !${key} - ${this.commandList[key].helpDescription}\n`;
|
||||||
}
|
}
|
||||||
channel.SendBotMessage(constructedHelp.slice(0, constructedHelp.length - 1));
|
channel.SendBotMessage(constructedHelp.slice(0, constructedHelp.length - 1));
|
||||||
|
|
|
@ -74,7 +74,7 @@ export default class DataStream {
|
||||||
public Send(data:Buffer) {
|
public Send(data:Buffer) {
|
||||||
this.checkInactive();
|
this.checkInactive();
|
||||||
|
|
||||||
for (let user of this.users.getIterableItems()) {
|
for (const user of this.users.getIterableItems()) {
|
||||||
user.addActionToQueue(data);
|
user.addActionToQueue(data);
|
||||||
}
|
}
|
||||||
if (Constants.DEBUG) {
|
if (Constants.DEBUG) {
|
||||||
|
@ -85,7 +85,7 @@ export default class DataStream {
|
||||||
public SendWithExclusion(data:Buffer, exclude:User) {
|
public SendWithExclusion(data:Buffer, exclude:User) {
|
||||||
this.checkInactive();
|
this.checkInactive();
|
||||||
|
|
||||||
for (let user of this.users.getIterableItems()) {
|
for (const user of this.users.getIterableItems()) {
|
||||||
if (user.uuid !== exclude.uuid) {
|
if (user.uuid !== exclude.uuid) {
|
||||||
user.addActionToQueue(data);
|
user.addActionToQueue(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ export default class DataStreamArray extends FunkyArray<DataStream> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RemoveUserFromAllStreams(user:User) {
|
public RemoveUserFromAllStreams(user:User) {
|
||||||
for (let stream of this.getIterableItems()) {
|
for (const stream of this.getIterableItems()) {
|
||||||
stream.RemoveUser(user);
|
stream.RemoveUser(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ export default class FunkyArray<T> {
|
||||||
|
|
||||||
public regenerateIterableArray() : void {
|
public regenerateIterableArray() : void {
|
||||||
this.iterableArray = new Array();
|
this.iterableArray = new Array();
|
||||||
for (let itemKey of this.itemKeys) {
|
for (const itemKey of this.itemKeys) {
|
||||||
this.iterableArray.push(this.items[itemKey]);
|
this.iterableArray.push(this.items[itemKey]);
|
||||||
}
|
}
|
||||||
this.itemKeys = Object.keys(this.items);
|
this.itemKeys = Object.keys(this.items);
|
||||||
|
|
|
@ -522,7 +522,7 @@ export default class Match {
|
||||||
|
|
||||||
// All players have loaded the beatmap, start playing.
|
// All players have loaded the beatmap, start playing.
|
||||||
if (allLoaded) {
|
if (allLoaded) {
|
||||||
let osuPacketWriter = osu.Bancho.Writer();
|
const osuPacketWriter = osu.Bancho.Writer();
|
||||||
osuPacketWriter.MatchAllPlayersLoaded();
|
osuPacketWriter.MatchAllPlayersLoaded();
|
||||||
this.matchStream.Send(osuPacketWriter.toBuffer);
|
this.matchStream.Send(osuPacketWriter.toBuffer);
|
||||||
|
|
||||||
|
@ -591,7 +591,7 @@ export default class Match {
|
||||||
this.matchLoadSlots = undefined;
|
this.matchLoadSlots = undefined;
|
||||||
this.inProgress = false;
|
this.inProgress = false;
|
||||||
|
|
||||||
let osuPacketWriter = osu.Bancho.Writer();
|
const osuPacketWriter = osu.Bancho.Writer();
|
||||||
|
|
||||||
let queryData:Array<any> = [
|
let queryData:Array<any> = [
|
||||||
this.matchId,
|
this.matchId,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import Match from "./Match";
|
||||||
|
|
||||||
export default class MatchArray extends FunkyArray<Match> {
|
export default class MatchArray extends FunkyArray<Match> {
|
||||||
public getById(id:number) : Match | undefined {
|
public getById(id:number) : Match | undefined {
|
||||||
for (let match of this.getIterableItems()) {
|
for (const match of this.getIterableItems()) {
|
||||||
if (match.matchId === id) {
|
if (match.matchId === id) {
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import User from "./User";
|
||||||
|
|
||||||
export default class UserArray extends FunkyArray<User> {
|
export default class UserArray extends FunkyArray<User> {
|
||||||
public getById(id:number) : User | undefined {
|
public getById(id:number) : User | undefined {
|
||||||
for (let user of this.getIterableItems()) {
|
for (const user of this.getIterableItems()) {
|
||||||
if (user.id == id)
|
if (user.id == id)
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ export default class UserArray extends FunkyArray<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getByUsername(username:string) : User | undefined {
|
public getByUsername(username:string) : User | undefined {
|
||||||
for (let user of this.getIterableItems()) {
|
for (const user of this.getIterableItems()) {
|
||||||
if (user.username === username)
|
if (user.username === username)
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default function UserPresenceBundle(arg0:User | Shared) : Buffer {
|
||||||
|
|
||||||
let userIds:Array<number> = new Array<number>();
|
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);
|
userIds.push(userData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import UserPresenceBundle from "./UserPresenceBundle";
|
||||||
export default function UserStatsRequest(user:User, data:Array<number>) {
|
export default function UserStatsRequest(user:User, data:Array<number>) {
|
||||||
UserPresenceBundle(user);
|
UserPresenceBundle(user);
|
||||||
|
|
||||||
for (let id of data) {
|
for (const id of data) {
|
||||||
UserPresence(user, id);
|
UserPresence(user, id);
|
||||||
StatusUpdate(user, id);
|
StatusUpdate(user, id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue