mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-22 23:10:52 +01:00
Merge branch 'rcon-change-username' into 'dev'
Added new RCON command (Change Username) See merge request morningstar/Arcturus-Community!547
This commit is contained in:
commit
8724c301ba
@ -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');
|
||||
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.');
|
||||
|
71
src/main/java/com/eu/habbo/messages/rcon/ChangeUsername.java
Normal file
71
src/main/java/com/eu/habbo/messages/rcon/ChangeUsername.java
Normal file
@ -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<ChangeUsername.JSON> {
|
||||
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;
|
||||
}
|
||||
}
|
@ -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(";"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user