WIP: listen to response
This commit is contained in:
parent
fcb2491c66
commit
fe69711818
|
|
@ -1,5 +1,6 @@
|
|||
package org.adde0109.ambassador.forge;
|
||||
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
|
|
@ -17,30 +18,37 @@ public class ForgeFML2ClientConnectionPhase implements VelocityForgeClientConnec
|
|||
private final MinecraftConnection connection;
|
||||
private boolean isResettable;
|
||||
private ByteBuf modListData;
|
||||
private Continuation whenComplete;
|
||||
ForgeFML2ClientConnectionPhase(MinecraftConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
@Override
|
||||
public void handleLogin(@Nullable ForgeHandshakeUtils.CachedServerHandshake handshake) {
|
||||
public void handleLogin(ForgeHandshakeUtils.CachedServerHandshake handshake, Continuation continuation) {
|
||||
VelocityForgeHandshakeSessionHandler sessionHandler = new VelocityForgeHandshakeSessionHandler(this);
|
||||
if(handshake == null) {
|
||||
this.connection.write(new LoginPluginMessage(98,"fml:loginwrapper", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generateResetPacket())));
|
||||
sessionHandler.listen(98);
|
||||
} else {
|
||||
this.connection.delayedWrite(new LoginPluginMessage(1,"fml:loginwrapper", Unpooled.wrappedBuffer(handshake.modListPacket)));
|
||||
sessionHandler.listen(1);
|
||||
for (int i = 0;i<handshake.otherPackets.size();i++) {
|
||||
this.connection.delayedWrite(new LoginPluginMessage(i+2,"fml:loginwrapper", Unpooled.wrappedBuffer(handshake.otherPackets.get(i))));
|
||||
sessionHandler.listen(i+2);
|
||||
}
|
||||
//TODO:Register sent packets
|
||||
this.connection.setSessionHandler(new VelocityForgeHandshakeSessionHandler(this));
|
||||
this.connection.setSessionHandler(sessionHandler);
|
||||
this.connection.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(LoginPluginResponse packet) {
|
||||
public void handle(LoginPluginResponse packet, boolean lastMessage) {
|
||||
if (packet.getId() == 98) {
|
||||
isResettable = packet.isSuccess();
|
||||
} else {
|
||||
modListData = packet.content().retain();
|
||||
}
|
||||
if (lastMessage) {
|
||||
whenComplete.resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class ForgeHandshakeHandler {
|
|||
if (ex != null) {
|
||||
ambassador.logger.warn("Forge player, " + player.getUsername() + ", is entering vanilla-mode because of: " + ex.getMessage());
|
||||
}
|
||||
phase.handleLogin(msg);
|
||||
phase.handleLogin(msg,continuation);
|
||||
}, player.getConnection().eventLoop());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.adde0109.ambassador.velocity;
|
||||
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
|
|
@ -9,8 +10,8 @@ import javax.annotation.Nullable;
|
|||
|
||||
public interface VelocityForgeClientConnectionPhase extends ClientConnectionPhase {
|
||||
|
||||
default void handleLogin(@Nullable ForgeHandshakeUtils.CachedServerHandshake initialHandshake) {
|
||||
default void handleLogin(@Nullable ForgeHandshakeUtils.CachedServerHandshake initialHandshake, Continuation continuation) {
|
||||
}
|
||||
default void handle(LoginPluginResponse packet) {
|
||||
default void handle(LoginPluginResponse packet, boolean lastMessage) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityForgeHandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
private final ArrayList<Integer> listenerList = new ArrayList();
|
||||
private final VelocityForgeClientConnectionPhase phase;
|
||||
public VelocityForgeHandshakeSessionHandler(VelocityForgeClientConnectionPhase phase) {
|
||||
this.phase = phase;
|
||||
|
|
@ -13,10 +16,12 @@ public class VelocityForgeHandshakeSessionHandler implements MinecraftSessionHan
|
|||
|
||||
@Override
|
||||
public boolean handle(LoginPluginResponse packet) {
|
||||
//TODO: Check if we sent it
|
||||
if (packet.getId() == 1 && packet.getId() == 98) {
|
||||
phase.handle(packet);
|
||||
if (listenerList.removeIf(id -> id.equals(packet.getId()))) {
|
||||
phase.handle(packet, listenerList.isEmpty());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void listen(int id) {
|
||||
listenerList.add(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user