WIP
This commit is contained in:
parent
52a818b109
commit
ff934dc106
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.adde0109.ambassador.forge;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
|
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
|
||||||
|
|
||||||
|
public class ForgeClientConnectionPhase implements ClientConnectionPhase {
|
||||||
|
|
||||||
|
public void handleLogin() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.adde0109.ambassador.forge;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
|
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||||
|
import com.velocitypowered.proxy.connection.ConnectionType;
|
||||||
|
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
||||||
|
|
||||||
|
public class ForgeConnectionType implements ConnectionType {
|
||||||
|
@Override
|
||||||
|
public ClientConnectionPhase getInitialClientPhase() {
|
||||||
|
return new ForgeClientConnectionPhase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BackendConnectionPhase getInitialBackendPhase() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GameProfile addGameProfileTokensIfRequired(GameProfile original, PlayerInfoForwarding forwardingType) {
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,8 +4,10 @@ import com.velocitypowered.api.event.Continuation;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||||
|
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
||||||
import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerLoginPluginMessageEvent;
|
import com.velocitypowered.api.event.player.ServerLoginPluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.api.proxy.LoginPhaseConnection;
|
import com.velocitypowered.api.proxy.LoginPhaseConnection;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
|
@ -15,10 +17,18 @@ import java.net.InetSocketAddress;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.connection.ConnectionType;
|
||||||
|
import com.velocitypowered.proxy.connection.ConnectionTypes;
|
||||||
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
import net.kyori.adventure.text.Component;
|
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.checkerframework.checker.units.qual.A;
|
||||||
|
|
||||||
public class ForgeHandshakeHandler {
|
public class ForgeHandshakeHandler {
|
||||||
|
|
||||||
|
|
@ -37,37 +47,45 @@ public class ForgeHandshakeHandler {
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
@Subscribe(order = PostOrder.LAST)
|
||||||
public void onPreLoginEvent(PreLoginEvent event, Continuation continuation) {
|
public void onPreLoginEvent(PreLoginEvent event, Continuation continuation) {
|
||||||
if (!ambassador.config.shouldHandle(event.getConnection().getProtocolVersion().getProtocol()) || !event.getResult().isAllowed()) {
|
if (event.getConnection().getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RegisteredServer defaultServer = ambassador.config.getServer(event.getConnection().getProtocolVersion().getProtocol());
|
|
||||||
|
|
||||||
ForgeConnection forgeConnection = new ForgeConnection((LoginPhaseConnection) event.getConnection(), ambassador.logger);
|
MinecraftConnection connection = (MinecraftConnection)event.getConnection();
|
||||||
forgeConnection.testIfForge((LoginPhaseConnection) event.getConnection())
|
((LoginPhaseConnection) event.getConnection()).sendLoginPluginMessage(
|
||||||
.thenAccept((isForge) -> {
|
MinecraftChannelIdentifier.create("fml","loginwrapper"),
|
||||||
if (isForge)
|
ForgeHandshakeUtils.generateTestPacket(),(msg) -> {
|
||||||
registerForgeConnection(forgeConnection);
|
if (connection.getType() == ConnectionTypes.VANILLA) {
|
||||||
});
|
if (msg != null) {
|
||||||
|
connection.setType(new ForgeConnectionType());
|
||||||
if (ambassador.forgeServerSwitchHandler.reSyncMap.containsKey(event.getUsername())) {
|
}
|
||||||
forgeConnection.sync(ambassador.forgeServerSwitchHandler.reSyncMap.remove(event.getUsername())).thenAccept((done) -> {
|
}
|
||||||
continuation.resume();
|
});
|
||||||
});
|
//SEND ===CLIENT MODLIST REQUEST===
|
||||||
forgeConnection.setForced(true);
|
((LoginPhaseConnection) event.getConnection()).sendLoginPluginMessage(
|
||||||
} else if (defaultServer != null) {
|
MinecraftChannelIdentifier.create("fml","loginwrapper"),
|
||||||
//If a connection does not already exist, create one.
|
ForgeHandshakeUtils.generateTestPacket(),(msg) -> {
|
||||||
if (!forgeServerConnectionMap.containsKey(defaultServer)) {
|
if (msg != null) {
|
||||||
forgeServerConnectionMap.put(defaultServer, new ForgeServerConnection(defaultServer));
|
connection.setType(new ForgeConnectionType());
|
||||||
}
|
//Handle the response
|
||||||
//Forge Handshake
|
}
|
||||||
forgeConnection.sync(forgeServerConnectionMap.get(defaultServer)).thenAccept((done) -> {
|
});
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
});
|
}
|
||||||
forgeConnection.setForced(ambassador.config.getForced(forgeConnection.getConnection().getProtocolVersion().getProtocol()));
|
@Subscribe
|
||||||
} else {
|
public void onPermissionsSetupEvent(PermissionsSetupEvent event, Continuation continuation) {
|
||||||
|
//Filters...
|
||||||
|
if (!(event.getSubject() instanceof ConnectedPlayer)) {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
ConnectedPlayer player = ((ConnectedPlayer) event.getSubject());
|
||||||
|
if (!(player.getConnection().getType() instanceof ForgeConnectionType)) {
|
||||||
|
continuation.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
((ForgeClientConnectionPhase) player.getPhase()).handleLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerForgeConnection(ForgeConnection forgeConnection) {
|
private void registerForgeConnection(ForgeConnection forgeConnection) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.adde0109.ambassador.forge;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
|
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||||
|
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
public class ForgeSessionHandler implements MinecraftSessionHandler {
|
||||||
|
private final MinecraftSessionHandler delegate;
|
||||||
|
private final MinecraftConnection connection;
|
||||||
|
|
||||||
|
public ForgeSessionHandler(MinecraftSessionHandler delegate, MinecraftConnection connection) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.connection = connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleGeneric(MinecraftPacket packet) {
|
||||||
|
packet.handle(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activated() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handle(LoginPluginResponse packet) {
|
||||||
|
//DETECT FML or PCF
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user