Keep the error id a server refused the last connect with
The message alone does not tell a ban from a refusal worth retrying. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -141,6 +141,8 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
/** Guards against announcing the same disconnect from both the event and the teardown. */
|
||||
private volatile boolean disconnectAnnounced = true;
|
||||
private volatile long lastMutedTalkNanos;
|
||||
/** The server's error id for why the last connect was refused; 0 when it was not. */
|
||||
private volatile int connectErrorId;
|
||||
|
||||
public TeamspeakConnection(Settings settings, AudioBackend audio, ConnectionListener ui,
|
||||
SoundNotifier sounds, ContactStore contacts) {
|
||||
@@ -173,6 +175,14 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
return playback;
|
||||
}
|
||||
|
||||
/**
|
||||
* The error id the server refused the last connect with ({@code 3329} for a ban,
|
||||
* for one), or 0 when it was not refused or did not get that far.
|
||||
*/
|
||||
public int getConnectErrorId() {
|
||||
return connectErrorId;
|
||||
}
|
||||
|
||||
/** The identity this connection authenticated with. */
|
||||
public LocalIdentity getIdentity() {
|
||||
return identity;
|
||||
@@ -257,6 +267,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
String channel, String channelPassword) {
|
||||
Object attempt = new Object();
|
||||
connectAttempt = attempt;
|
||||
connectErrorId = 0;
|
||||
// A socket or audio line an earlier connect left behind must not outlive it.
|
||||
connected = false;
|
||||
safeCleanup();
|
||||
@@ -363,6 +374,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
// connect has set up in the meantime.
|
||||
if (connectAttempt != attempt) return;
|
||||
connected = false;
|
||||
connectErrorId = refusalId(e);
|
||||
String failure = "Connection failed: " + rootMessage(e) + versionHint(e);
|
||||
ui.onError(failure);
|
||||
safeCleanup();
|
||||
@@ -373,6 +385,13 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private static int refusalId(Throwable e) {
|
||||
for (Throwable t = e; t != null; t = t.getCause()) {
|
||||
if (t instanceof CommandException refusal) return refusal.getErrorId();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* "client is modified" is what a server answers when it does not accept the reported
|
||||
* version: too old for its minimum, not a version it knows for that platform, or a
|
||||
|
||||
Reference in New Issue
Block a user