Esempio n. 1
0
        public void Start()
        {
            string configFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ConfigFile);

            if (!File.Exists(configFile))
            {
                Config = new SharpStarConfig();

                Config.ConfigFile.ListenPort     = DefaultListenPort;
                Config.ConfigFile.ServerPort     = DefaultServerPort;
                Config.ConfigFile.EnableAccounts = true;

                Config.ConfigFile.AllowedStarboundCommands.Add("pvp");
                Config.ConfigFile.AllowedStarboundCommands.Add("w");

                Config.Save(configFile);
            }
            else
            {
                Config = SharpStarConfig.Load(configFile);
            }

            if (string.IsNullOrEmpty(Config.ConfigFile.PythonLibLocation))
            {
                string pythonLoc = Python.GetPythonInstallDir();

                if (!string.IsNullOrEmpty(pythonLoc))
                {
                    Config.ConfigFile.PythonLibLocation = Path.Combine(pythonLoc, "Lib");
                }

                Config.Save(configFile);
            }

            Database = new SharpStarDb(DatabaseName);

            if (File.Exists("SharpStar.db"))
            {
                SharpStarLogger.DefaultLogger.Info("Migrating SharpStar database...");

                SqlNetToNHibernate.Migrate("SharpStar.db", DatabaseName);

                SharpStarLogger.DefaultLogger.Info("Migration complete!");

                File.Move("SharpStar.db", "SharpStar-" + Guid.NewGuid() + ".db.old");
            }

            SharpStarLogger.DefaultLogger.Info("Listening on port {0}", Config.ConfigFile.ListenPort);

            Server = new SharpStarServer(Config.ConfigFile.ServerPort, 100);

            IPEndPoint ipe;

            if (Config.ConfigFile.SharpStarBind == "*" || string.IsNullOrEmpty(Config.ConfigFile.SharpStarBind))
            {
                ipe = new IPEndPoint(IPAddress.Any, Config.ConfigFile.ListenPort);
            }
            else
            {
                SharpStarLogger.DefaultLogger.Info("SharpStar is bound to {0}", Config.ConfigFile.SharpStarBind);

                ipe = new IPEndPoint(IPAddress.Parse(Config.ConfigFile.SharpStarBind), Config.ConfigFile.ListenPort);
            }

            PluginManager = new PluginManager();
            PluginManager.LoadPlugins();

            Server.Start(ipe);

            UDPServer = new StarboundUDPServer();
            UDPServer.Start();

            if (Config.ConfigFile.AutoUpdatePlugins)
            {
                addinUpdateChecker          = new Timer();
                addinUpdateChecker.Interval = TimeSpan.FromDays(1).TotalMilliseconds;
                addinUpdateChecker.Elapsed += (s, e) => PluginManager.CSPluginManager.UpdatePlugins();
                addinUpdateChecker.Start();
            }
        }