From aeafc99468e766c018f6293ac7b91455510a0d68 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 25 Jan 2020 20:20:04 +0200 Subject: [PATCH] Add custom timer support (closes #320) --- .../com/eu/habbo/messages/PacketManager.java | 1 + .../eu/habbo/messages/incoming/Incoming.java | 2 ++ .../HotelViewRequestSecondsUntilEvent.java | 20 ++++++++++++++++ .../eu/habbo/messages/outgoing/Outgoing.java | 1 + .../HotelViewSecondsUntilComposer.java | 24 +++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 src/main/java/com/eu/habbo/messages/incoming/hotelview/HotelViewRequestSecondsUntilEvent.java create mode 100644 src/main/java/com/eu/habbo/messages/outgoing/hotelview/HotelViewSecondsUntilComposer.java diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index 4f4cb8ad..ccc54701 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -339,6 +339,7 @@ public class PacketManager { this.registerHandler(Incoming.HotelViewRequestBadgeRewardEvent, HotelViewRequestBadgeRewardEvent.class); this.registerHandler(Incoming.HotelViewClaimBadgeRewardEvent, HotelViewClaimBadgeRewardEvent.class); this.registerHandler(Incoming.HotelViewRequestLTDAvailabilityEvent, HotelViewRequestLTDAvailabilityEvent.class); + this.registerHandler(Incoming.HotelViewRequestSecondsUntilEvent, HotelViewRequestSecondsUntilEvent.class); } private void registerInventory() throws Exception { diff --git a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java index 464c76b7..6b13ed2e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java +++ b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java @@ -351,6 +351,8 @@ public class Incoming { public static final int LoveLockStartConfirmEvent = 3775; public static final int HotelViewRequestLTDAvailabilityEvent = 410; + public static final int HotelViewRequestSecondsUntilEvent = 271; + public static final int PurchaseTargetOfferEvent = 1826; public static final int TargetOfferStateEvent = 2041; public static final int StopBreedingEvent = 2713; diff --git a/src/main/java/com/eu/habbo/messages/incoming/hotelview/HotelViewRequestSecondsUntilEvent.java b/src/main/java/com/eu/habbo/messages/incoming/hotelview/HotelViewRequestSecondsUntilEvent.java new file mode 100644 index 00000000..c7a6be24 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/hotelview/HotelViewRequestSecondsUntilEvent.java @@ -0,0 +1,20 @@ +package com.eu.habbo.messages.incoming.hotelview; + +import com.eu.habbo.Emulator; +import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.hotelview.HotelViewSecondsUntilComposer; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; + +public class HotelViewRequestSecondsUntilEvent extends MessageHandler { + private static DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm"); + + @Override + public void handle() throws Exception { + String date = this.packet.readString(); + int secondsUntil = Math.max(0, (int) (dateFormat.parse(date).getTime() / 1000) - Emulator.getIntUnixTimestamp()); + + this.client.sendResponse(new HotelViewSecondsUntilComposer(date, secondsUntil)); + } +} diff --git a/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java b/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java index cc7efef7..037efc81 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java @@ -525,6 +525,7 @@ public class Outgoing { public final static int UnknownRoomViewerComposer = 3523; public final static int ErrorLoginComposer = 4000; public final static int HotelViewNextLTDAvailableComposer = 44; + public final static int HotelViewSecondsUntilComposer = 3926; public final static int UnknownRoomDesktopComposer = 69; public final static int UnknownGuildComposer3 = 876; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/hotelview/HotelViewSecondsUntilComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/hotelview/HotelViewSecondsUntilComposer.java new file mode 100644 index 00000000..d258dc2a --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/outgoing/hotelview/HotelViewSecondsUntilComposer.java @@ -0,0 +1,24 @@ +package com.eu.habbo.messages.outgoing.hotelview; + +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.MessageComposer; +import com.eu.habbo.messages.outgoing.Outgoing; + +public class HotelViewSecondsUntilComposer extends MessageComposer { + private final String dateString; + private final int seconds; + + public HotelViewSecondsUntilComposer(String dateString, int seconds) { + this.dateString = dateString; + this.seconds = seconds; + } + + @Override + public ServerMessage compose() { + this.response.init(Outgoing.HotelViewSecondsUntilComposer); + this.response.appendString(this.dateString); + this.response.appendInt(this.seconds); + + return this.response; + } +}