diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index d4755ea2..60109f98 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -101,6 +101,7 @@ namespace TShockAPI commands.Add(new Command("help", "", new CommandDelegate(Help))); commands.Add(new Command("slap", "pvpfun", new CommandDelegate(Slap))); commands.Add(new Command("off-nosave", "maintenance", new CommandDelegate(OffNoSave))); + commands.Add(new Command("protectspawn", "cfg", new CommandDelegate(ProtectSpawn))); } #region Command Methods @@ -602,6 +603,12 @@ namespace TShockAPI else Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /slap [dmg]", new float[] { 255f, 0f, 0f }); } + + public static void ProtectSpawn(CommandArgs args) + { + ConfigurationManager.spawnProtect = (ConfigurationManager.spawnProtect == false); + Tools.SendMessage(args.PlayerID, "Spawn is now " + (ConfigurationManager.spawnProtect ? "protected" : "open") + "."); + } #endregion } } diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 1ce76424..868bcb2b 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -23,5 +23,7 @@ namespace TShockAPI public bool KickKillTileAbusers = false; public bool BanExplosives = true; public bool KickExplosives = true; + public bool SpawnProtection = true; + public int SpawnProtectionRadius = 5; } } diff --git a/TShockAPI/ConfigurationManager.cs b/TShockAPI/ConfigurationManager.cs index aacce18c..980791fc 100644 --- a/TShockAPI/ConfigurationManager.cs +++ b/TShockAPI/ConfigurationManager.cs @@ -29,6 +29,8 @@ namespace TShockAPI public static bool kickTnt = false; public static bool banBoom = true; public static bool kickBoom = true; + public static bool spawnProtect = true; + public static int spawnProtectRadius = 5; public enum NPCList : int { @@ -58,10 +60,16 @@ namespace TShockAPI kickTnt = cfg.KickKillTileAbusers; banBoom = cfg.BanExplosives; kickBoom = cfg.KickExplosives; + spawnProtect = cfg.SpawnProtection; + spawnProtectRadius = cfg.SpawnProtectionRadius; } public static void WriteJsonConfiguration() { + if (!System.IO.Directory.Exists(FileTools.SaveDir)) + { + System.IO.Directory.CreateDirectory(FileTools.SaveDir); + } if (System.IO.File.Exists(FileTools.SaveDir + "config.json")) { return; @@ -87,6 +95,8 @@ namespace TShockAPI cfg.KickKillTileAbusers = true; cfg.BanExplosives = true; cfg.KickExplosives = true; + cfg.SpawnProtection = true; + cfg.SpawnProtectionRadius = 5; string json = JsonConvert.SerializeObject(cfg, Formatting.Indented); TextWriter tr = new StreamWriter(FileTools.SaveDir + "config.json"); diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 04b1ff4e..99b24dc9 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -15,7 +15,7 @@ namespace TShockAPI public static string saveDir = "./tshock/"; - public static Version VersionNum = new Version(1, 5, 0, 1); + public static Version VersionNum = new Version(1, 6, 0, 0); public static bool shownVersion = false; @@ -104,6 +104,14 @@ namespace TShockAPI public override void Initialize() { + try + { + FileTools.SetupConfig(); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } Log.Initialize(FileTools.SaveDir + "log.txt", LogLevel.All, true); Log.Info("Starting..."); GameHooks.OnPreInitialize += OnPreInit; @@ -138,8 +146,6 @@ namespace TShockAPI NetHooks.OnPreGetData -= GetData; NetHooks.OnGreetPlayer -= new NetHooks.GreetPlayerD(OnGreetPlayer); NpcHooks.OnStrikeNpc -= new NpcHooks.StrikeNpcD(NpcHooks_OnStrikeNpc); - ConfigurationManager.WriteJsonConfiguration(); - Log.Info("Shutting down..."); } /* @@ -168,6 +174,18 @@ namespace TShockAPI byte type = br.ReadByte(); int x = br.ReadInt32(); int y = br.ReadInt32(); + byte typetile = br.ReadByte(); + if (type == 0 || type == 1) + if (ConfigurationManager.spawnProtect) + if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) + { + var flag = CheckSpawn(x, y); + if (flag) + { + Tools.SendMessage(e.Msg.whoAmI, "The spawn is protected!", new float[] { 255f, 0f, 0f }); + e.Handled = true; + } + } if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && Main.player[e.Msg.whoAmI].active) { @@ -192,6 +210,7 @@ namespace TShockAPI Main.player[e.Msg.whoAmI].hostile = true; NetMessage.SendData(30, -1, -1, "", e.Msg.whoAmI); e.Handled = true; + return; } else if (e.MsgID == 0x0A) //SendSection { @@ -304,6 +323,30 @@ namespace TShockAPI } } } + else if (e.MsgID == 0x30) + { + int x; + int y; + byte liquid; + bool lava; + using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))) + { + x = br.ReadInt32(); + y = br.ReadInt32(); + liquid = br.ReadByte(); + lava = br.ReadBoolean(); + } + if (ConfigurationManager.spawnProtect) + if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) + { + var flag = CheckSpawn(x, y); + if (flag) + { + Tools.SendMessage(e.Msg.whoAmI, "The spawn is protected!", new float[] { 255f, 0f, 0f }); + e.Handled = true; + } + } + } else if (e.MsgID == 0x2C) // KillMe { byte id; @@ -640,5 +683,16 @@ namespace TShockAPI } return false; } + + public static bool CheckSpawn(int x, int y) + { + Vector2 tile = new Vector2((float)x, (float)y); + Vector2 spawn = new Vector2((float)Main.spawnTileX, (float)Main.spawnTileY); + var distance = Vector2.Distance(spawn, tile); + if (distance > (float)ConfigurationManager.spawnProtectRadius) + return false; + else + return true; + } } } \ No newline at end of file diff --git a/TShockAPI/config/groups.txt b/TShockAPI/config/groups.txt index 119c51cb..8dfc39fb 100644 --- a/TShockAPI/config/groups.txt +++ b/TShockAPI/config/groups.txt @@ -8,11 +8,12 @@ #ALWAYS DECLARE A GROUP'S PARENT BEFORE YOU DECLARE THE GROUP #currently avaliable permissions: kick ban ignorecheatdetection -#power cfg causeevents spawnboss tp +#maintenance cfg causeevents spawnboss tp #spawnmob cheat kill pvpfun -#immunetoban immunetokick +#immunetoban immunetokick editspawn +#ignoregriefdetection default null -newadmin default kick +newadmin default kick editspawn admin newadmin ban causeevents spawnboss spawnmob tp immunetokick kill -trustedadmin admin ignorecheatdetection power cfg cheat pvpfun ignorecheatdetection immunetoban \ No newline at end of file +trustedadmin admin ignorecheatdetection maintenance cfg cheat pvpfun ignorecheatdetection immunetoban ignoregriefdetection \ No newline at end of file diff --git a/release-docs/changes.txt b/release-docs/changes.txt new file mode 100644 index 00000000..bc454cba --- /dev/null +++ b/release-docs/changes.txt @@ -0,0 +1,70 @@ +For the full list of changes, please take a look at GitHub: +https://github.com/TShock/TShock/commits/master + +Changes in API release 1.6.0.0: + - Added spawn protection + - Fixed numerous bugs + - Added a few commands + +Changes in API release 1.5.0.1: + - Fixed cheat detection + +Changes in API release 1.5.0.0: + - Added /time + - Added /kill + - Fixed /item + - Added /slap [dmg] + - Added broadcast event for kill tile abuse + - Fixed teleport somewhat + - More cheat detection + - Extended new cheat protection to mana + - Update player exploit patched + - Fixed /spawn + - Made /invasion a toggle + +Changes in API release 1.4.0.0: + - The configuration file is now located at config.json + - Something else. + +Changes in API release 1.3.0.1: + - Re-coded the entire command system + - Re-coded the help command + - Implemented what seems to be the most recurring blacklist ever + +Changes in API release 1.3.0.0: + - Added /maxspawns + - Added /spawnrate + - Resetup the configuration file to read spawn rate information. + - Patched the ability for clients to spawn NPCs + - Patched the ability for clients to rewrite the server through SendSection + - Make sure to use this Terraria.exe for the server: (http://dl.dropbox.com/u/29760911/Terraria.exe) + -- Allows spawn rates to be changed + +Changes in API release 1.2.0.1: + - New update system + +Changes in API release 1.2: + - Added /butcher + - Added /heal + - /spawnmob now takes another argument for the amount + - /item now adds items to the inventory directly + - This update credit to Deathmax + +Changes in API release 1.1: + - Added /tp + - Added /tphere + - Added /spawnmob + - Added /item + - Fixed /spawn + - Updated /help + - Everything in this update credit to Deathmax, High, and Shank + +Changes in API release 0.1: + - Added /save to save the world + - Added /spawn to teleport to spawn + - Added broken teleport stuff + - Major re-write of the anti-tnt code (now uses a blacklist instead of a whitelist) + - Fixed server crashing bug of the anti-tnt code + - Made the anti-tnt code decrease the threshold instantaniously + + Re added the update checker. \ No newline at end of file diff --git a/release-docs/documentation.txt b/release-docs/documentation.txt new file mode 100644 index 00000000..ebee2aa4 --- /dev/null +++ b/release-docs/documentation.txt @@ -0,0 +1,3 @@ +Documentation, NPC lists, Spawn lists, and more can be found on GitHub at: + +https://github.com/TShock/TShock/wiki \ No newline at end of file diff --git a/release-docs/installation.txt b/release-docs/installation.txt new file mode 100644 index 00000000..26b88e24 --- /dev/null +++ b/release-docs/installation.txt @@ -0,0 +1,3 @@ +For installation instructions, please refer to: + +https://github.com/TShock/TShock/wiki/Installation-instructions \ No newline at end of file