Search in sources :

Example 1 with MinecraftVersion

use of com.github.dirtpowered.dirtmv.data.MinecraftVersion in project DirtMultiversion by DirtPowered.

the class YamlConfig method getServerVersion.

@Override
public MinecraftVersion getServerVersion() {
    String val = (String) objects.getOrDefault("server_version", "B1_7_3");
    MinecraftVersion version = null;
    try {
        version = MinecraftVersion.valueOf(val);
    } catch (IllegalArgumentException e) {
        Logger.error("invalid server version {}, stopping", val);
        System.exit(0);
    }
    return version;
}
Also used : MinecraftVersion(com.github.dirtpowered.dirtmv.data.MinecraftVersion)

Example 2 with MinecraftVersion

use of com.github.dirtpowered.dirtmv.data.MinecraftVersion in project DirtMultiversion by DirtPowered.

the class ClientSession method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, PacketData packetData) {
    // server to client packets
    serverSession.sendPacket(packetData, PacketDirection.TO_CLIENT, null);
    // notify other sessions
    if (!stateLock) {
        boolean postNettyFlag = serverSession.getUserData().getProtocolState() == ProtocolState.PLAY;
        boolean preNettyFlag = serverSession.getUserData().getPreNettyProtocolState() == PreNettyProtocolState.IN_GAME;
        if (preNettyFlag || postNettyFlag) {
            MinecraftVersion server = main.getConfiguration().getServerVersion();
            MinecraftVersion client = serverSession.getUserData().getClientVersion();
            // call #onConnect only in user protocols
            for (ServerProtocol t : main.getTranslatorRegistry().getAllProtocolsBetween(server, client)) {
                t.onConnect(serverSession);
            }
            stateLock = true;
        }
    }
}
Also used : ServerProtocol(com.github.dirtpowered.dirtmv.data.translator.ServerProtocol) MinecraftVersion(com.github.dirtpowered.dirtmv.data.MinecraftVersion)

Example 3 with MinecraftVersion

use of com.github.dirtpowered.dirtmv.data.MinecraftVersion in project DirtMultiversion by DirtPowered.

the class ServerSession method channelInactive.

@Override
public void channelInactive(ChannelHandlerContext ctx) {
    disconnect();
    // notify other sessions
    MinecraftVersion server = main.getConfiguration().getServerVersion();
    MinecraftVersion client = userData.getClientVersion();
    // call #onDisconnect only in user protocols
    main.getTranslatorRegistry().getAllProtocolsBetween(server, client).forEach(t -> t.onDisconnect(this));
    ClientSession clientSession = getClientSession();
    if (clientSession != null) {
        clientSession.disconnectRemote();
    }
}
Also used : ClientSession(com.github.dirtpowered.dirtmv.network.client.ClientSession) MinecraftVersion(com.github.dirtpowered.dirtmv.data.MinecraftVersion)

Example 4 with MinecraftVersion

use of com.github.dirtpowered.dirtmv.data.MinecraftVersion in project DirtMultiversion by DirtPowered.

the class ServerSession method sendPacket.

/**
 * Translates and sends packet to server
 *
 * @param packet    {@link PacketData} Packet
 * @param direction {@link PacketDirection} sending direction (client/server)
 * @param from      Version to start from
 */
public void sendPacket(PacketData packet, PacketDirection direction, MinecraftVersion from) {
    MinecraftVersion version = main.getConfiguration().getServerVersion();
    if (from != null && from != version) {
        version = from;
    }
    List<ServerProtocol> protocols = main.getTranslatorRegistry().findProtocol(userData, version);
    boolean flag = direction == PacketDirection.TO_CLIENT;
    if (!flag) {
        Collections.reverse(protocols);
    }
    PacketData target = packet;
    for (ServerProtocol protocol : protocols) {
        boolean isNetty = userData.getClientVersion().isNettyProtocol();
        ProtocolState state = isNetty ? userData.getProtocolState() : ProtocolState.PRE_NETTY;
        if (target == null) {
            return;
        }
        // packet queue workaround
        state = packet.getNettyState() != null ? packet.getNettyState() : state;
        if (!protocol.getFrom().isNettyProtocol()) {
            state = ProtocolState.PRE_NETTY;
        }
        PacketTranslator translator = protocol.getTranslatorFor(target.getOpCode(), state, direction);
        if (translator != null) {
            if (from == null || from != protocol.getFrom()) {
                try {
                    target = translator.translate(this, target);
                } catch (IOException e) {
                    disconnect(e.getMessage());
                    return;
                }
                if (target.getOpCode() == -1) {
                    return;
                }
            }
        }
    }
    if (flag) {
        sendPacket(target);
    } else {
        ClientSession clientSession = getClientSession();
        if (target.getOpCode() == 2 && /* handshake */
        !hasServerPingProtocol()) {
            connectToServer();
        }
        if (clientSession != null && clientSession.getChannel().isActive()) {
            clientSession.sendPacket(target);
            return;
        }
        // queued packets are always login packets
        target.setNettyState(ProtocolState.LOGIN);
        initialPacketQueue.add(target);
    }
}
Also used : PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) ClientSession(com.github.dirtpowered.dirtmv.network.client.ClientSession) IOException(java.io.IOException) ServerProtocol(com.github.dirtpowered.dirtmv.data.translator.ServerProtocol) ProtocolState(com.github.dirtpowered.dirtmv.data.translator.ProtocolState) MinecraftVersion(com.github.dirtpowered.dirtmv.data.MinecraftVersion) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Example 5 with MinecraftVersion

use of com.github.dirtpowered.dirtmv.data.MinecraftVersion in project DirtMultiversion by DirtPowered.

the class PacketDecoder method setUserProtocol.

private void setUserProtocol(boolean flag, ByteBuf buffer) {
    if (!flag && !userData.isProtocolDetected()) {
        buffer.markReaderIndex();
        MinecraftVersion clientVersion = userData.getClientVersion();
        int packetId = buffer.readUnsignedByte();
        if (packetId == 0x01) /* login */
        {
            clientVersion = MinecraftVersion.fromRegistryId(buffer.readInt());
            userData.setProtocolDetected(true);
        } else if (packetId == 0x02) /* handshake */
        {
            // 1.3+ client is sending protocol version in handshake packet
            int protocol = buffer.readByte();
            if (protocol != 0) {
                clientVersion = MinecraftVersion.fromRegistryId(protocol);
                userData.setProtocolDetected(true);
            }
        }
        buffer.resetReaderIndex();
        userData.setClientVersion(clientVersion);
    }
}
Also used : MinecraftVersion(com.github.dirtpowered.dirtmv.data.MinecraftVersion)

Aggregations

MinecraftVersion (com.github.dirtpowered.dirtmv.data.MinecraftVersion)6 ServerProtocol (com.github.dirtpowered.dirtmv.data.translator.ServerProtocol)3 ClientSession (com.github.dirtpowered.dirtmv.network.client.ClientSession)2 Configuration (com.github.dirtpowered.dirtmv.api.Configuration)1 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)1 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)1 ProtocolState (com.github.dirtpowered.dirtmv.data.translator.ProtocolState)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 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1