This reverts commit 179cb50557.
This commit is contained in:
parent
179cb50557
commit
c2ecc76457
588 changed files with 16260 additions and 10926 deletions
|
|
@ -57,17 +57,19 @@ namespace Server.Items
|
|||
|
||||
if (content == null)
|
||||
{
|
||||
Pages = new BookPageInfo[Math.Min(pageCount, 255)];
|
||||
Pages = new BookPageInfo[pageCount];
|
||||
|
||||
for (int i = 0; i < Pages.Length; ++i)
|
||||
Pages[i] = new BookPageInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
Pages = content.Copy();
|
||||
}
|
||||
}
|
||||
|
||||
// Intended for defined books only
|
||||
public BaseBook(int itemID, bool writable) : this(itemID, 0, writable)
|
||||
public BaseBook(int itemID, bool writable) : this(itemID, 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -228,7 +230,12 @@ namespace Server.Items
|
|||
Pages[i] = new BookPageInfo(reader);
|
||||
}
|
||||
else
|
||||
Pages = content?.Copy() ?? new BookPageInfo[0];
|
||||
{
|
||||
if (content != null)
|
||||
Pages = content.Copy();
|
||||
else
|
||||
Pages = new BookPageInfo[0];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -247,7 +254,14 @@ namespace Server.Items
|
|||
Pages[i] = new BookPageInfo(reader);
|
||||
}
|
||||
else
|
||||
Pages = DefaultContent?.Copy() ?? new BookPageInfo[0];
|
||||
{
|
||||
BookContent content = DefaultContent;
|
||||
|
||||
if (content != null)
|
||||
Pages = content.Copy();
|
||||
else
|
||||
Pages = new BookPageInfo[0];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -293,8 +307,8 @@ namespace Server.Items
|
|||
Author = from.Name;
|
||||
}
|
||||
|
||||
BookPackets.SendBookHeader(from.NetState, from, this);
|
||||
BookPackets.SendBookPageDetails(from.NetState, this);
|
||||
from.Send(new BookHeader(from, this));
|
||||
from.Send(new BookPageDetails(this));
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
|
|
@ -336,14 +350,14 @@ namespace Server.Items
|
|||
if (titleLength > 60)
|
||||
return;
|
||||
|
||||
string title = pvSrc.ReadStringSafe(titleLength);
|
||||
string title = pvSrc.ReadUTF8StringSafe(titleLength);
|
||||
|
||||
int authorLength = pvSrc.ReadUInt16();
|
||||
|
||||
if (authorLength > 30)
|
||||
return;
|
||||
|
||||
string author = pvSrc.ReadStringSafe(authorLength);
|
||||
string author = pvSrc.ReadUTF8StringSafe(authorLength);
|
||||
|
||||
book.Title = Utility.FixHtml(title);
|
||||
book.Author = Utility.FixHtml(author);
|
||||
|
|
@ -366,23 +380,31 @@ namespace Server.Items
|
|||
{
|
||||
int index = pvSrc.ReadUInt16();
|
||||
|
||||
if (index < 1 || index > book.PagesCount)
|
||||
return;
|
||||
if (index >= 1 && index <= book.PagesCount)
|
||||
{
|
||||
--index;
|
||||
|
||||
--index;
|
||||
int lineCount = pvSrc.ReadUInt16();
|
||||
|
||||
int lineCount = pvSrc.ReadUInt16();
|
||||
if (lineCount <= 8)
|
||||
{
|
||||
string[] lines = new string[lineCount];
|
||||
|
||||
if (lineCount > 8)
|
||||
return;
|
||||
for (int j = 0; j < lineCount; ++j)
|
||||
if ((lines[j] = pvSrc.ReadUTF8StringSafe()).Length >= 80)
|
||||
return;
|
||||
|
||||
string[] lines = new string[lineCount];
|
||||
|
||||
for (int j = 0; j < lineCount; ++j)
|
||||
if ((lines[j] = pvSrc.ReadUTF8StringSafe()).Length >= 80)
|
||||
book.Pages[index].Lines = lines;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
|
||||
book.Pages[index].Lines = lines;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -396,4 +418,58 @@ namespace Server.Items
|
|||
Content = 0x08
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class BookPageDetails : Packet
|
||||
{
|
||||
public BookPageDetails(BaseBook book) : base(0x66)
|
||||
{
|
||||
EnsureCapacity(256);
|
||||
|
||||
m_Stream.Write(book.Serial);
|
||||
m_Stream.Write((ushort)book.PagesCount);
|
||||
|
||||
for (int i = 0; i < book.PagesCount; ++i)
|
||||
{
|
||||
BookPageInfo page = book.Pages[i];
|
||||
|
||||
m_Stream.Write((ushort)(i + 1));
|
||||
m_Stream.Write((ushort)page.Lines.Length);
|
||||
|
||||
for (int j = 0; j < page.Lines.Length; ++j)
|
||||
{
|
||||
byte[] buffer = Utility.UTF8.GetBytes(page.Lines[j]);
|
||||
|
||||
m_Stream.Write(buffer, 0, buffer.Length);
|
||||
m_Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class BookHeader : Packet
|
||||
{
|
||||
public BookHeader(Mobile from, BaseBook book) : base(0xD4)
|
||||
{
|
||||
string title = book.Title ?? "";
|
||||
string author = book.Author ?? "";
|
||||
|
||||
byte[] titleBuffer = Utility.UTF8.GetBytes(title);
|
||||
byte[] authorBuffer = Utility.UTF8.GetBytes(author);
|
||||
|
||||
EnsureCapacity(15 + titleBuffer.Length + authorBuffer.Length);
|
||||
|
||||
m_Stream.Write(book.Serial);
|
||||
m_Stream.Write(true);
|
||||
m_Stream.Write(book.Writable && from.InRange(book.GetWorldLocation(), 1));
|
||||
m_Stream.Write((ushort)book.PagesCount);
|
||||
|
||||
m_Stream.Write((ushort)(titleBuffer.Length + 1));
|
||||
m_Stream.Write(titleBuffer, 0, titleBuffer.Length);
|
||||
m_Stream.Write((byte)0); // terminate
|
||||
|
||||
m_Stream.Write((ushort)(authorBuffer.Length + 1));
|
||||
m_Stream.Write(authorBuffer, 0, authorBuffer.Length);
|
||||
m_Stream.Write((byte)0); // terminate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ namespace Server.Items
|
|||
}
|
||||
|
||||
[Constructible]
|
||||
public BrownBook(string title, string author, int pageCount, bool writable) :
|
||||
base(0xFEF, title, author, pageCount, writable)
|
||||
public BrownBook(string title, string author, int pageCount, bool writable) : base(0xFEF, title, author, pageCount,
|
||||
writable)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -41,4 +41,4 @@ namespace Server.Items
|
|||
writer.Write(0); // version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
using System;
|
||||
using Server.Buffers;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public static class BookPackets
|
||||
{
|
||||
public static void SendBookPageDetails(NetState ns, BaseBook book)
|
||||
{
|
||||
if (ns == null)
|
||||
return;
|
||||
|
||||
// 80 chars per line (240 bytes)
|
||||
// 8 lines per page
|
||||
// Max: 77049 bytes
|
||||
int length = 9;
|
||||
|
||||
for (int i = 0; i < book.PagesCount; i++)
|
||||
length += 1926 * book.Pages[i].Lines.Length;
|
||||
|
||||
SpanWriter writer = new SpanWriter(stackalloc byte[length]);
|
||||
writer.Write((byte)0x66); // Packet ID
|
||||
writer.Position += 2; // Dynamic Length
|
||||
|
||||
writer.Write(book.Serial);
|
||||
writer.Write((ushort)book.PagesCount);
|
||||
|
||||
for (int i = 0; i < book.PagesCount; i++)
|
||||
{
|
||||
BookPageInfo page = book.Pages[i];
|
||||
length = Math.Min(page.Lines.Length, 8);
|
||||
|
||||
writer.Write((ushort)(i + 1));
|
||||
writer.Write((ushort)length);
|
||||
|
||||
for (int j = 0; j < length; j++)
|
||||
{
|
||||
string line = page.Lines[j];
|
||||
writer.WriteUTF8Null(line);
|
||||
}
|
||||
}
|
||||
|
||||
writer.Position = 1;
|
||||
writer.Write((ushort)writer.WrittenCount);
|
||||
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
|
||||
public static void SendBookHeader(NetState ns, Mobile from, BaseBook book)
|
||||
{
|
||||
if (ns == null)
|
||||
return;
|
||||
|
||||
string title = book.Title ?? "";
|
||||
string author = book.Author ?? "";
|
||||
|
||||
int length = 17 + title.Length + author.Length;
|
||||
SpanWriter writer = new SpanWriter(stackalloc byte[length]);
|
||||
writer.Write((byte)0xD4); // Packet ID
|
||||
writer.Position += 2; // Dynamic Length
|
||||
|
||||
writer.Write(book.Serial);
|
||||
writer.Write((byte)0x1); // true
|
||||
writer.Write(book.Writable && from.InRange(book.GetWorldLocation(), 1));
|
||||
writer.Write((ushort)book.PagesCount);
|
||||
|
||||
writer.Write((ushort)title.Length + 1);
|
||||
writer.WriteAsciiNull(title);
|
||||
|
||||
writer.Write((ushort)author.Length + 1);
|
||||
writer.WriteAsciiNull(author);
|
||||
|
||||
writer.Position = 1;
|
||||
writer.Write((ushort)writer.WrittenCount);
|
||||
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,8 +13,8 @@ namespace Server.Items
|
|||
}
|
||||
|
||||
[Constructible]
|
||||
public RedBook(string title, string author, int pageCount, bool writable) :
|
||||
base(0xFF1, title, author, pageCount, writable)
|
||||
public RedBook(string title, string author, int pageCount, bool writable) : base(0xFF1, title, author, pageCount,
|
||||
writable)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -41,4 +41,4 @@ namespace Server.Items
|
|||
writer.Write(0); // version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,8 +13,8 @@ namespace Server.Items
|
|||
}
|
||||
|
||||
[Constructible]
|
||||
public TanBook(string title, string author, int pageCount, bool writable) :
|
||||
base(0xFF0, title, author, pageCount, writable)
|
||||
public TanBook(string title, string author, int pageCount, bool writable) : base(0xFF0, title, author, pageCount,
|
||||
writable)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -41,4 +41,4 @@ namespace Server.Items
|
|||
writer.Write(0); // version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue