Search in sources :

Example 26 with ServerSession

use of com.github.dirtpowered.dirtmv.network.server.ServerSession in project DirtMultiversion by DirtPowered.

the class GlobalProtocolHandler method registerTranslators.

@Override
public void registerTranslators() {
    // chat (pre-netty)
    addTranslator(0x03, ProtocolState.PRE_NETTY, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            int clientVersion = session.getUserData().getClientVersion().getRegistryId();
            String message = clientVersion <= 10 ? data.read(Type.UTF8_STRING, 0) : data.read(Type.STRING, 0);
            onChat(session, message);
            return data;
        }
    });
    // chat (post-netty)
    addTranslator(0x01, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            String message = data.read(Type.V1_7_STRING, 0);
            onChat(session, message);
            return data;
        }
    });
    // login (pre-netty)
    addTranslator(0x01, ProtocolState.PRE_NETTY, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            int clientVersion = session.getUserData().getClientVersion().getRegistryId();
            String username = clientVersion <= 10 ? data.read(Type.UTF8_STRING, 1) : data.read(Type.STRING, 1);
            session.getUserData().setUsername(username);
            return data;
        }
    });
    // login (post-netty)
    addTranslator(0x00, ProtocolState.LOGIN, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            session.getUserData().setUsername(data.read(Type.V1_7_STRING, 0));
            return data;
        }
    });
}
Also used : ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Aggregations

ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)26 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)25 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)25 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)23 ItemStack (com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack)14 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)8 List (java.util.List)8 Motion (com.github.dirtpowered.dirtmv.data.protocol.objects.Motion)5 SneakyThrows (lombok.SneakyThrows)5 MinecraftVersion (com.github.dirtpowered.dirtmv.data.MinecraftVersion)4 EntityType (com.github.dirtpowered.dirtmv.data.entity.EntityType)4 V1_2MultiBlockArray (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2MultiBlockArray)4 WatchableObject (com.github.dirtpowered.dirtmv.data.protocol.objects.WatchableObject)4 BlockStorage (com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 DirtMultiVersion (com.github.dirtpowered.dirtmv.DirtMultiVersion)3 BlockLocation (com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation)3 Location (com.github.dirtpowered.dirtmv.data.protocol.objects.Location)3 V1_2Chunk (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2Chunk)3