Skip to content
This repository was archived by the owner on Jun 6, 2021. It is now read-only.

Commit 97369c8

Browse files
committed
Improved BNC network+buffer syncing; More logging
1 parent 378a76d commit 97369c8

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/libs/BouncerMiddleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function bouncerMiddleware() {
3737
host: tags.host,
3838
port: parseInt(tags.port, 10),
3939
tls: tags.tls === '1',
40-
connect: tags.state === 'connected',
40+
connected: tags.state === 'connected',
4141
nick: tags.nick,
4242
currentNick: tags.currentNick,
4343
password: tags.password || '',

src/libs/BouncerProvider.js

+23-11
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ export default class BouncerProvider {
159159

160160
// Remove any networks we have locally but no longer exist on the BNC
161161
this.state.networks.forEach((existingNet) => {
162-
let isNetworkInBncList = !bncNetworks.find((n) => (
162+
let isNetworkInBncList = !!bncNetworks.find((n) => (
163163
n.networkId === existingNet.connection.bncnetid
164164
));
165165

166166
if (existingNet !== network && !isNetworkInBncList) {
167-
log(`Network '${existingNet.name}' (${existingNet.id}) was not in the BNC, removing locally`);
167+
log.debug(`Network '${existingNet.name}' (${existingNet.id}) was not in the BNC, removing locally`);
168168
this.state.removeNetwork(existingNet.id);
169169
}
170170
});
@@ -176,10 +176,17 @@ export default class BouncerProvider {
176176
async syncBncNetwork(bncNetwork) {
177177
let client = bncNetwork.ircClient;
178178

179-
log(`Syncing network ${bncNetwork.name} from the BNC`);
179+
log.debug(`Syncing network ${bncNetwork.name} from the BNC`);
180180

181181
let buffers = await client.bnc.getBuffers(bncNetwork.connection.bncnetid);
182182
buffers.forEach((buffer) => {
183+
// The list of buffers also include the network name. Make use of it and make sure our
184+
// network name is up to date while we can. It may have changed elsewhere
185+
if (bncNetwork.name !== buffer.network) {
186+
log(`Detected network name change while syncing buffers. ${bncNetwork.name} > ${buffer.network}`);
187+
bncNetwork.name = buffer.network;
188+
}
189+
183190
let newBuffer = this.state.addBuffer(bncNetwork.id, buffer.name);
184191
if (!newBuffer) {
185192
// The BNC might be giving up bad buffer names or something, so just make sure
@@ -252,9 +259,9 @@ export default class BouncerProvider {
252259
net.connection.server = network.host;
253260
net.connection.port = parseInt(network.port, 10);
254261
net.connection.tls = network.tls;
255-
net.connection.nick = network.nick;
262+
net.connection.nick = network.account || network.nick;
256263
net.connection.password = network.password || '';
257-
net.nick = network.nick;
264+
net.nick = network.currentNick || network.nick || '';
258265
net.password = network.account_password;
259266
}
260267

@@ -278,6 +285,7 @@ export default class BouncerProvider {
278285
host: network.connection.server,
279286
port: network.connection.port,
280287
tls: network.connection.tls,
288+
account: network.connection.nick,
281289
account_password: network.password,
282290
server_password: network.connection.password,
283291
nick: network.connection.nick,
@@ -291,7 +299,7 @@ export default class BouncerProvider {
291299
saveState() {
292300
let controller = this.getController();
293301
if (!controller) {
294-
log('No controller available to save networks');
302+
log.debug('No controller available to save networks');
295303
return;
296304
}
297305

@@ -327,6 +335,9 @@ export default class BouncerProvider {
327335
if (network.password !== snapshot.account_password) {
328336
tags.account_password = network.password;
329337
}
338+
if (network.connection.nick !== snapshot.account) {
339+
tags.account = network.connection.nick;
340+
}
330341
if (network.connection.password !== snapshot.server_password) {
331342
tags.password = network.connection.password;
332343
}
@@ -340,6 +351,7 @@ export default class BouncerProvider {
340351
// A newly added network would not have a snapshot name (bncnetid) property set yet.
341352
// Only save the network if we've entered connection info.
342353
if (!snapshot.bncnetid && tags.host && tags.port && tags.nick) {
354+
log(`Saving new network ${network.name} to the BNC`);
343355
// ?? network.connection.bncname = network.name;
344356
controller.ircClient.bnc.addNetwork(
345357
network.name,
@@ -354,6 +366,7 @@ export default class BouncerProvider {
354366
network.name = networkInfo.network;
355367
});
356368
} else if (snapshot.bncnetid && Object.keys(tags).length > 0) {
369+
log(`Updating network ${network.name} on the BNC`);
357370
controller.ircClient.bnc.saveNetwork(bncnetid, tags);
358371
}
359372
});
@@ -407,7 +420,7 @@ export default class BouncerProvider {
407420
state.$on('network.connecting', (event) => {
408421
let controller = this.getController();
409422
if (!controller) {
410-
log('No controller available to save network states');
423+
log.debug('No controller available to save network states');
411424
return;
412425
}
413426

@@ -455,13 +468,12 @@ export default class BouncerProvider {
455468
state.$on('network.removed', (event) => {
456469
let controller = this.getController();
457470
if (!controller) {
458-
log('No controller available to save network states');
471+
log.debug('No controller available to save network states');
459472
return;
460473
}
461474

462475
if (event.network.connection.bncnetid) {
463-
log('Skipping removal of BNC network while in dev');
464-
// controller.ircClient.bnc.removeNetwork(event.network.connection.bncnetid);
476+
controller.ircClient.bnc.removeNetwork(event.network.connection.bncnetid);
465477
}
466478
});
467479

@@ -472,7 +484,7 @@ export default class BouncerProvider {
472484

473485
let controller = this.getController();
474486
if (!controller) {
475-
log('No controller available to save buffer states');
487+
log.debug('No controller available to save buffer states');
476488
return;
477489
}
478490

0 commit comments

Comments
 (0)