Skip to content

Commit

Permalink
Update Velocity support
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Jan 13, 2024
1 parent 99659f1 commit 06e8a58
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.server.network.ServerHandshakePacketListenerImpl;
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import net.minecraft.server.network.ServerStatusPacketListenerImpl;
import net.minecraftforge.network.NetworkContext;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.apache.logging.log4j.LogManager;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -143,11 +142,7 @@ public void handleIntention(ClientIntentionPacket packetIn) {

private boolean arclight$handleSpecialLogin(ClientIntentionPacket packet) {
String ip = packet.hostName();
if (VelocitySupport.isEnabled()) {
// as if forge client connects
var forgePacket = new ClientIntentionPacket(packet.protocolVersion(), NetworkContext.enhanceHostName(ip), packet.port(), packet.intention());
return ServerLifecycleHooks.handleServerLogin(forgePacket, this.connection);
} else if (SpigotConfig.bungee) {
if (!VelocitySupport.isEnabled() && SpigotConfig.bungee) {
String[] split = ip.split("\0");
if (split.length == 4) {
Property[] properties = GSON.fromJson(split[3], Property[].class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
import net.minecraft.util.CryptException;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.fml.util.thread.SidedThreadGroups;
import net.minecraftforge.network.ConnectionType;
import net.minecraftforge.network.NetworkContext;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.filters.NetworkFilters;
import org.apache.commons.lang3.Validate;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.CraftServer;
Expand Down Expand Up @@ -257,8 +253,6 @@ private InetAddress getAddress() {
thread.start();
}

private static final String EXTRA_DATA = "extraData";

@Inject(method = "handleCustomQueryPacket", cancellable = true, at = @At("HEAD"))
private void arclight$modernForwardReply(ServerboundCustomQueryAnswerPacket packet, CallbackInfo ci) {
if (VelocitySupport.isEnabled() && packet.transactionId() == this.arclight$velocityLoginId) {
Expand Down Expand Up @@ -299,40 +293,6 @@ private InetAddress getAddress() {
this.connection.address = new java.net.InetSocketAddress(VelocitySupport.readAddress(buf), port);
this.authenticatedProfile = VelocitySupport.createProfile(buf);

// late forge setup
boolean forwarded = false;
for (var property : this.authenticatedProfile.getProperties().values()) {
if (Objects.equals(property.name(), EXTRA_DATA)) {
String extraData = property.value().replace("\1", "\0");
var ctx = NetworkContext.get(this.connection);
ctx.processIntention(extraData);
if (ctx.getType() == ConnectionType.MODDED && ctx.getNetVersion() != NetworkContext.NET_VERSION) {
this.disconnect("This modded server is not impl compatible with your modded client. Please verify your Forge version closely matches the server. Got net version " + ctx.getNetVersion() + " this server is net version " + NetworkContext.NET_VERSION);
ci.cancel();
return;
}
if (ctx.getType() == ConnectionType.VANILLA && !NetworkRegistry.acceptsVanillaClientConnections()) {
this.disconnect("This server has mods that require Forge to be installed on the client. Contact your server admin for more details.");
ci.cancel();
return;
}
NetworkFilters.injectIfNecessary(this.connection);
forwarded = true;
break;
}
}
if (!forwarded) {
// considered vanilla
var ctx = NetworkContext.get(this.connection);
ctx.processIntention("");
if (ctx.getType() == ConnectionType.VANILLA && !NetworkRegistry.acceptsVanillaClientConnections()) {
this.disconnect("This server has mods that require Forge to be installed on the client. Contact your server admin for more details.");
ci.cancel();
return;
}
NetworkFilters.injectIfNecessary(this.connection);
}

// Proceed with login
Util.backgroundExecutor().execute(() -> {
try {
Expand Down

0 comments on commit 06e8a58

Please sign in to comment.