Exemplo n.º 1
0
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = Group;

            if (g == null)
            {
                lock (this)
                {
                    g = Group ?? (Group = new DefaultChannelGroup(contex.Executor));
                }
            }
            base.ChannelActive(contex);
            string msg = $"欢迎 to {0} secure chat server! { Dns.GetHostName()}\n";

            ReplyContent <string> reply = new ReplyContent <string>()
            {
                ConnectionId = $"{contex.Channel.Id}",
                Cmd          = 0,
                Scope        = 0,
                Message      = msg
            };

            contex.WriteAndFlushAsync(reply.ToString());
            g.Add(contex.Channel);
        }
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = _group;

            if (g == null)
            {
                lock (this)
                {
                    if (_group == null)
                    {
                        g = _group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }
            g?.Add(contex.Channel);
            _poker.Player += 1;
            _poker.AddPlayer(_poker.Player, contex.Channel.RemoteAddress.ToString());
            //contex.WriteAndFlushAsync(g.Count);
            if (_poker.Player == 4)
            {
                contex.WriteAndFlushAsync("Welcome to the game!\n");
                _group.WriteAndFlushAsync("Welcome to the game\n", new EveryOneBut(contex.Channel.Id));
                _poker.IsGameStarted = true;
            }
            Console.WriteLine(_poker.Player);
        }
 public override void ChannelActive(IChannelHandlerContext context)
 {
     lock (_mutex)
     {
         _channels.Add(context.Channel);
         if (_channels.Count == 1)
         {
             _worker.Start();
         }
     }
     context.Channel.GetAttribute(ChannelAttributes.State).Set(new ChannelState());
     base.ChannelActive(context);
 }
Exemplo n.º 4
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            if (_group == null)
            {
                lock (this)
                {
                    if (_group == null)
                    {
                        _group = new DefaultChannelGroup(context.Executor);
                    }
                }
            }

            _group.Add(context.Channel);
        }
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = group;

            if (g == null)
            {
                lock (this)
                {
                    if (group == null)
                    {
                        g = group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }

            g.Add(contex.Channel);
        }
Exemplo n.º 6
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            if (group == null)
            {
                lock (this)
                {
                    if (group == null)
                    {
                        group = new DefaultChannelGroup(context.Executor);
                    }
                }
            }

            context.WriteAndFlushAsync("welcome\n");

            group.Add(context.Channel);
        }
Exemplo n.º 7
0
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = group;

            if (g == null)
            {
                lock (this)
                {
                    if (group == null)
                    {
                        g = group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }
            contex.WriteAndFlushAsync(string.Format("Welcome to {0} secure chat server!\n", Dns.GetHostName()));
            g.Add(contex.Channel);
        }
Exemplo n.º 8
0
        public Task <T> ConnectAsync <T>(
            INiftyClientConnector <T> clientChannelConnector,
            TimeSpan?connectTimeout,
            TimeSpan?receiveTimeout,
            TimeSpan?readTimeout,
            TimeSpan?sendTimeout,
            int maxFrameSize,
            ClientSslConfig sslConfig,
            EndPoint socksProxyAddress)
            where T : INiftyClientChannel
        {
            this.ThrowIfDisposed();
            Guard.ArgumentNotNull(clientChannelConnector, nameof(clientChannelConnector));

            Bootstrap bootstrap = new Bootstrap();

            bootstrap.Group(this.WorkerExecutor)
            .Channel <TcpSocketChannel>()
            .Option(ChannelOption.TcpNodelay, true);

            if (connectTimeout != null)
            {
                bootstrap.Option(ChannelOption.ConnectTimeout, connectTimeout.Value);
            }
            bootstrap.Handler(new ActionChannelInitializer <ISocketChannel>(channel =>
            {
                clientChannelConnector.ConfigureChannelPipeline(channel.Pipeline, maxFrameSize, this.NettyClientConfig, sslConfig);
            }));
            Task <IChannel> connectTask = clientChannelConnector.ConnectAsync(bootstrap);

            return(connectTask.ContinueWith(t =>
            {
                if (t.Exception == null && t.Result != null && t.Result.Open)
                {
                    _allChannel.Add(t.GetAwaiter().GetResult());
                }
                if (t.Exception != null)
                {
                    _logger.LogError(nameof(EventId), t.Exception, "Failed to establish client connection.");
                }
                return CreateNiftyClientChannel(clientChannelConnector, receiveTimeout, readTimeout, sendTimeout, t);
            }));
        }
Exemplo n.º 9
0
        public override void ChannelRegistered(IChannelHandlerContext context)
        {
            IChannelGroup g = _group;

            if (g == null)
            {
                lock (_channel)
                {
                    if (_group == null)
                    {
                        g = _group = new DefaultChannelGroup(context.Executor);
                    }
                }
            }

            _endPoint = _channel.RemoteAddress as IPEndPoint;
            Log.Info($"[{_endPoint?.Address.MapToIPv4()}][SOCKET_ACCEPT] Client has been accepted");
            g.Add(context.Channel);
        }
Exemplo n.º 10
0
        public override void ChannelRegistered(IChannelHandlerContext context)
        {
            IChannelGroup g = _group;

            if (g == null)
            {
                lock (_channel)
                {
                    if (_group == null)
                    {
                        g = _group = new DefaultChannelGroup(context.Executor);
                    }
                }
            }

            Logger.Log.Info(string.Format(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.CLIENT_CONNECTED)));

            g.Add(context.Channel);
        }
Exemplo n.º 11
0
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = group;

            if (g == null)
            {
                lock (syncObject)
                {
                    if (group == null)
                    {
                        g = group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }

            var hostname = Dns.GetHostName();

            contex.WriteAndFlushAsync($"Welcome to {hostname} secure chat server!\n");
            g.Add(contex.Channel);
        }
Exemplo n.º 12
0
        void ChannelRegistered(IChannelHandlerContext context)
        {
            IChannelGroup g = group;

            if (g == null)
            {
                lock (this)
                {
                    if (group == null)
                    {
                        g = group = new DefaultChannelGroup(context.Executor);
                    }
                }
            }
            var id = context.Channel.Id.AsLongText();

            channelHandlerContexts.TryAdd(id, context);
            group.Add(context.Channel);
            Log.Info("ChannelRegistered: " + id);
        }
Exemplo n.º 13
0
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = group;

            if (g == null)
            {
                lock (this)
                {
                    if (group == null)
                    {
                        g = group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }

            contex.WriteAndFlushAsync("Welcome to BLACKJACK !\r\n");

            g.Add(contex.Channel);
            _bj.AddPlayer(contex);
        }
Exemplo n.º 14
0
        //private static volatile IChannelGroup group;
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IAttribute <string>        der       = contex.GetAttribute(AttributeMapConstant.HttpAttriKey);
            IAttribute <IChannelGroup> parentAtt = contex.Channel.Parent.GetAttribute(AttributeMapConstant.SockerGroup);
            IChannelGroup g = parentAtt.Get();

            if (g == null)
            {
                lock (this)
                {
                    if (g == null)
                    {
                        var chennGroup = new DefaultChannelGroup(contex.Executor);
                        g = chennGroup;
                        parentAtt.SetIfAbsent(chennGroup);
                    }
                }
            }
            contex.WriteAndFlushAsync(string.Format("Welcome to {0} secure chat server!{1}", Dns.GetHostName(), delimiterStr));
            g.Add(contex.Channel);
        }
Exemplo n.º 15
0
        //客户端连接进来时
        public override void HandlerAdded(IChannelHandlerContext context)
        {
            RecordLogEvent?.Invoke($"客户端{context}上线.");
            //SimpleEventBus.GetDefaultEventBus().Post("客户端连接进来:" + context, TimeSpan.Zero);
            base.HandlerAdded(context);

            IChannelGroup g = groups;

            if (g == null)
            {
                lock (this)
                {
                    if (groups == null)
                    {
                        g = groups = new DefaultChannelGroup(context.Executor);
                    }
                }
            }

            g.Add(context.Channel);
            //groups.WriteAndFlushAsync($"欢迎{context.Channel.RemoteAddress}加入.");
        }
Exemplo n.º 16
0
        void IChannelManager.ChannleActive(IChannelHandlerContext context)
        {
            var     channel   = context.Channel;
            var     sessionId = channel.Id.AsLongText();
            Channel ch;

            lock (_channelLocker)
            {
                if (_channels.ContainsKey(sessionId) == false)
                {
                    ch = new Channel(channel);
                    _channels.Add(sessionId, ch);
                }
                else
                {
                    ch = _channels[sessionId];
                }
            }

            if (_isServer)
            {
                IChannelGroup g = _group;
                if (g == null)
                {
                    lock (_groupLocker)
                    {
                        if (_group == null)
                        {
                            _group = new DefaultChannelGroup(context.Executor);
                        }
                        g = _group;
                    }
                }
                g.Add(channel);
            }

            this.OnActive(ch);
        }
Exemplo n.º 17
0
        public override void ChannelRegistered(IChannelHandlerContext context)
        {
            var _group = LoginTcpHandler._group;

            if (_group == null)
            {
                lock (_channel)
                {
                    if (LoginTcpHandler._group == null)
                    {
                        _group = LoginTcpHandler._group = new DefaultChannelGroup(context.Executor);
                    }
                }
            }

            _endPoint = _channel.RemoteAddress as IPEndPoint;
            _group.Add(context.Channel);

            _packetSerializer = new MsgPackGameSerializer(_log, _packetFactory);
            _log = new SessionLogger(typeof(LoginTcpHandler), $"([{_endPoint?.Address}]:{_endPoint?.Port}) ");

            _log.Debug("Client has been accepted");
        }
Exemplo n.º 18
0
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = group;

            if (g == null)
            {
                lock (this)
                {
                    if (group == null)
                    {
                        g = group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }
            contex.WriteAndFlushAsync(string.Format("[SERVER] : Welcome to Uno Server !\n"));
            if (numberPlayer == 4)
            {
                contex.WriteAndFlushAsync("[SERVER] : Sorry, game already started.\n");
                contex.CloseAsync();
                return;
            }
            ClientUser tmp = new ClientUser(contex, numberPlayer + 1);

            listUser.Add(tmp);
            numberPlayer += 1;
            g.Add(contex.Channel);
            SendIdAndCard(contex);
            if (numberPlayer == 4)
            {
                SetPlayerStart();
            }
            else
            {
                group.WriteAndFlushAsync(string.Format("[SERVER] : Player {0} has join. {1} player left before game start !\n", numberPlayer, 4 - (numberPlayer)));
            }
        }
Exemplo n.º 19
0
 public override void ChannelActive(IChannelHandlerContext context)
 {
     _allChannels.Add(context.Channel);
 }
Exemplo n.º 20
0
 public override void ChannelActive(IChannelHandlerContext context) => _group.Add(context.Channel);