From 609cfd4fe356e25592641410bba594d5dcdd709d Mon Sep 17 00:00:00 2001 From: Snaiker Date: Fri, 15 Apr 2022 02:02:35 +0100 Subject: [PATCH] Added new RCON command --- sqlupdates/3_0_0 to 3_0_1.sql | 5 +- .../habbo/messages/rcon/ChangeUsername.java | 71 +++++++++++++++++++ .../networking/rconserver/RCONServer.java | 1 + 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/eu/habbo/messages/rcon/ChangeUsername.java diff --git a/sqlupdates/3_0_0 to 3_0_1.sql b/sqlupdates/3_0_0 to 3_0_1.sql index b07fe18c..23f8efaf 100644 --- a/sqlupdates/3_0_0 to 3_0_1.sql +++ b/sqlupdates/3_0_0 to 3_0_1.sql @@ -87,4 +87,7 @@ INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.success.cmd_upda INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('moodlight.color_check.enabled', '1'); -- Mannequin name -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.mannequin.name.default', 'My look'); \ No newline at end of file +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.mannequin.name.default', 'My look'); + +-- RCON: Change Username +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('rcon.alert.user.change_username', 'You can change your username. Click on yourself to change it.'); diff --git a/src/main/java/com/eu/habbo/messages/rcon/ChangeUsername.java b/src/main/java/com/eu/habbo/messages/rcon/ChangeUsername.java new file mode 100644 index 00000000..e7cb6c69 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/rcon/ChangeUsername.java @@ -0,0 +1,71 @@ +package com.eu.habbo.messages.rcon; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.users.subscriptions.Subscription; +import com.eu.habbo.messages.outgoing.users.UserDataComposer; +import com.google.gson.Gson; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class ChangeUsername extends RCONMessage { + private static final Logger LOGGER = LoggerFactory.getLogger(ChangeUsername.class); + + public ChangeUsername() { + super(ChangeUsername.JSON.class); + } + + @Override + public void handle(Gson gson, JSON json) { + try { + if (json.user_id <= 0) { + this.status = RCONMessage.HABBO_NOT_FOUND; + this.message = "User not found"; + return; + } + + boolean success = true; + + Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(json.user_id); + if (habbo != null) { + if (json.canChange) + habbo.alert(Emulator.getTexts().getValue("rcon.alert.user.change_username")); + + habbo.getHabboStats().allowNameChange = json.canChange; + habbo.getClient().sendResponse(new UserDataComposer(habbo)); + } else { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { + try (PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET allow_name_change = ? WHERE user_id = ? LIMIT 1")) { + statement.setBoolean(1, json.canChange); + statement.setInt(2, json.user_id); + + success = statement.executeUpdate() >= 1; + } catch (SQLException sqlException) { + sqlException.printStackTrace(); + } + } catch (SQLException sqlException) { + sqlException.printStackTrace(); + } + } + + this.status = success ? RCONMessage.STATUS_OK : RCONMessage.STATUS_ERROR; + this.message = success ? "Sent successfully." : "There was an error updating this user."; + } + catch (Exception e) { + this.status = RCONMessage.SYSTEM_ERROR; + this.message = "Exception occurred"; + LOGGER.error("Exception occurred", e); + } + } + + static class JSON { + public int user_id; + + public boolean canChange; + } +} \ No newline at end of file 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 7bbd9f05..fed9aa56 100644 --- a/src/main/java/com/eu/habbo/networking/rconserver/RCONServer.java +++ b/src/main/java/com/eu/habbo/networking/rconserver/RCONServer.java @@ -62,6 +62,7 @@ public class RCONServer extends Server { this.addRCONMessage("setmotto", SetMotto.class); this.addRCONMessage("giveuserclothing", GiveUserClothing.class); this.addRCONMessage("modifysubscription", ModifyUserSubscription.class); + this.addRCONMessage("changeusername", ChangeUsername.class); Collections.addAll(this.allowedAdresses, Emulator.getConfig().getValue("rcon.allowed", "127.0.0.1").split(";")); }