Added networkId to all relevant messages
This commit is contained in:
parent
2e4e4c4693
commit
e9a29f253c
34
Client.cs
34
Client.cs
@ -25,27 +25,6 @@ namespace Passer.Control {
|
|||||||
}
|
}
|
||||||
static public List<Client> clients = new List<Client>();
|
static public List<Client> clients = new List<Client>();
|
||||||
|
|
||||||
//// These static functions are deprecated
|
|
||||||
//public static Client NewClient() {
|
|
||||||
// Client client = new();
|
|
||||||
// clients.Add(client);
|
|
||||||
// client.networkId = 0;
|
|
||||||
|
|
||||||
// return client;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public static Client NewUDPClient(UdpClient udpClient, string ipAddress, int port) {
|
|
||||||
// Client client = NewClient();
|
|
||||||
// client.ipAddress = null;
|
|
||||||
// client.port = port;
|
|
||||||
// client.udpClient = udpClient;
|
|
||||||
// return client;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public Client() {
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
public Client(UdpClient udpClient, int port) {
|
public Client(UdpClient udpClient, int port) {
|
||||||
this.udpClient = udpClient;
|
this.udpClient = udpClient;
|
||||||
this.ipAddress = null;
|
this.ipAddress = null;
|
||||||
@ -56,7 +35,7 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
public virtual void ProcessMessages() {
|
public virtual void ProcessMessages() {
|
||||||
while (this.messageQueue.TryDequeue(out IMessage msg))
|
while (this.messageQueue.TryDequeue(out IMessage msg))
|
||||||
ProcessMessage(msg);
|
ProcessMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessMessage(IMessage msg) {
|
public void ProcessMessage(IMessage msg) {
|
||||||
@ -91,7 +70,10 @@ namespace Passer.Control {
|
|||||||
case DestroyMsg destroy:
|
case DestroyMsg destroy:
|
||||||
ProcessDestroy(destroy);
|
ProcessDestroy(destroy);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
ForwardMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ProcessClient(ClientMsg client) { }
|
protected virtual void ProcessClient(ClientMsg client) { }
|
||||||
@ -113,5 +95,13 @@ namespace Passer.Control {
|
|||||||
protected virtual void ProcessText(TextMsg text) { }
|
protected virtual void ProcessText(TextMsg text) { }
|
||||||
|
|
||||||
protected virtual void ProcessDestroy(DestroyMsg destroy) { }
|
protected virtual void ProcessDestroy(DestroyMsg destroy) { }
|
||||||
|
|
||||||
|
private void ForwardMessage(IMessage thing) {
|
||||||
|
foreach (Client client in Client.clients) {
|
||||||
|
if (client == this)
|
||||||
|
continue;
|
||||||
|
IMessage.SendMsg(client, thing);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,13 +2,13 @@ using Passer;
|
|||||||
|
|
||||||
public class LowLevelMessages {
|
public class LowLevelMessages {
|
||||||
|
|
||||||
public static void SendSpherical(byte[] buffer, ref uint ix, Spherical v) {
|
public static void SendSpherical(byte[] buffer, ref byte ix, Spherical v) {
|
||||||
SendAngle8(buffer, ref ix, v.horizontal);
|
SendAngle8(buffer, ref ix, v.horizontal);
|
||||||
SendAngle8(buffer, ref ix, v.vertical);
|
SendAngle8(buffer, ref ix, v.vertical);
|
||||||
SendFloat16(buffer, ref ix, new float16(v.distance));
|
SendFloat16(buffer, ref ix, new float16(v.distance));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Spherical ReceiveSpherical(byte[] data, ref uint ix) {
|
public static Spherical ReceiveSpherical(byte[] data, ref byte ix) {
|
||||||
float horizontal = ReceiveAngle8(data, ref ix);
|
float horizontal = ReceiveAngle8(data, ref ix);
|
||||||
float vertical = ReceiveAngle8(data, ref ix);
|
float vertical = ReceiveAngle8(data, ref ix);
|
||||||
float distance = ReceiveFloat16(data, ref ix);
|
float distance = ReceiveFloat16(data, ref ix);
|
||||||
@ -16,7 +16,7 @@ public class LowLevelMessages {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendQuat32(byte[] buffer, ref uint ix, Quat32 q) {
|
public static void SendQuat32(byte[] buffer, ref byte ix, Quat32 q) {
|
||||||
int qx = (int)(q.x * 127 + 128);
|
int qx = (int)(q.x * 127 + 128);
|
||||||
int qy = (int)(q.y * 127 + 128);
|
int qy = (int)(q.y * 127 + 128);
|
||||||
int qz = (int)(q.z * 127 + 128);
|
int qz = (int)(q.z * 127 + 128);
|
||||||
@ -33,7 +33,7 @@ public class LowLevelMessages {
|
|||||||
buffer[ix++] = (byte)qz;
|
buffer[ix++] = (byte)qz;
|
||||||
buffer[ix++] = (byte)qw;
|
buffer[ix++] = (byte)qw;
|
||||||
}
|
}
|
||||||
public static Quat32 ReceiveQuat32(byte[] data, ref uint ix) {
|
public static Quat32 ReceiveQuat32(byte[] data, ref byte ix) {
|
||||||
Quat32 q = new(
|
Quat32 q = new(
|
||||||
(data[ix++] - 128.0F) / 127.0F,
|
(data[ix++] - 128.0F) / 127.0F,
|
||||||
(data[ix++] - 128.0F) / 127.0F,
|
(data[ix++] - 128.0F) / 127.0F,
|
||||||
@ -42,7 +42,7 @@ public class LowLevelMessages {
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendAngle8(byte[] buffer, ref uint ix, float angle) {
|
public static void SendAngle8(byte[] buffer, ref byte ix, float angle) {
|
||||||
// Normalize angle
|
// Normalize angle
|
||||||
while (angle >= 180)
|
while (angle >= 180)
|
||||||
angle -= 360;
|
angle -= 360;
|
||||||
@ -51,18 +51,18 @@ public class LowLevelMessages {
|
|||||||
buffer[ix++] = (byte)((angle / 360.0f) * 256.0f);
|
buffer[ix++] = (byte)((angle / 360.0f) * 256.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float ReceiveAngle8(byte[] data, ref uint ix) {
|
public static float ReceiveAngle8(byte[] data, ref byte ix) {
|
||||||
float value = (data[ix++] * 180) / 128.0F;
|
float value = (data[ix++] * 180) / 128.0F;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendFloat16(byte[] data, ref uint ix, float16 f) {
|
public static void SendFloat16(byte[] data, ref byte ix, float16 f) {
|
||||||
ushort binary = f.GetBinary();
|
ushort binary = f.GetBinary();
|
||||||
data[ix++] = (byte)(binary >> 8);
|
data[ix++] = (byte)(binary >> 8);
|
||||||
data[ix++] = (byte)(binary & 255);
|
data[ix++] = (byte)(binary & 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float ReceiveFloat16(byte[] data, ref uint ix) {
|
public static float ReceiveFloat16(byte[] data, ref byte ix) {
|
||||||
ushort value = (ushort)(data[ix++] << 8 | data[ix++]);
|
ushort value = (ushort)(data[ix++] << 8 | data[ix++]);
|
||||||
float16 f16 = new();
|
float16 f16 = new();
|
||||||
f16.SetBinary(value);
|
f16.SetBinary(value);
|
||||||
|
200
Messages.cs
200
Messages.cs
@ -5,32 +5,32 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
public class IMessage {
|
public class IMessage {
|
||||||
public IMessage() { }
|
public IMessage() { }
|
||||||
public IMessage(byte[] data) {
|
public IMessage(byte[] buffer) {
|
||||||
Deserialize(data);
|
Deserialize(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual byte[] Serialize() { return null; }
|
public virtual byte[] Serialize() { return null; }
|
||||||
public virtual void Deserialize(byte[] data) { }
|
public virtual void Deserialize(byte[] buffer) { }
|
||||||
|
|
||||||
public static bool SendMsg(Client client, IMessage msg) {
|
public static bool SendMsg(Client client, IMessage msg) {
|
||||||
return SendMsg(client, msg.Serialize());
|
return SendMsg(client, msg.Serialize());
|
||||||
}
|
}
|
||||||
public static bool SendMsg(Client client, byte[] data) {
|
public static bool SendMsg(Client client, byte[] buffer) {
|
||||||
if (client == null || client.ipAddress == null)
|
if (client == null || client.ipAddress == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
client.udpClient.Send(data, data.Length, client.ipAddress, client.port);
|
client.udpClient.Send(buffer, buffer.Length, client.ipAddress, client.port);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool PublishMsg(Client client, IMessage msg) {
|
public static bool PublishMsg(Client client, IMessage msg) {
|
||||||
return PublishMsg(client, msg.Serialize());
|
return PublishMsg(client, msg.Serialize());
|
||||||
}
|
}
|
||||||
public static bool PublishMsg(Client client, byte[] data) {
|
public static bool PublishMsg(Client client, byte[] buffer) {
|
||||||
if (client == null)
|
if (client == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
client.udpClient.Send(data, data.Length, "127.0.0.1", client.port);
|
client.udpClient.Send(buffer, buffer.Length, "127.0.0.1", client.port);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ namespace Passer.Control {
|
|||||||
public ClientMsg(byte networkId) {
|
public ClientMsg(byte networkId) {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
}
|
}
|
||||||
public ClientMsg(byte[] data) : base(data) { }
|
public ClientMsg(byte[] buffer) : base(buffer) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[ClientMsg.length];
|
byte[] buffer = new byte[ClientMsg.length];
|
||||||
@ -64,10 +64,10 @@ namespace Passer.Control {
|
|||||||
buffer[1] = networkId;
|
buffer[1] = networkId;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
base.Deserialize(data);
|
base.Deserialize(buffer);
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
networkId = data[ix];
|
networkId = buffer[ix];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte networkId) {
|
public static bool Send(Client client, byte networkId) {
|
||||||
@ -88,13 +88,11 @@ namespace Passer.Control {
|
|||||||
if (client.networkId == 0) {
|
if (client.networkId == 0) {
|
||||||
client.networkId = (byte)(Client.clients.Count);
|
client.networkId = (byte)(Client.clients.Count);
|
||||||
NetworkIdMsg.Send(client, client.networkId);
|
NetworkIdMsg.Send(client, client.networkId);
|
||||||
//if (string.IsNullOrEmpty(sceneUrl) == false)
|
client.messageQueue.Enqueue(msg);
|
||||||
//SendModelUrl(client, sceneUrl);
|
|
||||||
}
|
}
|
||||||
else if (msg.networkId == 0) {
|
else if (msg.networkId == 0) {
|
||||||
NetworkIdMsg.Send(client, client.networkId);
|
NetworkIdMsg.Send(client, client.networkId);
|
||||||
//if (string.IsNullOrEmpty(sceneUrl) == false)
|
client.messageQueue.Enqueue(msg);
|
||||||
//SendModelUrl(client, sceneUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -113,26 +111,22 @@ namespace Passer.Control {
|
|||||||
NetworkIdMsg(byte networkId) {
|
NetworkIdMsg(byte networkId) {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
}
|
}
|
||||||
NetworkIdMsg(byte[] data) : base(data) { }
|
NetworkIdMsg(byte[] buffer) : base(buffer) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] data = new byte[NetworkIdMsg.length];
|
byte[] buffer = new byte[NetworkIdMsg.length];
|
||||||
data[0] = NetworkIdMsg.Id;
|
buffer[0] = NetworkIdMsg.Id;
|
||||||
data[1] = this.networkId;
|
buffer[1] = this.networkId;
|
||||||
return data;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.networkId = data[ix];
|
this.networkId = buffer[ix];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte networkId) {
|
public static bool Send(Client client, byte networkId) {
|
||||||
NetworkIdMsg msg = new(networkId);
|
NetworkIdMsg msg = new(networkId);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
//byte[] data = new byte[NetworkIdMsg.length];
|
|
||||||
//data[0] = NetworkIdMsg.Id;
|
|
||||||
//data[1] = client.networkId;
|
|
||||||
//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)
|
||||||
@ -159,7 +153,7 @@ namespace Passer.Control {
|
|||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
}
|
}
|
||||||
public InvestigateMsg(byte[] data) : base(data) { }
|
public InvestigateMsg(byte[] buffer) : base(buffer) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[InvestigateMsg.length];
|
byte[] buffer = new byte[InvestigateMsg.length];
|
||||||
@ -168,10 +162,10 @@ namespace Passer.Control {
|
|||||||
buffer[2] = this.thingId;
|
buffer[2] = this.thingId;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.networkId = data[ix++];
|
this.networkId = buffer[ix++];
|
||||||
this.thingId = data[ix++];
|
this.thingId = buffer[ix++];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId) {
|
public static bool Send(Client client, byte thingId) {
|
||||||
@ -195,8 +189,9 @@ namespace Passer.Control {
|
|||||||
#region Thing
|
#region Thing
|
||||||
|
|
||||||
public class ThingMsg : IMessage {
|
public class ThingMsg : IMessage {
|
||||||
public const byte length = 4;
|
public const byte length = 5;
|
||||||
public const byte Id = 0x80;
|
public const byte Id = 0x80;
|
||||||
|
public byte networkId;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public byte thingType;
|
public byte thingType;
|
||||||
public byte parentId;
|
public byte parentId;
|
||||||
@ -206,22 +201,24 @@ namespace Passer.Control {
|
|||||||
this.thingType = thingType;
|
this.thingType = thingType;
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
}
|
}
|
||||||
public ThingMsg(byte[] data) : base(data) { }
|
public ThingMsg(byte[] buffer) : base(buffer) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] data = new byte[ThingMsg.length];
|
byte[] buffer = new byte[ThingMsg.length];
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
data[ix++] = ThingMsg.Id;
|
buffer[ix++] = ThingMsg.Id;
|
||||||
data[ix++] = this.thingId;
|
buffer[ix++] = this.networkId;
|
||||||
data[ix++] = this.thingType;
|
buffer[ix++] = this.thingId;
|
||||||
data[ix] = this.parentId;
|
buffer[ix++] = this.thingType;
|
||||||
return data;
|
buffer[ix] = this.parentId;
|
||||||
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.thingId = data[ix++];
|
this.networkId = buffer[ix++];
|
||||||
this.thingType = data[ix++];
|
this.thingId = buffer[ix++];
|
||||||
this.parentId = data[ix];
|
this.thingType = buffer[ix++];
|
||||||
|
this.parentId = buffer[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) {
|
||||||
@ -246,7 +243,8 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
public class NameMsg : IMessage {
|
public class NameMsg : IMessage {
|
||||||
public const byte Id = 0x91; // 145
|
public const byte Id = 0x91; // 145
|
||||||
public const byte length = 3;
|
public const byte length = 4;
|
||||||
|
public byte networkId;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public byte len;
|
public byte len;
|
||||||
public string name;
|
public string name;
|
||||||
@ -255,22 +253,24 @@ namespace Passer.Control {
|
|||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
public NameMsg(byte[] data) : base(data) { }
|
public NameMsg(byte[] buffer) : base(buffer) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[length + this.name.Length];
|
byte[] buffer = new byte[length + this.name.Length];
|
||||||
buffer[0] = NameMsg.Id;
|
byte ix = 0;
|
||||||
buffer[1] = this.thingId;
|
buffer[ix++] = NameMsg.Id;
|
||||||
buffer[2] = (byte)this.name.Length;
|
buffer[ix++] = this.networkId;
|
||||||
for (int ix = 0; ix < this.name.Length; ix++)
|
buffer[ix++] = this.thingId;
|
||||||
buffer[3 + ix] = (byte)this.name[ix];
|
buffer[ix++] = (byte)this.name.Length;
|
||||||
|
for (int nameIx = 0; nameIx < this.name.Length; nameIx++, ix++)
|
||||||
|
buffer[ix] = (byte)this.name[nameIx];
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.thingId = data[ix++];
|
this.thingId = buffer[ix++];
|
||||||
int strlen = data[ix++];
|
int strlen = buffer[ix++];
|
||||||
this.name = System.Text.Encoding.UTF8.GetString(data, (int)ix, strlen);
|
this.name = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, strlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, string name) {
|
public static bool Send(Client client, byte thingId, string name) {
|
||||||
@ -292,6 +292,7 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
public class ModelUrlMsg : IMessage {
|
public class ModelUrlMsg : IMessage {
|
||||||
public const byte Id = 0x90; // (144) Model URL
|
public const byte Id = 0x90; // (144) Model URL
|
||||||
|
public byte networkId;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public Spherical position;
|
public Spherical position;
|
||||||
public float scale;
|
public float scale;
|
||||||
@ -303,28 +304,29 @@ namespace Passer.Control {
|
|||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
this.position = Spherical.zero;
|
this.position = Spherical.zero;
|
||||||
}
|
}
|
||||||
public ModelUrlMsg(byte[] data) : base(data) { }
|
public ModelUrlMsg(byte[] buffer) : base(buffer) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] data = new byte[this.url.Length + 9];
|
byte[] buffer = new byte[this.url.Length + 5];
|
||||||
data[0] = ModelUrlMsg.Id;
|
byte ix = 0;
|
||||||
data[1] = this.thingId; // Thing Id
|
buffer[ix++] = ModelUrlMsg.Id;
|
||||||
// data[2]..[5] == position 0, 0, 0
|
buffer[ix++] = this.networkId;
|
||||||
data[6] = 0x3C; // Dummy float16 value 1
|
buffer[ix++] = this.thingId; // Thing Id
|
||||||
data[7] = 0x00;
|
LowLevelMessages.SendFloat16(buffer, ref ix, new float16(1.0f));
|
||||||
|
|
||||||
data[8] = (byte)url.Length;
|
buffer[8] = (byte)url.Length;
|
||||||
for (int ix = 0; ix < this.url.Length; ix++)
|
for (int urlIx = 0; urlIx < this.url.Length; urlIx++, ix++)
|
||||||
data[9 + ix] = (byte)url[ix];
|
buffer[ix] = (byte)url[urlIx];
|
||||||
return data;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
byte ix = 0;
|
||||||
this.thingId = data[ix++];
|
this.networkId = buffer[ix++];
|
||||||
this.position = LowLevelMessages.ReceiveSpherical(data, ref ix);
|
this.thingId = buffer[ix++];
|
||||||
this.scale = LowLevelMessages.ReceiveFloat16(data, ref ix);
|
//this.position = LowLevelMessages.ReceiveSpherical(data, ref ix);
|
||||||
int strlen = data[ix++];
|
this.scale = LowLevelMessages.ReceiveFloat16(buffer, ref ix);
|
||||||
url = System.Text.Encoding.UTF8.GetString(data, (int)ix, strlen);
|
int strlen = buffer[ix++];
|
||||||
|
url = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, strlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, string modelUrl) {
|
public static bool Send(Client client, byte thingId, string modelUrl) {
|
||||||
@ -345,7 +347,8 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
public class PoseMsg : IMessage {
|
public class PoseMsg : IMessage {
|
||||||
public const byte Id = 0x10;
|
public const byte Id = 0x10;
|
||||||
public const byte length = 3 + 4 + 4;
|
public const byte length = 4 + 4 + 4;
|
||||||
|
public byte networkId;
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
|
|
||||||
public byte poseType;
|
public byte poseType;
|
||||||
@ -369,12 +372,13 @@ namespace Passer.Control {
|
|||||||
else
|
else
|
||||||
this.orientation = new Quat32(0, 0, 0, 1);
|
this.orientation = new Quat32(0, 0, 0, 1);
|
||||||
}
|
}
|
||||||
public PoseMsg(byte[] data) : base(data) { }
|
public PoseMsg(byte[] buffer) : base(buffer) { }
|
||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[PoseMsg.length];
|
byte[] buffer = new byte[PoseMsg.length];
|
||||||
uint ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = PoseMsg.Id;
|
buffer[ix++] = PoseMsg.Id;
|
||||||
|
buffer[ix++] = this.networkId;
|
||||||
buffer[ix++] = this.thingId;
|
buffer[ix++] = this.thingId;
|
||||||
buffer[ix++] = this.poseType;
|
buffer[ix++] = this.poseType;
|
||||||
|
|
||||||
@ -382,15 +386,16 @@ namespace Passer.Control {
|
|||||||
LowLevelMessages.SendQuat32(buffer, ref ix, orientation);
|
LowLevelMessages.SendQuat32(buffer, ref ix, orientation);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
byte ix = 0;
|
||||||
thingId = data[ix++];
|
thingId = buffer[ix++];
|
||||||
poseType = data[ix++];
|
thingId = buffer[ix++];
|
||||||
|
poseType = buffer[ix++];
|
||||||
|
|
||||||
//if ((poseType & Pose_Position) != 0)
|
//if ((poseType & Pose_Position) != 0)
|
||||||
position = LowLevelMessages.ReceiveSpherical(data, ref ix);
|
position = LowLevelMessages.ReceiveSpherical(buffer, ref ix);
|
||||||
//if ((poseType & Pose_Orientation) != 0) {
|
//if ((poseType & Pose_Orientation) != 0) {
|
||||||
orientation = LowLevelMessages.ReceiveQuat32(data, ref ix);
|
orientation = LowLevelMessages.ReceiveQuat32(buffer, ref ix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, Spherical position, Quat32 orientation) {
|
public static bool Send(Client client, byte thingId, Spherical position, Quat32 orientation) {
|
||||||
@ -419,7 +424,7 @@ namespace Passer.Control {
|
|||||||
public byte thingId;
|
public byte thingId;
|
||||||
public byte[] bytes;
|
public byte[] bytes;
|
||||||
|
|
||||||
public CustomMsg(byte[] data) : base(data) { }
|
public CustomMsg(byte[] buffer) : base(buffer) { }
|
||||||
public CustomMsg(byte networkId, byte thingId, byte[] bytes) : base() {
|
public CustomMsg(byte networkId, byte thingId, byte[] bytes) : base() {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
@ -428,7 +433,7 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] buffer = new byte[4 + this.bytes.Length];
|
byte[] buffer = new byte[4 + this.bytes.Length];
|
||||||
int ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = CustomMsg.Id;
|
buffer[ix++] = CustomMsg.Id;
|
||||||
buffer[ix++] = this.networkId;
|
buffer[ix++] = this.networkId;
|
||||||
buffer[ix++] = this.thingId;
|
buffer[ix++] = this.thingId;
|
||||||
@ -438,15 +443,16 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.thingId = data[ix++];
|
this.networkId = buffer[ix++];
|
||||||
this.bytes = new byte[data.Length - ix];
|
this.thingId = buffer[ix++];
|
||||||
for (uint bytesIx = 0; ix < data.Length; ix++, bytesIx++)
|
byte length = buffer[ix++];
|
||||||
this.bytes[bytesIx] = data[ix];
|
this.bytes = new byte[length];
|
||||||
|
for (uint bytesIx = 0; ix < length; ix++, bytesIx++)
|
||||||
|
this.bytes[bytesIx] = buffer[ix];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void Send(Client client, byte thingId, byte[] bytes) {
|
public static void Send(Client client, byte thingId, byte[] bytes) {
|
||||||
CustomMsg msg = new(client.networkId, thingId, bytes);
|
CustomMsg msg = new(client.networkId, thingId, bytes);
|
||||||
SendMsg(client, msg);
|
SendMsg(client, msg);
|
||||||
@ -467,11 +473,11 @@ namespace Passer.Control {
|
|||||||
public const byte Id = 0xB0;
|
public const byte Id = 0xB0;
|
||||||
public string text;
|
public string text;
|
||||||
|
|
||||||
public TextMsg(byte[] data) : base(data) { }
|
public TextMsg(byte[] buffer) : base(buffer) { }
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
uint strlen = data[ix++];
|
uint strlen = buffer[ix++];
|
||||||
this.text = System.Text.Encoding.UTF8.GetString(data, (int)ix, (int)strlen);
|
this.text = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, (int)strlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
@ -490,12 +496,14 @@ namespace Passer.Control {
|
|||||||
public class DestroyMsg : IMessage {
|
public class DestroyMsg : IMessage {
|
||||||
public const byte Id = 0x20;
|
public const byte Id = 0x20;
|
||||||
public const byte length = 2;
|
public const byte length = 2;
|
||||||
public byte objectId;
|
public byte networkId;
|
||||||
|
public byte thingId;
|
||||||
|
|
||||||
public DestroyMsg(byte[] data) : base(data) { }
|
public DestroyMsg(byte[] buffer) : base(buffer) { }
|
||||||
|
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] buffer) {
|
||||||
objectId = data[0];
|
this.networkId = buffer[0];
|
||||||
|
this.thingId = buffer[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
|
@ -1,28 +1,9 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Passer.Control {
|
namespace Passer.Control {
|
||||||
|
|
||||||
public static class SiteServer {
|
public static class SiteServer {
|
||||||
//public static async Task ReceiveData() {
|
|
||||||
// while (true) {
|
|
||||||
// //foreach (var client in Client.clients) {
|
|
||||||
|
|
||||||
// for (int ix = 0; ix < Client.clients.Count; ix++) {
|
|
||||||
// if (ix > 0)
|
|
||||||
// UnityEngine.Debug.Log("Client2 ");
|
|
||||||
// Client client = Client.clients[ix];
|
|
||||||
// if (client == null)
|
|
||||||
// continue;
|
|
||||||
|
|
||||||
// byte packetSize = (byte)client.dataStream.ReadByte();
|
|
||||||
// if (packetSize != 0xFF)
|
|
||||||
// await ReceiveData(client.dataStream, client, packetSize);
|
|
||||||
// // else timeout
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static async Task ReceiveData(Stream dataStream, Client client) {
|
public static async Task ReceiveData(Stream dataStream, Client client) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user