Some fixes, stuck on downloading terrain

This commit is contained in:
catfoolyou
2025-02-25 11:29:11 -05:00
parent f2c62cf5c7
commit cf21caabb0
21 changed files with 106 additions and 157 deletions

View File

@@ -71,6 +71,8 @@ public final class UserConnection implements ProxiedPlayer
private int clientEntityId;
private final Map<String, Object> attachment = new WeakHashMap();
public void setServer(ServerConnection server) {
this.server = server;
}
@@ -239,11 +241,11 @@ public final class UserConnection implements ProxiedPlayer
this.tabList = tabList;
}
public void sendPacket(PacketWrapper packet)
{
ch.write( packet );
public void sendPacket(final byte[] b) {
this.ch.write(b);
}
@Deprecated
public boolean isActive()
{
@@ -429,8 +431,7 @@ public final class UserConnection implements ProxiedPlayer
@Override
public Map<String, Object> getAttachment() { // fix this (maybe)
System.out.println("This might be a problem");
return Map.of();
return attachment;
}
@Override

View File

@@ -9,6 +9,7 @@ import java.io.DataInput;
import java.net.InetAddress;
import java.util.Objects;
import io.netty.buffer.Unpooled;
import net.md_5.bungee.*;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
@@ -71,12 +72,10 @@ public class DownstreamBridge extends PacketHandler
}
@Override
public void handle(PacketWrapper packet) throws Exception
{
if ( !server.isObsolete() )
{
EntityMap.rewrite( packet.buf, con.getServerEntityId(), con.getClientEntityId() );
con.sendPacket( packet );
public void handle(final byte[] buf) throws Exception {
if (!this.server.isObsolete()) {
EntityMap.rewrite(Unpooled.wrappedBuffer(buf), this.con.getServerEntityId(), this.con.getClientEntityId());
this.con.sendPacket(buf);
}
}

View File

@@ -65,6 +65,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection {
@Override
public void connected(final ChannelWrapper channel) throws Exception {
System.out.println("[InitialHandler] - connected (I think)");
this.ch = channel;
}

View File

@@ -1,5 +1,6 @@
package net.md_5.bungee.connection;
import io.netty.buffer.Unpooled;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.EntityMap;
import net.md_5.bungee.UserConnection;
@@ -57,12 +58,10 @@ public class UpstreamBridge extends PacketHandler
}
@Override
public void handle(PacketWrapper packet) throws Exception
{
EntityMap.rewrite( packet.buf, con.getClientEntityId(), con.getServerEntityId() );
if ( con.getServer() != null )
{
con.getServer().getCh().write( packet );
public void handle(final byte[] buf) throws Exception {
EntityMap.rewrite(Unpooled.wrappedBuffer(buf), this.con.getClientEntityId(), this.con.getServerEntityId());
if (this.con.getServer() != null && this.con.getServer().getCh() != null) {
this.con.getServer().getCh().write(buf); // Change to buf if its a problem
}
}

View File

@@ -180,7 +180,6 @@ public class WebSocketListener extends WebSocketServer {
System.out.println("[WebsocketListener] - onMessage called");
Object o = arg0.getAttachment();
if(o == null || (o instanceof PendingSocket)) {
System.out.println("o is null");
InetAddress realAddr;
if(o == null) {
realAddr = arg0.getRemoteSocketAddress().getAddress();
@@ -210,7 +209,6 @@ public class WebSocketListener extends WebSocketServer {
o = proxyObj;
}
if(o != null) {
System.out.println("o is not null");
if(o instanceof WebSocketProxy) {
System.out.println("Instance of WebSocketProxy, sending packet");
((WebSocketProxy)o).sendPacket(arg1);

View File

@@ -1,123 +1,88 @@
//
// Decompiled by Procyon v0.5.36
//
package net.md_5.bungee.netty;
import com.google.common.base.Preconditions;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.ReadTimeoutException;
import java.io.IOException;
import java.util.logging.Level;
import com.google.common.base.Preconditions;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.MessageList;
import io.netty.handler.timeout.ReadTimeoutException;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.connection.CancelSendSignal;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.connection.PingHandler;
import net.md_5.bungee.protocol.BadPacketException;
/**
* This class is a primitive wrapper for {@link PacketHandler} instances tied to
* channels to maintain simple states, and only call the required, adapted
* methods when the channel is connected.
*/
public class HandlerBoss extends ChannelInboundHandlerAdapter
{
public class HandlerBoss extends ChannelInboundHandlerAdapter {
private ChannelWrapper channel;
private PacketHandler handler;
public void setHandler(PacketHandler handler)
{
Preconditions.checkArgument( handler != null, "handler" );
public void setHandler(final PacketHandler handler) {
Preconditions.checkArgument(handler != null, (Object) "handler");
this.handler = handler;
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception
{
if ( handler != null )
{
channel = new ChannelWrapper( ctx );
handler.connected( channel );
if ( !( handler instanceof InitialHandler || handler instanceof PingHandler ) )
{
ProxyServer.getInstance().getLogger().log( Level.INFO, "{0} has connected", handler );
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
if (this.handler != null) {
this.channel = new ChannelWrapper(ctx);
this.handler.connected(this.channel);
if (!(this.handler instanceof InitialHandler) && !(this.handler instanceof PingHandler)) {
ProxyServer.getInstance().getLogger().log(Level.INFO, "{0} has connected", this.handler);
}
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception
{
if ( handler != null )
{
handler.disconnected( channel );
if ( !( handler instanceof InitialHandler || handler instanceof PingHandler ) )
{
ProxyServer.getInstance().getLogger().log( Level.INFO, "{0} has disconnected", handler );
public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
if (this.handler != null) {
this.handler.disconnected(this.channel);
if (!(this.handler instanceof InitialHandler) && !(this.handler instanceof PingHandler)) {
ProxyServer.getInstance().getLogger().log(Level.INFO, "{0} has disconnected", this.handler);
}
}
}
//@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
{
if ( handler != null )
{
PacketWrapper packet = (PacketWrapper) msg;
boolean sendPacket = true;
try
{
if ( packet.packet != null )
{
try
{
packet.packet.handle( handler );
} catch ( CancelSendSignal ex )
{
public void messageReceived(final ChannelHandlerContext ctx, final MessageList<Object> msgs) throws Exception {
for (final Object msg : msgs) {
if (this.handler != null && ctx.channel().isActive()) {
if (msg instanceof PacketWrapper) {
boolean sendPacket = true;
try {
((PacketWrapper) msg).packet.handle(this.handler);
} catch (CancelSendSignal ex) {
sendPacket = false;
}
if (!sendPacket) {
continue;
}
this.handler.handle(((PacketWrapper) msg).buf);
} else {
this.handler.handle((byte[]) msg);
}
if ( sendPacket )
{
handler.handle( packet );
}
} finally
{
packet.trySingleRelease();
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
{
if ( ctx.channel().isActive() )
{
if ( cause instanceof ReadTimeoutException )
{
ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - read timed out" );
} else if ( cause instanceof BadPacketException )
{
ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - bad packet ID, are mods in use!?" );
} else if ( cause instanceof IOException )
{
ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - IOException: " + cause.getMessage() );
} else
{
ProxyServer.getInstance().getLogger().log( Level.SEVERE, handler + " - encountered exception", cause );
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
if (ctx.channel().isActive()) {
if (cause instanceof ReadTimeoutException) {
ProxyServer.getInstance().getLogger().log(Level.WARNING, this.handler + " - read timed out");
} else if (cause instanceof IOException) {
ProxyServer.getInstance().getLogger().log(Level.WARNING, this.handler + " - IOException: " + cause.getMessage());
} else {
ProxyServer.getInstance().getLogger().log(Level.SEVERE, this.handler + " - encountered exception", cause);
}
if ( handler != null )
{
try
{
handler.exception( cause );
} catch ( Exception ex )
{
ProxyServer.getInstance().getLogger().log( Level.SEVERE, handler + " - exception processing exception", ex );
if (this.handler != null) {
try {
this.handler.exception(cause);
} catch (Exception ex) {
ProxyServer.getInstance().getLogger().log(Level.SEVERE, this.handler + " - exception processing exception", ex);
}
}
ctx.close();
}
}

View File

@@ -28,7 +28,7 @@ public class PacketDecoder extends ReplayingDecoder<Void> {
in.readerIndex(endIndex);
this.checkpoint();
if (packet != null) {
out.add((Object) new PacketWrapper(packet, Unpooled.wrappedBuffer(buf)));
out.add((Object) new PacketWrapper(packet, buf));
} else {
out.add((Object) buf);
}

View File

@@ -10,7 +10,7 @@ public abstract class PacketHandler extends net.md_5.bungee.protocol.packet.Abst
{
}
public void handle(PacketWrapper packet) throws Exception
public void handle(byte[] buf) throws Exception
{
}

View File

@@ -1,31 +1,13 @@
package net.md_5.bungee.netty;
import io.netty.buffer.ByteBuf;
import net.md_5.bungee.protocol.packet.DefinedPacket;
public class PacketWrapper
{
public class PacketWrapper {
DefinedPacket packet;
byte[] buf;
public final DefinedPacket packet;
public final ByteBuf buf;
public PacketWrapper(DefinedPacket packet, ByteBuf buf) {
public PacketWrapper(final DefinedPacket packet, final byte[] buf) {
this.packet = packet;
this.buf = buf;
}
public void setReleased(boolean released) {
this.released = released;
}
private boolean released;
public void trySingleRelease()
{
if ( !released )
{
buf.release();
released = true;
}
}
}
}