️ Make BanchoClient#channels a regular object map

Makes more sense performance and cache-wise. Also, weak-value-map-based Maps aren't iterable.
parent d6bbbfd5
......@@ -86,7 +86,7 @@ class BanchoClient extends EventEmitter {
this.partCallbacks = [];
this.users = new CacheMap();
this.usersById = new CacheMap();
this.channels = new CacheMap();
this.channels = {};
// Register our own error listener so there are no uncaught exceptions
// for exceptions WE throw for the end-user that don't need to be caught (such as timeouts)
......@@ -198,7 +198,7 @@ class BanchoClient extends EventEmitter {
*/
onClose(err) {
// Every currently joined channel should be considered left.
for(const channel of this.channels)
for(const channel of Object.values(this.channels))
if(channel[1].joined)
IrcCommands.PART.emit(this, this.getSelf(), channel[1]);
......@@ -298,10 +298,10 @@ class BanchoClient extends EventEmitter {
getChannel(channelName) {
if(channelName.indexOf("#") != 0 || channelName.indexOf(",") != -1 || channelName.indexOf("") != -1)
throw new Error("Invalid channel name!");
let channel = this.channels.get(channelName);
let channel = this.channels[channelName];
if(!channel) {
channel = (channelName.indexOf("#mp_") == 0 && this.osuApi != null) ? new BanchoMultiplayerChannel(this, channelName) : new BanchoChannel(this, channelName);
this.channels.set(channelName, channel);
this.channels[channelName] = channel;
}
return channel;
}
......
......@@ -225,7 +225,7 @@ class BanchoUser extends EventEmitter {
set id(newId) {
if(isNaN(newId))
throw new Error("id needs to be a number!");
if(this._id != null && this.banchojs.usersById.get(this._id))
if(this._id != null)
this.banchojs.usersById.delete(this._id);
this._id = newId;
this.banchojs.usersById.set(this._id, this);
......
......@@ -19,7 +19,7 @@ class QuitCommand extends IrcCommand {
* @type {BanchoUser}
*/
client.emit("QUIT", user);
for(const channel of client.channels.values())
for(const channel of Object.values(client.channels))
channel.channelMembers.delete(user.ircUsername);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment