Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocol
Submodule protocol updated 122 files
5 changes: 5 additions & 0 deletions src/main/java/org/cloudburstmc/proxypass/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public class Configuration {
private boolean invertIgnoredList = false;
@JsonProperty("ignored-packets")
private Set<String> ignoredPackets = Collections.emptySet();
@JsonProperty("ignore-resource-packs")
private boolean ignoreResourcePacks = false;

@JsonProperty("blocks-packets")
private Set<String> blocksPackets = Collections.emptySet();

public static Configuration load(Path path) throws IOException {
try (BufferedReader reader = Files.newBufferedReader(path)) {
Expand Down
37 changes: 25 additions & 12 deletions src/main/java/org/cloudburstmc/proxypass/ProxyPass.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.cloudburstmc.protocol.bedrock.BedrockPong;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v975.Bedrock_v975;
import org.cloudburstmc.protocol.bedrock.codec.v1001.Bedrock_v1001;
import org.cloudburstmc.protocol.bedrock.data.EncodingSettings;
import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition;
import org.cloudburstmc.protocol.bedrock.netty.initializer.BedrockChannelInitializer;
Expand All @@ -67,16 +67,12 @@

import java.awt.Color;
import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.*;
Expand All @@ -96,19 +92,19 @@ public class ProxyPass {
public static final YAMLMapper YAML_MAPPER = (YAMLMapper) new YAMLMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
public static final String MINECRAFT_VERSION;

public static final BedrockCodecHelper HELPER = Bedrock_v975.CODEC.createHelper();
public static final BedrockCodec CODEC = Bedrock_v975.CODEC
public static final BedrockCodecHelper HELPER = Bedrock_v1001.CODEC.createHelper();
public static final BedrockCodec CODEC = Bedrock_v1001.CODEC
.toBuilder()
.protocolVersion(975)
.minecraftVersion("1.26.20")
.protocolVersion(1001)
.minecraftVersion("1.26.30")
.helper(() -> HELPER).build();

public static final int PROTOCOL_VERSION = CODEC.getProtocolVersion();
private static final BedrockPong ADVERTISEMENT = new BedrockPong()
.edition("MCPE")
.gameType("Survival")
.version(ProxyPass.MINECRAFT_VERSION)
.protocolVersion(ProxyPass.PROTOCOL_VERSION)
.version(CODEC.getMinecraftVersion())
.protocolVersion(CODEC.getProtocolVersion())
.motd("ProxyPass")
.playerCount(0)
.maximumPlayerCount(20)
Expand Down Expand Up @@ -154,6 +150,8 @@ public void writeObjectFieldValueSeparator(JsonGenerator generator) throws IOExc
private final Set<Channel> clients = ConcurrentHashMap.newKeySet();
@Getter(AccessLevel.NONE)
private final Set<Class<?>> ignoredPackets = Collections.newSetFromMap(new IdentityHashMap<>());
@Getter(AccessLevel.NONE)
private final Set<Class<?>> blockedPackets = Collections.newSetFromMap(new IdentityHashMap<>());
private Channel server;
private int maxClients = 0;
private boolean onlineMode = false;
Expand Down Expand Up @@ -210,7 +208,18 @@ public void boot() throws IOException {
try {
ignoredPackets.add(Class.forName("org.cloudburstmc.protocol.bedrock.packet." + s));
} catch (ClassNotFoundException e) {
log.warn("No packet with name {}", s);
log.warn("No packet with name {} for ignored packets", s);
}
});

log.warn(configuration.getBlocksPackets());

configuration.getBlocksPackets().forEach(s -> {
try {
blockedPackets.add(Class.forName("org.cloudburstmc.protocol.bedrock.packet." + s));
log.warn("Blocking {}.", s);
} catch (ClassNotFoundException e) {
log.warn("No packet with name {} for blocked packets", s);
}
});

Expand Down Expand Up @@ -529,6 +538,10 @@ public boolean isIgnoredPacket(Class<?> clazz) {
return this.configuration.isInvertIgnoredList() != this.ignoredPackets.contains(clazz);
}

public boolean isBlockedPacket(Class<?> clazz) {
return this.blockedPackets.contains(clazz);
}

public boolean isFull() {
return maxClients > 0 && this.clients.size() >= maxClients;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.cloudburstmc.protocol.bedrock.BedrockSession;
import org.cloudburstmc.protocol.bedrock.netty.BedrockPacketWrapper;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.ResourcePacksInfoPacket;
import org.cloudburstmc.protocol.bedrock.packet.UnknownPacket;
import org.cloudburstmc.protocol.common.PacketSignal;
import org.cloudburstmc.proxypass.ProxyPass;
Expand All @@ -34,6 +35,25 @@ public ProxyClientSession(BedrockPeer peer, int subClientId, ProxyPass proxyPass
@Override
protected void onPacket(BedrockPacketWrapper wrapper) {
BedrockPacket packet = wrapper.getPacket();
if (proxyPass.isBlockedPacket(packet.getClass())) return;
if (packet instanceof ResourcePacksInfoPacket infoPacket && proxyPass.getConfiguration().isIgnoreResourcePacks()) {
player.getPackIds().addAll(infoPacket.getResourcePackInfos().stream().map(entry -> entry.getPackId() + "_" + entry.getPackVersion()).toList());
ResourcePacksInfoPacket newPacket = new ResourcePacksInfoPacket();
newPacket.setForcedToAccept(infoPacket.isForcedToAccept());
newPacket.setHasAddonPacks(infoPacket.isHasAddonPacks());
newPacket.setScriptingEnabled(infoPacket.isScriptingEnabled());
newPacket.setForcingServerPacksEnabled(infoPacket.isForcingServerPacksEnabled());
newPacket.setWorldTemplateId(infoPacket.getWorldTemplateId());
newPacket.setWorldTemplateVersion(infoPacket.getWorldTemplateVersion());
newPacket.setVibrantVisualsForceDisabled(infoPacket.isVibrantVisualsForceDisabled());
wrapper = BedrockPacketWrapper.create(
wrapper.getPacketId(),
wrapper.getSenderSubClientId(),
wrapper.getTargetSubClientId(),
packet, null
);
packet = newPacket;
}
player.logger.logPacket(this, wrapper, false);
if (proxyPass.getConfiguration().isPacketTesting()) {
TestUtils.testPacket(this, wrapper);
Expand All @@ -44,6 +64,10 @@ protected void onPacket(BedrockPacketWrapper wrapper) {
} else if (this.packetHandler.handlePacket(packet) == PacketSignal.UNHANDLED && this.sendSession != null) {
// this.sendSession.sendPacket(ReferenceCountUtil.retain(packet));

if (wrapper.getPacketBuffer() == null) {
this.sendSession.sendPacket(packet);
return;
}
ByteBuf buffer = wrapper.getPacketBuffer()
.retainedSlice()
.skipBytes(wrapper.getHeaderLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import java.nio.file.Path;
import java.security.KeyPair;
import java.util.ArrayList;
import java.util.List;

@Log4j2
@Getter
Expand All @@ -21,6 +23,7 @@ public class ProxyPlayerSession {
private final KeyPair proxyKeyPair;
private final Path dataPath;
private final PackDownloader packDownloader;
private final List<String> packIds = new ArrayList<>();
private volatile boolean closed = false;

public final SessionLogger logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.cloudburstmc.protocol.bedrock.BedrockSession;
import org.cloudburstmc.protocol.bedrock.netty.BedrockPacketWrapper;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.ResourcePackClientResponsePacket;
import org.cloudburstmc.protocol.bedrock.packet.ResourcePacksInfoPacket;
import org.cloudburstmc.protocol.bedrock.packet.UnknownPacket;
import org.cloudburstmc.protocol.common.PacketSignal;
import org.cloudburstmc.proxypass.ProxyPass;
Expand All @@ -34,8 +36,14 @@ public ProxyServerSession(BedrockPeer peer, int subClientId, ProxyPass proxyPass
@Override
protected void onPacket(BedrockPacketWrapper wrapper) {
BedrockPacket packet = wrapper.getPacket();
if (proxyPass.isBlockedPacket(packet.getClass())) return;
if (player != null) {
player.logger.logPacket(this, wrapper, true);
if (packet instanceof ResourcePackClientResponsePacket responsePacket && proxyPass.getConfiguration().isIgnoreResourcePacks()) {
for (String packId : player.getPackIds()) {
if (!responsePacket.getPackIds().contains(packId)) responsePacket.getPackIds().add(packId);
}
}
}

if (proxyPass.getConfiguration().isPacketTesting()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public ServerAddress(Destination destination, Account account, HttpClient client
} else {
this.address = new NetherNetAddress(netherNetId);
log.info("Resolved friend's ('{}') session handle to NetherNet ID {}", friendName, netherNetId);
this.networkProtocol = "NETHERNET_JSONRPC";
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ private static boolean verifyJwt(String jwt, PublicKey key) throws JoseException
return jws.verifySignature();
}

@Override
public PacketSignal handlePacket(BedrockPacket packet) {
return BedrockPacketHandler.super.handlePacket(packet);
}

@Override
public PacketSignal handle(RequestNetworkSettingsPacket packet) {
int protocolVersion = packet.getProtocolVersion();
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ ignored-packets:
- "NetworkChunkPublisherUpdatePacket"
- "ClientCacheBlobStatusPacket"
- "ClientCacheMissResponsePacket"
## Should ProxyPass lie and say the client already has all the packs, even if it doesn't
ignore-resource-packs: false

## Packets to block going to and from the client.
blocks-packets: []
Loading