示例#1
0
        public void HandleConnectionData(ref byte[] data)
        {
            if (data[0] == 64)
            {
                int pos = 0;
                while (pos < data.Length)
                {
                    try
                    {
                        int  MessageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });
                        uint MessageId     = Base64Encoding.DecodeUInt32(new byte[] { data[pos++], data[pos++] });

                        byte[] Content = new byte[MessageLength - 2];
                        for (int j = 0; j < Content.Length; j++)
                        {
                            Content[j] = data[pos++];
                        }
                        if (this.MessageHandler == null)
                        {
                            this.InitHandler();
                        }
                        ClientMessage Message = new ClientMessage(MessageId, Content);
                        if (Message != null)
                        {
                            try
                            {
                                if (int.Parse(PhoenixEnvironment.GetConfig().data["debug"]) == 1)
                                {
                                    Logging.WriteLine(string.Concat(new object[] { "[", ClientId, "] --> [", Message.Id, "] ", Message.Header, Message.GetBody() }));
                                }
                            }
                            catch
                            {
                            }
                            MessageEvent MessageHandler;
                            if (PhoenixEnvironment.GetPacketManager().Get(Message.Id, out MessageHandler))
                            {
                                MessageHandler.parse(this, Message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.LogException("Error: " + ex.ToString());
                        this.Disconnect();
                    }
                }
            }
            else
            {
                if (true)
                {
                    this.Connection.SendData(CrossdomainPolicy.GetXmlPolicy());
                    this.Connection.Dispose();
                }
            }
        }
示例#2
0
        internal void HandleConnectionData(ref byte[] data)
        {
            if (data[0] == 64)
            {
                int pos = 0;

                while (pos < data.Length)
                {
                    try
                    {
                        int MessageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });
                        int MessageId     = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++] });

                        byte[] Content = new byte[MessageLength - 2];

                        for (int i = 0; i < Content.Length; i++)
                        {
                            Content[i] = data[pos++];
                        }

                        ClientMessage Message = new ClientMessage(MessageId, Content);

                        Console.WriteLine("[Request] >> [" + MessageId + "] " + Message.ToString());

                        if (MessageHandler == null)
                        {
                            InitHandler();
                        }

                        //DateTime PacketMsgStart = DateTime.Now;
                    }
                    catch (Exception e)
                    {
                        Logging.HandleException(e, "packet handling");
                        Disconnect();
                    }
                }
            }
            else
            {
                Connection.SendData(PiciEnvironment.GetDefaultEncoding().GetBytes(CrossdomainPolicy.GetXmlPolicy()));
            }
        }
示例#3
0
        public void ParsePacket(ref byte[] bytes)
        {
            //Console.WriteLine(Essential.GetDefaultEncoding().GetString(bytes));
            string Packet = Essential.GetDefaultEncoding().GetString(bytes);

            if (Essential.GetDefaultEncoding().GetString(bytes) == "<policy-file-request/>" + (char)0)
            {
                this.Connection.SendMessage(CrossdomainPolicy.GetXmlPolicy());
            }
            else if (Packet.StartsWith("GET") || Packet.StartsWith("POST"))
            {
                Essential.GetWebManager().HandleRequest(Packet, this.GetConnection());
            }

            /*if(Packet.StartsWith("imaphone"))
             * {
             *  //Essential.GetMobileHandler().HandleRequest(Packet, this);
             * }*/
            int index = 0;

            while (index < bytes.Length)
            {
                try
                {
                    // I tried to make a mobile Version of Habbo, but didn't continue it. If you want I could continue the developing of Essential Mobile
                    if (!Packet.StartsWith("mobile"))
                    {
                        #region "Normal Part"
                        int MessageLength = HabboEncoding.DecodeInt32(new byte[] { bytes[index++], bytes[index++], bytes[index++], bytes[index++] });
                        if (MessageLength < 2 || MessageLength > 1024)
                        {
                            //Console.WriteLine("bad size packet!");
                            continue;
                        }
                        int    MessageId = HabboEncoding.DecodeInt16(new byte[] { bytes[index++], bytes[index++] });
                        byte[] Content   = new byte[MessageLength - 2];
                        for (int i = 0; i < Content.Length && index < bytes.Length; i++)
                        {
                            Content[i] = bytes[index++];
                        }
                        if (MessageId == 1615)
                        {
                            return;
                        }
                        Interface     messageInterface;
                        ClientMessage cMessage = new ClientMessage((uint)MessageId, Content);
                        if (cMessage != null)
                        {
                            if (Essential.GetPacketManager().Handle((uint)MessageId, out messageInterface))
                            {
                                try
                                {
                                    /* Logging.WriteLine(string.Concat(new object[]
                                     * {
                                     *   "[INCOMING] ",
                                     *   "[",
                                     *   messageInterface.GetType().Name.ToString(),
                                     *   "] --> [",
                                     *   cMessage.Id,
                                     *   "] ",
                                     *   cMessage.ToString()
                                     * }));*/
                                    messageInterface.Handle(this, cMessage);
                                }
                                catch (Exception ex)
                                {
                                    Logging.LogException("Error: " + ex.ToString());
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region "Mobile Part"
                        if (Packet.Length < 2 || Packet.Length > 1024)
                        {
                            continue;
                        }
                        this.IsMobileUser = true;
                        this.GetConnection().IsMobileUser = true;
                        Interface     messageInterface;
                        uint          MessageId = uint.Parse(Packet.Split((char)1)[1]);
                        ClientMessage cMessage  = new ClientMessage((uint)MessageId, null, true, Packet);
                        if (cMessage != null)
                        {
                            if (Essential.GetPacketManager().Handle((uint)MessageId, out messageInterface))
                            {
                                try
                                {
                                    /*  Logging.WriteLine(string.Concat(new object[]
                                     * {
                                     *    "[INCOMING] ",
                                     *    "[",
                                     *    messageInterface.GetType().Name.ToString(),
                                     *    "] --> [",
                                     *    cMessage.Id,
                                     *    "] ",
                                     *    cMessage.ToString()
                                     * }));*/
                                    messageInterface.Handle(this, cMessage);
                                    break;
                                }
                                catch (Exception ex)
                                {
                                    Logging.LogException("Error: " + ex.ToString());
                                }
                            }
                        }
                        #endregion
                    }
                }
                catch (Exception e)
                {
                    if (e.GetType() == typeof(IndexOutOfRangeException))
                    {
                        return;
                    }
                    if (e.GetType() == typeof(NullReferenceException))
                    {
                        return;
                    }

                    Logging.LogException("Error: " + e.ToString());
                    ServerMessage ServerError = new ServerMessage(Outgoing.ServerError);
                    ServerError.AppendInt32(1);
                    ServerError.AppendInt32(1);
                    ServerError.AppendString(DateTime.Now.ToShortDateString().ToString());
                    this.SendMessage(ServerError);
                }
            }
        }
        public void ParsePacket(ref byte[] bytes)
        {
            if (bytes[0] == 64)
            {
                int i = 0;

                while (i < bytes.Length)
                {
                    try
                    {
                        int num = Base64Encoding.DecodeInt32(new byte[]
                        {
                            bytes[i++],
                            bytes[i++],
                            bytes[i++]
                        });

                        uint uint_ = Base64Encoding.DecodeUInt32(new byte[]
                        {
                            bytes[i++],
                            bytes[i++]
                        });

                        byte[] array = new byte[num - 2];
                        for (int j = 0; j < array.Length; j++)
                        {
                            array[j] = bytes[i++];
                        }

                        if (this.ClientMessageHandler == null)
                        {
                            this.CreateClientMessageHandler();
                        }
                        ClientMessage @class = new ClientMessage(uint_, array);
                        if (@class != null)
                        {
                            try
                            {
                                if (int.Parse(GoldTree.GetConfig().data["debug"]) == 1)
                                {
                                    Logging.WriteLine(string.Concat(new object[]
                                    {
                                        "[",
                                        this.ID,
                                        "] --> [",
                                        @class.Id,
                                        "] ",
                                        @class.Header,
                                        @class.GetBody()
                                    }));
                                }
                            }
                            catch
                            {
                            }
                            Interface @interface;
                            if (GoldTree.GetPacketManager().Handle(@class.Id, out @interface))
                            {
                                try
                                {
                                    @interface.Handle(this, @class);
                                }
                                catch (Exception ex)
                                {
                                    Logging.LogException("Error: " + ex.ToString());
                                    this.method_12();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.GetType() == typeof(IndexOutOfRangeException))
                        {
                            return;
                        }
                        Logging.LogException("Error: " + ex.ToString());
                        this.method_12();
                    }
                }
            }
            else
            {
                if (true)                //Class13.Boolean_7)
                {
                    this.Connection.SendMessage(CrossdomainPolicy.GetXmlPolicy());
                    //this.Message1_0.SendData(GoldTree.GetDefaultEncoding().GetBytes(CrossdomainPolicy.GetXmlPolicy()));
                    this.Connection.Close();
                }
            }
        }
示例#5
0
 public void method_13(ref byte[] byte_0)
 {
     if (byte_0[0] == 64)
     {
         int i = 0;
         while (i < byte_0.Length)
         {
             try
             {
                 int num = Base64Encoding.DecodeInt32(new byte[]
                 {
                     byte_0[i++],
                     byte_0[i++],
                     byte_0[i++]
                 });
                 uint uint_ = Base64Encoding.DecodeUInt32(new byte[]
                 {
                     byte_0[i++],
                     byte_0[i++]
                 });
                 byte[] array = new byte[num - 2];
                 for (int j = 0; j < array.Length; j++)
                 {
                     array[j] = byte_0[i++];
                 }
                 if (this.class17_0 == null)
                 {
                     this.method_4();
                 }
                 ClientMessage @class = new ClientMessage(uint_, array);
                 if (@class != null)
                 {
                     try
                     {
                         if (int.Parse(GoldTree.GetConfig().data["debug"]) == 1)
                         {
                             Logging.WriteLine(string.Concat(new object[]
                             {
                                 "[",
                                 this.UInt32_0,
                                 "] --> [",
                                 @class.Id,
                                 "] ",
                                 @class.Header,
                                 @class.GetBody()
                             }));
                         }
                     }
                     catch
                     {
                     }
                     Interface @interface;
                     if (GoldTree.smethod_10().Handle(@class.Id, out @interface))
                     {
                         @interface.Handle(this, @class);
                     }
                 }
             }
             catch (Exception ex)
             {
                 Logging.LogException("Error: " + ex.ToString());
                 this.method_12();
             }
         }
     }
     else
     {
         if (true)                //Class13.Boolean_7)
         {
             this.Message1_0.method_4(CrossdomainPolicy.GetXmlPolicy());
             this.Message1_0.Dispose();
         }
     }
 }
示例#6
0
 void PolicyRequest()
 {
     Connection.SendData(FirewindEnvironment.GetDefaultEncoding().GetBytes(CrossdomainPolicy.GetXmlPolicy()));
 }
示例#7
0
        internal void HandleConnectionData(ref byte[] data)
        {
            if (data[0] == 64)
            {
                int pos = 0;

                while (pos < data.Length)
                {
                    try
                    {
                        int MessageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });
                        int MessageId     = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++] });

                        byte[] Content = new byte[MessageLength - 2];

                        for (int i = 0; i < Content.Length; i++)
                        {
                            Content[i] = data[pos++];
                        }

                        ClientMessage Message = new ClientMessage(MessageId, Content);

                        if (MessageHandler == null)
                        {
                            InitHandler(); //Never ever register the packets BEFORE you receive any data.
                        }

                        //DateTime PacketMsgStart = DateTime.Now;
                    }
                    catch (Exception e)
                    {
                        Logging.HandleException(e, "packet handling");
                        Disconnect();
                    }
                }
            }
            else
            {
                Connection.SendData(ButterflyEnvironment.GetDefaultEncoding().GetBytes(CrossdomainPolicy.GetXmlPolicy()));
            }
        }
示例#8
0
 private void PolicyRequest()
 {
     this.Connection.SendData(CyberEnvironment.GetDefaultEncoding().GetBytes(CrossdomainPolicy.GetXmlPolicy()));
 }