private void Init() { #if !RUST throw new NotSupportedException("This plugin does not support this game"); #endif LoadConfigVariables(); sqlConnection = sqlLibrary.OpenDb(conf.MySQL.host, conf.MySQL.port, conf.MySQL.db, conf.MySQL.username, conf.MySQL.password, this); executeQuery($@"CREATE TABLE IF NOT EXISTS {conf.MySQL.table} (player_id BIGINT(20) NOT NULL, WCL INT(11) NULL, WCP INT(11) NULL, ML INT(11) NULL, MP INT(11) NULL, SL INT(11) NULL, SP INT(11) NULL, AL INT(11) NULL, AP INT(11) NULL, CL INT(11) NULL, CP INT(11) NULL, LD INT(11) NULL, LLD INT(11) NULL, XPM INT(11) NULL, CUI BOOLEAN NULL, ONOFF BOOLEAN NULL, PRIMARY KEY (`player_id`), UNIQUE (`player_id`) ) ENGINE=InnoDB;" ); }
void Init() { sqlLibrary = Interface.Oxide.GetLibrary<Core.MySql.Libraries.MySql>(); sqlConnection = sqlLibrary.OpenDb("localhost", 3306, "umod", "username", "password", this); CurrencyAmountPerKill = 50; }
private void OnServerInitialized() { // Open a connection with the database _mySqlConnection = _mySql.OpenDb(Config["DatabaseHostName"].ToString(), int.Parse(Config["DatabasePort"].ToString()), "onrust1_economy", Config["DatabaseUsername"].ToString(), Config["DatabasePassword"].ToString(), this); // Queries the database every X seconds and updates the local data file accordingly timer.Repeat(float.Parse(Config["UpdateDataTimer"].ToString()), 0, () => { UpdateDataFile(); }); }
private void StartConnection() { if (usingMySQL() && _mySqlConnection == null) { _mySqlConnection = _mySql.OpenDb( Address, Port, dbName, User, Password, this); Puts("Connection opened.(MySQL)"); } }
// MySQL Connection private void StartConnection() { try { Puts("Opening connection."); if (usingMySQL() && _mySqlConnection == null) { _mySqlConnection = _mySql.OpenDb(Config["Host"].ToString(), Convert.ToInt32(Config["Port"]), Config["Database"].ToString(), Config["Username"].ToString(), Config["Password"].ToString(), this); Puts("Connection opened."); } } catch (Exception ex) { Puts(ex.Message); } }
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); } }
/// <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 => { }); }
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!"); } } }); }
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); } }
void MySQLSetup() { Puts("Connecting to the database..."); try { mysqlConnection = mysql.OpenDb(MYSQL_HOST, 3306, MYSQL_DB, MYSQL_USER, MYSQL_PASS, this); if (mysqlConnection == null && mysqlConnection.Con == null) { Puts("Cannot connect to the server"); return; } MNonQuery(MBuild("SELECT 1=1;")); } catch (Exception e) { Puts($"Exception {e.Message}"); return; } Puts("Connection successfull"); }
private Connection GetSqlConnection() { return(_mySql.OpenDb(Settings.Instance.DatabaseServerIP, Settings.Instance.DatabaseServerPort, Settings.Instance.DatabaseName, Settings.Instance.DatabaseUserName, Settings.Instance.DatabasePassword, this)); }