From 287af8aba48aa0c92d4bd9d59c5c67d79b87f47a Mon Sep 17 00:00:00 2001 From: brenoepics <59066707+brenoepics@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:16:31 -0300 Subject: [PATCH] Fix calendar timestamp --- sqlupdates/3_0_0 to 3_0_1.sql | 62 ++++++++++--------- .../campaign/calendar/CalendarCampaign.java | 8 +-- .../campaign/calendar/CalendarManager.java | 6 +- .../habbohotel/commands/CalendarCommand.java | 2 +- .../incoming/handshake/UsernameEvent.java | 3 +- 5 files changed, 43 insertions(+), 38 deletions(-) diff --git a/sqlupdates/3_0_0 to 3_0_1.sql b/sqlupdates/3_0_0 to 3_0_1.sql index f82618c9..42ace602 100644 --- a/sqlupdates/3_0_0 to 3_0_1.sql +++ b/sqlupdates/3_0_0 to 3_0_1.sql @@ -11,45 +11,51 @@ INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('youtube.apikey', ''); INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('hotel.gifts.length.max', '300'); - -- ---------------------------- +-- ---------------------------- -- Table structure for calendar_campaigns -- ---------------------------- DROP TABLE IF EXISTS `calendar_campaigns`; CREATE TABLE `calendar_campaigns` ( - `id` int NOT NULL AUTO_INCREMENT, - `name` varchar(255) NOT NULL DEFAULT '', - `image` varchar(255) NOT NULL DEFAULT '', - `start_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', - `total_days` int NOT NULL DEFAULT '30', - `lock_expired` enum('1','0') NOT NULL DEFAULT '1', - `enabled` enum('1','0') NOT NULL DEFAULT '1', - UNIQUE KEY `id` (`id`) + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL DEFAULT '', + `image` varchar(255) NOT NULL DEFAULT '', + `start_timestamp` int NOT NULL DEFAULT '0', + `total_days` int NOT NULL DEFAULT '30', + `lock_expired` enum('1','0') NOT NULL DEFAULT '1', + `enabled` enum('1','0') NOT NULL DEFAULT '1', + UNIQUE KEY `id` (`id`) ); --- ---------------------------- --- Records of calendar_campaigns --- ---------------------------- -INSERT INTO `calendar_campaigns` VALUES ('1', 'test', '', '2022-02-09 16:49:13', '31', '1', '1'); - -- ---------------------------- -- Table structure for calendar_rewards -- ---------------------------- DROP TABLE IF EXISTS `calendar_rewards`; CREATE TABLE `calendar_rewards` ( - `id` int NOT NULL AUTO_INCREMENT, - `campaign_id` int NOT NULL DEFAULT '0', - `product_name` varchar(128) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '', - `custom_image` varchar(128) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '', - `credits` int NOT NULL DEFAULT '0', - `pixels` int NOT NULL DEFAULT '0', - `points` int NOT NULL DEFAULT '0', - `points_type` int NOT NULL DEFAULT '0', - `badge` varchar(25) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '', - `item_id` int NOT NULL DEFAULT '0', - `subscription_type` enum('HABBO_CLUB') CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL, - `subscription_type` varchar(128) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT '', - `subscription_days` int NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) USING BTREE + `id` int NOT NULL AUTO_INCREMENT, + `campaign_id` int NOT NULL DEFAULT '0', + `product_name` varchar(128) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '', + `custom_image` varchar(128) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '', + `credits` int NOT NULL DEFAULT '0', + `pixels` int NOT NULL DEFAULT '0', + `points` int NOT NULL DEFAULT '0', + `points_type` int NOT NULL DEFAULT '0', + `badge` varchar(25) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '', + `item_id` int NOT NULL DEFAULT '0', + `subscription_type` varchar(128) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT '', + `subscription_days` int NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) USING BTREE +); + +-- ---------------------------- +-- Table structure for calendar_rewards_claimed +-- ---------------------------- +DROP TABLE IF EXISTS `calendar_rewards_claimed`; +CREATE TABLE `calendar_rewards_claimed` ( + `user_id` int NOT NULL, + `campaign_id` int NOT NULL DEFAULT '0', + `day` int NOT NULL, + `reward_id` int NOT NULL, + `timestamp` int NOT NULL ); INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('hotel.calendar.default', 'test'); diff --git a/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarCampaign.java b/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarCampaign.java index b00cf7fc..29733ddb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarCampaign.java +++ b/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarCampaign.java @@ -12,7 +12,7 @@ public class CalendarCampaign { private final String name; private final String image; private Map rewards = new THashMap<>(); - private final Timestamp start_timestamp; + private final Integer start_timestamp; private final int total_days; private final boolean lock_expired; @@ -20,12 +20,12 @@ public class CalendarCampaign { this.id = set.getInt("id"); this.name = set.getString("name"); this.image = set.getString("image"); - this.start_timestamp = set.getTimestamp("start_timestamp"); + this.start_timestamp = set.getInt("start_timestamp"); this.total_days = set.getInt("total_days"); this.lock_expired = set.getInt("lock_expired") == 1; } - public CalendarCampaign(int id, String name, String image, Timestamp start_timestamp, int total_days, boolean lock_expired) { + public CalendarCampaign(int id, String name, String image, Integer start_timestamp, int total_days, boolean lock_expired) { this.id = id; this.name = name; this.image = image; @@ -46,7 +46,7 @@ public class CalendarCampaign { return this.image; } - public Timestamp getStartTimestamp() { + public Integer getStartTimestamp() { return this.start_timestamp; } diff --git a/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java b/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java index 4e2720e8..1336f88f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java @@ -68,7 +68,7 @@ public class CalendarManager { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO calendar_campaigns ( name, image, start_timestamp, total_days, lock_expired) VALUES (?, ?, ?, ? , ?)", Statement.RETURN_GENERATED_KEYS)) { statement.setString(1, campaign.getName()); statement.setString(2, campaign.getImage()); - statement.setTimestamp(3, campaign.getStartTimestamp()); + statement.setInt(3, campaign.getStartTimestamp()); statement.setInt(4, campaign.getTotalDays()); statement.setBoolean(5, campaign.getLockExpired()); int affectedRows = statement.executeUpdate(); @@ -124,7 +124,7 @@ public class CalendarManager { int random = rewards.get(rand); CalendarRewardObject object = campaign.getRewards().get(random); if (object == null) return; - int daysBetween = (int) DAYS.between(campaign.getStartTimestamp().toInstant(), new Date().toInstant()); + int daysBetween = (int) DAYS.between(new Timestamp(campaign.getStartTimestamp() * 1000L).toInstant(), new Date().toInstant()); if(daysBetween >= 0 && daysBetween <= campaign.getTotalDays()) { int diff = (daysBetween - day); if ((((diff <= 2 || !campaign.getLockExpired()) && diff >= 0) || (force && habbo.hasPermission("acc_calendar_force")))) { @@ -141,7 +141,7 @@ public class CalendarManager { statement.setInt(2, campaign.getId()); statement.setInt(3, day); statement.setInt(4, object.getId()); - statement.setTimestamp(5, new Timestamp(System.currentTimeMillis())); + statement.setInt(5, Emulator.getIntUnixTimestamp()); statement.execute(); } catch (SQLException e) { LOGGER.error("Caught SQL exception", e); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/CalendarCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/CalendarCommand.java index ea9d3c69..dd2a773f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/CalendarCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/CalendarCommand.java @@ -27,7 +27,7 @@ public class CalendarCommand extends Command { } CalendarCampaign campaign = Emulator.getGameEnvironment().getCalendarManager().getCalendarCampaign(campaignName); if(campaign == null) return false; - int daysBetween = (int) DAYS.between(campaign.getStartTimestamp().toInstant(), new Date().toInstant()); + int daysBetween = (int) DAYS.between(new Timestamp(campaign.getStartTimestamp() * 1000L).toInstant(), new Date().toInstant()); if(daysBetween >= 0) { gameClient.sendResponse(new AdventCalendarDataComposer(campaign.getName(), campaign.getImage(), campaign.getTotalDays(), daysBetween, gameClient.getHabbo().getHabboStats().calendarRewardsClaimed, campaign.getLockExpired())); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/UsernameEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/UsernameEvent.java index 3636c6c0..c217e946 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/UsernameEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/UsernameEvent.java @@ -88,11 +88,10 @@ public class UsernameEvent extends MessageHandler { deleteStatement.execute(); } } - if (Emulator.getConfig().getBoolean("hotel.calendar.enabled")) { CalendarCampaign campaign = Emulator.getGameEnvironment().getCalendarManager().getCalendarCampaign(Emulator.getConfig().getValue("hotel.calendar.default")); if(campaign != null){ - long daysBetween = DAYS.between(campaign.getStartTimestamp().toInstant(), new Date().toInstant()); + long daysBetween = DAYS.between(new Timestamp(campaign.getStartTimestamp() * 1000L).toInstant(), new Date().toInstant()); if(daysBetween >= 0) { this.client.sendResponse(new AdventCalendarDataComposer(campaign.getName(), campaign.getImage(), campaign.getTotalDays(), (int) daysBetween, this.client.getHabbo().getHabboStats().calendarRewardsClaimed, campaign.getLockExpired())); this.client.sendResponse(new NuxAlertComposer("openView/calendar"));