public void saveUser(BasePlayer player) { if (!playerList.ContainsKey(player.userID)) { Puts("Trying to save player, who haven't been loaded yet? Player name: " + player.displayName); return; } Dictionary <string, long> statsInit = getConnectedPlayerDetailsData(player.userID); string user = EncodeNonAsciiCharacters(player.displayName); //string user = player.displayName; string sqlText = "REPLACE INTO Donations (steam_id, user, amount, total_amount) " + "VALUES (@0, @1, @2, @3)"; if (usingMySQL()) { var sql = Core.Database.Sql.Builder.Append(sqlText, player.userID, //0 user, //1 statsInit["amount"], //2 statsInit["total_amount"]); //3 _mySql.Insert(sql, _mySqlConnection, list => { if (list == 0) // Save to DB failed. { Puts("OMG WE DIDN'T SAVED IT!: " + sql.SQL); } }); } }
/// <summary> /// A function to insert a player into the Mysql Database. /// </summary> /// <param name="player"></param> void InsertPlayer(BasePlayer player) { string ranks = string.Join(",", permission.GetUserGroups(player.IPlayer.Id)); string query = $"INSERT INTO {Config["Table"] as string} (UserID, Ranks) VALUES ({player.UserIDString}, \"{ranks}\")"; if (Debug) { Puts(query); } Sql command = Sql.Builder.Append(query); sqlLibrary.Insert(command, sqlConnection); }
private void PerformDatabaseInsert(string dbStatement, Action <int> callbackAction, Connection optionalConnection = null, params object[] sqlQueryArguments) { var sqlConnection = optionalConnection ?? GetSqlConnection(); var query = _mySql.NewSql().Append(dbStatement, sqlQueryArguments); _mySql.Insert(query, sqlConnection, callbackAction); CloseConnection(sqlConnection); }
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) { Puts("SQL connection is not open."); return; } Sql.Insert(Core.Database.Sql.Builder.Append($"CREATE TABLE IF NOT EXISTS {tablename} ( `UserID` VARCHAR(40) NOT NULL, `Name` VARCHAR(40) NOT NULL, `Kills` INT(11) NOT NULL, `Deaths` INT(11) NOT NULL, `GamesPlayed` INT(11) NOT NULL, `GamesWon` INT(11) NOT NULL, `GamesLost` INT(11) NOT NULL, `Score` INT(11) NOT NULL, `Rank` INT(11) NOT NULL, `FlagsCaptured` INT(11) NOT NULL, `ShotsFired` INT(11) NOT NULL, `ChoppersKilled` INT(11) NOT NULL, PRIMARY KEY (`UserID`) );"), Sql_conn); Puts("Creating or Updating EM Stats Table"); } catch (Exception e) { Puts("SQL Save failed."); } foreach (var c in data.stats) { Sql.Insert(Core.Database.Sql.Builder.Append($"INSERT INTO {tablename} ( `UserID`, `Name`, `Kills`, `Deaths`, `GamesPlayed`, `GamesWon`, `GamesLost`, `Score`, `Rank`, `FlagsCaptured`, `ShotsFired`, `ChoppersKilled`) VALUES ( @0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11) ON DUPLICATE KEY UPDATE UserID = @0, Name = @1, Kills = @2, Deaths = @3, GamesPlayed = @4, GamesWon = @5, GamesLost = @6, Score = @7, Rank = @8, FlagsCaptured = @9, ShotsFired = @10, ChoppersKilled = @11", c.Key, RemoveSurrogatePairs(c.Value.Name, ""), c.Value.Kills, c.Value.Deaths, c.Value.GamesPlayed, c.Value.GamesWon, c.Value.GamesLost, c.Value.Score, c.Value.Rank, c.Value.FlagsCaptured, c.Value.ShotsFired, c.Value.ChoppersKilled), Sql_conn); } }
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)); }); }
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 CreateNewColumn2(string column) { Sql.Insert(Core.Database.Sql.Builder.Append(string.Format("ALTER TABLE `playerdatabase` ADD `{0}` LONGTEXT", column)), Sql_conn); sqlColumns.Add(column); }
public void executeQuery(string query, params object[] data) { var sql = Sql.Builder.Append(query, data); sqlLibrary.Insert(sql, sqlConnection); }
public static void MInsert(Sql sql, Action <int> callback = null) { mysql.Insert(sql, mysqlConnection, callback); }