mysimulation/server/tso.files/Formats/tsodata/MessageItem.cs
Tony Bark 8fec258215 Added FSO.Files for use with the API server
Don't ask me. FreeSO is the prime example of dependency hell.
2024-05-01 04:38:12 -04:00

87 lines
2.6 KiB
C#
Executable file

using FSO.Files.Utils;
using System.IO;
namespace FSO.Files.Formats.tsodata
{
public class MessageItem
{
public static int CURRENT_VERSION = 1;
public int Version = CURRENT_VERSION;
public int ID;
public uint SenderID;
public uint TargetID;
public string Subject;
public string Body;
public string SenderName;
public long Time;
public int Type; //(message/vote/club/maxis/tso/house/roommate/call)
public int Subtype; //(urgent?)
public int ReadState;
public int? ReplyID;
public MessageItem()
{
}
public MessageItem(Stream stream)
{
Read(stream);
}
public void Save(Stream stream) {
using (var writer = IoWriter.FromStream(stream))
{
writer.WriteCString("FSOI", 4);
writer.WriteInt32(Version);
writer.WriteInt32(ID);
writer.WriteUInt32(SenderID);
writer.WriteUInt32(TargetID);
writer.WriteLongPascalString(Subject);
writer.WriteLongPascalString(Body);
writer.WriteLongPascalString(SenderName);
writer.WriteInt64(Time);
writer.WriteInt32(Type);
writer.WriteInt32(Subtype);
writer.WriteInt32(ReadState);
writer.WriteByte((byte)((ReplyID == null) ? 0 : 1));
if (ReplyID != null) writer.WriteInt32(ReplyID.Value);
}
}
public void Read(Stream stream)
{
using (var reader = IoBuffer.FromStream(stream))
{
var magic = reader.ReadCString(4);
Version = reader.ReadInt32();
ID = reader.ReadInt32();
SenderID = reader.ReadUInt32();
TargetID = reader.ReadUInt32();
Subject = reader.ReadLongPascalString();
Body = reader.ReadLongPascalString();
SenderName = reader.ReadLongPascalString();
Time = reader.ReadInt64();
Type = reader.ReadInt32();
Subtype = reader.ReadInt32();
ReadState = reader.ReadInt32();
if (reader.ReadByte() > 0)
{
ReplyID = reader.ReadInt32();
}
}
}
}
public enum MessageSpecialType
{
Normal = 0,
//neighbourhoods
Nominate = 1,
Vote = 2,
AcceptNomination = 3,
FreeVote = 4
}
}