use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class VersionedPacketTransformerImpl method transformPacket.
private void transformPacket(PacketWrapper packet) throws Exception {
// If clientbound: Constructor given inputProtocolVersion → Client version
// If serverbound: Constructor given inputProtocolVersion → Server version
PacketType packetType = packet.getPacketType();
UserConnection connection = packet.user();
boolean clientbound = packetType.direction() == Direction.CLIENTBOUND;
int serverProtocolVersion = clientbound ? this.inputProtocolVersion : connection.getProtocolInfo().getServerProtocolVersion();
int clientProtocolVersion = clientbound ? connection.getProtocolInfo().getProtocolVersion() : this.inputProtocolVersion;
// Construct protocol pipeline
List<ProtocolPathEntry> path = Via.getManager().getProtocolManager().getProtocolPath(clientProtocolVersion, serverProtocolVersion);
List<Protocol> protocolList = null;
if (path != null) {
protocolList = new ArrayList<>(path.size());
for (ProtocolPathEntry entry : path) {
protocolList.add(entry.protocol());
}
} else if (serverProtocolVersion != clientProtocolVersion) {
throw new RuntimeException("No protocol path between client version " + clientProtocolVersion + " and server version " + serverProtocolVersion);
}
if (protocolList != null) {
// Reset reader and apply pipeline
packet.resetReader();
try {
packet.apply(packetType.direction(), State.PLAY, 0, protocolList, clientbound);
} catch (Exception e) {
throw new Exception("Exception trying to transform packet between client version " + clientProtocolVersion + " and server version " + serverProtocolVersion + ". Are you sure you used the correct input version and packet write types?", e);
}
}
}
use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class ConnectionManagerImpl method getConnectedClientId.
@Override
@Nullable
public UUID getConnectedClientId(UserConnection connection) {
if (connection.getProtocolInfo() == null)
return null;
UUID uuid = connection.getProtocolInfo().getUuid();
UserConnection client = clients.get(uuid);
if (connection.equals(client)) {
// This is frontend
return uuid;
}
return null;
}
use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class CommonBoss method sendPacket.
private void sendPacket(UpdateAction action) {
for (UserConnection conn : new ArrayList<>(connections.values())) {
PacketWrapper wrapper = getPacket(action, conn);
sendPacketConnection(conn, wrapper);
}
}
use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class ViaIdleThread method run.
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
ProtocolInfo protocolInfo = info.getProtocolInfo();
if (protocolInfo == null || !protocolInfo.getPipeline().contains(Protocol1_9To1_8.class))
continue;
MovementTracker movementTracker = info.get(MovementTracker.class);
if (movementTracker == null)
continue;
long nextIdleUpdate = movementTracker.getNextIdlePacket();
if (nextIdleUpdate <= System.currentTimeMillis() && info.getChannel().isOpen()) {
Via.getManager().getProviders().get(MovementTransmitterProvider.class).sendPlayer(info);
}
}
}
use of com.viaversion.viaversion.api.connection.UserConnection in project LiquidBouncePlus by WYSI-Foundation.
the class ProviderLoader method load.
@Override
public void load() {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new BaseVersionProvider() {
@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide())
return ViaForge.getInstance().getVersion();
return super.getClosestServerProtocol(connection);
}
});
}
Aggregations