mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-03-21 17:11:30 +00:00
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
70 lines
1.9 KiB
C#
Executable file
70 lines
1.9 KiB
C#
Executable file
using FSO.Common.Serialization;
|
|
using FSO.Files.Formats.tsodata;
|
|
using Mina.Core.Buffer;
|
|
using System.IO;
|
|
|
|
namespace FSO.Server.Protocol.Electron.Packets
|
|
{
|
|
public class MailRequest : AbstractElectronPacket
|
|
{
|
|
public MailRequestType Type;
|
|
public long TimestampID;
|
|
public MessageItem Item;
|
|
|
|
public override void Deserialize(IoBuffer input, ISerializationContext context)
|
|
{
|
|
Type = input.GetEnum<MailRequestType>();
|
|
if (Type == MailRequestType.SEND) {
|
|
var length = input.GetInt32();
|
|
var dat = new byte[length];
|
|
for (int i=0; i<length; i++)
|
|
{
|
|
dat[i] = input.Get();
|
|
}
|
|
|
|
using (var str = new MemoryStream(dat))
|
|
{
|
|
Item = new MessageItem(str);
|
|
|
|
}
|
|
} else
|
|
{
|
|
TimestampID = input.GetInt64();
|
|
}
|
|
}
|
|
|
|
public override ElectronPacketType GetPacketType()
|
|
{
|
|
return ElectronPacketType.MailRequest;
|
|
}
|
|
|
|
public override void Serialize(IoBuffer output, ISerializationContext context)
|
|
{
|
|
output.PutEnum(Type);
|
|
if (Type == MailRequestType.SEND)
|
|
{
|
|
byte[] dat;
|
|
if (Item == null) dat = new byte[0];
|
|
else
|
|
{
|
|
using (var str = new MemoryStream())
|
|
{
|
|
Item.Save(str);
|
|
dat = str.ToArray();
|
|
}
|
|
}
|
|
output.PutInt32(dat.Length);
|
|
foreach (var b in dat)
|
|
output.Put(b);
|
|
} else
|
|
output.PutInt64(TimestampID);
|
|
}
|
|
}
|
|
|
|
public enum MailRequestType : byte
|
|
{
|
|
POLL_INBOX,
|
|
SEND,
|
|
DELETE
|
|
}
|
|
}
|