downgrade netty to old version to fix annoying network bugs WHYYYYYYYYYYYYYYYYYYYYY?!?!?!?!

This commit is contained in:
Sen 2025-05-25 17:53:55 +02:00
parent 10fdaf0b1a
commit 77b5a34a33
15 changed files with 51 additions and 220 deletions

View file

@ -71,6 +71,7 @@ import client.renderer.texture.EntityTexManager;
import client.renderer.texture.TextureManager;
import client.renderer.texture.TextureMap;
import client.util.FileUtils;
import client.util.Message;
import client.util.PerfSection;
import client.util.PlayerController;
import client.vars.BoolVar;
@ -129,19 +130,18 @@ import common.item.ItemControl;
import common.item.ItemStack;
import common.log.Log;
import common.log.LogLevel;
import common.log.Message;
import common.network.IThreadListener;
import common.network.NetConnection;
import common.network.PacketDecoder;
import common.network.PacketEncoder;
import common.network.PacketPrepender;
import common.network.PacketRegistry;
import common.network.PacketSplitter;
import common.network.NetHandler.ThreadQuickExitException;
import common.packet.CPacketAction;
import common.packet.CPacketCheat;
import common.packet.CPacketMessage;
import common.packet.HPacketHandshake;
import common.packet.LPacketLogin;
import common.packet.CPacketAction.Action;
import common.potion.Potion;
import common.potion.PotionEffect;
@ -171,6 +171,8 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
/*
Een net ganz funktionierndes Programm ...
@ -513,13 +515,16 @@ public class Client implements IThreadListener {
public void connect(String address, int port, String user, String pass, String access) {
this.displayGuiScreen(GuiLoading.makeWaitTask("Verbinde zu " + (address == null ? "localhost" : address) + ":" + port + " ..."));
Log.JNI.info("Verbinde zu " + (address == null ? "localhost" : address) + ":" + port);
NetConnection connection = null;
final NetConnection connection;
try
{
connection = createNetworkManagerAndConnect(address == null ? InetAddress.getLoopbackAddress() : InetAddress.getByName(IDN.toASCII(address)), port);
connection.setNetHandler(new ClientLoginHandler(connection, this, user, access, pass));
connection.sendPacket(new HPacketHandshake(Config.PROTOCOL));
connection.sendPacket(new LPacketLogin());
connection.sendPacket(new HPacketHandshake(Config.PROTOCOL), new GenericFutureListener<Future<? super Void>>() {
public void operationComplete(Future<? super Void> u) throws Exception {
connection.setConnectionState(PacketRegistry.LOGIN);
}
});
}
catch (UnknownHostException u)
{
@ -793,8 +798,10 @@ public class Client implements IThreadListener {
}
else if (this.connection != null)
{
this.connection.processReceivedPackets();
this.connection.checkDisconnected();
if(this.connection.isChannelOpen())
this.connection.processReceivedPackets();
else
this.connection.checkDisconnected();
}
}
@ -2649,9 +2656,21 @@ public class Client implements IThreadListener {
});
this.registerDebug(Keysym.AE, "Programm sofort beenden und server beenden", new DebugRunner() {
public void execute(Keysym key) {
if(Client.this.player != null)
Client.this.player.client.addToSendQueue(new CPacketMessage(CPacketMessage.Type.COMMAND, "shutdown"));
Client.this.interrupted = true;
if(Client.this.getNetHandler() != null) {
Client.this.getNetHandler().getNetworkManager().sendPacket(new CPacketMessage(CPacketMessage.Type.COMMAND, "shutdown"), new GenericFutureListener<Future<? super Void>>() {
public void operationComplete(Future<? super Void> u) throws Exception {
try {
Thread.sleep(1000L);
}
catch(InterruptedException e) {
}
Client.this.interrupted = true;
}
});
}
else {
Client.this.interrupted = true;
}
}
});
}

View file

@ -18,7 +18,7 @@ public class GuiInfo extends Gui {
private static final String[] LIBRARIES = {
"LWJGL 3.3.6+1 (GLFW + OpenGL)",
"Netty 4.1.119-Final"
"Netty 4.0.23-Final"
};
private static final String[] CODE = {
"Albert Pham - WorldEdit (Snippets)",

View file

@ -45,6 +45,7 @@ public class ClientLoginHandler extends NetHandler implements IClientLoginHandle
}
public void handleEncrypt(RPacketRequestEncrypt packet) {
this.networkManager.setConnectionState(PacketRegistry.LOGIN);
final SecretKey secret = EncryptUtil.createNewSharedKey();
PublicKey pubkey = packet.getKey();
this.networkManager.sendPacket(new LPacketStartEncrypt(secret, pubkey, packet.getToken()), new GenericFutureListener < Future <? super Void >> () {

View file

@ -1,4 +1,4 @@
package common.log;
package client.util;
public class Message {
public final String message;

View file

@ -14,8 +14,6 @@ import java.util.Locale;
import javax.imageio.ImageIO;
import common.log.NettyLogger;
public abstract class Registry {
private static boolean crashed;
@ -116,7 +114,6 @@ public abstract class Registry {
timer.setDaemon(true);
timer.start();
System.setProperty("java.net.preferIPv4Stack", "true");
NettyLogger.init();
register();
}

View file

@ -1,170 +0,0 @@
package common.log;
import java.io.PrintWriter;
import java.io.StringWriter;
import io.netty.util.internal.logging.AbstractInternalLogger;
import io.netty.util.internal.logging.FormattingTuple;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import io.netty.util.internal.logging.MessageFormatter;
public class NettyLogger extends AbstractInternalLogger {
public static void init() {
InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
protected InternalLogger newInstance(String name) {
return new NettyLogger(name);
}
});
}
private NettyLogger(String name) {
super(name);
}
public boolean isTraceEnabled() {
return Log.getLevel().ordinal() >= LogLevel.TRACE.ordinal();
}
public void trace(String msg) {
this.log(LogLevel.TRACE, msg, null);
}
public void trace(String format, Object arg) {
FormattingTuple ft = MessageFormatter.format(format, arg);
this.log(LogLevel.TRACE, ft.getMessage(), ft.getThrowable());
}
public void trace(String format, Object argA, Object argB) {
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
this.log(LogLevel.TRACE, ft.getMessage(), ft.getThrowable());
}
public void trace(String format, Object... argArray) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
this.log(LogLevel.TRACE, ft.getMessage(), ft.getThrowable());
}
public void trace(String msg, Throwable t) {
this.log(LogLevel.TRACE, msg, t);
}
public boolean isDebugEnabled() {
return Log.getLevel().ordinal() >= LogLevel.DEBUG.ordinal();
}
public void debug(String msg) {
this.log(LogLevel.DEBUG, msg, null);
}
public void debug(String format, Object arg) {
FormattingTuple ft = MessageFormatter.format(format, arg);
this.log(LogLevel.DEBUG, ft.getMessage(), ft.getThrowable());
}
public void debug(String format, Object argA, Object argB) {
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
this.log(LogLevel.DEBUG, ft.getMessage(), ft.getThrowable());
}
public void debug(String format, Object... argArray) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
this.log(LogLevel.DEBUG, ft.getMessage(), ft.getThrowable());
}
public void debug(String msg, Throwable t) {
this.log(LogLevel.DEBUG, msg, t);
}
public boolean isInfoEnabled() {
return Log.getLevel().ordinal() >= LogLevel.INFO.ordinal();
}
public void info(String msg) {
this.log(LogLevel.INFO, msg, null);
}
public void info(String format, Object arg) {
FormattingTuple ft = MessageFormatter.format(format, arg);
this.log(LogLevel.INFO, ft.getMessage(), ft.getThrowable());
}
public void info(String format, Object argA, Object argB) {
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
this.log(LogLevel.INFO, ft.getMessage(), ft.getThrowable());
}
public void info(String format, Object... argArray) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
this.log(LogLevel.INFO, ft.getMessage(), ft.getThrowable());
}
public void info(String msg, Throwable t) {
this.log(LogLevel.INFO, msg, t);
}
public boolean isWarnEnabled() {
return Log.getLevel().ordinal() >= LogLevel.WARN.ordinal();
}
public void warn(String msg) {
this.log(LogLevel.WARN, msg, null);
}
public void warn(String format, Object arg) {
FormattingTuple ft = MessageFormatter.format(format, arg);
this.log(LogLevel.WARN, ft.getMessage(), ft.getThrowable());
}
public void warn(String format, Object argA, Object argB) {
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
this.log(LogLevel.WARN, ft.getMessage(), ft.getThrowable());
}
public void warn(String format, Object... argArray) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
this.log(LogLevel.WARN, ft.getMessage(), ft.getThrowable());
}
public void warn(String msg, Throwable t) {
this.log(LogLevel.WARN, msg, t);
}
public boolean isErrorEnabled() {
return Log.getLevel().ordinal() >= LogLevel.ERROR.ordinal();
}
public void error(String msg) {
this.log(LogLevel.ERROR, msg, null);
}
public void error(String format, Object arg) {
FormattingTuple ft = MessageFormatter.format(format, arg);
this.log(LogLevel.ERROR, ft.getMessage(), ft.getThrowable());
}
public void error(String format, Object argA, Object argB) {
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
this.log(LogLevel.ERROR, ft.getMessage(), ft.getThrowable());
}
public void error(String format, Object... arguments) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
this.log(LogLevel.ERROR, ft.getMessage(), ft.getThrowable());
}
public void error(String msg, Throwable t) {
this.log(LogLevel.ERROR, msg, t);
}
private void log(LogLevel level, String msg, Throwable t) {
Log.NETTY.log(level, msg);
if(t != null) {
StringWriter sw = new StringWriter();
PrintWriter st = new PrintWriter(sw);
t.printStackTrace(st);
sw.flush();
Log.NETTY.log(level, sw.toString().trim().replace('\t', ' '));
}
}
}

View file

@ -1,11 +1,9 @@
package common.network;
import common.packet.LPacketLogin;
import common.packet.LPacketPasswordResponse;
import common.packet.LPacketStartEncrypt;
public interface ILoginHandler {
void processPasswordResponse(LPacketPasswordResponse packet);
void processEncryption(LPacketStartEncrypt packet);
void processLogin(LPacketLogin packet);
}

View file

@ -24,6 +24,7 @@ import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
public class NetConnection extends SimpleChannelInboundHandler<Packet> {
private static final boolean DEBUG = System.getProperty("network.debug") != null;
private static final Pattern IP_REPLACER = Pattern.compile("([0-9]*)\\.([0-9]*)\\.[0-9]*\\.[0-9]*");
public static final AttributeKey<PacketRegistry> ATTR_STATE = AttributeKey.<PacketRegistry>valueOf("protocol");
@ -52,7 +53,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
public void setConnectionState(PacketRegistry newState) {
this.channel.attr(ATTR_STATE).set(newState);
this.channel.config().setAutoRead(true);
// Log.debug("Automatisches Lesen eingeschaltet");
if(DEBUG)
Log.SYSTEM.info("Automatisches Lesen eingeschaltet");
}
public void channelInactive(ChannelHandlerContext context) throws Exception {
@ -75,6 +77,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
}
protected void channelRead0(ChannelHandlerContext context, Packet packet) throws Exception {
if(DEBUG)
Log.SYSTEM.info("EIN: [" + context.channel().attr(NetConnection.ATTR_STATE).get() + "] " + packet.getClass().getName());
if(this.channel.isOpen()) {
try {
packet.processPacket(this.handler);
@ -132,7 +136,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
final PacketRegistry current = this.channel.attr(ATTR_STATE).get();
if(current != state) {
// Log.debug("Automatisches Lesen ausgeschaltet");
if(DEBUG)
Log.SYSTEM.info("Automatisches Lesen ausgeschaltet");
this.channel.config().setAutoRead(false);
}
@ -141,6 +146,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
this.setConnectionState(state);
}
if(DEBUG)
Log.SYSTEM.info("AUS: [" + this.channel.attr(NetConnection.ATTR_STATE).get() + "] " + packet.getClass().getName());
ChannelFuture future = this.channel.writeAndFlush(packet);
if(listeners != null) {
@ -156,6 +163,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
NetConnection.this.setConnectionState(state);
}
if(DEBUG)
Log.SYSTEM.info("AUS: [" + NetConnection.this.channel.attr(NetConnection.ATTR_STATE).get() + "] " + packet.getClass().getName());
ChannelFuture future = NetConnection.this.channel.writeAndFlush(packet);
if(listeners != null) {
@ -190,6 +199,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
this.handler.update();
if(this.channel != null)
this.channel.flush();
if(DEBUG)
Log.SYSTEM.info("Pakete synchronisiert");
}
public String getCutAddress() {

View file

@ -27,6 +27,5 @@ public class PacketDecoder extends ByteToMessageDecoder {
throw new IOException("Paket " + ((PacketRegistry)context.channel().attr(NetConnection.ATTR_STATE).get()).ordinal() + "/" + id + " ("
+ packet.getClass() + ") war größer als erwartet, " + pbuf.readableBytes() + " weitere Bytes wurden beim Lesen von Paket " + id + " gefunden");
output.add(packet);
// common.log.Log.SYSTEM.info("EIN: [" + context.channel().attr(NetConnection.ATTR_STATE).get() + ":" + id + "] " + packet.getClass().getName());
}
}

View file

@ -17,7 +17,6 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
Integer id = context.channel().attr(NetConnection.ATTR_STATE).get().getId(this.client, packet);
if(id == null)
throw new IOException("Kann nicht registriertes Paket nicht serialisieren");
// common.log.Log.SYSTEM.debug("AUS: [" + context.channel().attr(NetConnection.ATTR_STATE).get() + ":" + id + "] " + packet.getClass().getName());
PacketBuffer pbuf = new PacketBuffer(output);
pbuf.writeVarInt(id);
try {

View file

@ -22,7 +22,6 @@ import common.packet.CPacketPlayer;
import common.packet.CPacketSign;
import common.packet.CPacketSkin;
import common.packet.HPacketHandshake;
import common.packet.LPacketLogin;
import common.packet.LPacketPasswordResponse;
import common.packet.LPacketStartEncrypt;
import common.packet.RPacketDisconnect;
@ -105,7 +104,6 @@ public enum PacketRegistry {
this.server(RPacketLoginSuccess.class);
this.server(RPacketEnableCompression.class);
this.client(LPacketLogin.class);
this.client(LPacketStartEncrypt.class);
this.client(LPacketPasswordResponse.class);
}},

View file

@ -1,23 +0,0 @@
package common.packet;
import java.io.IOException;
import common.network.ILoginHandler;
import common.network.Packet;
import common.network.PacketBuffer;
public class LPacketLogin implements Packet<ILoginHandler> {
public LPacketLogin() {
}
public void readPacketData(PacketBuffer buf) throws IOException {
buf.readString(16);
}
public void writePacketData(PacketBuffer buf) throws IOException {
buf.writeString("TESTtestPlceHldr");
}
public void processPacket(ILoginHandler handler) {
handler.processLogin(this);
}
}

View file

@ -663,6 +663,7 @@ public final class Server implements IThreadListener {
this.saveAllWorlds(false);
this.saveTimer = 0;
}
Log.flushLog();
this.tickTimes[this.perfTimer++] = System.currentTimeMillis() - now;
if(this.perfTimer == 100) {
this.perfTimer = 0;

View file

@ -43,7 +43,9 @@ public class HandshakeHandler extends NetHandler implements IHandshakeHandler
}
else
{
this.networkManager.setNetHandler(new LoginHandler(this.server, this.networkManager));
LoginHandler handler = new LoginHandler(this.server, this.networkManager);
this.networkManager.setNetHandler(handler);
handler.sendLoginPacket();
}
}
}

View file

@ -13,7 +13,6 @@ import common.network.ILoginHandler;
import common.network.IPlayer;
import common.network.NetConnection;
import common.network.NetHandler;
import common.packet.LPacketLogin;
import common.packet.LPacketPasswordResponse;
import common.packet.LPacketStartEncrypt;
import common.packet.RPacketDisconnect;
@ -105,9 +104,9 @@ public class LoginHandler extends NetHandler implements ILoginHandler
this.state = LoginState.ACCEPTED;
}
public void processLogin(LPacketLogin packet) {
public void sendLoginPacket() {
if(this.state != LoginState.INIT)
throw new IllegalStateException("Unerwartetes Login-Paket");
throw new IllegalStateException("Unerwartetes Handshake-Paket");
this.state = LoginState.ENCRYPT;
this.loginToken = new byte[4];
TOKEN_RNG.nextBytes(this.loginToken);