WIP: Backend handler
This commit is contained in:
parent
8455e5b0e0
commit
4a07819c7d
|
|
@ -20,7 +20,7 @@ import org.adde0109.ambassador.forge.ForgeConnection;
|
||||||
import org.adde0109.ambassador.forge.ForgeHandshakeHandler;
|
import org.adde0109.ambassador.forge.ForgeHandshakeHandler;
|
||||||
import org.adde0109.ambassador.forge.ForgeHandshakeUtils;
|
import org.adde0109.ambassador.forge.ForgeHandshakeUtils;
|
||||||
import org.adde0109.ambassador.forge.ForgeServerSwitchHandler;
|
import org.adde0109.ambassador.forge.ForgeServerSwitchHandler;
|
||||||
import org.adde0109.ambassador.velocity.VelocityChannelInitializer;
|
import org.adde0109.ambassador.velocity.VelocityServerChannelInitializer;
|
||||||
import org.adde0109.ambassador.velocity.VelocityEventHandler;
|
import org.adde0109.ambassador.velocity.VelocityEventHandler;
|
||||||
import org.bstats.charts.SingleLineChart;
|
import org.bstats.charts.SingleLineChart;
|
||||||
import org.bstats.velocity.Metrics;
|
import org.bstats.velocity.Metrics;
|
||||||
|
|
@ -73,7 +73,7 @@ public class Ambassador {
|
||||||
Field cmField = VelocityServer.class.getDeclaredField("cm");
|
Field cmField = VelocityServer.class.getDeclaredField("cm");
|
||||||
cmField.setAccessible(true);
|
cmField.setAccessible(true);
|
||||||
ChannelInitializer<?> original = ((ConnectionManager) cmField.get(server)).serverChannelInitializer.get();
|
ChannelInitializer<?> original = ((ConnectionManager) cmField.get(server)).serverChannelInitializer.get();
|
||||||
((ConnectionManager) cmField.get(server)).serverChannelInitializer.set(new VelocityChannelInitializer(original));
|
((ConnectionManager) cmField.get(server)).serverChannelInitializer.set(new VelocityServerChannelInitializer(original));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
||||||
|
|
@ -12,50 +12,53 @@ import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||||
import org.adde0109.ambassador.velocity.VelocityForgeHandshakeSessionHandler;
|
import org.adde0109.ambassador.velocity.VelocityForgeHandshakeSessionHandler;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ForgeFML2ClientConnectionPhase implements VelocityForgeClientConnectionPhase {
|
public class ForgeFML2ClientConnectionPhase implements VelocityForgeClientConnectionPhase {
|
||||||
|
|
||||||
private final MinecraftConnection connection;
|
|
||||||
private boolean isResettable;
|
private boolean isResettable;
|
||||||
private Optional<ByteBuf> modListData = Optional.empty();
|
private Optional<ByteBuf> modListData = Optional.empty();
|
||||||
|
|
||||||
|
private final ArrayList<Integer> listenerList = new ArrayList();
|
||||||
private Continuation whenComplete;
|
private Continuation whenComplete;
|
||||||
ForgeFML2ClientConnectionPhase(MinecraftConnection connection) {
|
|
||||||
this.connection = connection;
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public void handleLogin(ForgeHandshakeUtils.CachedServerHandshake handshake, Continuation continuation) {
|
public void handleLogin(ConnectedPlayer player,ForgeHandshakeUtils.CachedServerHandshake handshake, Continuation continuation) {
|
||||||
this.whenComplete = continuation;
|
this.whenComplete = continuation;
|
||||||
VelocityForgeHandshakeSessionHandler sessionHandler = new VelocityForgeHandshakeSessionHandler(this);
|
final MinecraftConnection connection = player.getConnection();
|
||||||
|
VelocityForgeHandshakeSessionHandler sessionHandler = new VelocityForgeHandshakeSessionHandler(connection.getSessionHandler(),player);
|
||||||
if(handshake == null) {
|
if(handshake == null) {
|
||||||
this.connection.write(new LoginPluginMessage(98,"fml:loginwrapper", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generateResetPacket())));
|
connection.delayedWrite(new LoginPluginMessage(98,"fml:loginwrapper", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generateResetPacket())));
|
||||||
sessionHandler.listen(98);
|
listenerList.add(98);
|
||||||
} else {
|
} else {
|
||||||
this.connection.delayedWrite(new LoginPluginMessage(1,"fml:loginwrapper", Unpooled.wrappedBuffer(handshake.modListPacket)));
|
connection.delayedWrite(new LoginPluginMessage(1,"fml:loginwrapper", Unpooled.wrappedBuffer(handshake.modListPacket)));
|
||||||
sessionHandler.listen(1);
|
listenerList.add(1);
|
||||||
for (int i = 0;i<handshake.otherPackets.size();i++) {
|
for (int i = 0;i<handshake.otherPackets.size();i++) {
|
||||||
this.connection.delayedWrite(new LoginPluginMessage(i+2,"fml:loginwrapper", Unpooled.wrappedBuffer(handshake.otherPackets.get(i))));
|
connection.delayedWrite(new LoginPluginMessage(i+2,"fml:loginwrapper", Unpooled.wrappedBuffer(handshake.otherPackets.get(i))));
|
||||||
sessionHandler.listen(i+2);
|
listenerList.add(i+2);
|
||||||
}
|
}
|
||||||
this.connection.setSessionHandler(sessionHandler);
|
|
||||||
this.connection.flush();
|
|
||||||
}
|
}
|
||||||
|
connection.setSessionHandler(sessionHandler);
|
||||||
|
connection.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(LoginPluginResponse packet, boolean lastMessage) {
|
public boolean handle(ConnectedPlayer player, LoginPluginResponse packet) {
|
||||||
|
if (!listenerList.removeIf(id -> id.equals(packet.getId()))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (packet.getId() == 98) {
|
if (packet.getId() == 98) {
|
||||||
isResettable = packet.isSuccess();
|
isResettable = packet.isSuccess();
|
||||||
} else if (packet.getId() == 1) {
|
} else if (packet.getId() == 1) {
|
||||||
if (!packet.isSuccess()) {
|
if (!packet.isSuccess()) {
|
||||||
//TODO: Write disconnect message to end user
|
//TODO: Write disconnect message to end user
|
||||||
connection.close();
|
player.getConnection().close();
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
modListData = Optional.of(packet.content().retain());
|
modListData = Optional.of(packet.content().retain());
|
||||||
}
|
}
|
||||||
if (lastMessage) {
|
if (listenerList.isEmpty()) {
|
||||||
whenComplete.resume();
|
whenComplete.resume();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,18 @@ import com.velocitypowered.proxy.connection.ConnectionType;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
|
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
|
||||||
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
||||||
import org.adde0109.ambassador.forge.ForgeFML2ClientConnectionPhase;
|
import org.adde0109.ambassador.velocity.backend.VelocityForgeBackendConnectionPhase;
|
||||||
|
|
||||||
public class ForgeConnectionType implements ConnectionType {
|
public class ForgeFML2ConnectionType implements ConnectionType {
|
||||||
|
|
||||||
private final MinecraftConnection connection;
|
|
||||||
public ForgeConnectionType(MinecraftConnection connection) {
|
|
||||||
this.connection = connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientConnectionPhase getInitialClientPhase() {
|
public ClientConnectionPhase getInitialClientPhase() {
|
||||||
return new ForgeFML2ClientConnectionPhase(connection);
|
return new ForgeFML2ClientConnectionPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BackendConnectionPhase getInitialBackendPhase() {
|
public BackendConnectionPhase getInitialBackendPhase() {
|
||||||
return null;
|
return new VelocityForgeBackendConnectionPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -19,6 +19,7 @@ import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TranslatableComponent;
|
import net.kyori.adventure.text.TranslatableComponent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.adde0109.ambassador.Ambassador;
|
import org.adde0109.ambassador.Ambassador;
|
||||||
|
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||||
|
|
||||||
public class ForgeHandshakeHandler {
|
public class ForgeHandshakeHandler {
|
||||||
|
|
||||||
|
|
@ -37,12 +38,12 @@ public class ForgeHandshakeHandler {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void handleLogin(ConnectedPlayer player, ForgeFML2ClientConnectionPhase phase, Continuation continuation) {
|
public void handleLogin(ConnectedPlayer player, Continuation continuation) {
|
||||||
getInitialHandshake(player).whenCompleteAsync((msg,ex) -> {
|
getInitialHandshake(player).whenCompleteAsync((msg,ex) -> {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
ambassador.logger.warn("Forge player, " + player.getUsername() + ", is entering vanilla-mode because of: " + ex.getMessage());
|
ambassador.logger.warn("Forge player, " + player.getUsername() + ", is entering vanilla-mode because of: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
phase.handleLogin(msg,continuation);
|
((VelocityForgeClientConnectionPhase) player.getPhase()).handleLogin(player,msg,continuation);
|
||||||
}, player.getConnection().eventLoop());
|
}, player.getConnection().eventLoop());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +89,7 @@ public class ForgeHandshakeHandler {
|
||||||
forgeServerConnectionMap.remove(server);
|
forgeServerConnectionMap.remove(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
//@Subscribe
|
||||||
public void onServerLoginPluginMessageEvent(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
public void onServerLoginPluginMessageEvent(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
||||||
if (!event.getIdentifier().equals(LOGIN_WRAPPER_ID)) {
|
if (!event.getIdentifier().equals(LOGIN_WRAPPER_ID)) {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
|
|
@ -110,7 +111,7 @@ public class ForgeHandshakeHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
//@Subscribe
|
||||||
public void onKickedFromServerEvent(KickedFromServerEvent event, Continuation continuation) {
|
public void onKickedFromServerEvent(KickedFromServerEvent event, Continuation continuation) {
|
||||||
Optional<ForgeConnection> forgeConnectionOptional = getForgeConnection(event.getPlayer());
|
Optional<ForgeConnection> forgeConnectionOptional = getForgeConnection(event.getPlayer());
|
||||||
if (forgeConnectionOptional.isPresent()) {
|
if (forgeConnectionOptional.isPresent()) {
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,13 @@ public class ForgeHandshakeUtils {
|
||||||
public static byte[] generateResetPacket() {
|
public static byte[] generateResetPacket() {
|
||||||
ByteArrayDataOutput dataAndPacketIdStream = ByteStreams.newDataOutput();
|
ByteArrayDataOutput dataAndPacketIdStream = ByteStreams.newDataOutput();
|
||||||
writeVarInt(dataAndPacketIdStream,98);
|
writeVarInt(dataAndPacketIdStream,98);
|
||||||
return dataAndPacketIdStream.toByteArray();
|
|
||||||
|
ByteArrayDataOutput stream = ByteStreams.newDataOutput();
|
||||||
|
byte[] dataAndPacketId = dataAndPacketIdStream.toByteArray();
|
||||||
|
writeUtf(stream,"fml:handshake");
|
||||||
|
writeVarInt(stream,dataAndPacketId.length);
|
||||||
|
stream.write(dataAndPacketId);
|
||||||
|
return stream.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class HandshakeReceiver {
|
public static class HandshakeReceiver {
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public class ForgeServerSwitchHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
//@Subscribe(order = PostOrder.LAST)
|
||||||
public void onServerPreConnectEvent(ServerPreConnectEvent event, Continuation continuation) {
|
public void onServerPreConnectEvent(ServerPreConnectEvent event, Continuation continuation) {
|
||||||
if (!event.getResult().isAllowed()) {
|
if (!event.getResult().isAllowed()) {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
|
|
@ -111,7 +111,7 @@ public class ForgeServerSwitchHandler {
|
||||||
reSyncMap.put(player.getUsername(),forgeServerConnection);
|
reSyncMap.put(player.getUsername(),forgeServerConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
//@Subscribe
|
||||||
public void onServerConnectedEvent(ServerConnectedEvent event, Continuation continuation) {
|
public void onServerConnectedEvent(ServerConnectedEvent event, Continuation continuation) {
|
||||||
ConnectedPlayer player = ((ConnectedPlayer) event.getPlayer());
|
ConnectedPlayer player = ((ConnectedPlayer) event.getPlayer());
|
||||||
Optional<ForgeConnection> forgeConnection = ambassador.forgeHandshakeHandler.getForgeConnection(player);
|
Optional<ForgeConnection> forgeConnection = ambassador.forgeHandshakeHandler.getForgeConnection(player);
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,19 @@ package org.adde0109.ambassador.velocity;
|
||||||
import com.velocitypowered.api.event.Continuation;
|
import com.velocitypowered.api.event.Continuation;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerLoginPluginMessageEvent;
|
||||||
|
import com.velocitypowered.proxy.connection.ConnectionTypes;
|
||||||
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
|
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases;
|
||||||
|
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
import org.adde0109.ambassador.Ambassador;
|
import org.adde0109.ambassador.Ambassador;
|
||||||
import org.adde0109.ambassador.forge.ForgeFML2ClientConnectionPhase;
|
import org.adde0109.ambassador.forge.ForgeFML2ClientConnectionPhase;
|
||||||
|
import org.adde0109.ambassador.forge.ForgeFML2ConnectionType;
|
||||||
|
import org.adde0109.ambassador.velocity.backend.VelocityForgeBackendConnectionPhase;
|
||||||
|
import org.adde0109.ambassador.velocity.backend.VelocityForgeBackendHandshakeSessionHandler;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class VelocityEventHandler {
|
public class VelocityEventHandler {
|
||||||
|
|
||||||
|
|
@ -21,10 +31,26 @@ public class VelocityEventHandler {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(player.getPhase() instanceof ForgeFML2ClientConnectionPhase phase)) {
|
if (!(player.getPhase() instanceof VelocityForgeClientConnectionPhase phase)) {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ambassador.forgeHandshakeHandler.handleLogin(player,phase,continuation);
|
ambassador.forgeHandshakeHandler.handleLogin(player,continuation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onServerLoginPluginMessageEvent(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
||||||
|
if (!Objects.equals(event.getIdentifier().getId(), "fml:loginwrapper")) {
|
||||||
|
continuation.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final VelocityServerConnection serverCon = (VelocityServerConnection) event.getConnection();
|
||||||
|
final MinecraftConnection connection = serverCon.getConnection();
|
||||||
|
serverCon.setConnectionPhase(new VelocityForgeBackendConnectionPhase());
|
||||||
|
if (connection != null) {
|
||||||
|
connection.setType(new ForgeFML2ConnectionType());
|
||||||
|
connection.setSessionHandler(new VelocityForgeBackendHandshakeSessionHandler(connection.getSessionHandler(),serverCon,serverCon.getPlayer()));
|
||||||
|
}
|
||||||
|
continuation.resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package org.adde0109.ambassador.velocity;
|
||||||
import com.velocitypowered.api.event.Continuation;
|
import com.velocitypowered.api.event.Continuation;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||||
import org.adde0109.ambassador.forge.ForgeHandshakeUtils;
|
import org.adde0109.ambassador.forge.ForgeHandshakeUtils;
|
||||||
|
|
||||||
|
|
@ -11,8 +12,9 @@ import javax.annotation.Nullable;
|
||||||
public interface VelocityForgeClientConnectionPhase extends ClientConnectionPhase {
|
public interface VelocityForgeClientConnectionPhase extends ClientConnectionPhase {
|
||||||
//TODO:Make class when PCF is done
|
//TODO:Make class when PCF is done
|
||||||
|
|
||||||
default void handleLogin(@Nullable ForgeHandshakeUtils.CachedServerHandshake initialHandshake, Continuation continuation) {
|
default void handleLogin(ConnectedPlayer player, @Nullable ForgeHandshakeUtils.CachedServerHandshake initialHandshake, Continuation continuation) {
|
||||||
}
|
}
|
||||||
default void handle(LoginPluginResponse packet, boolean lastMessage) {
|
default boolean handle(ConnectedPlayer player,LoginPluginResponse packet) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,40 @@
|
||||||
package org.adde0109.ambassador.velocity;
|
package org.adde0109.ambassador.velocity;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
|
import com.velocitypowered.proxy.connection.client.LoginSessionHandler;
|
||||||
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.adde0109.ambassador.forge.ForgeFML2ClientConnectionPhase;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class VelocityForgeHandshakeSessionHandler implements MinecraftSessionHandler {
|
public class VelocityForgeHandshakeSessionHandler implements MinecraftSessionHandler {
|
||||||
|
private final MinecraftSessionHandler original;
|
||||||
private final ArrayList<Integer> listenerList = new ArrayList();
|
private final ConnectedPlayer player;
|
||||||
private final VelocityForgeClientConnectionPhase phase;
|
public VelocityForgeHandshakeSessionHandler(MinecraftSessionHandler original, ConnectedPlayer player) {
|
||||||
public VelocityForgeHandshakeSessionHandler(VelocityForgeClientConnectionPhase phase) {
|
this.original = original;
|
||||||
this.phase = phase;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(LoginPluginResponse packet) {
|
public boolean handle(LoginPluginResponse packet) {
|
||||||
if (listenerList.removeIf(id -> id.equals(packet.getId()))) {
|
if (((VelocityForgeClientConnectionPhase) player.getPhase()).handle(player, packet)) {
|
||||||
phase.handle(packet, listenerList.isEmpty());
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return original.handle(packet);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
public void listen(int id) {
|
@Override
|
||||||
listenerList.add(id);
|
public void handleUnknown(ByteBuf buf) {
|
||||||
|
original.handleUnknown(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnected() {
|
||||||
|
original.disconnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.adde0109.ambassador.forge.ForgeConnectionType;
|
import org.adde0109.ambassador.forge.ForgeFML2ConnectionType;
|
||||||
|
|
||||||
public class VelocityHandshakeSessionHandler implements MinecraftSessionHandler {
|
public class VelocityHandshakeSessionHandler implements MinecraftSessionHandler {
|
||||||
private final HandshakeSessionHandler original;
|
private final HandshakeSessionHandler original;
|
||||||
|
|
@ -24,7 +24,7 @@ public class VelocityHandshakeSessionHandler implements MinecraftSessionHandler
|
||||||
handshake.handle(original);
|
handshake.handle(original);
|
||||||
if (connection.getType() == ConnectionTypes.VANILLA && connection.getState() == StateRegistry.LOGIN) {
|
if (connection.getType() == ConnectionTypes.VANILLA && connection.getState() == StateRegistry.LOGIN) {
|
||||||
if (handshake.getServerAddress().split("\0")[1].equals("FML2")) {
|
if (handshake.getServerAddress().split("\0")[1].equals("FML2")) {
|
||||||
connection.setType(new ForgeConnectionType(connection));
|
connection.setType(new ForgeFML2ConnectionType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -33,7 +33,7 @@ public class VelocityHandshakeSessionHandler implements MinecraftSessionHandler
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleGeneric(MinecraftPacket packet) {
|
public void handleGeneric(MinecraftPacket packet) {
|
||||||
packet.handle(original);
|
original.handleGeneric(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class VelocityChannelInitializer extends ChannelInitializer<Channel> {
|
public class VelocityServerChannelInitializer extends ChannelInitializer<Channel> {
|
||||||
private static final Method INIT_CHANNEL;
|
private static final Method INIT_CHANNEL;
|
||||||
|
|
||||||
private final ChannelInitializer<?> original;
|
private final ChannelInitializer<?> original;
|
||||||
|
|
@ -24,7 +24,7 @@ public class VelocityChannelInitializer extends ChannelInitializer<Channel> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public VelocityChannelInitializer(ChannelInitializer<?> original) {
|
public VelocityServerChannelInitializer(ChannelInitializer<?> original) {
|
||||||
this.original = original;
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.adde0109.ambassador.velocity.backend;
|
||||||
|
|
||||||
|
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 com.velocitypowered.proxy.protocol.packet.PluginMessage;
|
||||||
|
|
||||||
|
public class VelocityForgeBackendConnectionPhase implements BackendConnectionPhase {
|
||||||
|
|
||||||
|
public boolean handle(VelocityServerConnection server, ConnectedPlayer player, LoginPluginMessage message) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package org.adde0109.ambassador.velocity.backend;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
|
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
|
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||||
|
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
||||||
|
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||||
|
|
||||||
|
public class VelocityForgeBackendHandshakeSessionHandler implements MinecraftSessionHandler {
|
||||||
|
private final MinecraftSessionHandler original;
|
||||||
|
private final VelocityServerConnection serverCon;
|
||||||
|
|
||||||
|
public VelocityForgeBackendHandshakeSessionHandler(MinecraftSessionHandler original, VelocityServerConnection serverCon) {
|
||||||
|
this.original = original;
|
||||||
|
this.serverCon = serverCon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnected() {
|
||||||
|
original.disconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exception(Throwable throwable) {
|
||||||
|
original.exception(throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handle(LoginPluginMessage packet) {
|
||||||
|
if (((VelocityForgeBackendConnectionPhase) serverCon.getPhase()).handle(serverCon, serverCon.getPlayer(), packet)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return original.handle(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handle(ServerLoginSuccess packet) {
|
||||||
|
|
||||||
|
return original.handle(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user