Report leaving a server once

Our own leave also fires the socket's disconnect event, queued, so it was
reported twice, and a late one could tear down a reconnect already under way.
The event now counts only for the current socket, and not while we leave.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 20:17:56 +00:00
co-authored by Claude Opus 5.5
parent cdbf051ca6
commit 8239a41c6a
@@ -39,7 +39,7 @@ import java.util.function.Consumer;
* the {@link ServerModel}, translating protocol events into {@link ConnectionListener}
* callbacks for the UI.
*/
public final class TeamspeakConnection implements TS3Listener {
public final class TeamspeakConnection {
/** Upper bound for a group icon; anything larger is not an icon. Also used by {@link ChannelAdmin}. */
static final int MAX_ICON_BYTES = 1024 * 1024;
@@ -273,7 +273,12 @@ public final class TeamspeakConnection implements TS3Listener {
client.setNickname(nickname);
setIfPresent(client, "client.nickname_phonetic", phoneticNickname);
client.setHWID("ts3jswing-" + Integer.toHexString(nickname.hashCode()));
client.addListener(this);
client.addListener(new TS3Listener() {
@Override
public void onDisconnected(DisconnectedEvent e) {
socketDisconnected(client, e);
}
});
client.addListener(events);
client.setVoiceHandler(playback::handleVoice);
client.setWhisperHandler(whisper -> {
@@ -768,9 +773,13 @@ public final class TeamspeakConnection implements TS3Listener {
* {@link #safeCleanup()} and the {@code connected}/announced flags this class
* already owns, so routing it through the event handler would only add an
* extra hop back into private lifecycle state.
*
* <p>Our own leaving fires this too, queued on the event thread, so it can run after
* {@link #disconnectBlocking} has reported the leave, or even once a newer connect has
* opened another socket. Only a socket still in use, ending without us asking, counts.
*/
@Override
public void onDisconnected(DisconnectedEvent e) {
private void socketDisconnected(LocalTeamspeakClientSocket socket, DisconnectedEvent e) {
if (leaving || uplink.currentSocket() != socket) return;
uplink.markDown();
disconnectReasonId = e.getReasonId();
safeCleanup();