Skip to content

Commit 9aba63a

Browse files
committed
proxy ping: player sample
1 parent af39e84 commit 9aba63a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/main/java/com/denizenscript/depenizen/bungee/packets/in/ProxyPingResultPacketIn.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import com.denizenscript.depenizen.bungee.DepenizenConnection;
55
import com.denizenscript.depenizen.bungee.PacketIn;
66
import io.netty.buffer.ByteBuf;
7+
import net.md_5.bungee.api.ServerPing;
78
import net.md_5.bungee.api.chat.BaseComponent;
89
import net.md_5.bungee.api.chat.TextComponent;
910
import net.md_5.bungee.api.event.ProxyPingEvent;
1011

12+
import java.util.UUID;
13+
1114
public class ProxyPingResultPacketIn extends PacketIn {
1215

1316
@Override
@@ -17,7 +20,7 @@ public String getName() {
1720

1821
@Override
1922
public void process(DepenizenConnection connection, ByteBuf data) {
20-
if (data.readableBytes() < 8 + 4 + 4) {
23+
if (data.readableBytes() < 8 + 4 + 4 + 4) {
2124
connection.fail("Invalid ProxyPingResultPacket (bytes available: " + data.readableBytes() + ")");
2225
return;
2326
}
@@ -35,6 +38,24 @@ public void process(DepenizenConnection connection, ByteBuf data) {
3538
return;
3639
}
3740
String motd = readString(data, motdLength);
41+
int playerListCount = data.readInt();
42+
if (playerListCount < -1 || playerListCount > 1024) {
43+
connection.fail("Invalid ProxyPingResultPacket (playerListCount requested: " + playerListCount + ")");
44+
return;
45+
}
46+
ServerPing.PlayerInfo[] playerInfo = playerListCount == -1 ? null : new ServerPing.PlayerInfo[playerListCount];
47+
for (int i = 0; i < playerListCount; i++) {
48+
int nameLength = data.readInt();
49+
if (data.readableBytes() < nameLength || nameLength < 0) {
50+
connection.fail("Invalid ProxyPingResultPacket (player " + i + "name bytes requested: " + nameLength + ")");
51+
return;
52+
}
53+
String name = readString(data, nameLength);
54+
long idMost = data.readLong();
55+
long idLeast = data.readLong();
56+
UUID uuid = new UUID(idMost, idLeast);
57+
playerInfo[i] = new ServerPing.PlayerInfo(name, uuid);
58+
}
3859
ProxyPingEvent event = connection.proxyEventMap.get(id);
3960
if (event == null) {
4061
return;
@@ -47,6 +68,9 @@ public void process(DepenizenConnection connection, ByteBuf data) {
4768
}
4869
event.getResponse().setDescriptionComponent(result);
4970
}
71+
if (playerInfo != null) {
72+
event.getResponse().getPlayers().setSample(playerInfo);
73+
}
5074
event.getResponse().getVersion().setName(version);
5175
event.completeIntent(DepenizenBungee.instance);
5276
connection.proxyEventMap.remove(id);

0 commit comments

Comments
 (0)