Improving stability
This commit is contained in:
parent
4c01404c9a
commit
1a78c2ea24
|
|
@ -25,7 +25,7 @@ import org.slf4j.Logger;
|
|||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.1.4-alpha", authors = {"adde0109"})
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.1.5-alpha", authors = {"adde0109"})
|
||||
public class Ambassador {
|
||||
|
||||
public ProxyServer server;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FML2CRPMClientConnectionPhase extends VelocityForgeClientConnectionPhase {
|
||||
private static String OUTBOUND_CATCHER_NAME = "ambassador-catcher";
|
||||
private static String RESET_LISTENER = "ambassador-reset-listener";
|
||||
|
||||
//TODO: Use modData inside ConnectedPlayer instead
|
||||
public byte[] modListData;
|
||||
|
|
@ -48,22 +46,26 @@ public class FML2CRPMClientConnectionPhase extends VelocityForgeClientConnection
|
|||
MinecraftConnection connection = player.getConnection();
|
||||
connection.setSessionHandler(new VelocityForgeHandshakeSessionHandler(connection.getSessionHandler(),player));
|
||||
|
||||
|
||||
serverConnection.getConnection().getChannel().config().setAutoRead(false);
|
||||
|
||||
ScheduledFuture<?> scheduledFuture = connection.eventLoop().schedule(()-> {
|
||||
connection.getChannel().pipeline().remove(OUTBOUND_CATCHER_NAME);
|
||||
connection.getChannel().pipeline().remove(ForgeConstants.OUTBOUND_CATCHER_NAME);
|
||||
|
||||
future.complete(false);
|
||||
},5, TimeUnit.SECONDS);
|
||||
connection.getChannel().pipeline().addBefore(Connections.MINECRAFT_DECODER,RESET_LISTENER,new FML2CRPMResetCompleteListener(() -> {
|
||||
},300, TimeUnit.SECONDS);
|
||||
connection.getChannel().pipeline().addBefore(Connections.MINECRAFT_DECODER,ForgeConstants.RESET_LISTENER,new FML2CRPMResetCompleteDecoder());
|
||||
getPayloadManager().listenFor(98).thenAccept(ignore -> {
|
||||
if (scheduledFuture.cancel(false)) {
|
||||
connection.getChannel().pipeline().remove(ForgeConstants.RESET_LISTENER);
|
||||
connection.setState(StateRegistry.LOGIN);
|
||||
this.clientPhase = ClientPhase.HANDSHAKE;
|
||||
serverConnection.getConnection().getChannel().config().setAutoRead(true);
|
||||
future.complete(true);
|
||||
}
|
||||
}));
|
||||
});
|
||||
connection.write(new PluginMessage("fml:handshake",Unpooled.wrappedBuffer(ForgeHandshakeUtils.generatePluginResetPacket())));
|
||||
this.clientPhase = null;
|
||||
connection.getChannel().pipeline().addBefore(Connections.HANDLER,OUTBOUND_CATCHER_NAME,new FML2CRPMOutboundCatcher());
|
||||
connection.getChannel().pipeline().addBefore(Connections.HANDLER,ForgeConstants.OUTBOUND_CATCHER_NAME,new FML2CRPMOutboundCatcher());
|
||||
return future;
|
||||
}
|
||||
public void complete(VelocityServer server, ConnectedPlayer player, MinecraftConnection connection) {
|
||||
|
|
@ -82,7 +84,6 @@ public class FML2CRPMClientConnectionPhase extends VelocityForgeClientConnection
|
|||
connection.setState(StateRegistry.PLAY);
|
||||
connection.setSessionHandler(((VelocityForgeHandshakeSessionHandler) connection.getSessionHandler()).getOriginal());
|
||||
|
||||
connection.getChannel().pipeline().remove(OUTBOUND_CATCHER_NAME);
|
||||
backupServer = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,11 @@ public class FML2CRPMOutboundCatcher extends ChannelOutboundHandlerAdapter {
|
|||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
if (msg instanceof LoginPluginMessage || msg instanceof ServerLoginSuccess) {
|
||||
if (msg instanceof LoginPluginMessage) {
|
||||
ctx.write(msg, promise);
|
||||
} else if (msg instanceof ServerLoginSuccess) {
|
||||
ctx.write(msg,promise);
|
||||
ctx.pipeline().remove(this);
|
||||
} else {
|
||||
catchedPackets.put(promise,msg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,13 @@
|
|||
package org.adde0109.ambassador.forge;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
|
||||
public class FML2CRPMResetCompleteListener extends ChannelInboundHandlerAdapter {
|
||||
|
||||
final Runnable whenComplete;
|
||||
|
||||
public FML2CRPMResetCompleteListener(Runnable whenComplete) {
|
||||
this.whenComplete = whenComplete;
|
||||
}
|
||||
public class FML2CRPMResetCompleteDecoder extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
|
|
@ -25,10 +20,16 @@ public class FML2CRPMResetCompleteListener extends ChannelInboundHandlerAdapter
|
|||
int originalReaderIndex = buf.readerIndex();
|
||||
int packetId = ProtocolUtils.readVarInt(buf);
|
||||
if (packetId == 0x02 && buf.readableBytes() > 1) {
|
||||
ReferenceCountUtil.release(msg);
|
||||
ctx.pipeline().remove(this);
|
||||
whenComplete.run();
|
||||
try {
|
||||
MinecraftPacket packet = new LoginPluginResponse();
|
||||
packet.decode(buf, ProtocolUtils.Direction.SERVERBOUND,null);
|
||||
ctx.fireChannelRead(packet);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
buf.readerIndex(originalReaderIndex);
|
||||
}
|
||||
}
|
||||
ctx.fireChannelRead(msg);
|
||||
|
|
@ -83,9 +83,9 @@ public class VelocityEventHandler {
|
|||
if (phase instanceof FML2ClientConnectionPhase specialPhase) {
|
||||
specialPhase.handleJoinGame();
|
||||
}
|
||||
//if (((ConnectedPlayer) event.getPlayer()).getConnectedServer() != null && ((ConnectedPlayer) event.getPlayer()).getConnectedServer().getConnection() != null) {
|
||||
// ((ConnectedPlayer) event.getPlayer()).getConnectedServer().getConnection().write(new ClientSettings("en_GB", (byte) 10, 0, true, (short) 0xFF,1,false,true));
|
||||
//}
|
||||
if (((ConnectedPlayer) event.getPlayer()).getConnectedServer() != null && ((ConnectedPlayer) event.getPlayer()).getConnectedServer().getConnection() != null) {
|
||||
((ConnectedPlayer) event.getPlayer()).getConnectedServer().getConnection().write(new ClientSettings("en_GB", (byte) 10, 0, true, (short) 0xFF,1,false,true));
|
||||
}
|
||||
continuation.resume();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public abstract class VelocityForgeClientConnectionPhase implements ClientConnec
|
|||
final public void forwardPayload(VelocityServerConnection serverConnection, LoginPluginMessage payload) {
|
||||
handleForward(serverConnection,payload);
|
||||
if (payloadManager == null) {
|
||||
payload.release();
|
||||
return;
|
||||
}
|
||||
payloadManager.sendPayload("fml:loginwrapper",payload.content()).thenAccept((responseData) -> {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
|
|||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||
|
||||
|
|
@ -27,12 +28,12 @@ public class VelocityForgeBackendConnectionPhase implements BackendConnectionPha
|
|||
public boolean handle(VelocityServerConnection server, ConnectedPlayer player, LoginPluginMessage message) throws Exception {
|
||||
VelocityForgeClientConnectionPhase clientPhase = ((VelocityForgeClientConnectionPhase) player.getPhase());
|
||||
if (clientPhase.clientPhase == VelocityForgeClientConnectionPhase.ClientPhase.VANILLA) {
|
||||
server.getConnection().getChannel().config().setAutoRead(false);
|
||||
message.retain();
|
||||
clientPhase.reset(server,player).thenAccept((success) -> {
|
||||
if (success) {
|
||||
clientPhase.forwardPayload(server,message);
|
||||
server.getConnection().getChannel().config().setAutoRead(true);
|
||||
} else {
|
||||
message.release();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user