/** * 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); }
/** * 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 static void refreshVersions() { supportedVersions.clear(); supportedVersions.add(ProtocolRegistry.SERVER_PROTOCOL); for (ProtocolVersion versions : ProtocolVersion.getProtocols()) { List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getId(), ProtocolRegistry.SERVER_PROTOCOL); if (paths == null) continue; supportedVersions.add(versions.getId()); for (Pair<Integer, Protocol> path : paths) supportedVersions.add(path.getKey()); } }
default void init(ViaRewindConfig config) { ViaRewind.init(this, config); ProtocolRegistry.registerProtocol(new Protocol1_8TO1_9(), Collections.singletonList(ProtocolVersion.v1_8.getId()), ProtocolVersion.v1_9.getId()); ProtocolRegistry.registerProtocol(new Protocol1_7_6_10TO1_8(), Collections.singletonList(ProtocolVersion.v1_7_6.getId()), ProtocolVersion.v1_8.getId()); ProtocolRegistry.registerProtocol(new Protocol1_7_0_5to1_7_6_10(), Collections.singletonList(ProtocolVersion.v1_7_1.getId()), ProtocolVersion.v1_7_6.getId()); }
/** * Cleans the pipe and adds {@link us.myles.ViaVersion.protocols.base.BaseProtocol} * /!\ WARNING - It doesn't add version-specific base Protocol */ public void cleanPipes() { pipes().clear(); registerPackets(); } }
/** * 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"); } }
@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); } }
/** * 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(); }
@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); } } } }
/** * Register an incoming packet, with id transformation and remapper. * * @param state The state which the packet is sent in. * @param oldPacketID The old packet ID * @param newPacketID The new packet ID * @param packetRemapper The remapper to use for the packet */ public void registerIncoming(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) { ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper); incoming.put(new Pair<>(state, newPacketID), protocolPacket); }
public ProtocolPipeline(UserConnection userConnection) { super(); init(userConnection); }
public Protocol() { registerPackets(); }
public static ProtocolVersion getProtocol(int id) { ProtocolVersion protocolVersion = versions.get(id); if (protocolVersion != null) { return protocolVersion; } else { return new ProtocolVersion(id, "Unknown (" + id + ")"); } }
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)); } } }); } }); }
/** * Register an outgoing packet, with id transformation and remapper. * * @param state The state which the packet is sent in. * @param oldPacketID The old packet ID * @param newPacketID The new packet ID * @param packetRemapper The remapper to use for the packet */ public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) { ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper); outgoing.put(new Pair<>(state, oldPacketID), protocolPacket); }
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);