Skip to content

Commit 5cd233d

Browse files
committed
finish bungee impl
1 parent 5cc49a8 commit 5cd233d

File tree

6 files changed

+87
-26
lines changed

6 files changed

+87
-26
lines changed

bungee/src/main/java/com/lunarclient/apollo/listener/ApolloMetadataListener.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,21 @@ public ApolloMetadataListener(Plugin plugin) {
7373
*/
7474
@EventHandler
7575
public void onPluginMessage(PluginMessageEvent event) {
76+
if (!(event.getSender() instanceof ProxiedPlayer)) {
77+
System.out.println("Not a player Brand");
78+
return;
79+
}
80+
81+
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
7682
String tag = event.getTag();
7783

7884
if (tag.equals("minecraft:brand") || tag.equals("MC|Brand")) {
79-
this.handleBrand(event.getData(), event.getSender());
85+
this.handleBrand(event.getData(), player);
8086
return;
8187
}
8288

8389
if (tag.equals("fml:handshake") || tag.equals("FML|HS")) {
84-
this.handleFml(event.getData(), event.getSender());
90+
this.handleFml(event.getData(), player);
8591
}
8692
}
8793

@@ -100,17 +106,20 @@ public void onPreLogin(PreLoginEvent event) {
100106
return;
101107
}
102108

109+
String hostString;
110+
111+
if (host.getAddress() != null) {
112+
hostString = host.getAddress().getHostAddress();
113+
} else {
114+
hostString = host.getHostName();
115+
}
116+
103117
BungeeMetadataManager manager = (BungeeMetadataManager) ApolloManager.getMetadataManager();
104-
manager.getServerAddress().add(host.getAddress().getHostAddress() + ":" + host.getPort());
105-
ApolloBungeePlatform.getInstance().getPlatformLogger().log(Level.WARNING, host.getAddress().getHostAddress() + ":" + host.getPort());
118+
manager.getServerAddress().add(hostString + ":" + host.getPort());
119+
ApolloBungeePlatform.getInstance().getPlatformLogger().log(Level.WARNING, hostString + ":" + host.getPort());
106120
}
107121

108122
private void handleBrand(byte[] data, Connection sender) {
109-
if (!(sender instanceof ProxiedPlayer)) {
110-
System.out.println("Not a player Brand");
111-
return;
112-
}
113-
114123
String brand = new String(data, StandardCharsets.UTF_8);
115124
ApolloBungeePlatform.getInstance().getPlatformLogger().log(Level.WARNING, ((ProxiedPlayer) sender).getName() + " is using client brand: " + brand);
116125

@@ -119,18 +128,12 @@ private void handleBrand(byte[] data, Connection sender) {
119128
}
120129

121130
private void handleFml(byte[] data, Connection sender) {
122-
if (!(sender instanceof ProxiedPlayer)) {
123-
System.out.println("Not a player FML");
124-
return;
125-
}
126-
127131
ProxiedPlayer player = (ProxiedPlayer) sender;
128132

129133
ByteArrayDataInput in = ByteStreams.newDataInput(data);
130134
byte discriminator = in.readByte();
131135

132136
if (discriminator != 2) {
133-
System.out.println("Discriminator is not 2: " + discriminator);
134137
return;
135138
}
136139

bungee/src/main/java/com/lunarclient/apollo/metadata/BungeeMetadata.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
package com.lunarclient.apollo.metadata;
2525

2626
import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
27+
import java.util.Map;
28+
import java.util.Set;
2729
import lombok.Builder;
2830
import lombok.ToString;
29-
import java.util.Set;
3031

3132
/**
3233
* Represents the bungee metadata implementation.
@@ -46,4 +47,23 @@ public class BungeeMetadata extends PlatformMetadata {
4647
*/
4748
private final Set<String> clientBrands;
4849

50+
/**
51+
* Tracks forge mods sent with the forge handshake.
52+
*
53+
* <p>A {@link Map} of {@link String} mod id
54+
* as a key and {@link String} version as value.</p>
55+
*
56+
* @since 1.1.9
57+
*/
58+
private final Map<String, String> mods;
59+
60+
/**
61+
* Tracks the server IP and port the player used to connect.
62+
*
63+
* <p>A {@link Set} of {@link String} server addresses in the format: <code>host:port</code></p>
64+
*
65+
* @since 1.1.9
66+
*/
67+
private final Set<String> serverAddress;
68+
4969
}

bungee/src/main/java/com/lunarclient/apollo/metadata/BungeeMetadataManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525

2626
import com.lunarclient.apollo.stats.metadata.ApolloMetadataManager;
2727
import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
28-
import lombok.Getter;
29-
3028
import java.util.HashMap;
3129
import java.util.HashSet;
3230
import java.util.Map;
3331
import java.util.Set;
32+
import lombok.Getter;
3433

3534
/**
3635
* The Bungee implementation of {@link ApolloMetadataManager}.
@@ -48,11 +47,16 @@ public class BungeeMetadataManager implements ApolloMetadataManager {
4847
public PlatformMetadata extract() {
4948
return BungeeMetadata.builder()
5049
.clientBrands(new HashSet<>(this.clientBrands))
50+
.mods(new HashMap<>(this.mods))
51+
.serverAddress(new HashSet<>(this.serverAddress))
5152
.build();
5253
}
5354

5455
@Override
5556
public void clear() {
5657
this.clientBrands.clear();
58+
this.mods.clear();
59+
this.serverAddress.clear();
5760
}
61+
5862
}

bungee/src/main/java/com/lunarclient/apollo/util/ByteBufUtil.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
*/
3434
public final class ByteBufUtil {
3535

36+
/**
37+
* Reads an int from the given input stream.
38+
*
39+
* @param in in the {@link ByteArrayDataInput} to read from
40+
* @return the read int
41+
* @throws IllegalArgumentException if the value length is invalid or too large
42+
* @since 1.1.9
43+
*/
3644
public static int readVarInt(ByteArrayDataInput in) {
3745
int i = 0;
3846
int j = 0;
@@ -53,6 +61,14 @@ public static int readVarInt(ByteArrayDataInput in) {
5361
return i;
5462
}
5563

64+
/**
65+
* Reads a UTF-8 encoded string from the given input stream.
66+
*
67+
* @param in the {@link ByteArrayDataInput} to read from
68+
* @return the decoded string
69+
* @throws IllegalArgumentException if the value length is invalid or too large
70+
* @since 1.1.9
71+
*/
5672
public static String readString(ByteArrayDataInput in) {
5773
int length = ByteBufUtil.readVarInt(in);
5874
byte[] bytes = new byte[length];

common/src/main/java/com/lunarclient/apollo/stats/metadata/ApolloMetadataManager.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@
2323
*/
2424
package com.lunarclient.apollo.stats.metadata;
2525

26-
import org.jetbrains.annotations.ApiStatus;
27-
2826
/**
2927
* Represents the Apollo metadata manager, responsible for
3028
* managing and extracting metadata related to the platform.
3129
*
3230
* @since 1.1.9
3331
*/
34-
@ApiStatus.NonExtendable
3532
public interface ApolloMetadataManager {
3633

3734
/**

velocity/src/main/java/com/lunarclient/apollo/ApolloVelocityPlatform.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,34 @@ public void onProxyShutdown(ProxyShutdownEvent event) {
221221
((ApolloModuleManagerImpl) Apollo.getModuleManager()).disableModules();
222222
}
223223

224-
static {
224+
/**
225+
* Creates a {@link MinecraftChannelIdentifier} in a way that supports both
226+
* modern and legacy Velocity APIs.
227+
*
228+
* @param channel the channel in {@code namespace:key} format (e.g. {@code minecraft:brand})
229+
* @return the channel identifier object for the provided channel
230+
* @throws IllegalArgumentException if the channel format is invalid
231+
* @since 1.1.9
232+
*/
233+
public static MinecraftChannelIdentifier createChannelIdentifier(String channel) {
225234
try {
226-
PLUGIN_CHANNEL = MinecraftChannelIdentifier.from(ApolloManager.PLUGIN_MESSAGE_CHANNEL);
227-
} catch (NoSuchMethodError e) {
228-
String[] messageChannel = ApolloManager.PLUGIN_MESSAGE_CHANNEL.split(":");
229-
PLUGIN_CHANNEL = MinecraftChannelIdentifier.create(messageChannel[0], messageChannel[1]);
235+
return MinecraftChannelIdentifier.from(channel);
236+
} catch (NoSuchMethodError | IllegalArgumentException e) {
237+
if (channel.contains("|")) {
238+
return MinecraftChannelIdentifier.create(channel, "");
239+
}
240+
241+
String[] parts = channel.split(":", 2);
242+
if (parts.length != 2) {
243+
throw new IllegalArgumentException("Invalid channel identifier: " + channel);
244+
}
245+
246+
return MinecraftChannelIdentifier.create(parts[0], parts[1]);
230247
}
231248
}
232249

250+
static {
251+
PLUGIN_CHANNEL = ApolloVelocityPlatform.createChannelIdentifier(ApolloManager.PLUGIN_MESSAGE_CHANNEL);
252+
}
253+
233254
}

0 commit comments

Comments
 (0)