void LoadMySQL()
 {
     try
     {
         Sql_conn = Sql.OpenDb(sql_host, sql_port, sql_db, sql_user, sql_pass, this);
         if (Sql_conn == null || Sql_conn.Con == null)
         {
             FatalError("Couldn't open the SQLite PlayerDatabase: " + Sql_conn.Con.State.ToString());
             return;
         }
         Sql.Insert(Core.Database.Sql.Builder.Append("CREATE TABLE IF NOT EXISTS playerdatabase ( `id` int(11) NOT NULL, `userid` VARCHAR(17) NOT NULL );"), Sql_conn);
         Sql.Query(Core.Database.Sql.Builder.Append("desc playerdatabase;"), Sql_conn, list =>
         {
             if (list == null)
             {
                 FatalError("Couldn't get columns. Database might be corrupted.");
                 return;
             }
             foreach (var entry in list)
             {
                 sqlColumns.Add((string)entry["Field"]);
             }
         });
         Sql.Query(Core.Database.Sql.Builder.Append("SELECT userid from playerdatabase"), Sql_conn, list =>
         {
             if (list == null)
             {
                 return;
             }
             foreach (var entry in list)
             {
                 string steamid = (string)entry["userid"];
                 if (steamid != "0")
                 {
                     sqlData.Add(steamid, new Hash <string, string>());
                 }
             }
             LoadPlayers();
         });
     }
     catch (Exception e)
     {
         FatalError(e.Message);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Checks if a table exists, if not, let's create one.
        /// </summary>
        void TableCheck()
        {
            sqlConnection = sqlLibrary.OpenDb(
                Config["Ip"] as string,
                int.Parse(Config["Port"] as string),
                Config["Database"] as string,
                Config["Username"] as string,
                Config["Password"] as string,
                this);
            // SQL syntax for table creation.
            string tableQuery = $"CREATE TABLE IF NOT EXISTS {Config["Table"] as string}(UserID varchar(255), Ranks TEXT)";

            // Create SQL command.
            Sql command = Sql.Builder.Append(tableQuery);

            // Don't need to do anything with the call back, and query the database.
            sqlLibrary.Query(command, sqlConnection, callback => { });
        }
Beispiel #3
0
        private void PerformDatabaseQuery(string dbStatement, Action <List <Dictionary <string, object> > > callbackAction,
                                          Connection optionalConnection = null, params object[] sqlQueryArguments)
        {
            var sqlConnection = optionalConnection ?? GetSqlConnection();

            var query = _mySql.NewSql().Append(dbStatement, sqlQueryArguments);

            _mySql.Query(query, sqlConnection, callbackAction);

            CloseConnection(sqlConnection);
        }
Beispiel #4
0
    void OnEntityDeath(EntityDeathEvent Event)
    {
      if (!Event.Entity.IsPlayer || !Event.KillingDamage.DamageSource.IsPlayer) return;

      string killer = Event.KillingDamage.DamageSource.Owner.Id;
      string verifyQuery = $"SELECT victim FROM kills WHERE killer={killer} AND victim={victim}";

      sqlLibrary.Query(verifyQuery, sqlConnection, list =>
      {
          if (list == null)
          {
            // Reward Player
            sqlLibrary.Query(verifyQuery, sqlConnection, list =>
            {

            }
          }
          else
          {
            // Player already killed.
          }
      });
    }
        public void loadUser(BasePlayer player)
        {
            packetSent = false;
            Dictionary <string, long> statsInit = new Dictionary <string, long>();

            statsInit.Add("amount", 0);
            statsInit.Add("total_amount", 0);

            if (usingMySQL())
            {
                var sql = Core.Database.Sql.Builder.Append("SELECT * FROM Donations WHERE steam_id = @0", player.userID);
                _mySql.Query(sql, _mySqlConnection, list =>
                {
                    initPlayer(player, statsInit, list);
                });
            }
            packetSent = true;
        }
Beispiel #6
0
        private void OnServerInitialized()
        {
            _mySqlConnection = _mySql.OpenDb(Config["host"].ToString(), Convert.ToInt32(Config["port"]), Config["database"].ToString(), Config["username"].ToString(), Config["password"].ToString(), this);
            var sql = Core.Database.Sql.Builder.Append(CreateQuery);

            _mySql.Insert(sql, _mySqlConnection);
            sql = Core.Database.Sql.Builder.Append(SelectData);
            _mySql.Query(sql, _mySqlConnection, list =>
            {
                if (list.Count > 0)
                {
                    foreach (var entry in list)
                    {
                        whitelistedPlayers.Add(entry["steamid"].ToString());
                    }
                }
                PrintWarning("Updated whitelisted users list, checking if players are whitelisted");
            });
        }
        void ChatCommand(IPlayer player, string command, string[] args)
        {
            var    playerEmail = string.Join("", args).Replace("@", "@@");
            string packageClaimed;

            connection = mySql.OpenDb(config.DatabaseHost, config.DatabasePort, config.DatabaseName, config.DatabaseUser, config.DatabasePassword, this);
            var sql = Sql.Builder.Append($"call {config.DatabaseName}.claim_donation('" + playerEmail + "');");

            mySql.Query(sql, connection, list =>
            {
                var sb = new StringBuilder();
                foreach (var entry in list)
                {
                    sb.AppendFormat("{0}", entry["item_name"]);
                    sb.AppendLine();
                }

                packageClaimed = sb.ToString();
                var packageKey = GetPackageKey(packageClaimed, config.Packages);

                if (packageClaimed.Length < 3)
                {
                    player.Reply(Lang("NoUnclaimed", player.Id, playerEmail));
                }
                else
                {
                    List <string> consoleCommands;
                    if (config.Packages.TryGetValue(packageKey, out consoleCommands))
                    {
                        RunConsoleCommands(consoleCommands, player.Id);
                        player.Reply(Lang("Claimed", player.Id, packageClaimed));
                        Puts($"{player} has claimed donation package {packageClaimed}");
                    }
                    else
                    {
                        player.Reply(Lang("NoPackage", player.Id, packageClaimed));
                        Puts($"{player} tried to claim {packageClaimed}, but the package could not be found in the config!");
                    }
                }
            });
        }
Beispiel #8
0
        private void OnUserConnected(IPlayer player)
        {
            string PlayerId = player.Id;
            string Name     = player.Name;
            string amount   = "0";

            var sql = Core.Database.Sql.Builder.Append(SelectSteam64, PlayerId);

            _mySql.Query(sql, _mySqlConnection, list =>
            {
                // if the database already contains the user
                if (list.Count > 0)
                {
                    // if the local data file doesn't contain the user
                    if (!storedData.PlayerAmounts.ContainsKey(PlayerId))
                    {
                        Puts(string.Format("User {0} ({1}) exists in the database but not in the local data file.", Name, PlayerId));

                        // get the players currency from the database
                        sql = Core.Database.Sql.Builder.Append(SelectAmount, PlayerId);

                        _mySql.Query(sql, _mySqlConnection, list1 =>
                        {
                            amount = list1[0]["amount"].ToString();
                        });

                        // add the player to the local data file
                        timer.Once(2f, () =>
                        {
                            storedData.PlayerAmounts.Add(PlayerId, amount);
                            Interface.Oxide.DataFileSystem.WriteObject("VorEconomy", storedData);

                            Puts(string.Format("User {0} ({1}) was added to the local data file with the amount of: {2}", Name, PlayerId, amount));
                        });
                    }
                    return;
                }

                // if the database doesn't contain the user, add them with a currency value of 0
                storedData.PlayerAmounts.Add(PlayerId, "0");
                Interface.Oxide.DataFileSystem.WriteObject("VorEconomy", storedData);

                sql = Core.Database.Sql.Builder.Append(InsertPlayerData, PlayerId, 0);
                _mySql.Insert(sql, _mySqlConnection);
                Puts(string.Format("User did not exist in the database. Successfully added {1} ({2}) with an amount of: 0", Name, PlayerId));
            });
        }
 public static void MQuery(Sql sql, Action <List <Dictionary <string, object> > > callback)
 {
     mysql.Query(sql, mysqlConnection, callback);
 }