Skip to content

Commit

Permalink
Add fetch_ips option
Browse files Browse the repository at this point in the history
  • Loading branch information
Pugmatt committed May 7, 2023
1 parent 1e4ef82 commit afe270a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public class BedrockConnect {
public static boolean userServers = true;
public static boolean featuredServers = true;
public static boolean fetchFeaturedIps = true;

public static boolean fetchIps = false;
public static File whitelistfile;

public static String release = "1.32";
public static String release = "1.33";

public static HashMap<String, String> featuredServerIps;

Expand Down Expand Up @@ -132,6 +134,9 @@ public static void main(String[] args) {
if (str.startsWith("fetch_featured_ips=")) {
fetchFeaturedIps = getArgValue(str, "fetch_featured_ips").toLowerCase().equals("true");
}
if (str.startsWith("fetch_ips=")) {
fetchIps = getArgValue(str, "fetch_ips").toLowerCase().equals("true");
}
if (str.startsWith("whitelist=")) {
try {
whitelistfile = new File(getArgValue(str, "whitelist"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ else if (!name.isEmpty() && !name.matches("^[a-zA-Z0-9]+( +[a-zA-Z0-9]+)*$"))
return false;
}

public static boolean isDomain(String address) {
return address.matches("(?![\\d.]+)((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\\.(xn--)?([a-z0-9\\._-]{1,61}|[a-z0-9-]{1,30})");
}

public static String[] validateAddress(String server, BCPlayer player) {
if (server.split(":").length > 1) {
return server.split(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setPlayer(BCPlayer player) {

public String getIP(String hostname) {
try {
if(BedrockConnect.fetchFeaturedIps) {
if(BedrockConnect.fetchFeaturedIps || BedrockConnect.fetchIps) {
InetAddress host = InetAddress.getByName(hostname);
return host.getHostAddress();
} else {
Expand All @@ -64,7 +64,7 @@ public String getIP(String hostname) {
} catch (UnknownHostException ex) {
ex.printStackTrace();
}
return "0.0.0.0";
return hostname;
}

@Override
Expand Down Expand Up @@ -396,7 +396,11 @@ public PacketSignal handle(NetworkStackLatencyPacket packet) {
public void transfer(String ip, int port) {
try {
TransferPacket tp = new TransferPacket();
tp.setAddress(ip);
if(BedrockConnect.fetchIps && UIComponents.isDomain(ip)) {
tp.setAddress(getIP(ip));
} else {
tp.setAddress(ip);
}
tp.setPort(port);
session.sendPacketImmediately(tp);
} catch (Exception e) {
Expand Down

0 comments on commit afe270a

Please sign in to comment.