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); } } }