Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string password;
            int    serverPort;
            int    servicePort;
            bool   usingIpV6;

            if (args.Length < 4)
            {
                WriteHelp();
                return;
            }

            password = args[0];

            if (!int.TryParse(args[1], out serverPort))
            {
                WriteHelp();
                return;
            }

            if (!int.TryParse(args[2], out servicePort))
            {
                WriteHelp();
                return;
            }

            if (!bool.TryParse(args[3], out usingIpV6))
            {
                WriteHelp();
                return;
            }

            var initializer = new ServerInitializer
            {
                AdminPassword   = password,
                PluginsPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins"),
                ExcludedPlugins = new string[0]
            };

            ServerModel.Init(initializer);
            ServerModel.Server.Start(serverPort, servicePort, usingIpV6);

            Console.WriteLine("Enter \"exit\" for server stop");

            while (true)
            {
                var command = Console.ReadLine();
                if (string.Equals(command, "exit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
            }

            ServerModel.Reset();
        }
Exemplo n.º 2
0
        static void Main(string[] argsRaw)
        {
            var args = new ArgsParser(argsRaw, WriteHelp);

            var serverAddresss      = args.Get(ServerAddressName);
            var p2pServicePort      = args.Get <int>(ServicePortName, int.TryParse);
            var certificatePath     = args.Get(CertificatePathName);
            var certificatePassword = args.GetOrDefault(CertificatePasswordName, null);
            var adminPassword       = args.Get(AdminPasswordName);

            if (!File.Exists(certificatePath))
            {
                Console.WriteLine("File not found: {0}", certificatePath);
                WriteHelp();
                return;
            }

            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                var error = e.ExceptionObject as Exception;
                if (error == null)
                {
                    return;
                }

                var logger = new Logger(AppDomain.CurrentDomain.BaseDirectory + "/UnhandledError.log");
                logger.Write(error);
            };

            var initializer = new ServerInitializer
            {
                AdminPassword   = adminPassword,
                PluginsPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins"),
                ExcludedPlugins = new string[0],
                Certificate     = new X509Certificate2(certificatePath, CreateSecureString(certificatePassword))
            };

            ServerModel.Init(initializer);
            var serverUri = Connection.CreateTcpchatUri(serverAddresss);

            ServerModel.Server.Start(serverUri, p2pServicePort);

            Console.WriteLine("Enter \"exit\" for server stop");

            while (true)
            {
                var command = Console.ReadLine();
                if (string.Equals(command, "exit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
            }

            ServerModel.Reset();
        }
Exemplo n.º 3
0
        private void EnableServer(object obj)
        {
            var dialog = new ServerDialog();

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            try
            {
                var excludedPlugins = Settings.Current.Plugins
                                      .Where(s => !s.Enabled)
                                      .Select(s => s.Name)
                                      .ToArray();

                var initializer = new ServerInitializer
                {
                    AdminPassword   = Settings.Current.AdminPassword,
                    PluginsPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins"),
                    ExcludedPlugins = excludedPlugins
                };

                ServerModel.Init(initializer);
                ServerModel.Server.Start(Settings.Current.Port, Settings.Current.ServicePort, Settings.Current.StateOfIPv6Protocol);

                InitializeClient(true);
            }
            catch (ArgumentException)
            {
                SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(ParamsErrorKey));

                if (ClientModel.IsInited)
                {
                    ClientModel.Reset();
                }

                if (ServerModel.IsInited)
                {
                    ServerModel.Reset();
                }
            }
        }
Exemplo n.º 4
0
        private void EnableServer(object obj)
        {
            var dialog = new ServerDialog();

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    var adminPassword   = Settings.Current.AdminPassword;
                    var p2pPort         = Settings.Current.ServerStartP2PPort;
                    var excludedPlugins = Settings.Current.Plugins
                                          .Where(s => !s.Enabled)
                                          .Select(s => s.Name)
                                          .ToArray();

                    var initializer = new ServerInitializer
                    {
                        AdminPassword   = adminPassword,
                        PluginsPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginsDirectoryName),
                        ExcludedPlugins = excludedPlugins,
                        Certificate     = new X509Certificate2(dialog.CertificatePath, dialog.CertificatePassword),
                    };

                    ServerModel.Init(initializer);

                    var serverStartUri = Connection.CreateTcpchatUri(dialog.ServerAddress);
                    ServerModel.Server.Start(serverStartUri, p2pPort);

                    dialog.SaveSettings();
                }
                catch (Exception e)
                {
                    var errorMessage = Localizer.Instance.Localize(ParamsErrorKey);
                    SelectedRoom.AddSystemMessage($"{errorMessage}\r\n{e.Message}");

                    if (ServerModel.IsInited)
                    {
                        ServerModel.Reset();
                    }
                }
            }
        }