diff --git a/DBEditor/Main.cs b/DBEditor/Main.cs index d5a98e2c..180d779b 100644 --- a/DBEditor/Main.cs +++ b/DBEditor/Main.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.IO; using System.Security.Cryptography; -using Community.CsharpSqlite.SQLiteClient; +using Mono.Data.Sqlite; using MySql.Data.MySqlClient; using System.Windows.Forms; diff --git a/DBEditor/TShockDBEditor.csproj b/DBEditor/TShockDBEditor.csproj index 3d95e73b..ac8260c1 100644 --- a/DBEditor/TShockDBEditor.csproj +++ b/DBEditor/TShockDBEditor.csproj @@ -26,6 +26,7 @@ true 0 1.0.0.%2a + false false true @@ -49,8 +50,8 @@ 4 - - ..\SqlBins\Community.CsharpSqlite.SQLiteClient.dll + + ..\SqlBins\Mono.Data.Sqlite.dll False diff --git a/SqlBins/Mono.Data.Sqlite.dll b/SqlBins/Mono.Data.Sqlite.dll new file mode 100644 index 00000000..ce600dbc Binary files /dev/null and b/SqlBins/Mono.Data.Sqlite.dll differ diff --git a/SqlBins/sqlite3.dll b/SqlBins/sqlite3.dll new file mode 100644 index 00000000..0c2371bd Binary files /dev/null and b/SqlBins/sqlite3.dll differ diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 8610c7ae..64db33a5 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -198,6 +198,8 @@ namespace TShockAPI add(Permissions.hardmode, StartHardMode, "hardmode"); add(Permissions.hardmode, DisableHardMode, "stophardmode", "disablehardmode"); add(Permissions.cfg, ServerInfo, "stats"); + add(Permissions.converthardmode, ConvertCorruption, "convertcorruption"); + add(Permissions.converthardmode, ConvertHallow, "converthallow"); } public static bool HandleCommand(TSPlayer player, string text) @@ -1223,6 +1225,58 @@ namespace TShockAPI Main.hardMode = false; } + private static void ConvertCorruption(CommandArgs args) + { + TShock.Utils.Broadcast("Server is might 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 25: + Main.tile[x, y].type = 117; + break; + case 23: + Main.tile[x, y].type = 109; + break; + case 112: + Main.tile[x, y].type = 116; + break; + default: + continue; + } + } + } + TShock.Utils.Broadcast("Corruption conversion done."); + } + + private static void ConvertHallow(CommandArgs args) + { + TShock.Utils.Broadcast("Server is might 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 117: + Main.tile[x, y].type = 25; + break; + case 109: + Main.tile[x, y].type = 23; + break; + case 116: + Main.tile[x, y].type = 112; + break; + default: + continue; + } + } + } + TShock.Utils.Broadcast("Hallow conversion done."); + } + #endregion Cause Events and Spawn Monsters Commands #region Teleport Commands @@ -1271,7 +1325,7 @@ namespace TShockAPI args.Player.SendMessage("Invalid player!", Color.Red); else if (players.Count > 1) args.Player.SendMessage("More than one player matched!", Color.Red); - else if (!args.Player.TPAllow && !args.Player.Group.HasPermission(Permissions.tpall)) + else if (!players[0].TPAllow && !args.Player.Group.HasPermission(Permissions.tpall)) { var plr = players[0]; args.Player.SendMessage(plr.Name + " Has Selected For Users Not To Teleport To Them"); @@ -2497,7 +2551,7 @@ namespace TShockAPI { if (args.Parameters.Count < 1) { - args.Player.SendMessage("Invalid syntax! Proper syntax: /item [item amount]", Color.Red); + args.Player.SendMessage("Invalid syntax! Proper syntax: /item [item amount] [prefix id/name]", Color.Red); return; } if (args.Parameters[0].Length == 0) @@ -2506,7 +2560,16 @@ namespace TShockAPI return; } int itemAmount = 0; - int.TryParse(args.Parameters[args.Parameters.Count - 1], out itemAmount); + int prefix = 0; + if (args.Parameters.Count == 2) + int.TryParse(args.Parameters[1], out itemAmount); + else if (args.Parameters.Count == 3) + { + int.TryParse(args.Parameters[1], out itemAmount); + var found = TShock.Utils.GetPrefixByIdOrName(args.Parameters[2]); + if (found.Count == 1) + prefix = found[0]; + } var items = TShock.Utils.GetItemByIdOrName(args.Parameters[0]); if (items.Count == 0) { @@ -2525,7 +2588,7 @@ namespace TShockAPI { if (itemAmount == 0 || itemAmount > item.maxStack) itemAmount = item.maxStack; - args.Player.GiveItem(item.type, item.name, item.width, item.height, itemAmount); + args.Player.GiveItem(item.type, item.name, item.width, item.height, itemAmount, prefix); args.Player.SendMessage(string.Format("Gave {0} {1}(s).", itemAmount, item.name)); } else @@ -2544,7 +2607,7 @@ namespace TShockAPI { if (args.Parameters.Count < 2) { - args.Player.SendMessage("Invalid syntax! Proper syntax: /give [item amount]", Color.Red); + args.Player.SendMessage("Invalid syntax! Proper syntax: /give [item amount] [prefix id/name]", Color.Red); return; } if (args.Parameters[0].Length == 0) @@ -2558,13 +2621,20 @@ namespace TShockAPI return; } int itemAmount = 0; + int prefix = 0; var items = TShock.Utils.GetItemByIdOrName(args.Parameters[0]); args.Parameters.RemoveAt(0); string plStr = args.Parameters[0]; args.Parameters.RemoveAt(0); - if (args.Parameters.Count > 0) - int.TryParse(args.Parameters[args.Parameters.Count - 1], out itemAmount); - + if (args.Parameters.Count == 1) + int.TryParse(args.Parameters[0], out itemAmount); + else if (args.Parameters.Count == 2) + { + int.TryParse(args.Parameters[0], out itemAmount); + var found = TShock.Utils.GetPrefixByIdOrName(args.Parameters[1]); + if (found.Count == 1) + prefix = found[0]; + } if (items.Count == 0) { @@ -2595,7 +2665,7 @@ namespace TShockAPI { if (itemAmount == 0 || itemAmount > item.maxStack) itemAmount = item.maxStack; - plr.GiveItem(item.type, item.name, item.width, item.height, itemAmount); + plr.GiveItem(item.type, item.name, item.width, item.height, itemAmount, prefix); args.Player.SendMessage(string.Format("Gave {0} {1} {2}(s).", plr.Name, itemAmount, item.name)); plr.SendMessage(string.Format("{0} gave you {1} {2}(s).", args.Player.Name, itemAmount, item.name)); } @@ -2618,39 +2688,29 @@ namespace TShockAPI int radius = 50; if (args.Parameters.Count > 0) { - if (args.Parameters[0].ToLower() == "all") { - radius = Int32.MaxValue / 16; - } else { - try { - radius = Convert.ToInt32(args.Parameters[0]); - } catch (Exception) { args.Player.SendMessage("Please either enter the keyword \"all\", or the block radius you wish to delete all items from.", Color.Red); return; } - } } int count = 0; for (int i = 0; i < 200; i++) { - if ((Math.Sqrt(Math.Pow(Main.item[i].position.X - args.Player.X, 2) + Math.Pow(Main.item[i].position.Y - args.Player.Y, 2)) < radius * 16) && (Main.item[i].active)) { - Main.item[i].active = false; NetMessage.SendData(0x15, -1, -1, "", i, 0f, 0f, 0f, 0); count++; } - } args.Player.SendMessage("All " + count.ToString() + " items within a radius of " + radius.ToString() + " have been deleted."); diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index c4ad5de8..11007055 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -214,6 +214,18 @@ namespace TShockAPI [Description("Disabling this prevents players from being banned or kicked based on item stacks.")] public bool EnableItemStackChecks = true; + [Description("Kicks users using a proxy as identified with the GeoIP database")] + public bool KickProxyUsers = true; + + [Description("Kicks banned users by their name")] + public bool EnableNameBans = false; + + [Description("Kicks banned users by their IP")] + public bool EnableIPBans = true; + + [Description("Disables hardmode, can't never be activated. Overrides /starthardmode")] + public bool DisableHardmode = false; + public static ConfigFile Read(string path) { if (!File.Exists(path)) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 035d3b43..56aa3755 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -118,6 +118,7 @@ namespace TShockAPI {PacketTypes.TileGetSection, HandleGetSection}, {PacketTypes.UpdateNPCHome, UpdateNPCHome }, {PacketTypes.PlayerAddBuff, HandlePlayerBuff}, + {PacketTypes.ItemDrop, HandleItemDrop} }; } @@ -156,7 +157,7 @@ namespace TShockAPI var itemname = it.name; if (!args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(itemname)) - args.Player.Disconnect("Using banned item: " + itemname + ", remove it and rejoin");; + args.Player.Disconnect("Using banned item: " + itemname + ", remove it and rejoin"); if (stack>it.maxStack) { string reason = string.Format("Item Stack Hack Detected: player has {0} {1}(s) in one stack", stack,itemname); @@ -266,7 +267,7 @@ namespace TShockAPI args.Player.LastTileChangeNotify = DateTime.UtcNow; } args.Player.SendTileSquare(x, y); - return true; + continue; } if (TShock.Config.DisableBuild) { @@ -278,7 +279,7 @@ namespace TShockAPI args.Player.LastTileChangeNotify = DateTime.UtcNow; } args.Player.SendTileSquare(x, y); - return true; + continue; } } if (TShock.Config.SpawnProtection) @@ -294,7 +295,7 @@ namespace TShockAPI args.Player.LastTileChangeNotify = DateTime.UtcNow; } args.Player.SendTileSquare(x, y); - return true; + continue; } } } @@ -389,6 +390,11 @@ namespace TShockAPI tile.type = 112; changed = true; } + else if (tile.type == 112 && newtile.Type == 53) + { + tile.type = 53; + changed = true; + } } } @@ -537,7 +543,7 @@ namespace TShockAPI args.Player.TileThreshold++; var coords = new Vector2(x, y); if (!args.Player.TilesDestroyed.ContainsKey(coords)) - args.Player.TilesDestroyed.Add(coords, Main.tile[x, y].Data); + args.Player.TilesDestroyed.Add(coords, Main.tile[x, y]); } if ((DateTime.UtcNow - args.Player.LastExplosive).TotalMilliseconds < 1000) @@ -616,12 +622,24 @@ namespace TShockAPI byte owner = args.Data.ReadInt8(); byte type = args.Data.ReadInt8(); - if (ident > Main.maxProjectiles || ident < 0) + var index = TShock.Utils.SearchProjectile(ident); + + if (index > Main.maxProjectiles || index < 0) { TShock.Utils.HandleGriefer(args.Player, TShock.Config.ExplosiveAbuseReason); return true; } + if (dmg > 125) // random number, if false positives, increase + { + TShock.Utils.SendLogs(string.Format("{0} sent a projectile with more than 125 damage.", args.Player.Name), Color.Red); + if (dmg > 175) + { + TShock.Utils.HandleCheater(args.Player, TShock.Config.ProjectileAbuseReason); + return true; + } + } + if (type == 23) { if (velx == 0f && vely == 0f && dmg == 99) @@ -633,32 +651,34 @@ namespace TShockAPI return true; } - if (type == 29 || type == 28 || type == 37) //need more explosives from 1.1 { Log.Debug(string.Format("Explosive(PlyXY:{0}_{1}, Type:{2})", args.Player.TileX, args.Player.TileY, type)); - if (TShock.Config.DisableExplosives && (!args.Player.Group.HasPermission(Permissions.useexplosives) || !args.Player.Group.HasPermission(Permissions.ignoregriefdetection))) + if (TShock.Config.DisableExplosives && (!args.Player.Group.HasPermission(Permissions.useexplosives) && !args.Player.Group.HasPermission(Permissions.ignoregriefdetection))) { - Main.projectile[ident].type = 0; - Main.projectile[ident].owner = 255; - args.Player.SendData(PacketTypes.ProjectileNew, "", ident); + //Main.projectile[index].SetDefaults(0); + Main.projectile[index].type = 0; + //Main.projectile[index].owner = 255; + //Main.projectile[index].position = new Vector2(0f, 0f); + Main.projectile[index].identity = ident; + args.Player.SendData(PacketTypes.ProjectileNew, "", index); args.Player.SendMessage("Explosives are disabled!", Color.Red); args.Player.LastExplosive = DateTime.UtcNow; - //return true; + return true; } else return TShock.Utils.HandleExplosivesUser(args.Player, TShock.Config.ExplosiveAbuseReason); } if (args.Player.Index != owner)//ignores projectiles whose senders aren't the same as their owners { - TShock.Players[args.Player.Index].SendData(PacketTypes.ProjectileNew, "", ident);//update projectile on senders end so he knows it didnt get created + TShock.Players[args.Player.Index].SendData(PacketTypes.ProjectileNew, "", index);//update projectile on senders end so he knows it didnt get created return true; } Projectile proj = new Projectile(); proj.SetDefaults(type); if (proj.hostile)//ignores all hostile projectiles from the client they shouldn't be sending them anyways { - TShock.Players[args.Player.Index].SendData(PacketTypes.ProjectileNew, "", ident); + TShock.Players[args.Player.Index].SendData(PacketTypes.ProjectileNew, "", index); return true; } return false; @@ -717,7 +737,7 @@ namespace TShockAPI int tileY = Math.Abs(y); bool bucket = false; - for (int i = 0; i < 44; i++) + for (int i = 0; i < 49; i++) { if (args.TPlayer.inventory[i].type >= 205 && args.TPlayer.inventory[i].type <= 207) { @@ -911,5 +931,29 @@ namespace TShockAPI { return !args.Player.Group.HasPermission(Permissions.ignoregriefdetection); } + + private static bool HandleItemDrop(GetDataHandlerArgs args) + { + var id = args.Data.ReadInt16(); + var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); + var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); + var stacks = args.Data.ReadInt8(); + var prefix = args.Data.ReadInt8(); + var type = args.Data.ReadInt16(); + + var item = new Item(); + item.netDefaults(type); + if (TShock.Config.EnableItemStackChecks) + { + if (stacks > item.maxStack) + { + TShock.Utils.HandleCheater(args.Player, "Dropped illegal stack of item"); + return true; + } + } + if (TShock.Itembans.ItemIsBanned(item.name)) + TShock.Utils.HandleCheater(args.Player, "Dropped banned item"); + return false; + } } } diff --git a/TShockAPI/PacketBufferer.cs b/TShockAPI/PacketBufferer.cs index 0257c78f..7c6ffc5e 100644 --- a/TShockAPI/PacketBufferer.cs +++ b/TShockAPI/PacketBufferer.cs @@ -169,7 +169,10 @@ namespace TShockAPI { if (socket.tcpClient.Client != null && socket.tcpClient.Client.Poll(0, SelectMode.SelectWrite)) { - socket.tcpClient.Client.Send(buffer, offset, count, SocketFlags.None); + if (Main.runningMono) + socket.networkStream.Write(buffer, offset, count); + else + socket.tcpClient.Client.Send(buffer, offset, count, SocketFlags.None); return true; } } @@ -179,6 +182,9 @@ namespace TShockAPI catch (SocketException) { } + catch (IOException) + { + } return false; } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index aa2be51a..1856abd5 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -153,6 +153,9 @@ namespace TShockAPI [Description("Users can tp to anyone")] public static readonly string tpall; + [Description("User can convert hallow into corruption and vice-versa")] + public static readonly string converthardmode; + static Permissions() { foreach (var field in typeof(Permissions).GetFields()) diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index 71927ec9..22671a01 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.3.4.1213")] -[assembly: AssemblyFileVersion("3.3.4.1213")] +[assembly: AssemblyVersion("3.3.4.1218")] +[assembly: AssemblyFileVersion("3.3.4.1218")] diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 1cda0126..7b051294 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -31,7 +31,7 @@ namespace TShockAPI public static readonly TSServerPlayer Server = new TSServerPlayer(); public static readonly TSPlayer All = new TSPlayer("All"); public int TileThreshold { get; set; } - public Dictionary TilesDestroyed { get; protected set; } + public Dictionary TilesDestroyed { get; protected set; } public bool SyncHP { get; set; } public bool SyncMP { get; set; } public Group Group { get; set; } @@ -62,6 +62,7 @@ namespace TShockAPI public bool ForceSpawn = false; public string Country = "??"; public int Difficulty; + private string CacheIP; public bool RealPlayer { @@ -75,7 +76,10 @@ namespace TShockAPI { get { - return RealPlayer ? TShock.Utils.GetRealIP(Netplay.serverSock[Index].tcpClient.Client.RemoteEndPoint.ToString()) : ""; + if (string.IsNullOrEmpty(CacheIP)) + return CacheIP = RealPlayer ? (Netplay.serverSock[Index].tcpClient.Connected ? TShock.Utils.GetRealIP(Netplay.serverSock[Index].tcpClient.Client.RemoteEndPoint.ToString()) : "") : ""; + else + return CacheIP; } } /// @@ -145,14 +149,14 @@ namespace TShockAPI public TSPlayer(int index) { - TilesDestroyed = new Dictionary(); + TilesDestroyed = new Dictionary(); Index = index; Group = new Group("null"); } protected TSPlayer(String playerName) { - TilesDestroyed = new Dictionary(); + TilesDestroyed = new Dictionary(); Index = -1; FakePlayer = new Player { name = playerName, whoAmi = -1 }; Group = new Group("null"); @@ -268,15 +272,16 @@ namespace TShockAPI return false; } - public virtual void GiveItem(int type, string name, int width, int height, int stack) + public virtual void GiveItem(int type, string name, int width, int height, int stack, int prefix = 0) { - int itemid = Item.NewItem((int)X, (int)Y, width, height, type, stack, true); + int itemid = Item.NewItem((int)X, (int)Y, width, height, type, stack, true, prefix); // This is for special pickaxe/hammers/swords etc Main.item[itemid].SetDefaults(name); // The set default overrides the wet and stack set by NewItem Main.item[itemid].wet = Collision.WetCollision(Main.item[itemid].position, Main.item[itemid].width, Main.item[itemid].height); Main.item[itemid].stack = stack; Main.item[itemid].owner = Index; + Main.item[itemid].prefix = (byte) prefix; NetMessage.SendData((int)PacketTypes.ItemDrop, -1, -1, "", itemid, 0f, 0f, 0f); NetMessage.SendData((int)PacketTypes.ItemOwner, -1, -1, "", itemid, 0f, 0f, 0f); } @@ -418,12 +423,12 @@ namespace TShockAPI NetMessage.SendData((int)PacketTypes.NpcStrike, -1, -1, "", npcid, damage, knockBack, hitDirection); } - public void RevertKillTile(Dictionary destroyedTiles) + public void RevertKillTile(Dictionary destroyedTiles) { // Update Main.Tile first so that when tile sqaure is sent it is correct - foreach (KeyValuePair entry in destroyedTiles) + foreach (KeyValuePair entry in destroyedTiles) { - Main.tile[(int)entry.Key.X, (int)entry.Key.Y].Data = entry.Value; + Main.tile[(int)entry.Key.X, (int)entry.Key.Y] = entry.Value; Log.Debug(string.Format("Reverted DestroyedTile(TileXY:{0}_{1}, Type:{2})", entry.Key.X, entry.Key.Y, Main.tile[(int)entry.Key.X, (int)entry.Key.Y].type)); } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 1899b94f..617d2e56 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -45,7 +45,7 @@ using TShockAPI.Net; namespace TShockAPI { - [APIVersion(1, 9)] + [APIVersion(1, 10)] public class TShock : TerrariaPlugin { public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; @@ -109,6 +109,8 @@ namespace TShockAPI [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] public override void Initialize() { + HandleCommandLine(Environment.GetCommandLineArgs()); + if (!Directory.Exists(SavePath)) Directory.CreateDirectory(SavePath); @@ -121,7 +123,6 @@ namespace TShockAPI try { - if (File.Exists(Path.Combine(SavePath, "tshock.pid"))) { Log.ConsoleInfo("TShock was improperly shut down. Please avoid this in the future, world corruption may result from this."); @@ -132,7 +133,7 @@ namespace TShockAPI ConfigFile.ConfigRead += OnConfigRead; FileTools.SetupConfig(); - HandleCommandLine(Environment.GetCommandLineArgs()); + HandleCommandLine_Port(Environment.GetCommandLineArgs()); if (Config.StorageType.ToLower() == "sqlite") { @@ -199,6 +200,7 @@ namespace TShockAPI NetHooks.GreetPlayer += OnGreetPlayer; NpcHooks.StrikeNpc += NpcHooks_OnStrikeNpc; ProjectileHooks.SetDefaults += OnProjectileSetDefaults; + WorldHooks.StartHardMode += OnStartHardMode; GetDataHandlers.InitGetDataHandler(); Commands.InitCommands(); @@ -384,6 +386,13 @@ namespace TShockAPI Log.ConsoleInfo("World path has been set to " + path); } } + } + } + + private void HandleCommandLine_Port(string[] parms) + { + for (int i = 0; i < parms.Length; i++) + { if (parms[i].ToLower() == "-port") { int port = Convert.ToInt32(parms[++i]); @@ -508,7 +517,14 @@ namespace TShockAPI return; } - var ban = Bans.GetBanByIp(player.IP); + var ipban = Bans.GetBanByIp(player.IP); + var nameban = Bans.GetBanByName(player.Name); + Ban ban = null; + if (ipban != null && Config.EnableIPBans) + ban = ipban; + else if (nameban != null && Config.EnableIPBans) + ban = nameban; + if (ban != null) { TShock.Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason)); @@ -718,6 +734,9 @@ namespace TShockAPI { var code = Geo.TryGetCountryCode(IPAddress.Parse(player.IP)); player.Country = code == null ? "N/A" : MaxMind.GeoIPCountry.GetCountryNameByCode(code); + if (code == "A1") + if (TShock.Config.KickProxyUsers) + TShock.Utils.Kick(player, "Proxies are not allowed"); Log.Info(string.Format("{0} ({1}) from '{2}' group from '{3}' joined.", player.Name, player.IP, player.Group.Name, player.Country)); TShock.Utils.Broadcast(player.Name + " is from the " + player.Country, Color.Yellow); } @@ -850,6 +869,12 @@ namespace TShockAPI e.Handled = true; } + void OnStartHardMode(HandledEventArgs e) + { + if (Config.DisableHardmode) + e.Handled = true; + } + /* * Useful stuff: * */ diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 311deee2..b1dd1445 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -248,7 +248,7 @@ namespace TShockAPI } //Method #2 - allows impartial matching var found = new List(); - for (int i = 1; i < Main.maxItemTypes; i++) + for (int i = -24; i < Main.maxItemTypes; i++) { try { @@ -284,7 +284,7 @@ namespace TShockAPI public List GetNPCByName(string name) { //Method #1 - must be exact match, allows support for different coloured slimes - for (int i = 1; i < Main.maxNPCTypes; i++) + for (int i = -17; i < Main.maxNPCTypes; i++) { NPC npc = new NPC(); npc.SetDefaults(name); @@ -309,10 +309,12 @@ namespace TShockAPI { return (id > 0 && id < Main.maxBuffs) ? Main.buffName[id] : "null"; } + public string GetBuffDescription(int id) { return (id > 0 && id < Main.maxBuffs) ? Main.buffTip[id] : "null"; } + public List GetBuffByName(string name) { for (int i = 1; i < Main.maxBuffs; i++) @@ -329,6 +331,51 @@ namespace TShockAPI return found; } + public string GetPrefixById(int id) + { + var item = new Item(); + item.SetDefaults(0); + item.prefix = (byte)id; + item.AffixName(); + return item.name.Trim(); + } + + public List GetPrefixByName(string name) + { + Item item = new Item(); + item.SetDefaults(0); + for (int i = 1; i < 83; i++) + { + item.prefix = (byte) i; + if (item.AffixName().Trim() == name) + return new List { i }; + } + var found = new List(); + for (int i = 1; i < 83; i++) + { + try + { + item.prefix = (byte) i; + if (item.AffixName().Trim().ToLower() == name.ToLower()) + return new List { i }; + if (item.AffixName().Trim().ToLower().StartsWith(name.ToLower())) + found.Add(i); + } + catch { } + } + return found; + } + + public List GetPrefixByIdOrName(string idOrName) + { + int type = -1; + if (int.TryParse(idOrName, out type) && type > 0 && type < 84) + { + return new List {type}; + } + return GetPrefixByName(idOrName); + } + /// /// Kicks all player from the server without checking for immunetokick permission. /// @@ -590,5 +637,15 @@ namespace TShockAPI } return true; } + + public int SearchProjectile(short identity) + { + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].identity == identity) + return i; + } + return 1000; + } } } diff --git a/TerrariaServerBins/TerrariaServer.exe b/TerrariaServerBins/TerrariaServer.exe index 8d7e11cf..792e4f9d 100644 Binary files a/TerrariaServerBins/TerrariaServer.exe and b/TerrariaServerBins/TerrariaServer.exe differ diff --git a/UnitTests/BanManagerTest.cs b/UnitTests/BanManagerTest.cs index d18ca714..52f19d9f 100644 --- a/UnitTests/BanManagerTest.cs +++ b/UnitTests/BanManagerTest.cs @@ -3,7 +3,7 @@ using System.Data; using System.Text; using System.Collections.Generic; using System.Linq; -using Community.CsharpSqlite.SQLiteClient; +using Mono.Data.Sqlite; using Microsoft.VisualStudio.TestTools.UnitTesting; using TShockAPI; using TShockAPI.DB; @@ -43,7 +43,7 @@ namespace UnitTests [TestMethod] public void FindBanTest() { - Assert.IsNotNull(Bans.GetBanByIp("127.0.0.1")); + D:\SVNs\TShock_GitHub\UnitTests\BanManagerTest.orderedtest Assert.IsNotNull(Bans.GetBanByIp("127.0.0.1")); TShock.Config.EnableBanOnUsernames = true; Assert.IsNotNull(Bans.GetBanByName("BanTest")); TShock.Config.EnableBanOnUsernames = false; diff --git a/UnitTests/GroupManagerTest.cs b/UnitTests/GroupManagerTest.cs index ab7912fc..2e4efc1d 100644 --- a/UnitTests/GroupManagerTest.cs +++ b/UnitTests/GroupManagerTest.cs @@ -3,7 +3,7 @@ using System.Data; using System.Text; using System.Collections.Generic; using System.Linq; -using Community.CsharpSqlite.SQLiteClient; +using Mono.Data.Sqlite; using Microsoft.VisualStudio.TestTools.UnitTesting; using TShockAPI; using TShockAPI.DB; diff --git a/UnitTests/ItemManagerTest.cs b/UnitTests/ItemManagerTest.cs index ef6ed314..7e19d5d6 100644 --- a/UnitTests/ItemManagerTest.cs +++ b/UnitTests/ItemManagerTest.cs @@ -10,7 +10,7 @@ using System.Diagnostics; using System.Net; using System.Reflection; using System.Threading; -using Community.CsharpSqlite.SQLiteClient; +using Mono.Data.Sqlite; using TShockAPI.DB; using TShockAPI; diff --git a/UnitTests/RegionManagerTest.cs b/UnitTests/RegionManagerTest.cs index 8fd1ea08..a8620117 100644 --- a/UnitTests/RegionManagerTest.cs +++ b/UnitTests/RegionManagerTest.cs @@ -5,7 +5,7 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Data; using TShockAPI; -using Community.CsharpSqlite.SQLiteClient; +using Mono.Data.Sqlite; using TShockAPI.DB; using Region = TShockAPI.DB.Region; diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index d8e57ddc..ec70bd7f 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -48,13 +48,10 @@ 4 - - ..\SqlBins\Community.CsharpSqlite.dll - - - ..\SqlBins\Community.CsharpSqlite.SQLiteClient.dll - + + ..\SqlBins\Mono.Data.Sqlite.dll + ..\SqlBins\MySql.Data.dll