상속: IDisposable
 public static void ReOpen()
 {
     if (instance != null)
     {
         instance.Dispose();
         instance = null;
     }
     _flagImageList.Images.Clear();
     disabled = false;
 }
        static void Main(string[] args)
        {
            #if DEBUG
            config.logLevel = LogType.Debug;
            #endif
            startTime = Utils.getTimestamp();
            changeState(ServerState.Starting, "StarryboundServer::Main");
            Console.Title = "Loading... Starrybound Server (" + VersionNum + ") (" + ProtocolVersion + ")";

            try
            {
                int processId = Convert.ToInt32(File.ReadAllText("starbound_server.pid"));
                Process proc = Process.GetProcessById(processId);
                proc.Kill();
                File.Delete("starbound_server.pid");
            }
            catch (Exception) { }

            monitorThread = new Thread(new ThreadStart(crashMonitor));
            monitorThread.Start();

            if (IsMono)
                Environment.CurrentDirectory = Path.GetDirectoryName(typeof(StarryboundServer).Assembly.Location);

            AppDomain.CurrentDomain.ProcessExit += new EventHandler(ProcessExit);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException);

            if (!IsMono)
                NativeMethods.SetConsoleCtrlHandler(new NativeMethods.HandlerRoutine(ConsoleCtrlCheck), true);

            BootstrapConfig.SetupConfig();

            writeLog("", LogType.FileOnly);
            writeLog("-- Log Start: " + DateTime.Now + " --", LogType.FileOnly);

            logInfo("##############################################");
            logInfo("####   Avilance Ltd. Starrybound Server   ####");
            logInfo("####   Copyright (c) Avilance Ltd. 2013   ####");
            logInfo("####       Licensed under the GPLv3       ####");
            logInfo("##############################################");
            logInfo("Version: " + VersionNum + " (" + ProtocolVersion + ")");
            logInfo("Loading Starrybound Server...");

            Config.SetupConfig();
            ServerConfig.SetupConfig();
            Groups.SetupGroups();
            Users.SetupUsers();
            #if !DEBUG
            if (config.logLevel == LogType.Debug)
            {
                logWarn("The logLevel in your config is currently set to DEBUG. This **WILL** flood your console and log file, if you do not want this please edit your config logLevel to INFO");
                logWarn("Launch will proceed in 5 seconds.");
                System.Threading.Thread.Sleep(5000);
            }
            #endif
            #if !NOSERVER
            if(config.proxyPort == config.serverPort)
            {
                logFatal("You cannot have the serverPort and proxyPort on the same port!");
                Thread.Sleep(5000);
                Environment.Exit(3);
            }
            #endif
            var geoippath = Path.Combine(SavePath, "GeoIP.dat");
            if (config.enableGeoIP && File.Exists(geoippath))
                Geo = new GeoIPCountry(geoippath);

            foreach(string sector in config.sectors)
            {
                byte[] sectorBytes = Encoding.UTF8.GetBytes(sector);
                byte[] buffer = new byte[sectorBytes.Length + 1];
                buffer[0] = (byte)sectorBytes.Length;
                Buffer.BlockCopy(sectorBytes, 0, buffer, 1, sectorBytes.Length);
                sectors.Add(sectorBytes);
            }
            Bans.ProcessBans();

            logInfo("Starrybound Server initialization complete.");

            listener = new ListenerThread();
            listenerThread = new Thread(new ThreadStart(listener.runTcp));
            listenerThread.Start();

            udpThread = new Thread(new ThreadStart(listener.runUdp));
            udpThread.Start();

            while (serverState != ServerState.ListenerReady) { }
            if ((int)serverState > 3) return;

            Console.Title = "Starting... Starrybound Server (" + VersionNum + ") (" + ProtocolVersion + ")";
            #if !NOSERVER
            logInfo("Starting parent Starbound server - This may take a few moments...");
            sbServer = new ServerThread();
            sbServerThread = new Thread(new ThreadStart(sbServer.run));
            sbServerThread.Start();
            while (serverState != ServerState.StarboundReady) { }
            if ((int)serverState > 3) return;
            #endif
            logInfo("Parent Starbound server is ready. Starrybound Server now accepting connections.");
            changeState(ServerState.Running, "StarryboundServer::Main");
        }
예제 #3
0
파일: TShock.cs 프로젝트: InanZen/TShock
        public override void Initialize()
        {
            HandleCommandLine(Environment.GetCommandLineArgs());

            if (!Directory.Exists(SavePath))
                Directory.CreateDirectory(SavePath);

            DateTime now = DateTime.Now;
            string logFilename;
            try
            {
                logFilename = Path.Combine(SavePath, now.ToString(LogFormat)+".log");
            }
            catch(Exception)
            {
                // Problem with the log format use the default
                logFilename = Path.Combine(SavePath, now.ToString(LogFormatDefault) + ".log");
            }
            #if DEBUG
            Log.Initialize(logFilename, LogLevel.All, false);
            #else
            Log.Initialize(logFilename, LogLevel.All & ~LogLevel.Debug, LogClear);
            #endif
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            try
            {
                if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
                {
                    Log.ConsoleInfo(
                        "TShock was improperly shut down. Please use the exit command in the future to prevent this.");
                    File.Delete(Path.Combine(SavePath, "tshock.pid"));
                }
                File.WriteAllText(Path.Combine(SavePath, "tshock.pid"), Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture));

                ConfigFile.ConfigRead += OnConfigRead;
                FileTools.SetupConfig();

                HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs());

                if (Config.StorageType.ToLower() == "sqlite")
                {
                    string sql = Path.Combine(SavePath, "tshock.sqlite");
                    DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
                }
                else if (Config.StorageType.ToLower() == "mysql")
                {
                    try
                    {
                        var hostport = Config.MySqlHost.Split(':');
                        DB = new MySqlConnection();
                        DB.ConnectionString =
                            String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
                                          hostport[0],
                                          hostport.Length > 1 ? hostport[1] : "3306",
                                          Config.MySqlDbName,
                                          Config.MySqlUsername,
                                          Config.MySqlPassword
                                );
                    }
                    catch (MySqlException ex)
                    {
                        Log.Error(ex.ToString());
                        throw new Exception("MySql not setup correctly");
                    }
                }
                else
                {
                    throw new Exception("Invalid storage type");
                }

                Backups = new BackupManager(Path.Combine(SavePath, "backups"));
                Backups.KeepFor = Config.BackupKeepFor;
                Backups.Interval = Config.BackupInterval;
                Bans = new BanManager(DB);
                Warps = new WarpManager(DB);
                Users = new UserManager(DB);
                Groups = new GroupManager(DB);
                Regions = new RegionManager(DB);
                Itembans = new ItemManager(DB);
                RememberedPos = new RemeberedPosManager(DB);
                InventoryDB = new InventoryManager(DB);
                RestApi = new SecureRest(Netplay.serverListenIP, Config.RestApiPort);
                RestApi.Verify += RestApi_Verify;
                RestApi.Port = Config.RestApiPort;
                RestManager = new RestManager(RestApi);
                RestManager.RegisterRestfulCommands();

                var geoippath = Path.Combine(SavePath, "GeoIP.dat");
                if (Config.EnableGeoIP && File.Exists(geoippath))
                    Geo = new GeoIPCountry(geoippath);

                Log.ConsoleInfo(string.Format("TerrariaShock Version {0} ({1}) now running.", Version, VersionCodename));

                GameHooks.PostInitialize += OnPostInit;
                GameHooks.Update += OnUpdate;
                ServerHooks.Connect += OnConnect;
                ServerHooks.Join += OnJoin;
                ServerHooks.Leave += OnLeave;
                ServerHooks.Chat += OnChat;
                ServerHooks.Command += ServerHooks_OnCommand;
                NetHooks.GetData += OnGetData;
                NetHooks.SendData += NetHooks_SendData;
                NetHooks.GreetPlayer += OnGreetPlayer;
                NpcHooks.StrikeNpc += NpcHooks_OnStrikeNpc;
                NpcHooks.SetDefaultsInt += OnNpcSetDefaults;
                ProjectileHooks.SetDefaults += OnProjectileSetDefaults;
                WorldHooks.StartHardMode += OnStartHardMode;
                WorldHooks.SaveWorld += SaveManager.Instance.OnSaveWorld;

                GetDataHandlers.InitGetDataHandler();
                Commands.InitCommands();
                //RconHandler.StartThread();

                if (Config.RestApiEnabled)
                    RestApi.Start();

                if (Config.BufferPackets)
                    PacketBuffer = new PacketBufferer();

                Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
                Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled"));

                if (Initialized != null)
                    Initialized();
            }
            catch (Exception ex)
            {
                Log.Error("Fatal Startup Exception");
                Log.Error(ex.ToString());
                Environment.Exit(1);
            }
        }
예제 #4
0
파일: TShock.cs 프로젝트: B-BOB/TShock
        public override void Initialize()
        {
            string logFilename;
            string logPathSetupWarning;

            try
            {
                HandleCommandLine(Environment.GetCommandLineArgs());

                if (!Directory.Exists(SavePath))
                    Directory.CreateDirectory(SavePath);

                ConfigFile.ConfigRead += OnConfigRead;
                FileTools.SetupConfig();

                Main.ServerSideCharacter = ServerSideCharacterConfig.Enabled;

                DateTime now = DateTime.Now;
                // Log path was not already set by the command line parameter?
                if (LogPath == LogPathDefault)
                    LogPath = Config.LogPath;
                try
                {
                    logFilename = Path.Combine(LogPath, now.ToString(LogFormat) + ".log");
                    if (!Directory.Exists(LogPath))
                        Directory.CreateDirectory(LogPath);
                }
                catch (Exception ex)
                {
                    logPathSetupWarning =
                        "Could not apply the given log path / log format, defaults will be used. Exception details:\n" + ex;

                    ServerApi.LogWriter.PluginWriteLine(this, logPathSetupWarning, TraceLevel.Error);

                    // Problem with the log path or format use the default
                    logFilename = Path.Combine(LogPathDefault, now.ToString(LogFormatDefault) + ".log");
                }

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            }
            catch (Exception ex)
            {
                // Will be handled by the server api and written to its crashlog.txt.
                throw new Exception("Fatal TShock initialization exception. See inner exception for details.", ex);
            }

            // Further exceptions are written to TShock's log from now on.
            try
            {
                if (Config.StorageType.ToLower() == "sqlite")
                {
                    string sql = Path.Combine(SavePath, "tshock.sqlite");
                    DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
                }
                else if (Config.StorageType.ToLower() == "mysql")
                {
                    try
                    {
                        var hostport = Config.MySqlHost.Split(':');
                        DB = new MySqlConnection();
                        DB.ConnectionString =
                            String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
                                hostport[0],
                                hostport.Length > 1 ? hostport[1] : "3306",
                                Config.MySqlDbName,
                                Config.MySqlUsername,
                                Config.MySqlPassword
                                );
                    }
                    catch (MySqlException ex)
                    {
                        ServerApi.LogWriter.PluginWriteLine(this, ex.ToString(), TraceLevel.Error);
                        throw new Exception("MySql not setup correctly");
                    }
                }
                else
                {
                    throw new Exception("Invalid storage type");
                }

                if (Config.UseSqlLogs)
                    Log = new SqlLog(DB, logFilename, LogClear);
                else
                    Log = new TextLog(logFilename, LogClear);

                if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
                {
                    Log.ConsoleInfo(
                        "TShock was improperly shut down. Please use the exit command in the future to prevent this.");
                    File.Delete(Path.Combine(SavePath, "tshock.pid"));
                }
                File.WriteAllText(Path.Combine(SavePath, "tshock.pid"),
                    Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture));

                HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs());

                Backups = new BackupManager(Path.Combine(SavePath, "backups"));
                Backups.KeepFor = Config.BackupKeepFor;
                Backups.Interval = Config.BackupInterval;
                Bans = new BanManager(DB);
                Warps = new WarpManager(DB);
                Regions = new RegionManager(DB);
                Users = new UserManager(DB);
                Groups = new GroupManager(DB);
                Itembans = new ItemManager(DB);
                ProjectileBans = new ProjectileManagager(DB);
                TileBans = new TileManager(DB);
                RememberedPos = new RememberedPosManager(DB);
                CharacterDB = new CharacterManager(DB);
                RestApi = new SecureRest(Netplay.ServerIP, Config.RestApiPort);
                RestManager = new RestManager(RestApi);
                RestManager.RegisterRestfulCommands();

                var geoippath = Path.Combine(SavePath, "GeoIP.dat");
                if (Config.EnableGeoIP && File.Exists(geoippath))
                    Geo = new GeoIPCountry(geoippath);

                Log.ConsoleInfo("TShock {0} ({1}) now running.", Version, VersionCodename);

                ServerApi.Hooks.GamePostInitialize.Register(this, OnPostInit);
                ServerApi.Hooks.GameUpdate.Register(this, OnUpdate);
                ServerApi.Hooks.GameHardmodeTileUpdate.Register(this, OnHardUpdate);
                ServerApi.Hooks.GameStatueSpawn.Register(this, OnStatueSpawn);
                ServerApi.Hooks.ServerConnect.Register(this, OnConnect);
                ServerApi.Hooks.ServerJoin.Register(this, OnJoin);
                ServerApi.Hooks.ServerLeave.Register(this, OnLeave);
                ServerApi.Hooks.ServerChat.Register(this, OnChat);
                ServerApi.Hooks.ServerCommand.Register(this, ServerHooks_OnCommand);
                ServerApi.Hooks.NetGetData.Register(this, OnGetData);
                ServerApi.Hooks.NetSendData.Register(this, NetHooks_SendData);
                ServerApi.Hooks.NetGreetPlayer.Register(this, OnGreetPlayer);
                ServerApi.Hooks.NpcStrike.Register(this, NpcHooks_OnStrikeNpc);
                ServerApi.Hooks.ProjectileSetDefaults.Register(this, OnProjectileSetDefaults);
                ServerApi.Hooks.WorldStartHardMode.Register(this, OnStartHardMode);
                ServerApi.Hooks.WorldSave.Register(this, SaveManager.Instance.OnSaveWorld);
                ServerApi.Hooks.WorldChristmasCheck.Register(this, OnXmasCheck);
                ServerApi.Hooks.WorldHalloweenCheck.Register(this, OnHalloweenCheck);
                ServerApi.Hooks.NetNameCollision.Register(this, NetHooks_NameCollision);
                Hooks.PlayerHooks.PlayerPreLogin += OnPlayerPreLogin;
                Hooks.PlayerHooks.PlayerPostLogin += OnPlayerLogin;
                Hooks.AccountHooks.AccountDelete += OnAccountDelete;
                Hooks.AccountHooks.AccountCreate += OnAccountCreate;

                GetDataHandlers.InitGetDataHandler();
                Commands.InitCommands();

                if (Config.RestApiEnabled)
                    RestApi.Start();

                if (Config.BufferPackets)
                    PacketBuffer = new PacketBufferer(this);

                Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
                Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled"));

                if (Initialized != null)
                    Initialized();

                Log.ConsoleInfo("Welcome to TShock for Terraria. Initialization complete.");
            }
            catch (Exception ex)
            {
                Log.Error("Fatal Startup Exception");
                Log.Error(ex.ToString());
                Environment.Exit(1);
            }
        }
예제 #5
0
        public override void Initialize()
        {
            HandleCommandLine(Environment.GetCommandLineArgs());

            if (!Directory.Exists(SavePath))
                Directory.CreateDirectory(SavePath);

            #if DEBUG
            Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All, false);
            #else
            Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All & ~LogLevel.Debug, false);
            #endif
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            try
            {
                if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
                {
                    Log.ConsoleInfo(
                        "TShock was improperly shut down. Please avoid this in the future, world corruption may result from this.");
                    File.Delete(Path.Combine(SavePath, "tshock.pid"));
                }
                File.WriteAllText(Path.Combine(SavePath, "tshock.pid"), Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture));

                ConfigFile.ConfigRead += OnConfigRead;
                FileTools.SetupConfig();

                HandleCommandLine_Port(Environment.GetCommandLineArgs());

                if (Config.StorageType.ToLower() == "sqlite")
                {
                    string sql = Path.Combine(SavePath, "tshock.sqlite");
                    DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
                }
                else if (Config.StorageType.ToLower() == "mysql")
                {
                    try
                    {
                        var hostport = Config.MySqlHost.Split(':');
                        DB = new MySqlConnection();
                        DB.ConnectionString =
                            String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
                                          hostport[0],
                                          hostport.Length > 1 ? hostport[1] : "3306",
                                          Config.MySqlDbName,
                                          Config.MySqlUsername,
                                          Config.MySqlPassword
                                );
                    }
                    catch (MySqlException ex)
                    {
                        Log.Error(ex.ToString());
                        throw new Exception("MySql not setup correctly");
                    }
                }
                else
                {
                    throw new Exception("Invalid storage type");
                }

                Backups = new BackupManager(Path.Combine(SavePath, "backups"));
                Backups.KeepFor = Config.BackupKeepFor;
                Backups.Interval = Config.BackupInterval;
                Bans = new BanManager(DB);
                Warps = new WarpManager(DB);
                Users = new UserManager(DB);
                Groups = new GroupManager(DB);
                Groups.LoadPermisions();
                Regions = new RegionManager(DB);
                Itembans = new ItemManager(DB);
                RememberedPos = new RemeberedPosManager(DB);
                Inventory = new InventoryManager(DB);
                HomeManager = new HomeManager(DB);
                ArmorShopManager = new ArmorShopManager(DB);
                WeaponShopManager = new WeaponShopManager(DB);
                ItemShopManager = new ItemShopManager(DB);
                BlockShopManager = new BlockShopManager(DB);
                OtherShopManager = new OtherShopManager(DB);
                Towns = new TownManager(DB);
                Chat = new ChatManager(DB);
                Restart = new RestartManager();
                RestApi = new SecureRest(Netplay.serverListenIP, 8080);
                RestApi.Verify += RestApi_Verify;
                RestApi.Port = Config.RestApiPort;
                RestManager = new RestManager(RestApi);
                RestManager.RegisterRestfulCommands();

                var geoippath = Path.Combine(SavePath, "GeoIP.dat");
                if (Config.EnableGeoIP && File.Exists(geoippath))
                    Geo = new GeoIPCountry(geoippath);

                    profiles = @"Z:\profiles\";
                    temp = @"Z:\profiles\temp\";

                Console.Title = string.Format("TerrariaShock Version {0} ({1})", Version, VersionCodename);
                Log.ConsoleInfo(string.Format("TerrariaShock Version {0} ({1}) now running.", Version, VersionCodename));

                GameHooks.PostInitialize += OnPostInit;
                GameHooks.Update += OnUpdate;
                ServerHooks.Connect += OnConnect;
                ServerHooks.Join += OnJoin;
                ServerHooks.Leave += OnLeave;
                ServerHooks.Chat += OnChat;
                ServerHooks.Command += ServerHooks_OnCommand;
                NetHooks.GetData += OnGetData;
                NetHooks.SendData += NetHooks_SendData;
                NetHooks.GreetPlayer += OnGreetPlayer;
                NpcHooks.StrikeNpc += NpcHooks_OnStrikeNpc;
                NpcHooks.SetDefaultsInt += OnNpcSetDefaults;
                ProjectileHooks.SetDefaults += OnProjectileSetDefaults;
                WorldHooks.StartHardMode += OnStartHardMode;
                WorldHooks.SaveWorld += OnSaveWorld;

                GetDataHandlers.InitGetDataHandler();
                Commands.InitCommands();

                if (Config.BufferPackets)
                    PacketBuffer = new PacketBufferer();

                Users.DeletePlayersAfterMinutes(TShock.Config.DeleteUserAfterMinutes, 30, false);
                Users.DeletePlayersAfterMinutes(TShock.Config.DeleteUserAfterMinutes * 2, 100, false);
                Users.DeletePlayersAfterMinutes(TShock.Config.DeleteUserAfterMinutes * 3, 10000, true);

                Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
                Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled"));

                if (Initialized != null)
                    Initialized();
            }
            catch (Exception ex)
            {
                Log.Error("Fatal Startup Exception");
                Log.Error(ex.ToString());
                TShock.Backups.Backup();
                Environment.Exit(1);
            }
        }
예제 #6
0
파일: TShock.cs 프로젝트: k0rd/TShock
        public override void Initialize()
        {
            try
            {
                HandleCommandLine(Environment.GetCommandLineArgs());

                if (Version.Major >= 4)
                    getTShockAscii();

                if (!Directory.Exists(SavePath))
                    Directory.CreateDirectory(SavePath);

                ConfigFile.ConfigRead += OnConfigRead;
                FileTools.SetupConfig();

                DateTime now = DateTime.Now;
                string logFilename;
                string logPathSetupWarning = null;
                // Log path was not already set by the command line parameter?
                if (LogPath == LogPathDefault)
                    LogPath = Config.LogPath;
                try
                {
                    logFilename = Path.Combine(LogPath, now.ToString(LogFormat)+".log");
                    if (!Directory.Exists(LogPath))
                        Directory.CreateDirectory(LogPath);
                }
                catch(Exception ex)
                {
                    logPathSetupWarning = "Could not apply the given log path / log format, defaults will be used. Exception details:\n" + ex;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(logPathSetupWarning);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    // Problem with the log path or format use the default
                    logFilename = Path.Combine(LogPathDefault, now.ToString(LogFormatDefault) + ".log");
                }
            #if DEBUG
                Log.Initialize(logFilename, LogLevel.All, false);
            #else
                Log.Initialize(logFilename, LogLevel.All & ~LogLevel.Debug, LogClear);
            #endif
                if (logPathSetupWarning != null)
                    Log.Warn(logPathSetupWarning);

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            }
            catch(Exception ex)
            {
                // Will be handled by the server api and written to its crashlog.txt.
                throw new Exception("Fatal TShock initialization exception. See inner exception for details.", ex);
            }

            // Further exceptions are written to TShock's log from now on.
            try
            {
                if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
                {
                    Log.ConsoleInfo(
                        "TShock was improperly shut down. Please use the exit command in the future to prevent this.");
                    File.Delete(Path.Combine(SavePath, "tshock.pid"));
                }
                File.WriteAllText(Path.Combine(SavePath, "tshock.pid"), Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture));

                HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs());

                if (Config.StorageType.ToLower() == "sqlite")
                {
                    string sql = Path.Combine(SavePath, "tshock.sqlite");
                    DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
                }
                else if (Config.StorageType.ToLower() == "mysql")
                {
                    try
                    {
                        var hostport = Config.MySqlHost.Split(':');
                        DB = new MySqlConnection();
                        DB.ConnectionString =
                            String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
                                          hostport[0],
                                          hostport.Length > 1 ? hostport[1] : "3306",
                                          Config.MySqlDbName,
                                          Config.MySqlUsername,
                                          Config.MySqlPassword
                                );
                    }
                    catch (MySqlException ex)
                    {
                        Log.Error(ex.ToString());
                        throw new Exception("MySql not setup correctly");
                    }
                }
                else
                {
                    throw new Exception("Invalid storage type");
                }

                Backups = new BackupManager(Path.Combine(SavePath, "backups"));
                Backups.KeepFor = Config.BackupKeepFor;
                Backups.Interval = Config.BackupInterval;
                Bans = new BanManager(DB);
                Warps = new WarpManager(DB);
                Regions = new RegionManager(DB);
                Users = new UserManager(DB);
                Groups = new GroupManager(DB);
                Itembans = new ItemManager(DB);
                RememberedPos = new RememberedPosManager(DB);
                InventoryDB = new InventoryManager(DB);
                RestApi = new SecureRest(Netplay.serverListenIP, Config.RestApiPort);
                RestApi.Port = Config.RestApiPort;
                RestManager = new RestManager(RestApi);
                RestManager.RegisterRestfulCommands();

                var geoippath = Path.Combine(SavePath, "GeoIP.dat");
                if (Config.EnableGeoIP && File.Exists(geoippath))
                    Geo = new GeoIPCountry(geoippath);

                Log.ConsoleInfo(string.Format("|> Version {0} ({1}) now running.", Version, VersionCodename));

                GameHooks.PostInitialize += OnPostInit;
                GameHooks.Update += OnUpdate;
                GameHooks.HardUpdate += OnHardUpdate;
                GameHooks.StatueSpawn += OnStatueSpawn;
                ServerHooks.Connect += OnConnect;
                ServerHooks.Join += OnJoin;
                ServerHooks.Leave += OnLeave;
                ServerHooks.Chat += OnChat;
                ServerHooks.Command += ServerHooks_OnCommand;
                NetHooks.GetData += OnGetData;
                NetHooks.SendData += NetHooks_SendData;
                NetHooks.GreetPlayer += OnGreetPlayer;
                NpcHooks.StrikeNpc += NpcHooks_OnStrikeNpc;
                NpcHooks.SetDefaultsInt += OnNpcSetDefaults;
                ProjectileHooks.SetDefaults += OnProjectileSetDefaults;
                WorldHooks.StartHardMode += OnStartHardMode;
                WorldHooks.SaveWorld += SaveManager.Instance.OnSaveWorld;
                WorldHooks.ChristmasCheck += OnXmasCheck;
                NetHooks.NameCollision += NetHooks_NameCollision;
                TShockAPI.Hooks.PlayerHooks.PlayerPostLogin += OnPlayerLogin;

                GetDataHandlers.InitGetDataHandler();
                Commands.InitCommands();
                //RconHandler.StartThread();

                if (Config.RestApiEnabled)
                    RestApi.Start();

                if (Config.BufferPackets)
                    PacketBuffer = new PacketBufferer();

                Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
                Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled"));

                if (Initialized != null)
                    Initialized();
            }
            catch (Exception ex)
            {
                Log.Error("Fatal Startup Exception");
                Log.Error(ex.ToString());
                Environment.Exit(1);
            }
        }
 public static void ReOpen()
 {
     if (instance != null)
     {
         instance.Dispose();
         instance = null;
     }
     _flagImageList.Images.Clear();
     disabled = false;
 }