Merge pull request #76 from simoleo89/pr/catalog-admin-fixes

fix(catalog): NPE on page creation + admin handlers
This commit is contained in:
DuckieTM
2026-04-13 15:47:33 +02:00
committed by GitHub
6 changed files with 93 additions and 3 deletions
@@ -706,7 +706,7 @@ public class CatalogManager {
public CatalogPage createCatalogPage(String caption, String captionSave, int roomId, int icon, CatalogPageLayouts layout, int minRank, int parentId) {
CatalogPage catalogPage = null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO catalog_pages (parent_id, caption, caption_save, icon_image, visible, enabled, min_rank, page_layout, room_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO catalog_pages (parent_id, caption, caption_save, icon_image, visible, enabled, min_rank, page_layout, room_id, includes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
statement.setInt(1, parentId);
statement.setString(2, caption);
statement.setString(3, captionSave);
@@ -716,6 +716,7 @@ public class CatalogManager {
statement.setInt(7, minRank);
statement.setString(8, layout.name());
statement.setInt(9, roomId);
statement.setString(10, "");
statement.execute();
try (ResultSet set = statement.getGeneratedKeys()) {
if (set.next()) {
@@ -68,8 +68,9 @@ public abstract class CatalogPage implements Comparable<CatalogPage>, ISerialize
this.textDetails = set.getString("page_text_details");
this.textTeaser = set.getString("page_text_teaser");
if (!set.getString("includes").isEmpty()) {
for (String id : set.getString("includes").split(";")) {
String includes = set.getString("includes");
if (includes != null && !includes.isEmpty()) {
for (String id : includes.split(";")) {
try {
this.included.add(Integer.valueOf(id));
} catch (Exception e) {
@@ -279,6 +279,8 @@ public class PacketManager {
this.registerHandler(Incoming.CatalogAdminMoveOfferEvent, CatalogAdminMoveOfferEvent.class);
this.registerHandler(Incoming.CatalogAdminMovePageEvent, CatalogAdminMovePageEvent.class);
this.registerHandler(Incoming.CatalogAdminPublishEvent, CatalogAdminPublishEvent.class);
this.registerHandler(Incoming.CatalogAdminSavePageImagesEvent, CatalogAdminSavePageImagesEvent.class);
this.registerHandler(Incoming.CatalogAdminSavePageIconEvent, CatalogAdminSavePageIconEvent.class);
}
private void registerEvent() throws Exception {
@@ -430,6 +430,8 @@ public class Incoming {
public static final int CatalogAdminMoveOfferEvent = 10056;
public static final int CatalogAdminMovePageEvent = 10057;
public static final int CatalogAdminPublishEvent = 10058;
public static final int CatalogAdminSavePageImagesEvent = 10060;
public static final int CatalogAdminSavePageIconEvent = 10061;
// Custom Prefixes
public static final int RequestUserPrefixesEvent = 7011;
@@ -0,0 +1,41 @@
package com.eu.habbo.messages.incoming.catalog.catalogadmin;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.catalog.CatalogPage;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.catalog.catalogadmin.CatalogAdminResultComposer;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class CatalogAdminSavePageIconEvent extends MessageHandler {
@Override
public void handle() throws Exception {
if (!this.client.getHabbo().hasPermission(Permission.ACC_CATALOGFURNI)) {
this.client.sendResponse(new CatalogAdminResultComposer(false, "No permission"));
return;
}
int pageId = this.packet.readInt();
int iconId = this.packet.readInt();
CatalogPage page = Emulator.getGameEnvironment().getCatalogManager().catalogPages.get(pageId);
if (page == null) {
this.client.sendResponse(new CatalogAdminResultComposer(false, "Page not found: " + pageId));
return;
}
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement(
"UPDATE catalog_pages SET icon_image = ? WHERE id = ?")) {
statement.setInt(1, iconId);
statement.setInt(2, pageId);
statement.execute();
}
this.client.sendResponse(new CatalogAdminResultComposer(true, "Page icon saved"));
}
}
@@ -0,0 +1,43 @@
package com.eu.habbo.messages.incoming.catalog.catalogadmin;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.catalog.CatalogPage;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.catalog.catalogadmin.CatalogAdminResultComposer;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class CatalogAdminSavePageImagesEvent extends MessageHandler {
@Override
public void handle() throws Exception {
if (!this.client.getHabbo().hasPermission(Permission.ACC_CATALOGFURNI)) {
this.client.sendResponse(new CatalogAdminResultComposer(false, "No permission"));
return;
}
int pageId = this.packet.readInt();
String headerImage = this.packet.readString();
String teaserImage = this.packet.readString();
CatalogPage page = Emulator.getGameEnvironment().getCatalogManager().catalogPages.get(pageId);
if (page == null) {
this.client.sendResponse(new CatalogAdminResultComposer(false, "Page not found: " + pageId));
return;
}
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement(
"UPDATE catalog_pages SET page_headline = ?, page_teaser = ? WHERE id = ?")) {
statement.setString(1, headerImage);
statement.setString(2, teaserImage);
statement.setInt(3, pageId);
statement.execute();
}
this.client.sendResponse(new CatalogAdminResultComposer(true, "Page images saved"));
}
}