More Execute instead of executeQuery and Fill instead of fillData for Database. calls.

This commit is contained in:
UnknownShadow200 2016-07-26 16:07:06 +10:00
parent 6e97d8a047
commit d30edf8df4
7 changed files with 22 additions and 53 deletions

View File

@ -56,7 +56,6 @@ namespace MCGalaxy.Commands {
} }
static void SetBotColor(Player p, PlayerBot pBot, string[] args) { static void SetBotColor(Player p, PlayerBot pBot, string[] args) {
ParameterisedQuery query = ParameterisedQuery.Create();
string color = args.Length == 2 ? "&1" : Colors.Parse(args[2]); string color = args.Length == 2 ? "&1" : Colors.Parse(args[2]);
if (color == "") { Player.Message(p, "There is no color \"" + args[2] + "\"."); return; } if (color == "") { Player.Message(p, "There is no color \"" + args[2] + "\"."); return; }
Player.GlobalMessage("Bot " + pBot.ColoredName + "'s %Scolor was changed to " + color + Colors.Name(color)); Player.GlobalMessage("Bot " + pBot.ColoredName + "'s %Scolor was changed to " + color + Colors.Name(color));
@ -68,23 +67,17 @@ namespace MCGalaxy.Commands {
} }
static void SetColor(Player p, Player who, string[] args) { static void SetColor(Player p, Player who, string[] args) {
ParameterisedQuery query = ParameterisedQuery.Create();
if (args.Length == 1) { if (args.Length == 1) {
Player.SendChatFrom(who, who.ColoredName + " %Shad their color removed.", false); Player.SendChatFrom(who, who.ColoredName + " %Shad their color removed.", false);
who.color = who.group.color; who.color = who.group.color;
Database.Execute("UPDATE Players SET color = '' WHERE name = @0", who.name);
query.AddParam("@Name", who.name);
Database.executeQuery(query, "UPDATE Players SET color = '' WHERE name = @Name");
} else { } else {
string color = Colors.Parse(args[1]); string color = Colors.Parse(args[1]);
if (color == "") { Player.Message(p, "There is no color \"" + args[1] + "\"."); return; } if (color == "") { Player.Message(p, "There is no color \"" + args[1] + "\"."); return; }
else if (color == who.color) { Player.Message(p, who.DisplayName + " already has that color."); return; } else if (color == who.color) { Player.Message(p, who.DisplayName + " already has that color."); return; }
Player.SendChatFrom(who, who.ColoredName + " %Shad their color changed to " + color + Colors.Name(color) + "%S.", false); Player.SendChatFrom(who, who.ColoredName + " %Shad their color changed to " + color + Colors.Name(color) + "%S.", false);
who.color = color; who.color = color;
Database.Execute("UPDATE Players SET color = @1 WHERE name = @0", who.name, color);
query.AddParam("@Color", color);
query.AddParam("@Name", who.name);
Database.executeQuery(query, "UPDATE Players SET color = @Color WHERE name = @Name");
} }
Entities.GlobalDespawn(who, true); Entities.GlobalDespawn(who, true);
Entities.GlobalSpawn(who, true); Entities.GlobalSpawn(who, true);

View File

@ -49,23 +49,17 @@ namespace MCGalaxy.Commands {
} }
static void SetTColor(Player p, Player who, string[] args) { static void SetTColor(Player p, Player who, string[] args) {
ParameterisedQuery query = ParameterisedQuery.Create();
if (args.Length == 1) { if (args.Length == 1) {
Player.SendChatFrom(who, who.ColoredName + " %Shad their title color removed.", false); Player.SendChatFrom(who, who.ColoredName + " %Shad their title color removed.", false);
who.titlecolor = ""; who.titlecolor = "";
Database.Execute("UPDATE Players SET title_color = '' WHERE Name = @0", who.name);
query.AddParam("@Name", who.name);
Database.executeQuery(query, "UPDATE Players SET title_color = '' WHERE Name = @Name");
} else { } else {
string color = Colors.Parse(args[1]); string color = Colors.Parse(args[1]);
if (color == "") { Player.Message(p, "There is no color \"" + args[1] + "\"."); return; } if (color == "") { Player.Message(p, "There is no color \"" + args[1] + "\"."); return; }
else if (color == who.titlecolor) { Player.Message(p, who.DisplayName + " already has that title color."); return; } else if (color == who.titlecolor) { Player.Message(p, who.DisplayName + " already has that title color."); return; }
Player.SendChatFrom(who, who.ColoredName + " %Shad their title color changed to " + color + Colors.Name(color) + "%S.", false); Player.SendChatFrom(who, who.ColoredName + " %Shad their title color changed to " + color + Colors.Name(color) + "%S.", false);
who.titlecolor = color; who.titlecolor = color;
Database.Execute("UPDATE Players SET title_color = @1 WHERE Name = @0", who.name, color);
query.AddParam("@Color", color);
query.AddParam("@Name", who.name);
Database.executeQuery(query, "UPDATE Players SET title_color = @Color WHERE Name = @Name");
} }
who.SetPrefix(); who.SetPrefix();
} }

View File

@ -51,20 +51,16 @@ namespace MCGalaxy.Commands {
static void SetTitle(Player p, Player who, string[] args) { static void SetTitle(Player p, Player who, string[] args) {
string title = args.Length > 1 ? args[1] : ""; string title = args.Length > 1 ? args[1] : "";
ParameterisedQuery query = ParameterisedQuery.Create();
if (title != "") if (title != "")
title = title.Replace("[", "").Replace("]", ""); title = title.Replace("[", "").Replace("]", "");
if (title.Length >= 20) { Player.Message(p, "Title must be under 20 letters."); return; } if (title.Length >= 20) { Player.Message(p, "Title must be under 20 letters."); return; }
if (title == "") { if (title == "") {
Player.SendChatFrom(who, who.FullName + " %Shad their title removed.", false); Player.SendChatFrom(who, who.FullName + " %Shad their title removed.", false);
query.AddParam("@Name", who.name); Database.Execute("UPDATE Players SET Title = '' WHERE Name = @0", who.name);
Database.executeQuery(query, "UPDATE Players SET Title = '' WHERE Name = @Name");
} else { } else {
Player.SendChatFrom(who, who.FullName + " %Swas given the title of &b[" + title + "%b]", false); Player.SendChatFrom(who, who.FullName + " %Swas given the title of &b[" + title + "%b]", false);
query.AddParam("@Title", title); Database.Execute("UPDATE Players SET Title = @1 WHERE Name = @0", who.name, title);
query.AddParam("@Name", who.name);
Database.executeQuery(query, "UPDATE Players SET Title = @Title WHERE Name = @Name");
} }
who.title = title; who.title = title;
who.SetPrefix(); who.SetPrefix();

View File

@ -176,13 +176,10 @@ namespace MCGalaxy.Commands {
} }
static void UpdateDB(Player p, string name, string type, string value, string column) { static void UpdateDB(Player p, string name, string type, string value, string column) {
ParameterisedQuery query = ParameterisedQuery.Create();
query.AddParam("@Name", name);
if (value != "") { if (value != "") {
query.AddParam("@ArgValue", value); Database.Execute("UPDATE Players SET " + column + "=@1 WHERE Name=@0", name, value);
Database.executeQuery(query, "UPDATE Players SET " + column + "=@ArgValue WHERE Name=@Name");
} else { } else {
Database.executeQuery(query, "UPDATE Players SET " + column + "='' WHERE Name=@Name"); Database.Execute("UPDATE Players SET " + column + "='' WHERE Name=@0", name);
} }
} }

View File

@ -58,10 +58,10 @@ namespace MCGalaxy {
//safe against SQL injections because foundLevel is being checked and, //safe against SQL injections because foundLevel is being checked and,
//newName is being split and partly checked on illegal characters reserved for Windows. //newName is being split and partly checked on illegal characters reserved for Windows.
if (Server.useMySQL) if (Server.useMySQL)
Database.Excecute(String.Format("RENAME TABLE `Block{0}` TO `Block{1}`, " + Database.Execute(String.Format("RENAME TABLE `Block{0}` TO `Block{1}`, " +
"`Portals{0}` TO `Portals{1}`, " + "`Portals{0}` TO `Portals{1}`, " +
"`Messages{0}` TO `Messages{1}`, " + "`Messages{0}` TO `Messages{1}`, " +
"`Zone{0}` TO `Zone{1}`", src, dst)); "`Zone{0}` TO `Zone{1}`", src, dst));
else { else {
using (BulkTransaction helper = SQLiteBulkTransaction.Create()) { // ensures that it's either all work, or none work. using (BulkTransaction helper = SQLiteBulkTransaction.Create()) { // ensures that it's either all work, or none work.
helper.Execute(String.Format("ALTER TABLE `Block{0}` RENAME TO `Block{1}`", src, dst)); helper.Execute(String.Format("ALTER TABLE `Block{0}` RENAME TO `Block{1}`", src, dst));

View File

@ -443,10 +443,7 @@ namespace MCGalaxy {
if (Server.verify) return Server.whiteList.Contains(name); if (Server.verify) return Server.whiteList.Contains(name);
// Verify names is off, check if the player is on the same IP. // Verify names is off, check if the player is on the same IP.
ParameterisedQuery query = ParameterisedQuery.Create(); return Server.whiteList.Contains(name) && PlayerInfo.FindAccounts(ip).Contains(name);
query.AddParam("@IP", ip);
using (DataTable ipQuery = Database.fillData(query, "SELECT Name FROM Players WHERE IP = @IP"))
return ipQuery.Rows.Contains(name) && Server.whiteList.Contains(name);
} }
void CompleteLoginProcess() { void CompleteLoginProcess() {
@ -489,9 +486,7 @@ namespace MCGalaxy {
//OpenClassic Client Check //OpenClassic Client Check
SendBlockchange(0, 0, 0, 0); SendBlockchange(0, 0, 0, 0);
ParameterisedQuery query = ParameterisedQuery.Create(); DataTable playerDb = Database.Fill("SELECT * FROM Players WHERE Name=@0", name);
query.AddParam("@Name", name);
DataTable playerDb = Database.fillData(query, "SELECT * FROM Players WHERE Name=@Name");
timeLogged = DateTime.Now; timeLogged = DateTime.Now;
lastLogin = DateTime.Now; lastLogin = DateTime.Now;

View File

@ -157,11 +157,9 @@ namespace MCGalaxy {
} }
public static List<string> FindAccounts(string ip) { public static List<string> FindAccounts(string ip) {
ParameterisedQuery query = ParameterisedQuery.Create(); DataTable clones = Database.Fill("SELECT Name FROM Players WHERE IP=@0", ip);
query.AddParam("@IP", ip);
DataTable clones = Database.fillData(query, "SELECT Name FROM Players WHERE IP=@IP");
List<string> alts = new List<string>(); List<string> alts = new List<string>();
foreach (DataRow row in clones.Rows) { foreach (DataRow row in clones.Rows) {
string name = row["Name"].ToString(); string name = row["Name"].ToString();
if (!alts.CaselessContains(name)) if (!alts.CaselessContains(name))
@ -191,21 +189,17 @@ namespace MCGalaxy {
static DataTable Query(string name, string selector) { static DataTable Query(string name, string selector) {
ParameterisedQuery query = ParameterisedQuery.Create();
query.AddParam("@Name", name);
string syntax = Server.useMySQL ? string syntax = Server.useMySQL ?
"SELECT " + selector + " FROM Players WHERE Name=@Name COLLATE utf8_general_ci" : "SELECT " + selector + " FROM Players WHERE Name=@0 COLLATE utf8_general_ci" :
"SELECT " + selector + " FROM Players WHERE Name=@Name COLLATE NOCASE"; "SELECT " + selector + " FROM Players WHERE Name=@0 COLLATE NOCASE";
return Database.fillData(query, syntax); return Database.Fill(syntax, name);
} }
static DataTable QueryMulti(string name, string selector) { static DataTable QueryMulti(string name, string selector) {
ParameterisedQuery query = ParameterisedQuery.Create();
query.AddParam("@Name", "%" + name + "%");
string syntax = Server.useMySQL ? string syntax = Server.useMySQL ?
"SELECT " + selector + " FROM Players WHERE Name LIKE @Name LIMIT 21" : "SELECT " + selector + " FROM Players WHERE Name LIKE @0 LIMIT 21" :
"SELECT " + selector + " FROM Players WHERE Name LIKE @Name LIMIT 21 COLLATE NOCASE"; "SELECT " + selector + " FROM Players WHERE Name LIKE @0 LIMIT 21 COLLATE NOCASE";
return Database.fillData(query, syntax); return Database.Fill(syntax, "%" + name + "%");
} }
static OfflinePlayer FillInfo(DataRow row, bool fullStats) { static OfflinePlayer FillInfo(DataRow row, bool fullStats) {