Example #1
0
        internal static void Register <TPacket>(PacketDirection packetDirection, ConnectionState state, int packetId, Func <TPacket> createFunc) where TPacket : Packet
        {
            if (packetDirection == PacketDirection.ServerBound)
            {
                switch (state)
                {
                case ConnectionState.Handshake:
                    HandshakeFactory.Register(packetId, createFunc);
                    break;

                case ConnectionState.Status:
                    StatusFactory.Register(packetId, createFunc);
                    break;

                case ConnectionState.Login:
                    LoginFactory.Register(packetId, createFunc);
                    break;

                case ConnectionState.Play:
                    PlayFactory.Register(packetId, createFunc);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(state), state, null);
                }
            }
            else
            {
                switch (state)
                {
                case ConnectionState.Handshake:
                    ServerHandshakeFactory.Register(packetId, createFunc);
                    break;

                case ConnectionState.Status:
                    ServerStatusFactory.Register(packetId, createFunc);
                    break;

                case ConnectionState.Login:
                    ServerLoginFactory.Register(packetId, createFunc);
                    break;

                case ConnectionState.Play:
                    ServerPlayFactory.Register(packetId, createFunc);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(state), state, null);
                }
            }
        }
Example #2
0
        internal static void Register <TPacket>(ConnectionState state, int packetId, Func <TPacket> createFunc) where TPacket : Packet
        {
            switch (state)
            {
            case ConnectionState.Handshake:
                HandshakeFactory.Register(packetId, createFunc);
                break;

            case ConnectionState.Status:
                StatusFactory.Register(packetId, createFunc);
                break;

            case ConnectionState.Login:
                LoginFactory.Register(packetId, createFunc);
                break;

            case ConnectionState.Play:
                PlayFactory.Register(packetId, createFunc);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }
        }