From fc1d188951771ac0f61da61342d3b52c1aa8433b Mon Sep 17 00:00:00 2001 From: White Date: Wed, 8 Apr 2015 20:46:12 +0930 Subject: [PATCH 1/4] DEBUG preprocessor checks for ILog --- TShockAPI/GetDataHandlers.cs | 4 ++++ TShockAPI/ILog.cs | 2 ++ TShockAPI/Log.cs | 4 +++- TShockAPI/SqlLog.cs | 2 ++ TShockAPI/TSPlayer.cs | 4 +++- TShockAPI/TextLog.cs | 2 ++ 6 files changed, 16 insertions(+), 2 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index c746dbd1..8b0330b3 100755 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2469,7 +2469,9 @@ namespace TShockAPI { if (type == 100 || type == 164 || type == 180 || type == 261 || (type > 289 && type < 298) || (type >= 325 && type <= 328) || (type >= 345 && type <= 352)) { +#if DEBUG TShock.Log.Debug("Certain projectiles have been ignored for cheat detection."); +#endif } else { @@ -2496,7 +2498,9 @@ namespace TShockAPI { if (type == 90 && TShock.Config.ProjIgnoreShrapnel) // Ignore crystal shards { +#if DEBUG TShock.Log.Debug("Ignoring shrapnel per config.."); +#endif } else if (!Main.projectile[index].active) { diff --git a/TShockAPI/ILog.cs b/TShockAPI/ILog.cs index cae6755b..8da7284d 100644 --- a/TShockAPI/ILog.cs +++ b/TShockAPI/ILog.cs @@ -122,6 +122,7 @@ namespace TShockAPI /// LogLevel assosciated with the message void Write(string message, TraceLevel level); +#if DEBUG /// /// Writes a debug string to the log file. /// @@ -134,6 +135,7 @@ namespace TShockAPI /// The format of the message to be written. /// The format arguments. void Debug(string format, params object[] args); +#endif /// /// Dispose the Log diff --git a/TShockAPI/Log.cs b/TShockAPI/Log.cs index 93a2d0c1..85e611c7 100644 --- a/TShockAPI/Log.cs +++ b/TShockAPI/Log.cs @@ -154,7 +154,8 @@ namespace TShockAPI { ConsoleInfo(string.Format(format, args)); } - + +#if DEBUG /// /// Writes a debug string to the log file. /// @@ -175,6 +176,7 @@ namespace TShockAPI { Debug(string.Format(format, args)); } +#endif /// /// Internal method which writes a message directly to the log file. diff --git a/TShockAPI/SqlLog.cs b/TShockAPI/SqlLog.cs index ef0ceba7..4eb062cb 100644 --- a/TShockAPI/SqlLog.cs +++ b/TShockAPI/SqlLog.cs @@ -205,6 +205,7 @@ namespace TShockAPI ConsoleInfo(string.Format(format, args)); } +#if DEBUG /// /// Writes a debug string to the log file. /// @@ -223,6 +224,7 @@ namespace TShockAPI { Debug(string.Format(format, args)); } +#endif public void Write(string message, TraceLevel level) { diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 2a6a9f49..397b8d09 100755 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -849,7 +849,7 @@ namespace TShockAPI { if (displayConsole) { - TShock.Log.ConsoleInfo("Player {0} has been disabled for {1}.", Name, reason); + TShock.Log.ConsoleInfo("Player {0} has been disabled for {1}.", Name, reason); } else { @@ -858,11 +858,13 @@ namespace TShockAPI LastDisableNotification = DateTime.UtcNow; } } +#if DEBUG var trace = new StackTrace(); StackFrame frame = null; frame = trace.GetFrame(1); if (frame != null && frame.GetMethod().DeclaringType != null) TShock.Log.Debug(frame.GetMethod().DeclaringType.Name + " called Disable()."); +#endif } public virtual void Whoopie(object time) diff --git a/TShockAPI/TextLog.cs b/TShockAPI/TextLog.cs index aef72b7a..6d5fe143 100644 --- a/TShockAPI/TextLog.cs +++ b/TShockAPI/TextLog.cs @@ -172,6 +172,7 @@ namespace TShockAPI ConsoleInfo(string.Format(format, args)); } +#if DEBUG /// /// Writes a debug string to the log file. /// @@ -190,6 +191,7 @@ namespace TShockAPI { Debug(string.Format(format, args)); } +#endif /// /// Writes a message to the log From b4f2ddef47e34f6761a7afbe02fc4db455a79fcf Mon Sep 17 00:00:00 2001 From: White Date: Thu, 9 Apr 2015 15:56:51 +0930 Subject: [PATCH 2/4] DEBUG preprocessor conditional inside method --- TShockAPI/GetDataHandlers.cs | 4 ---- TShockAPI/ILog.cs | 6 ++---- TShockAPI/SqlLog.cs | 8 +++++--- TShockAPI/TSPlayer.cs | 2 -- TShockAPI/TextLog.cs | 6 ++++-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 8b0330b3..c746dbd1 100755 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2469,9 +2469,7 @@ namespace TShockAPI { if (type == 100 || type == 164 || type == 180 || type == 261 || (type > 289 && type < 298) || (type >= 325 && type <= 328) || (type >= 345 && type <= 352)) { -#if DEBUG TShock.Log.Debug("Certain projectiles have been ignored for cheat detection."); -#endif } else { @@ -2498,9 +2496,7 @@ namespace TShockAPI { if (type == 90 && TShock.Config.ProjIgnoreShrapnel) // Ignore crystal shards { -#if DEBUG TShock.Log.Debug("Ignoring shrapnel per config.."); -#endif } else if (!Main.projectile[index].active) { diff --git a/TShockAPI/ILog.cs b/TShockAPI/ILog.cs index 8da7284d..a2dff96f 100644 --- a/TShockAPI/ILog.cs +++ b/TShockAPI/ILog.cs @@ -122,20 +122,18 @@ namespace TShockAPI /// LogLevel assosciated with the message void Write(string message, TraceLevel level); -#if DEBUG /// - /// Writes a debug string to the log file. + /// Writes a debug string to the log file. Only works if the DEBUG preprocessor conditional is set. /// /// The message to be written. void Debug(string message); /// - /// Writes a debug string to the log file. + /// Writes a debug string to the log file. Only works if the DEBUG preprocessor conditional is set. /// /// The format of the message to be written. /// The format arguments. void Debug(string format, params object[] args); -#endif /// /// Dispose the Log diff --git a/TShockAPI/SqlLog.cs b/TShockAPI/SqlLog.cs index 4eb062cb..e1ebbf78 100644 --- a/TShockAPI/SqlLog.cs +++ b/TShockAPI/SqlLog.cs @@ -205,14 +205,15 @@ namespace TShockAPI ConsoleInfo(string.Format(format, args)); } -#if DEBUG /// /// Writes a debug string to the log file. /// /// The message to be written. public void Debug(string message) { - Write(message, TraceLevel.Verbose); +#if DEBUG + Write(message, TraceLevel.Verbose);\ +#endif } /// @@ -222,9 +223,10 @@ namespace TShockAPI /// The format arguments. public void Debug(string format, params object[] args) { +#if DEBUG Debug(string.Format(format, args)); - } #endif + } public void Write(string message, TraceLevel level) { diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 397b8d09..80caaa18 100755 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -858,13 +858,11 @@ namespace TShockAPI LastDisableNotification = DateTime.UtcNow; } } -#if DEBUG var trace = new StackTrace(); StackFrame frame = null; frame = trace.GetFrame(1); if (frame != null && frame.GetMethod().DeclaringType != null) TShock.Log.Debug(frame.GetMethod().DeclaringType.Name + " called Disable()."); -#endif } public virtual void Whoopie(object time) diff --git a/TShockAPI/TextLog.cs b/TShockAPI/TextLog.cs index 6d5fe143..464305ad 100644 --- a/TShockAPI/TextLog.cs +++ b/TShockAPI/TextLog.cs @@ -172,14 +172,15 @@ namespace TShockAPI ConsoleInfo(string.Format(format, args)); } -#if DEBUG /// /// Writes a debug string to the log file. /// /// The message to be written. public void Debug(string message) { +#if DEBUG Write(message, TraceLevel.Verbose); +#endif } /// @@ -189,9 +190,10 @@ namespace TShockAPI /// The format arguments. public void Debug(string format, params object[] args) { +#if DEBUG Debug(string.Format(format, args)); - } #endif + } /// /// Writes a message to the log From cf34aad594570dcf4498bbffbf15ffa88f92cb91 Mon Sep 17 00:00:00 2001 From: White Date: Thu, 9 Apr 2015 15:58:10 +0930 Subject: [PATCH 3/4] Remove the pesky '/' that got in there somehow --- TShockAPI/SqlLog.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/SqlLog.cs b/TShockAPI/SqlLog.cs index e1ebbf78..083f76e7 100644 --- a/TShockAPI/SqlLog.cs +++ b/TShockAPI/SqlLog.cs @@ -212,7 +212,7 @@ namespace TShockAPI public void Debug(string message) { #if DEBUG - Write(message, TraceLevel.Verbose);\ + Write(message, TraceLevel.Verbose); #endif } From 904c44a1b636884816d03c3166ff2ae19a7a3a9a Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Thu, 9 Apr 2015 22:58:32 -0400 Subject: [PATCH 4/4] Fix UseServerName config options, to now work properly. Remove duplicate unused code. Ensure that everywhere we use Main.WorldName, we are sending the config server name. --- TShockAPI/Commands.cs | 2 +- TShockAPI/Rest/RestManager.cs | 4 +- TShockAPI/TSPlayer.cs | 72 ----------------------------------- TShockAPI/TShock.cs | 16 +++++--- TShockAPI/Utils.cs | 2 +- 5 files changed, 15 insertions(+), 81 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 6ef9d615..5976fd7a 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1121,7 +1121,7 @@ namespace TShockAPI private static void WorldInfo(CommandArgs args) { - args.Player.SendInfoMessage("World name: " + Main.worldName); + args.Player.SendInfoMessage("World name: " + (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName)); args.Player.SendInfoMessage("World size: {0}x{1}", Main.maxTilesX, Main.maxTilesY); args.Player.SendInfoMessage("World ID: " + Main.worldID); } diff --git a/TShockAPI/Rest/RestManager.cs b/TShockAPI/Rest/RestManager.cs index 4dd8150c..b40b8115 100644 --- a/TShockAPI/Rest/RestManager.cs +++ b/TShockAPI/Rest/RestManager.cs @@ -333,7 +333,7 @@ namespace TShockAPI {"port", TShock.Config.ServerPort}, {"playercount", Main.player.Where(p => null != p && p.active).Count()}, {"maxplayers", TShock.Config.MaxSlots}, - {"world", Main.worldName}, + {"world", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName)}, {"uptime", (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).ToString(@"d'.'hh':'mm':'ss")}, {"serverpassword", !string.IsNullOrEmpty(TShock.Config.ServerPassword)} }; @@ -707,7 +707,7 @@ namespace TShockAPI { return new RestObject() { - {"name", Main.worldName}, + {"name", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName)}, {"size", Main.maxTilesX + "*" + Main.maxTilesY}, {"time", Main.time}, {"daytime", Main.dayTime}, diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 80caaa18..c60844bc 100755 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -538,78 +538,6 @@ namespace TShockAPI } } - public void SendWorldInfo(int tilex, int tiley, bool fakeid) - { - using (var ms = new MemoryStream()) - { - var msg = new WorldInfoMsg - { - Time = (int)Main.time, - DayTime = Main.dayTime, - MoonPhase = (byte)Main.moonPhase, - BloodMoon = Main.bloodMoon, - Eclipse = Main.eclipse, - MaxTilesX = (short)Main.maxTilesX, - MaxTilesY = (short)Main.maxTilesY, - SpawnX = (short)Main.spawnTileX, - SpawnY = (short)Main.spawnTileY, - WorldSurface = (short)Main.worldSurface, - RockLayer = (short)Main.rockLayer, - //Sending a fake world id causes the client to not be able to find a stored spawnx/y. - //This fixes the bed spawn point bug. With a fake world id it wont be able to find the bed spawn. - WorldID = Main.worldID, - MoonType = (byte)Main.moonType, - TreeX0 = Main.treeX[0], - TreeX1 = Main.treeX[1], - TreeX2 = Main.treeX[2], - TreeStyle0 = (byte)Main.treeStyle[0], - TreeStyle1 = (byte)Main.treeStyle[1], - TreeStyle2 = (byte)Main.treeStyle[2], - TreeStyle3 = (byte)Main.treeStyle[3], - CaveBackX0 = Main.caveBackX[0], - CaveBackX1 = Main.caveBackX[1], - CaveBackX2 = Main.caveBackX[2], - CaveBackStyle0 = (byte)Main.caveBackStyle[0], - CaveBackStyle1 = (byte)Main.caveBackStyle[1], - CaveBackStyle2 = (byte)Main.caveBackStyle[2], - CaveBackStyle3 = (byte)Main.caveBackStyle[3], - SetBG0 = (byte)WorldGen.treeBG, - SetBG1 = (byte)WorldGen.corruptBG, - SetBG2 = (byte)WorldGen.jungleBG, - SetBG3 = (byte)WorldGen.snowBG, - SetBG4 = (byte)WorldGen.hallowBG, - SetBG5 = (byte)WorldGen.crimsonBG, - SetBG6 = (byte)WorldGen.desertBG, - SetBG7 = (byte)WorldGen.oceanBG, - IceBackStyle = (byte)Main.iceBackStyle, - JungleBackStyle = (byte)Main.jungleBackStyle, - HellBackStyle = (byte)Main.hellBackStyle, - WindSpeed = Main.windSpeed, - NumberOfClouds = (byte)Main.numClouds, - BossFlags = (WorldGen.shadowOrbSmashed ? BossFlags.OrbSmashed : BossFlags.None) | - (NPC.downedBoss1 ? BossFlags.DownedBoss1 : BossFlags.None) | - (NPC.downedBoss2 ? BossFlags.DownedBoss2 : BossFlags.None) | - (NPC.downedBoss3 ? BossFlags.DownedBoss3 : BossFlags.None) | - (Main.hardMode ? BossFlags.HardMode : BossFlags.None) | - (NPC.downedClown ? BossFlags.DownedClown : BossFlags.None) | - (Main.ServerSideCharacter ? BossFlags.ServerSideCharacter : BossFlags.None) | - (NPC.downedPlantBoss ? BossFlags.DownedPlantBoss : BossFlags.None), - BossFlags2 = (NPC.downedMechBoss1 ? BossFlags2.DownedMechBoss1 : BossFlags2.None) | - (NPC.downedMechBoss2 ? BossFlags2.DownedMechBoss2 : BossFlags2.None) | - (NPC.downedMechBoss3 ? BossFlags2.DownedMechBoss3 : BossFlags2.None) | - (NPC.downedMechBossAny ? BossFlags2.DownedMechBossAny : BossFlags2.None) | - (Main.cloudBGActive == 1f ? BossFlags2.CloudBg : BossFlags2.None) | - (WorldGen.crimson ? BossFlags2.Crimson : BossFlags2.None) | - (Main.pumpkinMoon ? BossFlags2.PumpkinMoon : BossFlags2.None) | - (Main.snowMoon ? BossFlags2.SnowMoon : BossFlags2.None), - Rain = Main.maxRaining, - WorldName = TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName - }; - msg.PackFull(ms); - SendRawData(ms.ToArray()); - } - } - public bool Teleport(float x, float y, byte style = 1) { if (x > Main.rightWorld - 992) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 3b039acc..666207d0 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1358,9 +1358,6 @@ namespace TShockAPI } else if (e.MsgId == PacketTypes.WorldInfo) { - if (e.remoteClient == -1) return; - var player = Players[e.remoteClient]; - if (player == null) return; using (var ms = new MemoryStream()) { var msg = new WorldInfoMsg @@ -1422,12 +1419,21 @@ namespace TShockAPI (Main.cloudBGActive >= 1f ? BossFlags2.CloudBg : BossFlags2.None) | (WorldGen.crimson ? BossFlags2.Crimson : BossFlags2.None) | (Main.pumpkinMoon ? BossFlags2.PumpkinMoon : BossFlags2.None) | - (Main.snowMoon ? BossFlags2.SnowMoon : BossFlags2.None) , + (Main.snowMoon ? BossFlags2.SnowMoon : BossFlags2.None), Rain = Main.maxRaining, WorldName = TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName }; msg.PackFull(ms); - player.SendRawData(ms.ToArray()); + if (e.remoteClient == -1) + { + TSPlayer.All.SendRawData(ms.ToArray()); + } + else + { + var player = Players[e.remoteClient]; + if (player == null) return; + player.SendRawData(ms.ToArray()); + } } e.Handled = true; return; diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 873b2ee7..2cc8bcc3 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -650,7 +650,7 @@ namespace TShockAPI continue; } - foo = foo.Replace("%map%", Main.worldName); + foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName)); foo = foo.Replace("%players%", String.Join(",", GetPlayers(false))); Regex reg = new Regex("%\\s*(?\\d{1,3})\\s*,\\s*(?\\d{1,3})\\s*,\\s*(?\\d{1,3})\\s*%"); var matches = reg.Matches(foo);