예제 #1
1
파일: Sql.cs 프로젝트: 906507516/Oxide
        private void Build(StringBuilder sb, List<object> args, Sql lhs)
        {
            if (!String.IsNullOrEmpty(_sql))
            {
                // Add SQL to the string
                if (sb.Length > 0)
                {
                    sb.Append("\n");
                }

                var sql = ProcessParams(_sql, _args, args);

                if (Is(lhs, "WHERE ") && Is(this, "WHERE "))
                    sql = "AND " + sql.Substring(6);
                if (Is(lhs, "ORDER BY ") && Is(this, "ORDER BY "))
                    sql = ", " + sql.Substring(9);

                sb.Append(sql);
            }

            // Now do rhs
            _rhs?.Build(sb, args, this);
        }
예제 #2
0
        object GetName(string userid)
        {
            if (useSQLITE)
            {
                string query = string.Format("SELECT name FROM {0} WHERE steamid = {1} LIMIT 1", "playerdatabase", userid);
                sqlite.Append(query);
                IEnumerable <Dictionary <string, object> > res = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Query(sqlite, sqconnection);
                foreach (Dictionary <string, object> obj in res)
                {
                    foreach (object value in obj.Values)
                    {
                        if (value != null || value != "")
                        {
                            return(value.ToString());
                        }
                    }
                }
            }
            else if (useMysql)
            {
                string query = string.Format("SELECT name FROM `{0}` WHERE `steamid` = '{1}' LIMIT 1", mysqlTable, userid);
                sql = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").NewSql();
                sql.Append(query);
                IEnumerable <Dictionary <string, object> > res = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").Query(sql, connection);
                foreach (Dictionary <string, object> obj in res)
                {
                    foreach (object value in obj.Values)
                    {
                        if (value != null || value != "")
                        {
                            return(value.ToString());
                        }
                    }
                }
            }
            else
            {
                if (Data[userid] != null && ((Dictionary <string, object>)Data[userid])["name"] != null)
                {
                    return(((Dictionary <string, object>)Data[userid])["name"]);
                }
            }
            if (steamapikey.Length < 5)
            {
                return(null);
            }
            var url = string.Format("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={0}&steamids={1}", steamapikey, userid);

            Interface.GetMod().GetLibrary <WebRequests>("WebRequests").EnqueueGet(url, (code, response) =>
            {
                var tempnewname = CheckResponse(code, response);
                if (tempnewname != null)
                {
                    SetPlayerData(userid, "name", tempnewname.ToString());
                }
            }
                                                                                  , this);
            return(null);
        }
예제 #3
0
파일: Sql.cs 프로젝트: 906507516/Oxide
        public Sql Append(Sql sql)
        {
            if (_rhs != null)
                _rhs.Append(sql);
            else
                _rhs = sql;

            return this;
        }
예제 #4
0
        string[] FindAllPlayers(string name)
        {
            var returnlist = new List <string>();

            if (useSQLITE)
            {
                string query = string.Format("SELECT steamid FROM `{0}` WHERE `name` LIKE '%{1}%'", "playerdatabase", name);
                sqlite.Append(query);
                IEnumerable <Dictionary <string, object> > res = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Query(sqlite, sqconnection);
                foreach (Dictionary <string, object> obj in res)
                {
                    foreach (object value in obj.Values)
                    {
                        returnlist.Add(value.ToString());
                    }
                }
            }
            else if (useMysql)
            {
                string query = string.Format("SELECT steamid FROM `{0}` WHERE `name` LIKE '%{1}%'", mysqlTable, name);
                sql = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").NewSql();
                sql.Append(query);
                IEnumerable <Dictionary <string, object> > res = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").Query(sql, connection);
                foreach (Dictionary <string, object> obj in res)
                {
                    foreach (object value in obj.Values)
                    {
                        returnlist.Add(value.ToString());
                    }
                }
            }
            else
            {
                name = name.ToLower();
                Dictionary <string, object> currenttable;
                foreach (KeyValuePair <string, object> pair in Data)
                {
                    currenttable = pair.Value as Dictionary <string, object>;
                    if (currenttable.ContainsKey("name"))
                    {
                        if (currenttable["name"].ToString().ToLower().Contains(name))
                        {
                            returnlist.Add(pair.Key);
                        }
                    }
                }
            }
            return(returnlist.ToArray());
        }
예제 #5
0
 object GetPlayerData(string userid, string key)
 {
     if (key == "name")
     {
         return(GetName(userid));
     }
     if (useSQLITE)
     {
         string query = string.Format("SELECT {2} FROM {0} WHERE steamid = {1} LIMIT 1", "playerdatabase", userid, key);
         sqlite.Append(query);
         IEnumerable <Dictionary <string, object> > res = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Query(sqlite, sqconnection);
         foreach (Dictionary <string, object> obj in res)
         {
             foreach (object value in obj.Values)
             {
                 return(value.ToString());
             }
         }
     }
     else if (useMysql)
     {
         string query = string.Format("SELECT {2} FROM `{0}` WHERE `steamid` = '{1}' LIMIT 1", mysqlTable, userid, key);
         sql = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").NewSql();
         sql.Append(query);
         IEnumerable <Dictionary <string, object> > res = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").Query(sql, connection);
         foreach (Dictionary <string, object> obj in res)
         {
             foreach (object value in obj.Values)
             {
                 return(value.ToString());
             }
         }
     }
     else
     {
         if (Data[userid] == null)
         {
             return(null);
         }
         if (!((Dictionary <string, object>)Data[userid]).ContainsKey(key))
         {
             return(null);
         }
         return(((Dictionary <string, object>)Data[userid])[key]);
     }
     return(null);
 }
예제 #6
0
        void Loaded()
        {
            if (!permission.PermissionExists("admin"))
            {
                permission.RegisterPermission("admin", this);
            }
            LoadData();
            if (useSQLITE)
            {
                sqconnection = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").OpenDb("PlayerDatabaseSQL");
                sqlite       = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").NewSql();
                sqlite.Append("create table if not exists playerdatabase (name text, steamid text)");
                Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Query(sqlite, sqconnection);
                sqlite.Append("PRAGMA encoding = 'UTF - 8'");
                Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Query(sqlite, sqconnection);
                sqlite.Append("SELECT steamid FROM playerdatabase");

                IEnumerable <Dictionary <string, object> > res = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Query(sqlite, sqconnection);

                foreach (Dictionary <string, object> obj in res)
                {
                    foreach (object key in obj.Values)
                    {
                        AvaibleUserID.Add(key.ToString());
                    }
                }
                sqlite.Append("SELECT * FROM playerdatabase");
                res = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Query(sqlite, sqconnection);

                foreach (Dictionary <string, object> obj in res)
                {
                    Debug.Log(obj.ToString());
                    foreach (string key in obj.Keys)
                    {
                        AvaibleKeys.Add(key.ToString());
                    }
                    break;
                }
                if (AvaibleKeys.Count == 0)
                {
                    AvaibleKeys.Add("name");
                    AvaibleKeys.Add("steamid");
                }
            }
            else if (useMysql)
            {
                connection = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").OpenDb(mysqlHost, mysqlPort, mysqlDatabase, mysqlUsername, mysqlPass);
                sql        = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").NewSql();
                sql.Append("SELECT steamid FROM `" + mysqlTable + "`");
                IEnumerable <Dictionary <string, object> > res = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").Query(sql, connection);
                foreach (Dictionary <string, object> obj in res)
                {
                    foreach (object key in obj.Values)
                    {
                        AvaibleUserID.Add(key.ToString());
                    }
                }
                sql = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").NewSql();
                sql.Append("SELECT * FROM `" + mysqlTable + "`");
                res = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").Query(sql, connection);
                foreach (Dictionary <string, object> obj in res)
                {
                    foreach (string key in obj.Keys)
                    {
                        AvaibleKeys.Add(key.ToString());
                    }
                    break;
                }
                if (AvaibleKeys.Count == 0)
                {
                    AvaibleKeys.Add("name");
                    AvaibleKeys.Add("steamid");
                }
            }
        }
예제 #7
0
        void SetPlayerData(string userid, string key, object value)
        {
            if (useSQLITE)
            {
                string query = string.Empty;
                if (!AvaibleKeys.Contains(key))
                {
                    query = string.Format("ALTER TABLE {0} ADD {1} VARCHAR(255);", "playerdatabase", key);
                    sqlite.Append(query);
                    Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Query(sqlite, sqconnection);
                    AvaibleKeys.Add(key);
                }

                if (!AvaibleUserID.Contains(userid))
                {
                    query = string.Format("INSERT INTO {0} (steamid) VALUES ('{1}');", "playerdatabase", userid);
                    sqlite.Append(query);
                    var test2 = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Update(sqlite, sqconnection);
                    Debug.Log(test2.ToString());
                    AvaibleUserID.Add(userid);
                }

                query = string.Format("UPDATE {0} SET {2} = '{3}' WHERE steamid = '{1}';", "playerdatabase", userid, key, value.ToString());
                sqlite.Append(query);
                var test = Interface.Oxide.GetLibrary <Ext.SQLite.Libraries.SQLite>("SQLite").Update(sqlite, sqconnection);
                Debug.Log(test.ToString());
            }
            else if (useMysql)
            {
                string query = string.Empty;
                if (!AvaibleKeys.Contains(key))
                {
                    query = string.Format("ALTER TABLE `{0}` ADD `{1}` VARCHAR(255) NOT NULL;", mysqlTable, key);
                    sql   = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").NewSql();
                    sql.Append(query);
                    Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").Query(sql, connection);
                    AvaibleKeys.Add(key);
                }

                if (!AvaibleUserID.Contains(userid))
                {
                    query = string.Format("INSERT INTO `{0}` (`steamid`) VALUES('{1}');", mysqlTable, userid);
                    sql   = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").NewSql();
                    sql.Append(query);
                    Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").Query(sql, connection);
                    AvaibleUserID.Add(userid);
                }

                query = string.Format("UPDATE `{0}` SET `{2}` = '{3}' WHERE `{0}`.`steamid` = {1};", mysqlTable, userid, key, value.ToString());
                sql   = Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").NewSql();
                sql.Append(query);

                Interface.Oxide.GetLibrary <Ext.MySql.Libraries.MySql>("MySql").Query(sql, connection);
            }
            else
            {
                if (Data[userid] == null)
                {
                    Data[userid] = new Dictionary <string, object>();
                }
                if (!((Dictionary <string, object>)Data[userid]).ContainsKey(key))
                {
                    ((Dictionary <string, object>)Data[userid]).Add(key, value);
                }
                else
                {
                    ((Dictionary <string, object>)Data[userid])[key] = value;
                }
            }
        }
예제 #8
0
파일: Sql.cs 프로젝트: 906507516/Oxide
 private static bool Is(Sql sql, string sqltype)
 {
     return sql?._sql != null && sql._sql.StartsWith(sqltype, StringComparison.InvariantCultureIgnoreCase);
 }
예제 #9
0
파일: Sql.cs 프로젝트: 906507516/Oxide
 public SqlJoinClause(Sql sql)
 {
     _sql = sql;
 }