internal void GiveBadge(string Badge, int Slot, Boolean InDatabase) { if (HasBadge(Badge)) { return; } if (InDatabase) { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO user_badges (user_id,badge_id,badge_slot) VALUES (" + UserId + ",@badge," + Slot + ")"); dbClient.addParameter("badge", Badge); dbClient.runQuery(); } } Badges.Add(Badge, new Badge(Badge, Slot)); }
internal static ChatMessage CreateMessage(string message, GameClient user, Room room) { uint userID = user.GetHabbo().Id; string username = user.GetHabbo().Username; uint roomID = room.RoomId; string roomName = room.Name; DateTime timeSpoken = DateTime.Now; ChatMessage chatMessage = new ChatMessage(userID, username, roomID, roomName, message, timeSpoken); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT into `chatlogs`(`user_id`, `room_id`, `hour`, `minute`, `full_date`, `timestamp`, `message`, `user_name`) VALUES(" + userID + ", " + roomID + ", " + timeSpoken.Hour + ", " + timeSpoken.Minute + ", '" + timeSpoken.ToString() + "', " + FirewindEnvironment.GetUnixTimestamp() + ", @msg, '" + user.GetHabbo().Username + "');"); dbClient.addParameter("msg", message); dbClient.runQuery(); } return(chatMessage); }
internal void ClearItems() { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("DELETE FROM items_users WHERE user_id = " + UserId); //Do join //dbClient.runFastQuery("DELETE FROM user_items_songs WHERE user_id = " + UserId); } mAddedItems.Clear(); mRemovedItems.Clear(); floorItems.Clear(); wallItems.Clear(); discs.Clear(); InventoryPets.Clear(); isUpdated = true; mClient.GetMessageHandler().GetResponse().Init(Outgoing.UpdateInventary); GetClient().GetMessageHandler().SendResponse(); }
internal void RemoveTask() { TimeSpan sinceLastTime = DateTime.Now - removeLastExecution; if (sinceLastTime.TotalMilliseconds >= 5000) { removeLastExecution = DateTime.Now; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { foreach (Room room in mToRemove) { Logging.WriteLine("[RoomMgr] Requesting unload of idle room - ID#: " + room.RoomId); room.GetRoomItemHandler().SaveFurniture(dbClient); UnloadRoom(room); } } mToRemove.Clear(); } }
internal static UInt32 GetTeleRoomId(UInt32 TeleId, Room pRoom) { if (pRoom.GetRoomItemHandler().GetItem(TeleId) != null) { return(pRoom.RoomId); } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT room_id FROM items_rooms WHERE item_id = " + TeleId); DataRow Row = dbClient.getRow(); if (Row == null) { return(0); } return(Convert.ToUInt32(Row[0])); } }
internal void RemoveFavorite() { Firewind.HabboHotel.Users.Habbo targetHabbo = Session.GetHabbo(); if (targetHabbo == null) { return; } uint Id = Request.ReadUInt32(); Session.GetHabbo().FavoriteRooms.Remove(Id); GetResponse().Init(Outgoing.FavsUpdateMessageComposer); GetResponse().AppendUInt(Id); GetResponse().AppendBoolean(false); SendResponse(); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("DELETE FROM user_favorites WHERE user_id = " + Session.GetHabbo().Id + " AND room_id = " + Id + ""); } }
internal void EnableEffect(int EffectId) { AvatarEffect Effect = GetEffect(EffectId, false); if (Effect == null || Effect.HasExpired || Effect.Activated) { return; } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE user_effects SET is_activated = '1', activated_stamp = " + FirewindEnvironment.GetUnixTimestamp() + " WHERE user_id = " + UserId + " AND effect_id = " + EffectId + ""); } Effect.Activate(); GetClient().GetMessageHandler().GetResponse().Init(Outgoing.EnableEffect); GetClient().GetMessageHandler().GetResponse().AppendInt32(Effect.EffectId); GetClient().GetMessageHandler().GetResponse().AppendInt32(Effect.TotalDuration); GetClient().GetMessageHandler().SendResponse(); }
internal void InitPets() { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id, user_id, room_id, name, type, race, color, expirience, energy, nutrition, respect, createstamp, x, y, z, have_saddle FROM user_pets WHERE room_id = " + RoomId); DataTable Data = dbClient.getTable(); if (Data == null) { return; } foreach (DataRow Row in Data.Rows) { Pet Pet = Catalog.GeneratePetFromRow(Row); List <RandomSpeech> RndSpeechList = new List <RandomSpeech>(); List <BotResponse> BotResponse = new List <RoomBots.BotResponse>(); roomUserManager.DeployBot(new RoomBot(Pet.PetId, RoomId, AIType.Pet, "freeroam", Pet.Name, "", Pet.Look, Pet.X, Pet.Y, (int)Pet.Z, 0, 0, 0, 0, 0, ref RndSpeechList, ref BotResponse), Pet); } } }
internal static UInt32 GetLinkedTele(UInt32 TeleId, Room pRoom) { //foreach (RoomItem Item in pRoom.FloorItems.Values) //{ // if (Item.Id == TeleId) // return Item.Id; //} using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT tele_two_id FROM items_tele_links WHERE tele_one_id = " + TeleId); DataRow Row = dbClient.getRow(); if (Row == null) { return(0); } return(Convert.ToUInt32(Row[0])); } }
internal void AddOrExtendSubscription(string SubscriptionId, int DurationSeconds) { SubscriptionId = SubscriptionId.ToLower(); if (Subscriptions.ContainsKey(SubscriptionId)) { Subscription Sub = Subscriptions[SubscriptionId]; if (Sub.IsValid()) { Sub.ExtendSubscription(DurationSeconds); } else { Sub.SetEndTime(((int)FirewindEnvironment.GetUnixTimestamp() + DurationSeconds)); } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("UPDATE user_subscriptions SET timestamp_expire = " + Sub.ExpireTime + " WHERE user_id = " + UserId + " AND subscription_id = 'habbo_vip'"); //dbClient.addParameter("subcrbr", SubscriptionId); dbClient.runQuery(); } return; } int TimeCreated = (int)FirewindEnvironment.GetUnixTimestamp(); int TimeExpire = ((int)FirewindEnvironment.GetUnixTimestamp() + DurationSeconds); Subscription NewSub = new Subscription(SubscriptionId, TimeExpire); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO user_subscriptions (user_id,subscription_id,timestamp_activated,timestamp_expire) VALUES (" + UserId + ",'habbo_vip'," + TimeCreated + "," + TimeExpire + ")"); //dbClient.addParameter("subcrbr", SubscriptionId); dbClient.runQuery(); } Subscriptions.Add(NewSub.SubscriptionId.ToLower(), NewSub); }
internal RoomData CreateRoom(GameClient Session, string Name, string Model) { Name = FirewindEnvironment.FilterInjectionChars(Name); if (!roomModels.ContainsKey(Model)) { Session.SendNotif(LanguageLocale.GetValue("room.modelmissing")); return(null); } if (((RoomModel)roomModels[Model]).ClubOnly && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip")) { Session.SendNotif(LanguageLocale.GetValue("room.missingclub")); return(null); } if (Name.Length < 3) { Session.SendNotif(LanguageLocale.GetValue("room.namelengthshort")); return(null); } UInt32 RoomId = 0; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO rooms (caption,owner,model_name) VALUES (@caption,@username,@model)"); dbClient.addParameter("caption", Name); dbClient.addParameter("model", Model); dbClient.addParameter("username", Session.GetHabbo().Username); RoomId = (UInt32)dbClient.insertQuery(); } RoomData newRoomData = GenerateRoomData(RoomId); Session.GetHabbo().UsersRooms.Add(newRoomData); return(newRoomData); }
internal void LoadRights() { this.UsersWithRights = new List <uint>(); DataTable Data = new DataTable(); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT room_rights.user_id FROM room_rights WHERE room_id = " + Id); Data = dbClient.getTable(); } if (Data == null) { return; } foreach (DataRow Row in Data.Rows) { this.UsersWithRights.Add(Convert.ToUInt32(Row["user_id"])); } }
internal static void SellItem(GameClient Session, uint ItemId, int SellingPrice) { UserItem Item = Session.GetHabbo().GetInventoryComponent().GetItem(ItemId); if (Item == null || SellingPrice > 10000 || !CanSellItem(Item)) { Session.GetMessageHandler().GetResponse().Init(610); Session.GetMessageHandler().GetResponse().AppendBoolean(false); Session.GetMessageHandler().GetResponse(); Session.GetMessageHandler().SendResponse(); return; } int Comission = CalculateComissionPrice(SellingPrice); int TotalPrice = SellingPrice + Comission; int ItemType = 1; if (Item.GetBaseItem().Type == 'i') { ItemType++; } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO catalog_marketplace_offers (item_id,user_id,asking_price,total_price,public_name,sprite_id,item_type,timestamp,extra_data) VALUES (" + Item.BaseItem + "," + Session.GetHabbo().Id + "," + SellingPrice + "," + TotalPrice + ",@public_name," + Item.GetBaseItem().SpriteId + "," + ItemType + "," + FirewindEnvironment.GetUnixTimestamp() + ",@extra_data)"); dbClient.addParameter("public_name", "NEEDS REPLACMENT HERE"); dbClient.addParameter("extra_data", Item.Data); dbClient.runQuery(); } Session.GetHabbo().GetInventoryComponent().RemoveItem(ItemId, false); Session.GetHabbo().GetInventoryComponent().RunDBUpdate(); Session.GetMessageHandler().GetResponse().Init(610); Session.GetMessageHandler().GetResponse().AppendBoolean(true); Session.GetMessageHandler().SendResponse(); }
internal bool LoadGroup(int id) { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT * FROM guild WHERE id = @id"); dbClient.addParameter("id", id); DataRow row = dbClient.getRow(); if (row == null || row.ItemArray.Length == 0) { return(false); } dbClient.setQuery("SELECT * FROM group_memberships WHERE id = @id"); dbClient.addParameter("id", id); Group group = new Group(row, dbClient.getTable()); Groups.Add(id, group); return(true); } }
internal void UpdatePreset(int Preset, string Color, int Intensity, bool BgOnly) { if (!IsValidColor(Color) || !IsValidIntensity(Intensity)) { return; } string Pr; switch (Preset) { case 3: Pr = "three"; break; case 2: Pr = "two"; break; case 1: default: Pr = "one"; break; } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("UPDATE items_moodlight SET preset_" + Pr + " = '@color," + Intensity + "," + FirewindEnvironment.BoolToEnum(BgOnly) + "' WHERE item_id = " + ItemId); dbClient.addParameter("color", Color); dbClient.runQuery(); } GetPreset(Preset).ColorCode = Color; GetPreset(Preset).ColorIntensity = Intensity; GetPreset(Preset).BackgroundOnly = BgOnly; }
internal void Disconnect() { if (GetHabbo() != null && GetHabbo().GetInventoryComponent() != null) { using (IQueryAdapter db = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { db.setQuery("UPDATE users SET online = '0' WHERE id = @id"); db.addParameter("id", this.GetHabbo().Id); db.runQuery(); } GetHabbo().GetInventoryComponent().RunDBUpdate(); } if (!Disconnected) { if (Connection != null) { Connection.Dispose(); } Disconnected = true; } }
internal static void PerformRoomAction(GameClient ModSession, uint RoomId, Boolean KickUsers, Boolean LockRoom, Boolean InappropriateRoom) { Room Room = FirewindEnvironment.GetGame().GetRoomManager().GetRoom(RoomId); if (Room == null) { return; } if (LockRoom) { Room.State = 1; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE rooms SET state = 'locked' WHERE id = " + Room.RoomId); } Room.Name = "Inappropriate to Hotel Management"; } if (InappropriateRoom) { Room.Name = LanguageLocale.GetValue("moderation.room.roomclosed"); Room.Description = LanguageLocale.GetValue("moderation.room.roomclosed"); Room.ClearTags(); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE rooms SET caption = 'Inappropriate to Hotel Management', description = 'Inappropriate to Hotel Management', tags = '' WHERE id = " + Room.RoomId + ""); } } if (KickUsers) { onCycleDoneDelegate kick = new onCycleDoneDelegate(Room.onRoomKick); Room.GetRoomUserManager().UserList.QueueDelegate(kick); } }
public Group CreateGroup(GameClient creator, string name, string description, int roomID, int color1, int color2, List <Tuple <int, int, int> > badgeData) { // We call this method after doing all checks. int groupID; string badgeCode = Group.GenerateBadgeImage(badgeData); string createTime = DateTime.Now.ToString("d-M-yyyy"); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { // Insert the group dbClient.setQuery("INSERT INTO guild(name,description,badge,users_id,rooms_id,color1,color2,date_created) VALUES(@name,@desc,@badge,@ownerid,@roomid,@color1,@color2,@date)"); dbClient.addParameter("name", name); dbClient.addParameter("desc", description); dbClient.addParameter("ownerid", creator.GetHabbo().Id); dbClient.addParameter("roomid", roomID); dbClient.addParameter("color1", color1); dbClient.addParameter("color2", color2); dbClient.addParameter("badge", badgeCode); dbClient.addParameter("date", createTime); groupID = (int)dbClient.insertQuery(); } Group group = new Group() { ID = groupID, Name = name, Description = description, RoomID = roomID, ColorID1 = color1, ColorID2 = color2, BadgeCode = badgeCode, DateCreated = createTime, }; return(group); }
internal void LoadMusic() { DataTable dTable; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT items_rooms_songs.songid,items.* FROM items_rooms_songs LEFT JOIN items ON items.item_id = items_rooms_songs.itemid WHERE items_rooms_songs.roomid = " + this.RoomId); dTable = dbClient.getTable(); } int songID; uint itemID; int baseID; foreach (DataRow dRow in dTable.Rows) { songID = (int)dRow[0]; itemID = Convert.ToUInt32(dRow[1]); baseID = Convert.ToInt32(dRow[2]); SongItem item = new SongItem(itemID, songID, baseID); GetRoomMusicController().AddDisk(item); } }
internal void LoadFurniture() { //this.Items.Clear(); this.mFloorItems.Clear(); this.mWallItems.Clear(); DataTable Data; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("CALL getroomitems(@roomid)"); dbClient.addParameter("roomid", room.RoomId); Data = dbClient.getTable(); uint itemID; decimal x; decimal y; sbyte n; uint baseID; int dataType; string extradata; WallCoordinate wallCoord; int extra; foreach (DataRow dRow in Data.Rows) { itemID = Convert.ToUInt32(dRow[0]); x = Convert.ToDecimal(dRow[1]); y = Convert.ToDecimal(dRow[2]); n = Convert.ToSByte(dRow[3]); baseID = Convert.ToUInt32(dRow[4]); IRoomItemData data; if (DBNull.Value.Equals(dRow[5])) { data = new StringData(""); extra = 0; } else { dataType = Convert.ToInt32(dRow[5]); extradata = (string)dRow[6]; extra = Convert.ToInt32(dRow[7]); switch (dataType) { case 0: data = new StringData(extradata); break; case 1: data = new MapStuffData(); break; case 2: data = new StringArrayStuffData(); break; case 3: data = new StringIntData(); break; default: data = new StringData(extradata); break; } try { data.Parse(extradata); } catch { Logging.LogException(string.Format("Error in furni data! Item ID: \"{0}\" and data: \"{1}\"", itemID, extradata.Replace(Convert.ToChar(1).ToString(), "[1]"))); dbClient.runFastQuery(string.Format("DELETE FROM items_extradata WHERE item_id = {0}", itemID)); } } if (FirewindEnvironment.GetGame().GetItemManager().GetItem(baseID).Type == 'i') // Is wallitem { wallCoord = new WallCoordinate((double)x, (double)y, n); RoomItem item = new RoomItem(itemID, room.RoomId, baseID, data, extra, wallCoord, room); if (!mWallItems.ContainsKey(itemID)) { mWallItems.Inner.Add(itemID, item); } } else //Is flooritem { int coordX, coordY; TextHandling.Split((double)x, out coordX, out coordY); RoomItem item = new RoomItem(itemID, room.RoomId, baseID, data, extra, coordX, coordY, (double)y, n, room); if (!mFloorItems.ContainsKey(itemID)) { mFloorItems.Inner.Add(itemID, item); } } } foreach (RoomItem Item in mFloorItems.Values) { if (Item.IsRoller) { mGotRollers = true; } else if (Item.GetBaseItem().InteractionType == Firewind.HabboHotel.Items.InteractionType.dimmer) { if (room.MoodlightData == null) { room.MoodlightData = new MoodlightData(Item.Id); } } else if (WiredUtillity.TypeIsWired(Item.GetBaseItem().InteractionType)) { WiredLoader.LoadWiredItem(Item, room, dbClient); room.GetWiredHandler().AddWire(Item, Item.Coordinate, Item.Rot, Item.GetBaseItem().InteractionType); } } } }
internal bool RequestBuddy(string UserQuery) { int userID; bool hasFQDisabled; GameClient client = FirewindEnvironment.GetGame().GetClientManager().GetClientByUsername(UserQuery); if (client == null) { DataRow Row = null; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id,block_newfriends FROM users WHERE username = @query"); dbClient.addParameter("query", UserQuery.ToLower()); Row = dbClient.getRow(); } if (Row == null) { return(false); } userID = Convert.ToInt32(Row["id"]); hasFQDisabled = FirewindEnvironment.EnumToBool(Row["block_newfriends"].ToString()); } else { userID = client.GetHabbo().Id; hasFQDisabled = client.GetHabbo().HasFriendRequestsDisabled; } if (hasFQDisabled) { GetClient().GetMessageHandler().GetResponse().Init(Outgoing.MessengerError); GetClient().GetMessageHandler().GetResponse().AppendInt32(0); // clientMessageId (not that important really) GetClient().GetMessageHandler().GetResponse().AppendInt32(3); // errorCode (1=limit reached,2=limit reached for other person,3=requests disabled,4=requestnotfound) GetClient().GetMessageHandler().SendResponse(); return(true); } int ToId = userID; if (RequestExists(ToId)) { return(true); } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("REPLACE INTO messenger_requests (sender,receiver) VALUES (" + this.UserId + "," + ToId + ")"); } GameClient ToUser = FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(ToId); if (ToUser == null || ToUser.GetHabbo() == null) { return(true); } MessengerRequest Request = new MessengerRequest(ToId, UserId, FirewindEnvironment.GetGame().GetClientManager().GetNameById(UserId)); ToUser.GetHabbo().GetMessenger().OnNewRequest(UserId); ServerMessage NewFriendNotif = new ServerMessage(Outgoing.SendFriendRequest); Request.Serialize(NewFriendNotif); ToUser.SendMessage(NewFriendNotif); requests.Add(ToId, Request); return(true); }
internal List <UserItem> DeliverItems(GameClient Session, Item Item, int Amount, String ExtraData, uint songID = 0) { List <UserItem> result = new List <UserItem>(); switch (Item.Type.ToString()) { case "i": case "s": for (int i = 0; i < Amount; i++) { //uint GeneratedId = GenerateItemId(); switch (Item.InteractionType) { case InteractionType.pet: int petType = int.Parse(Item.Name.Substring(Item.Name.IndexOf(' ') + 4)); string[] PetData = ExtraData.Split('\n'); Pet GeneratedPet = CreatePet(Session.GetHabbo().Id, PetData[0], petType, PetData[1], PetData[2]); Session.GetHabbo().GetInventoryComponent().AddPet(GeneratedPet); result.Add(Session.GetHabbo().GetInventoryComponent().AddNewItem(0, 320, new StringData("0"), 0, true, false, 0)); break; case InteractionType.teleport: UserItem one = Session.GetHabbo().GetInventoryComponent().AddNewItem(0, Item.ItemId, new StringData("0"), 0, true, false, 0); uint idOne = one.Id; UserItem two = Session.GetHabbo().GetInventoryComponent().AddNewItem(0, Item.ItemId, new StringData("0"), 0, true, false, 0); uint idTwo = two.Id; result.Add(one); result.Add(two); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("INSERT INTO items_tele_links (tele_one_id,tele_two_id) VALUES (" + idOne + "," + idTwo + ")"); dbClient.runFastQuery("INSERT INTO items_tele_links (tele_one_id,tele_two_id) VALUES (" + idTwo + "," + idOne + ")"); } break; case InteractionType.dimmer: UserItem it = Session.GetHabbo().GetInventoryComponent().AddNewItem(0, Item.ItemId, new StringData(ExtraData), 0, true, false, 0); uint id = it.Id; result.Add(it); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("INSERT INTO items_moodlight (item_id,enabled,current_preset,preset_one,preset_two,preset_three) VALUES (" + id + ",0,1,'#000000,255,0','#000000,255,0','#000000,255,0')"); } break; case InteractionType.musicdisc: { result.Add(Session.GetHabbo().GetInventoryComponent().AddNewItem(0, Item.ItemId, new StringData(songID.ToString()), 0, true, false, songID)); break; } case InteractionType.mannequin: MapStuffData data = new MapStuffData(); data.Data.Add("OUTFIT_NAME", ""); data.Data.Add("FIGURE", "hr-515-33.hd-600-1.ch-635-70.lg-716-66-62.sh-735-68"); data.Data.Add("GENDER", "M"); result.Add(Session.GetHabbo().GetInventoryComponent().AddNewItem(0, Item.ItemId, data, 0, true, false, songID)); break; case InteractionType.guildgeneric: case InteractionType.guilddoor: int groupID = int.Parse(ExtraData); Group group = FirewindEnvironment.GetGame().GetGroupManager().GetGroup(groupID); if (group == null || group.GetMemberType(Session.GetHabbo().Id) == 0) // check if member { break; } StringArrayStuffData stringData = new StringArrayStuffData(); stringData.Data.Add("0"); // furniture state stringData.Data.Add(groupID.ToString()); // guild id stringData.Data.Add(group.BadgeCode); // badge string stringData.Data.Add(group.Color1); // COLOR_1_STUFFDATA stringData.Data.Add(group.Color2); // COLOR_2_STUFFDATA result.Add(Session.GetHabbo().GetInventoryComponent().AddNewItem(0, Item.ItemId, stringData, 0, true, false, songID)); break; default: result.Add(Session.GetHabbo().GetInventoryComponent().AddNewItem(0, Item.ItemId, new StringData(ExtraData), 0, true, false, songID)); break; } } return(result); case "e": for (int i = 0; i < Amount; i++) { Session.GetHabbo().GetAvatarEffectsInventoryComponent().AddEffect(Item.SpriteId, 3600); } return(result); case "r": // Rentable bot return(result); default: Session.SendNotif(LanguageLocale.GetValue("catalog.buyerror")); return(result); } }
internal void HandlePurchase(GameClient Session, int PageId, uint ItemId, string extraParameter, int buyAmount, Boolean IsGift, string GiftUser, string GiftMessage, int GiftSpriteId, int GiftLazo, int GiftColor, bool giftShowIdentity) { int finalAmount = buyAmount; if (buyAmount > 5) // Possible discount! { // Nearest number that increases the amount of free items int nearestDiscount = ((int)Math.Floor(buyAmount / 6.0) * 6); // How many free ones we get int freeItemsCount = (nearestDiscount - 3) / 3; // Add 1 free if more than 42 if (buyAmount >= 42) { freeItemsCount++; } // Doesn't follow rules as it isn't dividable by 6, but still increases free items if (buyAmount >= 99) { freeItemsCount = 33; } // This is how many we pay for in the end finalAmount = buyAmount - freeItemsCount; } //Logging.WriteLine("Amount: " + priceAmount + "; withOffer= " + finalAmount); CatalogPage Page; if (!Pages.TryGetValue(PageId, out Page)) { return; } if (Page == null || !Page.Enabled || !Page.Visible || Session == null || Session.GetHabbo() == null) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (Page.ClubOnly && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_club") && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip")) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (Page.MinRank > Session.GetHabbo().Rank) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } CatalogItem Item = Page.GetItem(ItemId); if (Item == null) // TODO: Check item minimum club rank { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (!Item.HaveOffer && buyAmount > 1) // Check if somebody is bulk-buying when not allowed { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (Item.IsLimited && Item.LimitedStack <= Item.LimitedSelled) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } int GiftUserId = 0; //int giftWrappingCost = 0; if (IsGift) { if (!Item.AllowGift) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (Item.Items.Count > 1 || Item.Amount > 1) // Gifts can only have 1 item? { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } DataRow dRow; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE username = @gift_user"); dbClient.addParameter("gift_user", GiftUser); dRow = dbClient.getRow(); } if (dRow == null) { Session.GetMessageHandler().GetResponse().Init(Outgoing.GiftError); Session.GetMessageHandler().GetResponse().AppendString(GiftUser); Session.GetMessageHandler().SendResponse(); return; } GiftUserId = Convert.ToInt32(dRow[0]); if (GiftUserId == 0) { Session.GetMessageHandler().GetResponse().Init(Outgoing.GiftError); Session.GetMessageHandler().GetResponse().AppendString(GiftUser); Session.GetMessageHandler().SendResponse(); return; } } Boolean CreditsError = false; Boolean PixelError = false; Boolean CrystalError = false; if (Session.GetHabbo().Credits < (Item.CreditsCost * finalAmount)) { CreditsError = true; } if (Session.GetHabbo().VipPoints < (Item.CrystalCost * finalAmount)) { CrystalError = true; } if (Session.GetHabbo().ActivityPoints < (Item.PixelsCost * finalAmount)) { PixelError = true; } if (CreditsError || PixelError) { ServerMessage message = new ServerMessage(Outgoing.NotEnoughBalance); message.AppendBoolean(CreditsError); message.AppendBoolean(PixelError); Session.SendMessage(message); return; } if (Item.CrystalCost > 0) { int cost = Item.CrystalCost * finalAmount; if (Session.GetHabbo().VipPoints < cost) { Session.SendNotif("You can't afford that item!"); Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } Session.GetHabbo().VipPoints -= cost; Session.GetHabbo().UpdateActivityPointsBalance(true); using (IQueryAdapter adapter = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { adapter.runFastQuery("UPDATE users SET vip_points = " + Session.GetHabbo().VipPoints + " WHERE id = " + Session.GetHabbo().Id); } } if (Item.CreditsCost > 0 && !IsGift) { Session.GetHabbo().Credits -= (Item.CreditsCost * finalAmount); Session.GetHabbo().UpdateCreditsBalance(); } if (Item.PixelsCost > 0 && !IsGift) { Session.GetHabbo().ActivityPoints -= (Item.PixelsCost * finalAmount); Session.GetHabbo().UpdateActivityPointsBalance(true); } // Item is purchased, now do post-proccessing if (Item.IsLimited) { Item.LimitedSelled++; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE catalog_items SET limited_sells = " + Item.LimitedSelled + " WHERE id = " + Item.Id); } Page.InitMsg(); // update page! // send update Session.SendMessage(Page.GetMessage); } foreach (uint i in Item.Items) { //Logging.WriteLine(Item.GetBaseItem().ItemId); //Logging.WriteLine(Item.GetBaseItem().InteractionType.ToLower()); // Extra Data is _NOT_ filtered at this point and MUST BE VERIFIED BELOW: if (Item.GetBaseItem(i).Type == 'h') // Subscription { int Months = 0; int Days = 0; if (Item.Name.Contains("HABBO_CLUB_VIP_")) { if (Item.Name.Contains("_DAY")) { Days = int.Parse(Item.Name.Split('_')[3]); } else if (Item.Name.Contains("_MONTH")) { Months = int.Parse(Item.Name.Split('_')[3]); Days = 31 * Months; } } else if (Item.Name.Equals("deal_vip_1_year_and_badge")) { Months = 12; Days = 31 * Months; } else if (Item.Name.Equals("HABBO_CLUB_VIP_5_YEAR")) { Months = 5 * 12; Days = 31 * Months; } else if (Item.Name.StartsWith("DEAL_HC_")) { Months = int.Parse(Item.Name.Split('_')[2]); Days = 31 * Months; Session.GetHabbo().GetSubscriptionManager().AddOrExtendSubscription("habbo_club", Days * 24 * 3600); Session.GetHabbo().SerializeClub(); return; } Session.GetHabbo().GetSubscriptionManager().AddOrExtendSubscription("habbo_vip", Days * 24 * 3600); Session.GetHabbo().SerializeClub(); return; } if (IsGift && Item.GetBaseItem(i).Type == 'e') { Session.SendNotif(LanguageLocale.GetValue("catalog.gift.send.error")); return; } IRoomItemData itemData = new StringData(extraParameter); switch (Item.GetBaseItem(i).InteractionType) { case InteractionType.none: //itemData = new StringData(extraParameter); break; case InteractionType.musicdisc: itemData = new StringData(Item.songID.ToString()); break; #region Pet handling case InteractionType.pet: try { string[] Bits = extraParameter.Split('\n'); string PetName = Bits[0]; string Race = Bits[1]; string Color = Bits[2]; int.Parse(Race); // to trigger any possible errors if (!CheckPetName(PetName)) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } //if (Race.Length != 1) // return; if (Color.Length != 6) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } } catch (Exception e) { Logging.WriteLine(e.ToString()); Logging.HandleException(e, "Catalog.HandlePurchase"); Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } break; #endregion case InteractionType.roomeffect: Double Number = 0; try { if (string.IsNullOrEmpty(extraParameter)) { Number = 0; } else { Number = Double.Parse(extraParameter, FirewindEnvironment.cultureInfo); } } catch (Exception e) { Logging.HandleException(e, "Catalog.HandlePurchase: " + extraParameter); } itemData = new StringData(Number.ToString().Replace(',', '.')); break; // maintain extra data // todo: validate case InteractionType.postit: itemData = new StringData("FFFF33"); break; case InteractionType.dimmer: itemData = new StringData("1,1,1,#000000,255"); break; case InteractionType.trophy: itemData = new StringData(String.Format("{0}\t{1}\t{2}", Session.GetHabbo().Username, DateTime.Now.ToString("d-M-yyy"), extraParameter)); break; //case InteractionType.mannequin: // MapStuffData data = new MapStuffData(); // data.Data.Add("OUTFIT_NAME", ""); // data.Data.Add("FIGURE", ""); // data.Data.Add("GENDER", ""); // itemData = data; // break; default: //itemData = new StringData(extraParameter); break; } //Session.GetMessageHandler().GetResponse().Init(Outgoing.UpdateInventory); //Session.GetMessageHandler().SendResponse(); Session.GetMessageHandler().GetResponse().Init(Outgoing.PurchaseOK); // PurchaseOKMessageEvent Item.Serialize(Session.GetMessageHandler().GetResponse()); Session.GetMessageHandler().SendResponse(); if (IsGift) { uint itemID; //uint GenId = GenerateItemId(); Item Present = FirewindEnvironment.GetGame().GetItemManager().GetItemBySpriteID(GiftSpriteId); if (Present == null) { Logging.LogDebug(string.Format("Somebody tried to purchase a present with invalid sprite ID: {0}", GiftSpriteId)); Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } MapStuffData giftData = new MapStuffData(); if (giftShowIdentity) { giftData.Data.Add("PURCHASER_NAME", Session.GetHabbo().Username); giftData.Data.Add("PURCHASER_FIGURE", Session.GetHabbo().Look); } giftData.Data.Add("MESSAGE", GiftMessage); giftData.Data.Add("PRODUCT_CODE", "10"); giftData.Data.Add("EXTRA_PARAM", "test"); giftData.Data.Add("state", "1"); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + Present.ItemId + ")"); itemID = (uint)dbClient.insertQuery(); dbClient.runFastQuery("INSERT INTO items_users VALUES (" + itemID + "," + GiftUserId + ")"); if (!string.IsNullOrEmpty(GiftMessage)) { dbClient.setQuery("INSERT INTO items_extradata VALUES (" + itemID + ",@datatype,@data,@extra)"); dbClient.addParameter("datatype", giftData.GetTypeID()); dbClient.addParameter("data", giftData.ToString()); dbClient.addParameter("extra", GiftColor * 1000 + GiftLazo); dbClient.runQuery(); } dbClient.setQuery("INSERT INTO user_presents (item_id,base_id,amount,extra_data) VALUES (" + itemID + "," + Item.GetBaseItem(i).ItemId + "," + Item.Amount + ",@extra_data)"); dbClient.addParameter("extra_data", itemData.ToString()); dbClient.runQuery(); } GameClient Receiver = FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(GiftUserId); if (Receiver != null) { Receiver.SendNotif(LanguageLocale.GetValue("catalog.gift.received") + Session.GetHabbo().Username); UserItem u = Receiver.GetHabbo().GetInventoryComponent().AddNewItem(itemID, Present.ItemId, giftData, GiftColor * 1000 + GiftLazo, false, false, 0); Receiver.GetHabbo().GetInventoryComponent().SendFloorInventoryUpdate(); Receiver.GetMessageHandler().GetResponse().Init(Outgoing.UnseenItems); Receiver.GetMessageHandler().GetResponse().AppendInt32(1); // items Receiver.GetMessageHandler().GetResponse().AppendInt32(1); // type (gift) == s Receiver.GetMessageHandler().GetResponse().AppendInt32(1); Receiver.GetMessageHandler().GetResponse().AppendUInt(u.Id); Receiver.GetMessageHandler().SendResponse(); InventoryComponent targetInventory = Receiver.GetHabbo().GetInventoryComponent(); if (targetInventory != null) { targetInventory.RunDBUpdate(); } } Session.SendNotif(LanguageLocale.GetValue("catalog.gift.sent")); } else { List <UserItem> items = DeliverItems(Session, Item.GetBaseItem(i), (buyAmount * Item.Amount), itemData.ToString(), Item.songID); int Type = 2; if (Item.GetBaseItem(i).Type.ToString().ToLower().Equals("s")) { if (Item.GetBaseItem(i).InteractionType == InteractionType.pet) { Type = 3; } else { Type = 1; } } Session.GetMessageHandler().GetResponse().Init(Outgoing.UnseenItems); Session.GetMessageHandler().GetResponse().AppendInt32(1); // items Session.GetMessageHandler().GetResponse().AppendInt32(Type); Session.GetMessageHandler().GetResponse().AppendInt32(items.Count); foreach (UserItem u in items) { Session.GetMessageHandler().GetResponse().AppendUInt(u.Id); } Session.GetMessageHandler().SendResponse(); //Logging.WriteLine("Purchased " + items.Count); Session.GetHabbo().GetInventoryComponent().UpdateItems(false); if (Item.GetBaseItem(i).InteractionType == InteractionType.pet) { Session.SendMessage(Session.GetHabbo().GetInventoryComponent().SerializePetInventory()); } } } }
internal void ProgressUserQuest(GameClient Session, QuestType QuestType, uint EventData = 0) { if (Session == null || Session.GetHabbo() == null || Session.GetHabbo().CurrentQuestId <= 0) { return; } Quest UserQuest = GetQuest(Session.GetHabbo().CurrentQuestId); if (UserQuest == null || UserQuest.GoalType != QuestType) { return; } int CurrentProgress = Session.GetHabbo().GetQuestProgress(UserQuest.Id); int NewProgress = CurrentProgress; bool PassQuest = false; switch (QuestType) { default: NewProgress++; if (NewProgress >= UserQuest.GoalData) { PassQuest = true; } break; case QuestType.EXPLORE_FIND_ITEM: if (EventData != UserQuest.GoalData) { return; } NewProgress = (int)UserQuest.GoalData; PassQuest = true; break; } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE user_quests SET progress = " + NewProgress + " WHERE user_id = " + Session.GetHabbo().Id + " AND quest_id = " + UserQuest.Id); if (PassQuest) { dbClient.runFastQuery("UPDATE users SET currentquestid = 0 WHERE id = " + Session.GetHabbo().Id); //Quest NextQuest = GetNextQuestInSeries(UserQuest.Category, UserQuest.Number + 1); //if (NextQuest != null) // dbClient.runFastQuery("INSERT INTO user_quests (user_id, quest_id, progress) VALUES (" + Session.GetHabbo().Id + ", " + NextQuest.Id + ", 0)"); } } Session.GetHabbo().quests[Session.GetHabbo().CurrentQuestId] = NewProgress; Session.SendMessage(QuestStartedComposer.Compose(Session, UserQuest)); if (PassQuest) { Session.GetHabbo().CurrentQuestId = 0; Session.GetHabbo().LastCompleted = UserQuest.Id; Session.SendMessage(QuestCompletedComposer.Compose(Session, UserQuest)); Session.GetHabbo().ActivityPoints += UserQuest.Reward; Session.GetHabbo().UpdateActivityPointsBalance(false); GetList(Session, null); } }
internal void ChangeLook() { if (Session.GetHabbo().MutantPenalty) { Session.SendNotif("Because of a penalty or restriction on your account, you are not allowed to change your look."); return; } string Gender = Request.ReadString().ToUpper(); string Look = FirewindEnvironment.FilterInjectionChars(Request.ReadString()); //if (!AntiMutant.ValidateLook(Look, Gender)) //{ // return; //} FirewindEnvironment.GetGame().GetQuestManager().ProgressUserQuest(Session, HabboHotel.Quests.QuestType.PROFILE_CHANGE_LOOK); Session.GetHabbo().Look = FirewindEnvironment.FilterFigure(Look); Session.GetHabbo().Gender = Gender.ToLower(); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("UPDATE users SET look = @look, gender = @gender WHERE id = " + Session.GetHabbo().Id); dbClient.addParameter("look", Look); dbClient.addParameter("gender", Gender); dbClient.runQuery(); } FirewindEnvironment.GetGame().GetAchievementManager().ProgressUserAchievement(Session, "ACH_AvatarLooks", 1); Session.GetMessageHandler().GetResponse().Init(Outgoing.UpdateUserInformation); Session.GetMessageHandler().GetResponse().AppendInt32(-1); Session.GetMessageHandler().GetResponse().AppendString(Session.GetHabbo().Look); Session.GetMessageHandler().GetResponse().AppendString(Session.GetHabbo().Gender.ToLower()); Session.GetMessageHandler().GetResponse().AppendString(Session.GetHabbo().Motto); Session.GetMessageHandler().GetResponse().AppendInt32(Session.GetHabbo().AchievementPoints); Session.GetMessageHandler().SendResponse(); if (Session.GetHabbo().InRoom) { Room Room = Session.GetHabbo().CurrentRoom; if (Room == null) { return; } RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id); if (User == null) { return; } ServerMessage RoomUpdate = new ServerMessage(Outgoing.UpdateUserInformation); RoomUpdate.AppendInt32(User.VirtualId); RoomUpdate.AppendString(Session.GetHabbo().Look); RoomUpdate.AppendString(Session.GetHabbo().Gender.ToLower()); RoomUpdate.AppendString(Session.GetHabbo().Motto); RoomUpdate.AppendInt32(Session.GetHabbo().AchievementPoints); Room.SendMessage(RoomUpdate); } }
internal void UpdateBadges() { Session.GetHabbo().GetBadgeComponent().ResetSlots(); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE user_badges SET badge_slot = 0 WHERE user_id = " + Session.GetHabbo().Id); } for (int i = 0; i < 5; i++) { int Slot = Request.ReadInt32(); string Badge = Request.ReadString(); if (Badge.Length == 0) { continue; } if (!Session.GetHabbo().GetBadgeComponent().HasBadge(Badge) || Slot < 1 || Slot > 5) { return; } Session.GetHabbo().GetBadgeComponent().GetBadge(Badge).Slot = Slot; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("UPDATE user_badges SET badge_slot = " + Slot + " WHERE badge_id = @badge AND user_id = " + Session.GetHabbo().Id + ""); dbClient.addParameter("badge", Badge); dbClient.runQuery(); } } FirewindEnvironment.GetGame().GetQuestManager().ProgressUserQuest(Session, HabboHotel.Quests.QuestType.PROFILE_BADGE); ServerMessage Message = new ServerMessage(Outgoing.UpdateBadges); Message.AppendUInt(Session.GetHabbo().Id); Message.AppendInt32(Session.GetHabbo().GetBadgeComponent().EquippedCount); foreach (Badge Badge in Session.GetHabbo().GetBadgeComponent().BadgeList.Values) { if (Badge.Slot <= 0) { continue; } Message.AppendInt32(Badge.Slot); Message.AppendString(Badge.Code); } if (Session.GetHabbo().InRoom&& FirewindEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId) != null) { FirewindEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId).SendMessage(Message); } else { Session.SendMessage(Message); } }
internal bool tryLogin(string AuthTicket) { int loginProgress = 0; try { string ip = GetConnection().getIp(); byte errorCode = 0; UserData userData = UserDataFactory.GetUserData(AuthTicket, ip, out errorCode); if (errorCode == 1) { SendNotifWithScroll(LanguageLocale.GetValue("login.invalidsso")); return(false); } else if (errorCode == 2) { SendNotifWithScroll(LanguageLocale.GetValue("login.loggedin")); return(false); } loginProgress++; FirewindEnvironment.GetGame().GetClientManager().RegisterClient(this, userData.userID, userData.user.Username); this.Habbo = userData.user; userData.user.LoadData(userData); loginProgress++; if (userData.user.Username == null) { SendBanMessage("You have no username."); return(false); } string banReason = FirewindEnvironment.GetGame().GetBanManager().GetBanReason(userData.user.Username, ip); loginProgress++; if (!string.IsNullOrEmpty(banReason)) { SendBanMessage(banReason); return(false); } userData.user.Init(this, userData); QueuedServerMessage response = new QueuedServerMessage(Connection); ServerMessage UniqueId = new ServerMessage(Outgoing.UniqueID); UniqueId.AppendString(this.MachineId); response.appendResponse(UniqueId); ServerMessage authok = new ServerMessage(Outgoing.AuthenticationOK); response.appendResponse(authok); ServerMessage HomeRoom = new ServerMessage(Outgoing.HomeRoom); HomeRoom.AppendUInt(this.GetHabbo().HomeRoom); // first home HomeRoom.AppendUInt(this.GetHabbo().HomeRoom); // first home SendMessage(HomeRoom); loginProgress++; ServerMessage FavouriteRooms = new ServerMessage(Outgoing.FavouriteRooms); FavouriteRooms.AppendInt32(30); // max rooms FavouriteRooms.AppendInt32(userData.user.FavoriteRooms.Count); foreach (uint Id in userData.user.FavoriteRooms.ToArray()) { FavouriteRooms.AppendUInt(Id); } response.appendResponse(FavouriteRooms); loginProgress++; ServerMessage fuserights = new ServerMessage(Outgoing.Fuserights); if (GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip")) // VIP { fuserights.AppendInt32(2); } else if (GetHabbo().GetSubscriptionManager().HasSubscription("habbo_club")) // HC { fuserights.AppendInt32(1); } else { fuserights.AppendInt32(0); } fuserights.AppendUInt(this.GetHabbo().Rank); response.appendResponse(fuserights); loginProgress++; ServerMessage bools1 = new ServerMessage(Outgoing.AvailabilityStatus); bools1.AppendBoolean(true); bools1.AppendBoolean(false); response.appendResponse(bools1); ServerMessage bools2 = new ServerMessage(Outgoing.InfoFeedEnable); bools2.AppendBoolean(false); response.appendResponse(bools2); loginProgress++; ServerMessage setRanking = new ServerMessage(Outgoing.SerializeCompetitionWinners); setRanking.AppendString("hlatCompetitions"); // competition type setRanking.AppendInt32(Ranking.getCompetitionForInfo("hlatCompetitions").Count); loginProgress++; int i = 0; foreach (Ranking r in Ranking.getCompetitionForInfo("hlatCompetitions")) { i++; setRanking.AppendUInt(r.UserId); Habbo data = FirewindEnvironment.getHabboForId(r.UserId); setRanking.AppendString((data != null) ? data.Username : "******"); setRanking.AppendString((data != null) ? data.Look : "sh-907-96.hd-3096-3.he-3082-91.lg-3018-81.ch-660-95.hr-9534-34"); setRanking.AppendInt32(i); // position setRanking.AppendInt32(r.Score); } response.appendResponse(setRanking); loginProgress++; if (userData.user.HasFuse("fuse_mod")) { this.SendMessage(FirewindEnvironment.GetGame().GetModerationTool().SerializeTool()); FirewindEnvironment.GetGame().GetModerationTool().SerializeOpenTickets(ref response, userData.userID); } if (LanguageLocale.welcomeAlertEnabled) { this.SendMOTD(LanguageLocale.welcomeAlert); } loginProgress++; using (IQueryAdapter db = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { db.setQuery("UPDATE users SET online = '1' WHERE id = @id"); db.addParameter("id", this.GetHabbo().Id); db.runQuery(); } loginProgress++; // Send the big chunk response.sendResponse(); // fire the event! FirewindEnvironment.GetGame().GetClientManager().ClientLoggedIn(this); return(true); } catch (UserDataNotFoundException e) { SendNotifWithScroll(LanguageLocale.GetValue("login.invalidsso") + "extra data: " + e.ToString()); } catch (Exception e) { Logging.LogCriticalException(String.Format("Invalid Dario bug duing user login (progress = {0}): ", loginProgress) + e.ToString()); SendNotifWithScroll("Login error: " + e.ToString()); } return(false); }
// PENDING REWRITE internal void BanUser(GameClient Client, string Moderator, Double LengthSeconds, string Reason, Boolean IpBan) { ModerationBanType Type = ModerationBanType.USERNAME; string Var = Client.GetHabbo().Username; string RawVar = "user"; Double Expire = FirewindEnvironment.GetUnixTimestamp() + LengthSeconds; if (IpBan) { Type = ModerationBanType.IP; Var = Client.GetConnection().getIp(); RawVar = "ip"; } ModerationBan ban = new ModerationBan(Type, Var, Reason, Expire); if (ban.Type == ModerationBanType.IP) { if (bannedIPs.ContainsKey(Var)) { bannedIPs[Var] = ban; } else { bannedIPs.Add(Var, ban); } } else { if (bannedUsernames.ContainsKey(Var)) { bannedUsernames[Var] = ban; } else { bannedUsernames.Add(Var, ban); } } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO bans (bantype,value,reason,expire,added_by,added_date) VALUES (@rawvar,@var,@reason,'" + Expire + "',@mod,'" + DateTime.Now.ToLongDateString() + "')"); dbClient.addParameter("rawvar", RawVar); dbClient.addParameter("var", Var); dbClient.addParameter("reason", Reason); dbClient.addParameter("mod", Moderator); dbClient.runQuery(); } if (IpBan) { DataTable UsersAffected = null; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE ip_last = @var"); dbClient.addParameter("var", Var); UsersAffected = dbClient.getTable(); } if (UsersAffected != null) { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { foreach (DataRow Row in UsersAffected.Rows) { dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Convert.ToUInt32(Row["id"])); } } } BanUser(Client, Moderator, LengthSeconds, Reason, false); } else { using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE user_info SET bans = bans + 1 WHERE user_id = " + Client.GetHabbo().Id); } Client.SendBanMessage(LanguageLocale.GetValue("moderation.banned") + " " + Reason); Client.Disconnect(); } }
internal void Serialize(ServerMessage Message, int UserId) { // int // int // int // int // int // string // int (extra) // int data type (0,1,2,3,4) ( // 0 = (StringData?) - string // 1 = (MapStuffData) - int i, foreach i { string, string } // 2 = (StringArrayStuffData) - int i, foreach i { string } // 3 = (?) - string, int // 4 = not implemented? // ---data // int // int // int // int // if type < 0, string if (IsFloorItem) { Message.AppendUInt(Id); Message.AppendInt32(GetBaseItem().SpriteId); // type Message.AppendInt32(mX); // x Message.AppendInt32(mY); // y Message.AppendInt32(Rot); // dir Message.AppendString(String.Format("{0:0.00}", TextHandling.GetString(mZ))); // z Message.AppendInt32(Extra); // extra Message.AppendInt32(data.GetTypeID()); // data type data.AppendToMessage(Message); //if (this.GetBaseItem().InteractionType == InteractionType.gift) //{ // int result = 0; // if (ExtraData.Contains(Convert.ToChar(5).ToString())) // { // int color = int.Parse(ExtraData.Split((char)5)[1]); // int lazo = int.Parse(ExtraData.Split((char)5)[2]); // result = color * 1000 + lazo; // } // Message.AppendInt32(result); // if (this.ExtraData.Contains(Convert.ToChar(5).ToString())) // { // uint PurchaserId = (uint)int.Parse(ExtraData.Split(';')[0]); // Habbo Purchaser = FirewindEnvironment.getHabboForId(PurchaserId); // if (Purchaser != null) // { // // "MESSAGE", "PRODUCT_CODE", "EXTRA_PARAM", "PURCHASER_NAME", "PURCHASER_FIGURE"; // Message.AppendInt32(1); // Message.AppendInt32(6); // Message.AppendString("EXTRA_PARAM"); // Message.AppendString(""); // Message.AppendString("MESSAGE"); // Message.AppendString(ExtraData.Split(';')[1].Split((char)5)[0]); // Message.AppendString("PURCHASER_NAME"); // Message.AppendString(Purchaser.Username); // Message.AppendString("PURCHASER_FIGURE"); // Message.AppendString(Purchaser.Look); // Message.AppendString("PRODUCT_CODE"); // Message.AppendString(""); // Message.AppendString("state"); // Message.AppendString(MagicRemove ? "1" : "0"); // } // else // { // Message.AppendInt32(0); // } // } // // this.ExtraData.Contains(Convert.ToChar(5).ToString()) ? ExtraData.Split((char)5)[1] : "0" // else // Message.AppendInt32(0); //} //else //{ // Message.AppendInt32(0); // Message.AppendInt32(0); // if (GetBaseItem().InteractionType != InteractionType.fbgate) // Message.AppendString(ExtraData); // else // Message.AppendString(string.Empty); //} Message.AppendInt32(-1); Message.AppendInt32(1); // Type New R63 ('use bottom') Message.AppendInt32(UserId); } else if (IsWallItem) { Message.AppendString(Id + String.Empty); Message.AppendInt32(GetBaseItem().SpriteId); Message.AppendString(wallCoord.ToString()); switch (GetBaseItem().InteractionType) { case InteractionType.postit: Message.AppendString(data.GetData().ToString().Split(' ')[0]); break; default: Message.AppendString(data.ToString()); break; } Message.AppendInt32(1); // Type New R63 ('use bottom') Message.AppendInt32(UserId); if (data.GetType() != typeof(StringData)) { Logging.LogException(string.Format("Strange wallitem, {2}, {3}, {0}, \"{1}\"", Id, data.ToString(), GetBaseItem().Name, GetBaseItem().Type)); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) dbClient.runFastQuery(string.Format("DELETE FROM items_extradata WHERE item_id = {0}", Id)); } } }
internal ServerMessage SerializePopularRoomTags() { Dictionary <string, int> Tags = new Dictionary <string, int>(); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT rooms.tags, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE active_users > 0 ORDER BY active_users DESC LIMIT 50"); DataTable Data = dbClient.getTable(); if (Data != null) { int activeUsers; foreach (DataRow Row in Data.Rows) { if (!string.IsNullOrEmpty(Row["active_users"].ToString())) { activeUsers = (int)Row["active_users"]; } else { activeUsers = 0; } List <string> RoomTags = new List <string>(); foreach (string Tag in Row["tags"].ToString().Split(',')) { RoomTags.Add(Tag); } foreach (string Tag in RoomTags) { if (Tags.ContainsKey(Tag)) { Tags[Tag] += activeUsers; } else { Tags.Add(Tag, activeUsers); } } } } List <KeyValuePair <string, int> > SortedTags = new List <KeyValuePair <string, int> >(Tags); SortedTags.Sort( delegate(KeyValuePair <string, int> firstPair, KeyValuePair <string, int> nextPair) { return(firstPair.Value.CompareTo(nextPair.Value)); } ); ServerMessage Message = new ServerMessage(Outgoing.PopularTags); Message.AppendInt32(SortedTags.Count); foreach (KeyValuePair <string, int> TagData in SortedTags) { Message.AppendString(TagData.Key); Message.AppendInt32(TagData.Value); } return(Message); } }