From 955117936242017f741b9756dbbb8a4fba9192c8 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 22 Jan 2012 02:02:39 -0700 Subject: [PATCH 01/21] Change codename --- TShockAPI/TShock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 2c024cab..b4531662 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -41,7 +41,7 @@ namespace TShockAPI public class TShock : TerrariaPlugin { public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; - public static readonly string VersionCodename = "Pre-Release - Code Freeze"; + public static readonly string VersionCodename = "1.1.2 in the house!"; public static string SavePath = "tshock"; From 7e26c40744567c90fc426ee7700f0199431db909 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Thu, 26 Jan 2012 22:39:46 -0700 Subject: [PATCH 02/21] VERSION TICK: 3.6.0.0126 (I'm counting third as a hotfix count, this isn't a hotfix) --- TShockAPI/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index 5beaf1ff..857627ed 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -48,5 +48,5 @@ using System.Runtime.InteropServices; // Build Number // MMdd of the build -[assembly: AssemblyVersion("3.5.2.0127")] -[assembly: AssemblyFileVersion("3.5.2.0127")] +[assembly: AssemblyVersion("3.6.0.0126")] +[assembly: AssemblyFileVersion("3.6.0.0126")] From 1e8cb04fdd75f51d79960e41711a492f8f9fc463 Mon Sep 17 00:00:00 2001 From: k0rd Date: Sat, 28 Jan 2012 05:19:15 -0500 Subject: [PATCH 03/21] allow teleporting and warps at edges of the map --- TShockAPI/TSPlayer.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index ce1f3261..dfa932ce 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -313,11 +313,35 @@ namespace TShockAPI try { int num = (size - 1)/2; - SendData(PacketTypes.TileSendSquare, "", size, (x - num), (y - num)); + int m_x=0; + int m_y=0; + + if (x - num <0){ + m_x=0; + }else{ + m_x = x - num; + } + + if (y - num <0){ + m_y=0; + }else{ + m_y = y - num; + } + + if (m_x + size > Main.maxTilesX){ + m_x=Main.maxTilesX - size; + } + + if (m_y + size > Main.maxTilesY){ + m_y=Main.maxTilesY - size; + } + + SendData(PacketTypes.TileSendSquare, "", size, m_x, m_y); return true; } catch (IndexOutOfRangeException) { + // This is expected if square exceeds array. } catch (Exception ex) From ccda71027be9b64ac432ff535185bb0812c19b9f Mon Sep 17 00:00:00 2001 From: k0rd Date: Sun, 29 Jan 2012 03:07:19 -0500 Subject: [PATCH 04/21] attempting to fix client/server tile disagreements after teleporting --- TShockAPI/TSPlayer.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index dfa932ce..441543c5 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -270,6 +270,9 @@ namespace TShockAPI TPlayer.position.X = (float)(tilex * 16 + 8 - TPlayer.width /2); TPlayer.position.Y = (float)(tiley * 16 - TPlayer.height); + //We need to send the tile data again to prevent clients from thinking they *really* destroyed blocks just now. + + SendTileSquare(tilex, tiley, 150); return true; } From 436cd058ec2a3be3d18f13603085b9155dc3349a Mon Sep 17 00:00:00 2001 From: k0rd Date: Sun, 29 Jan 2012 08:39:42 -0500 Subject: [PATCH 05/21] We don't want to revert everything the player has done on the server in case of disable() for tilekill --- TShockAPI/TShock.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index abd70cb1..c4b4b4e0 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -492,6 +492,8 @@ namespace TShockAPI if (player.TileKillThreshold > 0) { player.TileKillThreshold = 0; + //We don't want to revert the entire map in case of a disable. + player.TilesDestroyed.Clear(); } if (player.TilesCreated != null) { @@ -1429,4 +1431,4 @@ namespace TShockAPI Utils.HashAlgo = file.HashAlgorithm; } } -} \ No newline at end of file +} From 74035d5c1ef08279340cf38ed2540203fabe51c8 Mon Sep 17 00:00:00 2001 From: k0rd Date: Mon, 30 Jan 2012 04:05:55 -0500 Subject: [PATCH 06/21] sand, silt, pearlsand, and ebonsand shouldn't trigger noclip detection --- TShockAPI/GetDataHandlers.cs | 44 ++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 9935c96c..279ab251 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -412,7 +412,47 @@ namespace TShockAPI PlayerUpdate.Invoke(null, args); return args.Handled; } - + public static bool TSCheckNoclip(Vector2 Position, int Width, int Height) + { + int num = (int)(Position.X / 16f) - 1; + int num2 = (int)((Position.X + (float)Width) / 16f) + 2; + int num3 = (int)(Position.Y / 16f) - 1; + int num4 = (int)((Position.Y + (float)Height) / 16f) + 2; + if (num < 0) + { + num = 0; + } + if (num2 > Main.maxTilesX) + { + num2 = Main.maxTilesX; + } + if (num3 < 0) + { + num3 = 0; + } + if (num4 > Main.maxTilesY) + { + num4 = Main.maxTilesY; + } + for (int i = num; i < num2; i++) + { + for (int j = num3; j < num4; j++) + { + if (Main.tile[i, j] != null && Main.tile[i, j].active && Main.tileSolid[(int)Main.tile[i, j].type] && !Main.tileSolidTop[(int)Main.tile[i, j].type] &&(((int)Main.tile[i,j].type !=53) && ((int)Main.tile[i,j].type !=112) && ((int)Main.tile[i,j].type !=116) && ((int)Main.tile[i,j].type !=123))) + { + Vector2 vector; + vector.X = (float)(i * 16); + vector.Y = (float)(j * 16); + if (Position.X + (float)Width > vector.X && Position.X < vector.X + 16f && Position.Y + (float)Height > vector.Y && Position.Y < vector.Y + 16f) + { + return true; + } + } + } + } + return false; + } + /// /// For use in a SendTileSquare event /// @@ -1801,7 +1841,7 @@ namespace TShockAPI } if (!args.Player.Group.HasPermission(Permissions.ignorenoclipdetection) && - Collision.SolidCollision(pos, args.TPlayer.width, args.TPlayer.height) && !TShock.Config.IgnoreNoClip) + TSCheckNoclip(pos, args.TPlayer.width, args.TPlayer.height) && !TShock.Config.IgnoreNoClip) { int lastTileX = (int) (args.Player.LastNetPosition.X/16f); int lastTileY = (int) (args.Player.LastNetPosition.Y/16f); From 13e00c7d2d375206174fe0f3dc3bc0cc924dc4a9 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 31 Jan 2012 02:10:05 -0700 Subject: [PATCH 07/21] Save SSI on /off Should technically solve #339, but there are probably more instances around the codebase that have the same issue. --- TShockAPI/Commands.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 71594c46..9431886d 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -986,6 +986,18 @@ namespace TShockAPI private static void Off(CommandArgs args) { + + if (TShock.Config.ServerSideInventory) + { + foreach (TSPlayer player in TShock.Players) + { + if (player != null && player.IsLoggedIn && !player.IgnoreActionsForClearingTrashCan) + { + TShock.InventoryDB.InsertPlayerData(player); + } + } + } + TShock.Utils.ForceKickAll("Server shutting down!"); WorldGen.saveWorld(); Netplay.disconnect = true; From 9371c4972dda9c5cfd2c0353173a1ecd5d1b5bf0 Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Tue, 31 Jan 2012 03:41:25 -0600 Subject: [PATCH 08/21] Log's name is now timestamp with yyyyMMddHHmmss.log format --- TShockAPI/TShock.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index c4b4b4e0..bee91793 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -108,7 +108,8 @@ namespace TShockAPI Directory.CreateDirectory(SavePath); #if DEBUG - Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All, false); + DateTime now = DateTime.Now; + Log.Initialize(Path.Combine(SavePath, now.ToString("yyyyMMddHHmmss")+".log"), LogLevel.All, false); #else Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All & ~LogLevel.Debug, false); #endif From 550e6b3685f3cf4cf7930c56d5ce6080600fa48f Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Tue, 31 Jan 2012 04:50:20 -0600 Subject: [PATCH 09/21] Removed deperecated Rest API endpoints and updated UserListV2 method --- TShockAPI/Rest/RestManager.cs | 283 +--------------------------------- 1 file changed, 4 insertions(+), 279 deletions(-) diff --git a/TShockAPI/Rest/RestManager.cs b/TShockAPI/Rest/RestManager.cs index 3540a037..50e029a6 100644 --- a/TShockAPI/Rest/RestManager.cs +++ b/TShockAPI/Rest/RestManager.cs @@ -39,7 +39,6 @@ namespace TShockAPI Rest.Register(new RestCommand("/status", Status) {RequiresToken = false}); Rest.Register(new RestCommand("/tokentest", TokenTest) {RequiresToken = true}); - Rest.Register(new RestCommand("/users/activelist", UserList) {RequiresToken = true}); Rest.Register(new RestCommand("/v2/users/activelist", UserListV2) { RequiresToken = true }); Rest.Register(new RestCommand("/v2/users/read", UserInfoV2) { RequiresToken = true }); Rest.Register(new RestCommand("/v2/users/destroy", UserDestroyV2) { RequiresToken = true }); @@ -68,20 +67,6 @@ namespace TShockAPI Rest.Register(new RestCommand("/v2/server/broadcast", Broadcast) { RequiresToken = true}); Rest.Register(new RestCommand("/v2/server/off", Off) {RequiresToken = true}); Rest.Register(new RestCommand("/v2/server/rawcmd", ServerCommand) {RequiresToken = true}); - - #region Deprecated Endpoints - Rest.Register(new RestCommand("/bans/read/{user}/info", BanInfo) { RequiresToken = true }); - Rest.Register(new RestCommand("/bans/destroy/{user}", BanDestroy) { RequiresToken = true }); - - Rest.Register(new RestCommand("/users/read/{user}/info", UserInfo) { RequiresToken = true }); - Rest.Register(new RestCommand("/users/destroy/{user}", UserDestroy) { RequiresToken = true }); - Rest.Register(new RestCommand("/users/update/{user}", UserUpdate) { RequiresToken = true }); - - Rest.Register(new RestCommand("/players/read/{player}", PlayerRead) { RequiresToken = true }); - Rest.Register(new RestCommand("/players/{player}/kick", PlayerKick) { RequiresToken = true }); - Rest.Register(new RestCommand("/players/{player}/ban", PlayerBan) { RequiresToken = true }); - #endregion - } #region RestServerMethods @@ -172,14 +157,15 @@ namespace TShockAPI private object UserListV2(RestVerbs verbs, IParameterCollection parameters) { - var ret = new RestObject("200"); string playerlist = ""; foreach (var TSPlayer in TShock.Players) { playerlist += playerlist == "" ? TSPlayer.UserAccountName : "\t" + TSPlayer.UserAccountName; } - ret["activeusers"] = playerlist; - return ret; + var returnBlock = new Dictionary(); + returnBlock.Add("status", "200"); + returnBlock.Add("activeusers", playerlist); + return returnBlock; } private object UserUpdateV2(RestVerbs verbs, IParameterCollection parameters) @@ -664,266 +650,5 @@ namespace TShockAPI } #endregion - - #region Deperecated endpoints - - private object UserUpdate(RestVerbs verbs, IParameterCollection parameters) - { - var returnBlock = new Dictionary(); - var password = parameters["password"]; - var group = parameters["group"]; - - if (group == null && password == null) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "No parameters were passed."); - return returnBlock; - } - - var user = TShock.Users.GetUserByName(verbs["user"]); - if (user == null) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "The specefied user doesn't exist."); - return returnBlock; - } - - if (password != null) - { - TShock.Users.SetUserPassword(user, password); - returnBlock.Add("password-response", "Password updated successfully."); - } - - if (group != null) - { - TShock.Users.SetUserGroup(user, group); - returnBlock.Add("group-response", "Group updated successfully."); - } - - returnBlock.Add("status", "200"); - returnBlock.Add("deprecated", "This endpoint is deprecated. It will be fully removed from code in TShock 3.6."); - return returnBlock; - } - - private object UserDestroy(RestVerbs verbs, IParameterCollection parameters) - { - var user = TShock.Users.GetUserByName(verbs["user"]); - if (user == null) - { - return new Dictionary { { "status", "400" }, { "error", "The specified user account does not exist." } }; - } - var returnBlock = new Dictionary(); - try - { - TShock.Users.RemoveUser(user); - } - catch (Exception) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "The specified user was unable to be removed."); - return returnBlock; - } - returnBlock.Add("status", "200"); - returnBlock.Add("response", "User deleted successfully."); - returnBlock.Add("deprecated", "This endpoint is deprecated. It will be fully removed from code in TShock 3.6."); - return returnBlock; - } - - private object UserInfo(RestVerbs verbs, IParameterCollection parameters) - { - var user = TShock.Users.GetUserByName(verbs["user"]); - if (user == null) - { - return new Dictionary { { "status", "400" }, { "error", "The specified user account does not exist." } }; - } - - var returnBlock = new Dictionary(); - returnBlock.Add("status", "200"); - returnBlock.Add("group", user.Group); - returnBlock.Add("id", user.ID.ToString()); - returnBlock.Add("deprecated", "This endpoint is deprecated. It will be fully removed from code in TShock 3.6."); - return returnBlock; - } - - private object UserList(RestVerbs verbs, IParameterCollection parameters) - { - var ret = new RestObject("200"); - string playerlist = ""; - foreach (var TSPlayer in TShock.Players) - { - if (playerlist == "") - { - playerlist += TSPlayer.UserAccountName; - } - else - { - playerlist += ", " + TSPlayer.UserAccountName; - } - } - ret["activeuesrs"] = playerlist; - return ret; - } - - private object BanDestroy(RestVerbs verbs, IParameterCollection parameters) - { - var returnBlock = new Dictionary(); - - var type = parameters["type"]; - if (type == null) - { - returnBlock.Add("Error", "Invalid Type"); - return returnBlock; - } - - var ban = new Ban(); - if (type == "ip") ban = TShock.Bans.GetBanByIp(verbs["user"]); - else if (type == "name") ban = TShock.Bans.GetBanByName(verbs["user"]); - else - { - returnBlock.Add("Error", "Invalid Type"); - return returnBlock; - } - - if (ban == null) - { - return new Dictionary { { "status", "400" }, { "error", "The specified ban does not exist." } }; - } - - try - { - TShock.Bans.RemoveBan(ban.IP); - } - catch (Exception) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "The specified ban was unable to be removed."); - return returnBlock; - } - returnBlock.Add("status", "200"); - returnBlock.Add("response", "Ban deleted successfully."); - returnBlock.Add("deprecated", "This endpoint is deprecated. It will be fully removed from code in TShock 3.6."); - return returnBlock; - } - - private object PlayerRead(RestVerbs verbs, IParameterCollection parameters) - { - var returnBlock = new Dictionary(); - var playerParam = verbs["player"]; - var found = TShock.Utils.FindPlayer(playerParam); - if (found.Count == 0) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam + " was not found"); - } - else if (found.Count > 1) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam + " matches " + playerParam.Count() + " players"); - } - else if (found.Count == 1) - { - var player = found[0]; - returnBlock.Add("status", "200"); - returnBlock.Add("nickname", player.Name); - returnBlock.Add("username", player.UserAccountName == null ? "" : player.UserAccountName); - returnBlock.Add("ip", player.IP); - returnBlock.Add("group", player.Group.Name); - returnBlock.Add("position", player.TileX + "," + player.TileY); - var activeItems = player.TPlayer.inventory.Where(p => p.active).ToList(); - returnBlock.Add("inventory", string.Join(", ", activeItems.Select(p => p.name))); - returnBlock.Add("buffs", string.Join(", ", player.TPlayer.buffType)); - } - returnBlock.Add("deprecated", "This endpoint is deprecated. It will be fully removed from code in TShock 3.6."); - return returnBlock; - } - - private object PlayerKick(RestVerbs verbs, IParameterCollection parameters) - { - var returnBlock = new Dictionary(); - var playerParam = verbs["player"]; - var found = TShock.Utils.FindPlayer(playerParam); - var reason = verbs["reason"]; - if (found.Count == 0) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam + " was not found"); - } - else if (found.Count > 1) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam + " matches " + playerParam.Count() + " players"); - } - else if (found.Count == 1) - { - var player = found[0]; - TShock.Utils.ForceKick(player, reason == null ? "Kicked via web" : reason); - returnBlock.Add("status", "200"); - returnBlock.Add("response", "Player " + player.Name + " was kicked"); - } - returnBlock.Add("deprecated", "This endpoint is deprecated. It will be fully removed from code in TShock 3.6."); - return returnBlock; - } - - private object PlayerBan(RestVerbs verbs, IParameterCollection parameters) - { - var returnBlock = new Dictionary(); - var playerParam = verbs["player"]; - var found = TShock.Utils.FindPlayer(playerParam); - var reason = verbs["reason"]; - if (found.Count == 0) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam + " was not found"); - } - else if (found.Count > 1) - { - returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam + " matches " + playerParam.Count() + " players"); - } - else if (found.Count == 1) - { - var player = found[0]; - TShock.Bans.AddBan(player.IP, player.Name, reason == null ? "Banned via web" : reason); - TShock.Utils.ForceKick(player, reason == null ? "Banned via web" : reason); - returnBlock.Add("status", "200"); - returnBlock.Add("response", "Player " + player.Name + " was banned"); - } - returnBlock.Add("deprecated", "This endpoint is deprecated. It will be fully removed from code in TShock 3.6."); - return returnBlock; - } - - private object BanInfo(RestVerbs verbs, IParameterCollection parameters) - { - var returnBlock = new Dictionary(); - - var type = parameters["type"]; - if (type == null) - { - returnBlock.Add("Error", "Invalid Type"); - return returnBlock; - } - - var ban = new Ban(); - if (type == "ip") ban = TShock.Bans.GetBanByIp(verbs["user"]); - else if (type == "name") ban = TShock.Bans.GetBanByName(verbs["user"]); - else - { - returnBlock.Add("Error", "Invalid Type"); - return returnBlock; - } - - if (ban == null) - { - return new Dictionary { { "status", "400" }, { "error", "The specified ban does not exist." } }; - } - - returnBlock.Add("status", "200"); - returnBlock.Add("name", ban.Name); - returnBlock.Add("ip", ban.IP); - returnBlock.Add("reason", ban.Reason); - returnBlock.Add("deprecated", "This endpoint is deprecated. It will be fully removed from code in TShock 3.6."); - return returnBlock; - } - #endregion } } \ No newline at end of file From fcb44cc62a3401543a734648770a9d2ac7270904 Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Tue, 31 Jan 2012 05:02:45 -0600 Subject: [PATCH 10/21] Fixed minor error in log name code --- TShockAPI/TShock.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index bee91793..eec78456 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -107,13 +107,13 @@ namespace TShockAPI if (!Directory.Exists(SavePath)) Directory.CreateDirectory(SavePath); -#if DEBUG DateTime now = DateTime.Now; +#if DEBUG Log.Initialize(Path.Combine(SavePath, now.ToString("yyyyMMddHHmmss")+".log"), LogLevel.All, false); #else - Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All & ~LogLevel.Debug, false); + Log.Initialize(Path.Combine(SavePath, now.ToString("yyyyMMddHHmmss")+".log"), LogLevel.All & ~LogLevel.Debug, false); #endif - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; try { From 2e9f07c6f342aaa25ef1dd15b4130eada91d6636 Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Tue, 31 Jan 2012 06:31:08 -0600 Subject: [PATCH 11/21] More functionality in spawnrate and maxspawns commands --- TShockAPI/Commands.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 9431886d..698e46e7 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -2132,9 +2132,24 @@ namespace TShockAPI if (args.Parameters.Count != 1) { args.Player.SendMessage("Invalid syntax! Proper syntax: /maxspawns ", Color.Red); + args.Player.SendMessage("Proper syntax: /maxspawns show", Color.Red); + args.Player.SendMessage("Proper syntax: /maxspawns default", Color.Red); return; } + if (args.Parameters[0] == "show") + { + args.Player.SendMessage("Current maximum spawns is: " + TShock.Config.DefaultMaximumSpawns); + return; + } + + if(args.Parameters[0]=="default"){ + TShock.Config.DefaultMaximumSpawns = 5; + NPC.defaultMaxSpawns = 5; + TShock.Utils.Broadcast(string.Format("{0} changed the maximum spawns to: 5", args.Player.Name)); + return; + } + int amount = Convert.ToInt32(args.Parameters[0]); int.TryParse(args.Parameters[0], out amount); NPC.defaultMaxSpawns = amount; @@ -2147,9 +2162,25 @@ namespace TShockAPI if (args.Parameters.Count != 1) { args.Player.SendMessage("Invalid syntax! Proper syntax: /spawnrate ", Color.Red); + args.Player.SendMessage("/spawnrate show", Color.Red); + args.Player.SendMessage("/spawnrate default", Color.Red); return; } + if (args.Parameters[0] == "show") + { + args.Player.SendMessage("Current spawn rate is: " + TShock.Config.DefaultSpawnRate); + return; + } + + if (args.Parameters[0] == "default") + { + TShock.Config.DefaultSpawnRate = 600; + NPC.defaultSpawnRate = 600; + TShock.Utils.Broadcast(string.Format("{0} changed the spawn rate to: 600", args.Player.Name)); + return; + } + int amount = Convert.ToInt32(args.Parameters[0]); int.TryParse(args.Parameters[0], out amount); NPC.defaultSpawnRate = amount; From 87e3fd347da0ac706a4dcb6feacd1fff93cad830 Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Tue, 31 Jan 2012 11:31:58 -0600 Subject: [PATCH 12/21] Added 'restart' command --- TShockAPI/Commands.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 698e46e7..ce920f03 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -26,6 +26,7 @@ using System.Text; using System.Threading; using Terraria; using TShockAPI.DB; +using System.Reflection; namespace TShockAPI { @@ -129,6 +130,7 @@ namespace TShockAPI add(Permissions.maintenance, ClearBans, "clearbans"); add(Permissions.whitelist, Whitelist, "whitelist"); add(Permissions.maintenance, Off, "off", "exit"); + add(Permissions.maintenance, Restart, "restart"); //Added restart command add(Permissions.maintenance, OffNoSave, "off-nosave", "exit-nosave"); add(Permissions.maintenance, CheckUpdates, "checkupdates"); add(Permissions.causeevents, DropMeteor, "dropmeteor"); @@ -1002,6 +1004,27 @@ namespace TShockAPI WorldGen.saveWorld(); Netplay.disconnect = true; } + //Added restart command + private static void Restart(CommandArgs args) + { + + if (TShock.Config.ServerSideInventory) + { + foreach (TSPlayer player in TShock.Players) + { + if (player != null && player.IsLoggedIn && !player.IgnoreActionsForClearingTrashCan) + { + TShock.InventoryDB.InsertPlayerData(player); + } + } + } + + TShock.Utils.ForceKickAll("Server restarting!"); + WorldGen.saveWorld(); + Netplay.disconnect = true; + System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); + Environment.Exit(0); + } private static void OffNoSave(CommandArgs args) { From ad56dd0741bd861dcf18698491715af7952ae719 Mon Sep 17 00:00:00 2001 From: k0rd Date: Tue, 31 Jan 2012 21:02:16 -0500 Subject: [PATCH 13/21] this was trying to enter Player Names in multiple rows when the IP was different - but player name is the primary key! (also fixed position on reconnect) Remembering Position should now work correctly. --- TShockAPI/DB/RememberPosManager.cs | 32 ++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/TShockAPI/DB/RememberPosManager.cs b/TShockAPI/DB/RememberPosManager.cs index 4cc4d441..50df4110 100644 --- a/TShockAPI/DB/RememberPosManager.cs +++ b/TShockAPI/DB/RememberPosManager.cs @@ -44,6 +44,28 @@ namespace TShockAPI.DB creator.EnsureExists(table); } + public Vector2 CheckLeavePos(string name) + { + try + { + using (var reader = database.QueryReader("SELECT * FROM RememberedPos WHERE Name=@0", name)) + { + if (reader.Read()) + { + return new Vector2(reader.Get("X"), reader.Get("Y")); + } + } + } + catch (Exception ex) + { + Log.Error(ex.ToString()); + } + + return new Vector2(); + } + + + public Vector2 GetLeavePos(string name, string IP) { try @@ -66,12 +88,11 @@ namespace TShockAPI.DB public void InsertLeavePos(string name, string IP, int X, int Y) { - if (GetLeavePos(name, IP) == Vector2.Zero) + if (CheckLeavePos(name) == Vector2.Zero) { try { - database.Query("INSERT INTO RememberedPos (Name, IP, X, Y, WorldID) VALUES (@0, @1, @2, @3, @4);", name, IP, X, - Y + 3, Main.worldID.ToString()); + database.Query("INSERT INTO RememberedPos (Name, IP, X, Y, WorldID) VALUES (@0, @1, @2, @3, @4);", name, IP, X, Y , Main.worldID.ToString()); } catch (Exception ex) { @@ -82,8 +103,7 @@ namespace TShockAPI.DB { try { - database.Query("UPDATE RememberedPos SET X = @0, Y = @1 WHERE Name = @2 AND IP = @3 AND WorldID = @4;", X, Y + 3, - name, IP, Main.worldID.ToString()); + database.Query("UPDATE RememberedPos SET X = @0, Y = @1, IP = @2 WHERE Name = @3 AND WorldID = @4;", X, Y, IP, name, Main.worldID.ToString()); } catch (Exception ex) { @@ -92,4 +112,4 @@ namespace TShockAPI.DB } } } -} \ No newline at end of file +} From f3d4b0c6d101eba3f09a82ec2e8e03ddf286342e Mon Sep 17 00:00:00 2001 From: k0rd Date: Tue, 31 Jan 2012 23:00:56 -0500 Subject: [PATCH 14/21] another change to make remembered position work correctly --- TShockAPI/TShock.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index eec78456..2f4394e8 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -854,10 +854,11 @@ namespace TShockAPI if (Config.RememberLeavePos) { + if (RememberedPos.GetLeavePos(player.Name, player.IP) != Vector2.Zero){ var pos = RememberedPos.GetLeavePos(player.Name, player.IP); player.LastNetPosition = pos; player.Teleport((int) pos.X, (int) pos.Y + 3); - } + }} e.Handled = true; } From d6f0c0ecf55d11146c2f1cb02843d91f21d44149 Mon Sep 17 00:00:00 2001 From: k0rd Date: Tue, 31 Jan 2012 23:37:59 -0500 Subject: [PATCH 15/21] /restart doesn't work for mono.. yet --- TShockAPI/Commands.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index ce920f03..5eb46e83 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1007,7 +1007,9 @@ namespace TShockAPI //Added restart command private static void Restart(CommandArgs args) { - + if (Main.runningMono){ + Log.ConsoleInfo("Sorry, this command has not yet been implemented in Mono"); + }else{ if (TShock.Config.ServerSideInventory) { foreach (TSPlayer player in TShock.Players) @@ -1024,7 +1026,7 @@ namespace TShockAPI Netplay.disconnect = true; System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Environment.Exit(0); - } + }} private static void OffNoSave(CommandArgs args) { @@ -3452,4 +3454,4 @@ namespace TShockAPI #endregion Cheat Comamnds } -} \ No newline at end of file +} From 44afc6d8ddc1b0344703e3fe3a6aa0ab015ee79d Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Wed, 1 Feb 2012 12:00:31 -0600 Subject: [PATCH 16/21] Updated Local Files --- TShockAPI/Commands.cs | 8 +++++--- TShockAPI/DB/RememberPosManager.cs | 32 ++++++++++++++++++++++++------ TShockAPI/TShock.cs | 3 ++- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index ce920f03..5eb46e83 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1007,7 +1007,9 @@ namespace TShockAPI //Added restart command private static void Restart(CommandArgs args) { - + if (Main.runningMono){ + Log.ConsoleInfo("Sorry, this command has not yet been implemented in Mono"); + }else{ if (TShock.Config.ServerSideInventory) { foreach (TSPlayer player in TShock.Players) @@ -1024,7 +1026,7 @@ namespace TShockAPI Netplay.disconnect = true; System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Environment.Exit(0); - } + }} private static void OffNoSave(CommandArgs args) { @@ -3452,4 +3454,4 @@ namespace TShockAPI #endregion Cheat Comamnds } -} \ No newline at end of file +} diff --git a/TShockAPI/DB/RememberPosManager.cs b/TShockAPI/DB/RememberPosManager.cs index 4cc4d441..50df4110 100644 --- a/TShockAPI/DB/RememberPosManager.cs +++ b/TShockAPI/DB/RememberPosManager.cs @@ -44,6 +44,28 @@ namespace TShockAPI.DB creator.EnsureExists(table); } + public Vector2 CheckLeavePos(string name) + { + try + { + using (var reader = database.QueryReader("SELECT * FROM RememberedPos WHERE Name=@0", name)) + { + if (reader.Read()) + { + return new Vector2(reader.Get("X"), reader.Get("Y")); + } + } + } + catch (Exception ex) + { + Log.Error(ex.ToString()); + } + + return new Vector2(); + } + + + public Vector2 GetLeavePos(string name, string IP) { try @@ -66,12 +88,11 @@ namespace TShockAPI.DB public void InsertLeavePos(string name, string IP, int X, int Y) { - if (GetLeavePos(name, IP) == Vector2.Zero) + if (CheckLeavePos(name) == Vector2.Zero) { try { - database.Query("INSERT INTO RememberedPos (Name, IP, X, Y, WorldID) VALUES (@0, @1, @2, @3, @4);", name, IP, X, - Y + 3, Main.worldID.ToString()); + database.Query("INSERT INTO RememberedPos (Name, IP, X, Y, WorldID) VALUES (@0, @1, @2, @3, @4);", name, IP, X, Y , Main.worldID.ToString()); } catch (Exception ex) { @@ -82,8 +103,7 @@ namespace TShockAPI.DB { try { - database.Query("UPDATE RememberedPos SET X = @0, Y = @1 WHERE Name = @2 AND IP = @3 AND WorldID = @4;", X, Y + 3, - name, IP, Main.worldID.ToString()); + database.Query("UPDATE RememberedPos SET X = @0, Y = @1, IP = @2 WHERE Name = @3 AND WorldID = @4;", X, Y, IP, name, Main.worldID.ToString()); } catch (Exception ex) { @@ -92,4 +112,4 @@ namespace TShockAPI.DB } } } -} \ No newline at end of file +} diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index eec78456..2f4394e8 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -854,10 +854,11 @@ namespace TShockAPI if (Config.RememberLeavePos) { + if (RememberedPos.GetLeavePos(player.Name, player.IP) != Vector2.Zero){ var pos = RememberedPos.GetLeavePos(player.Name, player.IP); player.LastNetPosition = pos; player.Teleport((int) pos.X, (int) pos.Y + 3); - } + }} e.Handled = true; } From 5a6b59cbad23d66f504ab792d299b098920b1811 Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Wed, 1 Feb 2012 13:44:05 -0600 Subject: [PATCH 17/21] Added removespecial command --- TShockAPI/Commands.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 5eb46e83..05adacb6 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -215,6 +215,7 @@ namespace TShockAPI add(Permissions.cfg, WorldInfo, "world"); add(Permissions.converthardmode, ConvertCorruption, "convertcorruption"); add(Permissions.converthardmode, ConvertHallow, "converthallow"); + add(Permissions.converthardmode, RemoveSpecial, "removespecial"); } public static bool HandleCommand(TSPlayer player, string text) @@ -1488,6 +1489,45 @@ namespace TShockAPI TShock.Utils.Broadcast("Hallow conversion done."); } + private static void RemoveSpecial(CommandArgs args) + { + TShock.Utils.Broadcast("Server may lag for a moment.", Color.Red); + for (int x = 0; x < Main.maxTilesX; x++) + { + for (int y = 0; y < Main.maxTilesY; y++) + { + switch (Main.tile[x, y].type) + { + case 22: + case 117: + case 25: + Main.tile[x, y].type = 1; + break; + case 109: + case 23: + Main.tile[x, y].type = 2; + break; + case 32: + Main.tile[x, y].type = 0; + Main.tile[x, y].active = false; + break; + case 24: + Main.tile[x, y].type = 3; + break; + case 112: + case 116: + Main.tile[x, y].type = 169; + break; + default: + continue; + } + } + } + WorldGen.CountTiles(0); + TSPlayer.All.SendData(PacketTypes.UpdateGoodEvil); + Netplay.ResetSections(); + TShock.Utils.Broadcast("Special tile conversion done."); + } #endregion Cause Events and Spawn Monsters Commands #region Teleport Commands From accdb03d191d97342ef15e8554b9afb28fa346d3 Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Wed, 1 Feb 2012 13:48:56 -0600 Subject: [PATCH 18/21] Removed demonite ore from the "removespecial" and "convertcorruption" commands. --- TShockAPI/Commands.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 05adacb6..3b1dfb1b 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1432,7 +1432,6 @@ namespace TShockAPI { switch (Main.tile[x, y].type) { - case 22: case 25: Main.tile[x, y].type = 117; break; @@ -1498,7 +1497,6 @@ namespace TShockAPI { switch (Main.tile[x, y].type) { - case 22: case 117: case 25: Main.tile[x, y].type = 1; From 99fb24c82accb291bf733b4ec21b40a6f99fd351 Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Wed, 1 Feb 2012 14:55:41 -0600 Subject: [PATCH 19/21] removespecial now removes pearlstone bricks --- TShockAPI/Commands.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 3b1dfb1b..9f28db34 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1516,6 +1516,9 @@ namespace TShockAPI case 116: Main.tile[x, y].type = 169; break; + case 113: + Main.tile[x, y].type = 38; + break; default: continue; } From da87682719e8e97aac73d62df676c1df22753ccf Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Wed, 1 Feb 2012 14:59:25 -0600 Subject: [PATCH 20/21] removespecial now removes pearlstone bricks --- TShockAPI/Commands.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 3b1dfb1b..0667a7d6 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1516,6 +1516,9 @@ namespace TShockAPI case 116: Main.tile[x, y].type = 169; break; + case 118: + Main.tile[x, y].type = 38; + break; default: continue; } From 9d18ab3ce028792d265ac9de19608890b49b0752 Mon Sep 17 00:00:00 2001 From: Darkvengance aka Sildaekar Date: Wed, 1 Feb 2012 15:14:04 -0600 Subject: [PATCH 21/21] pearlstone brick now changed to grey brick --- TShockAPI/Commands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 0667a7d6..9f28db34 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1516,7 +1516,7 @@ namespace TShockAPI case 116: Main.tile[x, y].type = 169; break; - case 118: + case 113: Main.tile[x, y].type = 38; break; default: