From 5b869f35b43d21815b8b4ffb20f23b42b93666a4 Mon Sep 17 00:00:00 2001 From: brenoepic <59066707+brenoepics@users.noreply.github.com> Date: Fri, 15 Apr 2022 18:59:06 -0300 Subject: [PATCH] Fix flagme --- .../incoming/handshake/SecureLoginEvent.java | 111 ++++++++++++++++-- 1 file changed, 104 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index 2a47300f..fcee1568 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -1,6 +1,9 @@ package com.eu.habbo.messages.incoming.handshake; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.achievements.AchievementManager; +import com.eu.habbo.habbohotel.campaign.calendar.CalendarCampaign; +import com.eu.habbo.habbohotel.catalog.TargetOffer; import com.eu.habbo.habbohotel.messenger.Messenger; import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; import com.eu.habbo.habbohotel.modtool.ModToolSanctions; @@ -14,16 +17,19 @@ import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionHabboClub; import com.eu.habbo.messages.NoAuthMessage; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.catalog.TargetedOfferComposer; +import com.eu.habbo.messages.outgoing.events.calendar.AdventCalendarDataComposer; import com.eu.habbo.messages.outgoing.gamecenter.GameCenterAccountInfoComposer; import com.eu.habbo.messages.outgoing.gamecenter.GameCenterGameListComposer; import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer; import com.eu.habbo.messages.outgoing.generic.alerts.MessagesForYouComposer; import com.eu.habbo.messages.outgoing.habboway.nux.NewUserIdentityComposer; +import com.eu.habbo.messages.outgoing.habboway.nux.NuxAlertComposer; import com.eu.habbo.messages.outgoing.handshake.EnableNotificationsComposer; import com.eu.habbo.messages.outgoing.handshake.SecureLoginOKComposer; import com.eu.habbo.messages.outgoing.handshake.AvailabilityStatusMessageComposer; import com.eu.habbo.messages.outgoing.handshake.PingComposer; -import com.eu.habbo.messages.outgoing.inventory.InventoryAchievementsComposer; +import com.eu.habbo.messages.outgoing.inventory.BadgePointLimitsComposer; import com.eu.habbo.messages.outgoing.inventory.UserEffectsListComposer; import com.eu.habbo.messages.outgoing.modtool.CfhTopicsMessageComposer; import com.eu.habbo.messages.outgoing.modtool.ModToolComposer; @@ -38,15 +44,22 @@ import gnu.trove.map.hash.THashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Timestamp; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; +import static java.time.temporal.ChronoUnit.DAYS; + @NoAuthMessage public class SecureLoginEvent extends MessageHandler { private static final Logger LOGGER = LoggerFactory.getLogger(SecureLoginEvent.class); - @Override public void handle() throws Exception { if (!this.client.getChannel().isOpen()) { @@ -83,7 +96,7 @@ public class SecureLoginEvent extends MessageHandler { try { habbo.setClient(this.client); this.client.setHabbo(habbo); - if(!this.client.getHabbo().connect()) { + if (!this.client.getHabbo().connect()) { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); return; } @@ -105,9 +118,9 @@ public class SecureLoginEvent extends MessageHandler { return; } - if(ClothingValidationManager.VALIDATE_ON_LOGIN) { + if (ClothingValidationManager.VALIDATE_ON_LOGIN) { String validated = ClothingValidationManager.validateLook(this.client.getHabbo()); - if(!validated.equals(this.client.getHabbo().getHabboInfo().getLook())) { + if (!validated.equals(this.client.getHabbo().getHabboInfo().getLook())) { this.client.getHabbo().getHabboInfo().setLook(validated); } } @@ -123,6 +136,70 @@ public class SecureLoginEvent extends MessageHandler { else if (!this.client.getHabbo().getHabboStats().nux || Emulator.getConfig().getBoolean("retro.style.homeroom") && RoomManager.HOME_ROOM_ID > 0) roomIdToEnter = RoomManager.HOME_ROOM_ID; + boolean calendar = false; + if (!this.client.getHabbo().getHabboStats().getAchievementProgress().containsKey(Emulator.getGameEnvironment().getAchievementManager().getAchievement("Login"))) { + AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("Login")); + calendar = true; + } else { + int previousOnline = (int)this.client.getHabbo().getHabboStats().cache.get("previousOnline"); + long daysBetween = ChronoUnit.DAYS.between(new Date((long) previousOnline * 1000L).toInstant(), new Date().toInstant()); + + Date lastLogin = new Date(previousOnline); + Calendar c1 = Calendar.getInstance(); + c1.add(Calendar.DAY_OF_YEAR, -1); + + Calendar c2 = Calendar.getInstance(); + c2.setTime(lastLogin); + + if (daysBetween == 1) { + if (this.client.getHabbo().getHabboStats().getAchievementProgress().get(Emulator.getGameEnvironment().getAchievementManager().getAchievement("Login")) == this.client.getHabbo().getHabboStats().loginStreak) { + AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("Login")); + } + this.client.getHabbo().getHabboStats().loginStreak++; + calendar = true; + } else if (daysBetween >= 1) { + calendar = true; + } else { + if (((lastLogin.getTime() / 1000) - Emulator.getIntUnixTimestamp()) > 86400) { + this.client.getHabbo().getHabboStats().loginStreak = 0; + } + } + } + + if (!this.client.getHabbo().getHabboStats().getAchievementProgress().containsKey(Emulator.getGameEnvironment().getAchievementManager().getAchievement("RegistrationDuration"))) { + AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RegistrationDuration"), 0); + } else { + int daysRegistered = ((Emulator.getIntUnixTimestamp() - this.client.getHabbo().getHabboInfo().getAccountCreated()) / 86400); + + int days = this.client.getHabbo().getHabboStats().getAchievementProgress( + Emulator.getGameEnvironment().getAchievementManager().getAchievement("RegistrationDuration") + ); + + if (daysRegistered - days > 0) { + AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RegistrationDuration"), daysRegistered - days); + } + } + + if (!this.client.getHabbo().getHabboStats().getAchievementProgress().containsKey(Emulator.getGameEnvironment().getAchievementManager().getAchievement("TraderPass"))) { + AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("TraderPass")); + } + + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement achievementQueueStatement = connection.prepareStatement("SELECT * FROM users_achievements_queue WHERE user_id = ?")) { + achievementQueueStatement.setInt(1, this.client.getHabbo().getHabboInfo().getId()); + + try (ResultSet achievementSet = achievementQueueStatement.executeQuery()) { + while (achievementSet.next()) { + AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement(achievementSet.getInt("achievement_id")), achievementSet.getInt("amount")); + } + } + + try (PreparedStatement deleteStatement = connection.prepareStatement("DELETE FROM users_achievements_queue WHERE user_id = ?")) { + deleteStatement.setInt(1, this.client.getHabbo().getHabboInfo().getId()); + deleteStatement.execute(); + } + } + messages.add(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), roomIdToEnter).compose()); messages.add(new UserEffectsListComposer(habbo, this.client.getHabbo().getInventory().getEffectsComponent().effects.values()).compose()); messages.add(new UserClothesComposer(this.client.getHabbo()).compose()); @@ -147,11 +224,31 @@ public class SecureLoginEvent extends MessageHandler { messages.add(new ModToolComposer(this.client.getHabbo()).compose()); } + + CalendarCampaign campaign = Emulator.getGameEnvironment().getCalendarManager().getCalendarCampaign(Emulator.getConfig().getValue("hotel.calendar.default")); + if (campaign != null) { + long daysBetween = DAYS.between(new Timestamp(campaign.getStartTimestamp() * 1000L).toInstant(), new Date().toInstant()); + if (daysBetween >= 0) { + messages.add(new AdventCalendarDataComposer(campaign.getName(), campaign.getImage(), campaign.getTotalDays(), (int) daysBetween, this.client.getHabbo().getHabboStats().calendarRewardsClaimed, campaign.getLockExpired()).compose()); + if(Emulator.getConfig().getBoolean("hotel.login.show.calendar", false)) { + messages.add(new NuxAlertComposer("openView/calendar").compose()); + } + } + } + + if (TargetOffer.ACTIVE_TARGET_OFFER_ID > 0) { + TargetOffer offer = Emulator.getGameEnvironment().getCatalogManager().getTargetOffer(TargetOffer.ACTIVE_TARGET_OFFER_ID); + + if (offer != null) { + messages.add(new TargetedOfferComposer(this.client.getHabbo(), offer).compose()); + } + } + this.client.sendResponses(messages); //Hardcoded //this.client.sendResponse(new ForumsTestComposer()); - this.client.sendResponse(new InventoryAchievementsComposer()); + this.client.sendResponse(new BadgePointLimitsComposer()); ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); @@ -199,7 +296,7 @@ public class SecureLoginEvent extends MessageHandler { }, Emulator.getConfig().getInt("hotel.welcome.alert.delay", 5000)); } - if(SubscriptionHabboClub.HC_PAYDAY_ENABLED) { + if (SubscriptionHabboClub.HC_PAYDAY_ENABLED) { SubscriptionHabboClub.processUnclaimed(habbo); }