Skip to content

Commit

Permalink
Add setting to allow offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Feb 21, 2023
1 parent f85354c commit e18d7b3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Minekube Connect allows you to connect any Minecraft server, whether online mode
your protected home network or anywhere else in the world, with our highly available, performant and
low latency edge proxies network nearest to you.

Please refer to https://developers.minekube.com/connect for more documentation.
Please refer to https://connect.minekube.com for more documentation.

## Working setups

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

allprojects {
group = "com.minekube.connect"
version = "0.2.13"
version = "0.3.0"
description =
"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"
}
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ protobuf {
}
}
}
}
}
27 changes: 13 additions & 14 deletions core/src/main/java/com/minekube/connect/config/ConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,21 @@ String get() {
.url(URL)
.build();

Response res;
try {
res = client.newCall(req).execute();
} catch (IOException e) {
e.printStackTrace();
return fallback();
}
String name;

if (res.code() != 200) {
return fallback();
}
try (Response res = client.newCall(req).execute()) {
if (res.code() != 200) {
return fallback();
}

try (ResponseBody body = res.body()) {
assert body != null;
name = body.string();
} catch (IOException e) {
e.printStackTrace();
return fallback();
}

String name;
try (ResponseBody body = res.body()) {
assert body != null;
name = body.string();
} catch (IOException e) {
e.printStackTrace();
return fallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public class ConnectConfig {
*/
private final String endpoint = Utils.randomString(5); // default to random name

/**
* Whether cracked players should be allowed to join.
* If not set, Connect will automatically detect if the server is in offline mode.
*/
private Boolean allowOfflineModePlayers;

private static final String ENDPOINT_ENV = System.getenv("CONNECT_ENDPOINT");

public String getEndpoint() {
Expand Down
14 changes: 10 additions & 4 deletions core/src/main/java/com/minekube/connect/watch/WatchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

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

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

public WebSocket watch(Watcher watcher) {
Request request = new Request.Builder()
Request.Builder request = new Request.Builder()
.url(WATCH_URL)
.addHeader(ENDPOINT_HEADER, config.getEndpoint())
.build();
.header(ENDPOINT_HEADER, config.getEndpoint());

return httpClient.newWebSocket(request, new WebSocketListener() {
if (config.getAllowOfflineModePlayers() != null) {
request = request.header(ENDPOINT_OFFLINE_MODE_HEADER,
config.getAllowOfflineModePlayers().toString());
}

Request req = request.build();
return httpClient.newWebSocket(req, new WebSocketListener() {
@Override
public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
watcher.onCompleted();
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# The endpoint name of this server/proxy instance registered on startup with the Connect network.
# Default is a random string. Uncomment to specify your own endpoint name.
# Default is a random string. You can change it to a custom endpoint name.
endpoint: ${endpoint}

# This setting is only relevant if you want to allow cracked players to join.
# This should not be irritated by offline-mode servers behind an online-mode proxy, keep this setting disabled.
# If left blank, the correct mode will be securely detected automatically.
allow-offline-mode-players: false

# The default locale for Connect. By default, Connect uses the system locale
#default-locale: en_US

Expand Down
6 changes: 5 additions & 1 deletion core/src/main/resources/proxy-config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# The endpoint name of this server/proxy instance registered on startup with the Connect network.
# Default is a random string. Uncomment to specify your own endpoint name.
# Default is a random string. You can change it to a custom endpoint name.
endpoint: ${endpoint}

# This setting is only relevant if you want to allow cracked players to join.
# If left blank, the correct mode will be securely detected automatically.
allow-offline-mode-players: false

# The default locale for Connect. By default, Connect uses the system locale
#default-locale: en_US

Expand Down

0 comments on commit e18d7b3

Please sign in to comment.