ace/Source/ACE.Server/Network/Structure/PackableHashTable.cs
gmriggs aa9bc542ba
fix some client memory leaks from incorrectly ordered hashtables on login (#3576)
* fix some client memory leaks with appraisals

* fix some client memory leaks from incorrectly ordered hashtables on login

* more organization for PackableHashTable vs. deprecated PHashTable

* fully deprecate PHashTable -- 0 references now

* refactor RestrictionDB.Write() to use PackableHashTable common method. trying to ensure all places in the system that send PackableHashTables go through common method, for consistency and tracing

* cleanup

* finding more references

* update HouseAccess to match client

* add full explanation where numBuckets=89 originates from

* update code for empty collection in AllegianceHierarchy for reference
2021-06-12 16:10:21 -04:00

35 lines
1,016 B
C#

using System.Collections.Generic;
using System.IO;
using System.Linq;
using ACE.Database.Models.Shard;
namespace ACE.Server.Network.Structure
{
/// <summary>
/// HashTable which is packable for network
/// </summary>
public static class PackableHashTable
{
public static void WriteHeader(BinaryWriter writer, int count, int numBuckets)
{
writer.Write((ushort)count);
writer.Write((ushort)numBuckets);
}
public static void WriteOld(this BinaryWriter writer, List<CharacterPropertiesFillCompBook> fillComps)
{
const int numBuckets = 256; // constant from retail pcaps
WriteHeader(writer, fillComps.Count, numBuckets);
var sorted = fillComps.OrderBy(i => i.SpellComponentId % numBuckets);
foreach (var fillComp in sorted)
{
writer.Write(fillComp.SpellComponentId);
writer.Write(fillComp.QuantityToRebuy);
}
}
}
}