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:
@@ -39,7 +39,7 @@ import java.util.function.Consumer;
|
|||||||
* the {@link ServerModel}, translating protocol events into {@link ConnectionListener}
|
* the {@link ServerModel}, translating protocol events into {@link ConnectionListener}
|
||||||
* callbacks for the UI.
|
* 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}. */
|
/** 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;
|
static final int MAX_ICON_BYTES = 1024 * 1024;
|
||||||
@@ -273,7 +273,12 @@ public final class TeamspeakConnection implements TS3Listener {
|
|||||||
client.setNickname(nickname);
|
client.setNickname(nickname);
|
||||||
setIfPresent(client, "client.nickname_phonetic", phoneticNickname);
|
setIfPresent(client, "client.nickname_phonetic", phoneticNickname);
|
||||||
client.setHWID("ts3jswing-" + Integer.toHexString(nickname.hashCode()));
|
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.addListener(events);
|
||||||
client.setVoiceHandler(playback::handleVoice);
|
client.setVoiceHandler(playback::handleVoice);
|
||||||
client.setWhisperHandler(whisper -> {
|
client.setWhisperHandler(whisper -> {
|
||||||
@@ -768,9 +773,13 @@ public final class TeamspeakConnection implements TS3Listener {
|
|||||||
* {@link #safeCleanup()} and the {@code connected}/announced flags this class
|
* {@link #safeCleanup()} and the {@code connected}/announced flags this class
|
||||||
* already owns, so routing it through the event handler would only add an
|
* already owns, so routing it through the event handler would only add an
|
||||||
* extra hop back into private lifecycle state.
|
* 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
|
private void socketDisconnected(LocalTeamspeakClientSocket socket, DisconnectedEvent e) {
|
||||||
public void onDisconnected(DisconnectedEvent e) {
|
if (leaving || uplink.currentSocket() != socket) return;
|
||||||
uplink.markDown();
|
uplink.markDown();
|
||||||
disconnectReasonId = e.getReasonId();
|
disconnectReasonId = e.getReasonId();
|
||||||
safeCleanup();
|
safeCleanup();
|
||||||
|
|||||||
Reference in New Issue
Block a user