From 41c10d2b16c90be12a912d2f4f70a31ae2ec8962 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 6 Apr 2016 18:52:09 +1000 Subject: [PATCH] Now with 4.256% less redundant looking up of DataRows. --- Commands/Information/CmdAbout.cs | 14 +++++----- Commands/building/CmdMessageBlock.cs | 12 +++++--- Commands/building/CmdPortal.cs | 2 +- Levels/Level.cs | 41 +++++++++++++++------------- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/Commands/Information/CmdAbout.cs b/Commands/Information/CmdAbout.cs index 8e1a8f24e..afeee68b6 100644 --- a/Commands/Information/CmdAbout.cs +++ b/Commands/Information/CmdAbout.cs @@ -65,16 +65,16 @@ namespace MCGalaxy.Commands for (int i = 0; i < Blocks.Rows.Count; i++) { foundOne = true; - Username = Blocks.Rows[i]["Username"].ToString(); - TimePerformed = DateTime.Parse(Blocks.Rows[i]["TimePerformed"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); - //Server.s.Log(Blocks.Rows[i]["Type"].ToString()); - BlockUsed = Block.Name(Convert.ToByte(Blocks.Rows[i]["Type"])).ToString(); - Deleted = Convert.ToBoolean(Blocks.Rows[i]["Deleted"]); + DataRow row = Blocks.Rows[i]; + Username = row["Username"].ToString().Trim(); + TimePerformed = DateTime.Parse(row["TimePerformed"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); + BlockUsed = Block.Name(Convert.ToByte(row["Type"])).ToString(); + Deleted = Convert.ToBoolean(row["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 - 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); } diff --git a/Commands/building/CmdMessageBlock.cs b/Commands/building/CmdMessageBlock.cs index 55f69fed0..01a264609 100644 --- a/Commands/building/CmdMessageBlock.cs +++ b/Commands/building/CmdMessageBlock.cs @@ -112,12 +112,16 @@ namespace MCGalaxy.Commands { //safe against SQL injections because no user input is given here using (DataTable Messages = Database.fillData("SELECT * FROM `Messages" + p.level.name + "`")) { if (p.showMBs) { - 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); + for (int i = 0; i < Messages.Rows.Count; i++) { + 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."); } else { - 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()))); + for (int i = 0; i < Messages.Rows.Count; i++) { + 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."); } } diff --git a/Commands/building/CmdPortal.cs b/Commands/building/CmdPortal.cs index 01498410c..76ccf2dca 100644 --- a/Commands/building/CmdPortal.cs +++ b/Commands/building/CmdPortal.cs @@ -140,7 +140,7 @@ namespace MCGalaxy.Commands { } else { for (int i = 0; i < Portals.Rows.Count; 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["EntryX"]), U16(row["EntryY"]), U16(row["EntryZ"])); } diff --git a/Levels/Level.cs b/Levels/Level.cs index cdfccff9e..e1368c772 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -609,13 +609,14 @@ namespace MCGalaxy Zone Zn; for (int i = 0; i < ZoneDB.Rows.Count; ++i) { - Zn.smallX = ushort.Parse(ZoneDB.Rows[i]["SmallX"].ToString()); - Zn.smallY = ushort.Parse(ZoneDB.Rows[i]["SmallY"].ToString()); - Zn.smallZ = ushort.Parse(ZoneDB.Rows[i]["SmallZ"].ToString()); - Zn.bigX = ushort.Parse(ZoneDB.Rows[i]["BigX"].ToString()); - Zn.bigY = ushort.Parse(ZoneDB.Rows[i]["BigY"].ToString()); - Zn.bigZ = ushort.Parse(ZoneDB.Rows[i]["BigZ"].ToString()); - Zn.Owner = ZoneDB.Rows[i]["Owner"].ToString(); + DataRow row = ZoneDB.Rows[i]; + Zn.smallX = ushort.Parse(row["SmallX"].ToString()); + Zn.smallY = ushort.Parse(row["SmallY"].ToString()); + Zn.smallZ = ushort.Parse(row["SmallZ"].ToString()); + Zn.bigX = ushort.Parse(row["BigX"].ToString()); + Zn.bigY = ushort.Parse(row["BigY"].ToString()); + Zn.bigZ = ushort.Parse(row["BigZ"].ToString()); + Zn.Owner = row["Owner"].ToString(); level.ZoneList.Add(Zn); } } @@ -632,37 +633,39 @@ namespace MCGalaxy // level.StartPhysics(); //}; //level.physChecker.Start(); - //level.season = new SeasonsCore(level); + try { DataTable foundDB = Database.fillData("SELECT * FROM `Portals" + givenName + "`"); for (int i = 0; i < foundDB.Rows.Count; ++i) { + DataRow row = foundDB.Rows[i]; if ( - !Block.portal(level.GetTile(ushort.Parse(foundDB.Rows[i]["EntryX"].ToString()), - ushort.Parse(foundDB.Rows[i]["EntryY"].ToString()), - ushort.Parse(foundDB.Rows[i]["EntryZ"].ToString())))) + !Block.portal(level.GetTile(ushort.Parse(row["EntryX"].ToString()), + ushort.Parse(row["EntryY"].ToString()), + ushort.Parse(row["EntryZ"].ToString())))) { Database.executeQuery("DELETE FROM `Portals" + givenName + "` WHERE EntryX=" + - foundDB.Rows[i]["EntryX"] + " AND EntryY=" + - foundDB.Rows[i]["EntryY"] + " AND EntryZ=" + - foundDB.Rows[i]["EntryZ"]); + row["EntryX"] + " AND EntryY=" + + row["EntryY"] + " AND EntryZ=" + + row["EntryZ"]); } } foundDB = Database.fillData("SELECT * FROM `Messages" + givenName + "`"); for (int i = 0; i < foundDB.Rows.Count; ++i) { + DataRow row = foundDB.Rows[i]; if ( - !Block.mb(level.GetTile(ushort.Parse(foundDB.Rows[i]["X"].ToString()), - ushort.Parse(foundDB.Rows[i]["Y"].ToString()), - ushort.Parse(foundDB.Rows[i]["Z"].ToString())))) + !Block.mb(level.GetTile(ushort.Parse(row["X"].ToString()), + ushort.Parse(row["Y"].ToString()), + ushort.Parse(row["Z"].ToString())))) { //givenName is safe against SQL injections, it gets checked in CmdLoad.cs Database.executeQuery("DELETE FROM `Messages" + givenName + "` WHERE X=" + - foundDB.Rows[i]["X"] + " AND Y=" + foundDB.Rows[i]["Y"] + - " AND Z=" + foundDB.Rows[i]["Z"]); + row["X"] + " AND Y=" + row["Y"] + + " AND Z=" + row["Z"]); } } foundDB.Dispose();