public bool CheckWhitelistStaus(string steamHex, WhitelistServer serverType) { using (var conn = new MySqlConnection(Settings.getSettings().MySQLString)) { conn.OpenAsync(); var cmd = new MySqlCommand("SELECT * FROM whitelisted WHERE steamHex=@steamHex", conn); cmd.Parameters.AddWithValue("@steamHex", steamHex); using (var reader = cmd.ExecuteReader()) while (reader.Read()) { if (serverType.Equals(WhitelistServer.Production) && reader.GetBoolean(3)) { return(true); } if (serverType.Equals(WhitelistServer.Development) && reader.GetBoolean(4)) { return(true); } } } return(false); }
public async Task RemoveWhitelistStatus(SocketUser socketUser, WhitelistServer server) { switch (server) { case WhitelistServer.Production: { using (var conn = new MySqlConnection(Settings.getSettings().MySQLString)) { await conn.OpenAsync(); var cmd = new MySqlCommand("UPDATE whitelisted SET userName=@userName, production=@production WHERE discordId=@discordId", conn); cmd.Parameters.AddWithValue("@discordId", socketUser.Id); cmd.Parameters.AddWithValue("@userName", socketUser.Username); cmd.Parameters.AddWithValue("@production", false); cmd.ExecuteNonQueryAsync(); } break; } case WhitelistServer.Development: { using (var conn = new MySqlConnection(Settings.getSettings().MySQLString)) { await conn.OpenAsync(); var cmd = new MySqlCommand("UPDATE whitelisted SET userName=@userName, development=@development WHERE discordId=@discordId", conn); cmd.Parameters.AddWithValue("@discordId", socketUser.Id); cmd.Parameters.AddWithValue("@userName", socketUser.Username); cmd.Parameters.AddWithValue("@development", false); cmd.ExecuteNonQueryAsync(); } break; } } }
public async Task UpdateWhitelistStatus(SocketUser socketUser, string steamHex, WhitelistServer server, bool status) { if (IsSteamHexInDB(steamHex)) { switch (server) { case WhitelistServer.Production: { using (var conn = new MySqlConnection(Settings.getSettings().MySQLString)) { await conn.OpenAsync(); var cmd = new MySqlCommand("UPDATE whitelisted SET userName=@userName, steamHex=@steamHex, production=@production WHERE steamHex=@steamHex", conn); cmd.Parameters.AddWithValue("@discordId", socketUser.Id); cmd.Parameters.AddWithValue("@userName", socketUser.Username); cmd.Parameters.AddWithValue("@steamHex", steamHex); cmd.Parameters.AddWithValue("@production", status); cmd.ExecuteNonQueryAsync(); } break; } case WhitelistServer.Development: { using (var conn = new MySqlConnection(Settings.getSettings().MySQLString)) { await conn.OpenAsync(); var cmd = new MySqlCommand("UPDATE whitelisted SET userName=@userName, steamHex=@steamHex, development=@development WHERE steamHex=@steamHex", conn); cmd.Parameters.AddWithValue("@discordId", socketUser.Id); cmd.Parameters.AddWithValue("@userName", socketUser.Username); cmd.Parameters.AddWithValue("@steamHex", steamHex); cmd.Parameters.AddWithValue("@development", status); cmd.ExecuteNonQueryAsync(); } break; } } } else { switch (server) { case WhitelistServer.Production: { using (var conn = new MySqlConnection(Settings.getSettings().MySQLString)) { await conn.OpenAsync(); var cmd = new MySqlCommand("INSERT INTO whitelisted (discordId, userName, steamHex, production, development) VALUES (@discordId, @userName, @steamHex, @production, @development)", conn); cmd.Parameters.AddWithValue("@discordId", socketUser.Id); cmd.Parameters.AddWithValue("@userName", socketUser.Username); cmd.Parameters.AddWithValue("@steamHex", steamHex); cmd.Parameters.AddWithValue("@production", status); cmd.Parameters.AddWithValue("@development", false); cmd.ExecuteNonQueryAsync(); } break; } case WhitelistServer.Development: { using (var conn = new MySqlConnection(Settings.getSettings().MySQLString)) { await conn.OpenAsync(); var cmd = new MySqlCommand("INSERT INTO whitelisted (discordId, userName, steamHex, production, development) VALUES (@discordId, @userName, @steamHex, @production, @development)", conn); cmd.Parameters.AddWithValue("@discordId", socketUser.Id); cmd.Parameters.AddWithValue("@userName", socketUser.Username); cmd.Parameters.AddWithValue("@steamHex", steamHex); cmd.Parameters.AddWithValue("@production", false); cmd.Parameters.AddWithValue("@development", status); cmd.ExecuteNonQueryAsync(); } break; } } } }