using System; using System.Collections.Generic; using Hang.HabboHotel.GameClients; using Hang.HabboHotel.Misc; using Hang.HabboHotel.Pathfinding; using Hang.HabboHotel.Pets; using Hang.HabboHotel.RoomBots; using Hang.Messages; using Hang.Storage; using System.Data; using Kernel; using Hang.ServerManager; using System.Text; namespace Hang.HabboHotel.Rooms { class RoomUser { internal UInt32 HabboId; internal Int32 VirtualId; internal UInt32 RoomId; internal int IdleTime; internal int X; internal int Y; internal double Z; internal byte SqState; internal int AchievementPoints = 0; internal int CarryItemID; internal int CarryTimer; internal int RotHead; internal int RotBody; internal bool CanWalk; internal bool AllowOverride; internal int GoalX; internal int GoalY; internal Boolean SetStep; internal int SetX; internal int SetY; internal double SetZ; internal RoomBot BotData; internal BotAI BotAI; internal SwimType CurrentSwimType; internal bool Freezed; internal Coord Coordinate { get { return new Coord(X, Y); } } internal bool IsPet { get { return (IsBot && BotData.IsPet); } } internal Pet PetData; internal int IdFlood; internal int langMod = 0; internal DateTime LongFlood; public Boolean SquareEffect = false; internal Boolean IsWalking; internal Boolean UpdateNeeded; internal Boolean IsAsleep; internal Dictionary Statusses; public bool LastStep = false; public string LoopStatusMode = "default"; internal int DanceId; internal int TeleDelay; internal Boolean IsDancing { get { if (DanceId >= 1) { return true; } return false; } } internal Boolean NeedsAutokick { get { if (IsBot) { return false; } if (IdleTime >= 1800) { return true; } return false; } } internal bool IsTrading { get { if (IsBot) { return false; } if (Statusses.ContainsKey("trd")) { return true; } return false; } } internal bool IsBot { get { if (this.BotData != null) { return true; } return false; } } internal bool IsSpectator; internal int InternalRoomID; internal RoomUser(uint HabboId, uint RoomId, int VirtualId) { this.Freezed = false; this.HabboId = HabboId; this.RoomId = RoomId; this.VirtualId = VirtualId; this.IdleTime = 0; this.X = 0; this.Y = 0; this.Z = 0; this.RotHead = 0; this.RotBody = 0; this.UpdateNeeded = true; this.Statusses = new Dictionary(); //this.Path = new List(); //this.PathStep = 0; this.TeleDelay = -1; this.AllowOverride = false; this.CanWalk = true; this.IsSpectator = false; this.SqState = 3; //this.Steps = 0; this.InternalRoomID = 0; this.CurrentSwimType = SwimType.Walk; } internal RoomUser(uint HabboId, uint RoomId, int VirtualId, GameClient pClient) { this.mClient = pClient; this.Freezed = false; this.HabboId = HabboId; this.RoomId = RoomId; this.VirtualId = VirtualId; this.IdleTime = 0; this.X = 0; this.Y = 0; this.Z = 0; this.RotHead = 0; this.RotBody = 0; this.UpdateNeeded = true; this.Statusses = new Dictionary(); //this.Path = new List(); //this.PathStep = 0; this.TeleDelay = -1; this.AllowOverride = false; this.CanWalk = true; this.IsSpectator = false; this.SqState = 3; //this.Steps = 0; this.InternalRoomID = 0; this.CurrentSwimType = SwimType.Walk; } internal void Unidle() { this.IdleTime = 0; if (this.IsAsleep) { this.IsAsleep = false; ServerMessage Message = new ServerMessage(486); Message.AppendInt32(VirtualId); Message.AppendBoolean(false); GetRoom().SendMessage(Message); } } internal void Chat(GameClient Session, string Message, bool Shout) { if (Session != null) { if (Session.GetHabbo().Rank < 5) { if (GetRoom().RoomMuted) return; } } Unidle(); foreach (DataRow Row in Init.Words.Table.Rows) { string Filter = Row["word"].ToString().ToLower(); if (Message.ToLower().Contains(Filter)) { langMod++; Message = Message.Replace(Filter, "****"); if (langMod == 5) { Session.SendNotif("¡Hola, " + GetClient().GetHabbo().Username.ToString() + "!\r\nTe pedimos por favor que moderes el lenguaje ya que es inaceptable para el Hotel.\r\rUsted será callado durante: 30/segundos."); //Session.GetHabbo().Mute(); ServerMessage Packet = new ServerMessage(27); Packet.AppendInt32(30); GetClient().SendMessage(Packet); } } } if (!IsBot && GetClient().GetHabbo().Muted) { GetClient().SendNotif("You are muted."); return; } if (Message.StartsWith(":") && Session != null && ChatCommandHandler.Parse(Session, Message.Substring(1))) { return; } uint ChatHeader = 24; if (Shout) { ChatHeader = 26; } TimeSpan LastMessage = DateTime.Now - LongFlood; if (LastMessage.Seconds > 4) { IdFlood = 0; } if (LastMessage.Seconds < 4 && IdFlood > 5) { ServerMessage Packet = new ServerMessage(27); Packet.AppendInt32(30); GetClient().SendMessage(Packet); return; } LongFlood = DateTime.Now; IdFlood++; ServerMessage ChatMessage = new ServerMessage(ChatHeader); ChatMessage.AppendInt32(VirtualId); ChatMessage.AppendStringWithBreak(Message); ChatMessage.AppendInt32(GetSpeechEmotion(Message)); //GetRoom().TurnHeads(X, Y, HabboId); GetRoom().SendMessage(ChatMessage); if (!IsBot) { GetRoom().OnUserSay(this, Message, Shout); } if (!IsBot) { using (DatabaseClient MySQL = HangEnvironment.GetDatabase().GetClient()) { if (Init.IsEnabled == true) { MySQL.AddParamWithValue("message", Message); MySQL.AddParamWithValue("username", Session.GetHabbo().Username); MySQL.query("INSERT INTO chatlogs (user_id,room_id,hour,minute,timestamp,message,user_name,full_date) VALUES ('" + Session.GetHabbo().Id + "','" + GetRoom().RoomId + "','" + DateTime.Now.Hour + "','" + DateTime.Now.Minute + "','" + HangEnvironment.GetUnixTimestamp() + "',@message,@username,'" + DateTime.Now.ToLongDateString() + "')"); } } } } internal static int GetSpeechEmotion(string Message) { Message = Message.ToLower(); if (Message.Contains(":)") || Message.Contains(":d") || Message.Contains("=]") || Message.Contains("=d") || Message.Contains(":>")) { return 1; } if (Message.Contains(">:(") || Message.Contains(":@") || Message.Contains("grrrr")) { return 2; } if (Message.Contains(":o")) { return 3; } if (Message.Contains(":(") || Message.Contains("=[") || Message.Contains(":'(") || Message.Contains("='[")) { return 4; } return 0; } internal void ClearMovement(bool Update) { IsWalking = false; Statusses.Remove("mv"); GoalX = 0; GoalY = 0; SetStep = false; SetX = 0; SetY = 0; SetZ = 0; if (Update) { UpdateNeeded = true; } } internal void MoveTo(Coord c) { MoveTo(c.X, c.Y); } internal void MoveTo(int pX, int pY) { if (GetRoom().SquareHasUsers(pX, pY)) return; Unidle(); IsWalking = true; GoalX = pX; GoalY = pY; } internal void UnlockWalking() { this.AllowOverride = false; this.CanWalk = true; } internal void SetPos(int pX, int pY, double pZ) { this.X = pX; this.Y = pY; this.Z = pZ; } internal void CarryItem(int Item) { this.CarryItemID = Item; if (Item > 0) { this.CarryTimer = 240; } else { this.CarryTimer = 0; } ServerMessage Message = new ServerMessage(482); Message.AppendInt32(VirtualId); Message.AppendInt32(Item); GetRoom().SendMessage(Message); } internal void SetRot(int Rotation) { SetRot(Rotation, false); } internal void SetRot(int Rotation, bool HeadOnly) { if (Statusses.ContainsKey("lay") || IsWalking) { return; } int diff = this.RotBody - Rotation; this.RotHead = this.RotBody; if (Statusses.ContainsKey("sit") || HeadOnly) { if (RotBody == 2 || RotBody == 4) { if (diff > 0) { RotHead = RotBody - 1; } else if (diff < 0) { RotHead = RotBody + 1; } } else if (RotBody == 0 || RotBody == 6) { if (diff > 0) { RotHead = RotBody - 1; } else if (diff < 0) { RotHead = RotBody + 1; } } } else if (diff <= -2 || diff >= 2) { this.RotHead = Rotation; this.RotBody = Rotation; } else { this.RotHead = Rotation; } this.UpdateNeeded = true; } internal void AddStatus(string Key, string Value) { Statusses[Key] = Value; } internal void RemoveStatus(string Key) { if (Statusses.ContainsKey(Key)) { Statusses.Remove(Key); } } internal void Serialize(ServerMessage Message) { // @\Ihqu@UMeth0d13haiihr-893-45.hd-180-8.ch-875-62.lg-280-62.sh-290-62.ca-1813-.he-1601-[IMRAPD4.0JImMcIrDK // MSadiePull up a pew and have a brew!hr-500-45.hd-600-1.ch-823-75.lg-716-76.sh-730-62.he-1602-75IRBPA2.0PAK if (Message == null) return; if (IsSpectator) return; //if (GetClient() == null) Could be a bot // return; //if (GetClient().GetHabbo() == null) // return; if (!IsBot) { Message.AppendUInt(GetClient().GetHabbo().Id); Message.AppendStringWithBreak(GetClient().GetHabbo().Username); Message.AppendStringWithBreak(GetClient().GetHabbo().Motto); Message.AppendStringWithBreak(GetClient().GetHabbo().Look); Message.AppendInt32(VirtualId); Message.AppendInt32(X); Message.AppendInt32(Y); Message.AppendStringWithBreak(Z.ToString().Replace(',', '.')); Message.AppendInt32(2); Message.AppendInt32(1); Message.AppendStringWithBreak(GetClient().GetHabbo().Gender.ToLower()); Message.AppendInt32(-1); Message.AppendInt32(1); Message.AppendInt32(2); Message.AppendStringWithBreak(""); Message.AppendInt32(GetClient().GetHabbo().Achievements.Count * 10); // Points pending... } else { Message.AppendInt32(BotAI.BaseId); Message.AppendStringWithBreak(BotData.Name); Message.AppendStringWithBreak(BotData.Motto); Message.AppendStringWithBreak(BotData.Look); Message.AppendInt32(VirtualId); Message.AppendInt32(X); Message.AppendInt32(Y); Message.AppendStringWithBreak(Z.ToString().Replace(',', '.')); Message.AppendInt32(4); Message.AppendInt32((BotData.AiType == AIType.Pet) ? 2 : 3); if (BotData.AiType == AIType.Pet) { Message.AppendInt32(0); } } } internal void SerializeStatus(ServerMessage Message) { if (IsSpectator) { return; } Message.AppendInt32(VirtualId); Message.AppendInt32(X); Message.AppendInt32(Y); Message.AppendStringWithBreak(Z.ToString().Replace(',','.')); Message.AppendInt32(RotHead); Message.AppendInt32(RotBody); Message.AppendString("/"); foreach (KeyValuePair Status in Statusses) { Message.AppendString(Status.Key); Message.AppendString(" "); Message.AppendString(Status.Value); Message.AppendString("/"); } Message.AppendStringWithBreak("/"); } private GameClient mClient; internal GameClient GetClient() { if (IsBot) { return null; } if (mClient == null) mClient = HangEnvironment.GetGame().GetClientManager().GetClientByHabbo(HabboId); return mClient; } private Room mRoom; private Room GetRoom() { if (mRoom == null) mRoom = HangEnvironment.GetGame().GetRoomManager().GetRoom(RoomId); return mRoom; } } internal enum SwimType { Deep, Normal, Walk } }