internal void CreateGroup(string Name, string Desc, uint RoomId, string Badge, GameClient Session, int Colour1, int Colour2, out Group Group) { using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO groups (`name`, `desc`,`badge`,`owner_id`,`created`,`room_id`,`colour1`,`colour2`) VALUES" + "(@name, @desc, @badge, " + Session.GetHabbo().Id + ", UNIX_TIMESTAMP(), " + RoomId + ",'" + SymbolColours[Colour1].Colour + "','" + BackGroundColours[Colour2].Colour + "')"); dbClient.addParameter("name", Name); dbClient.addParameter("desc", Desc); dbClient.addParameter("badge", Badge); uint InsertId = (uint)dbClient.insertQuery(); dbClient.runFastQuery("UPDATE rooms SET group_id=" + InsertId + " WHERE id=" + RoomId + " LIMIT 1"); Dictionary<uint, GroupUser> Member = new Dictionary<uint, GroupUser>(); Member.Add(Session.GetHabbo().Id, new GroupUser(Session.GetHabbo().Id, InsertId, 2)); Groups.Add(InsertId, new Group((uint)InsertId, Name, Desc, RoomId, Badge, SilverwaveEnvironment.GetUnixTimestamp(), Session.GetHabbo().Id, Colour1, Colour2, Member, new List<uint>(), new Dictionary<uint,GroupUser>(), 0, 1)); Session.GetHabbo().UserGroups.Add(new GroupUser(Session.GetHabbo().Id, InsertId, 2)); dbClient.runFastQuery("INSERT INTO group_memberships (group_id, user_id, rank) VALUES (" + InsertId + ", " + Session.GetHabbo().Id + ", '2')"); Group = GetGroup(InsertId); dbClient.runFastQuery("UPDATE user_stats SET groupid=" + InsertId + " WHERE id= " + Session.GetHabbo().Id + " LIMIT 1"); dbClient.runFastQuery("DELETE FROM room_rights WHERE room_id=" + RoomId); } }
internal void CreateGroup(string Name, string Desc, uint RoomId, string Badge, GameClient Session, int Colour1, int Colour2, out Group Group) { using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO groups (`name`, `desc`,`badge`,`owner_id`,`created`,`room_id`,`colour1`,`colour2`) VALUES" + "(@name, @desc, @badge, " + Session.GetHabbo().Id + ", UNIX_TIMESTAMP(), " + RoomId + ",'" + Colour1 + "','" + Colour2 + "')"); dbClient.addParameter("name", Name); dbClient.addParameter("desc", Desc); dbClient.addParameter("badge", Badge); uint InsertId = (uint)dbClient.insertQuery(); dbClient.runFastQuery("UPDATE rooms SET group_id=" + InsertId + " WHERE id=" + RoomId + " LIMIT 1"); Console.Write(Colour1); Dictionary<uint, GroupUser> Member = new Dictionary<uint, GroupUser>(); Member.Add(Session.GetHabbo().Id, new GroupUser(Session.GetHabbo().Id, InsertId, 2)); Groups.Add(InsertId, new Group((uint)InsertId, Name, Desc, RoomId, Badge, SilverwaveEnvironment.GetUnixTimestamp(), Session.GetHabbo().Id, Colour1, Colour2, Member, new List<uint>(), new Dictionary<uint,GroupUser>(), 0, 1)); Session.GetHabbo().UserGroups.Add(new GroupUser(Session.GetHabbo().Id, InsertId, 2)); dbClient.runFastQuery("INSERT INTO group_memberships (group_id, user_id, rank) VALUES (" + InsertId + ", " + Session.GetHabbo().Id + ", '2')"); Group = GetGroup(InsertId); /*InsertGroupItem(InsertId, 393, 9, 4, "", "n_skin_speechbubbleskin", "Este Elemento muestra el nombre de tu Grupo, su descripción y su Placa. ¡Haz que lo conozca todo el mundo!", "stickie"); InsertGroupItem(InsertId, 27, 218, 3, "", "n_skin_metalskin", "¿Qué más?<br /><br />¡Haz clic en la barra de Elementos para encontrar tu Libro de Invitados para miembros del Grupo!<br /><br />Puede servirte para comunicarte con miembros de otros Grupos o configurarlo sólo para los miembros de tu Grupo", "stickie"); InsertGroupItem(InsertId, 26, 12, 2, "", "n_skin_metalskin", "¡Bienvenido a la página de tu " + Name + " Grupo!<br /><br />¡Aquí puedes editar la Página, elegir la Placa, crear los Datos del Grupo y hablar con el resto de miembros!<br /><br />Ahora mismo este Grupo no cuenta con más miembros. ¡Invita a un amigo!", "stickie"); InsertGroupItem(InsertId, 420, 260, 6, "", "n_skin_speechbubbleskin", "Este Elemento muestra a todos los miembros del Grupo y su categoría", "stickie"); InsertGroupItem(InsertId, 384, 338, 5, "MemberWidget", "w_skin_defaultskin", "", "widget"); InsertGroupItem(InsertId, 408, 85, 1, "GroupInfoWidget", "w_skin_notepadskin", "", "widget"); */ dbClient.runFastQuery("UPDATE user_stats SET groupid=" + InsertId + " WHERE id= " + Session.GetHabbo().Id + " LIMIT 1"); dbClient.runFastQuery("DELETE FROM room_rights WHERE room_id=" + RoomId); } }
private void Initialize(UInt32 Id, string Name, string Description, string Type, string Owner, int OwnerId, int Category, int State, int UsersMax, string ModelName, int Score, List<string> pTags, int AllowPets, int AllowPetsEating, int AllowWalkthrough, int Hidewall, string Password, string Wallpaper, string Floor, string Landscape, RoomData RoomData, bool RightOverride, int walltickness, int floorthickness, Group group, int GameId, int chattype, int chatballoon, int chatspeed, int chatmaxdis, int chatprotection, int whomute, int whokick, int whoban, uint groupid, List<Chatlog> Chat) { this.mDisposed = false; this.Id = Id; this.Name = Name; this.Description = Description; this.Owner = Owner; this.OwnerId = OwnerId; this.Category = Category; this.Type = Type; this.State = State; this.UsersNow = 0; this.UsersMax = UsersMax; this.ModelName = ModelName; this.Score = Score; tagCount = 0; this.Tags = new ArrayList(); foreach (string tag in pTags) { tagCount++; Tags.Add(tag); } this.ChatType = chattype; this.ChatBalloon = chatballoon; this.ChatSpeed = chatspeed; this.ChatMaxDistance = chatmaxdis; this.ChatFloodProtection = chatprotection; this.AllowPets = AllowPets; this.AllowPetsEating = AllowPetsEating; this.AllowWalkthrough = AllowWalkthrough; this.Hidewall = Hidewall; this.Group = group; this.Password = Password; this.Bans = new Dictionary<Int64, double>(); this.MutedUsers = new Dictionary<uint, uint>(); this.Wallpaper = Wallpaper; this.Floor = Floor; this.Landscape = Landscape; this.ActiveTrades = new ArrayList(); this.MutedPets = false; this.MutedBots = false; this.mCycleEnded = false; this.mRoomData = RoomData; this.EveryoneGotRights = RightOverride; this.roomMessages = new Queue(); this.chatMessageQueue = new Queue(); this.LoadedGroups = new Dictionary<uint, String>(); this.roomMessages = new Queue(); this.roomAlerts = new Queue(); this.roomBadge = new Queue(); this.roomKick = new Queue(); this.roomServerMessages = new Queue(); //this.DiceQueue = new Queue(); this.IdleTime = 0; this.RoomMuted = false; this.WallThickness = walltickness; this.FloorThickness = floorthickness; this.gamemap = new Gamemap(this); if (roomItemHandling == null) this.roomItemHandling = new RoomItemHandling(this); this.roomUserManager = new RoomUserManager(this); this.RoomChat = Chat; this.ForSale = false; this.SalePrice = 0; this.Event = SilverwaveEnvironment.GetGame().GetRoomEvents().GetEvent(Id); this.GameId = GameId; this.WhoCanBan = whoban; this.WhoCanKick = whokick; this.WhoCanBan = whoban; this.GroupId = groupid; LoadRights(); GetRoomItemHandler().LoadFurniture(); GetGameMap().GenerateMaps(); LoadMusic(); LoadBans(); InitUserBots(); this.Added = new List<Chatlog>(); using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE rooms SET users_now=1 WHERE id=" + Id + " LIMIT 1"); } SilverwaveEnvironment.GetGame().GetRoomManager().QueueActiveRoomAdd(mRoomData); }
internal void FillNull(UInt32 pId) { this.Id = pId; this.Name = "Unknown Room"; this.Description = "-"; this.Type = "private"; this.Owner = "-"; this.Category = 0; this.UsersNow = 0; this.UsersMax = 0; this.ModelName = "NO_MODEL"; this.CCTs = ""; this.Score = 0; this.Tags = new List<string>(); this.AllowPets = 1; this.AllowPetsEating = 0; this.AllowWalkthrough = 1; this.Hidewall = 0; this.Password = ""; this.Wallpaper = "0.0"; this.Floor = "0.0"; this.Landscape = "0.0"; this.WallThickness = 0; this.FloorThickness = 0; this.Group = null; this.AllowRightsOverride = false; this.Event = null; this.GameId = 0; this.WhoCanBan = 0; this.WhoCanKick = 0; this.WhoCanMute = 0; this.RoomChat = new List<Chatlog>(); mModel = SilverwaveEnvironment.GetGame().GetRoomManager().GetModel(ModelName); }
internal void Fill(Room Room) { this.Id = Room.RoomId; this.Name = Room.Name; this.Description = Room.Description; this.Type = Room.Type; this.Owner = Room.Owner; this.Category = Room.Category; this.State = Room.State; this.UsersNow = Room.UsersNow; this.UsersMax = Room.UsersMax; this.ModelName = Room.ModelName; this.Score = Room.Score; this.Tags = new List<string>(); foreach (string tag in Room.Tags.ToArray()) this.Tags.Add(tag); this.AllowPets = Room.AllowPets; this.AllowPetsEating = Room.AllowPetsEating; this.AllowWalkthrough = Room.AllowWalkthrough; this.Hidewall = Room.Hidewall; this.Password = Room.Password; this.Wallpaper = Room.Wallpaper; this.Floor = Room.Floor; this.Landscape = Room.Landscape; this.FloorThickness = Room.FloorThickness; this.WallThickness = Room.WallThickness; this.Group = Room.Group; this.Event = Room.Event; this.GameId = Room.GameId; this.ChatType = Room.ChatType; this.ChatBalloon = Room.ChatBalloon; this.ChatSpeed = Room.ChatSpeed; this.ChatMaxDistance = Room.ChatMaxDistance; this.ChatFloodProtection = Room.ChatFloodProtection; this.WhoCanMute = Room.WhoCanMute; this.WhoCanKick = Room.WhoCanKick; this.WhoCanBan = Room.WhoCanBan; this.RoomChat = Room.RoomChat; mModel = SilverwaveEnvironment.GetGame().GetRoomManager().GetModel(ModelName); }
internal void Fill(DataRow Row) { this.Id = Convert.ToUInt32(Row["id"]); this.Name = (string)Row["caption"]; this.Description = (string)Row["description"]; this.Type = (string)Row["roomtype"]; this.Owner = (string)Row["owner"]; this.OwnerId = 0; this.RoomChat = new List<Chatlog>(); using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE username = @owner"); dbClient.addParameter("owner", this.Owner); int result = dbClient.getInteger(); if(result > 0) this.OwnerId = result; dbClient.setQuery("SELECT user_id, message, timestamp FROM chatlogs WHERE room_id=@id ORDER BY timestamp DESC LIMIT 150"); dbClient.addParameter("id", this.Id); DataTable Table = dbClient.getTable(); foreach (DataRow mRow in Table.Rows) { RoomChat.Add(new Chatlog((uint)mRow[0], (string)mRow[1], Convert.ToDouble(mRow[2]))); } } switch (Row["state"].ToString().ToLower()) { case "open": this.State = 0; break; case "password": this.State = 2; break; case "locked": default: this.State = 1; break; } this.Category = (int)Row["category"]; if (!string.IsNullOrEmpty(Row["users_now"].ToString())) this.UsersNow = (int)Row["users_now"]; else this.UsersNow = 0; this.UsersMax = (int)Row["users_max"]; this.ModelName = (string)Row["model_name"]; this.CCTs = (string)Row["public_ccts"]; this.Score = (int)Row["score"]; this.Tags = new List<string>(); this.AllowPets = Convert.ToInt32(Row["allow_pets"].ToString()); this.AllowPetsEating = Convert.ToInt32(Row["allow_pets_eat"].ToString()); this.AllowWalkthrough = Convert.ToInt32(Row["allow_walkthrough"].ToString()); this.AllowRightsOverride = false; this.Hidewall = Convert.ToInt32(Row["allow_hidewall"].ToString()); this.Password = (string)Row["password"]; this.Wallpaper = (string)Row["wallpaper"]; this.Floor = (string)Row["floor"]; this.Landscape = (string)Row["landscape"]; this.FloorThickness = (int)Row["floorthick"]; this.WallThickness = (int)Row["wallthick"]; this.ChatType = (int)Row["chat_type"]; this.ChatBalloon = (int)Row["chat_balloon"]; this.ChatSpeed =(int)Row["chat_speed"]; this.ChatMaxDistance = (int)Row["chat_max_distance"]; this.ChatFloodProtection = (int)Row["chat_flood_protection"]; this.GameId = (int)Row["game_id"]; this.WhoCanMute = Convert.ToInt32(Row["mute_settings"]); this.WhoCanKick = Convert.ToInt32(Row["kick_settings"]); this.WhoCanBan = Convert.ToInt32(Row["ban_settings"]); this.GroupId = (uint)Row["group_id"]; this.Group = SilverwaveEnvironment.GetGame().GetGroupManager().GetGroup(this.GroupId); this.Event = SilverwaveEnvironment.GetGame().GetRoomEvents().GetEvent(Id); Dictionary<int, int> IconItems = new Dictionary<int,int>(); if (!string.IsNullOrEmpty(Row["icon_items"].ToString())) { foreach (string Bit in Row["icon_items"].ToString().Split('|')) { if (string.IsNullOrEmpty(Bit)) continue; string[] tBit = Bit.Replace('.', ',').Split(','); int a = 0; int b = 0; int.TryParse(tBit[0], out a); if (tBit.Length > 1) int.TryParse(tBit[1], out b); try { if (!IconItems.ContainsKey(a)) IconItems.Add(a, b); } catch (Exception e) { Logging.LogException("Exception: " + e.ToString() + "[" + Bit + "]"); } } } foreach (string Tag in Row["tags"].ToString().Split(',')) { this.Tags.Add(Tag); } mModel = SilverwaveEnvironment.GetGame().GetRoomManager().GetModel(ModelName); }
internal void SerializeGroupInfo(Group Group, ServerMessage Response, GameClient Session, Room Room, bool NewWindow = false) { DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime Time = origin.AddSeconds(Group.CreateTime); Response.Init(Outgoing.SerializeGroupInfo); Response.AppendInt32(Group.Id); Response.AppendBoolean(true); Response.AppendInt32(Group.State); // Type (0 = 50k users, 1 = Request, 2 = blocked, 3 = ?, 4 = ?.. Response.AppendString(Group.Name); Response.AppendString(Group.Description); Response.AppendString(Group.Badge); Response.AppendInt32(Group.RoomId); Response.AppendString((SilverwaveEnvironment.GetGame().GetRoomManager().GenerateRoomData(Group.RoomId) == null) ? "No room found.." : SilverwaveEnvironment.GetGame().GetRoomManager().GenerateRoomData(Group.RoomId).Name); // room name Response.AppendInt32((Group.CreatorId == Session.GetHabbo().Id) ? 3 : (Group.Requests.Contains(Session.GetHabbo().Id)) ? 2 : (Group.Members.ContainsKey(Session.GetHabbo().Id)) ? 1 : 0); //Member Response.AppendInt32(Group.Members.Count); // Members Response.AppendBoolean(Session.GetHabbo().FavouriteGroup == Group.Id); Response.AppendString(Time.Day + "-" + Time.Month + "-" + Time.Year); Response.AppendBoolean(Group.CreatorId == Session.GetHabbo().Id); Response.AppendBoolean((Group.Admins.ContainsKey(Session.GetHabbo().Id))); Response.AppendString((SilverwaveEnvironment.getHabboForId(Group.CreatorId) == null) ? "" : SilverwaveEnvironment.getHabboForId(Group.CreatorId).Username); Response.AppendBoolean(NewWindow); // Show group info Response.AppendBoolean(Group.AdminOnlyDeco == 0); // Any user can place furni in home room Response.AppendInt32(Group.Requests.Count); // Pending users Response.AppendBoolean(true); if (Room != null) Room.SendMessage(Response); else if (Session != null) Session.SendMessage(Response); /*if (Session.GetHabbo().Id == Group.CreatorId) SerializeGroupInfo(Group, Response, Session, false);*/ }
internal List<uint> GetGroupRequestsByString(Group Group, String SearchVal, uint Req) { if (string.IsNullOrWhiteSpace(SearchVal)) return Group.Requests; var Users = new List<uint>(); using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE username LIKE @query"); dbClient.addParameter("query", "%" + SearchVal + "%"); DataTable Table = dbClient.getTable(); if (Table != null) { foreach (DataRow Row in Table.Rows) { if (Group.Requests.Contains((uint)Row[0])) Users.Add((uint)Row[0]); } } } return Users; }
internal List<GroupUser> GetGroupUsersByString(Group Group, String SearchVal, uint Req) { var Users = new List<GroupUser>(); if (string.IsNullOrWhiteSpace(SearchVal)) { if (Req == 0) foreach (GroupUser U in Group.Members.Values) Users.Add(U); else foreach (GroupUser U in Group.Admins.Values) Users.Add(U); } else { using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE username LIKE @query"); dbClient.addParameter("query", "%" + SearchVal + "%"); DataTable Table = dbClient.getTable(); if (Table == null) { if (Req == 0) foreach (GroupUser U in Group.Members.Values) Users.Add(U); else foreach (GroupUser U in Group.Admins.Values) Users.Add(U); } else { foreach (DataRow Row in Table.Rows) { if (Group.Members.ContainsKey((uint)Row[0])) Users.Add(Group.Members[(uint)Row[0]]); } } } } return Users; }
internal ServerMessage SerializeGroupMembers(ServerMessage Response, Group Group, uint ReqType, GameClient Session, string SearchVal = "", int Page = 0) { if (Group == null || Session == null) return null; if (Page < 1) Page = 0; List<List<GroupUser>> Users = Split(GetGroupUsersByString(Group, SearchVal, ReqType)); Response.AppendInt32(Group.Id); Response.AppendString(Group.Name); Response.AppendInt32(Group.RoomId); Response.AppendString(Group.Badge); switch (ReqType) { case 0: Response.AppendInt32(Group.Members.Count); Response.AppendInt32(Users[(int)Page].Count); foreach (GroupUser User in Users[(int)Page]) { Habbo Habbo = SilverwaveEnvironment.getHabboForId(User.Id); if (Habbo == null) { Response.AppendInt32(0); Response.AppendInt32(0); Response.AppendString(""); Response.AppendString(""); Response.AppendString(""); } else { Response.AppendInt32((User.Rank == 2) ? 0 : (User.Rank == 1) ? 1 : 2); Response.AppendInt32(Habbo.Id); Response.AppendString(Habbo.Username); Response.AppendString(Habbo.Look); Response.AppendString(""); } } break; case 1: Response.AppendInt32(Group.Admins.Count); if (Group.Admins.Count > 0) { Response.AppendInt32(Users[(int)Page].Count); foreach (GroupUser User in Users[(int)Page]) { Habbo Habbo = SilverwaveEnvironment.getHabboForId(User.Id); if (Habbo == null) { Response.AppendInt32(0); Response.AppendInt32(0); Response.AppendString(""); Response.AppendString(""); Response.AppendString(""); } else { Response.AppendInt32((User.Rank == 2) ? 0 : (User.Rank == 1) ? 1 : 2); Response.AppendInt32(Habbo.Id); Response.AppendString(Habbo.Username); Response.AppendString(Habbo.Look); Response.AppendString(""); } } } else Response.AppendInt32(0); break; case 2: List<List<uint>> Userx = Split(GetGroupRequestsByString(Group, SearchVal, ReqType)); Response.AppendInt32(Group.Requests.Count); if (Group.Requests.Count > 0) { Response.AppendInt32(Userx[(int)Page].Count); foreach (uint User in Userx[(int)Page]) { Habbo Habbo = SilverwaveEnvironment.getHabboForId(User); if (Habbo == null) { Response.AppendInt32(0); Response.AppendInt32(0); Response.AppendString(""); Response.AppendString(""); Response.AppendString(""); } else { Response.AppendInt32(3); Response.AppendInt32(Habbo.Id); Response.AppendString(Habbo.Username); Response.AppendString(Habbo.Look); Response.AppendString(""); } } } else Response.AppendInt32(0); break; } Response.AppendBoolean((Session.GetHabbo().Id == Group.CreatorId)); Response.AppendInt32(14); Response.AppendInt32(Page); Response.AppendInt32(ReqType); // 0 = all users, 1 = admins, 2 = requests Response.AppendString(SearchVal); return Response; }
internal Group GetGroup(uint GroupId) { if (Groups != null) { if (Groups.ContainsKey(GroupId)) { return Groups[GroupId]; } else { using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT * FROM groups WHERE id=" + GroupId + " LIMIT 1"); DataRow dRow = dbClient.getRow(); if (dRow == null) { return null; } dbClient.setQuery("SELECT user_id, rank FROM group_memberships WHERE group_id=" + GroupId); DataTable d = dbClient.getTable(); dbClient.setQuery("SELECT user_id FROM group_requests WHERE group_id=" + GroupId); DataTable r = dbClient.getTable(); Dictionary<uint, GroupUser> Member = new Dictionary<uint, GroupUser>(); Dictionary<uint, GroupUser> Admins = new Dictionary<uint, GroupUser>(); List<uint> Requests = new List<uint>(); foreach (DataRow Row in d.Rows) { Member.Add((uint)Row[0], new GroupUser((uint)Row[0], (uint)GroupId, Convert.ToInt16(Row[1]))); if (Convert.ToInt16(Row[1]) == 1) Admins.Add((uint)Row[0], new GroupUser((uint)Row[0], (uint)GroupId, 1)); } foreach (DataRow Row in r.Rows) Requests.Add((uint)Row[0]); Group Group = new Group((uint)dRow[0], dRow[1].ToString(), dRow[2].ToString(), (uint)dRow[6], dRow[3].ToString(), (int)dRow[5], (uint)dRow[4], (int)dRow[8], (int)dRow[9], Member, Requests, Admins, Convert.ToUInt16(dRow[7]), Convert.ToUInt16(dRow[10])); Groups.Add((uint)dRow[0], Group); return Group; } } } return null; }