ace/Source/ACE.Server/Network/ServerPacket.cs
Mag-nus 99fb8bcc55
All this does is cleanup a bunch of style issues that Resharper complains about (#629)
* Removed unused using statements

* Removed redudnant ToString()'s

* Removed some redundant type casts

* Removed redundant bool comparisons

* remove redundant initializers

* xml summary in invalid place switched to comments

* Use string interpolation

* use format separators

* Removed redundant parenths

* remove redundant else

* direct cast when safe

* redundant string interpolation

* xml summary fixes

* removed empty ctors

* fix modifier order

* Convert to auto property

* Convert some getters to method bodies

* use format separators

* changelog

* Auto-properties that can made to get-only

* fixed some references in XML comments

* remove redundant base()

* Revert "Auto-properties that can made to get-only"

This reverts commit 32a1225ce8.

* fix starter gear json

* Use collections count property

* simplify conditional ternary expression

* remove redundant return statements

* Constructors for abstract classes changed to protected

* Moved declarations to inner scopes

* Join declaration and assignments

* inline out variables

* Use enum extension methods instead of static methods

* inline out more variables

* more unused usings

* Remove specifying enums as ints
2018-02-09 06:46:49 -06:00

70 lines
2.1 KiB
C#

using System;
using System.IO;
using ACE.Common.Cryptography;
namespace ACE.Server.Network
{
public class ServerPacket : Packet
{
public BinaryWriter BodyWriter { get; private set; }
private uint issacXor;
private bool issacXorSet;
public uint IssacXor
{
get
{
return issacXor;
}
set
{
if (issacXorSet)
throw new InvalidOperationException("IssacXor can only be set once!");
issacXorSet = true;
issacXor = value;
}
}
public ServerPacket()
{
Header = new PacketHeader();
Data = new MemoryStream();
BodyWriter = new BinaryWriter(Data);
}
public byte[] GetPayload()
{
uint bodyChecksum = 0u;
uint fragmentChecksum = 0u;
using (MemoryStream stream = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter(stream))
{
writer.Seek((int)PacketHeader.HeaderSize, SeekOrigin.Begin);
if (Data.Length > 0)
{
var body = Data.ToArray();
writer.Write(body);
bodyChecksum = Hash32.Calculate(body, body.Length);
}
foreach (ServerPacketFragment fragment in Fragments)
{
fragmentChecksum += fragment.GetPayload(writer);
}
Header.Size = (ushort)(stream.Length - PacketHeader.HeaderSize);
var headerChecksum = Header.CalculateHash32();
uint payloadChecksum = bodyChecksum + fragmentChecksum;
Header.Checksum = headerChecksum + (payloadChecksum ^ issacXor);
writer.Seek(0, SeekOrigin.Begin);
writer.Write(Header.GetRaw());
writer.Flush();
return stream.ToArray();
}
}
}
}
}