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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue