Example #1
0
        /// <summary>
        /// Reads a configuration file from a given path, creates it if it doesn't exist.
        /// </summary>
        /// <param name="path">string path</param>
        /// <returns>Config object</returns>
        public static Config Read(string path)
        {
            Config cf;

            if (!File.Exists(path))
            {
                cf = new Config();
                cf.Write(ConfigPath);
                return cf;
            }

            cf = JsonConvert.DeserializeObject<Config>(File.ReadAllText(path));
            return cf;
        }
Example #2
0
        public override void Initialize()
        {
            Config = Config.Read();

            ServerApi.Hooks.WorldSave.Register(this, OnWorldSave);
            ServerApi.Hooks.NpcStrike.Register(this, OnDamage);
            ServerApi.Hooks.ServerJoin.Register(this, OnJoin);

            Commands.InitCommands();

            if (TShock.Config.StorageType.ToLower() == "sqlite")
            {
                string sql = Path.Combine(TShock.SavePath, "vocations.sqlite");
                DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
            }
            else
            {
                try
                {
                    var hostport = TShock.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",
                            TShock.Config.MySqlDbName,
                            TShock.Config.MySqlUsername,
                            TShock.Config.MySqlPassword
                        );
                }
                catch (MySqlException ex)
                {
                    ServerApi.LogWriter.PluginWriteLine(this, ex.ToString(), System.Diagnostics.TraceLevel.Error);
                    throw new Exception("MySql not setup correctly");
                }
            }
            Vocations = new VocationManager(DB);
        }