FML3 support
This commit is contained in:
parent
56826d5583
commit
aa8d768fc2
|
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group 'org.adde0109'
|
||||
version '1.0.12-alpha'
|
||||
version '1.0.13-alpha'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import org.slf4j.Logger;
|
|||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.0.12-alpha", authors = {"adde0109"})
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "1.0.13-alpha", authors = {"adde0109"})
|
||||
public class Ambassador {
|
||||
|
||||
public ProxyServer server;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,14 @@
|
|||
package org.adde0109.ambassador.forge;
|
||||
|
||||
import com.velocitypowered.proxy.connection.ConnectionType;
|
||||
|
||||
public class ForgeConstants {
|
||||
public static final String HANDLER = "Modern Forge handler";
|
||||
public static final ForgeFML2ConnectionType ForgeFML2 = new ForgeFML2ConnectionType();
|
||||
public static final String OUTBOUND_CATCHER_NAME = "ambassador-catcher";
|
||||
public static final String RESET_LISTENER = "ambassador-reset-listener";
|
||||
|
||||
public static final String FML2Marker = "\0FML2\0";
|
||||
public static final String FML3Marker = "\0FML3\0";
|
||||
public static final ConnectionType ForgeFML2 = new ForgeFMLConnectionType(2);
|
||||
public static final ConnectionType ForgeFML3 = new ForgeFMLConnectionType(3);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,13 @@ import org.adde0109.ambassador.velocity.backend.VelocityForgeBackendConnectionPh
|
|||
|
||||
import java.util.Collections;
|
||||
|
||||
public class ForgeFML2ConnectionType implements ConnectionType {
|
||||
public class ForgeFMLConnectionType implements ConnectionType {
|
||||
|
||||
final int netVersion;
|
||||
|
||||
public ForgeFMLConnectionType(int netVersion) {
|
||||
this.netVersion = netVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientConnectionPhase getInitialClientPhase() {
|
||||
|
|
@ -24,7 +30,7 @@ public class ForgeFML2ConnectionType implements ConnectionType {
|
|||
@Override
|
||||
public GameProfile addGameProfileTokensIfRequired(GameProfile original, PlayerInfoForwarding forwardingType) {
|
||||
if (forwardingType == PlayerInfoForwarding.LEGACY) {
|
||||
original.addProperties(Collections.singleton(new GameProfile.Property("extraData", "\1FML2\1", "")));
|
||||
original.addProperties(Collections.singleton(new GameProfile.Property("extraData", "\1FML" + netVersion + "\1", "")));
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
|
@ -23,8 +23,10 @@ public class VelocityHandshakeSessionHandler implements MinecraftSessionHandler
|
|||
public boolean handle(Handshake handshake) {
|
||||
handshake.handle(original);
|
||||
if (connection.getType() == ConnectionTypes.VANILLA && connection.getState() == StateRegistry.LOGIN) {
|
||||
if (handshake.getServerAddress().split("\0")[1].equals("FML2")) {
|
||||
connection.setType(ForgeConstants.ForgeFML2);
|
||||
final String marker = handshake.getServerAddress().split("\0")[1];
|
||||
switch (marker) {
|
||||
case "FML2" -> connection.setType(ForgeConstants.ForgeFML2);
|
||||
case "FML3" -> connection.setType(ForgeConstants.ForgeFML3);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package org.adde0109.ambassador.velocity.backend;
|
||||
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
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;
|
||||
|
|
@ -11,6 +13,7 @@ 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;
|
||||
|
||||
public class VelocityForgeBackendHandshakeHandler extends ChannelDuplexHandler {
|
||||
|
|
@ -24,30 +27,15 @@ public class VelocityForgeBackendHandshakeHandler extends ChannelDuplexHandler {
|
|||
|
||||
@Override
|
||||
public void flush(ChannelHandlerContext ctx) throws Exception {
|
||||
if (serverConnection != null){
|
||||
ctx.flush();
|
||||
if (serverConnection == null) {
|
||||
return;
|
||||
}
|
||||
ChannelHandler handler = ctx.pipeline().get(Connections.HANDLER);
|
||||
if (handler instanceof MinecraftConnection connection) {
|
||||
if (connection.getAssociation() instanceof VelocityServerConnection serverConnection) {
|
||||
if (serverConnection.getPlayer().getPhase() instanceof VelocityForgeClientConnectionPhase phase) {
|
||||
init(connection,serverConnection);
|
||||
if (phase.clientPhase == VelocityForgeClientConnectionPhase.ClientPhase.MODDED) {
|
||||
phase.reset(serverConnection ,serverConnection.getPlayer()).thenAccept(ignored -> ctx.flush());
|
||||
} else {
|
||||
ctx.flush();
|
||||
}
|
||||
} else {
|
||||
ctx.pipeline().remove(this);
|
||||
ctx.flush();
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Connection not associated with a server connection");
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Default minecraft packet handler not found");
|
||||
}
|
||||
VelocityForgeClientConnectionPhase clientPhase = (VelocityForgeClientConnectionPhase) serverConnection.getPhase();
|
||||
if (clientPhase.clientPhase == VelocityForgeClientConnectionPhase.ClientPhase.MODDED) {
|
||||
clientPhase.reset(serverConnection ,serverConnection.getPlayer()).thenAccept(ignored -> ctx.flush());
|
||||
} else {
|
||||
ctx.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -64,9 +52,37 @@ public class VelocityForgeBackendHandshakeHandler extends ChannelDuplexHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private void init(MinecraftConnection connection, VelocityServerConnection serverConnection) {
|
||||
private void initBackend(MinecraftConnection connection, VelocityServerConnection serverConnection, ForgeFMLConnectionType type) {
|
||||
this.serverConnection = serverConnection;
|
||||
connection.setType(ForgeConstants.ForgeFML2);
|
||||
connection.setType(type);
|
||||
serverConnection.setConnectionPhase(connection.getType().getInitialBackendPhase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
if (!(msg instanceof Handshake handshake)){
|
||||
ctx.write(msg, promise);
|
||||
return;
|
||||
}
|
||||
ChannelHandler handler = ctx.pipeline().get(Connections.HANDLER);
|
||||
if (handler instanceof MinecraftConnection connection) {
|
||||
if (connection.getAssociation() instanceof VelocityServerConnection serverConnection) {
|
||||
if (serverConnection.getPlayer().getConnection().getType() instanceof ForgeFMLConnectionType type) {
|
||||
initBackend(connection,serverConnection,type);
|
||||
if (type == ForgeConstants.ForgeFML2) {
|
||||
handshake.setServerAddress(handshake.getServerAddress() + ForgeConstants.FML2Marker);
|
||||
} else if (type == ForgeConstants.ForgeFML3) {
|
||||
handshake.setServerAddress(handshake.getServerAddress() + ForgeConstants.FML3Marker);
|
||||
}
|
||||
} else {
|
||||
ctx.pipeline().remove(this);
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Connection not associated with a server connection");
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Default minecraft packet handler not found");
|
||||
}
|
||||
ctx.write(msg,promise);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user