Пример #1
0
        public AuthServer()
        {
            _packetLogger = new PacketLogger();
            _logger       = new Logger()
            {
                WriteToConsole = true
            };
            _logger.Load(Path.Combine("logs", string.Format("auth_{0}.log", DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss"))));
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                Error(s, new ExceptionEventArgs((Exception)e.ExceptionObject));
                Environment.Exit(0);
            };

            _packetLogger.Load("auth_packets.log");
            _logger.Info("Loaded Packet Logger");

            Stopwatch sw = Stopwatch.StartNew();

            AuthConfig.Load();
            sw.Stop();
            _logger.Info("Loaded Auth Configuration in {0} ms", sw.Elapsed.TotalMilliseconds);

            _logger.Info("Starting up server connections...");

            _server = new TcpServer(IPAddress.Parse(AuthConfig.Instance.IP), AuthConfig.Instance.Port);
            _server.PacketReceived += HandlePacket;
            _server.Error          += Error;

            //
            // Initalize a list of ports
            //

            ushort[] ports = { 38915, 38917 };

            for (uint i = 0; ports.Length > i; i++)
            {
                // Handle NAT tests before starting...
                switch (i)
                {
                case 0:
                    _natServer = new UDPClient(ports[0]);
                    _natServer.PacketReceived += HandleNATTest;
                    _natServer.Error          += Error;
                    _logger.InfoAuth("NAT Test successful at Port {0}", ports[0]);
                    break;

                case 1:
                    _natServer2 = new UDPClient(ports[1]);
                    _natServer2.PacketReceived += HandleNATTest2;
                    _natServer2.Error          += Error;
                    _logger.InfoAuth("NAT Test successful at Port {0}", ports[1]);
                    break;

                default:
                    break;
                }
            }

            // Bind to pipe/tcp/http settings in configuration
            var isMono = Type.GetType("Mono.Runtime") != null;

            switch (AuthConfig.Instance.Remote.Binding)
            {
            case "pipe":
                if (isMono)
                {
                    _logger.Error("pipe is not supported in mono, use http!");
                    Environment.Exit(1);
                    return;
                }
                _remoteServer = new RemoteServer(this, ERemoteBinding.Pipe, string.Format("localhost/AuthServer/{0}/", SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                break;

            case "tcp":
                if (isMono)
                {
                    _logger.Error("tcp is not supported in mono, use http!");
                    Environment.Exit(1);
                    return;
                }
                _remoteServer = new RemoteServer(this, ERemoteBinding.Pipe, string.Format("{0}:{1}/AuthServer/{2}/", AuthConfig.Instance.Remote.Server, AuthConfig.Instance.Remote.Port, SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                break;

            case "http":
                _remoteServer = new RemoteServer(this, ERemoteBinding.Http, string.Format("{0}:{1}/AuthServer/{2}/", AuthConfig.Instance.Remote.Server, AuthConfig.Instance.Remote.Port, SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                break;

            default:
                _logger.Error("Invalid remote binding '{0}'", AuthConfig.Instance.Remote.Binding);
                Environment.Exit(1);
                return;
            }
            _remoteServer.AddServiceEndpoint(typeof(IAuthRemote), "IAuthRemote");
        }
Пример #2
0
        public AuthServer()
        {
            _packetLogger = new PacketLogger();
            _logger       = new Logger()
            {
                WriteToConsole = true
            };
            _logger.Load(Path.Combine("logs", string.Format("auth_{0}.log", DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss"))));
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                Error(s, new ExceptionEventArgs((Exception)e.ExceptionObject));
                Environment.Exit(0);
            };

            _packetLogger.Load("auth_packets.log");

            _logger.Info("Loading auth_config.xml...");
            AuthConfig.Load();

            _logger.Info("Setting up servers...");

            _server = new TcpServer(IPAddress.Parse(AuthConfig.Instance.IP), AuthConfig.Instance.Port);
            _server.PacketReceived += HandlePacket;
            _server.Error          += Error;

            _natServer = new UDPClient(38915);
            _natServer.PacketReceived += HandleNATTest;
            _natServer.Error          += Error;

            _natServer2 = new UDPClient(38917);
            _natServer2.PacketReceived += HandleNATTest2;
            _natServer2.Error          += Error;

            var isMono = Type.GetType("Mono.Runtime") != null;

            switch (AuthConfig.Instance.Remote.Binding)
            {
            case "pipe":
                if (isMono)
                {
                    _logger.Error("pipe is not supported in mono, use http!");
                    Environment.Exit(1);
                    return;
                }
                _remoteServer = new RemoteServer(this, ERemoteBinding.Pipe, string.Format("localhost/FagNetAuth/{0}/", SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                break;

            case "tcp":
                if (isMono)
                {
                    _logger.Error("tcp is not supported in mono, use http!");
                    Environment.Exit(1);
                    return;
                }
                _remoteServer = new RemoteServer(this, ERemoteBinding.Pipe, string.Format("{0}:{1}/FagNetAuth/{2}/", AuthConfig.Instance.Remote.Server, AuthConfig.Instance.Remote.Port, SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                break;

            case "http":
                _remoteServer = new RemoteServer(this, ERemoteBinding.Http, string.Format("{0}:{1}/FagNetAuth/{2}/", AuthConfig.Instance.Remote.Server, AuthConfig.Instance.Remote.Port, SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                break;

            default:
                _logger.Error("Invalid remote binding '{0}'", AuthConfig.Instance.Remote.Binding);
                Environment.Exit(1);
                return;
            }
            _remoteServer.AddServiceEndpoint(typeof(IAuthRemote), "IAuthRemote");
        }