TigerEmu/Communication/Messages/Outgoing/Catalog/CatalogPagesListComposer.cs

53 lines
1.5 KiB
C#

using Tiger.Communication.Messages.Interfaces;
using Tiger.Communication.Messages.Types;
using Tiger.Game.Catalogue;
namespace Tiger.Communication.Messages.Outgoing.Catalog;
public class CatalogPagesListComposer : IMessageComposer
{
private readonly IEnumerable<CataloguePage> _pages;
private readonly string _mode;
public CatalogPagesListComposer(IEnumerable<CataloguePage> pages, string mode)
{
_pages = pages;
_mode = mode;
}
public OutgoingHeaders Header => OutgoingHeaders.CatalogPageList;
public void Compose(ServerMessage message)
{
message.AppendBoolean(true);
message.AppendInt32(0);
message.AppendInt32(-1);
message.AppendString("root");
message.AppendString(string.Empty);
message.AppendInt32(0);
message.AppendInt32(_pages.Count());
foreach (var page in _pages)
{
SerializeNode(page, message);
}
message.AppendBoolean(false);
message.AppendString(_mode);
}
private void SerializeNode(CataloguePage page, ServerMessage message)
{
message.AppendBoolean(page.Visible);
message.AppendInt32(page.Icon);
message.AppendInt32(page.Id);
message.AppendString(page.InternalName);
message.AppendString(page.Name);
message.AppendInt32(0);
message.AppendInt32(page.Children.Count);
foreach (var child in page.Children)
{
SerializeNode(child, message);
}
}
}