public static void HandlePacket(Tcp tcp, Packet packet)
 {
     if (_packetHandlers.ContainsKey(packet.Command))
         _packetHandlers[packet.Command].Process(tcp, packet);
     else
         Console.WriteLine("UNSUPPORTED COMMAND: " + packet.Command);
 }
 public PacketParser(Action<Packet> packetCallback)
 {
     _packet = new Packet();
     _contentLength = 0;
     _rawData = new StringBuilder();
     _packetCallback = packetCallback;
 }
Example #3
0
 public void Process(Tcp tcp, Packet packet)
 {
     var payload = Encoding.Default.GetBytes(packet.Payload); // windows-1252
     var password = Encoding.Default.GetBytes(tcp.Password);
     var encrypted = Crypto.GenerateAuth(payload, password);
     var authpacket = PacketTemplates.Auth(encrypted, Enums.OnlineStatus.Online);
     tcp.SendPacket(authpacket);
 }
Example #4
0
 public void Process(Tcp tcp, Packet packet)
 {
     return;
     Console.WriteLine("[Start Response Packet]");
     Console.WriteLine(packet.ToString());
     var what = int.Parse(packet["WHAT"]);
     Console.WriteLine("[Stop Response Packet]");
 }
        public void Process(Tcp tcp, Packet packet)
        {
            // Gather info for deserialization
            int iv = 0;
            int rk = 0;
            if (packet.ContainsHeader("IV"))
                iv = int.Parse(packet["IV"]);
            if (iv > 0)
                rk = int.Parse(packet["RK"]);
            int l = packet.Payload.Length;
            int length = packet.Payload.Length - iv - rk;
            int startPos = iv;

            // Time to extract information
            var enc = Encoding.GetEncoding("windows-1252"); // Allows support for other OS (provided they have the windows-1252 encoding)
            var maps = Deserialize(enc.GetBytes(packet.Payload), startPos, length);

            try
            {
                var contactsMap = Deserialize(maps["contacts"], 0, maps["contacts"].Length);
                ParseContacts(contactsMap);
            }
            catch { }

            try
            {
                var groupsMap = Deserialize(maps["group_sub"], 0, maps["group_sub"].Length);
                ParseGroups(groupsMap);
            }
            catch { }

            try
            {
                var blockedMap = Deserialize(maps["blocked"], 0, maps["blocked"].Length);
                ParseBlockedUsers(blockedMap);
            }
            catch { }

            try
            {
                var requestsMap = Deserialize(maps["contact_add"], 0, maps["contact_add"].Length);
                ParseContactRequests(requestsMap);
            }
            catch { }

            if (_loginPacket)
            {
                var profile = new Contact();
                profile.ContactID = uint.Parse(Encoding.UTF8.GetString(maps["sub-id"]));
                profile.Reputation = int.Parse(Encoding.UTF8.GetString(maps["rep"]));
                profile.Privileges = uint.Parse(Encoding.UTF8.GetString(maps["privileges"]));
                profile.Nickname = Encoding.UTF8.GetString(maps["nickname"]);
                Cache.Profile = profile;
                tcp.RaiseLoginSuccess();
                _loginPacket = false;
            }
        }
 private static Packet ProcessFirstChunk(int totalLength, string message, int id, Enums.MessageTarget target)
 {
     Packet SendImage = new Packet();
     SendImage.Command = "MESG";
     SendImage.Headers.Add("content-type", "text/plain");
     SendImage.Headers.Add("mesg-id", "32840");
     SendImage.Headers.Add("mesg-target", ((int)target).ToString());
     SendImage.Headers.Add("target-id", id.ToString());
     SendImage.Headers.Add("total-Length", totalLength + "");
     SendImage.Payload = message;
     return SendImage;
 }
 private static Packet ProcessFirstChunk(int totalLength, byte[] data, int id, Enums.MessageTarget target)
 {
     Packet SendImage = new Packet();
     SendImage.Command = "MESG";
     SendImage.Headers.Add("content-type", "image/jpeg");
     SendImage.Headers.Add("mesg-id", "32840");
     SendImage.Headers.Add("mesg-target", ((int)target).ToString());
     SendImage.Headers.Add("target-id", id.ToString());
     SendImage.Headers.Add("total-Length", totalLength + "");
     SendImage.Payload = Encoding.GetEncoding("windows-1252").GetString(data);
     return SendImage;
 }
 public static void HandleMessage(Packet packet)
 {
     bool isGroup = packet.Headers.ContainsKey("TARGET-ID");
     var msgType = ParseMessageType(packet.Headers["CONTENT-TYPE"]);
     var data = packet.Payload;
     if (isGroup)
     {
         var groupId = int.Parse(packet.Headers["TARGET-ID"]);
         var sourceId = int.Parse(packet.Headers["SOURCE-ID"]);
         var cmds = _commands.Where(attr => attr.Value.Value.CommandType == Enums.CommandType.Group).ToList();
         foreach (var cmd in cmds)
         {
             if (data.ToLower().StartsWith(Tcp.Namespace.ToLower() + " " + cmd.Value.Value.Command.ToLower()))
             {
                 cmd.Value.Key.Invoke(null, new object[]
                 {
                     Tcp.Current,
                     new Message()
                         {
                             MessageTarget = Enums.MessageTarget.Group,
                             MessageType = msgType,
                             Payload = new String (data.Skip(Tcp.Namespace.Length + 1).ToArray()),
                             SourceId = sourceId,
                             TargetId = groupId,
                         }
                 });
             }
         }
     }
     else
     {
         var sourceId = int.Parse(packet.Headers["SOURCE-ID"]);
         var nickname = packet.Headers["NAME"];
         foreach (var cmd in _commands.Where(attr => attr.Value.Value.CommandType == Enums.CommandType.Private))
         {
             if (!data.StartsWith(cmd.Value.Value.Command)) return;
             cmd.Value.Key.Invoke(null, new object[]
                 {
                     Tcp.Current,
                     new Message()
                         {
                             MessageTarget = Enums.MessageTarget.Private,
                             MessageType = msgType,
                             Payload = data,
                             SourceId = sourceId,
                         }
                 });
         }
     }
 }
        private static Packet ProcessLastChunk(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("last", "1");
            SendImage.Headers.Add("mesg-id", "32862");
            SendImage.Headers.Add("mesg-target", ((int)target).ToString());
            SendImage.Headers.Add("target-id", id.ToString());
            SendImage.Payload = message;

            return SendImage;
        }
        public static Packet Logon(string email, Enums.DeviceType deviceType)
        {
            var packet = new Packet("LOGON");
            packet.Headers.Add("protocol-version", "2.0");
            switch (deviceType)
            {
                case Enums.DeviceType.Android:
                    packet.Headers.Add("app-type", "android");
                    packet.Headers.Add("Operator", "Verizon");
                    break;

                case Enums.DeviceType.iPad:
                    packet.Headers.Add("app-type", "Apple/iPad/Premium");
                    packet.Headers.Add("Operator", "");
                    break;

                case Enums.DeviceType.iPhone:
                    packet.Headers.Add("app-type", "Apple/iPhone/Premium");
                    packet.Headers.Add("Operator", "");
                    break;

                case Enums.DeviceType.Macintosh:
                    packet.Headers.Add("app-type", "Apple/Intel");
                    packet.Headers.Add("client-version", "4.6.4 (null)");
                    packet.Headers.Add("Operator", "OSX_CLIENT");
                    break;

                case Enums.DeviceType.WindowsPC:
                    packet.Headers.Add("app-type", "Windows x86");
                    packet.Headers.Add("Operator", "PC_Client");
                    break;

                case Enums.DeviceType.WindowsPhone:
                    packet.Headers.Add("app-type", "Win/P7");
                    packet.Headers.Add("Operator", "PHONE_7");
                    break;

                case Enums.DeviceType.Mobile:
                    packet.Headers.Add("app-type", "Java");
                    packet.Headers.Add("Operator", "Verizon");
                    break;
            }
            packet.Headers.Add("name", email);
            packet.Headers.Add("capabilities", "4");
            return packet;
        }
Example #11
0
 public void SendPacket(Packet[] packets)
 {
     foreach (var packet in packets)
         SendPacket(packet);
 }
Example #12
0
 public void SendPacket(Packet packet)
 {
     SendData(packet.Serialize());
     if (PacketSent != null)
         PacketSent(packet);
 }
 public static Packet FetchGroupAvatar(int groupId)
 {
     var packet = new Packet("AVATAR");
     packet.AddHeader("group", "T");
     packet.AddHeader("id", groupId.ToString());
     packet.AddHeader("MESG-id", LastMessageID++.ToString());
     packet.AddHeader("size", "2000");
     return packet;
 }
Example #14
0
        public void Process(Tcp tcp, Packet packet)
        {

        }
Example #15
0
 public void Process(Tcp tcp, Packet packet)
 {
 
     //tcp.SendPacket(PacketTemplates.PING());
     CommandManager.HandleMessage(packet);
 }
        /*public static Packet Create(DataMap map, object target, int sourceId, bool isName)
        {
            try
            {
                if (isName)
                {
                    Static.RequestedGroups.Add(new RequestGroup
                    {
                        Name = (string)target,
                        SourceId = sourceId,
                        IsName = true
                    });
                }
                else
                {
                    Static.RequestedGroups.Add(new RequestGroup
                    {
                        TargetId = (int)target,
                        SourceId = sourceId,
                        IsName = false
                    });
                }
            }
            catch (Exception)
            {
            }
            return new Packet("PROVIF QUERY")
            {
                Headers = { { "mesg-id", "34163" }, { "last", "1" } },
                Payload = Encoding.GetEncoding("windows-1252").GetString(map.Serialize())
            };
        }

        public static Packet Create(DataMap map, object target, int sourceId)
        {
            bool isName = false;
            try
            {
                if (isName)
                {
                    Static.RequestedGroups.Add(new RequestGroup
                    {
                        Name = (string)target,
                        SourceId = sourceId,
                        IsName = true
                    });
                }
                else
                {
                    Static.RequestedGroups.Add(new RequestGroup
                    {
                        TargetId = (int)target,
                        SourceId = sourceId,
                        IsName = false
                    });
                }
            }
            catch (Exception)
            {
            }
            return new Packet("PROVIF QUERY")
            {
                Headers = { { "mesg-id", "34163" }, { "last", "1" } },
                Payload = Encoding.GetEncoding("windows-1252").GetString(map.Serialize())
            };
        }

        public static Packet QueryGroup(string name, int targetGroup)
        {
            var search = new GroupSearch(1, true);
            search.AddGroupNameFilter(name, true);
            var datamap = search.ConstructDataMap();
            return Create(datamap, name, targetGroup, true);
        }

        public static Packet QueryGroup(int id, int targetGroup)
        {
            var search = new GroupSearch(1, true);
            search.AddGroupIDCriteria((ulong)id);
            var datamap = search.ConstructDataMap();
            return Create(datamap, id, targetGroup);
        }

        public static Packet QueryGroup(int id)
        {
            return QueryGroup(id, -1);
        }

        public static Packet QueryGroup(string name)
        {
            return QueryGroup(name, -1);
        }*/

        #endregion


        #region Queries

        public static Packet FetchUserAvatar(int userId)
        {
            var packet = new Packet("AVATAR");
            packet.AddHeader("id", userId.ToString());
            packet.AddHeader("MESG-id", LastMessageID++.ToString());
            packet.AddHeader("size", "2000");
            return packet;
        }
 public void Process(Tcp tcp, Packet packet)
 {
     System.Console.WriteLine("GroupUpdate Here");
 }
 private static Packet AdminAction(Enums.AdminAction action, int groupID, int targetID)
 {
     var packet = new Packet("GROUP ADMIN");
     packet.Headers.Add("group-id", groupID.ToString());
     packet.Headers.Add("target-id", targetID.ToString());
     packet.Headers.Add("last", "1");
     LastMessageID++;
     packet.Headers.Add("mesg-id", LastMessageID.ToString());
     packet.Headers.Add("action", ((int)action).ToString());
     return packet;
 }
Example #19
0
 public void Process(Tcp tcp, Packet packet)
 {
     tcp.SendPacket(PacketTemplates.PING());
 }