{
+ T map(ResultSet rs) throws SQLException;
+ }
+
+ @FunctionalInterface
+ public interface RowConsumer {
+ void accept(ResultSet rs) throws SQLException;
+ }
+
+ @FunctionalInterface
+ public interface ParameterBinder {
+ void bind(PreparedStatement ps, P value) throws SQLException;
+ }
+
+ public static class DataAccessException extends RuntimeException {
+ public DataAccessException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ }
+
+ public static List query(String sql, RowMapper mapper, Object... params) {
+ try (Connection c = Emulator.getDatabase().getDataSource().getConnection();
+ PreparedStatement ps = c.prepareStatement(sql)) {
+ bindAll(ps, params);
+ try (ResultSet rs = ps.executeQuery()) {
+ List out = new ArrayList<>();
+ while (rs.next()) {
+ out.add(mapper.map(rs));
+ }
+ return out;
+ }
+ } catch (SQLException e) {
+ throw new DataAccessException("query failed: " + sql, e);
+ }
+ }
+
+ public static Optional queryOne(String sql, RowMapper mapper, Object... params) {
+ try (Connection c = Emulator.getDatabase().getDataSource().getConnection();
+ PreparedStatement ps = c.prepareStatement(sql)) {
+ bindAll(ps, params);
+ try (ResultSet rs = ps.executeQuery()) {
+ return rs.next() ? Optional.ofNullable(mapper.map(rs)) : Optional.empty();
+ }
+ } catch (SQLException e) {
+ throw new DataAccessException("queryOne failed: " + sql, e);
+ }
+ }
+
+ public static void forEach(String sql, RowConsumer consumer, Object... params) {
+ try (Connection c = Emulator.getDatabase().getDataSource().getConnection();
+ PreparedStatement ps = c.prepareStatement(sql)) {
+ bindAll(ps, params);
+ try (ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ consumer.accept(rs);
+ }
+ }
+ } catch (SQLException e) {
+ throw new DataAccessException("forEach failed: " + sql, e);
+ }
+ }
+
+ public static int update(String sql, Object... params) {
+ try (Connection c = Emulator.getDatabase().getDataSource().getConnection();
+ PreparedStatement ps = c.prepareStatement(sql)) {
+ bindAll(ps, params);
+ return ps.executeUpdate();
+ } catch (SQLException e) {
+ throw new DataAccessException("update failed: " + sql, e);
+ }
+ }
+
+ public static int[] batchUpdate(String sql, Collection extends P> items, ParameterBinder
binder) {
+ try (Connection c = Emulator.getDatabase().getDataSource().getConnection();
+ PreparedStatement ps = c.prepareStatement(sql)) {
+ for (P item : items) {
+ binder.bind(ps, item);
+ ps.addBatch();
+ }
+ return ps.executeBatch();
+ } catch (SQLException e) {
+ throw new DataAccessException("batchUpdate failed: " + sql, e);
+ }
+ }
+
+ private static void bindAll(PreparedStatement ps, Object[] params) throws SQLException {
+ if (params == null) {
+ return;
+ }
+ for (int i = 0; i < params.length; i++) {
+ ps.setObject(i + 1, params[i]);
+ }
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java
index 7e5ecdb8..36712b0e 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java
@@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.achievements;
import com.eu.habbo.Emulator;
+import com.eu.habbo.database.SqlQueries;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboBadge;
@@ -49,16 +50,12 @@ public class AchievementManager {
if (habbo != null) {
progressAchievement(habbo, achievement, amount);
} else {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
- PreparedStatement statement = connection.prepareStatement("" +
- "INSERT INTO users_achievements_queue (user_id, achievement_id, amount) VALUES (?, ?, ?) " +
- "ON DUPLICATE KEY UPDATE amount = amount + ?")) {
- statement.setInt(1, habboId);
- statement.setInt(2, achievement.id);
- statement.setInt(3, amount);
- statement.setInt(4, amount);
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update(
+ "INSERT INTO users_achievements_queue (user_id, achievement_id, amount) VALUES (?, ?, ?) "
+ + "ON DUPLICATE KEY UPDATE amount = amount + ?",
+ habboId, achievement.id, amount, amount);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
@@ -203,48 +200,41 @@ public class AchievementManager {
}
public static void createUserEntry(Habbo habbo, Achievement achievement) {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_achievements (user_id, achievement_name, progress) VALUES (?, ?, ?)")) {
- statement.setInt(1, habbo.getHabboInfo().getId());
- statement.setString(2, achievement.name);
- statement.setInt(3, 1);
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update(
+ "INSERT INTO users_achievements (user_id, achievement_name, progress) VALUES (?, ?, ?)",
+ habbo.getHabboInfo().getId(), achievement.name, 1);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
public static void saveAchievements(Habbo habbo) {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_achievements SET progress = ? WHERE achievement_name = ? AND user_id = ? LIMIT 1")) {
- statement.setInt(3, habbo.getHabboInfo().getId());
- for (Map.Entry map : habbo.getHabboStats().getAchievementProgress().entrySet()) {
- statement.setInt(1, map.getValue());
- statement.setString(2, map.getKey().name);
- statement.addBatch();
- }
- statement.executeBatch();
- } catch (SQLException e) {
+ int userId = habbo.getHabboInfo().getId();
+ try {
+ SqlQueries.batchUpdate(
+ "UPDATE users_achievements SET progress = ? WHERE achievement_name = ? AND user_id = ? LIMIT 1",
+ habbo.getHabboStats().getAchievementProgress().entrySet(),
+ (ps, entry) -> {
+ ps.setInt(1, entry.getValue());
+ ps.setString(2, entry.getKey().name);
+ ps.setInt(3, userId);
+ });
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
public static int getAchievementProgressForHabbo(int userId, Achievement achievement) {
- if (achievement == null) {
+ try {
+ return SqlQueries.queryOne(
+ "SELECT progress FROM users_achievements WHERE user_id = ? AND achievement_name = ? LIMIT 1",
+ rs -> rs.getInt("progress"),
+ userId, achievement.name).orElse(0);
+ } catch (SqlQueries.DataAccessException e) {
+ LOGGER.error("Caught SQL exception", e);
return 0;
}
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT progress FROM users_achievements WHERE user_id = ? AND achievement_name = ? LIMIT 1")) {
- statement.setInt(1, userId);
- statement.setString(2, achievement.name);
- try (ResultSet set = statement.executeQuery()) {
- if (set.next()) {
- return set.getInt("progress");
- }
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
-
- return 0;
}
public void reload() {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java
index 1336f88f..99c238c3 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/campaign/calendar/CalendarManager.java
@@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.campaign.calendar;
import com.eu.habbo.Emulator;
+import com.eu.habbo.database.SqlQueries;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.outgoing.events.calendar.AdventCalendarProductComposer;
import com.eu.habbo.plugin.events.users.calendar.UserClaimRewardEvent;
@@ -33,27 +34,27 @@ public class CalendarManager {
public boolean reload() {
this.dispose();
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM calendar_campaigns WHERE enabled = 1")) {
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- calendarCampaigns.put(set.getInt("id"), new CalendarCampaign(set));
- }
- }
- } catch (SQLException e) {
+ try {
+ SqlQueries.query(
+ "SELECT * FROM calendar_campaigns WHERE enabled = 1",
+ CalendarCampaign::new)
+ .forEach(c -> calendarCampaigns.put(c.getId(), c));
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
return false;
}
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM calendar_rewards")) {
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- CalendarCampaign campaign = calendarCampaigns.get(set.getInt("campaign_id"));
- if(campaign != null){
- campaign.addReward(new CalendarRewardObject(set));
- }
- }
- }
- } catch (SQLException e) {
+ try {
+ SqlQueries.query(
+ "SELECT * FROM calendar_rewards",
+ rs -> Map.entry(rs.getInt("campaign_id"), new CalendarRewardObject(rs)))
+ .forEach(entry -> {
+ CalendarCampaign campaign = calendarCampaigns.get(entry.getKey());
+ if (campaign != null) {
+ campaign.addReward(entry.getValue());
+ }
+ });
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
return false;
}
@@ -94,14 +95,12 @@ public class CalendarManager {
public boolean deleteCampaign(CalendarCampaign campaign) {
calendarCampaigns.remove(campaign.getId());
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM calendar_campaigns WHERE id = ? LIMIT 1")) {
- statement.setInt(1, campaign.getId());
- return statement.execute();
- } catch (SQLException e) {
+ try {
+ return SqlQueries.update("DELETE FROM calendar_campaigns WHERE id = ? LIMIT 1", campaign.getId()) > 0;
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
+ return false;
}
-
- return false;
}
public CalendarCampaign getCalendarCampaign(String campaignName) {
@@ -136,14 +135,15 @@ public class CalendarManager {
habbo.getHabboStats().calendarRewardsClaimed.add(new CalendarRewardClaimed(habbo.getHabboInfo().getId(), campaign.getId(), day, object.getId(), new Timestamp(System.currentTimeMillis())));
habbo.getClient().sendResponse(new AdventCalendarProductComposer(true, object, habbo));
object.give(habbo);
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO calendar_rewards_claimed (user_id, campaign_id, day, reward_id, timestamp) VALUES (?, ?, ?, ?, ?)")) {
- statement.setInt(1, habbo.getHabboInfo().getId());
- statement.setInt(2, campaign.getId());
- statement.setInt(3, day);
- statement.setInt(4, object.getId());
- statement.setInt(5, Emulator.getIntUnixTimestamp());
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update(
+ "INSERT INTO calendar_rewards_claimed (user_id, campaign_id, day, reward_id, timestamp) VALUES (?, ?, ?, ?, ?)",
+ habbo.getHabboInfo().getId(),
+ campaign.getId(),
+ day,
+ object.getId(),
+ Emulator.getIntUnixTimestamp());
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java
index 9f937c66..ccb9b559 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java
@@ -831,36 +831,17 @@ public class CatalogManager {
public CatalogPage createCatalogPage(String caption, String captionSave, int roomId, int icon, CatalogPageLayouts layout, int minRank, int parentId, CatalogPageType pageType, CatalogPageType catalogMode) {
CatalogPage catalogPage = null;
- boolean buildersClubPage = (pageType == CatalogPageType.BUILDER);
- String insertQuery = buildersClubPage
- ? "INSERT INTO catalog_pages_bc (parent_id, caption, page_layout, icon_color, icon_image, order_num, visible, enabled) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
- : "INSERT INTO catalog_pages (parent_id, caption, caption_save, icon_image, visible, enabled, min_rank, page_layout, room_id, catalog_mode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
- String selectQuery = buildersClubPage
- ? "SELECT id, parent_id, caption, caption AS caption_save, page_layout, icon_color, icon_image, 1 AS min_rank, order_num, visible, enabled, '0' AS club_only, 'BUILDERS_CLUB' AS catalog_mode, page_headline, page_teaser, page_special, page_text1, page_text2, page_text_details, page_text_teaser, '' AS includes FROM catalog_pages_bc WHERE id = ?"
- : "SELECT * FROM catalog_pages WHERE id = ?";
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
- PreparedStatement statement = connection.prepareStatement(insertQuery, 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);
-
- if (buildersClubPage) {
- statement.setString(3, layout.name());
- statement.setInt(4, 1);
- statement.setInt(5, icon);
- statement.setInt(6, 1);
- statement.setString(7, "1");
- statement.setString(8, "1");
- } else {
- statement.setString(3, captionSave);
- statement.setInt(4, icon);
- statement.setString(5, "1");
- statement.setString(6, "1");
- statement.setInt(7, minRank);
- statement.setString(8, layout.name());
- statement.setInt(9, roomId);
- statement.setString(10, catalogMode.name());
- }
+ statement.setString(3, captionSave);
+ statement.setInt(4, icon);
+ statement.setString(5, "1");
+ statement.setString(6, "1");
+ 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()) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPage.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPage.java
index 2db319e1..0f136688 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPage.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPage.java
@@ -74,8 +74,9 @@ public abstract class CatalogPage implements Comparable, 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) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java
index 1328ed19..8abf0b25 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java
@@ -36,7 +36,8 @@ public class BadgeCommand extends Command {
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(params[1]);
if (habbo != null) {
- if (habbo.addBadge(params[2])) {
+ String senderName = gameClient.getHabbo().getHabboInfo().getUsername();
+ if (habbo.addBadge(params[2], senderName)) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_badge.given").replace("%user%", params[1]).replace("%badge%", params[2]), RoomChatMessageBubbles.ALERT);
} else {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_badge.already_owned").replace("%user%", params[1]).replace("%badge%", params[2]), RoomChatMessageBubbles.ALERT);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java
index b4a3ca78..c2a244cc 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java
@@ -84,7 +84,7 @@ public class UserInfoCommand extends Command {
if (onlineHabbo != null) {
message.append("\r" + "Other accounts (");
- ArrayList users = Emulator.getGameEnvironment().getHabboManager().getCloneAccounts(onlineHabbo, 10);
+ List users = Emulator.getGameEnvironment().getHabboManager().getCloneAccounts(onlineHabbo, 10);
users.sort(new Comparator() {
@Override
public int compare(HabboInfo o1, HabboInfo o2) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
index 0fc8a660..9280c25d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
@@ -683,7 +683,7 @@ public class ItemManager {
statement.execute();
try (ResultSet set = statement.getGeneratedKeys()) {
- try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO items_presents VALUES (?, ?)")) {
+ try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO items_presents (item_id, base_item_reward) VALUES (?, ?)")) {
while (set.next() && item == null) {
preparedStatement.setInt(1, set.getInt(1));
preparedStatement.setInt(2, Integer.parseInt(itemId));
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
index 1e96dfc3..01eae2ad 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
@@ -177,6 +177,10 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
index a12c1874..4fb60898 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
@@ -164,6 +164,10 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
this.all = (params.length > 0) && (params[0] == 1);
this.furniSource = (params.length > 1) ? params[1] : ((params.length > 0 && params[0] > 1) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER);
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
index 0b91d791..02d2a0c9 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
@@ -240,6 +240,10 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
this.quantifier = (params.length > 2) ? this.normalizeQuantifier(params[2]) : QUANTIFIER_ALL;
}
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
return false;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHasAltitude.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHasAltitude.java
index 155da036..43a71b8f 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHasAltitude.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHasAltitude.java
@@ -171,6 +171,10 @@ public class WiredConditionHasAltitude extends InteractionWiredCondition {
return false;
}
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
index c4540b26..41f72077 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
@@ -177,6 +177,10 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
index 3aec0268..a7d85525 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
@@ -163,6 +163,10 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
this.all = (params.length > 0) && (params[0] == 1);
this.furniSource = (params.length > 1) ? params[1] : ((params.length > 0 && params[0] > 1) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER);
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
index bcc3fa5c..82054911 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
@@ -186,6 +186,10 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER;
this.quantifier = (params.length > 2) ? this.normalizeQuantifier(params[2]) : QUANTIFIER_ALL;
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
index 582a8f19..cb7d6d22 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
@@ -133,6 +133,10 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
List newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
index bb345e12..0ccb96b6 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
@@ -85,6 +85,10 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
List newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
index 611b06d1..58756370 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
@@ -290,6 +290,10 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
THashMap newItems = new THashMap<>();
for (int i = 0; i < itemsCount; i++) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
index 63d01717..ce14ea24 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
@@ -263,6 +263,10 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
List newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
index ecdc90a7..291fc053 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
@@ -59,6 +59,11 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
this.furniSource = settings.getIntParams()[2];
int count = settings.getFurniIds().length;
+
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
for (int i = 0; i < count; i++) {
this.items.add(room.getHabboItem(settings.getFurniIds()[i]));
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
index be02d463..cde1e962 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
@@ -415,6 +415,10 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
List newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
index 26bbe3ab..52bbe142 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
@@ -261,6 +261,10 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
int count = settings.getFurniIds().length;
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count", 5)) return false;
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
for (int i = 0; i < count; i++) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
index 591880ac..92c60e46 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
@@ -7,16 +7,11 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
import com.eu.habbo.habbohotel.pets.RideablePet;
-import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.rooms.RoomTile;
-import com.eu.habbo.habbohotel.rooms.RoomTileState;
-import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
-import com.eu.habbo.habbohotel.rooms.RoomUnitType;
+import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo;
-import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
+import com.eu.habbo.habbohotel.wired.core.WiredContext;
import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
import com.eu.habbo.messages.ServerMessage;
@@ -189,6 +184,10 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
List newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
index 5c4e4489..6aa3a078 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
@@ -169,6 +169,10 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
List newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
for (int i = 0; i < itemsCount; i++) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
index 8ba458c2..32ba5870 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
@@ -153,6 +153,10 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
List newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
index 0adf1de5..2dda07c8 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
@@ -101,6 +101,10 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (itemsCount > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
List newItems = new ArrayList<>();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectUserFurniBase.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectUserFurniBase.java
index 9f8df66b..359e463b 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectUserFurniBase.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectUserFurniBase.java
@@ -275,6 +275,10 @@ public abstract class WiredEffectUserFurniBase extends InteractionWiredEffect {
throw new WiredSaveException("Too many furni selected");
}
+ if (settings.getFurniIds().length > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
throw new WiredSaveException("Room not found");
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectUserToFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectUserToFurni.java
index 69960024..12b65a63 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectUserToFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectUserToFurni.java
@@ -199,6 +199,10 @@ public class WiredEffectUserToFurni extends WiredEffectUserFurniBase {
throw new WiredSaveException("Too many furni selected");
}
+ if (settings.getFurniIds().length > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
throw new WiredSaveException("Room not found");
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/selector/WiredEffectFurniOnFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/selector/WiredEffectFurniOnFurni.java
index 0e3c9e01..2b70e9b9 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/selector/WiredEffectFurniOnFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/selector/WiredEffectFurniOnFurni.java
@@ -92,6 +92,10 @@ public class WiredEffectFurniOnFurni extends InteractionWiredEffect {
return false;
}
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/selector/WiredEffectUsersOnFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/selector/WiredEffectUsersOnFurni.java
index 833d10a4..149ae0cb 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/selector/WiredEffectUsersOnFurni.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/selector/WiredEffectUsersOnFurni.java
@@ -79,6 +79,10 @@ public class WiredEffectUsersOnFurni extends InteractionWiredEffect {
return false;
}
+ if (count > 0 && this.furniSource == WiredSourceUtil.SOURCE_TRIGGER) {
+ this.furniSource = WiredSourceUtil.SOURCE_SELECTED;
+ }
+
this.items.clear();
if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) {
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerReceiveSignal.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerReceiveSignal.java
index 391293ba..0a860b2a 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerReceiveSignal.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerReceiveSignal.java
@@ -31,7 +31,7 @@ public class WiredTriggerReceiveSignal extends InteractionWiredTrigger {
private static final long ACTIVATION_PULSE_MS = 300L;
private static final String ANTENNA_INTERACTION = "antenna";
- private static final String REQUIRE_ANTENNA_ERROR = "Puoi selezionare solo furni antenna.";
+ private static final String REQUIRE_ANTENNA_ERROR = "You can only select antenna furni.";
private int channel = 0; // signal channel (0-based)
private THashSet items;
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/messenger/Message.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/messenger/Message.java
index a081bfc5..727729b6 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/messenger/Message.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/messenger/Message.java
@@ -1,15 +1,14 @@
package com.eu.habbo.habbohotel.messenger;
import com.eu.habbo.Emulator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import com.eu.habbo.core.DatabaseLoggable;
-import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
-public class Message implements Runnable {
- private static final Logger LOGGER = LoggerFactory.getLogger(Message.class);
+public class Message implements Runnable, DatabaseLoggable {
+
+ private static final String QUERY = "INSERT INTO chatlogs_private (user_from_id, user_to_id, message, timestamp) VALUES (?, ?, ?, ?)";
private final int fromId;
private final int toId;
@@ -26,20 +25,25 @@ public class Message implements Runnable {
@Override
public void run() {
- //TODO Turn into scheduler
if (Messenger.SAVE_PRIVATE_CHATS) {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO chatlogs_private (user_from_id, user_to_id, message, timestamp) VALUES (?, ?, ?, ?)")) {
- statement.setInt(1, this.fromId);
- statement.setInt(2, this.toId);
- statement.setString(3, this.message);
- statement.setInt(4, this.timestamp);
- statement.execute();
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
+ Emulator.getDatabaseLogger().store(this);
}
}
+ @Override
+ public String getQuery() {
+ return QUERY;
+ }
+
+ @Override
+ public void log(PreparedStatement statement) throws SQLException {
+ statement.setInt(1, this.fromId);
+ statement.setInt(2, this.toId);
+ statement.setString(3, this.message);
+ statement.setInt(4, this.timestamp);
+ statement.addBatch();
+ }
+
public int getToId() {
return this.toId;
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
index 77ee4857..bec25f7d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
@@ -190,11 +190,35 @@ public class Room implements Comparable, ISerialize, Runnable {
private volatile boolean muted;
private RoomSpecialTypes roomSpecialTypes;
private TraxManager traxManager;
- private final Object wiredSettingsLock = new Object();
- private volatile boolean wiredSettingsLoaded;
- private int wiredInspectMask = WIRED_ACCESS_DEFAULT_INSPECT_MASK;
- private int wiredModifyMask = WIRED_ACCESS_DEFAULT_MODIFY_MASK;
-
+
+ // YouTube room broadcast state: tracks the current video being broadcast
+ // by the room owner, the owner's playlist, and which users have the player open.
+ private boolean youtubeEnabled = false;
+ private String youtubeCurrentVideo = "";
+ private String youtubeSenderName = "";
+ private final java.util.List youtubePlaylist = new java.util.concurrent.CopyOnWriteArrayList<>();
+ private final java.util.Set youtubeWatchers = java.util.concurrent.ConcurrentHashMap.newKeySet();
+
+ public boolean isYoutubeEnabled() { return this.youtubeEnabled; }
+ public void setYoutubeEnabled(boolean enabled) { this.youtubeEnabled = enabled; }
+ public String getYoutubeCurrentVideo() { return this.youtubeCurrentVideo; }
+ public String getYoutubeSenderName() { return this.youtubeSenderName; }
+ public java.util.List getYoutubePlaylist() { return this.youtubePlaylist; }
+ public java.util.Set getYoutubeWatchers() { return this.youtubeWatchers; }
+
+ public void setYoutubeVideo(String videoId, String senderName, java.util.List playlist) {
+ this.youtubeCurrentVideo = videoId;
+ this.youtubeSenderName = senderName;
+ this.youtubePlaylist.clear();
+ if (playlist != null) this.youtubePlaylist.addAll(playlist);
+ }
+
+ public void clearYoutubeVideo() {
+ this.youtubeCurrentVideo = "";
+ this.youtubeSenderName = "";
+ this.youtubePlaylist.clear();
+ }
+
public final THashMap cache;
public Room(ResultSet set) throws SQLException {
@@ -222,6 +246,7 @@ public class Room implements Comparable, ISerialize, Runnable {
this.allowPetsEat = set.getBoolean("allow_other_pets_eat");
this.allowWalkthrough = set.getBoolean("allow_walkthrough");
this.hideWall = set.getBoolean("allow_hidewall");
+ try { this.youtubeEnabled = set.getBoolean("youtube_enabled"); } catch (Exception e) { this.youtubeEnabled = false; }
this.chatMode = set.getInt("chat_mode");
this.chatWeight = set.getInt("chat_weight");
this.chatSpeed = set.getInt("chat_speed");
@@ -1151,7 +1176,7 @@ public class Room implements Comparable, ISerialize, Runnable {
if (this.needsUpdate) {
try (Connection connection = Emulator.getDatabase().getDataSource()
.getConnection(); PreparedStatement statement = connection.prepareStatement(
- "UPDATE rooms SET name = ?, description = ?, password = ?, state = ?, users_max = ?, category = ?, score = ?, paper_floor = ?, paper_wall = ?, paper_landscape = ?, thickness_wall = ?, wall_height = ?, thickness_floor = ?, moodlight_data = ?, tags = ?, allow_other_pets = ?, allow_other_pets_eat = ?, allow_walkthrough = ?, allow_hidewall = ?, chat_mode = ?, chat_weight = ?, chat_speed = ?, chat_hearing_distance = ?, chat_protection =?, who_can_mute = ?, who_can_kick = ?, who_can_ban = ?, poll_id = ?, guild_id = ?, roller_speed = ?, override_model = ?, is_staff_picked = ?, promoted = ?, trade_mode = ?, move_diagonally = ?, owner_id = ?, owner_name = ?, jukebox_active = ?, hidewired = ?, allow_underpass = ?, builders_club_trial_locked = ?, builders_club_original_state = ? WHERE id = ?")) {
+ "UPDATE rooms SET name = ?, description = ?, password = ?, state = ?, users_max = ?, category = ?, score = ?, paper_floor = ?, paper_wall = ?, paper_landscape = ?, thickness_wall = ?, wall_height = ?, thickness_floor = ?, moodlight_data = ?, tags = ?, allow_other_pets = ?, allow_other_pets_eat = ?, allow_walkthrough = ?, allow_hidewall = ?, chat_mode = ?, chat_weight = ?, chat_speed = ?, chat_hearing_distance = ?, chat_protection =?, who_can_mute = ?, who_can_kick = ?, who_can_ban = ?, poll_id = ?, guild_id = ?, roller_speed = ?, override_model = ?, is_staff_picked = ?, promoted = ?, trade_mode = ?, move_diagonally = ?, owner_id = ?, owner_name = ?, jukebox_active = ?, hidewired = ?, allow_underpass = ?, youtube_enabled = ? WHERE id = ?")) {
statement.setString(1, this.name);
statement.setString(2, this.description);
statement.setString(3, this.password);
@@ -1201,9 +1226,8 @@ public class Room implements Comparable, ISerialize, Runnable {
statement.setString(38, this.jukeboxActive ? "1" : "0");
statement.setString(39, this.hideWired ? "1" : "0");
statement.setString(40, this.allowUnderpass ? "1" : "0");
- statement.setString(41, this.buildersClubTrialLocked ? "1" : "0");
- statement.setString(42, (this.buildersClubOriginalState != null ? this.buildersClubOriginalState : RoomState.OPEN).name().toLowerCase());
- statement.setInt(43, this.id);
+ statement.setString(41, this.youtubeEnabled ? "1" : "0");
+ statement.setInt(42, this.id);
statement.executeUpdate();
this.needsUpdate = false;
} catch (SQLException e) {
@@ -1865,13 +1889,31 @@ public class Room implements Comparable, ISerialize, Runnable {
}
public void removeHabbo(Habbo habbo) {
+ this.cleanupYoutubeWatcher(habbo);
this.unitManager.removeHabbo(habbo);
}
public void removeHabbo(Habbo habbo, boolean sendRemovePacket) {
+ this.cleanupYoutubeWatcher(habbo);
this.unitManager.removeHabbo(habbo, sendRemovePacket);
}
+ private void cleanupYoutubeWatcher(Habbo habbo) {
+ if (habbo == null) return;
+ int userId = habbo.getHabboInfo().getId();
+
+ // If the broadcast sender leaves, stop the broadcast for everyone
+ if (!this.youtubeCurrentVideo.isEmpty()
+ && habbo.getHabboInfo().getUsername().equals(this.youtubeSenderName)) {
+ this.clearYoutubeVideo();
+ this.sendComposer(new com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomBroadcastComposer("", "", java.util.Collections.emptyList()).compose());
+ }
+
+ if (this.youtubeWatchers.remove(userId)) {
+ this.sendComposer(new com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomWatchersComposer(this.youtubeWatchers).compose());
+ }
+ }
+
public void addBot(Bot bot) {
this.unitManager.addBot(bot);
}
@@ -2337,7 +2379,7 @@ public class Room implements Comparable, ISerialize, Runnable {
this.rightsManager.refreshRightsForHabbo(habbo);
}
- public THashMap getUsersWithRights() {
+ public Map getUsersWithRights() {
return this.rightsManager.getUsersWithRights();
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java
index a22414e9..a9699d0f 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java
@@ -498,7 +498,7 @@ public class RoomManager {
h.getClient().sendResponse(new RoomScoreComposer(room.getScore(), !this.hasVotedForRoom(h, room)));
}
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_votes VALUES (?, ?)")) {
+ try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_votes (user_id, room_id) VALUES (?, ?)")) {
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(2, room.getId());
statement.execute();
@@ -789,6 +789,15 @@ public class RoomManager {
habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
}
+ if (habbo.getRoomUnit().getCurrentLocation() == null) {
+ LOGGER.warn("Failed to resolve a valid door tile for room {} ({}) while {} was entering; sending user back to hotel view",
+ room.getId(), room.getName(), habbo.getHabboInfo().getUsername());
+ habbo.getHabboInfo().setLoadingRoom(0);
+ habbo.getHabboInfo().setCurrentRoom(null);
+ habbo.getClient().sendResponse(new HotelViewComposer());
+ return;
+ }
+
habbo.getRoomUnit().setPathFinderRoom(room);
habbo.getRoomUnit().resetIdleTimer();
@@ -797,7 +806,6 @@ public class RoomManager {
BuildersClubRoomSupport.sendCurrentRoomPlacementStatus(room);
room.getUserVariableManager().restorePermanentAssignments(habbo);
- // Pre-send own wearing badges so the client cache is populated before the user clicks themselves
habbo.getClient().sendResponse(new UserBadgesComposer(habbo.getInventory().getBadgesComponent().getWearingBadges(), habbo.getHabboInfo().getId()));
List habbos = new ArrayList<>();
@@ -998,6 +1006,20 @@ public class RoomManager {
}
}
+ habbo.getClient().sendResponse(new com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomSettingsComposer(
+ room.isYoutubeEnabled()).compose());
+
+ if (!room.getYoutubeCurrentVideo().isEmpty()) {
+ habbo.getClient().sendResponse(new com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomBroadcastComposer(
+ room.getYoutubeCurrentVideo(),
+ room.getYoutubeSenderName(),
+ room.getYoutubePlaylist()).compose());
+ }
+ if (!room.getYoutubeWatchers().isEmpty()) {
+ habbo.getClient().sendResponse(new com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomWatchersComposer(
+ room.getYoutubeWatchers()).compose());
+ }
+
WiredManager.triggerUserEntersRoom(room, habbo.getRoomUnit());
room.habboEntered(habbo);
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java
index b50edef8..c9eb266d 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java
@@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
+import com.eu.habbo.database.SqlQueries;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildMember;
import com.eu.habbo.habbohotel.guilds.GuildRank;
@@ -16,7 +17,6 @@ import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.plugin.events.users.UserRightsTakenEvent;
import gnu.trove.list.array.TIntArrayList;
-import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import org.slf4j.Logger;
@@ -26,6 +26,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
* Manages room rights, bans, and mutes.
@@ -156,13 +159,11 @@ public class RoomRightsManager {
}
if (this.rights.add(userId)) {
- try (Connection connection = Emulator.getDatabase().getDataSource()
- .getConnection(); PreparedStatement statement = connection.prepareStatement(
- "INSERT INTO room_rights VALUES (?, ?)")) {
- statement.setInt(1, this.room.getId());
- statement.setInt(2, userId);
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update(
+ "INSERT INTO room_rights (room_id, user_id) VALUES (?, ?)",
+ this.room.getId(), userId);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
@@ -203,13 +204,11 @@ public class RoomRightsManager {
this.room.sendComposer(new RoomRemoveRightsListComposer(this.room, userId).compose());
if (this.rights.remove(userId)) {
- try (Connection connection = Emulator.getDatabase().getDataSource()
- .getConnection(); PreparedStatement statement = connection.prepareStatement(
- "DELETE FROM room_rights WHERE room_id = ? AND user_id = ?")) {
- statement.setInt(1, this.room.getId());
- statement.setInt(2, userId);
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update(
+ "DELETE FROM room_rights WHERE room_id = ? AND user_id = ?",
+ this.room.getId(), userId);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
@@ -232,12 +231,9 @@ public class RoomRightsManager {
this.rights.clear();
- try (Connection connection = Emulator.getDatabase().getDataSource()
- .getConnection(); PreparedStatement statement = connection.prepareStatement(
- "DELETE FROM room_rights WHERE room_id = ?")) {
- statement.setInt(1, this.room.getId());
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update("DELETE FROM room_rights WHERE room_id = ?", this.room.getId());
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
@@ -295,25 +291,22 @@ public class RoomRightsManager {
/**
* Gets all users with rights in the room.
*/
- public THashMap getUsersWithRights() {
- THashMap rightsMap = new THashMap<>();
-
- if (!this.rights.isEmpty()) {
- try (Connection connection = Emulator.getDatabase().getDataSource()
- .getConnection(); PreparedStatement statement = connection.prepareStatement(
- "SELECT users.username AS username, users.id as user_id FROM room_rights INNER JOIN users ON room_rights.user_id = users.id WHERE room_id = ?")) {
- statement.setInt(1, this.room.getId());
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- rightsMap.put(set.getInt("user_id"), set.getString("username"));
- }
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
+ public Map getUsersWithRights() {
+ if (this.rights.isEmpty()) {
+ return Collections.emptyMap();
}
- return rightsMap;
+ try {
+ return SqlQueries.query(
+ "SELECT users.username AS username, users.id as user_id FROM room_rights INNER JOIN users ON room_rights.user_id = users.id WHERE room_id = ?",
+ rs -> Map.entry(rs.getInt("user_id"), rs.getString("username")),
+ this.room.getId())
+ .stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b));
+ } catch (SqlQueries.DataAccessException e) {
+ LOGGER.error("Caught SQL exception", e);
+ return Collections.emptyMap();
+ }
}
/**
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java
index 983ef85b..7b9326e0 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java
@@ -411,11 +411,11 @@ public class RoomUnit {
}
public short getX() {
- return this.currentLocation.x;
+ return this.currentLocation == null ? 0 : this.currentLocation.x;
}
public short getY() {
- return this.currentLocation.y;
+ return this.currentLocation == null ? 0 : this.currentLocation.y;
}
public double getZ() {
@@ -598,6 +598,7 @@ public class RoomUnit {
}
public boolean isAtGoal() {
+ if (this.currentLocation == null) return true;
return this.currentLocation.equals(this.goalLocation);
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java
index ce3537c5..e7707611 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java
@@ -12,11 +12,11 @@ import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.WiredUserActionType;
import com.eu.habbo.habbohotel.wired.core.WiredFreezeUtil;
import com.eu.habbo.habbohotel.wired.core.WiredManager;
import com.eu.habbo.habbohotel.wired.core.WiredMoveCarryHelper;
import com.eu.habbo.habbohotel.wired.core.WiredUserMovementHelper;
-import com.eu.habbo.habbohotel.wired.WiredUserActionType;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericErrorMessagesComposer;
import com.eu.habbo.messages.outgoing.inventory.AddPetComposer;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer;
@@ -1264,9 +1264,14 @@ public class RoomUnitManager {
if (habbo == null || habbo.getRoomUnit() == null) {
return;
}
+
+ boolean wasIdle = habbo.getRoomUnit().isIdle();
habbo.getRoomUnit().resetIdleTimer();
- this.room.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose());
- WiredManager.triggerUserUnidles(this.room, habbo.getRoomUnit());
+
+ if (wasIdle) {
+ this.room.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose());
+ WiredManager.triggerUserUnidles(this.room, habbo.getRoomUnit());
+ }
}
/**
@@ -1448,11 +1453,6 @@ public class RoomUnitManager {
}
}
- // ==================== DISPOSAL ====================
-
- /**
- * Disposes the unit manager.
- */
public void dispose() {
this.currentHabbos.clear();
this.currentBots.clear();
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java
index 399fc1c0..61f8075e 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java
@@ -273,7 +273,7 @@ public class Habbo implements Runnable {
return;
this.getHabboInfo().addPixels(event.points);
- if (this.client != null) this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo()));
+ if (this.client != null) this.client.sendResponse(new UserCurrencyComposer(this));
}
@@ -292,7 +292,7 @@ public class Habbo implements Runnable {
this.getHabboInfo().addCurrencyAmount(event.type, event.points);
if (this.client != null)
- this.client.sendResponse(new UserPointsComposer(this.client.getHabbo().getHabboInfo().getCurrencyAmount(type), event.points, event.type));
+ this.client.sendResponse(new UserPointsComposer(this.getHabboInfo().getCurrencyAmount(type), event.points, event.type));
}
@@ -303,7 +303,7 @@ public class Habbo implements Runnable {
public void whisper(String message, RoomChatMessageBubbles bubble) {
if (this.getRoomUnit().isInRoom()) {
- this.client.sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(message, this.client.getHabbo().getRoomUnit(), bubble)));
+ this.client.sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(message, this.getRoomUnit(), bubble)));
}
}
@@ -315,7 +315,7 @@ public class Habbo implements Runnable {
public void talk(String message, RoomChatMessageBubbles bubble) {
if (this.getRoomUnit().isInRoom()) {
- this.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserTalkComposer(new RoomChatMessage(message, this.client.getHabbo().getRoomUnit(), bubble)).compose());
+ this.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserTalkComposer(new RoomChatMessage(message, this.getRoomUnit(), bubble)).compose());
}
}
@@ -327,7 +327,7 @@ public class Habbo implements Runnable {
public void shout(String message, RoomChatMessageBubbles bubble) {
if (this.getRoomUnit().isInRoom()) {
- this.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserShoutComposer(new RoomChatMessage(message, this.client.getHabbo().getRoomUnit(), bubble)).compose());
+ this.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserShoutComposer(new RoomChatMessage(message, this.getRoomUnit(), bubble)).compose());
}
}
@@ -408,10 +408,14 @@ public class Habbo implements Runnable {
public boolean addBadge(String code) {
+ return this.addBadge(code, "");
+ }
+
+ public boolean addBadge(String code, String senderName) {
if (!this.habboInventory.getBadgesComponent().hasBadge(code)) {
HabboBadge badge = BadgesComponent.createBadge(code, this);
this.habboInventory.getBadgesComponent().addBadge(badge);
- this.client.sendResponse(new AddUserBadgeComposer(badge));
+ this.client.sendResponse(new AddUserBadgeComposer(badge, senderName));
this.client.sendResponse(new AddHabboItemComposer(badge.getId(), AddHabboItemComposer.AddHabboItemCategory.BADGE));
THashMap keys = new THashMap<>();
@@ -446,7 +450,7 @@ public class Habbo implements Runnable {
this.client.sendResponse(new FloodCounterComposer(remaining));
this.client.sendResponse(new MutedWhisperComposer(remaining));
- Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
+ Room room = this.getHabboInfo().getCurrentRoom();
if (room != null && !isFlood) {
room.sendComposer(new RoomUserIgnoredComposer(this, RoomUserIgnoredComposer.MUTED).compose());
}
@@ -456,7 +460,7 @@ public class Habbo implements Runnable {
public void unMute() {
this.habboStats.unMute();
this.client.sendResponse(new FloodCounterComposer(3));
- Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
+ Room room = this.getHabboInfo().getCurrentRoom();
if (room != null) {
room.sendComposer(new RoomUserIgnoredComposer(this, RoomUserIgnoredComposer.UNIGNORED).compose());
}
@@ -493,18 +497,18 @@ public class Habbo implements Runnable {
public void respect(Habbo target) {
- if (target != null && target != this.client.getHabbo()) {
+ if (target != null && target != this) {
target.getHabboStats().respectPointsReceived++;
- this.client.getHabbo().getHabboStats().respectPointsGiven++;
- this.client.getHabbo().getHabboStats().respectPointsToGive--;
- this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserRespectComposer(target).compose());
- this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserActionComposer(this.client.getHabbo().getRoomUnit(), RoomUserAction.THUMB_UP).compose());
+ this.getHabboStats().respectPointsGiven++;
+ this.getHabboStats().respectPointsToGive--;
+ this.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserRespectComposer(target).compose());
+ this.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserActionComposer(this.getRoomUnit(), RoomUserAction.THUMB_UP).compose());
- AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectGiven"));
+ AchievementManager.progressAchievement(this, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectGiven"));
AchievementManager.progressAchievement(target, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectEarned"));
- this.client.getHabbo().getHabboInfo().getCurrentRoom().unIdle(this.client.getHabbo());
- this.client.getHabbo().getHabboInfo().getCurrentRoom().dance(this.client.getHabbo().getRoomUnit(), DanceType.NONE);
+ this.getHabboInfo().getCurrentRoom().unIdle(this);
+ this.getHabboInfo().getCurrentRoom().dance(this.getRoomUnit(), DanceType.NONE);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java
index 5c21f4ca..e53aee11 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java
@@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users;
import com.eu.habbo.Emulator;
+import com.eu.habbo.database.SqlQueries;
import com.eu.habbo.habbohotel.catalog.CatalogItem;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.GamePlayer;
@@ -14,7 +15,6 @@ import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import gnu.trove.map.hash.TIntIntHashMap;
-import gnu.trove.procedure.TIntIntProcedure;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,53 +104,47 @@ public class HabboInfo implements Runnable {
private void loadCurrencies() {
this.currencies = new TIntIntHashMap();
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users_currency WHERE user_id = ?")) {
- statement.setInt(1, this.id);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- this.currencies.put(set.getInt("type"), set.getInt("amount"));
- }
- }
- } catch (SQLException e) {
+ try {
+ SqlQueries.forEach(
+ "SELECT * FROM users_currency WHERE user_id = ?",
+ rs -> this.currencies.put(rs.getInt("type"), rs.getInt("amount")),
+ this.id);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
private void saveCurrencies() {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_currency (user_id, type, amount) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE amount = ?")) {
- this.currencies.forEachEntry(new TIntIntProcedure() {
- @Override
- public boolean execute(int a, int b) {
- try {
- statement.setInt(1, HabboInfo.this.getId());
- statement.setInt(2, a);
- statement.setInt(3, b);
- statement.setInt(4, b);
- statement.addBatch();
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- return true;
- }
- });
- statement.executeBatch();
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
+ List entries = new ArrayList<>(this.currencies.size());
+ this.currencies.forEachEntry((type, amount) -> {
+ entries.add(new int[]{type, amount});
+ return true;
+ });
+
+ try {
+ SqlQueries.batchUpdate(
+ "INSERT INTO users_currency (user_id, type, amount) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE amount = ?",
+ entries,
+ (ps, e) -> {
+ ps.setInt(1, this.id);
+ ps.setInt(2, e[0]);
+ ps.setInt(3, e[1]);
+ ps.setInt(4, e[1]);
+ });
+ } catch (SqlQueries.DataAccessException ex) {
+ LOGGER.error("Caught SQL exception", ex);
}
}
private void loadSavedSearches() {
- this.savedSearches = new ArrayList<>();
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users_saved_searches WHERE user_id = ?")) {
- statement.setInt(1, this.id);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- this.savedSearches.add(new NavigatorSavedSearch(set.getString("search_code"), set.getString("filter"), set.getInt("id")));
- }
- }
- } catch (SQLException e) {
+ try {
+ this.savedSearches = SqlQueries.query(
+ "SELECT * FROM users_saved_searches WHERE user_id = ?",
+ rs -> new NavigatorSavedSearch(rs.getString("search_code"), rs.getString("filter"), rs.getInt("id")),
+ this.id);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
+ this.savedSearches = new ArrayList<>();
}
}
@@ -182,26 +176,22 @@ public class HabboInfo implements Runnable {
public void deleteSavedSearch(NavigatorSavedSearch search) {
this.savedSearches.remove(search);
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_saved_searches WHERE id = ?")) {
- statement.setInt(1, search.getId());
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update("DELETE FROM users_saved_searches WHERE id = ?", search.getId());
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
private void loadMessengerCategories() {
- this.messengerCategories = new ArrayList<>();
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM messenger_categories WHERE user_id = ?")) {
- statement.setInt(1, this.id);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- this.messengerCategories.add(new MessengerCategory(set.getString("name"), set.getInt("user_id"), set.getInt("id")));
- }
- }
- } catch (SQLException e) {
+ try {
+ this.messengerCategories = SqlQueries.query(
+ "SELECT * FROM messenger_categories WHERE user_id = ?",
+ rs -> new MessengerCategory(rs.getString("name"), rs.getInt("user_id"), rs.getInt("id")),
+ this.id);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
+ this.messengerCategories = new ArrayList<>();
}
}
@@ -232,10 +222,9 @@ public class HabboInfo implements Runnable {
public void deleteMessengerCategory(MessengerCategory category) {
this.messengerCategories.remove(category);
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM messenger_categories WHERE id = ?")) {
- statement.setInt(1, category.getId());
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update("DELETE FROM messenger_categories WHERE id = ?", category.getId());
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
@@ -389,12 +378,10 @@ public class HabboInfo implements Runnable {
public void setPixels(int pixels) {
this.setCurrencyAmount(0, pixels);
- this.run();
}
public void addPixels(int pixels) {
this.addCurrencyAmount(0, pixels);
- this.run();
}
public int getLastOnline() {
@@ -588,25 +575,26 @@ public class HabboInfo implements Runnable {
public void run() {
this.saveCurrencies();
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users SET motto = ?, online = ?, look = ?, gender = ?, credits = ?, last_login = ?, last_online = ?, home_room = ?, ip_current = ?, `rank` = ?, machine_id = ?, username = ?, background_id = ?, background_stand_id = ?, background_overlay_id = ? WHERE id = ?")) {
- statement.setString(1, this.motto);
- statement.setString(2, this.online ? "1" : "0");
- statement.setString(3, this.look);
- statement.setString(4, this.gender.name());
- statement.setInt(5, this.credits);
- statement.setInt(7, this.lastOnline);
- statement.setInt(6, Emulator.getIntUnixTimestamp());
- statement.setInt(8, this.homeRoom);
- statement.setString(9, this.ipLogin);
- statement.setInt(10, this.rank != null ? this.rank.getId() : 1);
- statement.setString(11, this.machineID);
- statement.setString(12, this.username);
- statement.setInt(13, this.InfostandBg);
- statement.setInt(14, this.InfostandStand);
- statement.setInt(15, this.InfostandOverlay);
- statement.setInt(16, this.id);
- statement.executeUpdate();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update(
+ "UPDATE users SET motto = ?, online = ?, look = ?, gender = ?, credits = ?, last_login = ?, last_online = ?, home_room = ?, ip_current = ?, `rank` = ?, machine_id = ?, username = ?, background_id = ?, background_stand_id = ?, background_overlay_id = ? WHERE id = ?",
+ this.motto,
+ this.online ? "1" : "0",
+ this.look,
+ this.gender.name(),
+ this.credits,
+ Emulator.getIntUnixTimestamp(),
+ this.lastOnline,
+ this.homeRoom,
+ this.ipLogin,
+ this.rank != null ? this.rank.getId() : 1,
+ this.machineID,
+ this.username,
+ this.InfostandBg,
+ this.InfostandStand,
+ this.InfostandOverlay,
+ this.id);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java
index 8fc6aeb6..14fd99bf 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java
@@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users;
import com.eu.habbo.Emulator;
+import com.eu.habbo.database.SqlQueries;
import com.eu.habbo.habbohotel.modtool.ModToolBan;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.permissions.Rank;
@@ -22,6 +23,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.AbstractMap;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -47,37 +49,27 @@ public class HabboManager {
}
public static HabboInfo getOfflineHabboInfo(int id) {
- HabboInfo info = null;
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE id = ? LIMIT 1")) {
- statement.setInt(1, id);
- try (ResultSet set = statement.executeQuery()) {
- if (set.next()) {
- info = new HabboInfo(set);
- }
- }
- } catch (SQLException e) {
+ try {
+ return SqlQueries.queryOne(
+ "SELECT * FROM users WHERE id = ? LIMIT 1",
+ HabboInfo::new,
+ id).orElse(null);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
+ return null;
}
-
- return info;
}
public static HabboInfo getOfflineHabboInfo(String username) {
- HabboInfo info = null;
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE username = ? LIMIT 1")) {
- statement.setString(1, username);
-
- try (ResultSet set = statement.executeQuery()) {
- if (set.next()) {
- info = new HabboInfo(set);
- }
- }
- } catch (SQLException e) {
+ try {
+ return SqlQueries.queryOne(
+ "SELECT * FROM users WHERE username = ? LIMIT 1",
+ HabboInfo::new,
+ username).orElse(null);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
+ return null;
}
-
- return info;
}
public void addHabbo(Habbo habbo) {
@@ -195,43 +187,32 @@ public class HabboManager {
LOGGER.info("Habbo Manager -> Disposed!");
}
- public ArrayList getCloneAccounts(Habbo habbo, int limit) {
- ArrayList habboInfo = new ArrayList<>();
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE (ip_register = ? OR ip_current = ?) AND id != ? ORDER BY id DESC LIMIT ?")) {
- statement.setString(1, habbo.getHabboInfo().getIpRegister());
- statement.setString(2, habbo.getHabboInfo().getIpLogin());
- statement.setInt(3, habbo.getHabboInfo().getId());
- statement.setInt(4, limit);
-
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- habboInfo.add(new HabboInfo(set));
- }
- }
- } catch (SQLException e) {
+ public List getCloneAccounts(Habbo habbo, int limit) {
+ try {
+ return SqlQueries.query(
+ "SELECT * FROM users WHERE (ip_register = ? OR ip_current = ?) AND id != ? ORDER BY id DESC LIMIT ?",
+ HabboInfo::new,
+ habbo.getHabboInfo().getIpRegister(),
+ habbo.getHabboInfo().getIpLogin(),
+ habbo.getHabboInfo().getId(),
+ limit);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
+ return new ArrayList<>();
}
-
- return habboInfo;
}
public List> getNameChanges(int userId, int limit) {
- List> nameChanges = new ArrayList<>();
-
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT timestamp, new_name FROM namechange_log WHERE user_id = ? ORDER by timestamp DESC LIMIT ?")) {
- statement.setInt(1, userId);
- statement.setInt(2, limit);
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- nameChanges.add(new AbstractMap.SimpleEntry<>(set.getInt("timestamp"), set.getString("new_name")));
- }
- }
- } catch (SQLException e) {
+ try {
+ return SqlQueries.query(
+ "SELECT timestamp, new_name FROM namechange_log WHERE user_id = ? ORDER by timestamp DESC LIMIT ?",
+ rs -> new AbstractMap.SimpleEntry<>(rs.getInt("timestamp"), rs.getString("new_name")),
+ userId,
+ limit);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
+ return Collections.emptyList();
}
-
- return nameChanges;
}
@@ -277,11 +258,9 @@ public class HabboManager {
habbo.getClient().sendResponse(new RecyclerLogicComposer());
habbo.alert(Emulator.getTexts().getValue("commands.generic.cmd_give_rank.new_rank").replace("id", newRank.getName()));
} else {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users SET `rank` = ? WHERE id = ? LIMIT 1")) {
- statement.setInt(1, rankId);
- statement.setInt(2, userId);
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update("UPDATE users SET `rank` = ? WHERE id = ? LIMIT 1", rankId, userId);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
@@ -294,11 +273,9 @@ public class HabboManager {
if (habbo != null) {
habbo.giveCredits(credits);
} else {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users SET credits = credits + ? WHERE id = ? LIMIT 1")) {
- statement.setInt(1, credits);
- statement.setInt(2, userId);
- statement.execute();
- } catch (SQLException e) {
+ try {
+ SqlQueries.update("UPDATE users SET credits = credits + ? WHERE id = ? LIMIT 1", credits, userId);
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java
index 5ada79ca..8f496d17 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java
@@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.users.inventory;
import com.eu.habbo.Emulator;
+import com.eu.habbo.database.SqlQueries;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInventory;
@@ -9,7 +10,6 @@ import com.eu.habbo.plugin.events.inventory.InventoryItemAddedEvent;
import com.eu.habbo.plugin.events.inventory.InventoryItemRemovedEvent;
import com.eu.habbo.plugin.events.inventory.InventoryItemsAddedEvent;
import gnu.trove.TCollections;
-import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TIntObjectHashMap;
@@ -18,11 +18,9 @@ import gnu.trove.set.hash.THashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.NoSuchElementException;
+import java.util.ArrayList;
+import java.util.List;
public class ItemsComponent {
private static final Logger LOGGER = LoggerFactory.getLogger(ItemsComponent.class);
@@ -39,25 +37,23 @@ public class ItemsComponent {
public static THashMap loadItems(Habbo habbo) {
THashMap itemsList = new THashMap<>();
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT items.* FROM items LEFT JOIN builders_club_items ON builders_club_items.item_id = items.id WHERE items.room_id = ? AND items.user_id = ? AND builders_club_items.item_id IS NULL")) {
- statement.setInt(1, 0);
- statement.setInt(2, habbo.getHabboInfo().getId());
- try (ResultSet set = statement.executeQuery()) {
- while (set.next()) {
- try {
- HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set);
-
- if (item != null) {
- itemsList.put(set.getInt("id"), item);
- } else {
- LOGGER.error("Failed to load HabboItem: {}", set.getInt("id"));
+ try {
+ SqlQueries.forEach(
+ "SELECT * FROM items WHERE room_id = ? AND user_id = ?",
+ rs -> {
+ try {
+ HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(rs);
+ if (item != null) {
+ itemsList.put(rs.getInt("id"), item);
+ } else {
+ LOGGER.error("Failed to load HabboItem: {}", rs.getInt("id"));
+ }
+ } catch (SQLException e) {
+ LOGGER.error("Caught SQL exception", e);
}
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
- }
- }
- } catch (SQLException e) {
+ },
+ 0, habbo.getHabboInfo().getId());
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception", e);
}
@@ -151,70 +147,45 @@ public class ItemsComponent {
public void dispose() {
synchronized (this.items) {
- TIntObjectIterator items = this.items.iterator();
-
- if (items == null) {
- LOGGER.error("Items is NULL!");
- return;
- }
-
if (!this.items.isEmpty()) {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
- try (PreparedStatement updateStmt = connection.prepareStatement(
- "UPDATE items SET user_id = ?, room_id = ?, wall_pos = ?, x = ?, y = ?, z = ?, rot = ?, extra_data = ?, limited_data = ? WHERE id = ?")) {
- try (PreparedStatement deleteStmt = connection.prepareStatement(
- "DELETE FROM items WHERE id = ?")) {
-
- int updateCount = 0;
- int deleteCount = 0;
-
- for (int i = this.items.size(); i-- > 0; ) {
- try {
- items.advance();
- } catch (NoSuchElementException e) {
- break;
- }
-
- HabboItem item = items.value();
- if (item.needsDelete()) {
- deleteStmt.setInt(1, item.getId());
- deleteStmt.addBatch();
- deleteCount++;
- item.needsUpdate(false);
- item.needsDelete(false);
- } else if (item.needsUpdate()) {
- updateStmt.setInt(1, item.getUserId());
- updateStmt.setInt(2, item.getRoomId());
- updateStmt.setString(3, item.getWallPosition());
- updateStmt.setInt(4, item.getX());
- updateStmt.setInt(5, item.getY());
- updateStmt.setDouble(6, item.getZ());
- updateStmt.setInt(7, item.getRotation());
- updateStmt.setString(8, item.getExtradata());
- updateStmt.setString(9, item.getLimitedStack() + ":" + item.getLimitedSells());
- updateStmt.setInt(10, item.getId());
- updateStmt.addBatch();
- updateCount++;
- item.needsUpdate(false);
- }
-
- if (updateCount > 0 && updateCount % 100 == 0) {
- updateStmt.executeBatch();
- }
- if (deleteCount > 0 && deleteCount % 100 == 0) {
- deleteStmt.executeBatch();
- }
- }
-
- if (deleteCount % 100 != 0) {
- deleteStmt.executeBatch();
- }
- if (updateCount % 100 != 0) {
- updateStmt.executeBatch();
- }
- }
+ List updates = new ArrayList<>();
+ List deletes = new ArrayList<>();
+ for (HabboItem item : this.items.valueCollection()) {
+ if (item.needsDelete()) {
+ deletes.add(item);
+ item.needsUpdate(false);
+ item.needsDelete(false);
+ } else if (item.needsUpdate()) {
+ updates.add(item);
+ item.needsUpdate(false);
}
- } catch (SQLException e) {
+ }
+
+ try {
+ if (!deletes.isEmpty()) {
+ SqlQueries.batchUpdate(
+ "DELETE FROM items WHERE id = ?",
+ deletes,
+ (ps, item) -> ps.setInt(1, item.getId()));
+ }
+ if (!updates.isEmpty()) {
+ SqlQueries.batchUpdate(
+ "UPDATE items SET user_id = ?, room_id = ?, wall_pos = ?, x = ?, y = ?, z = ?, rot = ?, extra_data = ?, limited_data = ? WHERE id = ?",
+ updates,
+ (ps, item) -> {
+ ps.setInt(1, item.getUserId());
+ ps.setInt(2, item.getRoomId());
+ ps.setString(3, item.getWallPosition());
+ ps.setInt(4, item.getX());
+ ps.setInt(5, item.getY());
+ ps.setDouble(6, item.getZ());
+ ps.setInt(7, item.getRotation());
+ ps.setString(8, item.getExtradata());
+ ps.setString(9, item.getLimitedStack() + ":" + item.getLimitedSells());
+ ps.setInt(10, item.getId());
+ });
+ }
+ } catch (SqlQueries.DataAccessException e) {
LOGGER.error("Caught SQL exception during batch item save", e);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java
index 5e1efddd..83716292 100644
--- a/Emulator/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java
+++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java
@@ -14,7 +14,6 @@ import com.eu.habbo.messages.outgoing.catalog.ClubCenterDataComposer;
import com.eu.habbo.messages.outgoing.generic.PickMonthlyClubGiftNotificationComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer;
import com.eu.habbo.messages.outgoing.users.*;
-import gnu.trove.map.hash.THashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -24,6 +23,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
@@ -215,7 +215,7 @@ public class SubscriptionHabboClub extends Subscription {
}
}
- THashMap queryParams = new THashMap<>();
+ Map queryParams = new HashMap<>();
queryParams.put("@user_id", habbo.getId());
queryParams.put("@timestamp_start", habbo.getHabboStats().lastHCPayday);
queryParams.put("@timestamp_end", HC_PAYDAY_NEXT_DATE);
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/PacketManager.java b/Emulator/src/main/java/com/eu/habbo/messages/PacketManager.java
index a66c77e4..e1e4d312 100644
--- a/Emulator/src/main/java/com/eu/habbo/messages/PacketManager.java
+++ b/Emulator/src/main/java/com/eu/habbo/messages/PacketManager.java
@@ -288,6 +288,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 {
@@ -693,5 +695,10 @@ public class PacketManager {
this.registerHandler(Incoming.GameCenterLeaveGameEvent, GameCenterLeaveGameEvent.class);
this.registerHandler(Incoming.GameCenterEvent, GameCenterEvent.class);
this.registerHandler(Incoming.GameCenterRequestGameStatusEvent, GameCenterRequestGameStatusEvent.class);
+
+ // YouTube Room Broadcast
+ this.registerHandler(Incoming.YouTubeRoomPlayEvent, com.eu.habbo.messages.incoming.rooms.youtube.YouTubeRoomPlayEvent.class);
+ this.registerHandler(Incoming.YouTubeRoomWatchingEvent, com.eu.habbo.messages.incoming.rooms.youtube.YouTubeRoomWatchingEvent.class);
+ this.registerHandler(Incoming.YouTubeRoomSettingsEvent, com.eu.habbo.messages.incoming.rooms.youtube.YouTubeRoomSettingsEvent.class);
}
}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/Emulator/src/main/java/com/eu/habbo/messages/incoming/Incoming.java
index cd672c70..d2b24daf 100644
--- a/Emulator/src/main/java/com/eu/habbo/messages/incoming/Incoming.java
+++ b/Emulator/src/main/java/com/eu/habbo/messages/incoming/Incoming.java
@@ -440,10 +440,17 @@ 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;
public static final int SetActivePrefixEvent = 7012;
public static final int DeletePrefixEvent = 7013;
public static final int PurchasePrefixEvent = 7014;
+
+ // YouTube Room Broadcast
+ public static final int YouTubeRoomPlayEvent = 8001;
+ public static final int YouTubeRoomWatchingEvent = 8002;
+ public static final int YouTubeRoomSettingsEvent = 8003;
}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/incoming/catalog/catalogadmin/CatalogAdminSavePageIconEvent.java b/Emulator/src/main/java/com/eu/habbo/messages/incoming/catalog/catalogadmin/CatalogAdminSavePageIconEvent.java
new file mode 100644
index 00000000..8dd75010
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/messages/incoming/catalog/catalogadmin/CatalogAdminSavePageIconEvent.java
@@ -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"));
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/incoming/catalog/catalogadmin/CatalogAdminSavePageImagesEvent.java b/Emulator/src/main/java/com/eu/habbo/messages/incoming/catalog/catalogadmin/CatalogAdminSavePageImagesEvent.java
new file mode 100644
index 00000000..29d2a8c2
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/messages/incoming/catalog/catalogadmin/CatalogAdminSavePageImagesEvent.java
@@ -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"));
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomPlayEvent.java b/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomPlayEvent.java
new file mode 100644
index 00000000..1dec152a
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomPlayEvent.java
@@ -0,0 +1,63 @@
+package com.eu.habbo.messages.incoming.rooms.youtube;
+
+import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.messages.incoming.MessageHandler;
+import com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomBroadcastComposer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class YouTubeRoomPlayEvent extends MessageHandler {
+
+ private static final int MAX_VIDEO_ID_LENGTH = 100;
+ private static final int MAX_PLAYLIST_ITEM_LENGTH = 200;
+ private static final int MAX_PLAYLIST_SIZE = 50;
+
+ @Override
+ public int getRatelimit() {
+ // Max 1 broadcast every 2 seconds per client
+ return 2000;
+ }
+
+ @Override
+ public void handle() throws Exception {
+ Habbo habbo = this.client.getHabbo();
+ if (habbo == null) return;
+
+ Room room = habbo.getHabboInfo().getCurrentRoom();
+ if (room == null) return;
+ if (!room.isYoutubeEnabled()) return;
+ if (!room.isOwner(habbo) && !room.hasRights(habbo)) return;
+
+ String videoId = this.packet.readString();
+ if (videoId.length() > MAX_VIDEO_ID_LENGTH) {
+ videoId = videoId.substring(0, MAX_VIDEO_ID_LENGTH);
+ }
+
+ int playlistCount = this.packet.readInt();
+ if (playlistCount > MAX_PLAYLIST_SIZE) playlistCount = MAX_PLAYLIST_SIZE;
+ if (playlistCount < 0) playlistCount = 0;
+
+ List playlist = new ArrayList<>();
+ for (int i = 0; i < playlistCount; i++) {
+ String item = this.packet.readString();
+ if (item.length() > MAX_PLAYLIST_ITEM_LENGTH) {
+ item = item.substring(0, MAX_PLAYLIST_ITEM_LENGTH);
+ }
+ playlist.add(item);
+ }
+
+ // Store the current video + playlist on the room, or clear if empty
+ if (videoId.isEmpty()) {
+ room.clearYoutubeVideo();
+ } else {
+ room.setYoutubeVideo(videoId, habbo.getHabboInfo().getUsername(), playlist);
+ }
+
+ // Broadcast to everyone in the room (empty videoId = stop)
+ room.sendComposer(
+ new YouTubeRoomBroadcastComposer(videoId, habbo.getHabboInfo().getUsername(), playlist).compose()
+ );
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomSettingsEvent.java b/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomSettingsEvent.java
new file mode 100644
index 00000000..b3f8ceb5
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomSettingsEvent.java
@@ -0,0 +1,35 @@
+package com.eu.habbo.messages.incoming.rooms.youtube;
+
+import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.messages.incoming.MessageHandler;
+import com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomBroadcastComposer;
+import com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomSettingsComposer;
+
+public class YouTubeRoomSettingsEvent extends MessageHandler {
+
+ @Override
+ public int getRatelimit() {
+ return 200;
+ }
+
+ @Override
+ public void handle() throws Exception {
+ Habbo habbo = this.client.getHabbo();
+ if (habbo == null) return;
+
+ Room room = habbo.getHabboInfo().getCurrentRoom();
+ if (room == null) return;
+ if (!room.isOwner(habbo)) return;
+
+ boolean enabled = this.packet.readInt() == 1;
+ room.setYoutubeEnabled(enabled);
+ room.setNeedsUpdate(true);
+ room.sendComposer(new YouTubeRoomSettingsComposer(enabled).compose());
+
+ if (!enabled && !room.getYoutubeCurrentVideo().isEmpty()) {
+ room.clearYoutubeVideo();
+ room.sendComposer(new YouTubeRoomBroadcastComposer("", "", java.util.Collections.emptyList()).compose());
+ }
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomWatchingEvent.java b/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomWatchingEvent.java
new file mode 100644
index 00000000..3de11651
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/messages/incoming/rooms/youtube/YouTubeRoomWatchingEvent.java
@@ -0,0 +1,39 @@
+package com.eu.habbo.messages.incoming.rooms.youtube;
+
+import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.messages.incoming.MessageHandler;
+import com.eu.habbo.messages.outgoing.rooms.youtube.YouTubeRoomWatchersComposer;
+
+public class YouTubeRoomWatchingEvent extends MessageHandler {
+
+ @Override
+ public int getRatelimit() {
+ return 500;
+ }
+
+ @Override
+ public void handle() throws Exception {
+ Habbo habbo = this.client.getHabbo();
+ if (habbo == null) return;
+
+ Room room = habbo.getHabboInfo().getCurrentRoom();
+ if (room == null) return;
+
+ boolean watching = this.packet.readInt() == 1;
+ int userId = habbo.getHabboInfo().getId();
+
+ boolean changed;
+ if (watching) {
+ changed = room.getYoutubeWatchers().add(userId);
+ } else {
+ changed = room.getYoutubeWatchers().remove(userId);
+ }
+
+ if (changed) {
+ room.sendComposer(
+ new YouTubeRoomWatchersComposer(room.getYoutubeWatchers()).compose()
+ );
+ }
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java
index 2b01ff81..9a28a3a6 100644
--- a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java
+++ b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java
@@ -578,4 +578,9 @@ public class Outgoing {
public static final int ActivePrefixUpdatedComposer = 7003;
public static final int AvailableCommandsComposer = 4050;
+ // YouTube Room Broadcast
+ public static final int YouTubeRoomBroadcastComposer = 8001;
+ public static final int YouTubeRoomWatchersComposer = 8002;
+ public static final int YouTubeRoomSettingsComposer = 8003;
+
}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomRightsListComposer.java b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomRightsListComposer.java
index 42e2c571..f9626bc1 100644
--- a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomRightsListComposer.java
+++ b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomRightsListComposer.java
@@ -4,7 +4,6 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
-import gnu.trove.map.hash.THashMap;
import java.util.Map;
@@ -20,7 +19,7 @@ public class RoomRightsListComposer extends MessageComposer {
this.response.init(Outgoing.RoomRightsListComposer);
this.response.appendInt(this.room.getId());
- THashMap rightsMap = this.room.getUsersWithRights();
+ Map rightsMap = this.room.getUsersWithRights();
this.response.appendInt(rightsMap.size());
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomBroadcastComposer.java b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomBroadcastComposer.java
new file mode 100644
index 00000000..7f8680b3
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomBroadcastComposer.java
@@ -0,0 +1,31 @@
+package com.eu.habbo.messages.outgoing.rooms.youtube;
+
+import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.outgoing.MessageComposer;
+import com.eu.habbo.messages.outgoing.Outgoing;
+
+import java.util.List;
+
+public class YouTubeRoomBroadcastComposer extends MessageComposer {
+ private final String videoId;
+ private final String senderName;
+ private final List playlist;
+
+ public YouTubeRoomBroadcastComposer(String videoId, String senderName, List playlist) {
+ this.videoId = videoId;
+ this.senderName = senderName;
+ this.playlist = playlist;
+ }
+
+ @Override
+ protected ServerMessage composeInternal() {
+ this.response.init(Outgoing.YouTubeRoomBroadcastComposer);
+ this.response.appendString(this.videoId);
+ this.response.appendString(this.senderName);
+ this.response.appendInt(this.playlist.size());
+ for (String id : this.playlist) {
+ this.response.appendString(id);
+ }
+ return this.response;
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomSettingsComposer.java b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomSettingsComposer.java
new file mode 100644
index 00000000..64ff91cb
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomSettingsComposer.java
@@ -0,0 +1,20 @@
+package com.eu.habbo.messages.outgoing.rooms.youtube;
+
+import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.outgoing.MessageComposer;
+import com.eu.habbo.messages.outgoing.Outgoing;
+
+public class YouTubeRoomSettingsComposer extends MessageComposer {
+ private final boolean youtubeEnabled;
+
+ public YouTubeRoomSettingsComposer(boolean youtubeEnabled) {
+ this.youtubeEnabled = youtubeEnabled;
+ }
+
+ @Override
+ protected ServerMessage composeInternal() {
+ this.response.init(Outgoing.YouTubeRoomSettingsComposer);
+ this.response.appendInt(this.youtubeEnabled ? 1 : 0);
+ return this.response;
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomWatchersComposer.java b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomWatchersComposer.java
new file mode 100644
index 00000000..d57a3463
--- /dev/null
+++ b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/rooms/youtube/YouTubeRoomWatchersComposer.java
@@ -0,0 +1,25 @@
+package com.eu.habbo.messages.outgoing.rooms.youtube;
+
+import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.outgoing.MessageComposer;
+import com.eu.habbo.messages.outgoing.Outgoing;
+
+import java.util.Set;
+
+public class YouTubeRoomWatchersComposer extends MessageComposer {
+ private final Set watcherIds;
+
+ public YouTubeRoomWatchersComposer(Set watcherIds) {
+ this.watcherIds = watcherIds;
+ }
+
+ @Override
+ protected ServerMessage composeInternal() {
+ this.response.init(Outgoing.YouTubeRoomWatchersComposer);
+ this.response.appendInt(this.watcherIds.size());
+ for (int id : this.watcherIds) {
+ this.response.appendInt(id);
+ }
+ return this.response;
+ }
+}
diff --git a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/users/AddUserBadgeComposer.java b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/users/AddUserBadgeComposer.java
index d8802b20..1e4216bf 100644
--- a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/users/AddUserBadgeComposer.java
+++ b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/users/AddUserBadgeComposer.java
@@ -7,9 +7,15 @@ import com.eu.habbo.messages.outgoing.Outgoing;
public class AddUserBadgeComposer extends MessageComposer {
private final HabboBadge badge;
+ private final String senderName;
public AddUserBadgeComposer(HabboBadge badge) {
+ this(badge, "");
+ }
+
+ public AddUserBadgeComposer(HabboBadge badge, String senderName) {
this.badge = badge;
+ this.senderName = senderName == null ? "" : senderName;
}
@Override
@@ -17,10 +23,15 @@ public class AddUserBadgeComposer extends MessageComposer {
this.response.init(Outgoing.AddUserBadgeComposer);
this.response.appendInt(this.badge.getId());
this.response.appendString(this.badge.getCode());
+ this.response.appendString(this.senderName);
return this.response;
}
public HabboBadge getBadge() {
return badge;
}
+
+ public String getSenderName() {
+ return senderName;
+ }
}
diff --git a/Emulator/src/main/java/com/eu/habbo/networking/gameserver/decoders/GameMessageRateLimit.java b/Emulator/src/main/java/com/eu/habbo/networking/gameserver/decoders/GameMessageRateLimit.java
index 7a4c8de2..1b83a3ee 100644
--- a/Emulator/src/main/java/com/eu/habbo/networking/gameserver/decoders/GameMessageRateLimit.java
+++ b/Emulator/src/main/java/com/eu/habbo/networking/gameserver/decoders/GameMessageRateLimit.java
@@ -6,13 +6,18 @@ import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.networking.gameserver.GameServerAttributes;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.List;
public class GameMessageRateLimit extends MessageToMessageDecoder {
+ private static final Logger LOGGER = LoggerFactory.getLogger(GameMessageRateLimit.class);
+
private static final int RESET_TIME = 1;
private static final int MAX_COUNTER = 10;
+ private static final int DEFAULT_GLOBAL_MAX = 50;
@Override
protected void decode(ChannelHandlerContext ctx, ClientMessage message, List