Merge commit '355dd5c1c519cf07cfb6b9f9200f7f7311e68f20' into V2
This commit is contained in:
commit
394dc220ca
39
Messages.cs
39
Messages.cs
@ -237,26 +237,39 @@ namespace Passer.Control {
|
|||||||
public class ThingMsg : IMessage {
|
public class ThingMsg : IMessage {
|
||||||
public const byte length = 5;
|
public const byte length = 5;
|
||||||
public const byte Id = 0x80;
|
public const byte Id = 0x80;
|
||||||
public byte objectId;
|
public byte networkId;
|
||||||
public byte objectType;
|
public byte thingId;
|
||||||
|
public byte thingType;
|
||||||
public byte parentId;
|
public byte parentId;
|
||||||
|
|
||||||
|
public ThingMsg(byte networkId, byte thingId, byte thingType, byte parentId) {
|
||||||
|
this.networkId = networkId;
|
||||||
|
this.thingId = thingId;
|
||||||
|
this.thingType = thingType;
|
||||||
|
this.parentId = parentId;
|
||||||
|
}
|
||||||
public ThingMsg(byte[] data) : base(data) { }
|
public ThingMsg(byte[] data) : base(data) { }
|
||||||
public override void Deserialize(byte[] data) {
|
|
||||||
|
public override byte[] Serialize() {
|
||||||
|
byte[] data = new byte[ThingMsg.length];
|
||||||
|
data[0] = ThingMsg.Id;
|
||||||
|
data[1] = this.networkId;
|
||||||
|
data[2] = this.thingId;
|
||||||
|
data[3] = this.thingType;
|
||||||
|
data[4] = this.parentId;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
public override void Deserialize(byte[] data) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
objectId = data[ix++];
|
this.networkId = data[ix++];
|
||||||
objectType = data[ix++];
|
this.thingId = data[ix++];
|
||||||
parentId = data[ix];
|
this.thingType = data[ix++];
|
||||||
|
this.parentId = data[ix];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, byte thingType, byte parentId) {
|
public static bool Send(Client client, byte thingId, byte thingType, byte parentId) {
|
||||||
byte[] data = new byte[ThingMsg.length];
|
ThingMsg msg = new(client.networkId, thingId, thingType, parentId);
|
||||||
data[0] = ThingMsg.Id;
|
return SendMsg(client, msg);
|
||||||
data[1] = client.networkId;
|
|
||||||
data[2] = thingId;
|
|
||||||
data[3] = thingType;
|
|
||||||
data[4] = parentId;
|
|
||||||
return SendMsg(client, data);
|
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
if (packetSize != length)
|
if (packetSize != length)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user