public Packet(PacketTypeEnum messageType, PacketBoundryFlagEnum packetBoundryFlag, byte identifier) { this.payLoad = new byte[0]; this.MessageType = messageType; this.PacketBoundryFlag = packetBoundryFlag; this.identifier = identifier; }
public Packet(PacketTypeEnum messageType, PacketBoundryFlagEnum packetBoundryFlag, byte identifier, byte[] payLoad) { if (payLoad == null) { this.payLoad = new byte[0]; } else { this.payLoad = payLoad; } this.MessageType = messageType; this.PacketBoundryFlag = packetBoundryFlag; this.identifier = identifier; }
public ControlPacket(PacketTypeEnum packetType, PacketBoundryFlagEnum pbf, GroupIdentifierEnum groupIdentifier, byte opcodeIdentifier) : base(packetType, pbf, (byte)groupIdentifier) { this.opcodeIdentifier = opcodeIdentifier; }
public void SetHeader(PacketTypeEnum eventType, EndPoint clientEndpoint) { Header.Sender = clientEndpoint; Header.SocketEventType = eventType; }
/// <summary> /// Initializes a new instance of the <see cref="Packet"/> class. /// </summary> /// <param name="opcode">The opcode.</param> /// <param name="type">The type.</param> public Packet(OpcodeEnum opcode, PacketTypeEnum type) : this(opcode, type, "") { }
/// <summary> /// Initializes a new instance of the <see cref="Packet"/> class. /// </summary> /// <param name="opcode">The opcode.</param> /// <param name="type">The type.</param> /// <param name="data">The data.</param> public Packet(OpcodeEnum opcode, PacketTypeEnum type, int data) : this(opcode, type, data.ToString()) { }
/// <summary> /// Initializes a new instance of the <see cref="Packet"/> class. /// </summary> /// <param name="opcode">The opcode.</param> /// <param name="type">The type.</param> /// <param name="data">The data.</param> public Packet(OpcodeEnum opcode, PacketTypeEnum type, string data) : this(opcode, type, Encoding.Default.GetBytes(data + "\0")) { }
/// <summary> /// Initializes a new instance of the <see cref="Packet"/> class. /// </summary> /// <param name="opcode">The opcode.</param> /// <param name="type">The type.</param> /// <param name="data">The data.</param> public Packet(OpcodeEnum opcode, PacketTypeEnum type, byte[] data) : this() { Opcode = opcode; Type = type; Data = data; }
// Server sent us a packet about all connected clients or an update for all cube positions void ProcessServerData(byte[] buffer) { NetworkReader nr = new NetworkReader(buffer); PacketTypeEnum packetType = (PacketTypeEnum)nr.ReadByte(); switch (packetType) { case PacketTypeEnum.Position: List <PositionData> posList = new List <PositionData>(); PositionData p; while (nr.Position != buffer.Length) { p = new PositionData(); p.objectId = nr.ReadInt32(); p.pos = nr.ReadVector3(); posList.Add(p); } // Update game objects foreach (var item in clientList) { if (item.obj == null) { continue; } p = posList.FirstOrDefault(x => x.objectId == item.objectId); if (p == null) { Debug.Log("Cannot find game object"); } else { item.obj.transform.position = p.pos; } } break; case PacketTypeEnum.Information: List <InformationData> infoList = new List <InformationData>(); InformationData info; while (nr.Position != buffer.Length) { info = new InformationData(); info.objectId = nr.ReadInt32(); info.name = nr.ReadString(); info.pos = nr.ReadVector3(); info.r = nr.ReadSingle(); info.g = nr.ReadSingle(); info.b = nr.ReadSingle(); infoList.Add(info); } // Remove clients that aren't listed foreach (var item in clientList) { if (item.obj == null) { continue; } info = infoList.FirstOrDefault(x => x.objectId == item.objectId); if (info == null) { Destroy(item.obj); } } clientList.RemoveAll(x => x.obj == null); // Note items are set to null only after Update! foreach (var item in infoList) { ClientData cd = clientList.FirstOrDefault(x => x.objectId == item.objectId); // Is this new client info? if (cd == null) { // Create new object GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); // No CharacterController here! // Set position obj.transform.position = item.pos; // Set color obj.GetComponent <Renderer>().material.color = new Color(item.r, item.g, item.b); cd = new ClientData(); cd.objectId = item.objectId; cd.name = item.name; cd.obj = obj; clientList.Add(cd); Debug.Log(string.Format("New client info for {0}", cd.name)); } } break; default: Debug.Log("Unknown packet type"); break; } }
public ResponsePacket(PacketTypeEnum type, Dictionary <string, string> attrs, string tag) : base(type, tag) { Attrs = attrs; }
protected Response(PacketTypeEnum type, string tag) { Type = type; Tag = tag; }