Merge branch 'calendar-fix' into 'dev'

Fix calendar timestamp on mariadb

See merge request morningstar/Arcturus-Community!506
This commit is contained in:
ArpyAge 2022-03-21 23:27:12 +00:00
commit 10f2d6d98e
5 changed files with 44 additions and 38 deletions

View File

@ -22,45 +22,52 @@ CREATE TABLE `messenger_categories` (
-- Set an ID (int) from category list items
ALTER TABLE messenger_friendships ADD category int NOT NULL DEFAULT '0' AFTER friends_since;
-- ----------------------------
-- 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');

View File

@ -12,7 +12,7 @@ public class CalendarCampaign {
private final String name;
private final String image;
private Map<Integer , CalendarRewardObject> 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;
}

View File

@ -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);

View File

@ -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()));
}

View File

@ -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"));