diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index bfef48bb..c06a18e9 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -15,10 +15,11 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + using System; using System.Collections.Generic; using System.Diagnostics; - +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Net; @@ -26,7 +27,6 @@ using System.Text; using System.Threading; using Terraria; using TShockAPI.DB; -using Region = TShockAPI.DB.Region; namespace TShockAPI { @@ -641,12 +641,12 @@ namespace TShockAPI #region Stupid commands public static void ServerInfo(CommandArgs args) { - args.Player.SendMessage("Memory usage: " + System.Diagnostics.Process.GetCurrentProcess().WorkingSet64); - args.Player.SendMessage("Allocated memory: " + System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64); - args.Player.SendMessage("Total processor time: " + System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime); - args.Player.SendMessage("Ver: " + System.Environment.OSVersion); - args.Player.SendMessage("Proc count: " + System.Environment.ProcessorCount); - args.Player.SendMessage("Machine name: " + System.Environment.MachineName); + args.Player.SendMessage("Memory usage: " + Process.GetCurrentProcess().WorkingSet64); + args.Player.SendMessage("Allocated memory: " + Process.GetCurrentProcess().VirtualMemorySize64); + args.Player.SendMessage("Total processor time: " + Process.GetCurrentProcess().TotalProcessorTime); + args.Player.SendMessage("Ver: " + Environment.OSVersion); + args.Player.SendMessage("Proc count: " + Environment.ProcessorCount); + args.Player.SendMessage("Machine name: " + Environment.MachineName); } #endregion @@ -938,7 +938,7 @@ namespace TShockAPI ThreadPool.QueueUserWorkItem(UpdateManager.CheckUpdate); } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] private static void UpdateNow(CommandArgs args) { Process TServer = Process.GetCurrentProcess(); @@ -1103,7 +1103,7 @@ namespace TShockAPI private static void WoF(CommandArgs args) { - if (Main.wof >= 0 || (args.Player.Y / 16f < (float)(Main.maxTilesY - 205))) + if (Main.wof >= 0 || (args.Player.Y / 16f < (Main.maxTilesY - 205))) { args.Player.SendMessage("Can't spawn Wall of Flesh!", Color.Red); return; @@ -2855,7 +2855,7 @@ namespace TShockAPI count++; } } - args.Player.SendMessage("All " + count.ToString() + " items within a radius of " + radius.ToString() + " have been deleted."); + args.Player.SendMessage("All " + count + " items within a radius of " + radius + " have been deleted."); } diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 9ccc2f4c..898fd4bb 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -142,16 +142,16 @@ namespace TShockAPI public bool SaveWorldOnCrash = true; [Description("This will announce a player's location on join")] - public bool EnableGeoIP = false; + public bool EnableGeoIP; [Description("This will turn on a token requirement for the /status API endpoint.")] - public bool EnableTokenEndpointAuthentication = false; + public bool EnableTokenEndpointAuthentication; [Description("This is used when the API endpoint /status is queried.")] public string ServerNickname = "TShock Server"; [Description("Enable/Disable the rest api.")] - public bool RestApiEnabled = false; + public bool RestApiEnabled; [Description("This is the port which the rest api will listen on.")] public int RestApiPort = 7878; @@ -160,7 +160,7 @@ namespace TShockAPI public bool DisableTombstones = true; [Description("Displays a player's IP on join to everyone who has the log permission")] - public bool DisplayIPToAdmins = false; + public bool DisplayIPToAdmins; [Description("Some tiles are 'fixed' by not letting TShock handle them. Disabling this may break certain asthetic tiles.")] public bool EnableInsecureTileFixes = true; @@ -169,22 +169,22 @@ namespace TShockAPI public bool KickProxyUsers = true; [Description("Disables hardmode, can't never be activated. Overrides /starthardmode")] - public bool DisableHardmode = false; + public bool DisableHardmode; [Description("Disables Dungeon Guardian from being spawned by player packets, this will instead force a respawn")] - public bool DisableDungeonGuardian = false; + public bool DisableDungeonGuardian; [Description("Enable Server Side Inventory checks, EXPERIMENTAL")] - public bool ServerSideInventory = false; + public bool ServerSideInventory; [Description("Disables reporting of playercount to the stat system.")] - public bool DisablePlayerCountReporting = false; + public bool DisablePlayerCountReporting; [Description("Disables clown bomb projectiles from spawning")] - public bool DisableClownBombs = false; + public bool DisableClownBombs; [Description("Disables snow ball projectiles from spawning")] - public bool DisableSnowBalls = false; + public bool DisableSnowBalls; [Description("Change ingame chat format, {0} = Group Name, {1} = Group Prefix, {2} = Player Name, {3} = Group Suffix, {4} = Chat Message")] public string ChatFormat = "{1}{2}{3}: {4}"; @@ -205,10 +205,10 @@ namespace TShockAPI public int ProjectileThreshold = 50; [Description("Require all players to register or login before being allowed to play.")] - public bool RequireLogin = false; + public bool RequireLogin; [Description("Disables Invisibility potions from being used in PvP (Note, they can use them on the client, but the effect isn't sent to the rest of the server)")] - public bool DisableInvisPvP = false; + public bool DisableInvisPvP; [Description("The maximum distance players disabled for various reasons can move from")] public int MaxRangeForDisabled = 10; @@ -217,13 +217,13 @@ namespace TShockAPI public string ServerPassword = ""; [Description("Protect chests with region and build permissions")] - public bool RegionProtectChests = false; + public bool RegionProtectChests; [Description("Disable users from being able to login with account password when joining")] - public bool DisableLoginBeforeJoin = false; + public bool DisableLoginBeforeJoin; [Description("Allows users to register any username with /register")] - public bool AllowRegisterAnyUsername = false; + public bool AllowRegisterAnyUsername; public static ConfigFile Read(string path) { diff --git a/TShockAPI/DB/IQueryBuilder.cs b/TShockAPI/DB/IQueryBuilder.cs index 96e71b8c..3ca1d3de 100644 --- a/TShockAPI/DB/IQueryBuilder.cs +++ b/TShockAPI/DB/IQueryBuilder.cs @@ -57,7 +57,7 @@ namespace TShockAPI.DB int count = 0; foreach (SqlValue where in wheres) { - sbwheres.Append(where.Name + "=" + where.Value.ToString()); + sbwheres.Append(where.Name + "=" + where.Value); if (count != wheres.Count - 1) sbwheres.Append(" AND "); count++; @@ -74,7 +74,7 @@ namespace TShockAPI.DB int count = 0; foreach (SqlValue value in values) { - sbvalues.Append(value.Name + "=" + value.Value.ToString()); + sbvalues.Append(value.Name + "=" + value.Value); if (count != values.Count - 1) sbvalues.Append(","); count++; @@ -82,7 +82,7 @@ namespace TShockAPI.DB count = 0; foreach (SqlValue where in wheres) { - sbwheres.Append(where.Name + "=" + where.Value.ToString()); + sbwheres.Append(where.Name + "=" + where.Value); if (count != wheres.Count - 1) sbwheres.Append(" AND "); count++; @@ -124,7 +124,7 @@ namespace TShockAPI.DB foreach (SqlValue where in wheres) { - sbwheres.Append(where.Name + "=" + where.Value.ToString()); + sbwheres.Append(where.Name + "=" + where.Value); if (count != wheres.Count - 1) sbwheres.Append(" AND "); count++; @@ -186,7 +186,7 @@ namespace TShockAPI.DB int count = 0; foreach (SqlValue where in wheres) { - sbwheres.Append(where.Name + "=" + where.Value.ToString()); + sbwheres.Append(where.Name + "=" + where.Value); if (count != wheres.Count - 1) sbwheres.Append(" AND "); count++; @@ -203,7 +203,7 @@ namespace TShockAPI.DB int count = 0; foreach (SqlValue value in values) { - sbvalues.Append(value.Name + "=" + value.Value.ToString()); + sbvalues.Append(value.Name + "=" + value.Value); if (count != values.Count - 1) sbvalues.Append("AND"); count++; @@ -211,7 +211,7 @@ namespace TShockAPI.DB count = 0; foreach (SqlValue where in wheres) { - sbwheres.Append(where.Name + "=" + where.Value.ToString()); + sbwheres.Append(where.Name + "=" + where.Value); if (count != wheres.Count - 1) sbwheres.Append(" AND "); count++; @@ -254,7 +254,7 @@ namespace TShockAPI.DB foreach (SqlValue where in wheres) { - sbwheres.Append(where.Name + "=" + where.Value.ToString()); + sbwheres.Append(where.Name + "=" + where.Value); if (count != wheres.Count - 1) sbwheres.Append(" AND "); count++; diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index 64155671..37bc2e78 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -20,7 +20,6 @@ using System; using System.Collections.Generic; using System.Data; using System.Diagnostics.CodeAnalysis; - using System.IO; using System.Linq; using System.Xml; diff --git a/TShockAPI/DB/RememberPosManager.cs b/TShockAPI/DB/RememberPosManager.cs index 71a9bc5e..5e70c01a 100644 --- a/TShockAPI/DB/RememberPosManager.cs +++ b/TShockAPI/DB/RememberPosManager.cs @@ -18,7 +18,6 @@ along with this program. If not, see . using System; using System.Data; - using MySql.Data.MySqlClient; using Terraria; diff --git a/TShockAPI/DB/SqlValue.cs b/TShockAPI/DB/SqlValue.cs index a5520236..48630d7a 100644 --- a/TShockAPI/DB/SqlValue.cs +++ b/TShockAPI/DB/SqlValue.cs @@ -1,5 +1,5 @@ -using System.Data; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Data; namespace TShockAPI.DB { diff --git a/TShockAPI/DB/WarpsManager.cs b/TShockAPI/DB/WarpsManager.cs index c1599e0b..54e1d10e 100644 --- a/TShockAPI/DB/WarpsManager.cs +++ b/TShockAPI/DB/WarpsManager.cs @@ -19,7 +19,7 @@ along with this program. If not, see . using System; using System.Collections.Generic; using System.Data; - +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Xml; using MySql.Data.MySqlClient; @@ -31,7 +31,7 @@ namespace TShockAPI.DB { private IDbConnection database; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] public WarpManager(IDbConnection db) { database = db; diff --git a/TShockAPI/Extensions/DbExt.cs b/TShockAPI/Extensions/DbExt.cs index 66d7ac8b..4fdb2dd4 100644 --- a/TShockAPI/Extensions/DbExt.cs +++ b/TShockAPI/Extensions/DbExt.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Diagnostics.CodeAnalysis; namespace TShockAPI.DB { @@ -14,7 +15,7 @@ namespace TShockAPI.DB /// Query string with parameters as @0, @1, etc. /// Parameters to be put in the query /// Rows affected by query - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")] + [SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")] public static int Query(this IDbConnection olddb, string query, params object[] args) { using (var db = olddb.CloneEx()) @@ -37,7 +38,7 @@ namespace TShockAPI.DB /// Query string with parameters as @0, @1, etc. /// Parameters to be put in the query /// Query result as IDataReader - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")] + [SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")] public static QueryResult QueryReader(this IDbConnection olddb, string query, params object[] args) { var db = olddb.CloneEx(); @@ -92,8 +93,8 @@ namespace TShockAPI.DB return SqlType.Unknown; } - static readonly Dictionary> ReadFuncs = new Dictionary>() - { + static readonly Dictionary> ReadFuncs = new Dictionary> + { {typeof(bool), (s, i) => s.GetBoolean(i)}, {typeof(byte), (s, i) => s.GetByte(i)}, {typeof(Int16), (s, i) => s.GetInt16(i)}, diff --git a/TShockAPI/GeoIPCountry.cs b/TShockAPI/GeoIPCountry.cs index a5db53fd..44ca4a19 100644 --- a/TShockAPI/GeoIPCountry.cs +++ b/TShockAPI/GeoIPCountry.cs @@ -20,6 +20,7 @@ using System; using System.IO; using System.Net; +using System.Net.Sockets; // This code is based on MaxMind's original C# code, which was ported from Java. // This version is very simplified and does not support a majority of features for speed. @@ -141,7 +142,7 @@ namespace MaxMind public GeoIPCountry(string filename) { FileStream fs = new FileStream(filename, FileMode.Open); - _geodata = (Stream)fs; + _geodata = fs; _close = true; } @@ -192,7 +193,7 @@ namespace MaxMind // Converts an IPv4 address into a long, for reading from geo database long AddressToLong(IPAddress ip) { - if (ip.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork) + if (ip.AddressFamily != AddressFamily.InterNetwork) throw new InvalidOperationException("IP address is not IPv4"); long num = 0; diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index f78da40e..5a77e4d7 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -15,15 +15,14 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + using System; using System.Collections.Generic; - using System.IO; +using System.IO.Streams; using System.Text; using Terraria; - using TShockAPI.Net; -using System.IO.Streams; namespace TShockAPI { @@ -121,8 +120,8 @@ namespace TShockAPI int plr = args.Data.ReadInt8(); int slot = args.Data.ReadInt8(); int stack = args.Data.ReadInt8(); - short prefix = (short) args.Data.ReadInt8(); - int type = (int) args.Data.ReadInt16(); + short prefix = args.Data.ReadInt8(); + int type = args.Data.ReadInt16(); if (plr != args.Player.Index) { diff --git a/TShockAPI/Net/BaseMsg.cs b/TShockAPI/Net/BaseMsg.cs index 5e41e2ee..8aa2b606 100644 --- a/TShockAPI/Net/BaseMsg.cs +++ b/TShockAPI/Net/BaseMsg.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.IO.Streams; namespace TShockAPI.Net @@ -9,7 +10,7 @@ namespace TShockAPI.Net { get { throw new NotImplementedException("Msg ID not implemented"); } } - public void PackFull(System.IO.Stream stream) + public void PackFull(Stream stream) { long start = stream.Position; stream.WriteInt32(1); @@ -21,12 +22,12 @@ namespace TShockAPI.Net stream.Position = end; } - public virtual void Unpack(System.IO.Stream stream) + public virtual void Unpack(Stream stream) { throw new NotImplementedException(); } - public virtual void Pack(System.IO.Stream stream) + public virtual void Pack(Stream stream) { throw new NotImplementedException(); } diff --git a/TShockAPI/Net/NetTile.cs b/TShockAPI/Net/NetTile.cs index 73efc484..12e4bc80 100644 --- a/TShockAPI/Net/NetTile.cs +++ b/TShockAPI/Net/NetTile.cs @@ -18,8 +18,8 @@ along with this program. If not, see . using System; using System.IO; -using Terraria; using System.IO.Streams; +using Terraria; namespace TShockAPI.Net { diff --git a/TShockAPI/Net/WorldInfoMsg.cs b/TShockAPI/Net/WorldInfoMsg.cs index d58647c1..a01807a1 100644 --- a/TShockAPI/Net/WorldInfoMsg.cs +++ b/TShockAPI/Net/WorldInfoMsg.cs @@ -18,9 +18,8 @@ along with this program. If not, see . using System; using System.IO; -using System.Text; - using System.IO.Streams; +using System.Text; namespace TShockAPI.Net { diff --git a/TShockAPI/PacketBufferer.cs b/TShockAPI/PacketBufferer.cs index 7c6ffc5e..85c4b295 100644 --- a/TShockAPI/PacketBufferer.cs +++ b/TShockAPI/PacketBufferer.cs @@ -4,9 +4,8 @@ using System.ComponentModel; using System.IO; using System.Net.Sockets; using System.Text; -using Terraria; - using Hooks; +using Terraria; namespace TShockAPI { diff --git a/TShockAPI/RconHandler.cs b/TShockAPI/RconHandler.cs index 4d42d8d8..74902216 100644 --- a/TShockAPI/RconHandler.cs +++ b/TShockAPI/RconHandler.cs @@ -19,12 +19,12 @@ along with this program. If not, see . using System; using System.Collections.Generic; using System.IO; +using System.IO.Streams; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using Terraria; -using System.IO.Streams; namespace TShockAPI { diff --git a/TShockAPI/Rest/RestManager.cs b/TShockAPI/Rest/RestManager.cs index b43e6542..86a866c9 100644 --- a/TShockAPI/Rest/RestManager.cs +++ b/TShockAPI/Rest/RestManager.cs @@ -4,6 +4,7 @@ using System.Linq; using HttpServer; using Rests; using Terraria; +using TShockAPI.DB; namespace TShockAPI { @@ -213,7 +214,7 @@ namespace TShockAPI return returnBlock; } - var ban = new DB.Ban(); + var ban = new Ban(); if (type == "ip") ban = TShock.Bans.GetBanByIp(verbs["user"]); else if (type == "name") ban = TShock.Bans.GetBanByName(verbs["user"]); else @@ -253,7 +254,7 @@ namespace TShockAPI return returnBlock; } - var ban = new DB.Ban(); + var ban = new Ban(); if (type == "ip") ban = TShock.Bans.GetBanByIp(verbs["user"]); else if (type == "name") ban = TShock.Bans.GetBanByName(verbs["user"]); else @@ -318,7 +319,7 @@ namespace TShockAPI } Main.bloodMoon = bloodmoon; returnBlock.Add("status", "200"); - returnBlock.Add("response", "Blood Moon has been set to " + bloodmoon.ToString()); + returnBlock.Add("response", "Blood Moon has been set to " + bloodmoon); return returnBlock; } #endregion @@ -328,16 +329,16 @@ namespace TShockAPI { var returnBlock = new Dictionary(); var playerParam = parameters["player"]; - var found = TShock.Utils.FindPlayer(playerParam.ToString()); + var found = TShock.Utils.FindPlayer(playerParam); if (found.Count == 0) { returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found"); + returnBlock.Add("error", "Name " + playerParam + " was not found"); } else if (found.Count > 1) { returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players"); + returnBlock.Add("error", "Name " + playerParam + " matches " + playerParam.Count() + " players"); } else if (found.Count == 1) { @@ -347,7 +348,7 @@ namespace TShockAPI returnBlock.Add("username", player.UserAccountName == null ? "" : player.UserAccountName); returnBlock.Add("ip", player.IP); returnBlock.Add("group", player.Group.Name); - returnBlock.Add("position", player.TileX.ToString() + "," + player.TileY.ToString()); + 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)); @@ -358,22 +359,22 @@ namespace TShockAPI { var returnBlock = new Dictionary(); var playerParam = parameters["player"]; - var found = TShock.Utils.FindPlayer(playerParam.ToString()); + var found = TShock.Utils.FindPlayer(playerParam); var reason = verbs["reason"]; if (found.Count == 0) { returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found"); + returnBlock.Add("error", "Name " + playerParam + " was not found"); } else if (found.Count > 1) { returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players"); + 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.ToString()); + TShock.Utils.ForceKick(player, reason == null ? "Kicked via web" : reason); returnBlock.Add("status", "200"); returnBlock.Add("response", "Player " + player.Name + " was kicked"); } @@ -383,23 +384,23 @@ namespace TShockAPI { var returnBlock = new Dictionary(); var playerParam = parameters["player"]; - var found = TShock.Utils.FindPlayer(playerParam.ToString()); + var found = TShock.Utils.FindPlayer(playerParam); var reason = verbs["reason"]; if (found.Count == 0) { returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found"); + returnBlock.Add("error", "Name " + playerParam + " was not found"); } else if (found.Count > 1) { returnBlock.Add("status", "400"); - returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players"); + 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.ToString()); - TShock.Utils.ForceKick(player, reason == null ? "Banned via web" : reason.ToString()); + 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"); } diff --git a/TShockAPI/StatTracker.cs b/TShockAPI/StatTracker.cs index 87ba219e..5cf75f74 100644 --- a/TShockAPI/StatTracker.cs +++ b/TShockAPI/StatTracker.cs @@ -57,11 +57,11 @@ namespace TShockAPI string response; if (TShock.Config.DisablePlayerCountReporting) { - response = client.DownloadString("http://tshock.co/tickto.php?do=log&fp=" + fp + "&ver=" + TShock.VersionNum + "&os=" + System.Environment.OSVersion.ToString() + "&mono=" + Main.runningMono + "&port=" + Netplay.serverPort + "&plcount=0"); + response = client.DownloadString("http://tshock.co/tickto.php?do=log&fp=" + fp + "&ver=" + TShock.VersionNum + "&os=" + Environment.OSVersion + "&mono=" + Main.runningMono + "&port=" + Netplay.serverPort + "&plcount=0"); } else { - response = client.DownloadString("http://tshock.co/tickto.php?do=log&fp=" + fp + "&ver=" + TShock.VersionNum + "&os=" + System.Environment.OSVersion.ToString() + "&mono=" + Main.runningMono + "&port=" + Netplay.serverPort + "&plcount=" + TShock.Utils.ActivePlayers()); + response = client.DownloadString("http://tshock.co/tickto.php?do=log&fp=" + fp + "&ver=" + TShock.VersionNum + "&os=" + Environment.OSVersion + "&mono=" + Main.runningMono + "&port=" + Netplay.serverPort + "&plcount=" + TShock.Utils.ActivePlayers()); } Log.ConsoleInfo("Stat Tracker: " + response + "\n"); } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 2fa914b8..0f3ebf85 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -15,13 +15,12 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + using System; using System.Collections.Generic; - using System.IO; using System.Threading; using Terraria; - using TShockAPI.Net; namespace TShockAPI @@ -60,21 +59,21 @@ namespace TShockAPI public int UserID = -1; public bool HasBeenNaggedAboutLoggingIn; public bool TPAllow = true; - public bool mute = false; - public bool TpLock = false; + public bool mute; + public bool TpLock; Player FakePlayer; - public bool RequestedSection = false; + public bool RequestedSection; public DateTime LastDeath { get; set; } - public bool Dead = false; + public bool Dead; public string Country = "??"; public int Difficulty; private string CacheIP; public string IgnoreActionsForInventory = "none"; public string IgnoreActionsForCheating = "none"; public string IgnoreActionsForDisabledArmor = "none"; - public bool IgnoreActionsForClearingTrashCan = false; + public bool IgnoreActionsForClearingTrashCan; public PlayerData PlayerData; - public bool RequiresPassword = false; + public bool RequiresPassword; public bool RealPlayer { @@ -266,8 +265,8 @@ namespace TShockAPI { using (var ms = new MemoryStream()) { - var msg = new SpawnMsg() - { + var msg = new SpawnMsg + { PlayerIndex = (byte)Index, TileX = tilex, TileY = tiley @@ -281,8 +280,8 @@ namespace TShockAPI { using (var ms = new MemoryStream()) { - var msg = new ProjectileRemoveMsg() - { + var msg = new ProjectileRemoveMsg + { Index = (short)index, Owner = (byte)owner }; @@ -296,7 +295,7 @@ namespace TShockAPI try { int num = (size - 1) / 2; - SendData(PacketTypes.TileSendSquare, "", size, (float)(x - num), (float)(y - num)); + SendData(PacketTypes.TileSendSquare, "", size, (x - num), (y - num)); return true; } catch (Exception ex) @@ -372,7 +371,7 @@ namespace TShockAPI if ((DateTime.UtcNow - LastThreat).TotalMilliseconds < 5000 && !bypass) return; - SendData(PacketTypes.PlayerAddBuff, number: Index, number2: (float)type, number3: (float)time); + SendData(PacketTypes.PlayerAddBuff, number: Index, number2: type, number3: time); } //Todo: Separate this into a few functions. SendTo, SendToAll, etc @@ -476,7 +475,7 @@ namespace TShockAPI public NetItem[] inventory = new NetItem[NetItem.maxNetInventory]; public int maxHealth = 100; //public int maxMana = 100; - public bool exists = false; + public bool exists; public PlayerData(TSPlayer player) { @@ -571,14 +570,14 @@ namespace TShockAPI public class NetItem { public static int maxNetInventory = 59; - public int netID = 0; - public int stack = 0; - public int prefix = 0; + public int netID; + public int stack; + public int prefix; public static string ToString(NetItem[] inventory) { string inventoryString = ""; - for (int i = 0; i < NetItem.maxNetInventory; i++) + for (int i = 0; i < maxNetInventory; i++) { if (i != 0) inventoryString += "~"; @@ -598,9 +597,9 @@ namespace TShockAPI public static NetItem[] Parse(string data) { - NetItem[] inventory = new NetItem[NetItem.maxNetInventory]; + NetItem[] inventory = new NetItem[maxNetInventory]; int i; - for (i = 0; i < NetItem.maxNetInventory; i++) + for (i = 0; i < maxNetInventory; i++) { inventory[i] = new NetItem(); } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 9c8f57c0..72be512b 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -17,8 +17,7 @@ along with this program. If not, see . */ /* TShock wouldn't be possible without: * Github - * Microsoft Visual Studio 2010 - * Adrenic + * Microsoft Visual Studio 2011 * And you, for your continued support and devotion to the evolution of TShock * Kerplunc Gaming * TerrariaGSP @@ -29,12 +28,14 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Net; using System.Reflection; using System.Threading; -using Mono.Data.Sqlite; using Hooks; +using MaxMind; +using Mono.Data.Sqlite; using MySql.Data.MySqlClient; using Rests; using Terraria; @@ -65,7 +66,7 @@ namespace TShockAPI public static IDbConnection DB; public static bool OverridePort; public static PacketBufferer PacketBuffer; - public static MaxMind.GeoIPCountry Geo; + public static GeoIPCountry Geo; public static SecureRest RestApi; public static RestManager RestManager; public static Utils Utils = new Utils(); @@ -105,7 +106,7 @@ namespace TShockAPI - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] public override void Initialize() { HandleCommandLine(Environment.GetCommandLineArgs()); @@ -185,7 +186,7 @@ namespace TShockAPI var geoippath = Path.Combine(SavePath, "GeoIP.dat"); if (Config.EnableGeoIP && File.Exists(geoippath)) - Geo = new MaxMind.GeoIPCountry(geoippath); + Geo = new GeoIPCountry(geoippath); Console.Title = string.Format("TerrariaShock Version {0} ({1})", Version, VersionCodename); Log.ConsoleInfo(string.Format("TerrariaShock Version {0} ({1}) now running.", Version, VersionCodename)); @@ -230,18 +231,18 @@ namespace TShockAPI RestObject RestApi_Verify(string username, string password) { - var userAccount = TShock.Users.GetUserByName(username); + var userAccount = Users.GetUserByName(username); if (userAccount == null) { return new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." }; } - if (TShock.Utils.HashPassword(password).ToUpper() != userAccount.Password.ToUpper()) + if (Utils.HashPassword(password).ToUpper() != userAccount.Password.ToUpper()) { return new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." }; } - if (!TShock.Utils.GetGroup(userAccount.Group).HasPermission("api") && userAccount.Group != "superadmin") + if (!Utils.GetGroup(userAccount.Group).HasPermission("api") && userAccount.Group != "superadmin") { return new RestObject("403") { Error = "Although your account was successfully found and identified, your account lacks the permission required to use the API. (api)" }; } @@ -249,7 +250,7 @@ namespace TShockAPI return new RestObject("200") { Response = "Successful login" }; //Maybe return some user info too? } - protected override void Dispose(bool disposing) + protected override void Dispose(bool disposing) { if (disposing) { @@ -453,12 +454,12 @@ namespace TShockAPI if ((DateTime.UtcNow - LastSave).TotalMinutes >= 15) { - foreach (TSPlayer player in TShock.Players) + foreach (TSPlayer player in Players) { // prevent null point exceptions if (player != null && player.IsLoggedIn) { - TShock.InventoryDB.InsertPlayerData(player); + InventoryDB.InsertPlayerData(player); } } LastSave = DateTime.UtcNow; @@ -543,7 +544,7 @@ namespace TShockAPI check = "none"; foreach (Item item in player.TPlayer.armor) { - if (!player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(item.name, player)) + if (!player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned(item.name, player)) { player.SetBuff(30, 120); //Bleeding player.SetBuff(36, 120); //Broken Armor @@ -557,7 +558,7 @@ namespace TShockAPI player.SetBuff(32, 120); //Slow player.SetBuff(23, 120); //Cursed } - else if(!player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(player.TPlayer.inventory[player.TPlayer.selectedItem].name, player)) + else if(!player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned(player.TPlayer.inventory[player.TPlayer.selectedItem].name, player)) { player.SetBuff(23, 120); //Cursed } @@ -578,9 +579,9 @@ namespace TShockAPI player.Group = Users.GetGroupForIP(player.IP); } - if (TShock.Utils.ActivePlayers() + 1 > Config.MaxSlots + 20) + if (Utils.ActivePlayers() + 1 > Config.MaxSlots + 20) { - TShock.Utils.ForceKick(player, Config.ServerFullNoReservedReason); + Utils.ForceKick(player, Config.ServerFullNoReservedReason); handler.Handled = true; return; } @@ -592,27 +593,27 @@ namespace TShockAPI if (ban != null) { - TShock.Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason)); + Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason)); handler.Handled = true; return; } if (!FileTools.OnWhitelist(player.IP)) { - TShock.Utils.ForceKick(player, "Not on whitelist."); + Utils.ForceKick(player, "Not on whitelist."); handler.Handled = true; return; } - if (TShock.Geo != null) + if (Geo != null) { - var code = TShock.Geo.TryGetCountryCode(IPAddress.Parse(player.IP)); - player.Country = code == null ? "N/A" : MaxMind.GeoIPCountry.GetCountryNameByCode(code); + var code = Geo.TryGetCountryCode(IPAddress.Parse(player.IP)); + player.Country = code == null ? "N/A" : GeoIPCountry.GetCountryNameByCode(code); if (code == "A1") { - if (TShock.Config.KickProxyUsers) + if (Config.KickProxyUsers) { - TShock.Utils.ForceKick(player, "Proxies are not allowed"); + Utils.ForceKick(player, "Proxies are not allowed"); handler.Handled = true; return; } @@ -637,7 +638,7 @@ namespace TShockAPI if (ban != null) { - TShock.Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason)); + Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason)); handler.Handled = true; return; } @@ -650,7 +651,7 @@ namespace TShockAPI if (tsplr != null && tsplr.ReceivedInfo) { - TShock.Utils.Broadcast(tsplr.Name + " has left", Color.Yellow); + Utils.Broadcast(tsplr.Name + " has left", Color.Yellow); Log.Info(string.Format("{0} left.", tsplr.Name)); if (tsplr.IsLoggedIn) @@ -678,7 +679,7 @@ namespace TShockAPI return; } - if (!TShock.Utils.ValidString(text)) + if (!Utils.ValidString(text)) { e.Handled = true; return; @@ -698,7 +699,7 @@ namespace TShockAPI } else if (!tsplr.mute) { - TShock.Utils.Broadcast(String.Format(TShock.Config.ChatFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix, text), tsplr.Group.R, tsplr.Group.G, tsplr.Group.B); + Utils.Broadcast(String.Format(Config.ChatFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix, text), tsplr.Group.R, tsplr.Group.G, tsplr.Group.B); e.Handled = true; } else if (tsplr.mute) @@ -815,7 +816,7 @@ namespace TShockAPI return; } - TShock.Utils.ShowFileToUser(player, "motd.txt"); + Utils.ShowFileToUser(player, "motd.txt"); if (Config.PvPMode == "always" && !player.TPlayer.hostile) { @@ -879,7 +880,7 @@ namespace TShockAPI void OnNpcSetDefaults(SetDefaultsEventArgs e) { - if (TShock.Itembans.ItemIsBanned(e.Object.name, null) ) + if (Itembans.ItemIsBanned(e.Object.name, null) ) { e.Object.SetDefaults(0); } @@ -959,8 +960,8 @@ namespace TShockAPI private void OnSaveWorld(bool resettime, HandledEventArgs e) { - TShock.Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red); - Thread SaveWorld = new Thread(TShock.Utils.SaveWorld); + Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red); + Thread SaveWorld = new Thread(Utils.SaveWorld); SaveWorld.Start(); e.Handled = true; } @@ -984,7 +985,7 @@ namespace TShockAPI } else { - Main.invasionSize = 100 + (Config.InvasionMultiplier * TShock.Utils.ActivePlayers()); + Main.invasionSize = 100 + (Config.InvasionMultiplier * Utils.ActivePlayers()); } Main.invasionWarn = 0; @@ -1010,22 +1011,22 @@ namespace TShockAPI switch (random) { case 0: - TShock.Utils.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount)); + Utils.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount)); break; case 1: - TShock.Utils.Broadcast(string.Format("Fatality! {0} goblins killed!", KillCount)); + Utils.Broadcast(string.Format("Fatality! {0} goblins killed!", KillCount)); break; case 2: - TShock.Utils.Broadcast(string.Format("Number of 'noobs' killed to date: {0}", KillCount)); + Utils.Broadcast(string.Format("Number of 'noobs' killed to date: {0}", KillCount)); break; case 3: - TShock.Utils.Broadcast(string.Format("Duke Nukem would be proud. {0} goblins killed.", KillCount)); + Utils.Broadcast(string.Format("Duke Nukem would be proud. {0} goblins killed.", KillCount)); break; case 4: - TShock.Utils.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount)); + Utils.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount)); break; case 5: - TShock.Utils.Broadcast(string.Format("{0} copies of Call of Duty smashed.", KillCount)); + Utils.Broadcast(string.Format("{0} copies of Call of Duty smashed.", KillCount)); break; } } @@ -1038,12 +1039,12 @@ namespace TShockAPI return true; } - if (type == 17 && !player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Dirt Rod", player)) //Dirt Rod Projectile + if (type == 17 && !player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned("Dirt Rod", player)) //Dirt Rod Projectile { return true; } - if ((type == 42 || type == 65 || type == 68) && !player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Sandgun", player)) //Sandgun Projectiles + if ((type == 42 || type == 65 || type == 68) && !player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned("Sandgun", player)) //Sandgun Projectiles { return true; } @@ -1051,7 +1052,7 @@ namespace TShockAPI Projectile proj = new Projectile(); proj.SetDefaults(type); - if (!player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(proj.name, player)) + if (!player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned(proj.name, player)) { return true; } @@ -1066,7 +1067,7 @@ namespace TShockAPI public static bool CheckRangePermission(TSPlayer player, int x, int y, int range = 32) { - if (TShock.Config.RangeChecks && ((Math.Abs(player.TileX - x) > 32) || (Math.Abs(player.TileY - y) > 32))) + if (Config.RangeChecks && ((Math.Abs(player.TileX - x) > 32) || (Math.Abs(player.TileY - y) > 32))) { return true; } @@ -1080,12 +1081,12 @@ namespace TShockAPI player.SendMessage("You do not have permission to build!", Color.Red); return true; } - if (!player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(tileX, tileY, player) && TShock.Regions.InArea(tileX, tileY)) + if (!player.Group.HasPermission(Permissions.editspawn) && !Regions.CanBuild(tileX, tileY, player) && Regions.InArea(tileX, tileY)) { player.SendMessage("Region protected from changes.", Color.Red); return true; } - if (TShock.Config.DisableBuild) + if (Config.DisableBuild) { if (!player.Group.HasPermission(Permissions.editspawn)) { @@ -1093,11 +1094,11 @@ namespace TShockAPI return true; } } - if (TShock.Config.SpawnProtection) + if (Config.SpawnProtection) { if (!player.Group.HasPermission(Permissions.editspawn)) { - var flag = TShock.CheckSpawn(tileX, tileY); + var flag = CheckSpawn(tileX, tileY); if (flag) { player.SendMessage("Spawn protected from changes.", Color.Red); @@ -1119,7 +1120,7 @@ namespace TShockAPI float num2 = value1.X - value2.X; float num = value1.Y - value2.Y; float num3 = (num2 * num2) + (num * num); - return (float)Math.Sqrt((double)num3); + return (float)Math.Sqrt(num3); } public static bool HackedHealth(TSPlayer player) @@ -1300,7 +1301,7 @@ namespace TShockAPI RconHandler.Password = file.RconPassword; RconHandler.ListenPort = file.RconPort; - TShock.Utils.HashAlgo = file.HashAlgorithm; + Utils.HashAlgo = file.HashAlgorithm; } } } \ No newline at end of file diff --git a/TShockAPI/UpdateManager.cs b/TShockAPI/UpdateManager.cs index 8aa168c1..ca6f9d81 100644 --- a/TShockAPI/UpdateManager.cs +++ b/TShockAPI/UpdateManager.cs @@ -15,9 +15,9 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + using System; using System.Collections.Generic; - using System.Net; using System.Threading; using Newtonsoft.Json; diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index de54a005..7e924c7c 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -15,9 +15,9 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + using System; using System.Collections.Generic; - using System.IO; using System.Linq; using System.Net; @@ -26,7 +26,6 @@ using System.Security.Cryptography; using System.Text; using Terraria; - namespace TShockAPI { public class Utils