2020-03-07 15:42:43 +00:00
|
|
|
|
using System;
|
2020-09-02 10:17:04 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
2020-03-07 15:42:43 +00:00
|
|
|
|
using UnityEngine.Networking;
|
2020-03-06 18:03:35 +00:00
|
|
|
|
|
2020-08-09 11:38:35 +00:00
|
|
|
|
namespace QSB.Messaging
|
2020-03-06 18:03:35 +00:00
|
|
|
|
{
|
2020-08-09 11:19:51 +00:00
|
|
|
|
public class PlayerLeaveMessage : PlayerMessage
|
2020-03-06 18:03:35 +00:00
|
|
|
|
{
|
2020-09-02 10:17:04 +00:00
|
|
|
|
public NetworkInstanceId[] NetIds { get; set; }
|
2020-03-07 15:42:43 +00:00
|
|
|
|
|
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
2020-09-02 10:17:04 +00:00
|
|
|
|
NetIds = DeserializeFromString<NetworkInstanceId[]>(reader.ReadString());
|
2020-03-07 15:42:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
2020-09-02 10:17:04 +00:00
|
|
|
|
writer.Write(SerializeToString(NetIds));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string SerializeToString<T>(T value)
|
|
|
|
|
{
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
(new BinaryFormatter()).Serialize(stream, value);
|
|
|
|
|
stream.Flush();
|
|
|
|
|
return Convert.ToBase64String(stream.ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static T DeserializeFromString<T>(string data)
|
|
|
|
|
{
|
|
|
|
|
byte[] bytes = Convert.FromBase64String(data);
|
|
|
|
|
using (var stream = new MemoryStream(bytes))
|
|
|
|
|
return (T)(new BinaryFormatter()).Deserialize(stream);
|
2020-03-07 15:42:43 +00:00
|
|
|
|
}
|
2020-03-06 18:03:35 +00:00
|
|
|
|
}
|
2020-08-09 11:19:51 +00:00
|
|
|
|
}
|