diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 2532950a..f4e8a8a4 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -103,8 +103,6 @@ namespace TShockAPI [Description("Enables kicking of banned users by matching their Character Name")] public bool EnableBanOnUsernames; - [Description("Drops excessive sync packets")] public bool EnableAntiLag = true; - [Description("Selects the default group name to place new registrants under")] public string DefaultRegistrationGroupName = "default"; @@ -195,8 +193,7 @@ namespace TShockAPI [Description("Allows users to register any username with /register")] public bool AllowRegisterAnyUsername; - [Description("Allows users to login with any username with /login")] - public bool AllowLoginAnyUsername; + [Description("Allows users to login with any username with /login")] public bool AllowLoginAnyUsername = true; public static ConfigFile Read(string path) { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index bb8c4b4d..5825d4d1 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -51,6 +51,10 @@ namespace TShockAPI private static Dictionary GetDataHandlerDelegates; public static int[] WhitelistBuffMaxTime; #region Events + + /// + /// TileEdit - called when a tile is placed or destroyed + /// public class TileEditEventArgs : HandledEventArgs { public int X { get; set; } @@ -74,6 +78,146 @@ namespace TShockAPI TileEdit.Invoke(null, args); return args.Handled; } + /// + /// TogglePvp - called when a player toggles pvp + /// + public class TogglePvpEventArgs : HandledEventArgs + { + public int id { get; set; } + public bool pvp { get; set; } + } + + public static HandlerList TogglePvp; + public static bool OnPvpToggled(int _id, bool _pvp) + { + if (TogglePvp == null) + return false; + + var args = new TogglePvpEventArgs + { + id = _id, + pvp = _pvp, + }; + TogglePvp.Invoke(null, args); + return args.Handled; + } + + /// + /// PlayerSlot - called at a PlayerSlot event + /// + public class PlayerSlotEventArgs : HandledEventArgs + { + public int plr { get; set; } + public int slot { get; set; } + public int stack { get; set; } + public short prefix { get; set; } + public int type { get; set; } + } + + public static HandlerList PlayerSlot; + + public static bool OnPlayerSlot(int _plr, int _slot, int _stack, short _prefix, int _type) + { + if (PlayerSlot == null) + return false; + + var args = new PlayerSlotEventArgs + { + plr = _plr, + slot = _slot, + stack = _stack, + prefix = _prefix, + type = _type + }; + PlayerSlot.Invoke(null, args); + return args.Handled; + } + + /// + /// PlayerHP - called at a PlayerHP event + /// + public class PlayerHPEventArgs : HandledEventArgs + { + public int plr { get; set; } + public int cur { get; set; } + public int max { get; set; } + } + + public static HandlerList PlayerHP; + + public static bool OnPlayerHP(int _plr, int _cur, int _max) + { + if (PlayerHP == null) + return false; + + var args = new PlayerHPEventArgs + { + plr = _plr, + cur = _cur, + max = _max, + }; + PlayerHP.Invoke(null, args); + return args.Handled; + } + + /// + /// PlayerMana - called at a PlayerMana event + /// + public class PlayerManaEventArgs : HandledEventArgs + { + public int plr { get; set; } + public int cur { get; set; } + public int max { get; set; } + } + + public static HandlerList PlayerMana; + + public static bool OnPlayerMana(int _plr, int _cur, int _max) + { + if (PlayerMana == null) + return false; + + var args = new PlayerManaEventArgs + { + plr = _plr, + cur = _cur, + max = _max, + }; + PlayerMana.Invoke(null, args); + return args.Handled; + } + + /// + /// PlayerInfo - called at a PlayerInfo event + /// If this is cancelled, the server will ForceKick the player. If this should be changed in the future, let someone know. + /// + public class PlayerInfoEventArgs : HandledEventArgs + { + public int playerid { get; set; } + public int hair { get; set; } + public int male { get; set; } + public int difficulty { get; set; } + public string name { get; set; } + } + + public static HandlerList PlayerInfo; + + public static bool OnPlayerInfo(int _plrid, int _hair, int _male, int _difficulty, string _name) + { + if (PlayerInfo == null) + return false; + + var args = new PlayerInfoEventArgs + { + playerid = _plrid, + hair = _hair, + male = _male, + difficulty = _difficulty, + name = _name, + }; + PlayerInfo.Invoke(null, args); + return args.Handled; + } #endregion public static void InitGetDataHandler() { @@ -99,7 +243,6 @@ namespace TShockAPI {PacketTypes.PlayerKillMe, HandlePlayerKillMe}, {PacketTypes.LiquidSet, HandleLiquidSet}, {PacketTypes.PlayerSpawn, HandleSpawn}, - {PacketTypes.SyncPlayers, HandleSync}, {PacketTypes.ChestGetContents, HandleChestOpen}, {PacketTypes.ChestItem, HandleChestItem}, {PacketTypes.SignNew, HandleSign}, @@ -137,11 +280,6 @@ namespace TShockAPI return false; } - private static bool HandleSync(GetDataHandlerArgs args) - { - return TShock.Config.EnableAntiLag; - } - private static bool HandlePlayerSlot(GetDataHandlerArgs args) { int plr = args.Data.ReadInt8(); @@ -150,6 +288,9 @@ namespace TShockAPI short prefix = args.Data.ReadInt8(); int type = args.Data.ReadInt16(); + if (OnPlayerSlot(plr, slot, stack, prefix, type)) + return true; + if (plr != args.Player.Index) { return true; @@ -178,6 +319,9 @@ namespace TShockAPI int cur = args.Data.ReadInt16(); int max = args.Data.ReadInt16(); + if (OnPlayerHP(plr, cur, max)) + return true; + if (args.Player.FirstMaxHP == 0) args.Player.FirstMaxHP = max; @@ -201,6 +345,9 @@ namespace TShockAPI int cur = args.Data.ReadInt16(); int max = args.Data.ReadInt16(); + if (OnPlayerMana(plr, cur, max)) + return true; + if (args.Player.FirstMaxMP == 0) args.Player.FirstMaxMP = max; @@ -222,6 +369,12 @@ namespace TShockAPI var difficulty = args.Data.ReadInt8(); string name = Encoding.ASCII.GetString(args.Data.ReadBytes((int) (args.Data.Length - args.Data.Position - 1))); + if (OnPlayerInfo(playerid, hair, male, difficulty, name)) + { + TShock.Utils.ForceKick(args.Player, "A plugin cancelled the event."); + return true; + } + if (!TShock.Utils.ValidString(name)) { TShock.Utils.ForceKick(args.Player, "Unprintable character in name"); @@ -724,6 +877,8 @@ namespace TShockAPI { int id = args.Data.ReadByte(); bool pvp = args.Data.ReadBoolean(); + if (OnPvpToggled(id, pvp)) + return true; if (id != args.Player.Index) { diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index cbde5304..f794aefa 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // Build Number // MMdd of the build -[assembly: AssemblyVersion("3.4.2.1230")] -[assembly: AssemblyFileVersion("3.4.2.1230")] \ No newline at end of file +[assembly: AssemblyVersion("3.4.2.1231")] +[assembly: AssemblyFileVersion("3.4.2.1231")] \ No newline at end of file