Пример #1
0
        public Packet Deserialize(byte[] packetData)
        {
            SourcePacket packet = new SourcePacket();

            packet.Type = PacketType.Response;
            packet.Origin = PacketOrigin.Client;
            packet.RequestId = BitConverter.ToInt32(packetData, 4);
            packet.ResponseType = (SourceResponseType)BitConverter.ToInt32(packetData, 8);

            int offset = (int)this.PacketHeaderSize;

            while (offset < packetData.Length && packetData[offset] != 0) {

                packet.String1 += Encoding.Default.GetString(new[] { packetData[offset] });

                offset++;
            }

            offset++;

            while (offset < packetData.Length && packetData[offset] != 0) {
                packet.String2 += Encoding.Default.GetString(new[] { packetData[offset] });

                offset++;
            }

            packet.Words = packet.String1.Wordify();

            return packet;
        }
Пример #2
0
        public SourcePacket GetRequestPacket(SourcePacket recievedPacket)
        {
            SourcePacket requestPacket = null;

            if (recievedPacket.RequestId != null && this.SentPackets.ContainsKey(recievedPacket.RequestId) == true) {
                requestPacket = this.SentPackets[recievedPacket.RequestId] as SourcePacket;
            }

            return requestPacket;
        }