From 761b023907f08e256f5c743d3f85def38c0c7c49 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 31 Dec 2011 13:14:54 -0700 Subject: [PATCH 1/7] Added a hook for when pvp is toggled. --- TShockAPI/GetDataHandlers.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index bb8c4b4d..3e63f0bd 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,27 @@ namespace TShockAPI TileEdit.Invoke(null, args); return args.Handled; } + + 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; + } #endregion public static void InitGetDataHandler() { @@ -724,6 +749,8 @@ namespace TShockAPI { int id = args.Data.ReadByte(); bool pvp = args.Data.ReadBoolean(); + if (OnPvpToggled(id, pvp)) + return true; if (id != args.Player.Index) { From dff87a174905f8c4fe371b88e4c62338cc900b70 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 31 Dec 2011 13:31:16 -0700 Subject: [PATCH 2/7] Added some more hooks --- TShockAPI/GetDataHandlers.cs | 68 +++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 3e63f0bd..7de2ea00 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -78,7 +78,9 @@ 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; } @@ -99,6 +101,64 @@ namespace TShockAPI 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; + } #endregion public static void InitGetDataHandler() { @@ -175,6 +235,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; @@ -203,6 +266,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; From e52dba26f7b5ea3b740c18c834ce6b28c10d37b7 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 31 Dec 2011 13:40:14 -0700 Subject: [PATCH 3/7] Add a hook for PlayerMana Remove code dealing with sync players --- TShockAPI/GetDataHandlers.cs | 36 +++++++++++++++++++++++----- TShockAPI/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 7de2ea00..6dd7a69a 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -159,6 +159,33 @@ namespace TShockAPI 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; + } #endregion public static void InitGetDataHandler() { @@ -184,7 +211,6 @@ namespace TShockAPI {PacketTypes.PlayerKillMe, HandlePlayerKillMe}, {PacketTypes.LiquidSet, HandleLiquidSet}, {PacketTypes.PlayerSpawn, HandleSpawn}, - {PacketTypes.SyncPlayers, HandleSync}, {PacketTypes.ChestGetContents, HandleChestOpen}, {PacketTypes.ChestItem, HandleChestItem}, {PacketTypes.SignNew, HandleSign}, @@ -222,11 +248,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(); @@ -292,6 +313,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; 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 From 94f5f12d461b201a9b50ce6653fcf8275b97e029 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 31 Dec 2011 13:41:55 -0700 Subject: [PATCH 4/7] Remove configuration option for sync players --- TShockAPI/ConfigFile.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 2532950a..51e9cdc3 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"; From a8e93455c925850b3b5c9167167f41fa6f7cfe46 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 31 Dec 2011 13:49:14 -0700 Subject: [PATCH 5/7] Add an event for PlayerInfo --- TShockAPI/GetDataHandlers.cs | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 6dd7a69a..61aaf7bd 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -186,6 +186,38 @@ namespace TShockAPI 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() { @@ -337,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((int)playerid, (int) hair, (int) male, (int) 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"); From 89b70f5612680a018ced2683cd3afc9f3cb2bf06 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 31 Dec 2011 16:14:42 -0700 Subject: [PATCH 6/7] Turn that stupid thing on by default. --- TShockAPI/ConfigFile.cs | 2 +- TShockAPI/GetDataHandlers.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 51e9cdc3..fbee24a6 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -194,7 +194,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; + public bool AllowLoginAnyUsername = true; public static ConfigFile Read(string path) { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 61aaf7bd..5825d4d1 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -369,7 +369,7 @@ 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((int)playerid, (int) hair, (int) male, (int) difficulty, name)) + if (OnPlayerInfo(playerid, hair, male, difficulty, name)) { TShock.Utils.ForceKick(args.Player, "A plugin cancelled the event."); return true; From 73bf4857ebdf555abdb96f50cf7204d1f193aec9 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 31 Dec 2011 16:18:34 -0700 Subject: [PATCH 7/7] Invalid expression term semicolon fuck off. --- TShockAPI/ConfigFile.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index fbee24a6..f4e8a8a4 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -193,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 = true; + [Description("Allows users to login with any username with /login")] public bool AllowLoginAnyUsername = true; public static ConfigFile Read(string path) {