Ejemplo n.º 1
0
        public static Packet[] Package(int id, Enums.MessageTarget target, string message)
        {
            int  totalPackets = message.Length % 512 > 1 ? message.Length / 512 : (message.Length / 512) - 1;
            bool first        = true;
            var  packets      = new List <Packet>();

            while (true)
            {
                if (first)
                {
                    packets.Add(ProcessFirstChunk(message.Length, message.Substring(0, 512), id, target));
                    first   = false;
                    message = message.Substring(512);
                }
                else
                {
                    if (message.Length > 512)
                    {
                        packets.Add(ProcessBodyChunk(message.Substring(0, 512), id, target));
                        message = message.Substring(512);
                    }
                    else
                    {
                        packets.Add(ProcessLastChunk(message, id, target));
                        break;
                    }
                }
            }
            return(packets.ToArray());
        }
Ejemplo n.º 2
0
        public static Packet[] Package(int id, Enums.MessageTarget target, byte[] img)
        {
            int  totalPackets = img.Length % 512 > 1 ? img.Length / 512 : (img.Length / 512) - 1;
            bool first        = true;
            var  packets      = new List <Packet>();

            while (true)
            {
                if (first)
                {
                    packets.Add(ProcessFirstChunk(img.Length, img.Take(512).ToArray(), id, target));
                    first = false;
                    img   = img.Skip(512).ToArray();
                }
                else
                {
                    if (img.Length > 512)
                    {
                        packets.Add(ProcessBodyChunk(img.Take(512).ToArray(), id, target));
                        img = img.Skip(512).ToArray();
                    }
                    else
                    {
                        packets.Add(ProcessLastChunk(img, id, target));
                        break;
                    }
                }
            }
            return(packets.ToArray());
        }
Ejemplo n.º 3
0
        private static Packet ProcessBodyChunk(string message, int id, Enums.MessageTarget target)
        {
            Packet SendImage = new Packet();

            SendImage.Command = "MESG";
            SendImage.Headers.Add("content-type", "text/plain");
            SendImage.Headers.Add("correlation-id", "32840");
            SendImage.Headers.Add("mesg-id", id.ToString());
            SendImage.Headers.Add("mesg-target", ((int)target).ToString());
            SendImage.Headers.Add("target-id", id.ToString());
            SendImage.Payload = message;

            return(SendImage);
        }
Ejemplo n.º 4
0
        private static Packet ProcessBodyChunk(byte[] data, int id, Enums.MessageTarget target)
        {
            Packet SendImage = new Packet();

            SendImage.Command = "MESG";
            SendImage.Headers.Add("content-type", "image/jpeg");
            SendImage.Headers.Add("correlation-id", "32840");
            SendImage.Headers.Add("mesg-id", id.ToString());
            SendImage.Headers.Add("mesg-target", ((int)target).ToString());
            SendImage.Headers.Add("target-id", id.ToString());
            SendImage.Payload = Encoding.GetEncoding("windows-1252").GetString(data);

            return(SendImage);
        }
Ejemplo n.º 5
0
        /*public static Packet[] ChangeProfilePicture(byte[] image)
         * {
         *  return IconPacket.Package(image);
         * }
         *
         * public static Packet RequestProfile(int contactID)
         * {
         *  var packet = new Packet("SUB PROFILE QUERY");
         *  packet.AddHeader("mesg-id", "33925");
         *  var dataMaps = new DataMap();
         *  dataMaps.SetValue("Sub-Id", contactID);
         *  packet.Payload = Encoding.GetEncoding("windows-1252").GetString(dataMaps.Serialize());
         *  return packet;
         * }
         *
         * public static Packet RequestProfile(int contactID, int targetGroup)
         * {
         *  var req = new Profiles { ContactID = contactID, GroupID = targetGroup };
         *  if (!Static.RequestedProfiles.Contains(req))
         *      Static.RequestedProfiles.Add(req);
         *  return RequestProfile(contactID);
         * }*/

        #endregion User Profile Stuff

        #region Messages

        private static Packet MessagePacket(Enums.MessageTarget Target, int TargetID, string Message)
        {
            return(new Packet("MESG")
            {
                Headers = new Dictionary <string, string>
                {
                    { "content-type", "text/plain" },
                    { "total-length", Message.Length.ToString() },
                    { "last", "T" },
                    { "mesg-id", "1" },
                    { "mesg-target", ((int)Target).ToString() },
                    { "target-id", TargetID.ToString() }
                },
                Payload = Message,
            });
        }