Catcher that catches anything sent to the client in reset
This commit is contained in:
parent
cc589a17d8
commit
81d22900fa
|
|
@ -10,6 +10,7 @@ import com.velocitypowered.proxy.config.VelocityConfiguration;
|
|||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.network.Connections;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
|
|
@ -18,16 +19,19 @@ import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.adde0109.ambassador.velocity.VelocityForgeClientConnectionPhase;
|
||||
import org.adde0109.ambassador.velocity.VelocityForgeHandshakeSessionHandler;
|
||||
import org.adde0109.ambassador.velocity.VelocityLoginPayloadManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class FML2CRPMClientConnectionPhase implements VelocityForgeClientConnectionPhase {
|
||||
private boolean isResettable;
|
||||
private static String OUTBOUND_CATCHER_NAME = "ambassador-catcher";
|
||||
|
||||
//TODO: Use modData inside ConnectedPlayer instead
|
||||
public byte[] modListData;
|
||||
|
|
@ -64,6 +68,7 @@ public class FML2CRPMClientConnectionPhase implements VelocityForgeClientConnect
|
|||
MinecraftConnection connection = player.getConnection();
|
||||
connection.setSessionHandler(new VelocityForgeHandshakeSessionHandler(connection.getSessionHandler(),player));
|
||||
|
||||
|
||||
if (connection.getState() == StateRegistry.LOGIN) {
|
||||
payloadManager.sendPayload("fml:loginwrapper", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generateResetPacket()));
|
||||
} else {
|
||||
|
|
@ -76,6 +81,7 @@ public class FML2CRPMClientConnectionPhase implements VelocityForgeClientConnect
|
|||
});
|
||||
|
||||
this.clientPhase = null;
|
||||
connection.getChannel().pipeline().addBefore(Connections.HANDLER,OUTBOUND_CATCHER_NAME,new FML2CRPMOutgoingCatcher());
|
||||
}
|
||||
public void complete(VelocityServer server, ConnectedPlayer player, MinecraftConnection connection) {
|
||||
VelocityConfiguration configuration = (VelocityConfiguration) server.getConfiguration();
|
||||
|
|
@ -92,6 +98,10 @@ public class FML2CRPMClientConnectionPhase implements VelocityForgeClientConnect
|
|||
|
||||
connection.setState(StateRegistry.PLAY);
|
||||
connection.setSessionHandler(((VelocityForgeHandshakeSessionHandler) connection.getSessionHandler()).getOriginal());
|
||||
try {
|
||||
connection.getChannel().pipeline().remove(OUTBOUND_CATCHER_NAME);
|
||||
} catch (NoSuchElementException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleKick(KickedFromServerEvent event) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package org.adde0109.ambassador.forge;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
||||
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FML2CRPMOutgoingCatcher extends ChannelOutboundHandlerAdapter {
|
||||
|
||||
private final Map<ChannelPromise, Object> catchedPackets = Collections.synchronizedMap(new LinkedHashMap<>());
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
final Set<Map.Entry<ChannelPromise, Object>> s = catchedPackets.entrySet();
|
||||
Iterator<Map.Entry<ChannelPromise, Object>> i = s.iterator();
|
||||
while (catchedPackets.entrySet().iterator().hasNext()) {
|
||||
final Map.Entry<ChannelPromise, Object> entry = i.next();
|
||||
ctx.write(entry.getValue(),entry.getKey());
|
||||
i.remove();
|
||||
}
|
||||
ctx.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
if (msg instanceof LoginPluginMessage || msg instanceof ServerLoginSuccess) {
|
||||
ctx.write(msg, promise);
|
||||
} else {
|
||||
catchedPackets.put(promise,msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,12 +5,9 @@ import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
|
|||
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class VelocityLoginPayloadManager {
|
||||
private final HashMap<Integer, CompletableFuture<ByteBuf>> listenerList = new HashMap<>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user