2021-12-11 07:28:42 +00:00
|
|
|
|
using System;
|
2021-12-21 00:35:12 +00:00
|
|
|
|
using QSB.Player;
|
2021-12-21 20:38:43 +00:00
|
|
|
|
using QuantumUNET.Messages;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
using QuantumUNET.Transport;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Messaging
|
|
|
|
|
{
|
2021-12-21 20:38:43 +00:00
|
|
|
|
public abstract class QSBMessage : QMessageBase
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// set automatically when sending a message
|
2021-12-11 07:28:42 +00:00
|
|
|
|
public uint From;
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// <summary>
|
2021-12-22 09:16:44 +00:00
|
|
|
|
/// (default) uint.MaxValue = send to everyone <br/>
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// 0 = send to host
|
|
|
|
|
/// </summary>
|
2021-12-11 08:06:09 +00:00
|
|
|
|
public uint To = uint.MaxValue;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// call the base method when overriding
|
2021-12-11 07:28:42 +00:00
|
|
|
|
public override void Serialize(QNetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
writer.Write(From);
|
|
|
|
|
writer.Write(To);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// call the base method when overriding
|
2021-12-11 07:28:42 +00:00
|
|
|
|
public override void Deserialize(QNetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
From = reader.ReadUInt32();
|
|
|
|
|
To = reader.ReadUInt32();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 00:35:12 +00:00
|
|
|
|
/// checked before calling either OnReceive
|
2021-12-21 20:38:43 +00:00
|
|
|
|
public virtual bool ShouldReceive => true;
|
|
|
|
|
public virtual void OnReceiveRemote() { }
|
|
|
|
|
public virtual void OnReceiveLocal() { }
|
2021-12-11 07:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class QSBBoolMessage : QSBMessage
|
|
|
|
|
{
|
|
|
|
|
public bool Value;
|
|
|
|
|
|
|
|
|
|
public override void Serialize(QNetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Deserialize(QNetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
Value = reader.ReadBoolean();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class QSBFloatMessage : QSBMessage
|
|
|
|
|
{
|
|
|
|
|
public float Value;
|
|
|
|
|
|
|
|
|
|
public override void Serialize(QNetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Deserialize(QNetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
Value = reader.ReadSingle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class QSBEnumMessage<E> : QSBMessage where E : Enum
|
|
|
|
|
{
|
|
|
|
|
public E Value;
|
|
|
|
|
|
|
|
|
|
public override void Serialize(QNetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write((int)(object)Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Deserialize(QNetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
Value = (E)(object)reader.ReadInt32();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|