mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-03-23 01:42:24 +00:00
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
54 lines
1.8 KiB
C#
Executable file
54 lines
1.8 KiB
C#
Executable file
using FSO.Common.Model;
|
|
using FSO.Common.Serialization;
|
|
using Mina.Core.Buffer;
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace FSO.Server.Protocol.Electron.Packets
|
|
{
|
|
public class GlobalTuningUpdate : AbstractElectronPacket
|
|
{
|
|
public DynamicTuning Tuning;
|
|
public byte[] ObjectUpgrades;
|
|
public override void Deserialize(IoBuffer input, ISerializationContext context)
|
|
{
|
|
|
|
var dataLen = input.GetInt32();
|
|
if (dataLen > 4000000 || dataLen > input.Remaining) throw new Exception("Tuning too long");
|
|
var data = new byte[dataLen];
|
|
input.Get(data, 0, dataLen);
|
|
using (var mem = new MemoryStream(data))
|
|
{
|
|
using (var reader = new BinaryReader(mem))
|
|
{
|
|
Tuning = new DynamicTuning(reader);
|
|
}
|
|
}
|
|
var upgLen = input.GetInt32();
|
|
if (upgLen > 10000000 || upgLen > input.Remaining) throw new Exception("Upgrades too long");
|
|
ObjectUpgrades = new byte[upgLen];
|
|
input.Get(ObjectUpgrades, 0, upgLen);
|
|
}
|
|
|
|
public override ElectronPacketType GetPacketType()
|
|
{
|
|
return ElectronPacketType.GlobalTuningUpdate;
|
|
}
|
|
|
|
public override void Serialize(IoBuffer output, ISerializationContext context)
|
|
{
|
|
using (var mem = new MemoryStream())
|
|
{
|
|
using (var writer = new BinaryWriter(mem))
|
|
{
|
|
Tuning.SerializeInto(writer);
|
|
var result = mem.ToArray();
|
|
output.PutInt32(result.Length);
|
|
output.Put(result, 0, result.Length);
|
|
}
|
|
}
|
|
output.PutInt32(ObjectUpgrades.Length);
|
|
output.Put(ObjectUpgrades, 0, ObjectUpgrades.Length);
|
|
}
|
|
}
|
|
}
|