diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index ce04a640..7fab1b5c 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -141,20 +141,20 @@ namespace TShockAPI { if (Main.player[i].team == Main.player[args.PlayerID].team) { - Tools.SendMessage(i, msg, new float[] { (float)Main.teamColor[playerTeam].R, (float)Main.teamColor[playerTeam].G, (float)Main.teamColor[playerTeam].B }); + Tools.SendMessage(i, msg, Main.teamColor[playerTeam].R, Main.teamColor[playerTeam].G, Main.teamColor[playerTeam].B); } } } else { - Tools.SendMessage(args.PlayerID, "You are not in a party!", new float[] { 255f, 240f, 20f }); + Tools.SendMessage(args.PlayerID, "You are not in a party!", 255f, 240f, 20f); } } public static void ThirdPerson(CommandArgs args) { string msg = args.Message.Remove(0, 3); - Tools.Broadcast("*" + Tools.FindPlayer(args.PlayerID) + " " + msg, new float[] { 205, 133, 63 }); + Tools.Broadcast("*" + Tools.FindPlayer(args.PlayerID) + " " + msg, 205, 133, 63); } public static void Playing(CommandArgs args) @@ -171,23 +171,23 @@ namespace TShockAPI lineOne += "BanCheater : " + ConfigurationManager.banCheater + ", "; lineOne += "KickGriefer : " + ConfigurationManager.kickGriefer + ", "; lineOne += "BanGriefer : " + ConfigurationManager.banGriefer; - Tools.SendMessage(ply, lineOne, new[] { 255f, 255f, 0f }); + Tools.SendMessage(ply, lineOne, 255f, 255f, 0f); string lineTwo = ""; lineTwo += "BanTnt : " + ConfigurationManager.banTnt + ", "; lineTwo += "KickTnt : " + ConfigurationManager.kickTnt + ", "; lineTwo += "BanBoom : " + ConfigurationManager.banBoom + ", "; lineTwo += "KickBoom : " + ConfigurationManager.kickBoom; - Tools.SendMessage(ply, lineTwo, new[] { 255f, 255f, 0f }); + Tools.SendMessage(ply, lineTwo, 255f, 255f, 0f); string lineThree = ""; lineThree += "InvMultiplier : " + ConfigurationManager.invasionMultiplier + ", "; lineThree += "ProtectS : " + ConfigurationManager.spawnProtect + ", "; lineThree += "ProtectR : " + ConfigurationManager.spawnProtectRadius + ", "; lineThree += "DMS : " + ConfigurationManager.defaultMaxSpawns + ", "; lineThree += "SpawnRate: " + ConfigurationManager.defaultSpawnRate; - Tools.SendMessage(ply, lineThree, new[] { 255f, 255f, 0f }); + Tools.SendMessage(ply, lineThree, 255f, 255f, 0f); string lineFour = ""; lineFour += "MaxSlots : " + ConfigurationManager.maxSlots + ", "; - Tools.SendMessage(ply, lineFour, new[] { 255f, 255f, 0f }); + Tools.SendMessage(ply, lineFour, 255f, 255f, 0f); } public static void Kick(CommandArgs args) @@ -210,20 +210,20 @@ namespace TShockAPI { int player = Tools.FindPlayer(plStr); if (player == -1) - Tools.SendMessage(ply, "Invalid player!", new[] { 255f, 0f, 0f }); + Tools.SendMessage(ply, "Invalid player!", 255f, 0f, 0f); else if (player == -2) - Tools.SendMessage(ply, "More than one player matched!", new[] { 255f, 0f, 0f }); + Tools.SendMessage(ply, "More than one player matched!", 255f, 0f, 0f ); else { if (!Tools.Kick(player, reason.Length != 0 ? reason : "Misbehaviour.")) { - Tools.SendMessage(ply, "You can't kick another admin!", new[] { 255f, 0f, 0f }); + Tools.SendMessage(ply, "You can't kick another admin!", 255f, 0f, 0f ); } } } else Tools.SendMessage(ply, "Invalid syntax! Proper syntax: /kick [reason]", - new[] { 255f, 0f, 0f }); + 255f, 0f, 0f ); } public static void BanIP(CommandArgs args) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index b9c40d8c..b1628713 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -19,7 +19,7 @@ namespace TShockAPI public static string saveDir = "./tshock/"; - public static Version VersionNum = new Version(2, 0, 0, 2); + public static Version VersionNum = new Version(2, 0, 0, 4); public static string VersionCodename = "UnrealIRCd ftw (irc.shankshock.com #terraria)"; @@ -134,9 +134,10 @@ namespace TShockAPI { Console.WriteLine(ex.ToString()); } - Console.WriteLine("TShock Version " + Version.Major + "." + Version.Minor + "." + Version.Build + "." + - Version.Revision + " (" + VersionCodename + ") now running."); + string version = "TShock Version " + Version + " (" + VersionCodename + ") now running."; + Console.WriteLine(version); Log.Initialize(FileTools.SaveDir + "log.txt", LogLevel.All, false); + Log.Info(version); Log.Info("Starting..."); GameHooks.Initialize += OnPreInit; @@ -445,41 +446,48 @@ namespace TShockAPI int tileX = Math.Abs(x); int tileY = Math.Abs(y); - int lavacount = 0; - int watercount = 0; - + bool bucket = false; for (int i = 0; i < 44; i++) { - if (Main.player[e.Msg.whoAmI].inventory[i].name == "Lava Bucket") - lavacount++; - else if (Main.player[e.Msg.whoAmI].inventory[i].name == "Water Bucket") - watercount++; + if (Main.player[e.Msg.whoAmI].inventory[i].type >= 205 && Main.player[e.Msg.whoAmI].inventory[i].type <= 207) + { + bucket = true; + break; + } } - if (lava && lavacount <= 0) + if (lava && !players[e.Msg.whoAmI].group.HasPermission("canlava")) { - Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5})", + Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use lava", Color.Red); + Tools.SendLogs(Main.player[e.Msg.whoAmI].name + " tried using lava", Color.Red); + + return true; + } + if (!lava && !players[e.Msg.whoAmI].group.HasPermission("canwater")) + { + Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use water", Color.Red); + Tools.SendLogs(Main.player[e.Msg.whoAmI].name + " tried using water", Color.Red); + return true; + } + + if (!bucket) + { + Log.Debug(string.Format("{0}(PlyXY:{1}_{2}, TileXY:{3}_{4}, Result:{5}_{6}, Amount:{7})", + lava ? "Lava" : "Water", plyX, plyY, tileX, tileY, - Math.Abs(plyX - tileX), Math.Abs(plyY - tileY) + Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), + liquid )); - return Tools.HandleGriefer(e.Msg.whoAmI, "Placing lava they didn't have."); ; - } - if (!lava && watercount <= 0) - { - Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5})", - plyX, plyY, - tileX, tileY, - Math.Abs(plyX - tileX), Math.Abs(plyY - tileY) - )); - return Tools.HandleGriefer(e.Msg.whoAmI, "Placing water they didn't have."); + return Tools.HandleGriefer(e.Msg.whoAmI, "Manipulating liquid without bucket."); ; } if ((Math.Abs(plyX - tileX) > 6) || (Math.Abs(plyY - tileY) > 6)) { - Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5})", + Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Amount:{6})", plyX, plyY, tileX, tileY, - Math.Abs(plyX - tileX), Math.Abs(plyY - tileY) + Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), + liquid )); return Tools.HandleGriefer(e.Msg.whoAmI, "Placing impossible to place liquid."); ; } @@ -521,10 +529,8 @@ namespace TShockAPI private void OnGreetPlayer(int who, HandledEventArgs e) { if (Main.netMode != 2) - { return; - } - int plr = who; //legacy support + Log.Info(Tools.FindPlayer(who) + " (" + Tools.GetPlayerIP(who) + ") from '" + players[who].group.GetName() + "' group joined."); Tools.ShowMOTD(who); if (HackedHealth(who)) @@ -571,15 +577,14 @@ namespace TShockAPI if (cmd == null) { - Tools.SendMessage(ply, "That command does not exist, try /help", new float[] { 255, 0, 0 }); + Tools.SendMessage(ply, "That command does not exist, try /help", Color.Red); } else { if (!cmd.Run(text, players[ply])) { - Log.Info(Tools.FindPlayer(ply) + " tried to execute " + cmd.Name() + - " that s/he did not have access to!"); - Tools.SendMessage(ply, "You do not have access to that command.", new float[] { 255, 0, 0 }); + Tools.SendLogs(Tools.FindPlayer(ply) + " tried to execute " + cmd.Name(), Color.Red); + Tools.SendMessage(ply, "You do not have access to that command.", Color.Red); } } e.Handled = true; diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index d76aef00..e0953979 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using Microsoft.Xna.Framework; using Terraria; namespace TShockAPI @@ -85,24 +86,60 @@ namespace TShockAPI Log.Info("Broadcast: " + msg); } - public static void Broadcast(string msg, float[] color) + public static void Broadcast(string msg, float red, float green, float blue) { for (int i = 0; i < Main.player.Length; i++) { - SendMessage(i, msg, color); + SendMessage(i, msg, red, green, blue); } Log.Info("Broadcast: " + msg); } + [Obsolete("STOP USING THIS")] + public static void SendMessage(int ply, string msg, float[] colors) + { + SendMessage(ply, msg, colors[0],colors[1],colors[2]); + } + + /// + /// Sends a message out to a single player + /// + /// int socket thingy for the player from the server socket + /// String message + + public static void SendMessage(int ply, string msg, float red, float green, float blue) + { + NetMessage.SendData(0x19, ply, -1, msg, 255, red, green, blue); + } + /// /// Sends a message out to a single player /// /// int socket thingy for the player from the server socket /// String message /// Float containing red, blue, and green color values - public static void SendMessage(int ply, string msg, float[] color) + public static void SendMessage(int ply, string msg, Color color) { - NetMessage.SendData(0x19, ply, -1, msg, 255, color[0], color[1], color[2]); + NetMessage.SendData(0x19, ply, -1, msg, 255, color.R, color.G, color.B); + } + + /// + /// Sends message to all users with 'logs' permission. + /// + /// + /// + public static void SendLogs(string log, Color color) + { + Log.Info(log); + for (int i = 0; i < Main.maxPlayers; i++) + { + if (TShock.players[i] == null) + continue; + if (!TShock.players[i].group.HasPermission("logs")) + continue; + + SendMessage(i, log, color); + } } /// diff --git a/TShockAPI/UpdateManager.cs b/TShockAPI/UpdateManager.cs index debd27bd..6dcdc154 100644 --- a/TShockAPI/UpdateManager.cs +++ b/TShockAPI/UpdateManager.cs @@ -64,7 +64,7 @@ namespace TShockAPI Tools.SendMessage(i, "The server is out of date. To update, type /updatenow."); for (int j = 4; j < changes.Length; j++) { - Tools.SendMessage(i, changes[j], new float[] { 255, 0, 0 }); + Tools.SendMessage(i, changes[j], 255, 0, 0); } } } diff --git a/TShockAPI/config/groups.txt b/TShockAPI/config/groups.txt index 748f5c90..1317092d 100644 --- a/TShockAPI/config/groups.txt +++ b/TShockAPI/config/groups.txt @@ -14,8 +14,8 @@ #immunetoban immunetokick editspawn #ignoregriefdetection reservedslot -default null +default null canwater canlava vip default reservedslot newadmin default kick editspawn reservedslot -admin newadmin ban unban unbanip causeevents spawnboss spawnmob tp immunetokick kill +admin newadmin ban unban unbanip causeevents spawnboss spawnmob tp immunetokick kill logs trustedadmin admin maintenance cfg cheat pvpfun ignorecheatdetection immunetoban ignoregriefdetection \ No newline at end of file