Exemplo n.º 1
0
        protected IClientBuilder AddDefaultSettings(IClientBuilder builder, NetConnectionParameters parameters)
        {
            var config = (IConfiguration)Services.GetService(typeof(IConfiguration));

            var tcpPort      = (parameters.TcpPort > 0) ? parameters.TcpPort : config.GetValue <int>("Network:TcpPort");
            var udpPort      = (parameters.UdpPort > 0) ? parameters.UdpPort : config.GetValue <int>("Network:UdpPort");
            var udpLocalPort = (parameters.UdpLocalPort > 0) ? parameters.UdpLocalPort : config.GetValue <int>("Network:UdpLocalPort");

            return(builder
                   .UseIp(parameters.Address)
                   .UseTcp(tcpPort)
                   .UseUdp(udpPort, udpLocalPort)
                   .UseZeroFormatter()
                   .UseConfiguration(config)
                   .ConfigureLogging(logBuilder =>
            {
                logBuilder.AddConfiguration(config.GetSection("Logging"));
                logBuilder.AddConsole();
            })
                   .RegisterTypes(serviceCollection =>
            {
                serviceCollection.AddSingleton(c => this);
                serviceCollection.AddSingleton(c => this.Chat);
                this.RegisterTypes(serviceCollection);
            })
                   .RegisterPacketHandler <User.Packets.LoginReplyPacket, User.LoginClientHandler>()
                   .RegisterPacketHandler <Chat.Packets.ChatReplyPacket, ChatReceiverHandler <TUser> >());
        }