Skip to content

Commit ec74d53

Browse files
committed
feat: Super Endpoints
1 parent 619fb8e commit ec74d53

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

core/src/main/java/com/minekube/connect/ConnectPlatform.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ public boolean enable(Module... postInitializeModules) {
121121
guice.getInstance(Metrics.class);
122122

123123
logger.info("Endpoint name: " + config.getEndpoint());
124+
if (config.getSuperEndpoints() != null && !config.getSuperEndpoints().isEmpty()) {
125+
logger.info("Super endpoints: " + String.join(", ", config.getSuperEndpoints()));
126+
}
124127
logger.info("Your public address: " + config.getEndpoint() + DOMAIN_SUFFIX);
125128

126129
return true;

core/src/main/java/com/minekube/connect/config/ConnectConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.minekube.connect.config;
2727

2828
import com.minekube.connect.util.Utils;
29+
import java.util.List;
2930
import lombok.Getter;
3031

3132
/**
@@ -49,10 +50,16 @@ public class ConnectConfig {
4950

5051
/**
5152
* Whether cracked players should be allowed to join.
52-
* If not set, Connect will automatically detect if the server is in offline mode.
53+
* If not set, Connect will automatically detect if the server allows cracked players.
5354
*/
5455
private Boolean allowOfflineModePlayers;
5556

57+
/**
58+
* Super endpoints are authorized to control this endpoint via Connect API.
59+
* e.g. disconnect players from this endpoint, send messages to players, etc.
60+
*/
61+
private List<String> superEndpoints;
62+
5663
private static final String ENDPOINT_ENV = System.getenv("CONNECT_ENDPOINT");
5764

5865
public String getEndpoint() {

core/src/main/java/com/minekube/connect/watch/WatchClient.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.inject.name.Named;
3030
import com.google.protobuf.InvalidProtocolBufferException;
3131
import com.minekube.connect.config.ConnectConfig;
32+
import java.io.IOException;
3233
import minekube.connect.v1alpha1.WatchServiceOuterClass.SessionRejection;
3334
import minekube.connect.v1alpha1.WatchServiceOuterClass.SessionRejection.Builder;
3435
import minekube.connect.v1alpha1.WatchServiceOuterClass.WatchRequest;
@@ -45,6 +46,7 @@
4546
public class WatchClient {
4647
private static final String ENDPOINT_HEADER = "Connect-Endpoint";
4748
private static final String ENDPOINT_OFFLINE_MODE_HEADER = ENDPOINT_HEADER + "-Offline-Mode";
49+
private static final String ENDPOINT_PARENTS_HEADER = ENDPOINT_HEADER + "-Parents";
4850
private static final String WATCH_URL = System.getenv().getOrDefault(
4951
"CONNECT_WATCH_URL", "wss://watch-connect.minekube.net");
5052

@@ -66,13 +68,19 @@ public WebSocket watch(Watcher watcher) {
6668
request = request.header(ENDPOINT_OFFLINE_MODE_HEADER,
6769
config.getAllowOfflineModePlayers().toString());
6870
}
71+
if (config.getSuperEndpoints() != null) {
72+
for (String superEndpoint : config.getSuperEndpoints()) {
73+
request = request.addHeader(ENDPOINT_PARENTS_HEADER, superEndpoint);
74+
}
75+
}
6976

7077
Request req = request.build();
7178
return httpClient.newWebSocket(req, new WebSocketListener() {
7279
@Override
7380
public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
7481
if (code != 1000) {
75-
watcher.onError(new RuntimeException("Watch closed with code " + code + ": " + reason));
82+
watcher.onError(
83+
new RuntimeException("Watch closed with code " + code + ": " + reason));
7684
return;
7785
}
7886
watcher.onCompleted();
@@ -86,7 +94,21 @@ public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String re
8694
@Override
8795
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t,
8896
@Nullable Response response) {
89-
watcher.onError(t);
97+
98+
// Try to get a more detailed error message from the server
99+
String message = null;
100+
if (response != null && response.body() != null) {
101+
try {
102+
message = response.body().string();
103+
} catch (IOException ignored) {
104+
}
105+
}
106+
107+
if (message == null || message.isEmpty()) {
108+
watcher.onError(t);
109+
} else {
110+
watcher.onError(new RuntimeException(message, t));
111+
}
90112
}
91113

92114
@Override

core/src/main/resources/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ endpoint: ${endpoint}
77
# If left blank, the correct mode will be securely detected automatically.
88
allow-offline-mode-players: false
99

10+
# Super endpoints are authorized to control this endpoint via Connect API.
11+
# e.g. disconnect players from this endpoint, send messages to players, etc.
12+
#
13+
# You can add as many super endpoint names as you want.
14+
#super-endpoints:
15+
# - pvp-endpoint
16+
# - someones-hub
17+
1018
# The default locale for Connect. By default, Connect uses the system locale
1119
#default-locale: en_US
1220

core/src/main/resources/proxy-config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ allow-offline-mode-players: false
99
# The default locale for Connect. By default, Connect uses the system locale
1010
#default-locale: en_US
1111

12+
# Super endpoints are authorized to control this endpoint via Connect API.
13+
# e.g. disconnect players from this endpoint, send messages to players, etc.
14+
#
15+
# You can add as many super endpoint names as you want.
16+
#super-endpoints:
17+
# - pvp-endpoint
18+
# - someones-hub
19+
1220
# bStats is a stat tracker that is entirely anonymous and tracks only basic information
1321
# about Connect, such as how many people are online, how many servers are using Connect,
1422
# what OS is being used, etc. You can learn more about bStats here: https://bstats.org/.

0 commit comments

Comments
 (0)