Пример #1
0
        public bool AllowGroup(int id, string name)
        {
            bool    flag;
            string  str         = "";
            BuffBan buffBanById = Koishi.BanBuff.Utils.GetBuffBanById(id);

            if (buffBanById != null)
            {
                try
                {
                    str = string.Join(",", buffBanById.AllowedGroups);
                    if (str.Length > 0)
                    {
                        str = string.Concat(str, ",");
                    }
                    str = string.Concat(str, name);
                    buffBanById.SetAllowedGroups(str);
                    IDbConnection dbConnection = this.database;
                    object[]      objArray     = new object[] { str, id };
                    flag = DbExt.Query(dbConnection, "UPDATE BuffBans SET AllowedGroups=@0 WHERE BuffID=@1", objArray) > 0;
                }
                catch (Exception exception)
                {
                    TShock.Log.Error(exception.ToString());
                    return(false);
                }
                return(flag);
            }
            return(false);
        }
Пример #2
0
        public bool RemoveGroup(int id, string group)
        {
            bool    flag;
            BuffBan buffBanById = Koishi.BanBuff.Utils.GetBuffBanById(id);

            if (buffBanById != null)
            {
                try
                {
                    buffBanById.RemoveGroup(group);
                    string        str          = string.Join(",", buffBanById.AllowedGroups);
                    IDbConnection dbConnection = this.database;
                    object[]      objArray     = new object[] { str, id };
                    if (DbExt.Query(dbConnection, "UPDATE BuffBans SET AllowedGroups=@0 WHERE BuffID=@1", objArray) <= 0)
                    {
                        return(false);
                    }
                    else
                    {
                        flag = true;
                    }
                }
                catch (Exception exception)
                {
                    TShock.Log.Error(exception.ToString());
                    return(false);
                }
                return(flag);
            }
            return(false);
        }
Пример #3
0
        public BuffManager(IDbConnection db)
        {
            IQueryBuilder sqliteQueryCreator;

            this.database = db;
            SqlColumn[] sqlColumn  = new SqlColumn[2];
            SqlColumn   sqlColumn1 = new SqlColumn("BuffID", MySqlDbType.Int32, new int?(50));

            sqlColumn1.Primary = true;
            sqlColumn[0]       = sqlColumn1;
            sqlColumn[1]       = new SqlColumn("AllowedGroups", MySqlDbType.Text);
            SqlTable      sqlTable     = new SqlTable("BuffBans", sqlColumn);
            IDbConnection dbConnection = db;

            if (DbExt.GetSqlType(db) == SqlType.Sqlite)
            {
                sqliteQueryCreator = new SqliteQueryCreator();
            }
            else
            {
                sqliteQueryCreator = new MysqlQueryCreator();
            }
            (new SqlTableCreator(dbConnection, sqliteQueryCreator)).EnsureTableStructure(sqlTable);
            this.UpdateBuffBans();
        }
Пример #4
0
 public void UpdateBuffBans()
 {
     this.BuffBans.Clear();
     using (QueryResult queryResult = DbExt.QueryReader(this.database, "SELECT * FROM BuffBans", new object[0]))
     {
         while (queryResult != null && queryResult.Read())
         {
             BuffBan buffBan = new BuffBan(queryResult.Get <int>("BuffID"));
             buffBan.SetAllowedGroups(queryResult.Get <string>("AllowedGroups"));
             this.BuffBans.Add(buffBan);
         }
     }
 }
Пример #5
0
 public void AddNewBan(int BuffID = 0)
 {
     try
     {
         IDbConnection dbConnection = this.database;
         object[]      buffID       = new object[] { BuffID, "" };
         DbExt.Query(dbConnection, "INSERT INTO BuffBans (BuffID, AllowedGroups) VALUES (@0, @1);", buffID);
         if (!this.BuffIsBanned(BuffID, null))
         {
             this.BuffBans.Add(new BuffBan(BuffID));
         }
     }
     catch (Exception exception)
     {
         TShock.Log.Error(exception.ToString());
     }
 }
Пример #6
0
 public void RemoveBan(int BuffID)
 {
     if (!this.BuffIsBanned(BuffID, null))
     {
         return;
     }
     try
     {
         IDbConnection dbConnection = this.database;
         object[]      buffID       = new object[] { BuffID };
         DbExt.Query(dbConnection, "DELETE FROM BuffBans WHERE BuffID=@0;", buffID);
         this.BuffBans.Remove(new BuffBan(BuffID));
     }
     catch (Exception exception)
     {
         TShock.Log.Error(exception.ToString());
     }
 }
Пример #7
0
        public void UpdateData(string table, object parameters, string where, FbTransaction trans)
        {
            CheckForNullArguments(table, parameters, trans.Connection, trans);

            var paramlist = DbExt.GetParams(parameters).ToArray();

            string[] setParams = paramlist.Select(param => $"{param.Key} = @{param.Key}").ToArray();
            string   sql       = $"update {table} set {string.Join(",", setParams)}" + (where.IsNullOrWhitespace() ? string.Empty : $" where {where}");

            using (var command = new FbCommand(sql, trans.Connection, trans))
            {
                foreach (var param in paramlist)
                {
                    command.Parameters.Add($"@{param.Key}", param.Value ?? DBNull.Value);
                }

                command.ExecuteNonQuery();
            }
        }
Пример #8
0
 public static void TryCreateTable()
 {
     try
     {
         SqlTable sqlTable = new SqlTable("PowerfulSign", new SqlColumn[]
         {
             new SqlColumn("SignID", MySql.Data.MySqlClient.MySqlDbType.Int32)
             {
                 Primary       = true,
                 AutoIncrement = true
             },
             new SqlColumn("Owner", MySql.Data.MySqlClient.MySqlDbType.Int32),
             new SqlColumn("Friends", MySql.Data.MySqlClient.MySqlDbType.Text),
             new SqlColumn("Text", MySql.Data.MySqlClient.MySqlDbType.Text),
             new SqlColumn("CanEdit", MySql.Data.MySqlClient.MySqlDbType.Int32)
             {
                 DefaultValue = "1"
             },                                                                                       //0为true, 1为false
             new SqlColumn("X", MySql.Data.MySqlClient.MySqlDbType.Int32),
             new SqlColumn("Y", MySql.Data.MySqlClient.MySqlDbType.Int32),
             new SqlColumn("WorldID", MySql.Data.MySqlClient.MySqlDbType.Int32)
         });
         IDbConnection db = TShock.DB;
         IQueryBuilder queryBuilder2;
         if (DbExt.GetSqlType(TShock.DB) != SqlType.Sqlite)
         {
             IQueryBuilder queryBuilder = new MysqlQueryCreator();
             queryBuilder2 = queryBuilder;
         }
         else
         {
             IQueryBuilder queryBuilder = new SqliteQueryCreator();
             queryBuilder2 = queryBuilder;
         }
         new SqlTableCreator(db, queryBuilder2).EnsureTableStructure(sqlTable);
         CheckSignImport();
     }
     catch (Exception ex) { TShock.Log.Error(ex.Message); }
     //Main.sign = new Sign[1000];
 }
Пример #9
0
        public void UpdateOrInsertData(string table, FbTransaction trans, object parameters, string matching)
        {
            CheckForNullArguments(table, parameters, trans.Connection, trans);

            var paramlist = DbExt.GetParams(parameters).ToArray();

            string[] sqlparams = paramlist.Select(param => param.Key).ToArray();

            string fields = string.Join(",", sqlparams);
            string values = sqlparams.Any() ? $"@{string.Join(",@", sqlparams)}" : string.Empty;

            string sql = $"update or insert into {table} ({fields}) values ({values})" + (matching.IsNullOrWhitespace() ? string.Empty : $" matching ({matching})");

            using (var command = new FbCommand(sql, trans.Connection, trans))
            {
                foreach (var param in paramlist)
                {
                    command.Parameters.Add($"@{param.Key}", param.Value ?? DBNull.Value);
                }

                command.ExecuteNonQuery();
            }
        }
Пример #10
0
 public static QueryResult RunSql(string sql, object[] args = null)
 {
     return(args == null?DbExt.QueryReader(TShock.DB, sql) : DbExt.QueryReader(TShock.DB, sql, args));
 }