protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { @Override public void registerMap() { protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() { @Override public void registerMap() { protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() { @Override public void registerMap() {
/** * Use the pipeline to filter a NMS packet * * @param o The NMS packet object * @param list The output list to write to * @return If it should not write the input object to te list. * @throws Exception If it failed to convert / packet cancelld. */ public boolean filter(Object o, List list) throws Exception { for (Protocol protocol : protocolList) { if (protocol.isFiltered(o.getClass())) { protocol.filterPacket(userConnection, o, list); return true; } } return false; }
/** * Called when the server is enabled, to register any non registered listeners. */ public static void onServerLoaded() { for (Protocol protocol : registerList) { protocol.registerListeners(); protocol.register(Via.getManager().getProviders()); } registerList.clear(); }
/** * Register an outgoing packet, with simple id transformation. * * @param state The state which the packet is sent in. * @param oldPacketID The old packet ID * @param newPacketID The new packet ID */ public void registerOutgoing(State state, int oldPacketID, int newPacketID) { registerOutgoing(state, oldPacketID, newPacketID, null); }
/** * Add a protocol to the current pipeline * This will call the {@link Protocol#init(UserConnection)} method. * * @param protocol The protocol to add to the end */ public void add(Protocol protocol) { if (protocolList != null) { protocolList.add(protocol); protocol.init(userConnection); // Move base Protocols to the end, so the login packets can be modified by other protocols List<Protocol> toMove = new ArrayList<>(); for (Protocol p : protocolList) { if (ProtocolRegistry.isBaseProtocol(p)) { toMove.add(p); } } protocolList.removeAll(toMove); protocolList.addAll(toMove); } else { throw new NullPointerException("Tried to add protocol to early"); } }
/** * Applies a pipeline from an index to the wrapper * * @param direction The direction * @param state The state * @param index The index to start from * @param pipeline The pipeline * @return The current packetwrapper * @throws Exception If it fails to transform a packet, exception will be thrown */ public PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception { for (int i = index; i < pipeline.size(); i++) { // Copy to prevent from removal. pipeline.get(i).transform(direction, state, this); // Reset the reader for the packetWrapper (So it can be recycled across packets) resetReader(); } return this; }
/** * Register an incoming packet, with simple id transformation. * * @param state The state which the packet is sent in. * @param oldPacketID The old packet ID * @param newPacketID The new packet ID */ public void registerIncoming(State state, int oldPacketID, int newPacketID) { registerIncoming(state, oldPacketID, newPacketID, null); }
public Protocol() { registerPackets(); }
public static void register(Protocol protocol) { //spawn particle protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID map(Type.BOOLEAN); // 1 - Long Distance map(Type.FLOAT); // 2 - X map(Type.FLOAT); // 3 - Y map(Type.FLOAT); // 4 - Z map(Type.FLOAT); // 5 - Offset X map(Type.FLOAT); // 6 - Offset Y map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 8 - Particle Data map(Type.INT); // 9 - Particle Count handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int id = wrapper.get(Type.INT, 0); if (id == 27) { wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM)); } } }); } }); }
@Override public void init(UserConnection userConnection) { this.userConnection = userConnection; ProtocolInfo protocolInfo = new ProtocolInfo(userConnection); protocolInfo.setPipeline(this); userConnection.put(protocolInfo); /* Init through all our pipes */ for (Protocol protocol : protocolList) { protocol.init(userConnection); } }
@Override public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { super.transform(direction, state, packetWrapper); if (direction == Direction.INCOMING && state == State.HANDSHAKE) { // Disable if it isn't a handshake packet. if (packetWrapper.getId() != 0) { packetWrapper.user().setActive(false); } } } }
protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { @Override public void registerMap() { protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() { @Override public void registerMap() { protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() { @Override public void registerMap() {
protocol.registerOutgoing(State.PLAY, 0x38, 0x3D); protocol.registerOutgoing(State.PLAY, 0x3F, 0x3B); protocol.registerOutgoing(State.PLAY, 0x41, 0x3E, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x42, 0x3C);
protocol.init(user);
@Override public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { CompressionSendStorage compressionSendStorage = packetWrapper.user().get(CompressionSendStorage.class); if (compressionSendStorage.isCompressionSend()) { Channel channel = packetWrapper.user().getChannel(); channel.pipeline().replace("decompress", "decompress", new EmptyChannelHandler()); channel.pipeline().replace("compress", "compress", new ForwardMessageToByteEncoder()); compressionSendStorage.setCompressionSend(false); } super.transform(direction, state, packetWrapper); }
/** * Register a protocol * * @param protocol The protocol to register. * @param supported Supported client versions. * @param output The output server version it converts to. */ public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) { // Clear cache as this may make new routes. if (pathCache.size() > 0) pathCache.clear(); for (Integer version : supported) { if (!registryMap.containsKey(version)) { registryMap.put(version, new HashMap<Integer, Protocol>()); } registryMap.get(version).put(output, protocol); } if (Via.getPlatform().isPluginEnabled()) { protocol.registerListeners(); protocol.register(Via.getManager().getProviders()); refreshVersions(); } else { registerList.add(protocol); } }
protocol.registerOutgoing(State.PLAY, 0x11, 0x32); protocol.registerOutgoing(State.PLAY, 0x12, 0x2E, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x13, 0x2D, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x14, 0x30, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x15, 0x31); protocol.registerOutgoing(State.PLAY, 0x16, 0x2F, new PacketRemapper() { @Override public void registerMap() { protocol.registerIncoming(State.PLAY, 0x08, 0x0D, new PacketRemapper() { @Override public void registerMap() { protocol.registerIncoming(State.PLAY, 0x07, 0x0E, new PacketRemapper() { @Override public void registerMap() { protocol.registerIncoming(State.PLAY, 0x05, 0x0F);
public static void register(Protocol protocol) { protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { @Override public void registerMap() { protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { @Override public void registerMap() {
protocol.init(user);
super.transform(direction, state, packetWrapper);