Exemple #1
0
        /// <summary>
        /// Writes a response code to the client and closes the current channel.
        /// </summary>
        /// <param name="ctx">The ctx.</param>
        /// <param name="response">The response.</param>
        private void WriteResponseCode(IChannelHandlerContext ctx, FourSevenFourLoginStatus response)
        {
            var buffer = ctx.Allocator.Buffer(sizeof(byte));

            buffer.WriteByte((int)response);
            ctx.WriteAndFlushAsync(buffer);
            HandleLoginProcessorResponse(null, response, ctx, null);
        }
Exemple #2
0
        private void HandleLoginProcessorResponse(Player player, FourSevenFourLoginStatus response, IChannelHandlerContext ctx, IsaacRandomPair randomPair)
        {
            if (response != FourSevenFourLoginStatus.StatusOk)
            {
                ctx.CloseAsync();
            }
            else
            {
                if (player == null)
                {
                    ctx.CloseAsync();
                    throw new InvalidOperationException("Cannot initialize player is null");
                }

                ctx.Channel.Pipeline.Remove(nameof(LoginEncoder));
                ctx.Channel.Pipeline.Remove(nameof(LoginDecoder));
                var gameMessageHandlers = _gameMessageProvider.Provide();

                foreach (var gameMessageHandler in gameMessageHandlers)
                {
                    /*if (gameMessageHandler is ICipherAwareHandler)
                     * {
                     *  ((ICipherAwareHandler)gameMessageHandler).CipherPair = randomPair;
                     * }*/

                    if (gameMessageHandler is IPlayerAwareHandler)
                    {
                        ((IPlayerAwareHandler)gameMessageHandler).Player = player;
                    }
                }
                ctx.Channel.Pipeline.AddLast(gameMessageHandlers);
                ctx.GetAttribute(Constants.PlayerAttributeKey).SetIfAbsent(player);
                player.ChannelHandlerContext = ctx;
                _world.Add(player);
                if (!_reconnecting)
                {
                    _ = _playerInitializer.InitializeAsync(player);
                }
                else
                {
                    player.UpdateAppearance();
                }
            }
        }