Validate room name and description when creating room & save trade mode

This commit is contained in:
Alejandro 2020-06-07 15:05:02 +03:00
parent db14789d6b
commit ed2ec3e6f3
3 changed files with 18 additions and 10 deletions

View File

@ -327,10 +327,10 @@ public class RoomManager {
} }
public Room createRoom(int ownerId, String ownerName, String name, String description, String modelName, int usersMax, int categoryId) { public Room createRoom(int ownerId, String ownerName, String name, String description, String modelName, int usersMax, int categoryId, int tradeType) {
Room room = null; Room room = null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO rooms (owner_id, owner_name, name, description, model, users_max, category) VALUES (?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO rooms (owner_id, owner_name, name, description, model, users_max, category, trade_mode) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
statement.setInt(1, ownerId); statement.setInt(1, ownerId);
statement.setString(2, ownerName); statement.setString(2, ownerName);
statement.setString(3, name); statement.setString(3, name);
@ -338,6 +338,7 @@ public class RoomManager {
statement.setString(5, modelName); statement.setString(5, modelName);
statement.setInt(6, usersMax); statement.setInt(6, usersMax);
statement.setInt(7, categoryId); statement.setInt(7, categoryId);
statement.setInt(8, tradeType);
statement.execute(); statement.execute();
try (ResultSet set = statement.getGeneratedKeys()) { try (ResultSet set = statement.getGeneratedKeys()) {
if (set.next()) if (set.next())
@ -351,8 +352,8 @@ public class RoomManager {
} }
public Room createRoomForHabbo(Habbo habbo, String name, String description, String modelName, int usersMax, int categoryId) { public Room createRoomForHabbo(Habbo habbo, String name, String description, String modelName, int usersMax, int categoryId, int tradeType) {
Room room = this.createRoom(habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername(), name, description, modelName, usersMax, categoryId); Room room = this.createRoom(habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername(), name, description, modelName, usersMax, categoryId, tradeType);
Emulator.getPluginManager().fireEvent(new NavigatorRoomCreatedEvent(habbo, room)); Emulator.getPluginManager().fireEvent(new NavigatorRoomCreatedEvent(habbo, room));

View File

@ -41,6 +41,12 @@ public class RequestCreateRoomEvent extends MessageHandler {
if (tradeType > 2) if (tradeType > 2)
return; return;
if (name.length() < 3 || name.length() > 25 || !Emulator.getGameEnvironment().getWordFilter().filter(name, this.client.getHabbo()).equals(name))
return;
if (description.length() > 128 || !Emulator.getGameEnvironment().getWordFilter().filter(description, this.client.getHabbo()).equals(description))
return;
int count = Emulator.getGameEnvironment().getRoomManager().getRoomsForHabbo(this.client.getHabbo()).size(); int count = Emulator.getGameEnvironment().getRoomManager().getRoomsForHabbo(this.client.getHabbo()).size();
int max = this.client.getHabbo().getHabboStats().hasActiveClub() ? RoomManager.MAXIMUM_ROOMS_VIP : RoomManager.MAXIMUM_ROOMS_USER; int max = this.client.getHabbo().getHabboStats().hasActiveClub() ? RoomManager.MAXIMUM_ROOMS_VIP : RoomManager.MAXIMUM_ROOMS_USER;
@ -49,13 +55,9 @@ public class RequestCreateRoomEvent extends MessageHandler {
return; return;
} }
final Room room = Emulator.getGameEnvironment().getRoomManager().createRoomForHabbo(this.client.getHabbo(), name, description, modelName, maxUsers, categoryId); final Room room = Emulator.getGameEnvironment().getRoomManager().createRoomForHabbo(this.client.getHabbo(), name, description, modelName, maxUsers, categoryId, tradeType);
if (room != null) { if (room != null) {
if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) {
//Emulator.getGameEnvironment().getRoomManager().leaveRoom(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getCurrentRoom());
}
this.client.sendResponse(new RoomCreatedComposer(room)); this.client.sendResponse(new RoomCreatedComposer(room));
} }
} }

View File

@ -23,7 +23,7 @@ public class RoomSettingsSaveEvent extends MessageHandler {
if (room.isOwner(this.client.getHabbo())) { if (room.isOwner(this.client.getHabbo())) {
String name = this.packet.readString(); String name = this.packet.readString();
if (name.isEmpty()) { if (name.trim().isEmpty() || name.length() > 60) {
this.client.sendResponse(new RoomEditSettingsErrorComposer(room.getId(), RoomEditSettingsErrorComposer.ROOM_NAME_MISSING, "")); this.client.sendResponse(new RoomEditSettingsErrorComposer(room.getId(), RoomEditSettingsErrorComposer.ROOM_NAME_MISSING, ""));
return; return;
} }
@ -34,6 +34,11 @@ public class RoomSettingsSaveEvent extends MessageHandler {
} }
String description = this.packet.readString(); String description = this.packet.readString();
if (description.length() > 255) {
return;
}
if (!Emulator.getGameEnvironment().getWordFilter().filter(description, this.client.getHabbo()).equals(description)) { if (!Emulator.getGameEnvironment().getWordFilter().filter(description, this.client.getHabbo()).equals(description)) {
this.client.sendResponse(new RoomEditSettingsErrorComposer(room.getId(), RoomEditSettingsErrorComposer.ROOM_DESCRIPTION_BADWORDS, "")); this.client.sendResponse(new RoomEditSettingsErrorComposer(room.getId(), RoomEditSettingsErrorComposer.ROOM_DESCRIPTION_BADWORDS, ""));
return; return;