network: add getLobby accessor
This documents what we actually want and allows us to shift the logic to the network
This commit is contained in:
parent
c2e7390127
commit
fade6a8d2e
@ -321,7 +321,7 @@ class Client {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Set network lobby channel id
|
// Set network lobby channel id
|
||||||
network.channels[0].id = lobbyChannelId;
|
network.getLobby().id = lobbyChannelId;
|
||||||
|
|
||||||
client.networks.push(network);
|
client.networks.push(network);
|
||||||
client.emit("network", {
|
client.emit("network", {
|
||||||
@ -344,7 +344,7 @@ class Client {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (network.userDisconnected) {
|
if (network.userDisconnected) {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
text: "You have manually disconnected from this network before, use the /connect command to connect again.",
|
text: "You have manually disconnected from this network before, use the /connect command to connect again.",
|
||||||
|
@ -208,7 +208,7 @@ class Network {
|
|||||||
this.proxyEnabled = !!this.proxyEnabled;
|
this.proxyEnabled = !!this.proxyEnabled;
|
||||||
|
|
||||||
const error = function (network: Network, text: string) {
|
const error = function (network: Network, text: string) {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
type: MessageType.ERROR,
|
type: MessageType.ERROR,
|
||||||
@ -241,7 +241,7 @@ class Network {
|
|||||||
if (Config.values.public) {
|
if (Config.values.public) {
|
||||||
this.name = Config.values.defaults.name;
|
this.name = Config.values.defaults.name;
|
||||||
// Sync lobby channel name
|
// Sync lobby channel name
|
||||||
this.channels[0].name = Config.values.defaults.name;
|
this.getLobby().name = Config.values.defaults.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.host = Config.values.defaults.host;
|
this.host = Config.values.defaults.host;
|
||||||
@ -401,7 +401,7 @@ class Network {
|
|||||||
.filter((command) => command.length > 0);
|
.filter((command) => command.length > 0);
|
||||||
|
|
||||||
// Sync lobby channel name
|
// Sync lobby channel name
|
||||||
this.channels[0].name = this.name;
|
this.getLobby().name = this.name;
|
||||||
|
|
||||||
if (this.name !== oldNetworkName) {
|
if (this.name !== oldNetworkName) {
|
||||||
// Send updated network name to all connected clients
|
// Send updated network name to all connected clients
|
||||||
@ -651,6 +651,10 @@ class Network {
|
|||||||
return i > 0 && that.name.toLowerCase() === name;
|
return i > 0 && that.name.toLowerCase() === name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLobby() {
|
||||||
|
return this.channels[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Network;
|
export default Network;
|
||||||
|
@ -19,7 +19,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
time: data.time,
|
time: data.time,
|
||||||
});
|
});
|
||||||
|
|
||||||
network.channels[0].pushMessage(client, msg, true);
|
network.getLobby().pushMessage(client, msg, true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
text: `Server sent a strict transport security policy, reconnecting to ${network.host}:${port}…`,
|
text: `Server sent a strict transport security policy, reconnecting to ${network.host}:${port}…`,
|
||||||
|
@ -11,7 +11,7 @@ import {ChanType, ChanState} from "../../models/chan";
|
|||||||
export default <IrcEventHandler>function (irc, network) {
|
export default <IrcEventHandler>function (irc, network) {
|
||||||
const client = this;
|
const client = this;
|
||||||
|
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
text: "Network created, connecting to " + network.host + ":" + network.port + "...",
|
text: "Network created, connecting to " + network.host + ":" + network.port + "...",
|
||||||
@ -21,7 +21,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
|
|
||||||
irc.on("registered", function () {
|
irc.on("registered", function () {
|
||||||
if (network.irc.network.cap.enabled.length > 0) {
|
if (network.irc.network.cap.enabled.length > 0) {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
text: "Enabled capabilities: " + network.irc.network.cap.enabled.join(", "),
|
text: "Enabled capabilities: " + network.irc.network.cap.enabled.join(", "),
|
||||||
@ -44,7 +44,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
network.commands.forEach((cmd) => {
|
network.commands.forEach((cmd) => {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
client.input({
|
client.input({
|
||||||
target: network.channels[0].id,
|
target: network.getLobby().id,
|
||||||
text: cmd,
|
text: cmd,
|
||||||
});
|
});
|
||||||
}, delay);
|
}, delay);
|
||||||
@ -69,7 +69,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
network.serverOptions.PREFIX.update(irc.network.options.PREFIX);
|
network.serverOptions.PREFIX.update(irc.network.options.PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
text: "Connected to the network.",
|
text: "Connected to the network.",
|
||||||
@ -81,7 +81,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
irc.on("close", function () {
|
irc.on("close", function () {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
text: "Disconnected from the network, and will not reconnect. Use /connect to reconnect again.",
|
text: "Disconnected from the network, and will not reconnect. Use /connect to reconnect again.",
|
||||||
@ -114,7 +114,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
type: MessageType.ERROR,
|
type: MessageType.ERROR,
|
||||||
@ -151,7 +151,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
|
|
||||||
if (Config.values.debug.raw) {
|
if (Config.values.debug.raw) {
|
||||||
irc.on("raw", function (message) {
|
irc.on("raw", function (message) {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
self: !message.from_server,
|
self: !message.from_server,
|
||||||
@ -164,7 +164,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
irc.on("socket error", function (err) {
|
irc.on("socket error", function (err) {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
type: MessageType.ERROR,
|
type: MessageType.ERROR,
|
||||||
@ -175,7 +175,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
irc.on("reconnecting", function (data) {
|
irc.on("reconnecting", function (data) {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
text: `Disconnected from the network. Reconnecting in ${Math.round(
|
text: `Disconnected from the network. Reconnecting in ${Math.round(
|
||||||
@ -187,7 +187,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
irc.on("ping timeout", function () {
|
irc.on("ping timeout", function () {
|
||||||
network.channels[0].pushMessage(
|
network.getLobby().pushMessage(
|
||||||
client,
|
client,
|
||||||
new Msg({
|
new Msg({
|
||||||
text: "Ping timeout, disconnecting…",
|
text: "Ping timeout, disconnecting…",
|
||||||
|
@ -17,7 +17,7 @@ const ctcpResponses = {
|
|||||||
|
|
||||||
export default <IrcEventHandler>function (irc, network) {
|
export default <IrcEventHandler>function (irc, network) {
|
||||||
const client = this;
|
const client = this;
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
|
|
||||||
irc.on("ctcp response", function (data) {
|
irc.on("ctcp response", function (data) {
|
||||||
const shouldIgnore = network.ignoreList.some(function (entry) {
|
const shouldIgnore = network.ignoreList.some(function (entry) {
|
||||||
|
@ -17,7 +17,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
command: data.command,
|
command: data.command,
|
||||||
});
|
});
|
||||||
|
|
||||||
let target = network.channels[0];
|
let target = network.getLobby();
|
||||||
|
|
||||||
// If this error is channel specific and a channel
|
// If this error is channel specific and a channel
|
||||||
// with this name exists, put this error in that channel
|
// with this name exists, put this error in that channel
|
||||||
@ -46,7 +46,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
network.keepNick = irc.user.nick;
|
network.keepNick = irc.user.nick;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
type: MessageType.ERROR,
|
type: MessageType.ERROR,
|
||||||
text: message,
|
text: message,
|
||||||
@ -74,7 +74,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
irc.on("nick invalid", function (data) {
|
irc.on("nick invalid", function (data) {
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
type: MessageType.ERROR,
|
type: MessageType.ERROR,
|
||||||
text: data.nick + ": " + (data.reason || "Nickname is invalid."),
|
text: data.nick + ": " + (data.reason || "Nickname is invalid."),
|
||||||
|
@ -5,7 +5,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
const client = this;
|
const client = this;
|
||||||
|
|
||||||
irc.on("help", function (data) {
|
irc.on("help", function (data) {
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
|
|
||||||
if (data.help) {
|
if (data.help) {
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
|
@ -5,7 +5,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
const client = this;
|
const client = this;
|
||||||
|
|
||||||
irc.on("info", function (data) {
|
irc.on("info", function (data) {
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
|
|
||||||
if (data.info) {
|
if (data.info) {
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
|
@ -9,7 +9,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
let chan = network.getChannel(data.channel);
|
let chan = network.getChannel(data.channel);
|
||||||
|
|
||||||
if (typeof chan === "undefined") {
|
if (typeof chan === "undefined") {
|
||||||
chan = network.channels[0];
|
chan = network.getLobby();
|
||||||
}
|
}
|
||||||
|
|
||||||
const invitedYou = data.invited === irc.user.nick;
|
const invitedYou = data.invited === irc.user.nick;
|
||||||
|
@ -75,7 +75,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
!network.getChannel(data.target) ||
|
!network.getChannel(data.target) ||
|
||||||
network.getChannel(data.target)?.type !== ChanType.CHANNEL)
|
network.getChannel(data.target)?.type !== ChanType.CHANNEL)
|
||||||
) {
|
) {
|
||||||
chan = network.channels[0];
|
chan = network.getLobby();
|
||||||
from = chan.getUser(data.nick);
|
from = chan.getUser(data.nick);
|
||||||
} else {
|
} else {
|
||||||
if (shouldIgnore) {
|
if (shouldIgnore) {
|
||||||
@ -95,7 +95,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
// Send notices that are not targeted at us into the server window
|
// Send notices that are not targeted at us into the server window
|
||||||
if (data.type === MessageType.NOTICE) {
|
if (data.type === MessageType.NOTICE) {
|
||||||
showInActive = true;
|
showInActive = true;
|
||||||
chan = network.channels[0];
|
chan = network.getLobby();
|
||||||
} else {
|
} else {
|
||||||
chan = client.createChannel({
|
chan = client.createChannel({
|
||||||
type: ChanType.QUERY,
|
type: ChanType.QUERY,
|
||||||
|
@ -41,7 +41,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
irc.on("user info", function (data) {
|
irc.on("user info", function (data) {
|
||||||
const serverChan = network.channels[0];
|
const serverChan = network.getLobby();
|
||||||
|
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
type: MessageType.MODE_USER,
|
type: MessageType.MODE_USER,
|
||||||
@ -56,7 +56,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
let targetChan;
|
let targetChan;
|
||||||
|
|
||||||
if (data.target === irc.user.nick) {
|
if (data.target === irc.user.nick) {
|
||||||
targetChan = network.channels[0];
|
targetChan = network.getLobby();
|
||||||
} else {
|
} else {
|
||||||
targetChan = network.getChannel(data.target);
|
targetChan = network.getChannel(data.target);
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
// Send error to lobby if we receive empty list for a channel we're not in
|
// Send error to lobby if we receive empty list for a channel we're not in
|
||||||
if (typeof chan === "undefined") {
|
if (typeof chan === "undefined") {
|
||||||
msg.showInActive = true;
|
msg.showInActive = true;
|
||||||
chan = network.channels[0];
|
chan = network.getLobby();
|
||||||
}
|
}
|
||||||
|
|
||||||
chan.pushMessage(client, msg, true);
|
chan.pushMessage(client, msg, true);
|
||||||
|
@ -6,7 +6,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
const client = this;
|
const client = this;
|
||||||
|
|
||||||
irc.on("motd", function (data) {
|
irc.on("motd", function (data) {
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
|
|
||||||
if (data.motd) {
|
if (data.motd) {
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
|
@ -11,7 +11,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
if (self) {
|
if (self) {
|
||||||
network.setNick(data.new_nick);
|
network.setNick(data.new_nick);
|
||||||
|
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||||
text: `You're now known as ${data.new_nick}`,
|
text: `You're now known as ${data.new_nick}`,
|
||||||
|
@ -6,7 +6,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
const client = this;
|
const client = this;
|
||||||
|
|
||||||
irc.on("loggedin", (data) => {
|
irc.on("loggedin", (data) => {
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
|
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
type: MessageType.LOGIN,
|
type: MessageType.LOGIN,
|
||||||
@ -17,7 +17,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
irc.on("loggedout", () => {
|
irc.on("loggedout", () => {
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
|
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
type: MessageType.LOGOUT,
|
type: MessageType.LOGOUT,
|
||||||
|
@ -6,7 +6,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
const client = this;
|
const client = this;
|
||||||
|
|
||||||
irc.on("unknown command", function (command) {
|
irc.on("unknown command", function (command) {
|
||||||
let target = network.channels[0];
|
let target = network.getLobby();
|
||||||
|
|
||||||
// Do not display users own name
|
// Do not display users own name
|
||||||
if (command.params.length > 0 && command.params[0] === network.irc.user.nick) {
|
if (command.params.length > 0 && command.params[0] === network.irc.user.nick) {
|
||||||
|
@ -8,7 +8,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
irc.on("registered", function (data) {
|
irc.on("registered", function (data) {
|
||||||
network.setNick(data.nick);
|
network.setNick(data.nick);
|
||||||
|
|
||||||
const lobby = network.channels[0];
|
const lobby = network.getLobby();
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
text: "You're now known as " + data.nick,
|
text: "You're now known as " + data.nick,
|
||||||
});
|
});
|
||||||
|
@ -20,7 +20,7 @@ export default <IrcEventHandler>function (irc, network) {
|
|||||||
if (typeof chan === "undefined") {
|
if (typeof chan === "undefined") {
|
||||||
// Do not create new windows for errors as they may contain illegal characters
|
// Do not create new windows for errors as they may contain illegal characters
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
chan = network.channels[0];
|
chan = network.getLobby();
|
||||||
} else {
|
} else {
|
||||||
chan = client.createChannel({
|
chan = client.createChannel({
|
||||||
type: ChanType.QUERY,
|
type: ChanType.QUERY,
|
||||||
|
Loading…
Reference in New Issue
Block a user