Fix room promotions (closes #337)

This commit is contained in:
Alejandro 2020-01-27 20:45:44 +02:00
parent fe78102678
commit 50c7b1d3f4
10 changed files with 124 additions and 62 deletions

View File

@ -1,3 +1,10 @@
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.publish', '5'); INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.publish', '5');
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.publish.type', '0'); INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.publish.type', '0');
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.type', '0'); INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.type', '0');
ALTER TABLE `room_promotions`
ADD COLUMN `start_timestamp` int(11) NOT NULL DEFAULT -1 AFTER `end_timestamp`;
ALTER TABLE `room_promotions`
ADD COLUMN `category` int(11) NOT NULL DEFAULT 0 AFTER `start_timestamp`;
INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('navigator.eventcategories', '1,Hottest Events,false;2,Parties & Music,true;3,Role Play,true;4,Help Desk,true;5,Trading,true;6,Games,true;7,Debates & Discussions,true;8,Grand Openings,true;9,Friending,true;10,Jobs,true;11,Group Events,true');

View File

@ -0,0 +1,43 @@
package com.eu.habbo.habbohotel.navigation;
import com.eu.habbo.messages.ServerMessage;
public class EventCategory {
private int id;
private String caption;
private boolean visible;
public EventCategory(int id, String caption, boolean visible) {
this.id = id;
this.caption = caption;
this.visible = visible;
}
public EventCategory(String serialized) throws Exception {
String[] parts = serialized.split(",");
if (parts.length != 3) throw new Exception("A serialized event category should contain 3 fields");
this.id = Integer.valueOf(parts[0]);
this.caption = parts[1];
this.visible = parts[2].equalsIgnoreCase("true");
}
public int getId() {
return id;
}
public String getCaption() {
return caption;
}
public boolean isVisible() {
return visible;
}
public void serialize(ServerMessage message) {
message.appendInt(this.id);
message.appendString(this.caption);
message.appendBoolean(this.visible);
}
}

View File

@ -2095,25 +2095,29 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return ""; return "";
} }
public void createPromotion(String title, String description) { public void createPromotion(String title, String description, int category) {
this.promoted = true; this.promoted = true;
if (this.promotion == null) { if (this.promotion == null) {
this.promotion = new RoomPromotion(this, title, description, Emulator.getIntUnixTimestamp() + (120 * 60)); this.promotion = new RoomPromotion(this, title, description, Emulator.getIntUnixTimestamp() + (120 * 60), Emulator.getIntUnixTimestamp(), category);
} else { } else {
this.promotion.setTitle(title); this.promotion.setTitle(title);
this.promotion.setDescription(description); this.promotion.setDescription(description);
this.promotion.setEndTimestamp(Emulator.getIntUnixTimestamp() + (120 * 60)); this.promotion.setEndTimestamp(Emulator.getIntUnixTimestamp() + (120 * 60));
this.promotion.setCategory(category);
} }
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_promotions (room_id, title, description, end_timestamp) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE title = ?, description = ?, end_timestamp = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_promotions (room_id, title, description, end_timestamp, start_timestamp, category) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title = ?, description = ?, end_timestamp = ?, category = ?")) {
statement.setInt(1, this.id); statement.setInt(1, this.id);
statement.setString(2, title); statement.setString(2, title);
statement.setString(3, description); statement.setString(3, description);
statement.setInt(4, this.promotion.getEndTimestamp()); statement.setInt(4, this.promotion.getEndTimestamp());
statement.setString(5, this.promotion.getTitle()); statement.setInt(5, this.promotion.getStartTimestamp());
statement.setString(6, this.promotion.getDescription()); statement.setInt(6, category);
statement.setInt(7, this.promotion.getEndTimestamp()); statement.setString(7, this.promotion.getTitle());
statement.setString(8, this.promotion.getDescription());
statement.setInt(9, this.promotion.getEndTimestamp());
statement.setInt(10, this.promotion.getCategory());
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Emulator.getLogging().logSQLException(e); Emulator.getLogging().logSQLException(e);

View File

@ -13,12 +13,16 @@ public class RoomPromotion {
private String title; private String title;
private String description; private String description;
private int endTimestamp; private int endTimestamp;
private int startTimestamp;
private int category;
public RoomPromotion(Room room, String title, String description, int endTimestamp) { public RoomPromotion(Room room, String title, String description, int endTimestamp, int startTimestamp, int category) {
this.room = room; this.room = room;
this.title = title; this.title = title;
this.description = description; this.description = description;
this.endTimestamp = endTimestamp; this.endTimestamp = endTimestamp;
this.startTimestamp = startTimestamp;
this.category = category;
} }
public RoomPromotion(Room room, ResultSet set) throws SQLException { public RoomPromotion(Room room, ResultSet set) throws SQLException {
@ -26,14 +30,17 @@ public class RoomPromotion {
this.title = set.getString("title"); this.title = set.getString("title");
this.description = set.getString("description"); this.description = set.getString("description");
this.endTimestamp = set.getInt("end_timestamp"); this.endTimestamp = set.getInt("end_timestamp");
this.startTimestamp = set.getInt("start_timestamp");
this.category = set.getInt("category");
} }
public void save() { public void save() {
if (this.needsUpdate) { if (this.needsUpdate) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE room_promotions SET title = ?, description = ? WHERE room_id = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE room_promotions SET title = ?, description = ?, category = ? WHERE room_id = ?")) {
statement.setString(1, this.title); statement.setString(1, this.title);
statement.setString(2, this.description); statement.setString(2, this.description);
statement.setInt(3, this.room.getId()); statement.setInt(3, this.category);
statement.setInt(4, this.room.getId());
statement.executeUpdate(); statement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
Emulator.getLogging().logSQLException(e); Emulator.getLogging().logSQLException(e);
@ -74,4 +81,20 @@ public class RoomPromotion {
public void addEndTimestamp(int time) { public void addEndTimestamp(int time) {
this.endTimestamp += time; this.endTimestamp += time;
} }
public int getStartTimestamp() {
return startTimestamp;
}
public void setStartTimestamp(int startTimestamp) {
this.startTimestamp = startTimestamp;
}
public int getCategory() {
return category;
}
public void setCategory(int category) {
this.category = category;
}
} }

View File

@ -259,6 +259,7 @@ public class Incoming {
public static final int RequestDeleteRoomEvent = 532; public static final int RequestDeleteRoomEvent = 532;
public static final int RequestPromotionRoomsEvent = 1075; public static final int RequestPromotionRoomsEvent = 1075;
public static final int BuyRoomPromotionEvent = 777; public static final int BuyRoomPromotionEvent = 777;
public static final int EditRoomPromotionMessageEvent = 3991;
public static final int RequestGuideToolEvent = 1922; public static final int RequestGuideToolEvent = 1922;
public static final int RequestGuideAssistanceEvent = 3338; public static final int RequestGuideAssistanceEvent = 3338;
public static final int GuideUserTypingEvent = 519; public static final int GuideUserTypingEvent = 519;
@ -314,7 +315,6 @@ public class Incoming {
public static final int YoutubeRequestStateChange = 3005; public static final int YoutubeRequestStateChange = 3005;
public static final int YoutubeRequestPlaylistChange = 2069; public static final int YoutubeRequestPlaylistChange = 2069;
public static final int EditRoomPromotionMessageEvent = 3707;
public static final int HotelViewRequestBadgeRewardEvent = 2318; public static final int HotelViewRequestBadgeRewardEvent = 2318;
public static final int HotelViewClaimBadgeRewardEvent = -1; public static final int HotelViewClaimBadgeRewardEvent = -1;

View File

@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.catalog.AlertPurchaseFailedComposer; import com.eu.habbo.messages.outgoing.catalog.AlertPurchaseFailedComposer;
import com.eu.habbo.messages.outgoing.catalog.PurchaseOKComposer; import com.eu.habbo.messages.outgoing.catalog.PurchaseOKComposer;
import com.eu.habbo.messages.outgoing.navigator.NewNavigatorEventCategoriesComposer;
import com.eu.habbo.messages.outgoing.rooms.promotions.RoomPromotionMessageComposer; import com.eu.habbo.messages.outgoing.rooms.promotions.RoomPromotionMessageComposer;
public class BuyRoomPromotionEvent extends MessageHandler { public class BuyRoomPromotionEvent extends MessageHandler {
@ -20,6 +21,9 @@ public class BuyRoomPromotionEvent extends MessageHandler {
String description = this.packet.readString(); String description = this.packet.readString();
int categoryId = this.packet.readInt(); int categoryId = this.packet.readInt();
if (NewNavigatorEventCategoriesComposer.CATEGORIES.stream().noneMatch(c -> c.getId() == categoryId))
return;
CatalogPage page = Emulator.getGameEnvironment().getCatalogManager().getCatalogPage(pageId); CatalogPage page = Emulator.getGameEnvironment().getCatalogManager().getCatalogPage(pageId);
if (page != null) { if (page != null) {
@ -35,7 +39,7 @@ public class BuyRoomPromotionEvent extends MessageHandler {
if (room.isPromoted()) { if (room.isPromoted()) {
room.getPromotion().addEndTimestamp(120 * 60); room.getPromotion().addEndTimestamp(120 * 60);
} else { } else {
room.createPromotion(title, description); room.createPromotion(title, description, categoryId);
} }
if (room.isPromoted()) { if (room.isPromoted()) {

View File

@ -388,13 +388,12 @@ public class Outgoing {
public final static int AlertPurchaseUnavailableComposer = 3770; // PRODUCTION-201611291003-338511768 public final static int AlertPurchaseUnavailableComposer = 3770; // PRODUCTION-201611291003-338511768
public final static int PetBreedingStartFailedComposer = 2621; // PRODUCTION-201611291003-338511768 public final static int PetBreedingStartFailedComposer = 2621; // PRODUCTION-201611291003-338511768
public final static int DailyQuestComposer = 1878; // PRODUCTION-201611291003-338511768 public final static int DailyQuestComposer = 1878; // PRODUCTION-201611291003-338511768
public final static int NewNavigatorRoomEventComposer = 1840; // PRODUCTION-201611291003-338511768
public final static int HotelViewHideCommunityVoteButtonComposer = 1435; // PRODUCTION-201611291003-338511768 public final static int HotelViewHideCommunityVoteButtonComposer = 1435; // PRODUCTION-201611291003-338511768
public final static int CatalogSearchResultComposer = 3388; // PRODUCTION-201611291003-338511768 public final static int CatalogSearchResultComposer = 3388; // PRODUCTION-201611291003-338511768
public final static int FriendFindingRoomComposer = 1210; // PRODUCTION-201611291003-338511768 public final static int FriendFindingRoomComposer = 1210; // PRODUCTION-201611291003-338511768
public final static int QuestComposer = 230; // PRODUCTION-201611291003-338511768 public final static int QuestComposer = 230; // PRODUCTION-201611291003-338511768
public final static int ModToolSanctionDataComposer = 2782; // PRODUCTION-201611291003-338511768 public final static int ModToolSanctionDataComposer = 2782; // PRODUCTION-201611291003-338511768
public final static int RoomEventMessageComposer = 2274; public final static int RoomEventMessageComposer = 1840;
public final static int JukeBoxMySongsComposer = 2602; // PRODUCTION-201611291003-338511768 public final static int JukeBoxMySongsComposer = 2602; // PRODUCTION-201611291003-338511768

View File

@ -1,47 +1,26 @@
package com.eu.habbo.messages.outgoing.navigator; package com.eu.habbo.messages.outgoing.navigator;
import com.eu.habbo.habbohotel.navigation.EventCategory;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing; import com.eu.habbo.messages.outgoing.Outgoing;
import java.util.ArrayList;
import java.util.List;
public class NewNavigatorEventCategoriesComposer extends MessageComposer { public class NewNavigatorEventCategoriesComposer extends MessageComposer {
public static List<EventCategory> CATEGORIES = new ArrayList<>();
@Override @Override
public ServerMessage compose() { public ServerMessage compose() {
this.response.init(Outgoing.NewNavigatorEventCategoriesComposer); this.response.init(Outgoing.NewNavigatorEventCategoriesComposer);
this.response.appendInt(11);
this.response.appendInt(1); this.response.appendInt(NewNavigatorEventCategoriesComposer.CATEGORIES.size());
this.response.appendString("Hottest Events");
this.response.appendBoolean(false); for (EventCategory category : NewNavigatorEventCategoriesComposer.CATEGORIES) {
this.response.appendInt(2); category.serialize(this.response);
this.response.appendString("Parties & Music"); }
this.response.appendBoolean(true);
this.response.appendInt(3);
this.response.appendString("Role Play");
this.response.appendBoolean(true);
this.response.appendInt(4);
this.response.appendString("Help Desk");
this.response.appendBoolean(true);
this.response.appendInt(5);
this.response.appendString("Trading");
this.response.appendBoolean(true);
this.response.appendInt(6);
this.response.appendString("Games");
this.response.appendBoolean(true);
this.response.appendInt(7);
this.response.appendString("Debates & Discussions");
this.response.appendBoolean(true);
this.response.appendInt(8);
this.response.appendString("Grand Openings");
this.response.appendBoolean(true);
this.response.appendInt(9);
this.response.appendString("Friending");
this.response.appendBoolean(true);
this.response.appendInt(10);
this.response.appendString("Jobs");
this.response.appendBoolean(true);
this.response.appendInt(11);
this.response.appendString("Group Events");
this.response.appendBoolean(true);
return this.response; return this.response;
} }
} }

View File

@ -1,5 +1,6 @@
package com.eu.habbo.messages.outgoing.rooms.promotions; package com.eu.habbo.messages.outgoing.rooms.promotions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomPromotion; import com.eu.habbo.habbohotel.rooms.RoomPromotion;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
@ -21,37 +22,29 @@ public class RoomPromotionMessageComposer extends MessageComposer {
this.response.init(Outgoing.RoomEventMessageComposer); this.response.init(Outgoing.RoomEventMessageComposer);
if (this.room == null || this.roomPromotion == null) { if (this.room == null || this.roomPromotion == null) {
this.response.appendInt(-1); this.response.appendInt(-1);
this.response.appendInt(-1); this.response.appendInt(-1);
this.response.appendString(""); this.response.appendString("");
this.response.appendInt(0); this.response.appendInt(0);
this.response.appendInt(0); this.response.appendInt(0);
this.response.appendString(""); this.response.appendString("");
this.response.appendString(""); this.response.appendString("");
this.response.appendInt(0); this.response.appendInt(0);
this.response.appendInt(0); this.response.appendInt(0);
this.response.appendInt(0); this.response.appendInt(0);
} else { } else {
this.response.appendInt(this.room.getId()); this.response.appendInt(this.room.getId()); // promotion id
this.response.appendInt(this.room.getOwnerId()); this.response.appendInt(this.room.getOwnerId());
this.response.appendString(this.room.getOwnerName()); this.response.appendString(this.room.getOwnerName());
this.response.appendInt(1); this.response.appendInt(this.room.getId()); // room id
this.response.appendInt(1); this.response.appendInt(1); // "type"
this.response.appendString(this.roomPromotion.getTitle()); this.response.appendString(this.roomPromotion.getTitle());
this.response.appendString(this.roomPromotion.getDescription()); this.response.appendString(this.roomPromotion.getDescription());
this.response.appendInt(0); this.response.appendInt((Emulator.getIntUnixTimestamp() - this.roomPromotion.getStartTimestamp()) / 60); // minutes since starting
this.response.appendInt(0); this.response.appendInt((this.roomPromotion.getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60); // minutes until end
this.response.appendInt(0); this.response.appendInt(this.roomPromotion.getCategory()); // category
} }
return this.response; return this.response;

View File

@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionRoller;
import com.eu.habbo.habbohotel.items.interactions.games.football.InteractionFootballGate; import com.eu.habbo.habbohotel.items.interactions.games.football.InteractionFootballGate;
import com.eu.habbo.habbohotel.messenger.Messenger; import com.eu.habbo.habbohotel.messenger.Messenger;
import com.eu.habbo.habbohotel.modtool.WordFilter; import com.eu.habbo.habbohotel.modtool.WordFilter;
import com.eu.habbo.habbohotel.navigation.EventCategory;
import com.eu.habbo.habbohotel.navigation.NavigatorManager; import com.eu.habbo.habbohotel.navigation.NavigatorManager;
import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboInventory; import com.eu.habbo.habbohotel.users.HabboInventory;
@ -28,6 +29,7 @@ import com.eu.habbo.messages.incoming.floorplaneditor.FloorPlanEditorSaveEvent;
import com.eu.habbo.messages.incoming.hotelview.HotelViewRequestLTDAvailabilityEvent; import com.eu.habbo.messages.incoming.hotelview.HotelViewRequestLTDAvailabilityEvent;
import com.eu.habbo.messages.incoming.users.ChangeNameCheckUsernameEvent; import com.eu.habbo.messages.incoming.users.ChangeNameCheckUsernameEvent;
import com.eu.habbo.messages.outgoing.catalog.DiscountComposer; import com.eu.habbo.messages.outgoing.catalog.DiscountComposer;
import com.eu.habbo.messages.outgoing.navigator.NewNavigatorEventCategoriesComposer;
import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent; import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent;
import com.eu.habbo.plugin.events.emulator.EmulatorLoadedEvent; import com.eu.habbo.plugin.events.emulator.EmulatorLoadedEvent;
import com.eu.habbo.plugin.events.roomunit.RoomUnitLookAtPointEvent; import com.eu.habbo.plugin.events.roomunit.RoomUnitLookAtPointEvent;
@ -132,12 +134,20 @@ public class PluginManager {
CameraPurchaseEvent.CAMERA_PURCHASE_POINTS = Emulator.getConfig().getInt("camera.price.points", 5); CameraPurchaseEvent.CAMERA_PURCHASE_POINTS = Emulator.getConfig().getInt("camera.price.points", 5);
CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE = Emulator.getConfig().getInt("camera.price.points.type", 0); CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE = Emulator.getConfig().getInt("camera.price.points.type", 0);
NewNavigatorEventCategoriesComposer.CATEGORIES.clear();
for (String category : Emulator.getConfig().getValue("navigator.eventcategories", "").split(";")) {
try {
NewNavigatorEventCategoriesComposer.CATEGORIES.add(new EventCategory(category));
} catch (Exception e) {
e.printStackTrace();
}
}
if (Emulator.isReady) { if (Emulator.isReady) {
Emulator.getGameEnvironment().getCreditsScheduler().reloadConfig(); Emulator.getGameEnvironment().getCreditsScheduler().reloadConfig();
Emulator.getGameEnvironment().getPointsScheduler().reloadConfig(); Emulator.getGameEnvironment().getPointsScheduler().reloadConfig();
Emulator.getGameEnvironment().getPixelScheduler().reloadConfig(); Emulator.getGameEnvironment().getPixelScheduler().reloadConfig();
Emulator.getGameEnvironment().getGotwPointsScheduler().reloadConfig(); Emulator.getGameEnvironment().getGotwPointsScheduler().reloadConfig();
} }
} }