From 27e8d823bd46b2dfd375ee9906ba806546640593 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 21 Jan 2020 21:00:56 -0800 Subject: [PATCH] Fixes packet length & PropertyList (#82) --- Projects/Scripts/Items/Armor/BaseArmor.cs | 4 +- .../Scripts/Items/Clothing/BaseClothing.cs | 4 +- Projects/Scripts/Items/Misc/Corpses/Corpse.cs | 33 ++--- Projects/Scripts/Scripts.csproj | 1 + Projects/Server/AssemblyHandler.cs | 39 +++--- Projects/Server/CityInfo.cs | 20 +++ Projects/Server/Configuration.cs | 22 ++- Projects/Server/Guild.cs | 30 +--- Projects/Server/Item.cs | 132 ++++++++++-------- Projects/Server/Items/BaseMulti.cs | 14 +- Projects/Server/Items/Container.cs | 30 +--- Projects/Server/Items/VirtualHair.cs | 12 +- Projects/Server/Layer.cs | 20 +++ Projects/Server/LightType.cs | 20 +++ Projects/Server/Mobile.cs | 34 ++++- Projects/Server/Network/PacketHandlers.cs | 13 +- .../Server/Network/StaticPacketHandlers.cs | 28 +--- Projects/Server/Notoriety.cs | 10 +- Projects/Server/ObjectPropertyList.cs | 10 +- Publish-OSX.sh | 0 20 files changed, 251 insertions(+), 225 deletions(-) mode change 100644 => 100755 Publish-OSX.sh diff --git a/Projects/Scripts/Items/Armor/BaseArmor.cs b/Projects/Scripts/Items/Armor/BaseArmor.cs index 451420f8c..d0c852626 100644 --- a/Projects/Scripts/Items/Armor/BaseArmor.cs +++ b/Projects/Scripts/Items/Armor/BaseArmor.cs @@ -1370,9 +1370,9 @@ namespace Server.Items return base.CanEquip(from); } - public override bool CheckPropertyConfliction(Mobile m) + public override bool CheckPropertyConflict(Mobile m) { - if (base.CheckPropertyConfliction(m)) + if (base.CheckPropertyConflict(m)) return true; if (Layer == Layer.Pants) diff --git a/Projects/Scripts/Items/Clothing/BaseClothing.cs b/Projects/Scripts/Items/Clothing/BaseClothing.cs index 63fdf08c3..6456037a6 100644 --- a/Projects/Scripts/Items/Clothing/BaseClothing.cs +++ b/Projects/Scripts/Items/Clothing/BaseClothing.cs @@ -544,9 +544,9 @@ namespace Server.Items return Attributes.SpellChanneling != 0; } - public override bool CheckPropertyConfliction(Mobile m) + public override bool CheckPropertyConflict(Mobile m) { - if (base.CheckPropertyConfliction(m)) + if (base.CheckPropertyConflict(m)) return true; if (Layer == Layer.Pants) diff --git a/Projects/Scripts/Items/Misc/Corpses/Corpse.cs b/Projects/Scripts/Items/Misc/Corpses/Corpse.cs index ad540e512..642e9010b 100644 --- a/Projects/Scripts/Items/Misc/Corpses/Corpse.cs +++ b/Projects/Scripts/Items/Misc/Corpses/Corpse.cs @@ -541,31 +541,22 @@ namespace Server.Items writer.WriteDeltaTime(TimeOfDeath); - List> list = m_RestoreTable == null - ? null - : new List>(m_RestoreTable); - int count = list?.Count ?? 0; - + int count = m_RestoreTable?.Count ?? 0; writer.Write(count); - for (int i = 0; i < count; ++i) - { - KeyValuePair kvp = list[i]; - Item item = kvp.Key; - Point3D loc = kvp.Value; - - writer.Write(item); - - if (item.Location == loc) + if (m_RestoreTable != null) + foreach (var (item, loc) in m_RestoreTable) { - writer.Write(false); + writer.Write(item); + + if (item.Location == loc) + writer.Write(false); + else + { + writer.Write(true); + writer.Write(loc); + } } - else - { - writer.Write(true); - writer.Write(loc); - } - } writer.Write(m_DecayTimer != null); diff --git a/Projects/Scripts/Scripts.csproj b/Projects/Scripts/Scripts.csproj index 71df03a57..5707e931e 100644 --- a/Projects/Scripts/Scripts.csproj +++ b/Projects/Scripts/Scripts.csproj @@ -13,6 +13,7 @@ true x64 + 8.0 ..\..\Distribution\Assemblies ..\..\Distribution\Assemblies ..\..\Distribution\Assemblies diff --git a/Projects/Server/AssemblyHandler.cs b/Projects/Server/AssemblyHandler.cs index 59c3ce852..e00b85b33 100644 --- a/Projects/Server/AssemblyHandler.cs +++ b/Projects/Server/AssemblyHandler.cs @@ -1,23 +1,22 @@ -/*************************************************************************** - * AssemblyHandler.cs - * -------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - +/************************************************************************* + * ModernUO * + * Copyright (C) 2019 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: AssemblyHandler.cs - Created: 2019/08/02 - Updated: 2020/01/19 * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ using System; using System.Collections.Generic; using System.IO; diff --git a/Projects/Server/CityInfo.cs b/Projects/Server/CityInfo.cs index 70e1ef9a4..1a3384997 100644 --- a/Projects/Server/CityInfo.cs +++ b/Projects/Server/CityInfo.cs @@ -1,3 +1,23 @@ +/************************************************************************* + * ModernUO * + * Copyright (C) 2019 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: CityInfo.cs - Created: 2019/10/04 - Updated: 2020/01/19 * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + namespace Server { public sealed class CityInfo diff --git a/Projects/Server/Configuration.cs b/Projects/Server/Configuration.cs index 6f0d39927..e83e55678 100644 --- a/Projects/Server/Configuration.cs +++ b/Projects/Server/Configuration.cs @@ -1,3 +1,23 @@ +/************************************************************************* + * ModernUO * + * Copyright (C) 2019 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: Configuration.cs - Created: 2019/10/04 - Updated: 2020/01/19 * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + using System; using System.Collections.Generic; using System.IO; @@ -67,7 +87,7 @@ namespace Server public void Flush() { using FileStream fs = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write); - string configJson = JsonSerializer.Serialize(this, new JsonSerializerOptions {WriteIndented = true}); + string configJson = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); Span data = stackalloc byte[Utility.UTF8WithEncoding.GetMaxByteCount(configJson.Length)]; int bytesWritten = Utility.UTF8WithEncoding.GetBytes(configJson, data); fs.Write(data.Slice(0, bytesWritten)); diff --git a/Projects/Server/Guild.cs b/Projects/Server/Guild.cs index 922c2daa9..df966e444 100644 --- a/Projects/Server/Guild.cs +++ b/Projects/Server/Guild.cs @@ -19,6 +19,7 @@ ***************************************************************************/ using System.Collections.Generic; +using System.Linq; namespace Server.Guilds { @@ -32,7 +33,7 @@ namespace Server.Guilds public abstract class BaseGuild : ISerializable { private BufferWriter m_SaveBuffer; - public BufferWriter SaveBuffer { get { return m_SaveBuffer; } } + public BufferWriter SaveBuffer => m_SaveBuffer; private static uint m_NextID = 1; @@ -83,23 +84,9 @@ namespace Server.Guilds return g; } - public static BaseGuild FindByName(string name) - { - foreach (BaseGuild g in List.Values) - if (g.Name == name) - return g; + public static BaseGuild FindByName(string name) => List.Values.FirstOrDefault(g => g.Name == name); - return null; - } - - public static BaseGuild FindByAbbrev(string abbr) - { - foreach (BaseGuild g in List.Values) - if (g.Abbreviation == abbr) - return g; - - return null; - } + public static BaseGuild FindByAbbrev(string abbr) => List.Values.FirstOrDefault(g => g.Abbreviation == abbr); public static List Search(string find) { @@ -108,16 +95,9 @@ namespace Server.Guilds foreach (BaseGuild g in List.Values) { - bool match = true; string name = g.Name.ToLower(); - for (int i = 0; i < words.Length; i++) - if (name.IndexOf(words[i]) == -1) - { - match = false; - break; - } - if (match) + if (words.All(t => name.IndexOf(t) != -1)) results.Add(g); } diff --git a/Projects/Server/Item.cs b/Projects/Server/Item.cs index c20ec7ea4..c153dd27b 100644 --- a/Projects/Server/Item.cs +++ b/Projects/Server/Item.cs @@ -347,7 +347,18 @@ namespace Server public Packet RemovePacket => StaticPacketHandlers.GetRemoveEntityPacket(this); public OPLInfo OPLPacket => StaticPacketHandlers.GetOPLInfoPacket(this); - public ObjectPropertyList PropertyList => StaticPacketHandlers.GetOPLPacket(this); + + private ObjectPropertyList m_PropertyList; + public ObjectPropertyList PropertyList => m_PropertyList ??= NewObjectPropertyList(); + + public void ReleaseOPLPacket() + { + if (m_PropertyList == null) + return; + + Packet.Release(m_PropertyList); + m_PropertyList = null; + } // World packets need to be invalidated when any of the following changes: // - ItemID @@ -960,17 +971,16 @@ namespace Server { NetState ns = rootParent.NetState; - if (ns != null) - if (rootParent.CanSee(this) && rootParent.InRange(worldLoc, GetUpdateRange(rootParent))) - { - if (ns.ContainerGridLines) - ns.Send(new ContainerContentUpdate6017(this)); - else - ns.Send(new ContainerContentUpdate(this)); + if (ns != null && rootParent.CanSee(this) && rootParent.InRange(worldLoc, GetUpdateRange(rootParent))) + { + if (ns.ContainerGridLines) + ns.Send(new ContainerContentUpdate6017(this)); + else + ns.Send(new ContainerContentUpdate(this)); - if (ObjectPropertyList.Enabled) - ns.Send(OPLPacket); - } + if (ObjectPropertyList.Enabled) + ns.Send(OPLPacket); + } } SecureTrade st = GetSecureTradeCont()?.Trade; @@ -1013,9 +1023,7 @@ namespace Server int range = GetUpdateRange(mob); if (mob.Map != map || !mob.InRange(worldLoc, range)) - { openers.RemoveAt(i--); - } else { if (mob == rootParent || mob == tradeRecip) @@ -1051,44 +1059,43 @@ namespace Server { Mobile m = state.Mobile; - if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m))) + if (!m.CanSee(this) || !m.InRange(worldLoc, GetUpdateRange(m))) continue; + + if (update) { - if (update) + if (m_Parent == null) + SendInfoTo(state, ObjectPropertyList.Enabled); + else { - if (m_Parent == null) - SendInfoTo(state, ObjectPropertyList.Enabled); - else + if (p != null) + state.Send(p); + else if (m_Parent is Item) { - if (p != null) - state.Send(p); - else if (m_Parent is Item) - { - if (state.ContainerGridLines) - state.Send(new ContainerContentUpdate6017(this)); - else - state.Send(new ContainerContentUpdate(this)); - } - else if (m_Parent is Mobile) - { - p = new EquipUpdate(this); - p.Acquire(); - - state.Send(p); - } - - if (ObjectPropertyList.Enabled) - state.Send(OPLPacket); + if (state.ContainerGridLines) + state.Send(new ContainerContentUpdate6017(this)); + else + state.Send(new ContainerContentUpdate(this)); + } + else if (m_Parent is Mobile) + { + p = new EquipUpdate(this); + p.Acquire(); + + state.Send(p); } - } - else if ((flags & ItemDelta.EquipOnly) != 0 && m_Parent is Mobile) - { - state.Send(p ?? (p = Packet.Acquire(new EquipUpdate(this)))); if (ObjectPropertyList.Enabled) state.Send(OPLPacket); - } else if (ObjectPropertyList.Enabled && (flags & ItemDelta.Properties) != 0) - state.Send(OPLPacket); + } } + else if ((flags & ItemDelta.EquipOnly) != 0 && m_Parent is Mobile) + { + state.Send(p ??= Packet.Acquire(new EquipUpdate(this))); + + if (ObjectPropertyList.Enabled) + state.Send(OPLPacket); + } else if (ObjectPropertyList.Enabled && (flags & ItemDelta.Properties) != 0) + state.Send(OPLPacket); } Packet.Release(p); @@ -1273,7 +1280,7 @@ namespace Server writer.Write((byte)m_Direction); if (GetSaveFlag(flags, SaveFlag.Bounce)) - BounceInfo.Serialize(info.m_Bounce, writer); + BounceInfo.Serialize(info?.m_Bounce, writer); if (GetSaveFlag(flags, SaveFlag.LootType)) writer.Write((byte)m_LootType); @@ -1414,7 +1421,7 @@ namespace Server private CompactInfo LookupCompactInfo() => m_CompactInfo; - private CompactInfo AcquireCompactInfo() => m_CompactInfo ?? (m_CompactInfo = new CompactInfo()); + private CompactInfo AcquireCompactInfo() => m_CompactInfo ??= new CompactInfo(); private void ReleaseCompactInfo() { @@ -1531,17 +1538,17 @@ namespace Server /// /// True /// - /// There is a confliction. The elemental resistance bonuses of this Item should not be applied to the + /// There is a conflict. The elemental resistance bonuses of this Item should not be applied to the /// /// /// /// /// False - /// There is no confliction. The bonuses should be applied. + /// There is no conflict. The bonuses should be applied. /// /// /// - public virtual bool CheckPropertyConfliction(Mobile m) => false; + public virtual bool CheckPropertyConflict(Mobile m) => false; /// /// Overridable. Sends the object property list to . @@ -2008,9 +2015,21 @@ namespace Server mobile.GetChildNameProperties(list, this); } + public ObjectPropertyList NewObjectPropertyList() + { + ObjectPropertyList list = new ObjectPropertyList(this); + + GetProperties(list); + AppendChildProperties(list); + + list.Terminate(); + list.SetStatic(); + return list; + } + public void ClearProperties() { - StaticPacketHandlers.FreeOPLPacket(this); + ReleaseOPLPacket(); StaticPacketHandlers.FreeOPLInfoPacket(this); } @@ -2021,9 +2040,10 @@ namespace Server if (m_Map != null && m_Map != Map.Internal && !World.Loading) { - ObjectPropertyList oldList = StaticPacketHandlers.FreeOPLPacket(this); + ObjectPropertyList oldList = m_PropertyList; + m_PropertyList = null; - if (oldList?.Hash != PropertyList.Hash) + if (oldList != null && oldList.Hash != PropertyList.Hash) { StaticPacketHandlers.FreeOPLInfoPacket(this); Delta(ItemDelta.Properties); @@ -2398,8 +2418,8 @@ namespace Server { List items = reader.ReadStrongItemList(); - if (this is Container) - (this as Container).m_Items = items; + if (this is Container cont) + cont.m_Items = items; else AcquireCompactInfo().m_Items = items; } @@ -2500,8 +2520,8 @@ namespace Server items.Add(item); } - if (this is Container) - (this as Container).m_Items = items; + if (this is Container cont) + cont.m_Items = items; else AcquireCompactInfo().m_Items = items; } @@ -2765,7 +2785,7 @@ namespace Server ReleaseWorldPackets(); StaticPacketHandlers.FreeRemoveItemPacket(this); StaticPacketHandlers.FreeOPLInfoPacket(this); - StaticPacketHandlers.FreeOPLPacket(this); + ReleaseOPLPacket(); } public void PublicOverheadMessage(MessageType type, int hue, bool ascii, string text) diff --git a/Projects/Server/Items/BaseMulti.cs b/Projects/Server/Items/BaseMulti.cs index 6e9280b82..5308d5ff7 100644 --- a/Projects/Server/Items/BaseMulti.cs +++ b/Projects/Server/Items/BaseMulti.cs @@ -111,19 +111,9 @@ namespace Server.Items && mcl.Tiles[x][y].Length > 0; } - public bool Contains(Mobile m) - { - if (m.Map == Map) - return Contains(m.X, m.Y); - return false; - } + public bool Contains(Mobile m) => m.Map == Map && Contains(m.X, m.Y); - public bool Contains(Item item) - { - if (item.Map == Map) - return Contains(item.X, item.Y); - return false; - } + public bool Contains(Item item) => item.Map == Map && Contains(item.X, item.Y); public override void Serialize(IGenericWriter writer) { diff --git a/Projects/Server/Items/Container.cs b/Projects/Server/Items/Container.cs index dca428fc6..ab30aadef 100644 --- a/Projects/Server/Items/Container.cs +++ b/Projects/Server/Items/Container.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Server.Network; namespace Server.Items @@ -1322,10 +1323,7 @@ namespace Server.Items for (int j = 0; j < groups.Count; ++j) { Item[] items = groups[j].ToArray(); - int total = 0; - - for (int k = 0; k < items.Length; ++k) - total += items[k].Amount; + int total = items.Sum(t => t.Amount); if (total >= best) best = total; @@ -1387,29 +1385,9 @@ namespace Server.Items return best; } - public int GetAmount(Type type, bool recurse = true) - { - Item[] items = FindItemsByType(type, recurse); + public int GetAmount(Type type, bool recurse = true) => FindItemsByType(type, recurse).Sum(t => t.Amount); - int amount = 0; - - for (int i = 0; i < items.Length; ++i) - amount += items[i].Amount; - - return amount; - } - - public int GetAmount(Type[] types, bool recurse = true) - { - Item[] items = FindItemsByType(types, recurse); - - int amount = 0; - - for (int i = 0; i < items.Length; ++i) - amount += items[i].Amount; - - return amount; - } + public int GetAmount(Type[] types, bool recurse = true) => FindItemsByType(types, recurse).Sum(t => t.Amount); #endregion diff --git a/Projects/Server/Items/VirtualHair.cs b/Projects/Server/Items/VirtualHair.cs index 2cba8205d..b3f8d1da7 100644 --- a/Projects/Server/Items/VirtualHair.cs +++ b/Projects/Server/Items/VirtualHair.cs @@ -106,10 +106,7 @@ namespace Server public HairEquipUpdate(Mobile parent) : base(0x2E, 15) { - int hue = parent.HairHue; - - if (parent.SolidHueOverride >= 0) - hue = parent.SolidHueOverride; + int hue = parent.SolidHueOverride >= 0 ? parent.SolidHueOverride : parent.HairHue; m_Stream.Write(HairInfo.FakeSerial(parent)); m_Stream.Write((short)parent.HairItemID); @@ -125,10 +122,7 @@ namespace Server public FacialHairEquipUpdate(Mobile parent) : base(0x2E, 15) { - int hue = parent.FacialHairHue; - - if (parent.SolidHueOverride >= 0) - hue = parent.SolidHueOverride; + int hue = parent.SolidHueOverride >= 0 ? parent.SolidHueOverride : parent.FacialHairHue; m_Stream.Write(FacialHairInfo.FakeSerial(parent)); m_Stream.Write((short)parent.FacialHairItemID); @@ -156,4 +150,4 @@ namespace Server m_Stream.Write(FacialHairInfo.FakeSerial(parent)); } } -} \ No newline at end of file +} diff --git a/Projects/Server/Layer.cs b/Projects/Server/Layer.cs index 936917bf6..64652e22f 100644 --- a/Projects/Server/Layer.cs +++ b/Projects/Server/Layer.cs @@ -1,3 +1,23 @@ +/************************************************************************* + * ModernUO * + * Copyright (C) 2019 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: Layer.cs - Created: 2019/03/15 - Updated: 2020/01/19 * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + namespace Server { /// diff --git a/Projects/Server/LightType.cs b/Projects/Server/LightType.cs index cdab2e58b..298964cac 100644 --- a/Projects/Server/LightType.cs +++ b/Projects/Server/LightType.cs @@ -1,3 +1,23 @@ +/************************************************************************* + * ModernUO * + * Copyright (C) 2019 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: LightType.cs - Created: 2019/03/15 - Updated: 2020/01/19 * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + namespace Server { public enum LightType diff --git a/Projects/Server/Mobile.cs b/Projects/Server/Mobile.cs index d752c5c62..2a16b7984 100644 --- a/Projects/Server/Mobile.cs +++ b/Projects/Server/Mobile.cs @@ -1759,7 +1759,17 @@ namespace Server public Packet RemovePacket => StaticPacketHandlers.GetRemoveEntityPacket(this); public OPLInfo OPLPacket => StaticPacketHandlers.GetOPLInfoPacket(this); - public ObjectPropertyList PropertyList => StaticPacketHandlers.GetOPLPacket(this); + private ObjectPropertyList m_PropertyList; + public ObjectPropertyList PropertyList => m_PropertyList ??= NewObjectPropertyList(); + + public void ReleaseOPLPacket() + { + if (m_PropertyList == null) + return; + + Packet.Release(m_PropertyList); + m_PropertyList = null; + } [CommandProperty(AccessLevel.GameMaster)] public int SolidHueOverride @@ -2902,7 +2912,7 @@ namespace Server { Item item = Items[i]; - if (item.CheckPropertyConfliction(this)) + if (item.CheckPropertyConflict(this)) continue; Resistances[0] += item.PhysicalResistance; @@ -6525,12 +6535,23 @@ namespace Server { StaticPacketHandlers.FreeRemoveItemPacket(this); StaticPacketHandlers.FreeOPLInfoPacket(this); - StaticPacketHandlers.FreeOPLPacket(this); + ReleaseOPLPacket(); + } + + public ObjectPropertyList NewObjectPropertyList() + { + ObjectPropertyList list = new ObjectPropertyList(this); + + GetProperties(list); + + list.Terminate(); + list.SetStatic(); + return list; } public void ClearProperties() { - StaticPacketHandlers.FreeOPLPacket(this); + ReleaseOPLPacket(); StaticPacketHandlers.FreeOPLInfoPacket(this); } @@ -6541,9 +6562,10 @@ namespace Server if (m_Map != null && m_Map != Map.Internal && !World.Loading) { - ObjectPropertyList oldList = StaticPacketHandlers.FreeOPLPacket(this); + ObjectPropertyList oldList = m_PropertyList; + m_PropertyList = null; - if (oldList?.Hash != PropertyList.Hash) + if (oldList != null && oldList.Hash != PropertyList.Hash) { StaticPacketHandlers.FreeOPLInfoPacket(this); Delta(MobileDelta.Properties); diff --git a/Projects/Server/Network/PacketHandlers.cs b/Projects/Server/Network/PacketHandlers.cs index 7aea2c22a..0f76afa73 100644 --- a/Projects/Server/Network/PacketHandlers.cs +++ b/Projects/Server/Network/PacketHandlers.cs @@ -567,7 +567,8 @@ namespace Server.Network } int count = pvSrc.ReadUInt16(); - if (count < 100 && pvSrc.Length == 1 + 2 + 4 + 2 + count * 6) + + if (count < 100 && pvSrc.Length == 4 + 2 + count * 6) { List sellList = new List(count); @@ -662,7 +663,7 @@ namespace Server.Network huePicker.OnResponse(hue); break; - } + } } public static void SystemInfo(NetState state, PacketReader pvSrc) @@ -1490,7 +1491,7 @@ namespace Server.Network { if (state.Mobile == null) Console.WriteLine( - "Client: {0}: Sent ingame packet (0xBFx{1:X2}) before having been attached to a mobile", state, + "Client: {0}: Sent in-game packet (0xBFx{1:X2}) before having been attached to a mobile", state, packetID); state.Dispose(); } @@ -1556,7 +1557,7 @@ namespace Server.Network Mobile from = state.Mobile; - long length = pvSrc.Length - 3; + long length = pvSrc.Length; if (length < 0 || length % 4 != 0) return; @@ -2122,7 +2123,7 @@ namespace Server.Network name, female, hue, str, dex, intl, info[cityIndex], - new SkillNameValue[] + new[] { new SkillNameValue((SkillName)is1, vs1), new SkillNameValue((SkillName)is2, vs2), @@ -2239,7 +2240,7 @@ namespace Server.Network name, female, hue, str, dex, intl, info[cityIndex], - new SkillNameValue[] + new[] { new SkillNameValue((SkillName)is1, vs1), new SkillNameValue((SkillName)is2, vs2), diff --git a/Projects/Server/Network/StaticPacketHandlers.cs b/Projects/Server/Network/StaticPacketHandlers.cs index 186de7840..6f8e2b2f6 100644 --- a/Projects/Server/Network/StaticPacketHandlers.cs +++ b/Projects/Server/Network/StaticPacketHandlers.cs @@ -19,6 +19,7 @@ * along with this program. If not, see . * *************************************************************************/ +using System; using System.Collections.Concurrent; namespace Server.Network @@ -26,7 +27,6 @@ namespace Server.Network public static class StaticPacketHandlers { private static ConcurrentDictionary OPLInfoPackets = new ConcurrentDictionary(); - private static ConcurrentDictionary ObjectPropertyListPackets = new ConcurrentDictionary(); private static ConcurrentDictionary RemoveEntityPackets = new ConcurrentDictionary(); private static ConcurrentDictionary WorldItemPackets = new ConcurrentDictionary(); @@ -37,7 +37,7 @@ namespace Server.Network { return OPLInfoPackets.GetOrAdd(obj, value => { - OPLInfo packet = new OPLInfo(value.PropertyList); + OPLInfo packet = new OPLInfo(value.PropertyList.Entity.Serial, value.PropertyList.Hash); packet.SetStatic(); return packet; }); @@ -51,30 +51,6 @@ namespace Server.Network return p; } - public static ObjectPropertyList GetOPLPacket(IPropertyListObject obj) - { - return ObjectPropertyListPackets.GetOrAdd(obj, value => - { - ObjectPropertyList list = new ObjectPropertyList(value); - - value.GetProperties(list); - if (value is Item item) - item.AppendChildProperties(list); - - list.Terminate(); - list.SetStatic(); - return list; - }); - } - - public static ObjectPropertyList FreeOPLPacket(IPropertyListObject obj) - { - if (ObjectPropertyListPackets.TryRemove(obj, out ObjectPropertyList list)) - Packet.Release(list); - - return list; - } - public static RemoveEntity GetRemoveEntityPacket(IEntity entity) { return RemoveEntityPackets.GetOrAdd(entity, value => diff --git a/Projects/Server/Notoriety.cs b/Projects/Server/Notoriety.cs index 60dd4e3b6..32499bf23 100644 --- a/Projects/Server/Notoriety.cs +++ b/Projects/Server/Notoriety.cs @@ -46,14 +46,8 @@ namespace Server 0x035 }; - public static int GetHue(int noto) - { - if (noto < 0 || noto >= Hues.Length) - return 0; - - return Hues[noto]; - } + public static int GetHue(int noto) => noto < 0 || noto >= Hues.Length ? 0 : Hues[noto]; public static int Compute(Mobile source, Mobile target) => Handler?.Invoke(source, target) ?? CanBeAttacked; } -} \ No newline at end of file +} diff --git a/Projects/Server/ObjectPropertyList.cs b/Projects/Server/ObjectPropertyList.cs index b1b09aa56..0f845e62a 100644 --- a/Projects/Server/ObjectPropertyList.cs +++ b/Projects/Server/ObjectPropertyList.cs @@ -26,8 +26,8 @@ namespace Server { public interface IPropertyListObject : IEntity { - ObjectPropertyList PropertyList{ get; } - OPLInfo OPLPacket{ get; } + ObjectPropertyList PropertyList { get; } + OPLInfo OPLPacket { get; } void GetProperties(ObjectPropertyList list); } @@ -189,10 +189,10 @@ namespace Server m_Stream.Write( (int) list.Hash ); }*/ - public OPLInfo(ObjectPropertyList list) : base(0xDC, 9) + public OPLInfo(Serial serial, int hash) : base(0xDC, 9) { - m_Stream.Write(list.Entity.Serial); - m_Stream.Write(list.Hash); + m_Stream.Write(serial); + m_Stream.Write(hash); } } } diff --git a/Publish-OSX.sh b/Publish-OSX.sh old mode 100644 new mode 100755