diff --git a/API/WhoWas.cs b/API/WhoWas.cs index 1a670ea78..f0834b3de 100644 --- a/API/WhoWas.cs +++ b/API/WhoWas.cs @@ -19,12 +19,12 @@ namespace MCGalaxy { PlayerData pl = PlayerInfo.FindData(p); if (pl == null) return; - modified_blocks = int.Parse(pl.Blocks); + modified_blocks = (int)pl.Blocks; time = pl.TotalTime; - first_login = pl.FirstLogin; - last_login = pl.LastLogin; - total_logins = int.Parse(pl.Logins); - kicks = int.Parse(pl.Kicks); + first_login = pl.FirstLogin.ToString("yyyy-MM-dd HH:mm:ss"); + last_login = pl.LastLogin.ToString("yyyy-MM-dd HH:mm:ss"); + total_logins = pl.Logins; + kicks = pl.Kicks; } } } \ No newline at end of file diff --git a/Commands/Information/CmdSeen.cs b/Commands/Information/CmdSeen.cs index 4128af2d4..330868e53 100644 --- a/Commands/Information/CmdSeen.cs +++ b/Commands/Information/CmdSeen.cs @@ -40,8 +40,7 @@ namespace MCGalaxy.Commands { Player.Message(p, "Searching PlayerDB.."); PlayerData target = PlayerInfo.FindOfflineMatches(p, message); if (target == null) return; - Show(p, target.Name, DateTime.Parse(target.FirstLogin), - DateTime.Parse(target.LastLogin)); + Show(p, target.Name, target.FirstLogin, target.LastLogin); } static void Show(Player p, string name, DateTime first, DateTime last) { diff --git a/Commands/Information/CmdWhois.cs b/Commands/Information/CmdWhois.cs index 9ee051d9f..e24dd9d26 100644 --- a/Commands/Information/CmdWhois.cs +++ b/Commands/Information/CmdWhois.cs @@ -60,7 +60,9 @@ namespace MCGalaxy.Commands { info.Name = who.name; info.Group = who.group; info.Money = who.money; info.Deaths = who.overallDeath; - info.TotalBlocks = who.overallBlocks; info.TotalDrawn = who.TotalBlocksDrawn; + + info.TotalBlocks = who.overallBlocks; info.TotalDrawn = who.TotalDrawn; + info.TotalPlaced = who.TotalPlaced; info.TotalDeleted = who.TotalDeleted; info.LoginBlocks = who.loginBlocks; info.TimeSpent = who.time; info.TimeOnline = DateTime.Now - who.timeLogged; @@ -76,27 +78,28 @@ namespace MCGalaxy.Commands { return info; } - WhoInfo FromOffline(PlayerData target, string message) { - Group group = Group.findPlayerGroup(target.Name); - string color = target.Color == "" ? group.color : target.Color; - string prefix = target.Title == "" ? "" : color + "[" + target.TitleColor + target.Title + color + "] "; + WhoInfo FromOffline(PlayerData data, string message) { + Group group = Group.findPlayerGroup(data.Name); + string color = data.Color == "" ? group.color : data.Color; + string prefix = data.Title == "" ? "" : color + "[" + data.TitleColor + data.Title + color + "] "; WhoInfo info = new WhoInfo(); - info.FullName = prefix + color + target.Name.TrimEnd('+'); - info.Name = target.Name; + info.FullName = prefix + color + data.Name.TrimEnd('+'); + info.Name = data.Name; info.Group = group; - info.Money = int.Parse(target.Money); info.Deaths = int.Parse(target.Deaths); - info.TotalBlocks = long.Parse(target.Blocks); info.LoginBlocks = -1; - info.TotalDrawn = long.Parse(target.Cuboided); + info.Money = data.Money; info.Deaths = data.Deaths; - info.TimeSpent = target.TotalTime.ParseDBTime(); - info.First = DateTime.Parse(target.FirstLogin); - info.Last = DateTime.Parse(target.LastLogin); - info.Logins = int.Parse(target.Logins); info.Kicks = int.Parse(target.Kicks); - info.IP = target.IP; + info.TotalBlocks = data.Blocks; info.TotalDrawn = data.Cuboided; + info.LoginBlocks = -1; + + info.TimeSpent = data.TotalTime.ParseDBTime(); + info.First = data.FirstLogin; + info.Last = data.LastLogin; + info.Logins = data.Logins; info.Kicks = data.Kicks; + info.IP = data.IP; if (Server.zombie.Running) { - ZombieStats stats = Server.zombie.LoadZombieStats(target.Name); + ZombieStats stats = Server.zombie.LoadZombieStats(data.Name); info.RoundsTotal = stats.TotalRounds; info.InfectedTotal = stats.TotalInfected; info.RoundsMax = stats.MaxRounds; info.InfectedMax = stats.MaxInfected; } diff --git a/Commands/Information/WhoInfo.cs b/Commands/Information/WhoInfo.cs index ebd82427f..799496ea6 100644 --- a/Commands/Information/WhoInfo.cs +++ b/Commands/Information/WhoInfo.cs @@ -23,7 +23,7 @@ namespace MCGalaxy.Commands { public string FullName, Name; public Group Group; public int Money, Deaths; - public long TotalBlocks, LoginBlocks, TotalDrawn; + public long TotalBlocks, LoginBlocks, TotalDrawn, TotalPlaced, TotalDeleted; public TimeSpan TimeSpent, TimeOnline; public DateTime First, Last; public int Logins, Kicks; @@ -48,7 +48,8 @@ namespace MCGalaxy.Commands { Player.Message(p, " Modified &a{0} %Sblocks, &a{1} %Ssince login", who.TotalBlocks, who.LoginBlocks); else Player.Message(p, " Modified &a{0} %Sblocks", who.TotalBlocks); - Player.Message(p, " &a0 %Splaced, &a0 %Sdeleted, &a{0} %Sdrawn", who.TotalDrawn); + Player.Message(p, " &a{0} %Splaced, &a{1} %Sdeleted, &a{2} %Sdrawn", + who.TotalPlaced, who.TotalDeleted, who.TotalDrawn); if (who.TimeOnline.Ticks > 0) Player.Message(p, " Spent &a{0}%S on the server, &a{1}%S this session", diff --git a/Commands/Moderation/CmdInfoSwap.cs b/Commands/Moderation/CmdInfoSwap.cs index 245320029..5a2418a18 100644 --- a/Commands/Moderation/CmdInfoSwap.cs +++ b/Commands/Moderation/CmdInfoSwap.cs @@ -56,8 +56,8 @@ namespace MCGalaxy.Commands { const string format = "yyyy-MM-dd HH:mm:ss"; void Swap(PlayerData src, PlayerData dst) { - string first = DateTime.Parse(src.FirstLogin).ToString(format); - string last = DateTime.Parse(src.LastLogin).ToString(format); + string first = src.FirstLogin.ToString(format); + string last = src.LastLogin.ToString(format); const string syntax = "UPDATE Players SET totalBlocks=@0, totalCuboided=@1" + ", color=@2, totalDeaths=@3, FirstLogin=@4, IP=@5, totalKicked=@6, LastLogin=@7" + ", totalLogin=@8, Money=@9, Title=@10, title_color=@11, TimeSpent=@12 WHERE Name=@13"; diff --git a/Commands/Moderation/CmdPlayerEditDB.cs b/Commands/Moderation/CmdPlayerEditDB.cs index 3be1b763e..7fba044ed 100644 --- a/Commands/Moderation/CmdPlayerEditDB.cs +++ b/Commands/Moderation/CmdPlayerEditDB.cs @@ -72,7 +72,7 @@ namespace MCGalaxy.Commands { SetInteger(p, args, "totalBlocks", int.MaxValue, who, v => who.overallBlocks = v); break; case "totalcuboided": case "totalcuboid": - SetInteger(p, args, "totalCuboided", int.MaxValue, who, v => who.TotalBlocksDrawn = v); break; + SetInteger(p, args, "totalCuboided", int.MaxValue, who, v => who.TotalDrawn = v); break; case "totalkicked": SetInteger(p, args, "totalKicked", 1000000000, who, v => who.totalKicked = v); break; case "timespent": diff --git a/Commands/Moderation/CmdRestoreSelection.cs b/Commands/Moderation/CmdRestoreSelection.cs index 3c36ac29a..8acf4a0bb 100644 --- a/Commands/Moderation/CmdRestoreSelection.cs +++ b/Commands/Moderation/CmdRestoreSelection.cs @@ -61,10 +61,10 @@ namespace MCGalaxy.Commands { for (int z = Math.Min(m[0].Z, m[1].Z); z <= Math.Max(m[0].Z, m[1].Z); z++) for (int x = Math.Min(m[0].X, m[1].X); x <= Math.Max(m[0].X, m[1].X); x++) { - byte tile = blocks[x + width * (z + y * length)], extTile = 0; - if (tile == Block.custom_block) - extTile = other.GetExtTile((ushort)x, (ushort)y, (ushort)z); - p.level.UpdateBlock(p, (ushort)x, (ushort)y, (ushort)z, tile, extTile); + byte block = blocks[x + width * (z + y * length)], extBlock = 0; + if (block == Block.custom_block) + extBlock = other.GetExtTile((ushort)x, (ushort)y, (ushort)z); + p.level.UpdateBlock(p, (ushort)x, (ushort)y, (ushort)z, block, extBlock, true); } return true; } diff --git a/Commands/building/CmdCenter.cs b/Commands/building/CmdCenter.cs index 9b2083cd8..be1958746 100644 --- a/Commands/building/CmdCenter.cs +++ b/Commands/building/CmdCenter.cs @@ -37,7 +37,7 @@ namespace MCGalaxy.Commands.Building { } static void Place(Player p, int x, int y, int z) { - p.level.UpdateBlock(p, (ushort)x, (ushort)y, (ushort)z, Block.goldsolid, 0); + p.level.UpdateBlock(p, (ushort)x, (ushort)y, (ushort)z, Block.goldsolid, 0, true); } public override void Help(Player p) { diff --git a/Commands/building/CmdDrill.cs b/Commands/building/CmdDrill.cs index 4079b5eae..7bbd8f5bf 100644 --- a/Commands/building/CmdDrill.cs +++ b/Commands/building/CmdDrill.cs @@ -84,7 +84,7 @@ namespace MCGalaxy.Commands.Building { if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z); bool sameBlock = type == Block.custom_block ? extType == extTile : type == tile; - if (sameBlock) p.level.UpdateBlock(p, x, y, z, Block.air, 0); + if (sameBlock) p.level.UpdateBlock(p, x, y, z, Block.air, 0, true); } Player.Message(p, "Drilled " + buffer.Count + " blocks."); return true; diff --git a/Commands/building/CmdImageprint.cs b/Commands/building/CmdImageprint.cs index 4649ef9ce..acbbcf295 100644 --- a/Commands/building/CmdImageprint.cs +++ b/Commands/building/CmdImageprint.cs @@ -166,7 +166,7 @@ namespace MCGalaxy.Commands.Building { } if (col.A < 20) cur.Block = Block.air; - p.level.UpdateBlock(p, (ushort)P.X, (ushort)P.Y, (ushort)P.Z, cur.Block, 0); + p.level.UpdateBlock(p, (ushort)P.X, (ushort)P.Y, (ushort)P.Z, cur.Block, 0, true); } if (dArgs.name == "tempImage_" + p.name) diff --git a/Commands/building/CmdSPlace.cs b/Commands/building/CmdSPlace.cs index d9123d3f4..e4e0811e4 100644 --- a/Commands/building/CmdSPlace.cs +++ b/Commands/building/CmdSPlace.cs @@ -69,7 +69,7 @@ namespace MCGalaxy.Commands.Building { ushort endX = (ushort)(m[0].X + dirX * distance); ushort endY = (ushort)(m[0].Y + dirY * distance); ushort endZ = (ushort)(m[0].Z + dirZ * distance); - p.level.UpdateBlock(p, endX, endY, endZ, Block.rock, 0); + p.level.UpdateBlock(p, endX, endY, endZ, Block.rock, 0, true); if (interval > 0) { int x = m[0].X, y = m[0].Y, z = m[0].Z; @@ -80,7 +80,7 @@ namespace MCGalaxy.Commands.Building { delta = Math.Abs(x - m[0].X) + Math.Abs(y - m[0].Y) + Math.Abs(z - m[0].Z); } } else { - p.level.UpdateBlock(p, (ushort)m[0].X, (ushort)m[0].Y, (ushort)m[0].Z, Block.rock, 0); + p.level.UpdateBlock(p, (ushort)m[0].X, (ushort)m[0].Y, (ushort)m[0].Z, Block.rock, 0, true); } Player.Message(p, "Placed stone blocks {0} apart.", interval > 0 ? interval : distance); diff --git a/Drawing/DrawOps/DrawOp.Performer.cs b/Drawing/DrawOps/DrawOp.Performer.cs index 2f6e81ada..a0f403771 100644 --- a/Drawing/DrawOps/DrawOp.Performer.cs +++ b/Drawing/DrawOps/DrawOp.Performer.cs @@ -137,9 +137,7 @@ namespace MCGalaxy.Drawing.Ops { continue; lvl.SetTile(b.X, b.Y, b.Z, b.Block, p, b.ExtBlock); - p.loginBlocks++; - p.overallBlocks++; - p.TotalBlocksDrawn++; + p.IncrementBlockStats(b.Block, true); } } else if (item.Level.bufferblocks) { foreach (var b in item.Op.Perform(item.Marks, p, lvl, item.Brush)) { diff --git a/Levels/Level.Blocks.cs b/Levels/Level.Blocks.cs index 098a8d287..28ffeabf9 100644 --- a/Levels/Level.Blocks.cs +++ b/Levels/Level.Blocks.cs @@ -292,9 +292,7 @@ namespace MCGalaxy { p.UndoBuffer.Add(this, Pos); errorLocation = "Setting tile"; - p.loginBlocks++; - p.overallBlocks++; - if (drawn) p.TotalBlocksDrawn++; + p.IncrementBlockStats(block, drawn); SetTile(x, y, z, block); if (b == Block.custom_block && block != Block.custom_block) diff --git a/Player/Player.Fields.cs b/Player/Player.Fields.cs index 06935f9d1..417a3321c 100644 --- a/Player/Player.Fields.cs +++ b/Player/Player.Fields.cs @@ -150,15 +150,15 @@ namespace MCGalaxy { //Using for anything else can cause unintended effects! public bool canBuild = true; - public int money = 0, loginMoney = 0; - public long overallBlocks = 0, TotalBlocksDrawn = 0; - public int loginBlocks = 0; + public int money, loginMoney; + public long overallBlocks, TotalDrawn, TotalPlaced, TotalDeleted; + public int loginBlocks; public DateTime timeLogged; public DateTime firstLogin, lastLogin; - public int totalLogins = 0; - public int totalKicked = 0; - public int overallDeath = 0; + public int totalLogins; + public int totalKicked; + public int overallDeath; public bool staticCommands = false; internal bool outdatedClient = false; // for ClassicalSharp 0.98.5, which didn't reload map for BlockDefinitions diff --git a/Player/Player.cs b/Player/Player.cs index dad97647d..f87e5967e 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -27,6 +27,15 @@ namespace MCGalaxy { public sealed partial class Player : IDisposable { + public void IncrementBlockStats(byte block, bool drawn) { + loginBlocks++; + overallBlocks++; + + if (drawn) TotalDrawn++; + else if (block == 0) TotalDeleted++; + else TotalPlaced++; + } + public static string CheckPlayerStatus(Player p) { if ( p.hidden ) return "hidden"; if ( p.IsAfk ) return "afk"; @@ -87,7 +96,7 @@ namespace MCGalaxy { public void save() { const string query = "UPDATE Players SET IP=@0, LastLogin=@1, totalLogin=@2, totalDeaths=@3, " + - "Money=@4, totalBlocks=@5, totalCuboided=@6, totalKicked=@7, TimeSpent=@8 WHERE Name=@9"; + "Money=@4, totalBlocks=@5, totalCuboided=@6, totalKicked=@7, TimeSpent=@8 WHERE Name=@9"; if (MySQLSave != null) MySQLSave(this, query); OnMySQLSaveEvent.Call(this, query); @@ -95,7 +104,7 @@ namespace MCGalaxy { Database.Execute(query, ip, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), totalLogins, overallDeath, money, overallBlocks, - TotalBlocksDrawn, totalKicked, time.ToDBTime(), name); + TotalDrawn, totalKicked, time.ToDBTime(), name); if (Economy.Enabled && loginMoney != money) { Economy.EcoStats ecos = Economy.RetrieveEcoStats(name); diff --git a/Player/PlayerData.cs b/Player/PlayerData.cs index 74f861637..5648b0c63 100644 --- a/Player/PlayerData.cs +++ b/Player/PlayerData.cs @@ -21,9 +21,10 @@ using MCGalaxy.SQL; namespace MCGalaxy { public class PlayerData { - public string Name, Color, Title, TitleColor; - public string Money, Deaths, Blocks, Cuboided, Logins, Kicks; - public string TotalTime, FirstLogin, LastLogin, IP, UserID; + public string Name, Color, Title, TitleColor, TotalTime, IP; + public DateTime FirstLogin, LastLogin; + public int UserID, Money, Deaths, Logins, Kicks; + public long Blocks, Cuboided; internal static void Create(Player p) { p.prefix = ""; @@ -38,7 +39,7 @@ namespace MCGalaxy { p.totalKicked = 0; p.overallDeath = 0; p.overallBlocks = 0; - p.TotalBlocksDrawn = 0; + p.TotalDrawn = 0; string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); const string query = "INSERT INTO Players (Name, IP, FirstLogin, LastLogin, totalLogin, Title, totalDeaths" + @@ -54,11 +55,11 @@ namespace MCGalaxy { internal static void Load(DataTable playerDb, Player p) { PlayerData data = PlayerData.Fill(playerDb.Rows[0]); - p.totalLogins = int.Parse(data.Logins) + 1; + p.totalLogins = data.Logins + 1; p.time = data.TotalTime.ParseDBTime(); - p.DatabaseID = int.Parse(data.UserID); - p.firstLogin = DateTime.Parse(data.FirstLogin); - p.lastLogin = DateTime.Parse(data.LastLogin); + p.DatabaseID = data.UserID; + p.firstLogin = data.FirstLogin; + p.lastLogin = data.LastLogin; p.title = data.Title; if (p.title != "") p.title = p.title.Replace("[", "").Replace("]", ""); @@ -67,36 +68,36 @@ namespace MCGalaxy { p.color = data.Color; if (p.color == "") p.color = p.group.color; - p.overallDeath = int.Parse(data.Deaths); - p.overallBlocks = long.Parse(data.Blocks); - p.TotalBlocksDrawn = long.Parse(data.Cuboided); + p.overallDeath = data.Deaths; + p.overallBlocks = data.Blocks; + p.TotalDrawn = data.Cuboided; //money = int.Parse(data.money); p.money = Economy.RetrieveEcoStats(p.name).money; p.loginMoney = p.money; - p.totalKicked = int.Parse(data.Kicks); + p.totalKicked = data.Kicks; } public static PlayerData Fill(DataRow row) { PlayerData pl = new PlayerData(); pl.Name = row["Name"].ToString().Trim(); pl.IP = row["IP"].ToString().Trim(); - pl.UserID = row["ID"].ToString().Trim(); + pl.UserID = int.Parse(row["ID"].ToString().Trim()); pl.TotalTime = row["TimeSpent"].ToString(); - pl.FirstLogin = row["FirstLogin"].ToString(); - pl.LastLogin = row["LastLogin"].ToString(); + pl.FirstLogin = DateTime.Parse(row["FirstLogin"].ToString()); + pl.LastLogin = DateTime.Parse(row["LastLogin"].ToString()); pl.Title = row["Title"].ToString().Trim(); pl.TitleColor = ParseColor(row["title_color"]); pl.Color = ParseColor(row["color"]); - pl.Money = row["Money"].ToString(); - pl.Deaths = row["TotalDeaths"].ToString(); - pl.Blocks = row["totalBlocks"].ToString(); - pl.Cuboided = row["totalCuboided"].ToString(); - pl.Logins = row["totalLogin"].ToString(); - pl.Kicks = row["totalKicked"].ToString(); + pl.Money = int.Parse(row["Money"].ToString()); + pl.Deaths = int.Parse(row["TotalDeaths"].ToString()); + pl.Blocks = long.Parse(row["totalBlocks"].ToString()); + pl.Cuboided = long.Parse(row["totalCuboided"].ToString()); + pl.Logins = int.Parse(row["totalLogin"].ToString()); + pl.Kicks = int.Parse(row["totalKicked"].ToString()); return pl; }