private void shopreload(CommandArgs args) { try { ShopList = new ShopData(this); SetupConfig(); } catch (Exception e) { TShock.Log.ConsoleError(e.ToString()); } }
private void OnInitialize(EventArgs args) { switch (TShock.Config.StorageType.ToLower()) { case "mysql": string[] host = TShock.Config.MySqlHost.Split(':'); Database = new MySqlConnection() { ConnectionString = string.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};", host[0], host.Length == 1 ? "3306" : host[1], TShock.Config.MySqlDbName, TShock.Config.MySqlUsername, TShock.Config.MySqlPassword) }; break; case "sqlite": // Create folder if it does not exist. (SQLITE Specific.) if (!System.IO.Directory.Exists(SavePath)) { System.IO.Directory.CreateDirectory(SavePath); } string sql = Path.Combine(SavePath, "store.sqlite"); Database = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql)); break; } SqlTableCreator sqlcreator = new SqlTableCreator(Database, Database.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator()); sqlcreator.EnsureTableStructure(new SqlTable("storeshop", new SqlColumn("name", MySqlDbType.VarChar) { Primary = true, Length = 30 }, new SqlColumn("price", MySqlDbType.Int32) { DefaultValue = "1", NotNull = true }, new SqlColumn("region", MySqlDbType.VarChar) { DefaultValue = "", Length = 30, NotNull = true }, new SqlColumn("groupname", MySqlDbType.VarChar) { DefaultValue = "", Length = 30, NotNull = true }, new SqlColumn("restockTimer", MySqlDbType.Int32) { DefaultValue = "-1", NotNull = true }, new SqlColumn("stock", MySqlDbType.Int32) { DefaultValue = "-1", NotNull = true }, new SqlColumn("onsale", MySqlDbType.VarChar) { DefaultValue = "", Length = 30, NotNull = true }, new SqlColumn("maxstock", MySqlDbType.Int32) { DefaultValue = "-1", Length = 30, NotNull = true } )); sqlcreator.EnsureTableStructure(new SqlTable("storetrade", new SqlColumn("ID", MySqlDbType.Int32) { Primary = true}, new SqlColumn("User", MySqlDbType.VarChar) { Length = 30 }, new SqlColumn("ItemID", MySqlDbType.Int32), new SqlColumn("Stack", MySqlDbType.Int32), new SqlColumn("WItemID", MySqlDbType.Int32), new SqlColumn("WStack", MySqlDbType.Int32), new SqlColumn("Active", MySqlDbType.Int32) )); sqlcreator.EnsureTableStructure(new SqlTable("storeoffer", new SqlColumn("ID", MySqlDbType.Int32) { Primary = true }, new SqlColumn("User", MySqlDbType.VarChar) { Length = 30 }, new SqlColumn("ItemID", MySqlDbType.Int32), new SqlColumn("Stack", MySqlDbType.Int32), new SqlColumn("TradeID", MySqlDbType.Int32), new SqlColumn("Active", MySqlDbType.Int32) )); ShopList = new ShopData(this); TradeList = new TradeData(this); configObj = new ShopConfig(); SetupConfig(); Commands.ChatCommands.Add(new Command("store.shop", shop, "shop")); Commands.ChatCommands.Add(new Command("store.admin", shopreload, "reloadstore")); Commands.ChatCommands.Add(new Command("store.trade", trade, "trade")); Commands.ChatCommands.Add(new Command("store.offer", offer, "offer")); }