Backend handler is now a session handler
This commit is contained in:
parent
1a78c2ea24
commit
fd5b8c8abb
|
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group 'org.adde0109'
|
||||
version '1.1.4-alpha'
|
||||
version '1.1.4-alpha-pixelax3'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import org.slf4j.Logger;
|
|||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.1.5-alpha", authors = {"adde0109"})
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.1.4-alpha", authors = {"adde0109"})
|
||||
public class Ambassador {
|
||||
|
||||
public ProxyServer server;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class FML2CRPMClientConnectionPhase extends VelocityForgeClientConnection
|
|||
}
|
||||
|
||||
MinecraftConnection connection = player.getConnection();
|
||||
connection.setSessionHandler(new VelocityForgeHandshakeSessionHandler(connection.getSessionHandler(),player));
|
||||
connection.setSessionHandler(new VelocityForgeHandshakeSessionHandler(connection.getSessionHandler(),this));
|
||||
|
||||
serverConnection.getConnection().getChannel().config().setAutoRead(false);
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ public class FML2CRPMClientConnectionPhase extends VelocityForgeClientConnection
|
|||
connection.getChannel().pipeline().remove(ForgeConstants.OUTBOUND_CATCHER_NAME);
|
||||
|
||||
future.complete(false);
|
||||
},300, TimeUnit.SECONDS);
|
||||
},5, TimeUnit.SECONDS);
|
||||
connection.getChannel().pipeline().addBefore(Connections.MINECRAFT_DECODER,ForgeConstants.RESET_LISTENER,new FML2CRPMResetCompleteDecoder());
|
||||
getPayloadManager().listenFor(98).thenAccept(ignore -> {
|
||||
if (scheduledFuture.cancel(false)) {
|
||||
|
|
@ -65,7 +65,7 @@ public class FML2CRPMClientConnectionPhase extends VelocityForgeClientConnection
|
|||
});
|
||||
connection.write(new PluginMessage("fml:handshake",Unpooled.wrappedBuffer(ForgeHandshakeUtils.generatePluginResetPacket())));
|
||||
this.clientPhase = null;
|
||||
connection.getChannel().pipeline().addBefore(Connections.HANDLER,ForgeConstants.OUTBOUND_CATCHER_NAME,new FML2CRPMOutboundCatcher());
|
||||
connection.getChannel().pipeline().addBefore(Connections.HANDLER,ForgeConstants.OUTBOUND_CATCHER_NAME,new FML2CRPMOutboundCatcher(connection));
|
||||
return future;
|
||||
}
|
||||
public void complete(VelocityServer server, ConnectedPlayer player, MinecraftConnection connection) {
|
||||
|
|
@ -81,7 +81,6 @@ public class FML2CRPMClientConnectionPhase extends VelocityForgeClientConnection
|
|||
|
||||
this.clientPhase = this.clientPhase == ClientPhase.MODLIST ? ClientPhase.MODDED : ClientPhase.VANILLA;
|
||||
|
||||
connection.setState(StateRegistry.PLAY);
|
||||
connection.setSessionHandler(((VelocityForgeHandshakeSessionHandler) connection.getSessionHandler()).getOriginal());
|
||||
|
||||
backupServer = null;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.adde0109.ambassador.forge;
|
||||
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
|
@ -11,8 +13,14 @@ import java.util.*;
|
|||
|
||||
public class FML2CRPMOutboundCatcher extends ChannelOutboundHandlerAdapter {
|
||||
|
||||
private final MinecraftConnection connection;
|
||||
|
||||
private final Map<ChannelPromise, Object> catchedPackets = Collections.synchronizedMap(new LinkedHashMap<>());
|
||||
|
||||
public FML2CRPMOutboundCatcher(MinecraftConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
final Set<Map.Entry<ChannelPromise, Object>> s = catchedPackets.entrySet();
|
||||
|
|
@ -39,6 +47,7 @@ public class FML2CRPMOutboundCatcher extends ChannelOutboundHandlerAdapter {
|
|||
ctx.write(msg, promise);
|
||||
} else if (msg instanceof ServerLoginSuccess) {
|
||||
ctx.write(msg,promise);
|
||||
connection.setState(StateRegistry.PLAY);
|
||||
ctx.pipeline().remove(this);
|
||||
} else {
|
||||
catchedPackets.put(promise,msg);
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@ import com.velocitypowered.api.event.PostOrder;
|
|||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
||||
import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.api.event.player.*;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
|
|
@ -16,6 +13,9 @@ import com.velocitypowered.proxy.protocol.packet.ClientSettings;
|
|||
import org.adde0109.ambassador.Ambassador;
|
||||
import org.adde0109.ambassador.forge.FML2CRPMClientConnectionPhase;
|
||||
import org.adde0109.ambassador.forge.FML2ClientConnectionPhase;
|
||||
import org.adde0109.ambassador.forge.ForgeConstants;
|
||||
import org.adde0109.ambassador.forge.ForgeFMLConnectionType;
|
||||
import org.adde0109.ambassador.velocity.backend.VelocityForgeBackendConnectionPhase;
|
||||
|
||||
public class VelocityEventHandler {
|
||||
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public abstract class VelocityForgeClientConnectionPhase implements ClientConnec
|
|||
payloadManager = new VelocityLoginPayloadManager(player.getConnection());
|
||||
handleLogin(player,server,continuation);
|
||||
|
||||
VelocityForgeHandshakeSessionHandler sessionHandler = new VelocityForgeHandshakeSessionHandler(player.getConnection().getSessionHandler(), player);
|
||||
VelocityForgeHandshakeSessionHandler sessionHandler = new VelocityForgeHandshakeSessionHandler(player.getConnection().getSessionHandler(), this);
|
||||
player.getConnection().setSessionHandler(sessionHandler);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,16 +7,16 @@ import io.netty.buffer.ByteBuf;
|
|||
|
||||
public class VelocityForgeHandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
private final MinecraftSessionHandler original;
|
||||
private final ConnectedPlayer player;
|
||||
private final VelocityForgeClientConnectionPhase phase;
|
||||
|
||||
public VelocityForgeHandshakeSessionHandler(MinecraftSessionHandler original, ConnectedPlayer player) {
|
||||
public VelocityForgeHandshakeSessionHandler(MinecraftSessionHandler original, VelocityForgeClientConnectionPhase phase) {
|
||||
this.original = original;
|
||||
this.player = player;
|
||||
this.phase = phase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(LoginPluginResponse packet) {
|
||||
if (((VelocityForgeClientConnectionPhase) player.getPhase()).getPayloadManager().handlePayload(packet)) {
|
||||
if (phase.getPayloadManager().handlePayload(packet)) {
|
||||
return true;
|
||||
} else {
|
||||
return original.handle(packet);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package org.adde0109.ambassador.velocity.backend;
|
||||
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.connection.backend.LoginSessionHandler;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ForgeHandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
private final LoginSessionHandler original;
|
||||
private final VelocityServerConnection serverConnection;
|
||||
private final VelocityForgeBackendConnectionPhase phase;
|
||||
private final VelocityServer server;
|
||||
|
||||
public ForgeHandshakeSessionHandler(LoginSessionHandler original, VelocityServerConnection serverConnection, VelocityServer server) {
|
||||
this.original = original;
|
||||
this.serverConnection = serverConnection;
|
||||
this.phase = (VelocityForgeBackendConnectionPhase) serverConnection.getPhase();
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(LoginPluginMessage packet) {
|
||||
if (phase.handle(serverConnection,serverConnection.getPlayer(),packet)) {
|
||||
return true;
|
||||
} else {
|
||||
return original.handle(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(ServerLoginSuccess packet) {
|
||||
phase.handleSuccess(serverConnection,server);
|
||||
return original.handle(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUnknown(ByteBuf buf) {
|
||||
original.handleUnknown(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
original.disconnected();
|
||||
}
|
||||
|
||||
public MinecraftSessionHandler getOriginal() {
|
||||
return this.original;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,21 +25,25 @@ public class VelocityForgeBackendConnectionPhase implements BackendConnectionPha
|
|||
clientPhase.complete((VelocityServer) server,serverCon.getPlayer(),serverCon.getPlayer().getConnection());
|
||||
}
|
||||
|
||||
public boolean handle(VelocityServerConnection server, ConnectedPlayer player, LoginPluginMessage message) throws Exception {
|
||||
VelocityForgeClientConnectionPhase clientPhase = ((VelocityForgeClientConnectionPhase) player.getPhase());
|
||||
if (clientPhase.clientPhase == VelocityForgeClientConnectionPhase.ClientPhase.VANILLA) {
|
||||
message.retain();
|
||||
clientPhase.reset(server,player).thenAccept((success) -> {
|
||||
if (success) {
|
||||
clientPhase.forwardPayload(server,message);
|
||||
} else {
|
||||
message.release();
|
||||
}
|
||||
});
|
||||
public boolean handle(VelocityServerConnection server, ConnectedPlayer player, LoginPluginMessage message) {
|
||||
if (message.getChannel().equals("fml:loginwrapper")) {
|
||||
VelocityForgeClientConnectionPhase clientPhase = ((VelocityForgeClientConnectionPhase) player.getPhase());
|
||||
if (clientPhase.clientPhase == VelocityForgeClientConnectionPhase.ClientPhase.VANILLA) {
|
||||
message.retain();
|
||||
clientPhase.reset(server,player).thenAccept((success) -> {
|
||||
if (success) {
|
||||
clientPhase.forwardPayload(server,message);
|
||||
} else {
|
||||
message.release();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
clientPhase.forwardPayload(server, (LoginPluginMessage) message.retain());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
clientPhase.forwardPayload(server, (LoginPluginMessage) message.retain());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.adde0109.ambassador.velocity.backend;
|
|||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.backend.LoginSessionHandler;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.network.Connections;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
|
|
@ -13,6 +14,7 @@ import io.netty.util.ReferenceCountUtil;
|
|||
import org.adde0109.ambassador.forge.ForgeConstants;
|
||||
import org.adde0109.ambassador.forge.ForgeFMLConnectionType;
|
||||
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class VelocityForgeBackendHandshakeHandler extends ChannelDuplexHandler {
|
||||
|
||||
|
|
@ -37,17 +39,10 @@ public class VelocityForgeBackendHandshakeHandler extends ChannelDuplexHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
if (msg instanceof LoginPluginMessage message && message.getChannel().equals("fml:loginwrapper")) {
|
||||
((VelocityForgeBackendConnectionPhase) serverConnection.getPhase()).handle(serverConnection, serverConnection.getPlayer(), message);
|
||||
ReferenceCountUtil.release(msg);
|
||||
} else if (msg instanceof ServerLoginSuccess) {
|
||||
((VelocityForgeBackendConnectionPhase) serverConnection.getPhase()).handleSuccess(serverConnection,server);
|
||||
ctx.pipeline().remove(this);
|
||||
ctx.fireChannelRead(msg);
|
||||
} else {
|
||||
ctx.fireChannelRead(msg);
|
||||
}
|
||||
public void channelActive(@NotNull ChannelHandlerContext ctx) throws Exception {
|
||||
this.serverConnection.getConnection().setSessionHandler(new ForgeHandshakeSessionHandler((LoginSessionHandler) this.serverConnection.getConnection().getSessionHandler(),serverConnection,server));
|
||||
ctx.pipeline().remove(this);
|
||||
ctx.pipeline().fireChannelActive();
|
||||
}
|
||||
|
||||
private void initBackend(MinecraftConnection connection, VelocityServerConnection serverConnection, ForgeFMLConnectionType type) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user