Fixed casting of ChannelInitializer. Synced login. Fixed Imports. 1.1.3
This commit is contained in:
parent
91e44b9c21
commit
099c228261
|
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group 'org.adde0109'
|
||||
version '1.1.2-alpha'
|
||||
version '1.1.3-alpha'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.adde0109.ambassador;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
|
|
@ -11,7 +12,9 @@ import java.lang.reflect.Field;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.network.BackendChannelInitializer;
|
||||
import com.velocitypowered.proxy.network.ConnectionManager;
|
||||
import com.velocitypowered.proxy.network.ServerChannelInitializer;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import org.adde0109.ambassador.velocity.VelocityBackendChannelInitializer;
|
||||
import org.adde0109.ambassador.velocity.VelocityServerChannelInitializer;
|
||||
|
|
@ -22,7 +25,7 @@ import org.slf4j.Logger;
|
|||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.1.2-alpha", authors = {"adde0109"})
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.1.3-alpha", authors = {"adde0109"})
|
||||
public class Ambassador {
|
||||
|
||||
public ProxyServer server;
|
||||
|
|
@ -41,7 +44,7 @@ public class Ambassador {
|
|||
this.metricsFactory = metricsFactory;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) throws ReflectiveOperationException {
|
||||
initMetrics();
|
||||
|
||||
|
|
@ -55,10 +58,10 @@ public class Ambassador {
|
|||
cmField.setAccessible(true);
|
||||
|
||||
ChannelInitializer<?> original = ((ConnectionManager) cmField.get(server)).serverChannelInitializer.get();
|
||||
((ConnectionManager) cmField.get(server)).serverChannelInitializer.set(new VelocityServerChannelInitializer(original));
|
||||
((ConnectionManager) cmField.get(server)).serverChannelInitializer.set(new VelocityServerChannelInitializer((ServerChannelInitializer) original,(VelocityServer) server));
|
||||
|
||||
ChannelInitializer<?> originalBackend = ((ConnectionManager) cmField.get(server)).backendChannelInitializer.get();
|
||||
((ConnectionManager) cmField.get(server)).backendChannelInitializer.set(new VelocityBackendChannelInitializer(originalBackend,(VelocityServer) server));
|
||||
((ConnectionManager) cmField.get(server)).backendChannelInitializer.set(new VelocityBackendChannelInitializer((BackendChannelInitializer) originalBackend,(VelocityServer) server));
|
||||
}
|
||||
|
||||
private void initMetrics() {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class FML2CRPMClientConnectionPhase extends VelocityForgeClientConnection
|
|||
connection.getChannel().pipeline().remove(OUTBOUND_CATCHER_NAME);
|
||||
future.complete(false);
|
||||
},5, TimeUnit.SECONDS);
|
||||
connection.getChannel().pipeline().addBefore(Connections.HANDLER,RESET_LISTENER,new FML2CRPMResetCompleteListener(() -> {
|
||||
connection.getChannel().pipeline().addBefore(Connections.MINECRAFT_DECODER,RESET_LISTENER,new FML2CRPMResetCompleteListener(() -> {
|
||||
if (scheduledFuture.cancel(false)) {
|
||||
connection.setState(StateRegistry.LOGIN);
|
||||
this.clientPhase = ClientPhase.HANDSHAKE;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ public class FML2CRPMResetCompleteListener extends ChannelInboundHandlerAdapter
|
|||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
if (msg instanceof ByteBuf buf) {
|
||||
if (!ctx.channel().isActive() || !buf.isReadable()) {
|
||||
buf.release();
|
||||
return;
|
||||
}
|
||||
|
||||
int originalReaderIndex = buf.readerIndex();
|
||||
int packetId = ProtocolUtils.readVarInt(buf);
|
||||
if (packetId == 0x02 && buf.readableBytes() > 1) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package org.adde0109.ambassador.forge;
|
|||
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
|
|
@ -10,8 +9,6 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
|||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||
|
|
@ -31,6 +28,7 @@ public class FML2ClientConnectionPhase extends VelocityForgeClientConnectionPhas
|
|||
private Throwable throwable;
|
||||
private RegisteredServer triedServer;
|
||||
private Continuation continuation;
|
||||
private CompletableFuture<Void> onJoinGame;
|
||||
|
||||
private static final Method CONNECT_TO_INITIAL_SERVER;
|
||||
|
||||
|
|
@ -92,11 +90,18 @@ public class FML2ClientConnectionPhase extends VelocityForgeClientConnectionPhas
|
|||
clientPhase = clientPhase == ClientPhase.MODLIST ? ClientPhase.MODDED : ClientPhase.VANILLA;
|
||||
internalServerConnection = player.getConnectionInFlight();
|
||||
player.resetInFlightConnection();
|
||||
this.onJoinGame = new CompletableFuture<>();
|
||||
continuation.resume();
|
||||
|
||||
}
|
||||
|
||||
public void handleJoinGame() {
|
||||
this.onJoinGame.complete(null);
|
||||
this.onJoinGame = null;
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> awaitJoinGame() {
|
||||
return this.onJoinGame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleForward(VelocityServerConnection serverConnection, LoginPluginMessage payload) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.adde0109.ambassador.velocity;
|
||||
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.network.BackendChannelInitializer;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import org.adde0109.ambassador.forge.ForgeConstants;
|
||||
|
|
@ -9,11 +10,11 @@ import org.adde0109.ambassador.velocity.backend.VelocityForgeBackendHandshakeHan
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class VelocityBackendChannelInitializer extends ChannelInitializer<Channel> {
|
||||
public class VelocityBackendChannelInitializer extends BackendChannelInitializer {
|
||||
|
||||
private static final Method INIT_CHANNEL;
|
||||
|
||||
private final ChannelInitializer<?> original;
|
||||
private final BackendChannelInitializer delegate;
|
||||
private final VelocityServer server;
|
||||
|
||||
static {
|
||||
|
|
@ -25,14 +26,19 @@ public class VelocityBackendChannelInitializer extends ChannelInitializer<Channe
|
|||
}
|
||||
}
|
||||
|
||||
public VelocityBackendChannelInitializer(ChannelInitializer<?> original, VelocityServer server) {
|
||||
this.original = original;
|
||||
public VelocityBackendChannelInitializer(BackendChannelInitializer delegate, VelocityServer server) {
|
||||
super(server);
|
||||
this.delegate = delegate;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
INIT_CHANNEL.invoke(original,ch);
|
||||
protected void initChannel(Channel ch) {
|
||||
try {
|
||||
INIT_CHANNEL.invoke(delegate,ch);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ch.pipeline().addLast(ForgeConstants.HANDLER, new VelocityForgeBackendHandshakeHandler(server));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@ package org.adde0109.ambassador.velocity;
|
|||
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.ResultedEvent;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
||||
import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
||||
|
|
@ -12,9 +10,11 @@ import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
|
|||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import org.adde0109.ambassador.Ambassador;
|
||||
import org.adde0109.ambassador.forge.FML2CRPMClientConnectionPhase;
|
||||
import org.adde0109.ambassador.forge.FML2ClientConnectionPhase;
|
||||
|
||||
public class VelocityEventHandler {
|
||||
|
||||
|
|
@ -54,6 +54,7 @@ public class VelocityEventHandler {
|
|||
}
|
||||
if (phase.internalServerConnection != null) {
|
||||
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
||||
player.setConnectedServer((VelocityServerConnection) phase.internalServerConnection);
|
||||
phase.internalServerConnection = null;
|
||||
}
|
||||
continuation.resume();
|
||||
|
|
@ -78,10 +79,28 @@ public class VelocityEventHandler {
|
|||
continuation.resume();
|
||||
return;
|
||||
}
|
||||
if (phase.internalServerConnection != null) {
|
||||
player.setConnectedServer(null);
|
||||
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));
|
||||
//}
|
||||
continuation.resume();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onLoginEvent(PostLoginEvent event, Continuation continuation) {
|
||||
ConnectedPlayer player = (ConnectedPlayer) event.getPlayer();
|
||||
if (!(player.getPhase() instanceof VelocityForgeClientConnectionPhase phase)) {
|
||||
continuation.resume();
|
||||
return;
|
||||
}
|
||||
|
||||
if (phase instanceof FML2ClientConnectionPhase specialPhase) {
|
||||
specialPhase.awaitJoinGame().thenAcceptAsync((ignored) -> {
|
||||
player.setConnectedServer(null);
|
||||
continuation.resume();
|
||||
},player.getConnection().eventLoop());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
|||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
import org.adde0109.ambassador.forge.FML2CRPMClientConnectionPhase;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package org.adde0109.ambassador.velocity;
|
||||
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
|
||||
import com.velocitypowered.proxy.network.Connections;
|
||||
import com.velocitypowered.proxy.network.ServerChannelInitializer;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
|
|
@ -10,10 +12,10 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class VelocityServerChannelInitializer extends ChannelInitializer<Channel> {
|
||||
public class VelocityServerChannelInitializer extends ServerChannelInitializer {
|
||||
private static final Method INIT_CHANNEL;
|
||||
|
||||
private final ChannelInitializer<?> original;
|
||||
private final ServerChannelInitializer delegate;
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -24,15 +26,20 @@ public class VelocityServerChannelInitializer extends ChannelInitializer<Channel
|
|||
}
|
||||
}
|
||||
|
||||
public VelocityServerChannelInitializer(ChannelInitializer<?> original) {
|
||||
this.original = original;
|
||||
public VelocityServerChannelInitializer(ServerChannelInitializer delegate,VelocityServer server) {
|
||||
super(server);
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(@NotNull Channel ch) throws Exception {
|
||||
INIT_CHANNEL.invoke(original,ch);
|
||||
protected void initChannel(@NotNull Channel ch){
|
||||
try {
|
||||
INIT_CHANNEL.invoke(delegate,ch);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ChannelHandler handler = ch.pipeline().get(Connections.HANDLER);
|
||||
if (!(handler instanceof final MinecraftConnection connection)) throw new Exception("plugin conflict");
|
||||
if (!(handler instanceof final MinecraftConnection connection)) throw new RuntimeException("plugin conflict");
|
||||
HandshakeSessionHandler originalSessionHandler = (HandshakeSessionHandler) connection.getSessionHandler();
|
||||
connection.setSessionHandler(new VelocityHandshakeSessionHandler(originalSessionHandler, connection));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
|||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.adde0109.ambassador.forge.FML2CRPMClientConnectionPhase;
|
||||
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
|||
|
|
@ -2,18 +2,15 @@ package org.adde0109.ambassador.velocity.backend;
|
|||
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.connection.ConnectionType;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.network.Connections;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLogin;
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.adde0109.ambassador.forge.ForgeConstants;
|
||||
import org.adde0109.ambassador.forge.FML2CRPMClientConnectionPhase;
|
||||
import org.adde0109.ambassador.forge.ForgeFMLConnectionType;
|
||||
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user