/** * Checks if the UUID is on the selected pipe * * @param uuid UUID Object * @return True if on pipe */ protected boolean isOnPipe(UUID uuid) { UserConnection userConnection = getUserConnection(uuid); return userConnection != null && userConnection.get(ProtocolInfo.class).getPipeline().contains(requiredPipeline); }
@Override public int getPlayerVersion(@NonNull UUID uuid) { if (!isPorted(uuid)) { return VelocityPlugin.PROXY.getPlayer(uuid) .map(InboundConnection::getProtocolVersion) .map(ProtocolVersion::getProtocol) .orElse(ProtocolRegistry.SERVER_PROTOCOL); } return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion(); }
public static UUID getUUID(UserConnection user) { return user.get(ProtocolInfo.class).getUuid(); } }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
int previousServerProtocol = info.getServerProtocolVersion(); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); pipeline.cleanPipes(); if (protocols == null) { protocolId = info.getProtocolVersion(); } else { for (Pair<Integer, Protocol> prot : protocols) { info.setServerProtocolVersion(protocolId);
int serverProtocol = userConnection.get(ProtocolInfo.class).getServerProtocolVersion(); int clientProtocol = userConnection.get(ProtocolInfo.class).getProtocolVersion(); ViaPlatform platform = Via.getPlatform(); String actualUsername = packetWrapper.user().get(ProtocolInfo.class).getUsername(); String username = actualUsername != null ? actualUsername + " " : "";
public void sendPlayer(UserConnection userConnection) { if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { wrapper.sendToServer(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } // PlayerPackets will increment idle } } }
@Override protected byte getStates(UserConnection user, Position position, int blockState) { byte states = super.getStates(user, position, blockState); return states == 0 && user.get(ProtocolInfo.class).getServerProtocolVersion() <= 47 && user.get(ProtocolInfo.class).getServerProtocolVersion() != -1 ? 0xF : states; } }
List<Protocol> protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes()); if (direction == Direction.OUTGOING) { apply(direction, user().get(ProtocolInfo.class).getState(), index, protocols);
int previousServerProtocol = info.getServerProtocolVersion(); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); pipeline.cleanPipes(); if (protocols == null) { protocolId = info.getProtocolVersion(); } else { for (Pair<Integer, Protocol> prot : protocols) { info.setServerProtocolVersion(protocolId);
public void sendPlayer(UserConnection userConnection) { if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { wrapper.sendToServer(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } // PlayerPackets will increment idle } } }
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper); wrapper.writeToBuffer(bytebuf); } catch (Exception e) {
@Override public int getServerProtocol(UserConnection user) throws Exception { if (ref == null) return super.getServerProtocol(user); // TODO Have one constant list forever until restart? (Might limit plugins if they change this) List<Integer> list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); List<Integer> sorted = new ArrayList<>(list); Collections.sort(sorted); ProtocolInfo info = user.get(ProtocolInfo.class); // Bungee supports it if (sorted.contains(info.getProtocolVersion())) return info.getProtocolVersion(); // Older than bungee supports, get the lowest version if (info.getProtocolVersion() < sorted.get(0)) { return getLowestSupportedVersion(); } // Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too) // TODO: This needs a better fix, i.e checking ProtocolRegistry to see if it would work. // This is more of a workaround for snapshot support by bungee. for (Integer protocol : Lists.reverse(sorted)) { if (info.getProtocolVersion() > protocol && ProtocolVersion.isRegistered(protocol)) return protocol; } Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + info.getProtocolVersion()); return info.getProtocolVersion(); }
@Override protected void encode(ChannelHandlerContext ctx, Object o, List list) throws Exception { // Split chunks bulk packet up in to single chunks packets before it reached the encoder. // This will prevent issues with several plugins and other protocol handlers due to the chunks being sent twice. // It also sends the chunks in the right order possible resolving some issues with added chunks/block/entity data. if (!(o instanceof ByteBuf)) { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ if (info.isActive()) { if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) { return; } } } list.add(o); } }
@Override public Set<UUID> getPlayers() { return Collections.singleton(connection.get(ProtocolInfo.class).getUuid()); }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
@Override public int getPlayerVersion(@NonNull UUID uuid) { if (!isPorted(uuid)) return ProtocolRegistry.SERVER_PROTOCOL; return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion(); }
@Override protected void encode(ChannelHandlerContext ctx, Object o, List list) throws Exception { // Split chunks bulk packet up in to single chunks packets before it reached the encoder. // This will prevent issues with several plugins and other protocol handlers due to the chunks being sent twice. // It also sends the chunks in the right order possible resolving some issues with added chunks/block/entity data. if (!(o instanceof ByteBuf)) { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ if (info.isActive()) { if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) { return; } } } list.add(o); } }
public void addPortedClient(UserConnection info) { portedPlayers.put(info.get(ProtocolInfo.class).getUuid(), info); }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);