Search in sources :

Example 1 with ProtocolStateHandler

use of com.github.dirtpowered.dirtmv.network.versions.ProtocolStateHandler in project DirtMultiversion by DirtPowered.

the class TranslatorRegistry method findProtocol.

/**
 * Returns all protocols translators between client and server version
 *
 * @param data      User data
 * @param versionTo Server version
 * @return {@link List<ServerProtocol> List} with ordered protocol pipeline classes
 */
public List<ServerProtocol> findProtocol(UserData data, MinecraftVersion versionTo) {
    List<ServerProtocol> serverProtocols = new LinkedList<>();
    MinecraftVersion from = data.getClientVersion();
    Configuration c = main.getConfiguration();
    GlobalProtocolHandler globalProtocolHandler = new GlobalProtocolHandler(from, versionTo);
    // check if translating is needed
    if (from == c.getServerVersion()) {
        ServerProtocol serverProtocol;
        // starting from r1.3 the whole connections is encrypted
        if (from.getRegistryId() >= MinecraftVersion.R1_3_1.getRegistryId() && !from.isNettyProtocol()) {
            serverProtocol = new ProtocolPassthroughEncrypted(from, versionTo);
        } else if (from.isNettyProtocol()) {
            serverProtocol = new ProtocolStateHandler(from, versionTo);
        } else {
            serverProtocol = new ProtocolPassthrough(from, versionTo);
        }
        return Arrays.asList(serverProtocol, globalProtocolHandler);
    } else {
        if (from.getRegistryId() < 39) {
            serverProtocols.add(new ProtocolPassthrough(from, versionTo));
        }
        if ((from.getRegistryId() >= 39 && c.getServerVersion().getRegistryId() >= 39) && !from.isNettyProtocol()) {
            // add encryption translators to pipeline
            serverProtocols.add(new ProtocolPassthroughEncrypted(from, versionTo));
        }
    }
    int clientProtocol = from.getRegistryId();
    int serverProtocol = versionTo.getRegistryId();
    for (int i = serverProtocol; i <= clientProtocol; i++) {
        if (MinecraftVersion.fromRegistryId(i) != null) {
            ServerProtocol target = protocols.get(i);
            if (target != null && !(i <= serverProtocol)) {
                serverProtocols.add(target);
            }
        }
    }
    if (from.isNettyProtocol()) {
        serverProtocols.add(new ProtocolStateHandler(from, versionTo));
    }
    // track packets in all protocols
    serverProtocols.add(globalProtocolHandler);
    return serverProtocols;
}
Also used : ProtocolStateHandler(com.github.dirtpowered.dirtmv.network.versions.ProtocolStateHandler) Configuration(com.github.dirtpowered.dirtmv.api.Configuration) ProtocolPassthroughEncrypted(com.github.dirtpowered.dirtmv.network.versions.ProtocolPassthroughEncrypted) ProtocolPassthrough(com.github.dirtpowered.dirtmv.network.versions.ProtocolPassthrough) GlobalProtocolHandler(com.github.dirtpowered.dirtmv.network.versions.handler.GlobalProtocolHandler) ServerProtocol(com.github.dirtpowered.dirtmv.data.translator.ServerProtocol) LinkedList(java.util.LinkedList) MinecraftVersion(com.github.dirtpowered.dirtmv.data.MinecraftVersion)

Aggregations

Configuration (com.github.dirtpowered.dirtmv.api.Configuration)1 MinecraftVersion (com.github.dirtpowered.dirtmv.data.MinecraftVersion)1 ServerProtocol (com.github.dirtpowered.dirtmv.data.translator.ServerProtocol)1 ProtocolPassthrough (com.github.dirtpowered.dirtmv.network.versions.ProtocolPassthrough)1 ProtocolPassthroughEncrypted (com.github.dirtpowered.dirtmv.network.versions.ProtocolPassthroughEncrypted)1 ProtocolStateHandler (com.github.dirtpowered.dirtmv.network.versions.ProtocolStateHandler)1 GlobalProtocolHandler (com.github.dirtpowered.dirtmv.network.versions.handler.GlobalProtocolHandler)1 LinkedList (java.util.LinkedList)1