Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NukkitListener implements Listener {
public void onLogin(PlayerLoginEvent ev) {
Player player = ev.getPlayer();

CloudInterface.getInstance().playerLogin(player.getName(), player.getUniqueId().toString(), player.getAddress());
CloudInterface.getInstance().playerLogin(player.getName(), player.getUniqueId().toString(), player.getRawSocketAddress().toString());
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class PNXListener implements Listener {
public void onLogin(PlayerLoginEvent ev) {
Player player = ev.getPlayer();

CloudInterface.getInstance().playerLogin(player.getName(), player.getUniqueId().toString(), player.getAddress());
CloudInterface.getInstance().playerLogin(player.getName(), player.getUniqueId().toString(), player.getRawSocketAddress().toString());
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.redstonecloud.bridge.platform.waterdogpe;

import com.google.gson.JsonObject;
import de.redstonecloud.api.redis.broker.packet.defaults.template.BestTemplateResultPacket;
import de.redstonecloud.api.redis.broker.packet.defaults.template.GetBestTemplatePacket;
import de.redstonecloud.bridge.cloudinterface.CloudInterface;
Expand Down Expand Up @@ -29,12 +30,12 @@ public WDPEHandler(

@Override
public ServerInfo resolveForcedHost(@Nullable String domain, @NonNull ProxiedPlayer player) {
return fetchServer();
return fetchServer(player);
}

@Override
public ServerInfo getFallbackServer(ProxiedPlayer player, ServerInfo oldServer, ReconnectReason reason, String kickMessage) {
return fetchServer();
return fetchServer(player);
}

@Override
Expand All @@ -43,16 +44,33 @@ public ServerInfo getFallbackServer(
@NonNull ServerInfo oldServer,
@NonNull String kickMessage
) {
return fetchServer();
return fetchServer(player);
}

@Override
public ServerInfo determineServer(ProxiedPlayer player) {
return fetchServer();
return fetchServer(player);
}

public static ServerInfo fetchServer() {
if(!CloudInterface.getBridgeConfig().has("hub_template")) return null;
public static ServerInfo fetchServer(ProxiedPlayer player) {
JsonObject cfg = CloudInterface.getBridgeConfig();
ServerInfo fallback = fetchFallback();
if(!cfg.has("hub_template")) return fallback;
boolean fallbackOnJoin = !cfg.has("fallback_on_join") || cfg.get("fallback_on_join").getAsBoolean();

if(!cfg.has("hub_template"))
return fallback;

ServerInfo hub = fetchHub();
if(hub != null) return hub;

if(player.getDownstreamConnection() != null && fallbackOnJoin)
return fallback;
Comment on lines +67 to +68
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor fallback_on_join for initial join selection

fetchServer only returns the configured fallback when player.getDownstreamConnection() != null, but the join-handler path (determineServer) runs before a downstream connection exists, so with fallback_on_join=true and no hub available the method returns null instead of the fallback server. This can block first-time joins during hub outages even though fallback is configured.

Useful? React with 👍 / 👎.


return null;
}

public static ServerInfo fetchHub() {
CompletableFuture<String> name = new CompletableFuture<>();

new GetBestTemplatePacket(CloudInterface.getBridgeConfig().get("hub_template").getAsString())
Expand All @@ -61,9 +79,17 @@ public static ServerInfo fetchServer() {

try {
BridgeServer srv = CloudInterface.getExecutor().determineServer(name.completeOnTimeout("", 3, TimeUnit.SECONDS).get().toUpperCase());
if(srv == null) return null;

return ProxyServer.getInstance().getServerInfo(srv.getName());
} catch (Exception e) {
return null;
}
}

public static ServerInfo fetchFallback() {
JsonObject cfg = CloudInterface.getBridgeConfig();
if(!cfg.has("fallback_name")) return null;
return ProxyServer.getInstance().getServerInfo(cfg.get("fallback_name").getAsString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class WDPEListener {
public static void onLogin(PlayerLoginEvent ev) {
ProxiedPlayer player = ev.getPlayer();

if(!ev.isCancelled()) CloudInterface.getInstance().playerLogin(player.getName(), player.getUniqueId().toString(), player.getAddress().getHostName());
if(!ev.isCancelled()) CloudInterface.getInstance().playerLogin(player.getName(), player.getUniqueId().toString(), player.getAddress().toString());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Send IP address without ephemeral source port

Switching login reporting to SocketAddress.toString() sends values that include the client source port (and sometimes extra formatting), so the ip field becomes different on every reconnect from the same client. This breaks stable IP-based tracking/lookup semantics for playerLogin and affects all newly changed listeners using this pattern.

Useful? React with 👍 / 👎.

if(ev.isCancelled()) CloudInterface.getInstance().playerDisconnect(player.getUniqueId().toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public HubCommand() {
@Override
public boolean onExecute(CommandSender sender, String alias, String[] args) {
if(!(sender instanceof ProxiedPlayer)) return false;
ServerInfo hub = WDPEHandler.fetchServer();
ServerInfo hub = WDPEHandler.fetchServer((ProxiedPlayer) sender);
if(hub == null) {
sender.sendMessage(CloudInterface.getBridgeConfig().has("hubcommand_no_hub_available") ? CloudInterface.getBridgeConfig().get("hubcommand_no_hub_available").getAsString() : "No hub available");
return true;
Expand Down
Loading