diff --git a/src/main/java/com/eu/habbo/messages/rcon/GiveUserClothing.java b/src/main/java/com/eu/habbo/messages/rcon/GiveUserClothing.java new file mode 100644 index 00000000..e601268a --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/rcon/GiveUserClothing.java @@ -0,0 +1,47 @@ +package com.eu.habbo.messages.rcon; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; +import com.eu.habbo.messages.outgoing.users.UserClothesComposer; +import com.google.gson.Gson; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class GiveUserClothing extends RCONMessage { + public GiveUserClothing() { + super(GiveUserClothing.JSONGiveUserClothing.class); + } + + @Override + public void handle(Gson gson, GiveUserClothing.JSONGiveUserClothing object) { + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(object.user_id); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_clothing (user_id, clothing_id) VALUES (?, ?)")) { + statement.setInt(1, object.user_id); + statement.setInt(2, object.clothing_id); + statement.execute(); + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + + if (habbo != null) { + GameClient client = habbo.getClient(); + + if (client != null) { + habbo.getInventory().getWardrobeComponent().getClothing().add(object.clothing_id); + client.sendResponse(new UserClothesComposer(habbo)); + client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FIGURESET_REDEEMED.key)); + } + } + } + + static class JSONGiveUserClothing { + public int user_id; + public int clothing_id; + } +} diff --git a/src/main/java/com/eu/habbo/networking/rconserver/RCONServer.java b/src/main/java/com/eu/habbo/networking/rconserver/RCONServer.java index a17c100e..ea65161a 100644 --- a/src/main/java/com/eu/habbo/networking/rconserver/RCONServer.java +++ b/src/main/java/com/eu/habbo/networking/rconserver/RCONServer.java @@ -56,6 +56,7 @@ public class RCONServer extends Server { this.addRCONMessage("giverespect", GiveRespect.class); this.addRCONMessage("ignoreuser", IgnoreUser.class); this.addRCONMessage("setmotto", SetMotto.class); + this.addRCONMessage("giveuserclothing", GiveUserClothing.class); Collections.addAll(this.allowedAdresses, Emulator.getConfig().getValue("rcon.allowed", "127.0.0.1").split(";")); }