예제 #1
0
        /// <summary>
        /// Creates the group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="desc">The desc.</param>
        /// <param name="roomId">The room identifier.</param>
        /// <param name="badge">The badge.</param>
        /// <param name="session">The session.</param>
        /// <param name="colour1">The colour1.</param>
        /// <param name="colour2">The colour2.</param>
        /// <param name="group">The group.</param>
        internal void CreateGroup(string name, string desc, uint roomId, string badge, GameClient session, int colour1,
            int colour2, out Guild group)
        {
            using (IQueryAdapter queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor())
            {
                queryReactor.SetQuery(string.Format("INSERT INTO groups_data (`name`, `desc`,`badge`,`owner_id`,`created`,`room_id`,`colour1`,`colour2`) VALUES(@name,@desc,@badge,'{0}',UNIX_TIMESTAMP(),'{1}','{2}','{3}')", session.GetHabbo().Id, roomId, colour1, colour2));
                queryReactor.AddParameter("name", name);
                queryReactor.AddParameter("desc", desc);
                queryReactor.AddParameter("badge", badge);

                int id = (int)queryReactor.InsertQuery();
                queryReactor.RunFastQuery(string.Format("UPDATE rooms_data SET group_id='{0}' WHERE id='{1}' LIMIT 1", id, roomId));
                var dictionary = new Dictionary<uint, GroupUser> { { session.GetHabbo().Id, new GroupUser(session.GetHabbo().Id, id, 2, AzureEmulator.GetUnixTimeStamp()) } };
                group = new Guild(id, name, desc, roomId, badge, AzureEmulator.GetUnixTimeStamp(), session.GetHabbo().Id, colour1, colour2, dictionary, new List<uint>(), new Dictionary<uint, GroupUser>(), 0u, 1u, false, name, desc, 0, 0.0, 0, string.Empty, 0, 0, 1, 1, 2);
                Groups.Add(id, group);
                queryReactor.RunFastQuery(string.Format("INSERT INTO groups_members (group_id, user_id, rank, date_join) VALUES ('{0}','{1}','2','{2}')", id, session.GetHabbo().Id, AzureEmulator.GetUnixTimeStamp()));
                var room = AzureEmulator.GetGame().GetRoomManager().GetRoom(roomId);
                if (room != null)
                {
                    room.RoomData.Group = group;
                    room.RoomData.GroupId = id;
                }
                GroupUser user = new GroupUser(session.GetHabbo().Id, id, 2, AzureEmulator.GetUnixTimeStamp());
                session.GetHabbo().UserGroups.Add(user);
                group.Admins.Add(session.GetHabbo().Id, user);
                queryReactor.RunFastQuery(string.Format("UPDATE users_stats SET favourite_group='{0}' WHERE id='{1}' LIMIT 1", id, session.GetHabbo().Id));
                queryReactor.RunFastQuery(string.Format("DELETE FROM rooms_rights WHERE room_id='{0}'", roomId));
            }
        }
예제 #2
0
 /// <summary>
 /// Serializes the group information.
 /// </summary>
 /// <param name="group">The group.</param>
 /// <param name="response">The response.</param>
 /// <param name="session">The session.</param>
 /// <param name="room">The room.</param>
 /// <param name="newWindow">if set to <c>true</c> [new window].</param>
 internal void SerializeGroupInfo(Guild group, ServerMessage response, GameClient session, Room room,
     bool newWindow = false)
 {
     if (room == null || group == null)
         return;
     DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
     DateTime dateTime2 = dateTime.AddSeconds(group.CreateTime);
     response.Init(LibraryParser.OutgoingRequest("GroupDataMessageComposer"));
     response.AppendInteger(group.Id);
     response.AppendBool(true);
     response.AppendInteger(group.State);
     response.AppendString(group.Name);
     response.AppendString(group.Description);
     response.AppendString(group.Badge);
     response.AppendInteger(group.RoomId);
     response.AppendString((AzureEmulator.GetGame().GetRoomManager().GenerateRoomData(group.RoomId) == null) ? "No room found.." : AzureEmulator.GetGame().GetRoomManager().GenerateRoomData(group.RoomId).Name);
     response.AppendInteger((group.CreatorId == session.GetHabbo().Id) ? 3 : (group.Requests.Contains(session.GetHabbo().Id) ? 2 : (group.Members.ContainsKey(session.GetHabbo().Id) ? 1 : 0)));
     response.AppendInteger(group.Members.Count);
     response.AppendBool(session.GetHabbo().FavouriteGroup == group.Id);
     response.AppendString(string.Format("{0}-{1}-{2}", dateTime2.Day.ToString("00"), dateTime2.Month.ToString("00"), dateTime2.Year));
     response.AppendBool(group.CreatorId == session.GetHabbo().Id);
     response.AppendBool(group.Admins.ContainsKey(session.GetHabbo().Id));
     response.AppendString((AzureEmulator.GetHabboById(group.CreatorId) == null) ? string.Empty : AzureEmulator.GetHabboById(group.CreatorId).UserName);
     response.AppendBool(newWindow);
     response.AppendBool(group.AdminOnlyDeco == 0u);
     response.AppendInteger(group.Requests.Count);
     response.AppendBool(group.HasForum);
     room.SendMessage(response);
 }
예제 #3
0
        /// <summary>
        /// Serializes the group members.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="group">The group.</param>
        /// <param name="reqType">Type of the req.</param>
        /// <param name="session">The session.</param>
        /// <param name="searchVal">The search value.</param>
        /// <param name="page">The page.</param>
        /// <returns>ServerMessage.</returns>
        internal ServerMessage SerializeGroupMembers(ServerMessage response, Guild group, uint reqType,
            GameClient session, string searchVal = "", int page = 0)
        {
            if (group == null || session == null)
                return null;
            if (page < 1)
                page = 0;
            var list = Split(GetGroupUsersByString(group, searchVal, reqType));
            response.AppendInteger(group.Id);
            response.AppendString(group.Name);
            response.AppendInteger(group.RoomId);
            response.AppendString(group.Badge);
            switch (reqType)
            {
                case 0u:
                    response.AppendInteger(group.Members.Count);
                    response.AppendInteger(list[page].Count);
                    using (var enumerator = list[page].GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            GroupUser current = enumerator.Current;
                            var habboForId = AzureEmulator.GetHabboById(current.Id);
                            if (habboForId == null)
                            {
                                response.AppendInteger(0);
                                response.AppendInteger(0);
                                response.AppendString(string.Empty);
                                response.AppendString(string.Empty);
                                response.AppendString(string.Empty);
                            }
                            else
                            {
                                response.AppendInteger((current.Rank == 2) ? 0 : ((current.Rank == 1) ? 1 : 2));
                                response.AppendInteger(habboForId.Id);
                                response.AppendString(habboForId.UserName);
                                response.AppendString(habboForId.Look);
                                response.AppendString(AzureEmulator.GetGroupDateJoinString(current.DateJoin));
                            }
                        }
                        goto AppendRest;
                    }
                case 1u:
                    break;

                case 2u:
                    {
                        var list2 = Split(GetGroupRequestsByString(group, searchVal, reqType));
                        response.AppendInteger(group.Requests.Count);
                        if (group.Requests.Count > 0)
                        {
                            response.AppendInteger(list2[page].Count);
                            using (var enumerator2 = list2[page].GetEnumerator())
                            {
                                while (enumerator2.MoveNext())
                                {
                                    var current2 = enumerator2.Current;
                                    var habboForId2 = AzureEmulator.GetHabboById(current2);
                                    if (habboForId2 == null)
                                    {
                                        response.AppendInteger(0);
                                        response.AppendInteger(0);
                                        response.AppendString(string.Empty);
                                        response.AppendString(string.Empty);
                                        response.AppendString(string.Empty);
                                    }
                                    else
                                    {
                                        response.AppendInteger(3);
                                        response.AppendInteger(habboForId2.Id);
                                        response.AppendString(habboForId2.UserName);
                                        response.AppendString(habboForId2.Look);
                                        response.AppendString("");
                                    }
                                }
                                goto AppendRest;
                            }
                        }
                        response.AppendInteger(0);
                        goto AppendRest;
                    }
                default:
                    goto AppendRest;
            }
            response.AppendInteger(group.Admins.Count);
            if (group.Admins.Count > 0)
            {
                response.AppendInteger(list[page].Count);
                using (var enumerator3 = list[page].GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        GroupUser current3 = enumerator3.Current;
                        var habboForId3 = AzureEmulator.GetHabboById(current3.Id);
                        if (habboForId3 == null)
                        {
                            response.AppendInteger(0);
                            response.AppendInteger(0);
                            response.AppendString(string.Empty);
                            response.AppendString(string.Empty);
                            response.AppendString(string.Empty);
                        }
                        else
                        {
                            response.AppendInteger((current3.Rank == 2) ? 0 : ((current3.Rank == 1) ? 1 : 2));
                            response.AppendInteger(habboForId3.Id);
                            response.AppendString(habboForId3.UserName);
                            response.AppendString(habboForId3.Look);
                            response.AppendString(AzureEmulator.GetGroupDateJoinString(current3.DateJoin));
                        }
                    }
                    goto AppendRest;
                }
            }
            response.AppendInteger(0);
            AppendRest:
            response.AppendBool(session.GetHabbo().Id == group.CreatorId);
            response.AppendInteger(14);
            response.AppendInteger(page);
            response.AppendInteger(reqType);
            response.AppendString(searchVal);
            return response;
        }
예제 #4
0
 /// <summary>
 /// Gets the group users by string.
 /// </summary>
 /// <param name="Group">The group.</param>
 /// <param name="searchVal">The search value.</param>
 /// <param name="req">The req.</param>
 /// <returns>List&lt;GroupUser&gt;.</returns>
 internal List<GroupUser> GetGroupUsersByString(Guild Group, string searchVal, uint req)
 {
     List<GroupUser> list = new List<GroupUser>();
     if (string.IsNullOrWhiteSpace(searchVal))
     {
         if (req == 0u)
             using (var enumerator = Group.Members.Values.GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     var current = enumerator.Current;
                     list.Add(current);
                 }
                 return list;
             }
         using (var enumerator2 = Group.Admins.Values.GetEnumerator())
         {
             while (enumerator2.MoveNext())
             {
                 var current2 = enumerator2.Current;
                 list.Add(current2);
             }
             return list;
         }
     }
     using (var queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor())
     {
         queryReactor.SetQuery("SELECT id FROM users WHERE username LIKE @name");
         queryReactor.AddParameter("name", "%" + searchVal + "%");
         DataTable table = queryReactor.GetTable();
         if (table == null)
         {
             if (req == 0u)
                 using (var enumerator3 = Group.Members.Values.GetEnumerator())
                 {
                     while (enumerator3.MoveNext())
                     {
                         GroupUser current3 = enumerator3.Current;
                         list.Add(current3);
                     }
                     return list;
                 }
             using (var enumerator4 = Group.Admins.Values.GetEnumerator())
             {
                 while (enumerator4.MoveNext())
                 {
                     GroupUser current4 = enumerator4.Current;
                     list.Add(current4);
                 }
                 return list;
             }
         }
         list.AddRange(from DataRow dataRow in table.Rows where Group.Members.ContainsKey((uint)dataRow[0]) select Group.Members[(uint)dataRow[0]]);
     }
     return list;
 }
예제 #5
0
 /// <summary>
 /// Gets the group requests by string.
 /// </summary>
 /// <param name="Group">The group.</param>
 /// <param name="searchVal">The search value.</param>
 /// <param name="req">The req.</param>
 /// <returns>List&lt;System.UInt32&gt;.</returns>
 internal List<uint> GetGroupRequestsByString(Guild Group, string searchVal, uint req)
 {
     if (Group == null)
         return null;
     if (string.IsNullOrWhiteSpace(searchVal))
         return Group.Requests;
     List<uint> list = new List<uint>();
     using (IQueryAdapter queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor())
     {
         queryReactor.SetQuery("SELECT id FROM users WHERE username LIKE @name");
         queryReactor.AddParameter("name", "%" + searchVal + "%");
         DataTable table = queryReactor.GetTable();
         if (table == null)
             return list;
         list.AddRange(from DataRow dataRow in table.Rows where Group.Requests.Contains((uint)dataRow[0]) select (uint)dataRow[0]);
     }
     return list;
 }
예제 #6
0
 /// <summary>
 /// Gets the group.
 /// </summary>
 /// <param name="groupId">The group identifier.</param>
 /// <returns>Guild.</returns>
 internal Guild GetGroup(int groupId)
 {
     if (Groups == null)
         return null;
     if (Groups.Contains(groupId))
         return (Guild)Groups[groupId];
     using (IQueryAdapter queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor())
     {
         queryReactor.SetQuery(string.Format("SELECT * FROM groups_data WHERE id='{0}' LIMIT 1", groupId));
         var row = queryReactor.GetRow();
         if (row == null)
             return null;
         queryReactor.SetQuery(string.Format("SELECT user_id, rank, date_join FROM groups_members WHERE group_id='{0}'",
             groupId));
         DataTable table = queryReactor.GetTable();
         queryReactor.SetQuery(string.Format("SELECT user_id FROM groups_requests WHERE group_id='{0}'", groupId));
         DataTable table2 = queryReactor.GetTable();
         var dictionary = new Dictionary<uint, GroupUser>();
         var dictionary2 = new Dictionary<uint, GroupUser>();
         foreach (DataRow dataRow in table.Rows)
         {
             dictionary.Add((uint)dataRow[0], new GroupUser((uint)dataRow[0], groupId, int.Parse(dataRow[1].ToString()), (int)dataRow[2]));
             if (int.Parse(dataRow[1].ToString()) >= 1)
                 dictionary2.Add((uint)dataRow[0], new GroupUser((uint)dataRow[0], groupId, int.Parse(dataRow[1].ToString()), (int)dataRow[2]));
         }
         var list = (from DataRow dataRow2 in table2.Rows select (uint)dataRow2[0]).ToList();
         Guild group = new Guild(groupId, (string)row["name"], (string)row["desc"], (uint)row["room_id"], (string)row["badge"], (int)row["created"], (uint)row["owner_id"], (int)row["colour1"], (int)row["colour2"], dictionary, list, dictionary2, (uint)row["state"], (uint)row["admindeco"], (string)row["has_forum"] == "1", (string)row["forum_name"], (string)row["forum_description"], (uint)row["forum_messages_count"], (uint)row["forum_score"], (uint)row["forum_lastposter_id"], (string)row["forum_lastposter_name"], (int)row["forum_lastposter_timestamp"], (int)row["who_can_read"], (int)row["who_can_post"], (int)row["who_can_thread"], (int)row["who_can_mod"]);
         this.Groups.Add(groupId, group);
         return group;
     }
 }
예제 #7
0
파일: RoomData.cs 프로젝트: BjkGkh/Azure2
 /// <summary>
 /// Fills the null.
 /// </summary>
 /// <param name="id">The identifier.</param>
 internal void FillNull(uint id)
 {
     Id = id;
     Name = "Unknown Room";
     Description = "-";
     Type = "private";
     Owner = "-";
     Category = 0;
     UsersNow = 0;
     UsersMax = 0;
     ModelName = "NO_MODEL";
     CCTs = string.Empty;
     Score = 0;
     Tags = new List<string>();
     AllowPets = true;
     AllowPetsEating = false;
     AllowWalkThrough = true;
     HideWall = false;
     PassWord = string.Empty;
     WallPaper = "0.0";
     Floor = "0.0";
     LandScape = "0.0";
     WallThickness = 0;
     FloorThickness = 0;
     Group = null;
     AllowRightsOverride = false;
     Event = null;
     GameId = 0;
     WhoCanBan = 0;
     WhoCanKick = 0;
     WhoCanMute = 0;
     TradeState = 2;
     State = 0;
     RoomChat = new ConcurrentStack<Chatlog>();
     WordFilter = new List<string>();
     WallHeight = -1;
     _model = AzureEmulator.GetGame().GetRoomManager().GetModel(ModelName, Id);
     CompetitionStatus = 0;
 }
예제 #8
0
파일: RoomData.cs 프로젝트: BjkGkh/Azure2
        /// <summary>
        /// Fills the specified row.
        /// </summary>
        /// <param name="row">The row.</param>
        internal void Fill(DataRow row)
        {
            try
            {
                Id = Convert.ToUInt32(row["id"]);
                Name = (string)row["caption"];
                PassWord = (string)row["password"];
                Description = (string)row["description"];
                Type = (string)row["roomtype"];
                Owner = (string)row["owner"];
                OwnerId = 0;
                RoomChat = new ConcurrentStack<Chatlog>();
                WordFilter = new List<string>();

                using (var queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor())
                {
                    queryReactor.SetQuery("SELECT id FROM users WHERE username = @name");
                    queryReactor.AddParameter("name", Owner);
                    uint integer = Convert.ToUInt32(queryReactor.GetInteger());

                    OwnerId = integer != uint.MinValue ? Convert.ToInt32(integer) : 0;

                    queryReactor.SetQuery(string.Format("SELECT user_id, message, timestamp FROM users_chatlogs WHERE room_id= '{0}' ORDER BY timestamp ASC LIMIT 150", Id));
                    var table = queryReactor.GetTable();
                    foreach (DataRow dataRow in table.Rows)
                    {
                        RoomChat.Push(new Chatlog((uint)dataRow[0], (string)dataRow[1], AzureEmulator.UnixToDateTime(int.Parse(dataRow[2].ToString())), true, Id));
                    }

                    queryReactor.SetQuery(string.Format("SELECT word FROM rooms_wordfilter WHERE room_id = '{0}'", Id));
                    DataTable tableFilter = queryReactor.GetTable();

                    foreach (DataRow dataRow in tableFilter.Rows)
                    {
                        WordFilter.Add(dataRow["word"].ToString());
                    }
                }
                var roomState = row["state"].ToString().ToLower();

                switch (roomState)
                {
                    case "locked":
                        State = 1;
                        break;

                    case "password":
                        State = 2;
                        break;

                    case "open":
                    default:
                        State = 0;
                        break;
                }

                ModelName = (string)row["model_name"];
                WallPaper = (string)row["wallpaper"];
                Floor = (string)row["floor"];
                LandScape = (string)row["landscape"];
                CCTs = (string)row["public_ccts"];

                int.TryParse(row["trade_state"].ToString(), out TradeState);
                int.TryParse(row["category"].ToString(), out Category);
                int.TryParse(row["walls_height"].ToString(), out WallHeight);
                int.TryParse(row["score"].ToString(), out Score);
                int.TryParse(row["floorthick"].ToString(), out FloorThickness);
                int.TryParse(row["wallthick"].ToString(), out WallThickness);
                int.TryParse(row["chat_type"].ToString(), out ChatType);
                int.TryParse(row["game_id"].ToString(), out GameId);
                int.TryParse(row["mute_settings"].ToString(), out WhoCanMute);
                int.TryParse(row["kick_settings"].ToString(), out WhoCanKick);
                int.TryParse(row["ban_settings"].ToString(), out WhoCanBan);

                uint.TryParse(row["users_now"].ToString(), out UsersNow);
                uint.TryParse(row["users_max"].ToString(), out UsersMax);
                int.TryParse(row["group_id"].ToString(), out GroupId);
                uint.TryParse(row["chat_balloon"].ToString(), out ChatBalloon);
                uint.TryParse(row["chat_speed"].ToString(), out ChatSpeed);
                uint.TryParse(row["chat_max_distance"].ToString(), out ChatMaxDistance);
                uint.TryParse(row["chat_flood_protection"].ToString(), out ChatFloodProtection);

                AllowPets = AzureEmulator.EnumToBool(row["allow_pets"].ToString());
                AllowPetsEating = AzureEmulator.EnumToBool(row["allow_pets_eat"].ToString());
                AllowWalkThrough = AzureEmulator.EnumToBool(row["allow_walkthrough"].ToString());
                HideWall = AzureEmulator.EnumToBool(row["hidewall"].ToString());

                AllowRightsOverride = false;

                Group = AzureEmulator.GetGame().GetGroupManager().GetGroup(GroupId);
                Event = AzureEmulator.GetGame().GetRoomEvents().GetEvent(Id);
                _model = AzureEmulator.GetGame().GetRoomManager().GetModel(ModelName, Id);
                CompetitionStatus = 0;

                /*
                var dictionary = new Dictionary<int, int>();
                if (!string.IsNullOrEmpty(row["icon_items"].ToString()))
                {
                    string[] array = row["icon_items"].ToString().Split('|');
                    foreach (string text in array)
                    {
                        if (string.IsNullOrEmpty(text))
                        {
                            continue;
                        }
                        string[] array2 = text.Replace('.', ',').Split(',');
                        int key = 0;
                        int value = 0;
                        int.TryParse(array2[0], out key);
                        if (array2.Length > 1)
                        {
                            int.TryParse(array2[1], out value);
                        }
                        try
                        {
                            if (!dictionary.ContainsKey(key))
                            {
                                dictionary.Add(key, value);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logging.LogException("Exception: " + ex + "[" + text + "]");
                        }
                    }
                }
                 */

                Tags = new List<string>();

                if (row.IsNull("tags") || !string.IsNullOrEmpty(row["tags"].ToString()))
                    return;

                foreach (var item in row["tags"].ToString().Split(','))
                    Tags.Add(item);
            }
            catch (Exception ex)
            {
                Logging.LogException("Exception on RoomData Loading (Fill Void): " + ex);
            }
        }