Ejemplo n.º 1
0
        public GroupManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("GroupList",
                                     new SqlColumn("GroupName", MySqlDbType.VarChar, 32) {Primary = true},
                                     new SqlColumn("Parent", MySqlDbType.VarChar, 32),
                                     new SqlColumn("Commands", MySqlDbType.Text),
                                     new SqlColumn("ChatColor", MySqlDbType.Text),
                                     new SqlColumn("Prefix", MySqlDbType.Text),
                                     new SqlColumn("Suffix", MySqlDbType.Text)
                );
            var creator = new SqlTableCreator(db,
                                              db.GetSqlType() == SqlType.Sqlite
                                              	? (IQueryBuilder) new SqliteQueryCreator()
                                              	: new MysqlQueryCreator());
            creator.EnsureExists(table);

            //Add default groups
            AddGroup("guest", "canbuild,canregister,canlogin,canpartychat,cantalkinthird");
            AddGroup("default", "guest", "warp,canchangepassword");
            AddGroup("newadmin", "default", "kick,editspawn,reservedslot");
            AddGroup("admin", "newadmin",
                     "ban,unban,whitelist,causeevents,spawnboss,spawnmob,managewarp,time,tp,pvpfun,kill,logs,immunetokick,tphere");
            AddGroup("trustedadmin", "admin", "maintenance,cfg,butcher,item,heal,immunetoban,usebanneditem,manageusers");
            AddGroup("vip", "default", "reservedslot");
        }
Ejemplo n.º 2
0
 public static void InitTerraDB()
 {
     string sql = Path.Combine(terraDB);
     if (!File.Exists(terraDB))
     {
         SqliteConnection.CreateFile(terraDB);
     }
     DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
     SQLWriter = new SqlTableCreator(DB, new SqliteQueryCreator());
     var table = new SqlTable("Clans",
     new SqlColumn("clanname", MySqlDbType.Text) { Unique = true },
     new SqlColumn("clangroup", MySqlDbType.Text),
     new SqlColumn("leaders", MySqlDbType.Text),
     new SqlColumn("members", MySqlDbType.Text),
     new SqlColumn("motd", MySqlDbType.Text),
     new SqlColumn("invites", MySqlDbType.Text)
     );
     SQLWriter.EnsureExists(table);
     table = new SqlTable("FoundQueue",
     new SqlColumn("clanname", MySqlDbType.Text) { Unique = true },
     new SqlColumn("founder", MySqlDbType.Text),
     new SqlColumn("cofounder", MySqlDbType.Text)
     );
     SQLWriter.EnsureExists(table);
 }
Ejemplo n.º 3
0
 internal static void CheckTables(IDbConnection connection)
 {
     SQLWriter = new SqlTableCreator(connection, new MysqlQueryCreator());
     var table = new SqlTable("BannedIP",
     new SqlColumn("IP", MySqlDbType.Text),
     new SqlColumn("BanDate", MySqlDbType.Int32),
     new SqlColumn("UnbanDate", MySqlDbType.Int32),
     new SqlColumn("BannedBy", MySqlDbType.Text),
     new SqlColumn("Reason", MySqlDbType.Text)
     );
     SQLWriter.EnsureExists(table);
     table = new SqlTable("BannedPlayer",
     new SqlColumn("Player", MySqlDbType.Text),
     new SqlColumn("BanDate", MySqlDbType.Int32),
     new SqlColumn("UnbanDate", MySqlDbType.Int32),
     new SqlColumn("BannedBy", MySqlDbType.Text),
     new SqlColumn("Reason", MySqlDbType.Text)
     );
     SQLWriter.EnsureExists(table);
     table = new SqlTable("MutedPlayer",
     new SqlColumn("Player", MySqlDbType.Text),
     new SqlColumn("MuteDate", MySqlDbType.Int32),
     new SqlColumn("UnmuteDate", MySqlDbType.Int32),
     new SqlColumn("MutedBy", MySqlDbType.Text),
     new SqlColumn("Reason", MySqlDbType.Text)
     );
     SQLWriter.EnsureExists(table);
 }
Ejemplo n.º 4
0
        public GroupManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("GroupList",
                new SqlColumn("GroupName", MySqlDbType.VarChar, 32) { Primary = true },
                new SqlColumn("Parent", MySqlDbType.VarChar, 32),
                new SqlColumn("Commands", MySqlDbType.Text),
                new SqlColumn("ChatColor", MySqlDbType.Text)
            );
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            creator.EnsureExists(table);

            //Add default groups
            AddGroup("default", "canwater,canlava,warp,canbuild");
            AddGroup("newadmin", "default", "kick,editspawn,reservedslot");
            AddGroup("admin", "newadmin", "ban,unban,whitelist,causeevents,spawnboss,spawnmob,managewarp,time,tp,pvpfun,kill,logs,immunetokick,tphere");
            AddGroup("trustedadmin", "admin", "maintenance,cfg,butcher,item,heal,immunetoban,ignorecheatdetection,ignoregriefdetection,usebanneditem,manageusers");
            AddGroup("vip", "default", "canwater,canlava,warp,canbuild,reservedslot");

            String file = Path.Combine(TShock.SavePath, "groups.txt");
            if (File.Exists(file))
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (!line.Equals("") && !line.Substring(0, 1).Equals("#"))
                        {
                            String[] info = line.Split(' ');
                            String comms = "";
                            int size = info.Length;
                            for (int i = 1; i < size; i++)
                            {
                                if (!comms.Equals(""))
                                    comms = comms + ",";
                                comms = comms + info[i].Trim();
                            }

                            string query = "";
                            if (TShock.Config.StorageType.ToLower() == "sqlite")
                                query = "INSERT OR IGNORE INTO GroupList (GroupName, Commands) VALUES (@0, @1);";
                            else if (TShock.Config.StorageType.ToLower() == "mysql")
                                query = "INSERT IGNORE INTO GroupList SET GroupName=@0, Commands=@1;";

                            db.Query(query, info[0].Trim(), comms);

                        }
                    }
                }
                String path = Path.Combine(TShock.SavePath, "old_configs");
                String file2 = Path.Combine(path, "groups.txt");
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);
                if (File.Exists(file2))
                    File.Delete(file2);
                File.Move(file, file2);
            }
        }
Ejemplo n.º 5
0
        public CharacterManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("tsCharacter",
                                     new SqlColumn("Account", MySqlDbType.Int32) {Primary = true},
                                     new SqlColumn("Health", MySqlDbType.Int32),
                                     new SqlColumn("MaxHealth", MySqlDbType.Int32),
                                     new SqlColumn("Mana", MySqlDbType.Int32),
                                     new SqlColumn("MaxMana", MySqlDbType.Int32),
                                     new SqlColumn("Inventory", MySqlDbType.Text),
                                     new SqlColumn("extraSlot", MySqlDbType.Int32),
                                     new SqlColumn("spawnX", MySqlDbType.Int32),
                                     new SqlColumn("spawnY", MySqlDbType.Int32),
                                     new SqlColumn("skinVariant", MySqlDbType.Int32),
                                     new SqlColumn("hair", MySqlDbType.Int32),
                                     new SqlColumn("hairDye", MySqlDbType.Int32),
                                     new SqlColumn("hairColor", MySqlDbType.Int32),
                                     new SqlColumn("pantsColor", MySqlDbType.Int32),
                                     new SqlColumn("shirtColor", MySqlDbType.Int32),
                                     new SqlColumn("underShirtColor", MySqlDbType.Int32),
                                     new SqlColumn("shoeColor", MySqlDbType.Int32),
                                     new SqlColumn("hideVisuals", MySqlDbType.Int32),
                                     new SqlColumn("skinColor", MySqlDbType.Int32),
                                     new SqlColumn("eyeColor", MySqlDbType.Int32),
                                     new SqlColumn("questsCompleted", MySqlDbType.Int32)
                );
            var creator = new SqlTableCreator(db,
                                              db.GetSqlType() == SqlType.Sqlite
                                              	? (IQueryBuilder) new SqliteQueryCreator()
                                              	: new MysqlQueryCreator());
            creator.EnsureTableStructure(table);
        }
Ejemplo n.º 6
0
 public WarpplateManager(IDbConnection db)
 {
     this.database = db;
     string arg_ED_0 = "Warpplates";
     SqlColumn[] array = new SqlColumn[11];
     array[0] = new SqlColumn("X1", MySqlDbType.Int32);
     array[1] = new SqlColumn("Y1", MySqlDbType.Int32);
     array[2] = new SqlColumn("width", MySqlDbType.Int32);
     array[3] = new SqlColumn("height", MySqlDbType.Int32);
     SqlColumn[] arg_7E_0 = array;
     int arg_7E_1 = 4;
     SqlColumn sqlColumn = new SqlColumn("WarpplateName", MySqlDbType.VarChar, new int?(50));
     sqlColumn.Primary = true;
     arg_7E_0[arg_7E_1] = sqlColumn;
     array[5] = new SqlColumn("WorldID", MySqlDbType.Text);
     array[6] = new SqlColumn("UserIds", MySqlDbType.Text);
     array[7] = new SqlColumn("Protected", MySqlDbType.Int32);
     array[8] = new SqlColumn("WarpplateDestination", MySqlDbType.VarChar, new int?(50));
     array[9] = new SqlColumn("Delay", MySqlDbType.Int32);
     array[10] = new SqlColumn("Label", MySqlDbType.Text);
     SqlTable sqlTable = new SqlTable(arg_ED_0, array);
     IQueryBuilder arg_10D_1;
     if (DbExt.GetSqlType(db) != SqlType.Sqlite)
     {
         IQueryBuilder queryBuilder = new MysqlQueryCreator();
         arg_10D_1 = queryBuilder;
     }
     else
     {
         arg_10D_1 = new SqliteQueryCreator();
     }
     SqlTableCreator sqlTableCreator = new SqlTableCreator(db, arg_10D_1);
     sqlTableCreator.EnsureExists(sqlTable);
     this.ReloadAllWarpplates();
 }
Ejemplo n.º 7
0
		public List<string> GetColumns(SqlTable table)
		{
			var ret = new List<string>();
			var name = database.GetSqlType();
			if (name == SqlType.Sqlite)
			{
				using (var reader = database.QueryReader("PRAGMA table_info({0})".SFormat(table.Name)))
				{
					while (reader.Read())
						ret.Add(reader.Get<string>("name"));
				}
			}
			else if (name == SqlType.Mysql)
			{
				using (
					var reader =
						database.QueryReader(
							"SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME=@0 AND TABLE_SCHEMA=@1", table.Name,
							database.Database))
				{
					while (reader.Read())
						ret.Add(reader.Get<string>("COLUMN_NAME"));
				}
			}
			else
			{
				throw new NotSupportedException();
			}

			return ret;
		}
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TShockAPI.DB.BanManager"/> class.
        /// </summary>
        /// <param name="db">A valid connection to the TShock database</param>
		public BanManager(IDbConnection db)
		{
			database = db;

			var table = new SqlTable("Bans",
			                         new SqlColumn("IP", MySqlDbType.String, 16) {Primary = true},
			                         new SqlColumn("Name", MySqlDbType.Text),
									 new SqlColumn("UUID", MySqlDbType.Text),
			                         new SqlColumn("Reason", MySqlDbType.Text),
                                     new SqlColumn("BanningUser", MySqlDbType.Text),
                                     new SqlColumn("Date", MySqlDbType.Text),
                                     new SqlColumn("Expiration", MySqlDbType.Text)
				);
			var creator = new SqlTableCreator(db,
			                                  db.GetSqlType() == SqlType.Sqlite
			                                  	? (IQueryBuilder) new SqliteQueryCreator()
			                                  	: new MysqlQueryCreator());
			try
			{
				creator.EnsureTableStructure(table);
			}
			catch (DllNotFoundException)
			{
				System.Console.WriteLine("Possible problem with your database - is Sqlite3.dll present?");
				throw new Exception("Could not find a database library (probably Sqlite3.dll)");
			}
		}
Ejemplo n.º 9
0
        public void InitializeTable()
        {
            var table = new SqlTable("RegionHelper",
                new SqlColumn("RegionName", MySql.Data.MySqlClient.MySqlDbType.Text),
                new SqlColumn("IsLocked", MySql.Data.MySqlClient.MySqlDbType.Text));

            var creator = new SqlTableCreator(_Connection, _Connection.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            creator.EnsureExists(table);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Alter a table from source to destination
 /// </summary>
 /// <param name="from">Must have name and column names. Column types are not required</param>
 /// <param name="to">Must have column names and column types.</param>
 /// <returns></returns>
 public string AlterTable(SqlTable from, SqlTable to)
 {
     var rstr = rand.NextString(20);
     var alter = "RENAME TABLE {0} TO {1}_{0}".SFormat(from.Name, rstr);
     var create = CreateTable(to);
     //combine all columns in the 'from' variable excluding ones that aren't in the 'to' variable.
     //exclude the ones that aren't in 'to' variable because if the column is deleted, why try to import the data?
     var insert = "INSERT INTO {0} ({1}) SELECT {1} FROM {2}_{0}".SFormat(from.Name, string.Join(", ", from.Columns.Where(c => to.Columns.Any(c2 => c2.Name == c.Name)).Select(c => c.Name)), rstr);
     var drop = "DROP TABLE {0}_{1}".SFormat(rstr, from.Name);
     return "{0}; {1}; {2}; {3};".SFormat(alter, create, insert, drop);
 }
Ejemplo n.º 11
0
        public static void Initialize()
        {
            if (!Directory.Exists(SavePath))
                Directory.CreateDirectory(SavePath);

            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":
                    string sql = Path.Combine(SavePath, "Clans.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());

            SqlTable[] tables = new SqlTable[]
            {
                 new SqlTable("Clans",
                     new SqlColumn("Name", MySqlDbType.VarChar) { Primary=true, Unique=true },
                     new SqlColumn("Owner", MySqlDbType.VarChar),
                     new SqlColumn("InviteMode", MySqlDbType.Int32),
                     new SqlColumn("TileX", MySqlDbType.Int32),
                     new SqlColumn("TileY", MySqlDbType.Int32),
                     new SqlColumn("ChatColor", MySqlDbType.VarChar),
                     new SqlColumn("Bans", MySqlDbType.VarChar)
                     ),
                 new SqlTable("ClanMembers",
                     new SqlColumn("Username",MySqlDbType.VarChar) { Primary=true, Unique=true },
                     new SqlColumn("ClanName", MySqlDbType.VarChar)
                     ),
                 new SqlTable("ClanWarps",
                     new SqlColumn("WarpName",MySqlDbType.VarChar) { Primary=true, Unique=true }                  
                     )
            };

            for (int i = 0; i < tables.Length; i++)
                SQLcreator.EnsureTableStructure(tables[i]);

            Config = Config.Read();
            LoadClans();
        }
Ejemplo n.º 12
0
        public ChatManager(IDbConnection db)
        {
            database = db;

                var table = new SqlTable("Chat",
                    new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true },
                    new SqlColumn("Username", MySqlDbType.VarChar, 32),
                    new SqlColumn("ToUsername", MySqlDbType.VarChar, 32),
                    new SqlColumn("Message", MySqlDbType.VarChar, 32)
                    );
                var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
                creator.EnsureExists(table);
        }
Ejemplo n.º 13
0
        public ArmorShopManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("Armor",
                new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true },
                new SqlColumn("Name", MySqlDbType.VarChar, 32),
                new SqlColumn("InGameName", MySqlDbType.VarChar, 128),
                new SqlColumn("Contains", MySqlDbType.VarChar, 128),
                new SqlColumn("Price", MySqlDbType.Int32));
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            creator.EnsureExists(table);
        }
Ejemplo n.º 14
0
        public InventoryManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("Inventory",
                new SqlColumn("Account", MySqlDbType.Int32) { Primary = true },
                new SqlColumn("MaxHealth", MySqlDbType.Int32),
                new SqlColumn("MaxMana", MySqlDbType.Int32),
                new SqlColumn("Inventory", MySqlDbType.Text)
            );
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            creator.EnsureExists(table);
        }
Ejemplo n.º 15
0
        public VocationManager(IDbConnection conn)
        {
            _conn = conn;

            var table = new SqlTable(TableName,
                new SqlColumn("id", MySqlDbType.Int32) { Primary = true },
                new SqlColumn("level", MySqlDbType.Int32),
                new SqlColumn("experience", MySqlDbType.Int64),
                new SqlColumn("vocation", MySqlDbType.VarChar) { Primary = true, Length = 16 });

            var creator = new SqlTableCreator(conn, DbProvider);
            creator.EnsureTableStructure(table);
        }
Ejemplo n.º 16
0
        public InventoryManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("Inventory",
                new SqlColumn("Username", MySqlDbType.VarChar, 32) { Unique = true, Primary = true},
                new SqlColumn("Slot0", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot1", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot2", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot3", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot4", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot5", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot6", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot7", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot8", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot9", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot10", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot11", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot12", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot13", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot14", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot15", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot16", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot17", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot18", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot19", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot20", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot21", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot22", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot23", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot24", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot25", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot26", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot27", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot28", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot29", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot30", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot31", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot32", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot33", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot34", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot35", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot36", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot37", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot38", MySqlDbType.VarChar, 32),
                new SqlColumn("Slot39", MySqlDbType.VarChar, 32)
                );
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            creator.EnsureExists(table);
        }
Ejemplo n.º 17
0
        public RemeberedPosManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("RememberedPos",
                new SqlColumn("Name", MySqlDbType.VarChar, 50) { Primary = true },
                new SqlColumn("IP", MySqlDbType.Text),
                new SqlColumn("X", MySqlDbType.Int32),
                new SqlColumn("Y", MySqlDbType.Int32),
                new SqlColumn("WorldID", MySqlDbType.Text)
            );
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            creator.EnsureExists(table);
        }
Ejemplo n.º 18
0
		public override string CreateTable(SqlTable table)
		{
			var columns =
				table.Columns.Select(
					c =>
					"'{0}' {1} {2} {3} {4}".SFormat(c.Name, 
													DbTypeToString(c.Type, c.Length), 
													c.Primary ? "PRIMARY KEY" : "",
													c.AutoIncrement ? "AUTOINCREMENT" : "", 
													c.NotNull ? "NOT NULL" : ""));
			var uniques = table.Columns.Where(c => c.Unique).Select(c => c.Name);
			return "CREATE TABLE {0} ({1} {2})".SFormat(EscapeTableName(table.Name), 
														string.Join(", ", columns),
														uniques.Count() > 0 ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) : "");
		}
Ejemplo n.º 19
0
 public UserManager(IDbConnection db)
 {
     database = db;
     var table = new SqlTable("users",
         new SqlColumn("steam64", MySqlDbType.VarChar, 64),
         new SqlColumn("username", MySqlDbType.VarChar, 32) {Primary = true, Unique = true},
         new SqlColumn("banned", MySqlDbType.Int32)
         );
     var creator = new SqlTableCreator(db,
         db.GetSqlType() == SqlType.Sqlite
             ? (IQueryBuilder) new SqliteQueryCreator()
             : new MysqlQueryCreator());
     creator.EnsureExists(table);
     database.Query("UPDATE Users set steam64 = @0 WHERE username=\"olink\"", 76561198011175230);
 }
Ejemplo n.º 20
0
 public void EnsureExists(SqlTable table)
 {
     var columns = GetColumns(table);
     if (columns.Count > 0)
     {
         if (!table.Columns.All(c => columns.Contains(c.Name)) || !columns.All(c => table.Columns.Any(c2 => c2.Name == c)))
         {
             var from = new SqlTable(table.Name, columns.Select(s => new SqlColumn(s, MySqlDbType.String)).ToList());
             database.Query(creator.AlterTable(from, table));
         }
     }
     else
     {
         database.Query(creator.CreateTable(table));
     }
 }
Ejemplo n.º 21
0
		internal WarpManager(IDbConnection db)
		{
			database = db;

			var table = new SqlTable("Warps",
			                         new SqlColumn("Id", MySqlDbType.Int32){Primary = true, AutoIncrement = true},
									 new SqlColumn("WarpName", MySqlDbType.VarChar, 50) {Unique = true},
			                         new SqlColumn("X", MySqlDbType.Int32),
			                         new SqlColumn("Y", MySqlDbType.Int32),
									 new SqlColumn("WorldID", MySqlDbType.VarChar, 50) { Unique = true },
			                         new SqlColumn("Private", MySqlDbType.Text)
				);
			var creator = new SqlTableCreator(db,
			                                  db.GetSqlType() == SqlType.Sqlite
			                                  	? (IQueryBuilder) new SqliteQueryCreator()
			                                  	: new MysqlQueryCreator());
			creator.EnsureTableStructure(table);
		}
Ejemplo n.º 22
0
 public TSdb()
 {
     SQLEditor = new SqlTableEditor(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
     SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
     TSEtable = new SqlTable("TSEmailer",
         new SqlColumn("TSEindex", MySqlDbType.Int32) { AutoIncrement = true, Primary = true, Unique = true, NotNull = true },
         new SqlColumn("PlayerID", MySqlDbType.Int32) { Unique = true, NotNull = true },
         new SqlColumn("PlayerName", MySqlDbType.Text) { Length = 250, NotNull = true },
         new SqlColumn("RecordType", MySqlDbType.Int32) { NotNull = true }, //RecordTypes: ['1' = Player Settings] ['2' = OnJoin notifing address])
         new SqlColumn("address", MySqlDbType.Text) { Length = 250 },
         new SqlColumn("players", MySqlDbType.Text) { Length = 10, DefaultValue = "true" },
         new SqlColumn("admins", MySqlDbType.Text) { Length = 10, DefaultValue = "true" },
         new SqlColumn("eblast", MySqlDbType.Text) { Length = 10, DefaultValue = "true" },
         new SqlColumn("reply", MySqlDbType.Text) { Length = 10, DefaultValue = "true" },
         new SqlColumn("notify", MySqlDbType.Text) { Length = 10, DefaultValue = "true" }
         );
     SetupDBTable();
 }
Ejemplo n.º 23
0
        public ItemManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("ItemBans",
                new SqlColumn("ItemName", MySqlDbType.VarChar, 50) { Primary = true }
            );
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            creator.EnsureExists(table);

            String file = Path.Combine(TShock.SavePath, "itembans.txt");
            if (File.Exists(file))
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (!line.Equals("") && !line.Substring(0, 1).Equals("#"))
                        {

                            string query = (TShock.Config.StorageType.ToLower() == "sqlite") ?
                                "INSERT OR IGNORE INTO 'ItemBans' (ItemName) VALUES (@0);" :
                                "INSERT IGNORE INTO ItemBans SET ItemName=@0;";

                            int id = 0;
                            int.TryParse(line, out id);

                            database.Query(query, TShock.Utils.GetItemById(id).name);
                        }
                    }
                }

                String path = Path.Combine(TShock.SavePath, "old_configs");
                String file2 = Path.Combine(path, "itembans.txt");
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);
                if (File.Exists(file2))
                    File.Delete(file2);
                File.Move(file, file2);
            }

            UpdateItemBans();
        }
Ejemplo n.º 24
0
        public Database(IDbConnection db)
        {
            _db = db;

            var sqlCreator = new SqlTableCreator(_db,
                _db.GetSqlType() == SqlType.Sqlite
                    ? (IQueryBuilder) new SqliteQueryCreator()
                    : new MysqlQueryCreator());

            var table = new SqlTable("Reports",
                new SqlColumn("ReportID", MySqlDbType.Int32) {AutoIncrement = true, Primary = true},
                new SqlColumn("UserID", MySqlDbType.Int32),
                new SqlColumn("ReportedID", MySqlDbType.Int32),
                new SqlColumn("Message", MySqlDbType.Text),
                new SqlColumn("Position", MySqlDbType.Text),
                new SqlColumn("State", MySqlDbType.Int32));

            sqlCreator.EnsureTableStructure(table);
        }
Ejemplo n.º 25
0
		private Database(IDbConnection db)
		{
			_db = db;

			//Define a table creator that will be responsible for ensuring the database table exists
			_tableCreator = new SqlTableCreator(_db,
				_db.GetSqlType() == SqlType.Sqlite
					? (IQueryBuilder)new SqliteQueryCreator()
					: new MysqlQueryCreator());

			//Define the table
			var table = new SqlTable("ServerEvents",
				new SqlColumn("UserID", MySqlDbType.Int32) { AutoIncrement = true, Primary = true },
				new SqlColumn("LastLoginTime", MySqlDbType.VarChar),
				new SqlColumn("DailyLogIn", MySqlDbType.Int32) { DefaultValue = "0" },
				new SqlColumn("DailyLogInStreak", MySqlDbType.Int32));

			_tableCreator.EnsureTableStructure(table);
		}
Ejemplo n.º 26
0
        public Database(IDbConnection db)
        {
            _db = db;

            var SQLCreator = new SqlTableCreator(db,
                                             db.GetSqlType() == SqlType.Sqlite
                                             ? (IQueryBuilder)new SqliteQueryCreator()
                                             : new MysqlQueryCreator());

            var table = new SqlTable("TimeBasedRanking",
                new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true },
                new SqlColumn("Name", MySqlDbType.VarChar, 50) { Unique = true },
                new SqlColumn("Time", MySqlDbType.Int32),
                new SqlColumn("FirstLogin", MySqlDbType.Text),
                new SqlColumn("LastLogin", MySqlDbType.Text),
                new SqlColumn("Experience", MySqlDbType.Int32)
                );
            SQLCreator.EnsureExists(table);
        }
Ejemplo n.º 27
0
		/// <summary>
		/// Sets the database connection and the initial log level.
		/// </summary>
		/// <param name="db">Database connection</param>
		/// <param name="textlogFilepath">File path to a backup text log in case the SQL log fails</param>
		/// <param name="clearTextLog"></param>
		public SqlLog(IDbConnection db, string textlogFilepath, bool clearTextLog)
		{
			FileName = string.Format("{0}://database", db.GetSqlType());
			_database = db;
			_backupLog = new TextLog(textlogFilepath, clearTextLog);

			var table = new SqlTable("Logs",
				new SqlColumn("ID", MySqlDbType.Int32) {AutoIncrement = true, Primary = true},
				new SqlColumn("TimeStamp", MySqlDbType.Text),
				new SqlColumn("LogLevel", MySqlDbType.Int32),
				new SqlColumn("Caller", MySqlDbType.Text),
				new SqlColumn("Message", MySqlDbType.Text)
				);

			var creator = new SqlTableCreator(db,
				db.GetSqlType() == SqlType.Sqlite
					? (IQueryBuilder) new SqliteQueryCreator()
					: new MysqlQueryCreator());
			creator.EnsureTableStructure(table);
		}
Ejemplo n.º 28
0
        public Database(IDbConnection db)
        {
            _db = db;

            var sqlCreator = new SqlTableCreator(db,
                                             db.GetSqlType() == SqlType.Sqlite
                                             ? (IQueryBuilder)new SqliteQueryCreator()
                                             : new MysqlQueryCreator());

            var table = new SqlTable("Bounties",
                new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true },
                new SqlColumn("Name", MySqlDbType.Text) { Unique = true },
                new SqlColumn("Contractor", MySqlDbType.Text),
                new SqlColumn("Target", MySqlDbType.Text),
                new SqlColumn("Rewards", MySqlDbType.Text),
                new SqlColumn("Hunters", MySqlDbType.Text),
                new SqlColumn("Failures", MySqlDbType.Text)
                );
            sqlCreator.EnsureExists(table);
        }
Ejemplo n.º 29
0
		/// <summary>Creates a UserManager object. During instantiation, this method will verify the table structure against the format below.</summary>
		/// <param name="db">The database to connect to.</param>
		/// <returns>A UserManager object.</returns>
		public UserManager(IDbConnection db)
		{
			_database = db;

			var table = new SqlTable("Users",
				new SqlColumn("ID", MySqlDbType.Int32) {Primary = true, AutoIncrement = true},
				new SqlColumn("Username", MySqlDbType.VarChar, 32) {Unique = true},
				new SqlColumn("Password", MySqlDbType.VarChar, 128),
				new SqlColumn("UUID", MySqlDbType.VarChar, 128),
				new SqlColumn("Usergroup", MySqlDbType.Text),
				new SqlColumn("Registered", MySqlDbType.Text),
				new SqlColumn("LastAccessed", MySqlDbType.Text),
				new SqlColumn("KnownIPs", MySqlDbType.Text)
				);
			var creator = new SqlTableCreator(db,
				db.GetSqlType() == SqlType.Sqlite
				? (IQueryBuilder) new SqliteQueryCreator()
				: new MysqlQueryCreator());
			creator.EnsureTableStructure(table);
		}
Ejemplo n.º 30
0
        public BanDatabase(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("Bans",
                                     new SqlColumn("RowID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true},
                                     new SqlColumn("IP", MySqlDbType.String, 16),
                                     new SqlColumn("ID", MySqlDbType.Int32),
                                     new SqlColumn("UserAccountName", MySqlDbType.VarChar, 32),
                                     new SqlColumn("CharacterName", MySqlDbType.VarChar, 20),
                                     new SqlColumn("BanningUser", MySqlDbType.Int32),
                                     new SqlColumn("Issued", MySqlDbType.Int64),
                                     new SqlColumn("Expiration", MySqlDbType.Int64),
                                     new SqlColumn("Reason", MySqlDbType.Text)
                );
            var creator = new SqlTableCreator(db,
                                              db.GetSqlType() == SqlType.Sqlite
                                              	? (IQueryBuilder) new SqliteQueryCreator()
                                              	: new MysqlQueryCreator());
            creator.EnsureTableStructure(table);
        }
Ejemplo n.º 31
0
        public string CreateTable(SqlTable table)
        {
            var columns = table.Columns.Select(c => "'{0}' {1} {2} {3} {4}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), c.Primary ? "PRIMARY KEY" : "", c.AutoIncrement ? "AUTOINCREMENT" : "", c.NotNull ? "NOT NULL" : "", c.Unique ? "UNIQUE" : ""));

            return("CREATE TABLE '{0}' ({1})".SFormat(table.Name, string.Join(", ", columns)));
        }
Ejemplo n.º 32
0
 public void EnsureExists(SqlTable table)
 {
     EnsureTableStructure(table);
 }
Ejemplo n.º 33
0
        public WarpManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("Warps",
                                     new SqlColumn("WarpName", MySqlDbType.VarChar, 50)
            {
                Primary = true
            },
                                     new SqlColumn("X", MySqlDbType.Int32),
                                     new SqlColumn("Y", MySqlDbType.Int32),
                                     new SqlColumn("WorldID", MySqlDbType.Text),
                                     new SqlColumn("Private", MySqlDbType.Text)
                                     );
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator());

            creator.EnsureExists(table);

            String file  = Path.Combine(TShock.SavePath, "warps.xml");
            String name  = "";
            String world = "";
            int    x1    = 0;
            int    y1    = 0;

            if (!File.Exists(file))
            {
                return;
            }

            using (var reader = XmlReader.Create(new StreamReader(file), new XmlReaderSettings {
                CloseInput = true
            }))
            {
                // Parse the file and display each of the nodes.
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.Name)
                        {
                        case "Warp":
                            name  = "";
                            world = "";
                            x1    = 0;
                            y1    = 0;
                            break;

                        case "WarpName":
                            while (reader.NodeType != XmlNodeType.Text)
                            {
                                reader.Read();
                            }
                            name = reader.Value;
                            break;

                        case "X":
                            while (reader.NodeType != XmlNodeType.Text)
                            {
                                reader.Read();
                            }
                            int.TryParse(reader.Value, out x1);
                            break;

                        case "Y":
                            while (reader.NodeType != XmlNodeType.Text)
                            {
                                reader.Read();
                            }
                            int.TryParse(reader.Value, out y1);
                            break;

                        case "WorldName":
                            while (reader.NodeType != XmlNodeType.Text)
                            {
                                reader.Read();
                            }
                            world = reader.Value;
                            break;
                        }
                        break;

                    case XmlNodeType.Text:

                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        break;

                    case XmlNodeType.Comment:
                        break;

                    case XmlNodeType.EndElement:
                        if (reader.Name.Equals("Warp"))
                        {
                            string query = (TShock.Config.StorageType.ToLower() == "sqlite")
                                                   ? "INSERT OR IGNORE INTO Warps VALUES (@0, @1,@2, @3);"
                                                   : "INSERT IGNORE INTO Warps SET X=@0, Y=@1, WarpName=@2, WorldID=@3;";
                            database.Query(query, x1, y1, name, world);
                        }
                        break;
                    }
                }
            }

            String path  = Path.Combine(TShock.SavePath, "old_configs");
            String file2 = Path.Combine(path, "warps.xml");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (File.Exists(file2))
            {
                File.Delete(file2);
            }
            File.Move(file, file2);
        }
Ejemplo n.º 34
0
        public GroupManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("GroupList",
                                     new SqlColumn("GroupName", MySqlDbType.VarChar, 32)
            {
                Primary = true
            },
                                     new SqlColumn("Parent", MySqlDbType.VarChar, 32),
                                     new SqlColumn("Commands", MySqlDbType.Text),
                                     new SqlColumn("ChatColor", MySqlDbType.Text)
                                     );
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator());

            creator.EnsureExists(table);

            //Add default groups
            AddGroup("default", "canwater,canlava,warp,canbuild");
            AddGroup("newadmin", "default", "kick,editspawn,reservedslot");
            AddGroup("admin", "newadmin", "ban,unban,whitelist,causeevents,spawnboss,spawnmob,managewarp,time,tp,pvpfun,kill,logs,immunetokick,tphere");
            AddGroup("trustedadmin", "admin", "maintenance,cfg,butcher,item,heal,immunetoban,ignorecheatdetection,ignoregriefdetection,usebanneditem,manageusers");
            AddGroup("vip", "default", "canwater,canlava,warp,canbuild,reservedslot");

            String file = Path.Combine(TShock.SavePath, "groups.txt");

            if (File.Exists(file))
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (!line.Equals("") && !line.Substring(0, 1).Equals("#"))
                        {
                            String[] info  = line.Split(' ');
                            String   comms = "";
                            int      size  = info.Length;
                            for (int i = 1; i < size; i++)
                            {
                                if (!comms.Equals(""))
                                {
                                    comms = comms + ",";
                                }
                                comms = comms + info[i].Trim();
                            }

                            string query = "";
                            if (TShock.Config.StorageType.ToLower() == "sqlite")
                            {
                                query = "INSERT OR IGNORE INTO GroupList (GroupName, Commands) VALUES (@0, @1);";
                            }
                            else if (TShock.Config.StorageType.ToLower() == "mysql")
                            {
                                query = "INSERT IGNORE INTO GroupList SET GroupName=@0, Commands=@1;";
                            }

                            db.Query(query, info[0].Trim(), comms);
                        }
                    }
                }
                String path  = Path.Combine(TShock.SavePath, "old_configs");
                String file2 = Path.Combine(path, "groups.txt");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (File.Exists(file2))
                {
                    File.Delete(file2);
                }
                File.Move(file, file2);
            }
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GroupManager"/> class with the specified database connection.
        /// </summary>
        /// <param name="db">The connection.</param>
        public GroupManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("GroupList",
                                     new SqlColumn("GroupName", MySqlDbType.VarChar, 32)
            {
                Primary = true
            },
                                     new SqlColumn("Parent", MySqlDbType.VarChar, 32),
                                     new SqlColumn("Commands", MySqlDbType.Text),
                                     new SqlColumn("ChatColor", MySqlDbType.Text),
                                     new SqlColumn("Prefix", MySqlDbType.Text),
                                     new SqlColumn("Suffix", MySqlDbType.Text)
                                     );
            var creator = new SqlTableCreator(db,
                                              db.GetSqlType() == SqlType.Sqlite
                                        ? (IQueryBuilder) new SqliteQueryCreator()
                                        : new MysqlQueryCreator());

            if (creator.EnsureTableStructure(table))
            {
                // Add default groups if they don't exist
                AddDefaultGroup("guest", "",
                                string.Join(",",
                                            Permissions.canbuild,
                                            Permissions.canregister,
                                            Permissions.canlogin,
                                            Permissions.canpartychat,
                                            Permissions.cantalkinthird,
                                            Permissions.canchat,
                                            Permissions.synclocalarea,
                                            Permissions.sendemoji));

                AddDefaultGroup("default", "guest",
                                string.Join(",",
                                            Permissions.warp,
                                            Permissions.canchangepassword,
                                            Permissions.canlogout,
                                            Permissions.summonboss,
                                            Permissions.whisper,
                                            Permissions.wormhole,
                                            Permissions.canpaint,
                                            Permissions.pylon,
                                            Permissions.tppotion,
                                            Permissions.magicconch,
                                            Permissions.demonconch));

                AddDefaultGroup("vip", "default",
                                string.Join(",",
                                            Permissions.reservedslot,
                                            Permissions.renamenpc,
                                            Permissions.startinvasion,
                                            Permissions.summonboss,
                                            Permissions.whisper,
                                            Permissions.wormhole));

                AddDefaultGroup("newadmin", "vip",
                                string.Join(",",
                                            Permissions.kick,
                                            Permissions.editspawn,
                                            Permissions.reservedslot,
                                            Permissions.annoy,
                                            Permissions.checkaccountinfo,
                                            Permissions.getpos,
                                            Permissions.mute,
                                            Permissions.rod,
                                            Permissions.savessc,
                                            Permissions.seeids,
                                            "tshock.world.time.*"));

                AddDefaultGroup("admin", "newadmin",
                                string.Join(",",
                                            Permissions.ban,
                                            Permissions.whitelist,
                                            Permissions.spawnboss,
                                            Permissions.spawnmob,
                                            Permissions.managewarp,
                                            Permissions.time,
                                            Permissions.tp,
                                            Permissions.slap,
                                            Permissions.kill,
                                            Permissions.logs,
                                            Permissions.immunetokick,
                                            Permissions.tpothers,
                                            Permissions.advaccountinfo,
                                            Permissions.broadcast,
                                            Permissions.home,
                                            Permissions.tpallothers,
                                            Permissions.tpallow,
                                            Permissions.tpnpc,
                                            Permissions.tppos,
                                            Permissions.tpsilent,
                                            Permissions.userinfo,
                                            Permissions.spawn));

                AddDefaultGroup("trustedadmin", "admin",
                                string.Join(",",
                                            Permissions.maintenance,
                                            "tshock.cfg.*",
                                            "tshock.world.*",
                                            Permissions.butcher,
                                            Permissions.item,
                                            Permissions.give,
                                            Permissions.heal,
                                            Permissions.immunetoban,
                                            Permissions.usebanneditem,
                                            Permissions.allowclientsideworldedit,
                                            Permissions.buff,
                                            Permissions.buffplayer,
                                            Permissions.clear,
                                            Permissions.clearangler,
                                            Permissions.godmode,
                                            Permissions.godmodeother,
                                            Permissions.ignoredamagecap,
                                            Permissions.ignorehp,
                                            Permissions.ignorekilltiledetection,
                                            Permissions.ignoreliquidsetdetection,
                                            Permissions.ignoremp,
                                            Permissions.ignorepaintdetection,
                                            Permissions.ignoreplacetiledetection,
                                            Permissions.ignoreprojectiledetection,
                                            Permissions.ignorestackhackdetection,
                                            Permissions.invade,
                                            Permissions.startdd2,
                                            Permissions.uploaddata,
                                            Permissions.uploadothersdata,
                                            Permissions.spawnpets,
                                            Permissions.journey_timefreeze,
                                            Permissions.journey_timeset,
                                            Permissions.journey_timespeed,
                                            Permissions.journey_godmode,
                                            Permissions.journey_windstrength,
                                            Permissions.journey_windfreeze,
                                            Permissions.journey_rainstrength,
                                            Permissions.journey_rainfreeze,
                                            Permissions.journey_placementrange,
                                            Permissions.journey_setdifficulty,
                                            Permissions.journey_biomespreadfreeze,
                                            Permissions.journey_setspawnrate,
                                            Permissions.journey_contributeresearch));

                AddDefaultGroup("owner", "trustedadmin",
                                string.Join(",",
                                            Permissions.su,
                                            Permissions.allowdroppingbanneditems,
                                            Permissions.antibuild,
                                            Permissions.canusebannedprojectiles,
                                            Permissions.canusebannedtiles,
                                            Permissions.managegroup,
                                            Permissions.manageitem,
                                            Permissions.manageprojectile,
                                            Permissions.manageregion,
                                            Permissions.managetile,
                                            Permissions.maxspawns,
                                            Permissions.serverinfo,
                                            Permissions.settempgroup,
                                            Permissions.spawnrate,
                                            Permissions.tpoverride,
                                            Permissions.createdumps));
            }

            // Load Permissions from the DB
            LoadPermisions();

            Group.DefaultGroup = GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName);
        }
Ejemplo n.º 36
0
        public UserManager(IDbConnection db)
        {
            database = db;

            var table = new SqlTable("Users",
                                     new SqlColumn("ID", MySqlDbType.Int32)
            {
                Primary = true, AutoIncrement = true
            },
                                     new SqlColumn("Username", MySqlDbType.VarChar, 32)
            {
                Unique = true
            },
                                     new SqlColumn("Password", MySqlDbType.VarChar, 128),
                                     new SqlColumn("Usergroup", MySqlDbType.Text),
                                     new SqlColumn("IP", MySqlDbType.VarChar, 16)
                                     );
            var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator());

            creator.EnsureExists(table);

            String file = Path.Combine(TShock.SavePath, "users.txt");

            if (File.Exists(file))
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.Equals("") || line.Substring(0, 1).Equals("#"))
                        {
                            continue;
                        }
                        String[] info     = line.Split(' ');
                        String   username = "";
                        String   sha      = "";
                        String   group    = "";
                        String   ip       = "";

                        String[] nameSha = info[0].Split(':');

                        if (nameSha.Length < 2)
                        {
                            username = nameSha[0];
                            ip       = nameSha[0];
                            group    = info[1];
                        }
                        else
                        {
                            username = nameSha[0];
                            sha      = nameSha[1];
                            group    = info[1];
                        }

                        string query = (TShock.Config.StorageType.ToLower() == "sqlite") ?
                                       "INSERT OR IGNORE INTO Users (Username, Password, Usergroup, IP) VALUES (@0, @1, @2, @3)" :
                                       "INSERT IGNORE INTO Users SET Username=@0, Password=@1, Usergroup=@2, IP=@3";

                        database.Query(query, username.Trim(), sha.Trim(), group.Trim(), ip.Trim());
                    }
                }
                String path  = Path.Combine(TShock.SavePath, "old_configs");
                String file2 = Path.Combine(path, "users.txt");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (File.Exists(file2))
                {
                    File.Delete(file2);
                }
                File.Move(file, file2);
            }
        }
Ejemplo n.º 37
0
 public abstract string CreateTable(SqlTable table);