|
14 | 14 | import org.spongepowered.asm.mixin.injection.Inject; |
15 | 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
16 | 16 |
|
| 17 | +import java.util.Arrays; |
17 | 18 | import java.util.List; |
18 | 19 | import java.util.regex.Pattern; |
19 | 20 |
|
20 | 21 | @Mixin(MultiplayerScreen.class) |
21 | 22 | public abstract class MMultiplayerScreen { |
22 | 23 | @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 | + |
24 | 32 |
|
25 | 33 | @Shadow |
26 | 34 | private ServerList serverList; |
27 | 35 |
|
28 | 36 | @Inject(method = "connect(Lnet/minecraft/client/network/ServerInfo;)V", at = @At("HEAD")) |
29 | 37 | 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); |
33 | 39 |
|
34 | 40 | if (!matcher.matches()) return; |
35 | 41 |
|
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, |
38 | 45 | Text.translatable("codeclient.toast.unofficial_address.title"), |
39 | 46 | Text.translatable("codeclient.toast.unofficial_address") |
40 | 47 | )); |
41 | 48 |
|
42 | 49 | 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 | + } |
49 | 58 | 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; |
52 | 63 |
|
53 | 64 | serverList.saveFile(); |
54 | 65 | } |
|
0 commit comments