Skip to content

Commit

Permalink
Exclude reconnect query if disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Feb 23, 2024
1 parent d46be36 commit e89cc97
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
6 changes: 6 additions & 0 deletions modules/vistas-server/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/bash/data.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BUILD_NUM="1397"
BUILD_NUM="1400"
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.craftmend.openaudiomc.generic.networking.interfaces.Authenticatable;
import com.craftmend.openaudiomc.generic.networking.interfaces.SocketDriver;

import com.craftmend.openaudiomc.generic.storage.enums.StorageKey;
import com.craftmend.openaudiomc.generic.uploads.UploadIndexService;
import io.socket.client.IO;
import io.socket.client.Socket;
Expand Down Expand Up @@ -102,13 +103,20 @@ public void setupConnection() {
opts.forceNew = true;
opts.rememberUpgrade = false;

// authentication headers
opts.query = String.format(
"type=server&private=%s&public=%s&reconnect=%s",
keySet.getPrivateKey().getValue(),
keySet.getPublicKey().getValue(),
isReconnect ? "true" : "false"
);
if (StorageKey.SETTINGS_AUTO_RECONNECT.getBoolean()) {
opts.query = String.format(
"type=server&private=%s&public=%s&reconnect=%s",
keySet.getPrivateKey().getValue(),
keySet.getPublicKey().getValue(),
isReconnect ? "true" : "false"
);
} else {
opts.query = String.format(
"type=server&private=%s&public=%s",
keySet.getPrivateKey().getValue(),
keySet.getPublicKey().getValue()
);
}

// only do login handling if we're not reconnecting, because then we'd be re-using the same config
if (!isReconnect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.craftmend.openaudiomc.generic.rest.RestRequest;
import com.craftmend.openaudiomc.generic.rest.response.NoResponse;
import com.craftmend.openaudiomc.generic.rest.routes.Endpoint;
import com.craftmend.openaudiomc.generic.storage.enums.StorageKey;
import lombok.Getter;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -43,12 +44,16 @@ public VoiceSocket(String server, String password, boolean isReconnectAttempt) {

public boolean start() {
// check if connections are allowed
RestRequest preAuthCheck = new RestRequest(NoResponse.class, Endpoint.VOICE_PREFLIGHT_CHECK);
RestRequest<NoResponse> preAuthCheck = new RestRequest<>(NoResponse.class, Endpoint.VOICE_PREFLIGHT_CHECK);
AuthenticationService authenticationService = OpenAudioMc.getService(AuthenticationService.class);
preAuthCheck.setQuery("publicKey", authenticationService.getServerKeySet().getPublicKey().getValue());
preAuthCheck.setQuery("privateKey", authenticationService.getServerKeySet().getPrivateKey().getValue());
preAuthCheck.setQuery("password", this.password);
preAuthCheck.setQuery("reconnect", String.valueOf(this.isReconnectAttempt));

if (StorageKey.SETTINGS_AUTO_RECONNECT.getBoolean()) {
preAuthCheck.setQuery("reconnect", String.valueOf(this.isReconnectAttempt));
}

preAuthCheck.setBaseUrl(this.server);
preAuthCheck.run();

Expand All @@ -59,13 +64,18 @@ public boolean start() {
}

// translate url to websocket
String ebUri = new RestRequest<>(NoResponse.class, Endpoint.VOICE_BUS)
RestRequest<NoResponse> urlBuilder = new RestRequest<>(NoResponse.class, Endpoint.VOICE_BUS)
.setQuery("publicKey", authenticationService.getServerKeySet().getPublicKey().getValue())
.setQuery("privateKey", authenticationService.getServerKeySet().getPrivateKey().getValue())
.setQuery("password", this.password)
.setQuery("reconnect", String.valueOf(this.isReconnectAttempt))
.setBaseUrl(this.server)
.buildURL();
.setQuery("password", this.password);

if (StorageKey.SETTINGS_AUTO_RECONNECT.getBoolean()) {
urlBuilder.setQuery("reconnect", String.valueOf(this.isReconnectAttempt));
}

urlBuilder.setBaseUrl(this.server);

String ebUri = urlBuilder.buildURL();

ebUri = ebUri.replace("http", "ws"); // https:// => wss:// and http:// => ws://

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ public void onEnable() {
OpenAudioLogger.error(e, "A fatal error occurred while enabling OpenAudioMc. The plugin will now disable itself.");
Bukkit.getServer().getPluginManager().disablePlugin(this);
}

getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
StateService stateService = OpenAudioMc.getService(StateService.class);
if (stateService.getCurrentState().canConnect()) {
OpenAudioLogger.debug("COnnecting from loop...");
OpenAudioMc.getService(NetworkingService.class).connectIfDown();
}
}, 30 * 20, 30 * 20);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/resources/data.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BUILD_NUM="1397"
BUILD_NUM="1400"
4 changes: 2 additions & 2 deletions plugin/src/main/resources/openaudiomc-build.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BUILD_VERSION="1397"
BUILD_COMMIT="492d368d6b912f0f8b02892644baee64bbc4a3af"
BUILD_VERSION="1400"
BUILD_COMMIT="d46be3657f6a32f5a9b33ccba19238354246d040"
BUILD_AUTHOR="Mats"

0 comments on commit e89cc97

Please sign in to comment.