WIP: Packet Handling

This commit is contained in:
Adrian Bergqvist 2022-09-14 22:47:11 +02:00
parent 55bb6df100
commit fcb2491c66
No known key found for this signature in database
GPG Key ID: FAE7D8EDE225E686
4 changed files with 45 additions and 7 deletions

View File

@ -4,19 +4,24 @@ import com.velocitypowered.proxy.connection.MinecraftConnection;
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
import org.adde0109.ambassador.velocity.VelocityForgeHandshakeSessionHandler;
import javax.annotation.Nullable;
public class ForgeFML2ClientConnectionPhase implements VelocityForgeClientConnectionPhase {
private final MinecraftConnection connection;
private boolean isResettable;
private ByteBuf modListData;
ForgeFML2ClientConnectionPhase(MinecraftConnection connection) {
this.connection = connection;
}
@Override
public void handleLogin(ForgeHandshakeUtils.CachedServerHandshake handshake) {
this.connection.setSessionHandler(new VelocityForgeHandshakeSessionHandler());
public void handleLogin(@Nullable ForgeHandshakeUtils.CachedServerHandshake handshake) {
if(handshake == null) {
this.connection.write(new LoginPluginMessage(98,"fml:loginwrapper", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generateResetPacket())));
} else {
@ -24,7 +29,18 @@ public class ForgeFML2ClientConnectionPhase implements VelocityForgeClientConnec
for (int i = 0;i<handshake.otherPackets.size();i++) {
this.connection.delayedWrite(new LoginPluginMessage(i+2,"fml:loginwrapper", Unpooled.wrappedBuffer(handshake.otherPackets.get(i))));
}
//TODO:Register sent packets
this.connection.setSessionHandler(new VelocityForgeHandshakeSessionHandler(this));
this.connection.flush();
}
}
@Override
public void handle(LoginPluginResponse packet) {
if (packet.getId() == 98) {
isResettable = packet.isSuccess();
} else {
modListData = packet.content().retain();
}
}
}

View File

@ -38,7 +38,12 @@ public class ForgeHandshakeHandler {
public void handleLogin(ConnectedPlayer player, ForgeFML2ClientConnectionPhase phase, Continuation continuation) {
getInitialHandshake(player).whenComplete((msg,ex) -> phase.handleLogin(msg));
getInitialHandshake(player).whenCompleteAsync((msg,ex) -> {
if (ex != null) {
ambassador.logger.warn("Forge player, " + player.getUsername() + ", is entering vanilla-mode because of: " + ex.getMessage());
}
phase.handleLogin(msg);
}, player.getConnection().eventLoop());
}
private CompletableFuture<ForgeHandshakeUtils.CachedServerHandshake> getInitialHandshake(ConnectedPlayer player) {
@ -47,7 +52,7 @@ public class ForgeHandshakeHandler {
if((initialServer = ambassador.config.getServer(player.getConnection().getProtocolVersion().getProtocol())) != null) {
future = ForgeHandshakeUtils.HandshakeReceiver.downloadHandshake(initialServer);
} else {
future = CompletableFuture.failedFuture(new Exception("No initial server specified"));
future = CompletableFuture.failedFuture(new Exception("No initial server is specified"));
}
return future;
}

View File

@ -1,10 +1,16 @@
package org.adde0109.ambassador.velocity;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
import org.adde0109.ambassador.forge.ForgeHandshakeUtils;
public interface VelocityForgeClientConnectionPhase extends ClientConnectionPhase {
default void handleLogin(ForgeHandshakeUtils.CachedServerHandshake handshake) {
import javax.annotation.Nullable;
public interface VelocityForgeClientConnectionPhase extends ClientConnectionPhase {
default void handleLogin(@Nullable ForgeHandshakeUtils.CachedServerHandshake initialHandshake) {
}
default void handle(LoginPluginResponse packet) {
}
}

View File

@ -1,11 +1,22 @@
package org.adde0109.ambassador.velocity;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
public class VelocityForgeHandshakeSessionHandler implements MinecraftSessionHandler {
private final VelocityForgeClientConnectionPhase phase;
public VelocityForgeHandshakeSessionHandler(VelocityForgeClientConnectionPhase phase) {
this.phase = phase;
}
@Override
public boolean handle(LoginPluginResponse packet) {
return true;
//TODO: Check if we sent it
if (packet.getId() == 1 && packet.getId() == 98) {
phase.handle(packet);
}
return true;
}
}