Exemple #1
0
        public static void ReadUserListReply(byte[] data, out byte replyType, out uint listVersion, out ContactListType formatType, out string reply)
        {
            using (PacketReader reader = new PacketReader(data))
            {
                replyType   = reader.ReadByte();                                  //type
                listVersion = reader.ReadUInt32();                                //list version
                formatType  = Utils.ToPublicContactListFormat(reader.ReadByte()); //format type
                reader.ReadByte();                                                //unknown
                byte[] rep = reader.ReadBytes(data.Length - 7);                   //reply

                using (MemoryStream memStream = new MemoryStream(rep))
                {
                    using (ZInputStream inflator = new ZInputStream(memStream))
                    {
                        byte[]       buffer = new byte[16384];
                        int          len;
                        PacketWriter output = new PacketWriter();
                        while ((len = inflator.read(buffer, 0, Math.Min(rep.Length, buffer.Length))) > 0)
                        {
                            output.Write(buffer, 0, len);
                        }
                        reply = (formatType == ContactListType.XML ? Encoding.UTF8 : Encoding.GetEncoding("windows-1250")).GetString(output.Data);
                        output.Close();

                        inflator.Close();
                    }
                }


                //reply = (formatType == ContactListType.XML ? Encoding.UTF8 : Encoding.GetEncoding("windows-1250")).GetString(rep);

                reader.Close();
            }
        }
Exemple #2
0
        /// <summary>
        /// Zdobądź token.
        /// </summary>
        /// <param name="width">Szerokość tokenu</param>
        /// <param name="height">Wysokość tokenu</param>
        /// <param name="length">Długość tokenu</param>
        /// <param name="id">Indetyfikator tokenu</param>
        /// <param name="tokenData">Dane tokenu</param>
        /// <returns>Bitmapa zawierająca token</returns>
        public static System.Drawing.Image GetToken(out int width, out int height, out int length, out string id, out byte[] tokenData)
        {
            string firstResponse = StringRequest("http://register.gadu-gadu.pl/appsvc/regtoken.asp", "GET", false);
            string addr          = string.Empty;

            using (StreamReader reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(firstResponse))))
            {
                string[] size = reader.ReadLine().Split(' ');
                width  = int.Parse(size[0]);
                height = int.Parse(size[1]);
                length = int.Parse(size[2]);
                id     = reader.ReadLine();
                addr   = reader.ReadLine() + "?tokenid=" + id;
                reader.Close();
            }

            Stream imgStream = DataRequest(addr, "GET");

            byte[]       buffer = new byte[16384];
            int          len;
            PacketWriter output = new PacketWriter();

            while ((len = imgStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                output.Write(buffer, 0, len);
            }
            tokenData = output.Data;
            output.Close();

            return(new System.Drawing.Bitmap(new MemoryStream(tokenData)));
        }