Skip to content

Commit e3c1534

Browse files
committed
feat: replace domains that forward handles
1 parent 2357119 commit e3c1534

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

src/main/java/dev/dfonline/codeclient/hypercube/HypercubeConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
*/
66
public class HypercubeConstants {
77
public static String SERVER_ADDRESS = "mcdiamondfire.com";
8+
public static String SUBDOMAIN_SERVER_ADDRESS = "diamondfire.games";
89
}

src/main/java/dev/dfonline/codeclient/mixin/render/hud/MTitleScreen.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ public class MTitleScreen {
1717
@Inject(method = "init", at = @At("RETURN"))
1818
public void onInit(CallbackInfo ci) {
1919
if (CodeClient.startupToast != null) {
20-
// UNSECURE_SERVER_WARNING so the toast stays longer, there is no visual difference.
21-
CodeClient.MC.getToastManager().add(new SystemToast(SystemToast.Type.UNSECURE_SERVER_WARNING, CodeClient.startupToast.title(), CodeClient.startupToast.description()));
20+
CodeClient.MC.getToastManager().add(SystemToast.create(
21+
CodeClient.MC,
22+
SystemToast.Type.PACK_LOAD_FAILURE,
23+
CodeClient.startupToast.title(),
24+
CodeClient.startupToast.description())
25+
);
2226
CodeClient.startupToast = null;
2327
}
2428

src/main/java/dev/dfonline/codeclient/mixin/screen/MMultiplayerScreen.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,52 @@
1414
import org.spongepowered.asm.mixin.injection.Inject;
1515
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1616

17+
import java.util.Arrays;
1718
import java.util.List;
1819
import java.util.regex.Pattern;
1920

2021
@Mixin(MultiplayerScreen.class)
2122
public abstract class MMultiplayerScreen {
2223
@Unique
23-
private static final String[] unofficialDFAddresses = {"mcdiamondfire.net", "luke.cash", "reason.codes", "boobs.im"};
24+
private static final String[] UNOFFICIAL_DF_ADDRESSES = {"mcdiamondfire.net", "luke.cash", "reason.codes", "boobs.im", "mcdiamondfire.games"};
25+
@Unique
26+
private static final Pattern UNOFFICIAL_DF_ADDRESS_PATTERN = Pattern.compile("(?<prefix>\\w+\\.)?(?<address>" + String.join("|", UNOFFICIAL_DF_ADDRESSES) + ")(?<suffix>:\\d+)?");
27+
@Unique
28+
private static final String[] PLOT_SUBDOMAIN_ADDRESSES = {"mcdiamondfire.games"};
29+
@Unique
30+
private static final List<String> OFFICIAL_SUBDOMAINS = List.of("node1", "node2", "node3", "node4", "node5", "node6", "node7", "beta", "dev", "dev2", "dev3", "events");
31+
2432

2533
@Shadow
2634
private ServerList serverList;
2735

2836
@Inject(method = "connect(Lnet/minecraft/client/network/ServerInfo;)V", at = @At("HEAD"))
2937
public void connect(ServerInfo entry, CallbackInfo ci) {
30-
var addressPattern = String.join("|", unofficialDFAddresses);
31-
var regex = Pattern.compile("(?<prefix>\\w+\\.)?(" + addressPattern + ")(?<suffix>:\\d+)?");
32-
var matcher = regex.matcher(entry.address);
38+
var matcher = UNOFFICIAL_DF_ADDRESS_PATTERN.matcher(entry.address);
3339

3440
if (!matcher.matches()) return;
3541

36-
CodeClient.MC.getToastManager().add(new SystemToast(
37-
SystemToast.Type.UNSECURE_SERVER_WARNING,
42+
CodeClient.MC.getToastManager().add(SystemToast.create(
43+
CodeClient.MC,
44+
SystemToast.Type.PACK_LOAD_FAILURE,
3845
Text.translatable("codeclient.toast.unofficial_address.title"),
3946
Text.translatable("codeclient.toast.unofficial_address")
4047
));
4148

4249
var prefix = matcher.group("prefix");
43-
// This check is needed for domains that use a subdomain for the diamondfire redirect, such as `df.domain.tld`,
44-
// which would turn the IP to `df.mcdiamondfire.com` instead of `mcdiamondfire.com`.
45-
if (prefix == null ||
46-
// 'dev3' does not exist, but is there for future proofing.
47-
!List.of("node1", "node2", "node3", "node4", "node5", "node6", "node7", "beta", "dev", "dev2", "dev3", "events").contains(prefix)
48-
) prefix = "";
50+
boolean isSubdomainAddress = Arrays.asList(PLOT_SUBDOMAIN_ADDRESSES).contains(matcher.group("address"));
51+
if (prefix == null || (!isSubdomainAddress && !OFFICIAL_SUBDOMAINS.contains(prefix.substring(0, prefix.length() - 1)))) {
52+
prefix = "";
53+
}
54+
String address = HypercubeConstants.SERVER_ADDRESS;
55+
if (isSubdomainAddress) {
56+
address = HypercubeConstants.SUBDOMAIN_SERVER_ADDRESS;
57+
}
4958
var suffix = matcher.group("suffix");
50-
if (suffix == null) suffix = "";
51-
entry.address = prefix + HypercubeConstants.SERVER_ADDRESS + suffix;
59+
if (suffix == null) {
60+
suffix = "";
61+
}
62+
entry.address = prefix + address + suffix;
5263

5364
serverList.saveFile();
5465
}

0 commit comments

Comments
 (0)