Now with 4.256% less redundant looking up of DataRows.

This commit is contained in:
UnknownShadow200 2016-04-06 18:52:09 +10:00
parent 4be21585a9
commit 41c10d2b16
4 changed files with 38 additions and 31 deletions

View File

@ -65,16 +65,16 @@ namespace MCGalaxy.Commands
for (int i = 0; i < Blocks.Rows.Count; i++) for (int i = 0; i < Blocks.Rows.Count; i++)
{ {
foundOne = true; foundOne = true;
Username = Blocks.Rows[i]["Username"].ToString(); DataRow row = Blocks.Rows[i];
TimePerformed = DateTime.Parse(Blocks.Rows[i]["TimePerformed"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); Username = row["Username"].ToString().Trim();
//Server.s.Log(Blocks.Rows[i]["Type"].ToString()); TimePerformed = DateTime.Parse(row["TimePerformed"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
BlockUsed = Block.Name(Convert.ToByte(Blocks.Rows[i]["Type"])).ToString(); BlockUsed = Block.Name(Convert.ToByte(row["Type"])).ToString();
Deleted = Convert.ToBoolean(Blocks.Rows[i]["Deleted"]); Deleted = Convert.ToBoolean(row["Deleted"]);
if (!Deleted) if (!Deleted)
Player.SendMessage(p, "&3Created by " + Server.FindColor(Username.Trim()) + Username.Trim() + "%S, using &3" + BlockUsed); Player.SendMessage(p, "&3Created by " + Server.FindColor(Username) + Username + "%S, using &3" + BlockUsed);
else else
Player.SendMessage(p, "&4Destroyed by " + Server.FindColor(Username.Trim()) + Username.Trim()+ "%S, using &3" + BlockUsed); Player.SendMessage(p, "&4Destroyed by " + Server.FindColor(Username) + Username + "%S, using &3" + BlockUsed);
Player.SendMessage(p, "Date and time modified: &2" + TimePerformed); Player.SendMessage(p, "Date and time modified: &2" + TimePerformed);
} }

View File

@ -112,12 +112,16 @@ namespace MCGalaxy.Commands {
//safe against SQL injections because no user input is given here //safe against SQL injections because no user input is given here
using (DataTable Messages = Database.fillData("SELECT * FROM `Messages" + p.level.name + "`")) { using (DataTable Messages = Database.fillData("SELECT * FROM `Messages" + p.level.name + "`")) {
if (p.showMBs) { if (p.showMBs) {
for (int i = 0; i < Messages.Rows.Count; i++) for (int i = 0; i < Messages.Rows.Count; i++) {
p.SendBlockchange(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString()), Block.MsgWhite); DataRow row = Messages.Rows[i];
p.SendBlockchange(ushort.Parse(row["X"].ToString()), ushort.Parse(row["Y"].ToString()), ushort.Parse(row["Z"].ToString()), Block.MsgWhite);
}
Player.SendMessage(p, "Now showing &a" + Messages.Rows.Count + " %SMBs."); Player.SendMessage(p, "Now showing &a" + Messages.Rows.Count + " %SMBs.");
} else { } else {
for (int i = 0; i < Messages.Rows.Count; i++) for (int i = 0; i < Messages.Rows.Count; i++) {
p.SendBlockchange(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString()), p.level.GetTile(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString()))); DataRow row = Messages.Rows[i];
p.RevertBlock(ushort.Parse(row["X"].ToString()), ushort.Parse(row["Y"].ToString()), ushort.Parse(row["Z"].ToString()));
}
Player.SendMessage(p, "Now hiding MBs."); Player.SendMessage(p, "Now hiding MBs.");
} }
} }

View File

@ -140,7 +140,7 @@ namespace MCGalaxy.Commands {
} else { } else {
for (int i = 0; i < Portals.Rows.Count; i++) { for (int i = 0; i < Portals.Rows.Count; i++) {
DataRow row = Portals.Rows[i]; DataRow row = Portals.Rows[i];
if (Portals.Rows[i]["ExitMap"].ToString() == p.level.name) if (row["ExitMap"].ToString() == p.level.name)
p.RevertBlock(U16(row["ExitX"]), U16(row["ExitY"]), U16(row["ExitZ"])); p.RevertBlock(U16(row["ExitX"]), U16(row["ExitY"]), U16(row["ExitZ"]));
p.RevertBlock(U16(row["EntryX"]), U16(row["EntryY"]), U16(row["EntryZ"])); p.RevertBlock(U16(row["EntryX"]), U16(row["EntryY"]), U16(row["EntryZ"]));
} }

View File

@ -609,13 +609,14 @@ namespace MCGalaxy
Zone Zn; Zone Zn;
for (int i = 0; i < ZoneDB.Rows.Count; ++i) for (int i = 0; i < ZoneDB.Rows.Count; ++i)
{ {
Zn.smallX = ushort.Parse(ZoneDB.Rows[i]["SmallX"].ToString()); DataRow row = ZoneDB.Rows[i];
Zn.smallY = ushort.Parse(ZoneDB.Rows[i]["SmallY"].ToString()); Zn.smallX = ushort.Parse(row["SmallX"].ToString());
Zn.smallZ = ushort.Parse(ZoneDB.Rows[i]["SmallZ"].ToString()); Zn.smallY = ushort.Parse(row["SmallY"].ToString());
Zn.bigX = ushort.Parse(ZoneDB.Rows[i]["BigX"].ToString()); Zn.smallZ = ushort.Parse(row["SmallZ"].ToString());
Zn.bigY = ushort.Parse(ZoneDB.Rows[i]["BigY"].ToString()); Zn.bigX = ushort.Parse(row["BigX"].ToString());
Zn.bigZ = ushort.Parse(ZoneDB.Rows[i]["BigZ"].ToString()); Zn.bigY = ushort.Parse(row["BigY"].ToString());
Zn.Owner = ZoneDB.Rows[i]["Owner"].ToString(); Zn.bigZ = ushort.Parse(row["BigZ"].ToString());
Zn.Owner = row["Owner"].ToString();
level.ZoneList.Add(Zn); level.ZoneList.Add(Zn);
} }
} }
@ -632,37 +633,39 @@ namespace MCGalaxy
// level.StartPhysics(); // level.StartPhysics();
//}; //};
//level.physChecker.Start(); //level.physChecker.Start();
//level.season = new SeasonsCore(level);
try try
{ {
DataTable foundDB = Database.fillData("SELECT * FROM `Portals" + givenName + "`"); DataTable foundDB = Database.fillData("SELECT * FROM `Portals" + givenName + "`");
for (int i = 0; i < foundDB.Rows.Count; ++i) for (int i = 0; i < foundDB.Rows.Count; ++i)
{ {
DataRow row = foundDB.Rows[i];
if ( if (
!Block.portal(level.GetTile(ushort.Parse(foundDB.Rows[i]["EntryX"].ToString()), !Block.portal(level.GetTile(ushort.Parse(row["EntryX"].ToString()),
ushort.Parse(foundDB.Rows[i]["EntryY"].ToString()), ushort.Parse(row["EntryY"].ToString()),
ushort.Parse(foundDB.Rows[i]["EntryZ"].ToString())))) ushort.Parse(row["EntryZ"].ToString()))))
{ {
Database.executeQuery("DELETE FROM `Portals" + givenName + "` WHERE EntryX=" + Database.executeQuery("DELETE FROM `Portals" + givenName + "` WHERE EntryX=" +
foundDB.Rows[i]["EntryX"] + " AND EntryY=" + row["EntryX"] + " AND EntryY=" +
foundDB.Rows[i]["EntryY"] + " AND EntryZ=" + row["EntryY"] + " AND EntryZ=" +
foundDB.Rows[i]["EntryZ"]); row["EntryZ"]);
} }
} }
foundDB = Database.fillData("SELECT * FROM `Messages" + givenName + "`"); foundDB = Database.fillData("SELECT * FROM `Messages" + givenName + "`");
for (int i = 0; i < foundDB.Rows.Count; ++i) for (int i = 0; i < foundDB.Rows.Count; ++i)
{ {
DataRow row = foundDB.Rows[i];
if ( if (
!Block.mb(level.GetTile(ushort.Parse(foundDB.Rows[i]["X"].ToString()), !Block.mb(level.GetTile(ushort.Parse(row["X"].ToString()),
ushort.Parse(foundDB.Rows[i]["Y"].ToString()), ushort.Parse(row["Y"].ToString()),
ushort.Parse(foundDB.Rows[i]["Z"].ToString())))) ushort.Parse(row["Z"].ToString()))))
{ {
//givenName is safe against SQL injections, it gets checked in CmdLoad.cs //givenName is safe against SQL injections, it gets checked in CmdLoad.cs
Database.executeQuery("DELETE FROM `Messages" + givenName + "` WHERE X=" + Database.executeQuery("DELETE FROM `Messages" + givenName + "` WHERE X=" +
foundDB.Rows[i]["X"] + " AND Y=" + foundDB.Rows[i]["Y"] + row["X"] + " AND Y=" + row["Y"] +
" AND Z=" + foundDB.Rows[i]["Z"]); " AND Z=" + row["Z"]);
} }
} }
foundDB.Dispose(); foundDB.Dispose();