using System; using System.Collections.Generic; using System.Linq; using System.Text; using DuckEmulator.HabboHotel.Inside.NET; using DuckEmulator.HabboHotel.Outside.Messages.Types; using DuckEmulator.Utilities; using DuckEmulator.HabboHotel.Outside.Messages; using DuckEmulator.HabboHotel.Outside.Habbos; namespace DuckEmulator.HabboHotel.Outside.Clients { class Client { private readonly uint Id; private SocketConnection Connection; private MessageHandler MessageHandler; internal HabboData HabboData; internal Client(uint Id, SocketConnection Connection) { this.Id = Id; this.Connection = Connection; this.MessageHandler = new MessageHandler(this); } internal void InvokeBytes(byte[] Bytes) { string Stringed = Encoding.ASCII.GetString(Bytes); if (Stringed == "" + Convert.ToChar(0)) { Connection.SendString(DuckEnvironment.GetXMLProxy()); } else if (Stringed == Convert.ToChar(1) + "") { Dispose(false); } else { ushort pos = new ushort(); while (pos < Bytes.Length) { try { int MessageLength = Base64Encoding.DecodeInt32(new byte[] { Bytes[pos++], Bytes[pos++], Bytes[pos++] }); uint MessageId = Base64Encoding.DecodeUInt32(new byte[] { Bytes[pos++], Bytes[pos++] }); byte[] Content = new byte[MessageLength - 2]; for (int i = 0; i < Content.Length; i++) { Content[i] = Bytes[pos++]; } ClientMessage Message = new ClientMessage(MessageId, Content); MessageHandler.Invoke(MessageId, Message); if (DuckEnvironment.SHOW_PACKETS) { DuckEnvironment.WriteLine("" + MessageId + " ► " + Message.ToString() + ""); } } catch { Dispose(false); } } } } internal void SendNotif(string Message, Boolean FromHotelManager) // from uber { ServerMessage nMessage = new ServerMessage(); if (FromHotelManager) { nMessage.Init(139); } else { nMessage.Init(161); } nMessage.AppendStringWithBreak(Message); GetConnection().SendResponse(nMessage); } internal void SendHA(string text) { ServerMessage nMessage = new ServerMessage(810); nMessage.AppendBoolean(true); nMessage.AppendStringWithBreak(text); GetConnection().SendResponse(nMessage); } /// /// Initiliaze the frame of the client /// internal void GenerateBars() { if (HabboData == null) { return; } DuckEnvironment.ClientManager.AddClient(this); // Load All Data() HabboData.LoadStructure(); Connection.SendResponse(new ServerMessage(3)); Connection.SendResponse(HabboData.GetEffectsTable().Serialize()); MessageHandler.GetResponse().Init(2); MessageHandler.GetResponse().AppendInt32(2); // club? MessageHandler.GetResponse().AppendBoolean(false); MessageHandler.SendResponse(); MessageHandler.GetResponse().Init(455); MessageHandler.GetResponse().AppendUInt(HabboData.HomeRoom); MessageHandler.SendResponse(); if (HabboData.HomeRoom > 0) { MessageHandler.GetResponse().Init(455); MessageHandler.GetResponse().AppendUInt(HabboData.HomeRoom); MessageHandler.SendResponse(); } // FavoriteRooms uint MessageHandler.GetResponse().Init(458); MessageHandler.GetResponse().AppendInt32(30); MessageHandler.GetResponse().AppendInt32(HabboData.Favorites.Count); HabboData.Favorites.ToList().ForEach(MessageHandler.GetResponse().AppendUInt); MessageHandler.SendResponse(); if (HabboData.Rank >= 3 && HabboData.GetBadgeTable().GetBadge("HS1") == null) { HabboData.GetBadgeTable().GiveBadge("HS1",false); } if (HabboData.Rank >= 2 && HabboData.GetBadgeTable().GetBadge("EXH") == null) { HabboData.GetBadgeTable().GiveBadge("EXH",false); } StringBuilder HotelMessage = new StringBuilder(); HotelMessage.AppendLine("DuckHotel - Test DuckEmulator ©"); HotelMessage.AppendLine("DuckEmulator is the fastest, advanced emulator ever! Its a multi-threaded and cached emulator that's created by Breakzne himself."); HotelMessage.AppendLine("Due the alive-running its updates and handles everything!"); HotelMessage.AppendLine("DuckEmulator has a new database manager, thats better then ever."); HotelMessage.AppendLine("RECENT UPDATES:"); HotelMessage.AppendLine("- Char filter (Anti-Exploit)"); HotelMessage.AppendLine("- Room settings + Icon"); HotelMessage.AppendLine("- Improved Pathfinder."); HotelMessage.AppendLine("- Added Rollers (User/Furni)."); SendHA(HotelMessage.ToString()); if (HabboData.ProgressQuest > 0) { GetConnection().SendResponse(DuckEnvironment.QuestManager.SerializeSideBar(HabboData.ProgressQuest, HabboData)); } } internal void Dispose(bool FromConnection) { if (HabboData != null) { DuckEnvironment.ClientManager.RemoveClient(GetId()); HabboData.OnDisconnect(); HabboData = null; } if (MessageHandler != null) { MessageHandler.Dispose(); MessageHandler = null; } if (Connection != null && !FromConnection) { Connection.Dispose(); Connection = null; } } internal uint GetId() { return this.Id; } internal SocketConnection GetConnection() { return this.Connection; } internal HabboData GetHabbo() { return this.HabboData; } internal MessageHandler GetMessageHandler() { return this.MessageHandler; } } }