From 5d7c38817a278ad03430ce32e4c540acb3aa6883 Mon Sep 17 00:00:00 2001 From: Deathmax Date: Mon, 15 Aug 2011 17:30:54 +0800 Subject: [PATCH 1/7] /annoy should work correctly now. /annoy's loop has a check to make sure player hasn't changed in the mean time (hopefully what I'm doing is thread-safe) --- TShockAPI/Properties/AssemblyInfo.cs | 4 ++-- TShockAPI/TSPlayer.cs | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index 6d3f5bc7..204b7aa3 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -36,5 +36,5 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.2.6.0813")] -[assembly: AssemblyFileVersion("3.2.6.0813")] +[assembly: AssemblyVersion("3.2.6.0815")] +[assembly: AssemblyFileVersion("3.2.6.0815")] diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index e717c063..149741ec 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -309,11 +309,12 @@ namespace TShockAPI if (Main.player[i] != null & Main.player[i].active && i != Index) player = i; SendMessage("You are now being annoyed.", Color.Red); - var oriinv = Main.player[0].inventory[player]; - while ((DateTime.UtcNow - launch).TotalSeconds < time2) + var oriinv = Main.player[player].inventory[0]; + var startname = Name; + while ((DateTime.UtcNow - launch).TotalSeconds < time2 && startname == Name) { - Main.player[0].inventory[player].SetDefaults("Whoopie Cushion"); - Main.player[0].inventory[player].stack = 1; + Main.player[player].inventory[0].SetDefaults("Whoopie Cushion"); + Main.player[player].inventory[0].stack = 1; SendData(PacketTypes.PlayerSlot, "Whoopie Cushion", player, 0f); Main.player[player].position = TPlayer.position; Main.player[player].selectedItem = 0; @@ -324,7 +325,7 @@ namespace TShockAPI SendData(PacketTypes.PlayerUpdate, number: player); Thread.Sleep(50); } - Main.player[0].inventory[0] = oriinv; + Main.player[player].inventory[0] = oriinv; SendData(PacketTypes.PlayerSlot, oriinv.name, player, 0f); } From d0b9e602f85b3483147718df4e86642b828b4408 Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 15 Aug 2011 12:46:24 -0300 Subject: [PATCH 2/7] Trying to get unit tests to test the groups via github... this could end poorly :D --- Terraria.vsmdi | 1 + 1 file changed, 1 insertion(+) diff --git a/Terraria.vsmdi b/Terraria.vsmdi index c807b09d..51901056 100644 --- a/Terraria.vsmdi +++ b/Terraria.vsmdi @@ -5,6 +5,7 @@ + From 4e1ecb7ebc99624d2bc21c75274db697dbbd9f95 Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 15 Aug 2011 12:48:00 -0300 Subject: [PATCH 3/7] part 2... --- Terraria.vsmdi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terraria.vsmdi b/Terraria.vsmdi index 51901056..f59d76e2 100644 --- a/Terraria.vsmdi +++ b/Terraria.vsmdi @@ -5,7 +5,7 @@ - + From d6c961693e3b4f001d4768e2b401cc49f43559a4 Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 15 Aug 2011 12:50:39 -0300 Subject: [PATCH 4/7] nvm, ill do it when i get home :D --- Terraria.vsmdi | 1 - 1 file changed, 1 deletion(-) diff --git a/Terraria.vsmdi b/Terraria.vsmdi index f59d76e2..c807b09d 100644 --- a/Terraria.vsmdi +++ b/Terraria.vsmdi @@ -5,7 +5,6 @@ - From e0d509982fa4fdddcf3854c05bfdcfaf0274f15d Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Mon, 15 Aug 2011 17:27:17 -0400 Subject: [PATCH 5/7] Regions will be less borked now, we hope. Unit test is now included for group( simple one ) --- TShockAPI/DB/RegionManager.cs | 25 +++++++++++++++++++++---- Terraria.vsmdi | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index d45ed084..4f8b828c 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -256,7 +256,7 @@ namespace TShockAPI.DB { try { - database.Query("INSERT INTO Regions VALUES (@0, @1, @2, @3, @4, @5, @6, @7);", tx, ty, width, height, regionname, worldid, "", 1); + database.Query("INSERT INTO Regions VALUES (@0, @1, @2, @3, @4, @5, @6, @7);", tx, ty, height, width, regionname, worldid, "", 1); Regions.Add(new Region(new Rectangle(tx, ty, width, height), regionname, true, worldid)); return true; } @@ -377,11 +377,14 @@ namespace TShockAPI.DB else MergedIDs = MergedIDs + "," + Convert.ToString(TShock.Users.GetUserID(userName)); - if (database.Query("UPDATE Regions SET UserIds=@0 WHERE RegionName=@1 AND WorldID=@2", MergedIDs, regionName, Main.worldID.ToString()) > 0) + int q = database.Query("UPDATE Regions SET UserIds=@0 WHERE RegionName=@1 AND WorldID=@2", MergedIDs, + regionName, Main.worldID.ToString()); + foreach (var r in Regions) { - ReloadAllRegions(); - return true; + if (r.Name == regionName && r.WorldID == Main.worldID.ToString()) + r.setAllowedIDs( MergedIDs ); } + return q != 0; } catch (Exception ex) { @@ -484,5 +487,19 @@ namespace TShockAPI.DB } return false; } + + public void setAllowedIDs( String ids ) + { + String[] id_arr = ids.Split(','); + List id_list = new List(); + foreach( String id in id_arr ) + { + int i = 0; + int.TryParse(id, out i); + if( i != 0 ) + id_list.Add( i ); + } + AllowedIDs = id_list; + } } } diff --git a/Terraria.vsmdi b/Terraria.vsmdi index c807b09d..5024fe82 100644 --- a/Terraria.vsmdi +++ b/Terraria.vsmdi @@ -5,6 +5,7 @@ + From ec63e61e1f157c32e46db2c6cd4b8c463bfd4415 Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Mon, 15 Aug 2011 18:18:35 -0400 Subject: [PATCH 6/7] regions should work, and load from db at start. regions also have remove syntax, /region remove user region which removes them from the list, if they exist. --- TShockAPI/Commands.cs | 37 ++++++++++++++++++++++++++++++++++- TShockAPI/DB/RegionManager.cs | 31 ++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 6527001b..c56543ae 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -154,7 +154,7 @@ namespace TShockAPI ChatCommands.Add(new Command("pvpfun", Slap, "slap")); ChatCommands.Add(new Command("editspawn", ToggleAntiBuild, "antibuild")); ChatCommands.Add(new Command("editspawn", ProtectSpawn, "protectspawn")); - ChatCommands.Add(new Command("editspawn", Region, "region")); + ChatCommands.Add(new Command("manageregion", Region, "region")); ChatCommands.Add(new Command("editspawn", DebugRegions, "debugreg")); ChatCommands.Add(new Command(Help, "help")); ChatCommands.Add(new Command(Playing, "playing", "online", "who")); @@ -1837,6 +1837,41 @@ namespace TShockAPI args.Player.SendMessage("Invalid syntax! Proper syntax: /region allow [name] [region]", Color.Red); break; } + case "remove": + if (args.Parameters.Count > 2) + { + string playerName = args.Parameters[1]; + string regionName = ""; + User playerID; + + for (int i = 2; i < args.Parameters.Count; i++) + { + if (regionName == "") + { + regionName = args.Parameters[2]; + } + else + { + regionName = regionName + " " + args.Parameters[i]; + } + } + if ((playerID = TShock.Users.GetUserByName(playerName)) != null) + { + if (TShock.Regions.RemoveUser(regionName, playerName)) + { + args.Player.SendMessage("Removed user " + playerName + " from " + regionName, Color.Yellow); + } + else + args.Player.SendMessage("Region " + regionName + " not found", Color.Red); + } + else + { + args.Player.SendMessage("Player " + playerName + " not found", Color.Red); + } + } + else + args.Player.SendMessage("Invalid syntax! Proper syntax: /region allow [name] [region]", Color.Red); + break; case "list": { //How many regions per page diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index 4f8b828c..b16331d5 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -52,6 +52,7 @@ namespace TShockAPI.DB creator.EnsureExists(table); ImportOld(); + ReloadAllRegions(); } @@ -361,6 +362,20 @@ namespace TShockAPI.DB return MergedIDs.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries).ToList(); } + public bool RemoveUser(string regionName, string userName ) + { + Region r = getRegion(regionName); + if( r != null ) + { + r.RemoveID(TShock.Users.GetUserID(userName)); + string ids = string.Join(",", r.AllowedIDs); + int q = database.Query("UPDATE Regions SET UserIds=@0 WHERE RegionName=@1 AND WorldID=@2", ids, + regionName, Main.worldID.ToString()); + if (q > 0) + return true; + } + return false; + } public bool AddNewUser(string regionName, String userName) { try @@ -420,7 +435,7 @@ namespace TShockAPI.DB { foreach (Region r in Regions) { - if (r.Name.Equals(name)) + if (r.Name.Equals(name) && r.WorldID == Main.worldID.ToString()) return r; } return new Region(); @@ -501,5 +516,19 @@ namespace TShockAPI.DB } AllowedIDs = id_list; } + + public void RemoveID(int id) + { + var index = -1; + for (int i = 0; i < AllowedIDs.Count; i++ ) + { + if (AllowedIDs[i] == id) + { + index = i; + break; + } + } + AllowedIDs.RemoveAt( index ); + } } } From 8f90da6e3876793bd3de93b805bc2ef7e70af1b5 Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Mon, 15 Aug 2011 18:19:33 -0400 Subject: [PATCH 7/7] also, there needs a permission change from editspawn to manageregion --- TShockAPI/config/groups.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/TShockAPI/config/groups.txt b/TShockAPI/config/groups.txt index b254646e..2c76af37 100644 --- a/TShockAPI/config/groups.txt +++ b/TShockAPI/config/groups.txt @@ -26,6 +26,7 @@ #managewarp - allow player to add/delete warp locations #managegroup - allow player to add/delete/modify groups #manageitem - allow a player to add/delete item bans +#manageregion - allow a user to create/edit regions #editspawn - allow player to enable/disable build protection #cfg - allow player to view/change tshock configuration #time - allow player to change time