Example #1
0
            public static PacketFormat FromBytes(byte[] bytes)
            {
                MemoryStream ms         = new MemoryStream(bytes);
                BinaryReader br         = new BinaryReader(ms);
                int          id         = br.ReadInt32();
                bool         response   = br.ReadBoolean();
                UpdateType   packettype = (UpdateType)br.ReadByte();
                int          keyindex   = br.ReadInt32();
                int          port       = br.ReadInt32();

                byte[] ebytes = new byte[ms.Length - ms.Position];
                br.Read(ebytes, 0, ebytes.Length);
                byte[] uebytes;
                if (CurrentUser.Keys.Length > keyindex && CurrentUser.Keys[keyindex] != null)
                {
                    uebytes = Storage.Decrypt(ebytes, true, CurrentUser.Keys[keyindex]);
                }
                else
                {
                    uebytes = Storage.Decrypt(ebytes, true, "ihavenokeys");
                }
                MemoryStream ems    = new MemoryStream(uebytes);
                BinaryReader ebr    = new BinaryReader(ems);
                int          userid = ebr.ReadInt32();
                PacketData   data   = (PacketData)Activator.CreateInstance(PacketData.PacketDataTypes[packettype], true);

                data.Response = response; //2015.04.03.
                data.FromBytes(uebytes);
                PacketFormat pf = new PacketFormat(response, keyindex, port, userid, data, id);

                return(pf);
            }