public void RefreshPets() { using (var queryReactor2 = Plus.GetDatabaseManager().GetQueryReactor()) { queryReactor2.SetQuery( string.Format("SELECT * FROM bots WHERE user_id = {0} AND room_id = 0 OR ai_type = 'fightpet' AND user_id = {0}", UserId)); var table2 = queryReactor2.GetTable(); if (table2 == null) { return; } foreach (DataRow botRow in table2.Rows) { switch ((string)botRow["ai_type"]) { case "pet": { queryReactor2.SetQuery(string.Format("SELECT * FROM pets_data WHERE id={0} LIMIT 1", botRow[0])); var row = queryReactor2.GetRow(); if (row == null) { continue; } var pet = Catalog.GeneratePetFromRow(botRow, row); AddPet(pet); } break; case "fightpet": { queryReactor2.SetQuery(string.Format("SELECT * FROM pets_data WHERE id={0} LIMIT 1", botRow[0])); var row = queryReactor2.GetRow(); if (row == null) { continue; } var pet = Catalog.GeneratePetFromRow(botRow, row); AddPet(pet); } break; case "generic": AddBot(BotManager.GenerateBotFromRow(botRow)); break; } } } SerializePetInventory(); }
internal void InitUserBots() { using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor.setQuery("SELECT * FROM bots WHERE room_id = " + this.RoomId + " AND ai_type = 'generic'"); DataTable table = queryreactor.getTable(); if (table != null) { foreach (DataRow dataRow in table.Rows) { queryreactor.setQuery("SELECT text, shout FROM bots_speech WHERE bots_speech.bot_id = '" + dataRow["id"] + "';"); DataTable table2 = queryreactor.getTable(); RoomBot roomBot = BotManager.GenerateBotFromRow(dataRow); List <RandomSpeech> list = new List <RandomSpeech>(); foreach (DataRow dataRow2 in table2.Rows) { list.Add(new RandomSpeech((string)dataRow2["text"], CyberEnvironment.EnumToBool(dataRow2["shout"].ToString()))); } List <BotResponse> list2 = new List <BotResponse>(); this.roomUserManager.DeployBot(new RoomBot(roomBot.BotId, roomBot.OwnerId, this.RoomId, AIType.Generic, "freeroam", roomBot.Name, roomBot.Motto, roomBot.Look, roomBot.X, roomBot.Y, (double)checked ((int)roomBot.Z), 4, 0, 0, 0, 0, ref list, ref list2, roomBot.Gender, roomBot.DanceId, roomBot.IsBartender), null); } } } }
/// <summary> /// Loads the inventory. /// </summary> internal void LoadInventory() { _floorItems.Clear(); _wallItems.Clear(); DataTable table; using (var queryReactor = Plus.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery("SELECT * FROM items_rooms WHERE user_id=@userid AND room_id='0' LIMIT 8000;"); queryReactor.AddParameter("userid", ((int)UserId)); table = queryReactor.GetTable(); } foreach (DataRow dataRow in table.Rows) { var id = Convert.ToUInt32(dataRow[0]); var itemId = Convert.ToUInt32(dataRow[3]); if (!Plus.GetGame().GetItemManager().ContainsItem(itemId)) { continue; } string extraData; if (!DBNull.Value.Equals(dataRow[4])) { extraData = (string)dataRow[4]; } else { extraData = string.Empty; } var group = Convert.ToUInt32(dataRow["group_id"]); string songCode; if (!DBNull.Value.Equals(dataRow["songcode"])) { songCode = (string)dataRow["songcode"]; } else { songCode = string.Empty; } var userItem = new UserItem(id, itemId, extraData, group, songCode); if (userItem.BaseItem.InteractionType == Interaction.MusicDisc && !SongDisks.Contains(id)) { SongDisks.Add(id, userItem); } if (userItem.IsWallItem) { if (!_wallItems.Contains(id)) { _wallItems.Add(id, userItem); } } else if (!_floorItems.Contains(id)) { _floorItems.Add(id, userItem); } } SongDisks.Clear(); _inventoryPets.Clear(); _inventoryBots.Clear(); using (var queryReactor2 = Plus.GetDatabaseManager().GetQueryReactor()) { queryReactor2.SetQuery( string.Format("SELECT * FROM bots WHERE user_id = {0} AND room_id = 0", UserId)); var table2 = queryReactor2.GetTable(); if (table2 == null) { return; } foreach (DataRow botRow in table2.Rows) { switch ((string)botRow["ai_type"]) { case "pet": { queryReactor2.SetQuery(string.Format("SELECT * FROM pets_data WHERE id={0} LIMIT 1", botRow[0])); var row = queryReactor2.GetRow(); if (row == null) { continue; } var pet = Catalog.GeneratePetFromRow(botRow, row); AddPet(pet); } break; case "fightpet": { queryReactor2.SetQuery(string.Format("SELECT * FROM pets_data WHERE id={0} LIMIT 1", botRow[0])); var row = queryReactor2.GetRow(); if (row == null) { continue; } var pet = Catalog.GeneratePetFromRow(botRow, row); AddPet(pet); } break; case "generic": AddBot(BotManager.GenerateBotFromRow(botRow)); break; } } } }
internal static UserData GetUserData(string sessionTicket, string ip, out byte errorCode) { DataTable dataTable = null; DataRow dataRow; uint Userid; DataTable dataTable2; DataTable table; DataRow row; DataTable dataTable3; DataTable dataTable4; DataTable dataTable5; DataRow dataRow2; DataTable dataTable6; DataTable dataTable7; DataTable dataTable8; DataTable dataTable9; DataTable dataTable10; DataTable dataTable11; DataTable dataTable12; DataTable dataTable13; DataTable table2; DataTable dataTable14; DataTable dataTable15; using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor.setQuery("SELECT * FROM users WHERE auth_ticket = @sso "); queryreactor.addParameter("sso", sessionTicket); queryreactor.addParameter("ipaddress", ip); dataRow = queryreactor.getRow(); if (dataRow == null) { errorCode = 1; throw new UserDataNotFoundException(string.Format("No user found with ip {0} and sso {1}.", ip, sessionTicket)); } Userid = Convert.ToUInt32(dataRow["id"]); queryreactor.runFastQuery("UPDATE users SET online='1' WHERE id=" + Userid + " LIMIT 1"); if (CyberEnvironment.GetGame().GetClientManager().GetClientByUserID(Userid) != null) { errorCode = 2; CyberEnvironment.GetGame().GetClientManager().GetClientByUserID(Userid).Disconnect(); return(null); } queryreactor.setQuery("SELECT * FROM user_achievement WHERE userid = " + Userid); dataTable2 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_talents WHERE userid = " + Userid); table = queryreactor.getTable(); queryreactor.setQuery("SELECT COUNT(*) FROM user_stats WHERE id=" + Userid); if (int.Parse(queryreactor.getString()) == 0) { queryreactor.runFastQuery("INSERT INTO user_stats (id) VALUES (" + Userid + ");"); } queryreactor.setQuery("SELECT * FROM user_stats WHERE id=" + Userid + " LIMIT 1"); row = queryreactor.getRow(); queryreactor.setQuery("SELECT room_id FROM user_favorites WHERE user_id = " + Userid); dataTable3 = queryreactor.getTable(); queryreactor.setQuery("SELECT ignore_id FROM user_ignores WHERE user_id = " + Userid); dataTable4 = queryreactor.getTable(); queryreactor.setQuery("SELECT tag FROM user_tags WHERE user_id = " + Userid); dataTable5 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_subscriptions WHERE user_id = " + Userid + " AND timestamp_expire > UNIX_TIMESTAMP() ORDER BY subscription_id DESC LIMIT 1"); dataRow2 = queryreactor.getRow(); queryreactor.setQuery("SELECT * FROM user_badges WHERE user_id = " + Userid); dataTable6 = queryreactor.getTable(); queryreactor.setQuery("SELECT `items`.* , COALESCE(`items_groups`.`group_id`, 0) AS group_id FROM `items` LEFT OUTER JOIN `items_groups` ON `items`.`id` = `items_groups`.`id` WHERE room_id='0' AND user_id=" + Userid + " LIMIT 8000"); dataTable7 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_effects WHERE user_id = " + Userid); dataTable8 = queryreactor.getTable(); queryreactor.setQuery("SELECT poll_id FROM user_polldata WHERE user_id = " + Userid + " GROUP BY poll_id;"); dataTable9 = queryreactor.getTable(); queryreactor.setQuery(string.Concat(new object[] { "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = ", Userid, " UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = ", Userid })); dataTable10 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_stats WHERE id=" + Userid + " LIMIT 1"); row = queryreactor.getRow(); queryreactor.setQuery("SELECT messenger_requests.from_id,messenger_requests.to_id,users.username FROM users JOIN messenger_requests ON users.id = messenger_requests.from_id WHERE messenger_requests.to_id = " + Userid); dataTable11 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM rooms WHERE owner = @name LIMIT 150"); queryreactor.addParameter("name", (string)dataRow["username"]); dataTable12 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM bots WHERE user_id = " + Userid + " AND room_id = 0 AND ai_type='pet'"); dataTable13 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_quests WHERE user_id = " + Userid); table2 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM bots WHERE user_id=" + Userid + " AND room_id=0 AND ai_type='generic'"); dataTable14 = queryreactor.getTable(); queryreactor.setQuery("SELECT group_id,rank FROM group_memberships WHERE user_id=" + Userid); dataTable = queryreactor.getTable(); queryreactor.setQuery(string.Concat(new object[] { "UPDATE user_info SET login_timestamp = '", CyberEnvironment.GetUnixTimestamp(), "' WHERE user_id = ", Userid, " ; " })); queryreactor.addParameter("ip", ip); queryreactor.runQuery(); queryreactor.setQuery("SELECT * FROM user_relationships WHERE user_id=@id"); queryreactor.addParameter("id", Userid); dataTable15 = queryreactor.getTable(); queryreactor.runFastQuery("UPDATE users SET online='1' WHERE id=" + Userid + " LIMIT 1"); } Dictionary <string, UserAchievement> dictionary = new Dictionary <string, UserAchievement>(); foreach (DataRow dataRow3 in dataTable2.Rows) { string text = (string)dataRow3["group"]; int level = (int)dataRow3["level"]; int progress = (int)dataRow3["progress"]; UserAchievement value = new UserAchievement(text, level, progress); dictionary.Add(text, value); } Dictionary <int, UserTalent> dictionary2 = new Dictionary <int, UserTalent>(); foreach (DataRow dataRow4 in table.Rows) { int num2 = (int)dataRow4["talent_id"]; int state = (int)dataRow4["talent_state"]; UserTalent value2 = new UserTalent(num2, state); dictionary2.Add(num2, value2); } List <uint> list = new List <uint>(); foreach (DataRow dataRow5 in dataTable3.Rows) { uint item = Convert.ToUInt32(dataRow5["room_id"]); list.Add(item); } List <uint> list2 = new List <uint>(); foreach (DataRow dataRow6 in dataTable4.Rows) { uint item2 = Convert.ToUInt32(dataRow6["ignore_id"]); list2.Add(item2); } List <string> list3 = new List <string>(); foreach (DataRow dataRow7 in dataTable5.Rows) { string item3 = dataRow7["tag"].ToString().Replace(" ", ""); list3.Add(item3); } Subscription sub = null; if (dataRow2 != null) { sub = new Subscription((int)dataRow2["subscription_id"], (int)dataRow2["timestamp_activated"], (int)dataRow2["timestamp_expire"], (int)dataRow2["timestamp_lastgift"]); } Dictionary <uint, RoomBot> dictionary3 = new Dictionary <uint, RoomBot>(); foreach (DataRow row2 in dataTable14.Rows) { RoomBot roomBot = BotManager.GenerateBotFromRow(row2); dictionary3.Add(roomBot.BotId, roomBot); } List <Badge> list4 = new List <Badge>(); foreach (DataRow dataRow8 in dataTable6.Rows) { string code = (string)dataRow8["badge_id"]; int slot = (int)dataRow8["badge_slot"]; list4.Add(new Badge(code, slot)); } int miniMailCount = 0; try { DataRow Rowi; using (IQueryAdapter dbClient = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { dbClient.setQuery("SELECT Count( IsReaded ) FROM xdrcms_minimail WHERE InBin = 0 AND IsReaded = 0 AND SenderId != " + Userid + " AND OwnerId = " + Userid); Rowi = dbClient.getRow(); } if (Rowi != null) { // We are using aXDR CMS with MiniMail! miniMailCount = int.Parse(Rowi[0].ToString()); } } catch { } List <UserItem> list5 = new List <UserItem>(); foreach (DataRow dataRow9 in dataTable7.Rows) { uint id = Convert.ToUInt32(dataRow9[0]); uint baseItem = Convert.ToUInt32(dataRow9[3]); string extraData; if (!DBNull.Value.Equals(dataRow9[4])) { extraData = (string)dataRow9[4]; } else { extraData = string.Empty; } uint group = Convert.ToUInt32(dataRow9["group_id"]); string songCode = (string)dataRow9["songcode"]; list5.Add(new UserItem(id, baseItem, extraData, group, songCode)); } List <AvatarEffect> list6 = new List <AvatarEffect>(); foreach (DataRow dataRow10 in dataTable8.Rows) { int effectId = (int)dataRow10["effect_id"]; int totalDuration = (int)dataRow10["total_duration"]; bool activated = CyberEnvironment.EnumToBool((string)dataRow10["is_activated"]); double activateTimestamp = (double)dataRow10["activated_stamp"]; list6.Add(new AvatarEffect(effectId, totalDuration, activated, activateTimestamp)); } HashSet <uint> pollSuggested = new HashSet <uint>(); foreach (DataRow Row in dataTable9.Rows) { uint pId = (uint)Row["poll_id"]; pollSuggested.Add(pId); } Dictionary <uint, MessengerBuddy> dictionary4 = new Dictionary <uint, MessengerBuddy>(); string arg_A3D_0 = (string)dataRow["username"]; int num3 = checked (dataTable10.Rows.Count - 700); if (num3 > 0) { using (IQueryAdapter queryreactor2 = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor2.runFastQuery(string.Concat(new object[] { "DELETE FROM messenger_friendships WHERE user_one_id=", Userid, " OR user_two_id=", Userid, " LIMIT ", num3 })); queryreactor2.setQuery(string.Concat(new object[] { "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = ", Userid, " UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = ", Userid })); dataTable10 = queryreactor2.getTable(); } } foreach (DataRow dataRow12 in dataTable10.Rows) { uint num4 = Convert.ToUInt32(dataRow12["id"]); string pUsername = (string)dataRow12["username"]; string pLook = (string)dataRow12["look"]; string pMotto = (string)dataRow12["motto"]; int pLastOnline = Convert.ToInt32(dataRow12["last_online"]); bool pAppearOffline = CyberEnvironment.EnumToBool(dataRow12["hide_online"].ToString()); bool pHideInroom = CyberEnvironment.EnumToBool(dataRow12["hide_inroom"].ToString()); if (num4 != Userid && !dictionary4.ContainsKey(num4)) { dictionary4.Add(num4, new MessengerBuddy(num4, pUsername, pLook, pMotto, pLastOnline, pAppearOffline, pHideInroom)); } } Dictionary <uint, MessengerRequest> dictionary5 = new Dictionary <uint, MessengerRequest>(); foreach (DataRow dataRow13 in dataTable11.Rows) { uint num5 = Convert.ToUInt32(dataRow13["from_id"]); uint num6 = Convert.ToUInt32(dataRow13["to_id"]); string pUsername2 = (string)dataRow13["username"]; if (num5 != Userid) { if (!dictionary5.ContainsKey(num5)) { dictionary5.Add(num5, new MessengerRequest(Userid, num5, pUsername2)); } } else { if (!dictionary5.ContainsKey(num6)) { dictionary5.Add(num6, new MessengerRequest(Userid, num6, pUsername2)); } } } HashSet <RoomData> list8 = new HashSet <RoomData>(); foreach (DataRow dataRow14 in dataTable12.Rows) { uint roomId = Convert.ToUInt32(dataRow14["id"]); list8.Add(CyberEnvironment.GetGame().GetRoomManager().FetchRoomData(roomId, dataRow14)); } Dictionary <uint, Pet> dictionary6 = new Dictionary <uint, Pet>(); foreach (DataRow dataRow15 in dataTable13.Rows) { using (IQueryAdapter queryreactor3 = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor3.setQuery("SELECT * FROM bots_petdata WHERE id=" + dataRow15[0] + " LIMIT 1"); DataRow row3 = queryreactor3.getRow(); if (row3 != null) { Pet pet = Catalog.GeneratePetFromRow(dataRow15, row3); dictionary6.Add(pet.PetId, pet); } } } Dictionary <uint, int> dictionary7 = new Dictionary <uint, int>(); foreach (DataRow dataRow16 in table2.Rows) { uint key = Convert.ToUInt32(dataRow16["quest_id"]); int value3 = (int)dataRow16["progress"]; if (dictionary7.ContainsKey(key)) { dictionary7.Remove(key); } dictionary7.Add(key, value3); } HashSet <GroupUser> list9 = new HashSet <GroupUser>(); foreach (DataRow dataRow17 in dataTable.Rows) { list9.Add(new GroupUser(Userid, (uint)dataRow17[0], (int)Convert.ToInt16(dataRow17[1]))); } Dictionary <int, Relationship> dictionary8 = new Dictionary <int, Relationship>(); foreach (DataRow dataRow18 in dataTable15.Rows) { dictionary8.Add((int)dataRow18[0], new Relationship((int)dataRow18[0], (int)dataRow18[2], Convert.ToInt32(dataRow18[3].ToString()))); } Habbo user = HabboFactory.GenerateHabbo(dataRow, row, list9); dataRow = null; dataTable2 = null; dataTable3 = null; dataTable4 = null; dataTable5 = null; dataRow2 = null; dataTable6 = null; dataTable7 = null; dataTable8 = null; dataTable10 = null; dataTable11 = null; dataTable12 = null; dataTable13 = null; dataTable14 = null; dataTable15 = null; dataTable9 = null; errorCode = 0; return(new UserData(Userid, dictionary, dictionary2, list, list2, list3, sub, list4, list5, list6, dictionary4, dictionary5, list8, dictionary6, dictionary7, user, dictionary3, dictionary8, pollSuggested, miniMailCount)); }
/// <summary> /// Gets the user data. /// </summary> /// <param name="sessionTicket">The session ticket.</param> /// <param name="ip">The ip.</param> /// <param name="errorCode">The error code.</param> /// <returns>UserData.</returns> /// <exception cref="UserDataNotFoundException"></exception> internal static UserData GetUserData(string sessionTicket, out uint errorCode) { uint userid = 0, miniMailCount = 0; errorCode = 1; DataTable groupsTable; DataRow dataRow; DataTable achievementsTable; DataTable talentsTable; DataRow statsTable; DataTable favoritesTable; DataTable ignoresTable; DataTable tagsTable; DataRow subscriptionsRow; DataTable badgesTable; DataTable itemsTable; DataTable effectsTable; DataTable pollsTable; DataTable friendsTable; DataTable friendsRequestsTable; DataTable myRoomsTable; DataTable petsTable; DataTable questsTable; DataTable botsTable; DataTable relationShipsTable; try { using (var queryReactor = Plus.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery("SELECT * FROM users WHERE auth_ticket = @ticket"); queryReactor.AddParameter("ticket", sessionTicket); dataRow = queryReactor.GetRow(); if (dataRow == null) { return(null); } errorCode = 0; userid = Convert.ToUInt32(dataRow["id"]); //queryReactor.RunFastQuery(string.Format("UPDATE users SET online = '1' WHERE id = '{0}'", userid)); if (Plus.GetGame().GetClientManager().GetClientByUserId(userid) != null) { if (Plus.GetGame().GetClientManager().GetClientByUserId(userid).LoggingOut) { //Plus.GetGame().GetClientManager().GetClientByUserId(userid).Disconnect("Force logout"); return(null); } else { Plus.GetGame().GetClientManager().GetClientByUserId(userid).Disconnect("User connected in other place"); } } queryReactor.SetQuery(string.Format("SELECT `group`, `level`, progress FROM users_achievements WHERE userid = {0}", Convert.ToUInt32(userid))); achievementsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT talent_id, talent_state FROM users_talents WHERE userid = {0}", Convert.ToUInt32(userid))); talentsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT COUNT(*) FROM users_stats WHERE id = {0}", Convert.ToUInt32(userid))); if (int.Parse(queryReactor.GetString()) == 0) { queryReactor.RunFastQuery(string.Format("INSERT INTO users_stats (id) VALUES ({0})", Convert.ToUInt32(userid))); } queryReactor.SetQuery(string.Format("SELECT room_id FROM users_favorites WHERE user_id = {0}", Convert.ToUInt32(userid))); favoritesTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT ignore_id FROM users_ignores WHERE user_id = {0}", Convert.ToUInt32(userid))); ignoresTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT tag FROM users_tags WHERE user_id = {0}", Convert.ToUInt32(userid))); tagsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT subscription_id, timestamp_activated, timestamp_expire, timestamp_lastgift FROM users_subscriptions WHERE user_id = {0} AND timestamp_expire > UNIX_TIMESTAMP() ORDER BY subscription_id DESC LIMIT 1", Convert.ToUInt32(userid))); subscriptionsRow = queryReactor.GetRow(); queryReactor.SetQuery(string.Format("SELECT * FROM users_badges WHERE user_id = {0}", Convert.ToUInt32(userid))); badgesTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT `items_rooms`.* , COALESCE(`items_groups`.`group_id`, 0) AS group_id FROM `items_rooms` LEFT OUTER JOIN `items_groups` ON `items_rooms`.`id` = `items_groups`.`id` WHERE room_id='0' AND user_id={0} LIMIT 8000", Convert.ToUInt32(userid))); itemsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT * FROM users_effects WHERE user_id = {0}", Convert.ToUInt32(userid))); effectsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT poll_id FROM users_polls WHERE user_id = {0} GROUP BY poll_id;", Convert.ToUInt32(userid))); pollsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = {0} UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = {0}", Convert.ToUInt32(userid))); friendsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT * FROM users_stats WHERE id = {0}", Convert.ToUInt32(userid))); statsTable = queryReactor.GetRow(); queryReactor.SetQuery(string.Format("SELECT messenger_requests.from_id,messenger_requests.to_id,users.Username FROM users JOIN messenger_requests ON users.id = messenger_requests.from_id WHERE messenger_requests.to_id = {0}", Convert.ToUInt32(userid))); friendsRequestsTable = queryReactor.GetTable(); queryReactor.SetQuery("SELECT * FROM rooms_data WHERE owner = @name LIMIT 150"); queryReactor.AddParameter("name", dataRow["username"]); myRoomsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT * FROM bots WHERE user_id = {0} AND room_id = 0 AND ai_type = 'fightpet'", Convert.ToUInt32(userid))); petsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT quest_id, progress FROM users_quests_data WHERE user_id = {0}", Convert.ToUInt32(userid))); questsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT * FROM bots WHERE user_id = {0} AND room_id=0 AND ai_type !='pet' AND ai_type != 'fightpet'", Convert.ToUInt32(userid))); botsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("SELECT group_id,rank FROM groups_members WHERE user_id = {0}", Convert.ToUInt32(userid))); groupsTable = queryReactor.GetTable(); queryReactor.SetQuery(string.Format("UPDATE users_info SET login_timestamp = '{1}' WHERE user_id = {0}", Convert.ToUInt32(userid), Plus.GetUnixTimeStamp())); queryReactor.RunQuery(); queryReactor.SetQuery(string.Format("SELECT * FROM users_relationships WHERE user_id = {0}", Convert.ToUInt32(userid))); relationShipsTable = queryReactor.GetTable(); queryReactor.RunFastQuery(string.Format("UPDATE users SET online='1' WHERE id = {0} LIMIT 1", Convert.ToUInt32(userid))); } var achievements = new Dictionary <string, UserAchievement>(); foreach (DataRow row in achievementsTable.Rows) { var text = (string)row["group"]; var level = (int)row["level"]; var progress = (int)row["progress"]; var value = new UserAchievement(text, level, progress); achievements.Add(text, value); } var talents = new Dictionary <int, UserTalent>(); foreach (DataRow row in talentsTable.Rows) { var num2 = (int)row["talent_id"]; var state = (int)row["talent_state"]; var value2 = new UserTalent(num2, state); talents.Add(num2, value2); } var favorites = (from DataRow row in favoritesTable.Rows select(uint) row["room_id"]).ToList(); var ignoreUsers = (from DataRow row in ignoresTable.Rows select(uint) row["ignore_id"]).ToList(); var tags = (from DataRow row in tagsTable.Rows select row["tag"].ToString().Replace(" ", "")).ToList(); var inventoryBots = (from DataRow row2 in botsTable.Rows select BotManager.GenerateBotFromRow(row2)).ToDictionary( roomBot => roomBot.BotId); var badges = (from DataRow dataRow8 in badgesTable.Rows select new Badge((string)dataRow8["badge_id"], (int)dataRow8["badge_slot"])).ToList(); Subscription subscriptions = null; if (subscriptionsRow != null) { subscriptions = new Subscription((int)subscriptionsRow["subscription_id"], (int)subscriptionsRow["timestamp_activated"], (int)subscriptionsRow["timestamp_expire"], (int)subscriptionsRow["timestamp_lastgift"]); } var items = new List <UserItem>(); foreach (DataRow row in itemsTable.Rows) { var id = Convert.ToUInt32(row[0]); var itemId = Convert.ToUInt32(row[3]); if (!Plus.GetGame().GetItemManager().ContainsItem(itemId)) { continue; } var extraData = !DBNull.Value.Equals(row[4]) ? (string)row[4] : string.Empty; var group = Convert.ToUInt32(row["group_id"]); var songCode = (string)row["songcode"]; items.Add(new UserItem(id, itemId, extraData, group, songCode)); } var effects = (from DataRow row in effectsTable.Rows let effectId = (int)row["effect_id"] let totalDuration = (int)row["total_duration"] let activated = Plus.EnumToBool((string)row["is_activated"]) let activateTimestamp = (double)row["activated_stamp"] let type = Convert.ToInt16(row["type"]) select new AvatarEffect(effectId, totalDuration, activated, activateTimestamp, type)).ToList(); var pollSuggested = new HashSet <uint>(); foreach (uint pId in from DataRow row in pollsTable.Rows select(uint) row["poll_id"]) { pollSuggested.Add(pId); } var friends = new Dictionary <uint, MessengerBuddy>(); var limit = (friendsTable.Rows.Count - 10000); if (limit > 0) { using (var queryreactor2 = Plus.GetDatabaseManager().GetQueryReactor()) { queryreactor2.RunFastQuery(string.Concat("DELETE FROM messenger_friendships WHERE user_one_id=", userid, " OR user_two_id=", userid, " LIMIT ", limit)); queryreactor2.SetQuery(string.Concat("SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = ", userid, " UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = ", userid)); friendsTable = queryreactor2.GetTable(); } } foreach (DataRow row in friendsTable.Rows) { var num4 = Convert.ToUInt32(row["id"]); var pUsername = (string)row["username"]; var pLook = (string)row["look"]; var pMotto = (string)row["motto"]; var pLastOnline = Convert.ToInt32(row["last_online"]); var pAppearOffline = Plus.EnumToBool(row["hide_online"].ToString()); var pHideInroom = Plus.EnumToBool(row["hide_inroom"].ToString()); if (num4 != userid && !friends.ContainsKey(num4)) { friends.Add(num4, new MessengerBuddy(num4, pUsername, pLook, pMotto, pLastOnline, pAppearOffline, pHideInroom)); } } var friendsRequests = new Dictionary <uint, MessengerRequest>(); foreach (DataRow row in friendsRequestsTable.Rows) { var num5 = Convert.ToUInt32(row["from_id"]); var num6 = Convert.ToUInt32(row["to_id"]); var pUsername2 = (string)row["Username"]; if (num5 != userid) { if (!friendsRequests.ContainsKey(num5)) { friendsRequests.Add(num5, new MessengerRequest(userid, num5, pUsername2)); } else if (!friendsRequests.ContainsKey(num6)) { friendsRequests.Add(num6, new MessengerRequest(userid, num6, pUsername2)); } } } var myRooms = new HashSet <RoomData>(); foreach (DataRow row in myRoomsTable.Rows) { var roomId = Convert.ToUInt32(row["id"]); myRooms.Add(Plus.GetGame().GetRoomManager().FetchRoomData(roomId, row)); } var pets = new Dictionary <uint, Pet>(); foreach (DataRow row in petsTable.Rows) { using (var queryreactor3 = Plus.GetDatabaseManager().GetQueryReactor()) { queryreactor3.SetQuery(string.Format("SELECT * FROM pets_data WHERE id={0} LIMIT 1", row[0])); var row3 = queryreactor3.GetRow(); if (row3 == null) { continue; } var pet = Catalog.GeneratePetFromRow(row, row3); pets.Add(pet.PetId, pet); } } var quests = new Dictionary <uint, int>(); foreach (DataRow row in questsTable.Rows) { var key = Convert.ToUInt32(row["quest_id"]); var value3 = (int)row["progress"]; if (quests.ContainsKey(key)) { quests.Remove(key); } quests.Add(key, value3); } var groups = new HashSet <GroupUser>(); foreach (DataRow row in groupsTable.Rows) { groups.Add(new GroupUser(userid, (uint)row[0], Convert.ToInt16(row[1]))); } var relationShips = relationShipsTable.Rows.Cast <DataRow>() .ToDictionary(row => (int)row[0], row => new Relationship((int)row[0], (int)row[2], Convert.ToInt32(row[3].ToString()))); var user = HabboFactory.GenerateHabbo(dataRow, statsTable, groups); dataRow = null; achievementsTable = null; favoritesTable = null; ignoresTable = null; tagsTable = null; subscriptionsRow = null; badgesTable = null; itemsTable = null; effectsTable = null; friendsTable = null; friendsRequestsTable = null; myRoomsTable = null; petsTable = null; botsTable = null; relationShipsTable = null; pollsTable = null; errorCode = 0; if (user.Rank >= Plus.StaffAlertMinRank) { friends.Add(0, new MessengerBuddy(0, "Staff Chat", "hr-831-45.fa-1206-91.sh-290-1331.ha-3129-100.hd-180-2.cc-3039-73.ch-3215-92.lg-270-73", string.Empty, 0, false, true)); } //if (user.Rank >= 2) // friends.Add(999999999, new MessengerBuddy(999999999, "VIP Chat", "hr-831-45.fa-1206-91.sh-290-1331.ha-3129-100.hd-180-2.cc-3039-73.ch-3215-92.lg-270-73", string.Empty, 999999999, false, true)); return(new UserData(userid, achievements, talents, favorites, ignoreUsers, tags, subscriptions, badges, items, effects, friends, friendsRequests, myRooms, pets, quests, user, inventoryBots, relationShips, pollSuggested, miniMailCount)); } catch (Exception e) { errorCode = 1; Out.WriteLine("An error occured when trying to login a user, could be possibly a error within the MySQL query.\n\n" + e.StackTrace, "", ConsoleColor.DarkRed); return(null); } }
/// <summary> /// Loads the inventory. /// </summary> internal void LoadInventory() { _floorItems.Clear(); _wallItems.Clear(); DataTable table; using (IQueryAdapter commitableQueryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { commitableQueryReactor.SetQuery( "SELECT * FROM items_rooms WHERE user_id=@userid AND room_id='0' LIMIT 8000;"); commitableQueryReactor.AddParameter("userid", (int)UserId); table = commitableQueryReactor.GetTable(); } foreach (DataRow dataRow in table.Rows) { uint id = Convert.ToUInt32(dataRow["id"]); string itemName = dataRow["item_name"].ToString(); if (!Yupi.GetGame().GetItemManager().ContainsItemByName(itemName)) { continue; } string extraData; if (!DBNull.Value.Equals(dataRow[4])) { extraData = (string)dataRow[4]; } else { extraData = string.Empty; } uint group = Convert.ToUInt32(dataRow["group_id"]); string songCode; if (!DBNull.Value.Equals(dataRow["songcode"])) { songCode = (string)dataRow["songcode"]; } else { songCode = string.Empty; } UserItem userItem = new UserItem(id, itemName, extraData, group, songCode); if (userItem.BaseItem.InteractionType == Interaction.MusicDisc && !SongDisks.Contains(id)) { SongDisks.Add(id, userItem); } if (userItem.IsWallItem) { if (!_wallItems.Contains(id)) { _wallItems.Add(id, userItem); } } else if (!_floorItems.Contains(id)) { _floorItems.Add(id, userItem); } } //SongDisks.Clear(); _inventoryPets.Clear(); _inventoryBots.Clear(); using (IQueryAdapter commitableQueryReactor2 = Yupi.GetDatabaseManager().GetQueryReactor()) { commitableQueryReactor2.SetQuery($"SELECT * FROM bots_data WHERE user_id = {UserId} AND room_id = 0"); DataTable table2 = commitableQueryReactor2.GetTable(); if (table2 == null) { return; } foreach (DataRow botRow in table2.Rows) { if ((string)botRow["ai_type"] == "generic") { AddBot(BotManager.GenerateBotFromRow(botRow)); } } commitableQueryReactor2.SetQuery($"SELECT * FROM pets_data WHERE user_id = {UserId} AND room_id = 0"); DataTable table3 = commitableQueryReactor2.GetTable(); if (table3 == null) { return; } foreach (DataRow petRow in table3.Rows) { if ((string)petRow["ai_type"] == "pet") { Pet pet = CatalogManager.GeneratePetFromRow(petRow); if (_inventoryPets.Contains(pet.PetId)) { _inventoryPets.Remove(pet.PetId); } _inventoryPets.Add(pet.PetId, pet); } } } }