Skip to content

Commit e18d7b3

Browse files
committed
Add setting to allow offline mode
1 parent f85354c commit e18d7b3

File tree

8 files changed

+43
-23
lines changed

8 files changed

+43
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Minekube Connect allows you to connect any Minecraft server, whether online mode
1111
your protected home network or anywhere else in the world, with our highly available, performant and
1212
low latency edge proxies network nearest to you.
1313

14-
Please refer to https://developers.minekube.com/connect for more documentation.
14+
Please refer to https://connect.minekube.com for more documentation.
1515

1616
## Working setups
1717

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
allprojects {
88
group = "com.minekube.connect"
9-
version = "0.2.13"
9+
version = "0.3.0"
1010
description =
1111
"Connects the server/proxy to the global Connect network to reach more players while also supporting online mode server, bungee or velocity mode. Visit https://minekube.com/connect"
1212
}

core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ protobuf {
5858
}
5959
}
6060
}
61-
}
61+
}

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,21 @@ String get() {
130130
.url(URL)
131131
.build();
132132

133-
Response res;
134-
try {
135-
res = client.newCall(req).execute();
136-
} catch (IOException e) {
137-
e.printStackTrace();
138-
return fallback();
139-
}
133+
String name;
140134

141-
if (res.code() != 200) {
142-
return fallback();
143-
}
135+
try (Response res = client.newCall(req).execute()) {
136+
if (res.code() != 200) {
137+
return fallback();
138+
}
139+
140+
try (ResponseBody body = res.body()) {
141+
assert body != null;
142+
name = body.string();
143+
} catch (IOException e) {
144+
e.printStackTrace();
145+
return fallback();
146+
}
144147

145-
String name;
146-
try (ResponseBody body = res.body()) {
147-
assert body != null;
148-
name = body.string();
149148
} catch (IOException e) {
150149
e.printStackTrace();
151150
return fallback();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public class ConnectConfig {
4747
*/
4848
private final String endpoint = Utils.randomString(5); // default to random name
4949

50+
/**
51+
* Whether cracked players should be allowed to join.
52+
* If not set, Connect will automatically detect if the server is in offline mode.
53+
*/
54+
private Boolean allowOfflineModePlayers;
55+
5056
private static final String ENDPOINT_ENV = System.getenv("CONNECT_ENDPOINT");
5157

5258
public String getEndpoint() {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
public class WatchClient {
4646
private static final String ENDPOINT_HEADER = "Connect-Endpoint";
47+
private static final String ENDPOINT_OFFLINE_MODE_HEADER = ENDPOINT_HEADER + "-Offline-Mode";
4748
private static final String WATCH_URL = System.getenv().getOrDefault(
4849
"CONNECT_WATCH_URL", "wss://watch-connect.minekube.net");
4950

@@ -57,12 +58,17 @@ public WatchClient(@Named("connectHttpClient") OkHttpClient httpClient, ConnectC
5758
}
5859

5960
public WebSocket watch(Watcher watcher) {
60-
Request request = new Request.Builder()
61+
Request.Builder request = new Request.Builder()
6162
.url(WATCH_URL)
62-
.addHeader(ENDPOINT_HEADER, config.getEndpoint())
63-
.build();
63+
.header(ENDPOINT_HEADER, config.getEndpoint());
6464

65-
return httpClient.newWebSocket(request, new WebSocketListener() {
65+
if (config.getAllowOfflineModePlayers() != null) {
66+
request = request.header(ENDPOINT_OFFLINE_MODE_HEADER,
67+
config.getAllowOfflineModePlayers().toString());
68+
}
69+
70+
Request req = request.build();
71+
return httpClient.newWebSocket(req, new WebSocketListener() {
6672
@Override
6773
public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
6874
watcher.onCompleted();

core/src/main/resources/config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# The endpoint name of this server/proxy instance registered on startup with the Connect network.
2-
# Default is a random string. Uncomment to specify your own endpoint name.
2+
# Default is a random string. You can change it to a custom endpoint name.
33
endpoint: ${endpoint}
44

5+
# This setting is only relevant if you want to allow cracked players to join.
6+
# This should not be irritated by offline-mode servers behind an online-mode proxy, keep this setting disabled.
7+
# If left blank, the correct mode will be securely detected automatically.
8+
allow-offline-mode-players: false
9+
510
# The default locale for Connect. By default, Connect uses the system locale
611
#default-locale: en_US
712

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# The endpoint name of this server/proxy instance registered on startup with the Connect network.
2-
# Default is a random string. Uncomment to specify your own endpoint name.
2+
# Default is a random string. You can change it to a custom endpoint name.
33
endpoint: ${endpoint}
44

5+
# This setting is only relevant if you want to allow cracked players to join.
6+
# If left blank, the correct mode will be securely detected automatically.
7+
allow-offline-mode-players: false
8+
59
# The default locale for Connect. By default, Connect uses the system locale
610
#default-locale: en_US
711

0 commit comments

Comments
 (0)