diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 71851e36..abb1ba1e 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -223,6 +223,7 @@ namespace TShockAPI commands.Add(new Command("auth", "", AuthToken)); commands.Add(new Command("me", "", ThirdPerson)); commands.Add(new Command("p", "", PartyChat)); + commands.Add(new Command("rules", "", Rules)); commands.Add(new Command("antibuild", "editspawn", ToggleAntiBuild)); if (ConfigurationManager.distributationAgent != "terraria-online") { @@ -237,6 +238,11 @@ namespace TShockAPI #region Command Methods + public static void Rules(CommandArgs args) + { + Tools.ShowFileToUser(args.PlayerID, "rules.txt"); + } + public static void ToggleAntiBuild(CommandArgs args) { Tools.SendMessage(args.PlayerID, "Toggled world anti-build."); @@ -297,14 +303,14 @@ namespace TShockAPI ConfigurationManager.banTnt, ConfigurationManager.kickTnt, ConfigurationManager.banBoom, ConfigurationManager.kickBoom); Tools.SendMessage(ply, lineTwo, Color.Yellow); - string lineThree = string.Format("InvMultiplier : {0}, ProtectS : {1}, ProtectR : {2}, DMS : {3}, SpawnRate {4}", - ConfigurationManager.invasionMultiplier, ConfigurationManager.spawnProtect, - ConfigurationManager.spawnProtectRadius, ConfigurationManager.defaultMaxSpawns, - ConfigurationManager.defaultSpawnRate); + string lineThree = string.Format("RangeChecks : {0}, DisableBuild : {1}, ProtectSpawn : {2}, ProtectRadius : {3}", + ConfigurationManager.rangeChecks, ConfigurationManager.disableBuild, + ConfigurationManager.spawnProtect, ConfigurationManager.spawnProtectRadius); Tools.SendMessage(ply, lineThree, Color.Yellow); - string lineFour = string.Format("MaxSlots : {0}, RangeChecks : {1}, SpamChecks : {2}", - ConfigurationManager.maxSlots, ConfigurationManager.rangeChecks, - ConfigurationManager.spamChecks); + string lineFour = string.Format("MaxSlots : {0}, SpamChecks : {1}, InvMultiplier : {2}, DMS : {3}, SpawnRate {4}", + ConfigurationManager.maxSlots, ConfigurationManager.spamChecks, + ConfigurationManager.invasionMultiplier, ConfigurationManager.defaultMaxSpawns, + ConfigurationManager.defaultSpawnRate); Tools.SendMessage(ply, lineFour, Color.Yellow); } @@ -1006,13 +1012,11 @@ namespace TShockAPI Tools.SendMessage(adminplr, "Invalid player!", Color.Red); else if (player == -2) Tools.SendMessage(adminplr, "More than one player matched!", Color.Red); - else if (player == adminplr) - Tools.SendMessage(adminplr, "Can't kill yourself!", Color.Red); else { Tools.SendMessage(adminplr, string.Format("You just killed {0}!", Tools.FindPlayer(player))); Tools.SendMessage(player, string.Format("{0} just killed you!", Tools.FindPlayer(adminplr))); - TShock.KillMe(player); + TShock.PlayerDamage(player, 999999); } } @@ -1044,7 +1048,7 @@ namespace TShockAPI { int.TryParse(args.Parameters[1], out damage); } - NetMessage.SendData(26, -1, -1, "", player, ((new Random()).Next(-1, 1)), damage, (float)0); + TShock.PlayerDamage(player, damage); Tools.Broadcast(string.Format("{0} slapped {1} for {2} damage.", Tools.FindPlayer(adminplr), Tools.FindPlayer(player), damage)); } diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index cd37dda2..f0a37a22 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -41,5 +41,7 @@ namespace TShockAPI public bool RangeChecks = true; public bool SpamChecks = false; public bool DisableBuild = false; + public float[] AdminChatRGB = {255, 0, 0}; + public string AdminChatPrefix = "(Admin) "; } } \ No newline at end of file diff --git a/TShockAPI/ConfigurationManager.cs b/TShockAPI/ConfigurationManager.cs index f1ce1b29..9a0b9b4b 100644 --- a/TShockAPI/ConfigurationManager.cs +++ b/TShockAPI/ConfigurationManager.cs @@ -52,6 +52,8 @@ namespace TShockAPI public static int maxSlots = 8; public static bool spamChecks = false; public static bool disableBuild = false; + public static float[] adminChatRGB = {255, 0, 0}; + public static string adminChatPrefix = "(Admin) "; public enum NPCList { @@ -90,6 +92,8 @@ namespace TShockAPI disableBuild = cfg.DisableBuild; NPC.maxSpawns = defaultMaxSpawns; NPC.defaultSpawnRate = defaultSpawnRate; + adminChatRGB = cfg.AdminChatRGB; + adminChatPrefix = cfg.AdminChatPrefix; } public static void WriteJsonConfiguration() @@ -121,6 +125,8 @@ namespace TShockAPI cfg.RangeChecks = rangeChecks; cfg.SpamChecks = spamChecks; cfg.DisableBuild = disableBuild; + cfg.AdminChatRGB = adminChatRGB; + cfg.AdminChatPrefix = adminChatPrefix; string json = JsonConvert.SerializeObject(cfg, Formatting.Indented); TextWriter tr = new StreamWriter(FileTools.SaveDir + "config.json"); tr.Write(json); diff --git a/TShockAPI/FileTools.cs b/TShockAPI/FileTools.cs index fc9eb531..15d498b7 100644 --- a/TShockAPI/FileTools.cs +++ b/TShockAPI/FileTools.cs @@ -61,6 +61,14 @@ namespace TShockAPI { Directory.CreateDirectory(SaveDir); } + if (!File.Exists(SaveDir + "rules.txt")) + { + CreateFile(SaveDir + "rules.txt"); + TextWriter tw = new StreamWriter(SaveDir + "rules.txt"); + tw.WriteLine("Respect the admins!"); + tw.WriteLine("Don't use TNT!"); + tw.Close(); + } if (!File.Exists(SaveDir + "motd.txt")) { CreateFile(SaveDir + "motd.txt"); diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index c8acbc8e..d3ac12a6 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -338,26 +338,26 @@ namespace TShockAPI )); return Tools.HandleGriefer(e.Msg.whoAmI, "Placing impossible to place blocks."); } - } - if (type == 0 || type == 1) + } + if (ConfigurationManager.disableBuild) { - if (ConfigurationManager.disableBuild) + if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) { - if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) - { - return true; - } + Tools.SendMessage(e.Msg.whoAmI, "World protected from changes.", Color.Red); + RevertPlayerChanges(e.Msg.whoAmI, type, x, y); + return true; } - if (ConfigurationManager.spawnProtect) + } + if (ConfigurationManager.spawnProtect) + { + if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) { - if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) + var flag = CheckSpawn(x, y); + if (flag) { - var flag = CheckSpawn(x, y); - if (flag) - { - Tools.SendMessage(e.Msg.whoAmI, "Spawn protected from changes.", Color.Red); - return true; - } + Tools.SendMessage(e.Msg.whoAmI, "Spawn protected from changes.", Color.Red); + RevertPlayerChanges(e.Msg.whoAmI, type, x, y); + return true; } } } @@ -371,6 +371,11 @@ namespace TShockAPI return false; } + private static void RevertPlayerChanges(int player, byte action, int x, int y) + { + NetMessage.SendData(20, player, -1, "", 10, (float)(x - 5), (float)(y - 5), 0f); + } + bool HandleTogglePvp(MemoryStream data, GetDataEventArgs e) { int id = data.ReadByte(); @@ -595,6 +600,13 @@ namespace TShockAPI return; } + if (players[ply].group.HasPermission("adminchat") && !text.StartsWith("/")) + { + Tools.Broadcast(ConfigurationManager.adminChatPrefix + "<" + Main.player[ply].name + "> " + text, ConfigurationManager.adminChatRGB); + e.Handled = true; + return; + } + int x = (int)Main.player[ply].position.X; int y = (int)Main.player[ply].position.Y; @@ -833,10 +845,9 @@ namespace TShockAPI } } - public static void KillMe(int plr) + public static void PlayerDamage(int plr, int damage) { - for (int i = 0; i < Main.player.Length; i++) - NetMessage.SendData(44, i, -1, "", plr, 1, 9999999, (float)0); + NetMessage.SendData(26, -1, -1, "", plr, ((new Random()).Next(-1, 1)), damage, (float)0); } //TODO : Notify the player if there is more than one match. (or do we want a First() kinda thing?) diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index ed0e7a78..025e3e58 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -105,7 +105,16 @@ namespace TShockAPI { for (int i = 0; i < Main.player.Length; i++) { - SendMessage(i, msg, red, green, blue); + SendMessage(i, msg, Tools.Clamp(red, 255, 0), Tools.Clamp(green, 255, 0), Tools.Clamp(blue, 255, 0)); + } + Log.Info(string.Format("Broadcast: {0}", msg)); + } + + public static void Broadcast(string msg, float[] colors) + { + for (int i = 0; i < Main.player.Length; i++) + { + SendMessage(i, msg, Tools.Clamp(colors[0], 255, 0), Tools.Clamp(colors[1], 255, 0), Tools.Clamp(colors[2], 255, 0)); } Log.Info(string.Format("Broadcast: {0}", msg)); } @@ -342,15 +351,20 @@ namespace TShockAPI } return false; } - - /// - /// Shows a MOTD to the player - /// - /// int player + [Obsolete("Use ShowFileToUser(int ply, string file) instead.")] public static void ShowMOTD(int ply) + { + ShowFileToUser(ply, "motd.txt"); + } + /// + /// Shows a file to the user. + /// + /// int player + /// string filename reletave to savedir + public static void ShowFileToUser(int ply, string file) { string foo = ""; - TextReader tr = new StreamReader(FileTools.SaveDir + "motd.txt"); + TextReader tr = new StreamReader(FileTools.SaveDir + file); while ((foo = tr.ReadLine()) != null) { foo = foo.Replace("%map%", Main.worldName);