2018-07-06 13:30:00 +00:00
|
|
|
package com.eu.habbo.habbohotel.rooms;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
2020-05-03 01:46:07 +02:00
|
|
|
import com.eu.habbo.core.DatabaseLoggable;
|
2020-06-05 04:12:49 -04:00
|
|
|
import com.eu.habbo.habbohotel.permissions.Permission;
|
2018-07-06 13:30:00 +00:00
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.eu.habbo.messages.ISerialize;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import com.eu.habbo.messages.incoming.Incoming;
|
|
|
|
import com.eu.habbo.messages.incoming.MessageHandler;
|
2020-05-03 01:46:07 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-05-03 01:46:07 +02:00
|
|
|
public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable {
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(RoomChatMessage.class);
|
|
|
|
private static final String QUERY = "INSERT INTO chatlogs_room (user_from_id, user_to_id, message, timestamp, room_id) VALUES (?, ?, ?, ?, ?)";
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
private static final List<String> chatColors = Arrays.asList("@red@", "@cyan@", "@blue@", "@green@", "@purple@");
|
2018-09-28 19:25:00 +00:00
|
|
|
public static int MAXIMUM_LENGTH = 100;
|
2018-07-06 13:30:00 +00:00
|
|
|
//Configuration. Loaded from database & updated accordingly.
|
|
|
|
public static boolean SAVE_ROOM_CHATS = false;
|
|
|
|
public static int[] BANNED_BUBBLES = {};
|
2019-05-26 21:14:53 +03:00
|
|
|
private final Habbo habbo;
|
|
|
|
public int roomId;
|
|
|
|
public boolean isCommand = false;
|
|
|
|
public boolean filtered = false;
|
2018-10-06 22:28:00 +00:00
|
|
|
private int roomUnitId;
|
2018-07-06 13:30:00 +00:00
|
|
|
private String message;
|
|
|
|
private String unfilteredMessage;
|
2018-11-17 13:28:00 +00:00
|
|
|
private int timestamp = 0;
|
2018-07-06 13:30:00 +00:00
|
|
|
private RoomChatMessageBubbles bubble;
|
|
|
|
private Habbo targetHabbo;
|
|
|
|
private byte emotion;
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public RoomChatMessage(MessageHandler message) {
|
|
|
|
if (message.packet.getMessageId() == Incoming.RoomUserWhisperEvent) {
|
2018-07-06 13:30:00 +00:00
|
|
|
String data = message.packet.readString();
|
|
|
|
this.targetHabbo = message.client.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(data.split(" ")[0]);
|
2019-03-18 01:22:00 +00:00
|
|
|
this.message = data.substring(data.split(" ")[0].length() + 1);
|
2019-05-26 21:14:53 +03:00
|
|
|
} else {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.message = message.packet.readString();
|
|
|
|
}
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.bubble = RoomChatMessageBubbles.getBubble(message.packet.readInt());
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.bubble = RoomChatMessageBubbles.NORMAL;
|
|
|
|
}
|
2019-03-18 01:22:00 +00:00
|
|
|
|
2020-06-05 04:12:49 -04:00
|
|
|
if (!message.client.getHabbo().hasPermission(Permission.ACC_ANYCHATCOLOR)) {
|
2019-05-26 21:14:53 +03:00
|
|
|
for (Integer i : RoomChatMessage.BANNED_BUBBLES) {
|
|
|
|
if (i == this.bubble.getType()) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.bubble = RoomChatMessageBubbles.NORMAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.habbo = message.client.getHabbo();
|
2019-03-18 01:22:00 +00:00
|
|
|
this.roomUnitId = this.habbo.getRoomUnit().getId();
|
|
|
|
this.unfilteredMessage = this.message;
|
2018-11-17 13:28:00 +00:00
|
|
|
this.timestamp = Emulator.getIntUnixTimestamp();
|
2018-07-06 13:30:00 +00:00
|
|
|
|
|
|
|
this.checkEmotion();
|
|
|
|
|
|
|
|
this.filter();
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public RoomChatMessage(RoomChatMessage chatMessage) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.message = chatMessage.getMessage();
|
|
|
|
this.unfilteredMessage = chatMessage.getUnfilteredMessage();
|
|
|
|
this.habbo = chatMessage.getHabbo();
|
|
|
|
this.targetHabbo = chatMessage.getTargetHabbo();
|
|
|
|
this.bubble = chatMessage.getBubble();
|
2018-10-06 22:28:00 +00:00
|
|
|
this.roomUnitId = chatMessage.roomUnitId;
|
2019-05-26 21:14:53 +03:00
|
|
|
this.emotion = (byte) chatMessage.getEmotion();
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public RoomChatMessage(String message, RoomUnit roomUnit, RoomChatMessageBubbles bubble) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.message = message;
|
|
|
|
this.unfilteredMessage = message;
|
|
|
|
this.habbo = null;
|
|
|
|
this.bubble = bubble;
|
2018-10-06 22:28:00 +00:00
|
|
|
this.roomUnitId = roomUnit.getId();
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public RoomChatMessage(String message, Habbo habbo, RoomChatMessageBubbles bubble) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.message = message;
|
|
|
|
this.unfilteredMessage = message;
|
|
|
|
this.habbo = habbo;
|
|
|
|
this.bubble = bubble;
|
|
|
|
this.checkEmotion();
|
2018-10-06 22:28:00 +00:00
|
|
|
this.roomUnitId = habbo.getRoomUnit().getId();
|
2018-07-06 13:30:00 +00:00
|
|
|
this.message = this.message.replace("\r", "").replace("\n", "");
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (this.bubble.isOverridable() && this.getHabbo().getHabboStats().chatColor != RoomChatMessageBubbles.NORMAL)
|
2018-07-06 13:30:00 +00:00
|
|
|
this.bubble = this.getHabbo().getHabboStats().chatColor;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public RoomChatMessage(String message, Habbo habbo, Habbo targetHabbo, RoomChatMessageBubbles bubble) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.message = message;
|
|
|
|
this.unfilteredMessage = message;
|
|
|
|
this.habbo = habbo;
|
|
|
|
this.targetHabbo = targetHabbo;
|
|
|
|
this.bubble = bubble;
|
|
|
|
this.checkEmotion();
|
2018-10-06 22:28:00 +00:00
|
|
|
this.roomUnitId = this.habbo.getRoomUnit().getId();
|
2018-07-06 13:30:00 +00:00
|
|
|
this.message = this.message.replace("\r", "").replace("\n", "");
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (this.bubble.isOverridable() && this.getHabbo().getHabboStats().chatColor != RoomChatMessageBubbles.NORMAL)
|
2018-07-06 13:30:00 +00:00
|
|
|
this.bubble = this.getHabbo().getHabboStats().chatColor;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
private void checkEmotion() {
|
|
|
|
if (this.message.contains(":)") || this.message.contains(":-)") || this.message.contains(":]")) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.emotion = 1;
|
2019-05-26 21:14:53 +03:00
|
|
|
} else if (this.message.contains(":@") || this.message.contains(">:(")) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.emotion = 2;
|
2019-05-26 21:14:53 +03:00
|
|
|
} else if (this.message.contains(":o") || this.message.contains(":O") || this.message.contains(":0") || this.message.contains("O.o") || this.message.contains("o.O") || this.message.contains("O.O")) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.emotion = 3;
|
2019-05-26 21:14:53 +03:00
|
|
|
} else if (this.message.contains(":(") || this.message.contains(":-(") || this.message.contains(":[")) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.emotion = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 21:14:53 +03:00
|
|
|
public void run() {
|
|
|
|
if (this.habbo == null)
|
2018-07-06 13:30:00 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (this.message.length() > RoomChatMessage.MAXIMUM_LENGTH) {
|
|
|
|
try {
|
|
|
|
this.message = this.message.substring(0, RoomChatMessage.MAXIMUM_LENGTH - 1);
|
|
|
|
} catch (Exception e) {
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-03 01:46:07 +02:00
|
|
|
|
|
|
|
Emulator.getDatabaseLogger().store(this);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public String getMessage() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.message;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public void setMessage(String message) {
|
|
|
|
this.message = message;
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public String getUnfilteredMessage() {
|
|
|
|
return this.unfilteredMessage;
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public RoomChatMessageBubbles getBubble() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.bubble;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Habbo getHabbo() {
|
|
|
|
return this.habbo;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public Habbo getTargetHabbo() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.targetHabbo;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public int getEmotion() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.emotion;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 21:14:53 +03:00
|
|
|
public void serialize(ServerMessage message) {
|
|
|
|
if (this.habbo != null && this.bubble.isOverridable()) {
|
2020-06-05 04:12:49 -04:00
|
|
|
if (!this.habbo.hasPermission(Permission.ACC_ANYCHATCOLOR)) {
|
2019-05-26 21:14:53 +03:00
|
|
|
for (Integer i : RoomChatMessage.BANNED_BUBBLES) {
|
|
|
|
if (i == this.bubble.getType()) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.bubble = RoomChatMessageBubbles.NORMAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (!this.getBubble().getPermission().isEmpty()) {
|
|
|
|
if (this.habbo != null && !this.habbo.hasPermission(this.getBubble().getPermission())) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.bubble = RoomChatMessageBubbles.NORMAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-10-06 22:28:00 +00:00
|
|
|
message.appendInt(this.roomUnitId);
|
2018-07-06 13:30:00 +00:00
|
|
|
message.appendString(this.getMessage());
|
|
|
|
message.appendInt(this.getEmotion());
|
|
|
|
message.appendInt(this.getBubble().getType());
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getMessage().length());
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public void filter() {
|
|
|
|
if (!this.habbo.getHabboStats().hasActiveClub()) {
|
2018-07-06 13:30:00 +00:00
|
|
|
for (String chatColor : chatColors) {
|
2019-03-18 01:22:00 +00:00
|
|
|
this.message = this.message.replace(chatColor, "");
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-26 21:14:53 +03:00
|
|
|
|
|
|
|
if (Emulator.getConfig().getBoolean("hotel.wordfilter.enabled") && Emulator.getConfig().getBoolean("hotel.wordfilter.rooms")) {
|
2020-06-05 04:12:49 -04:00
|
|
|
if (!this.habbo.hasPermission(Permission.ACC_CHAT_NO_FILTER)) {
|
2019-05-26 21:14:53 +03:00
|
|
|
if (!Emulator.getGameEnvironment().getWordFilter().autoReportCheck(this)) {
|
|
|
|
if (!Emulator.getGameEnvironment().getWordFilter().hideMessageCheck(this.message)) {
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.getGameEnvironment().getWordFilter().filter(this, this.habbo);
|
|
|
|
return;
|
|
|
|
}
|
2019-05-26 21:14:53 +03:00
|
|
|
} else {
|
2020-06-03 02:30:32 +02:00
|
|
|
int muteTime = Emulator.getConfig().getInt("hotel.wordfilter.automute");
|
|
|
|
if (muteTime > 0) {
|
|
|
|
this.habbo.mute(muteTime, false);
|
|
|
|
} else {
|
|
|
|
LOGGER.error("Invalid hotel.wordfilter.automute defined in emulator_settings ({}).", muteTime);
|
|
|
|
}
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.message = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-06 22:28:00 +00:00
|
|
|
|
2020-05-03 01:46:07 +02:00
|
|
|
@Override
|
|
|
|
public String getQuery() {
|
|
|
|
return QUERY;
|
|
|
|
}
|
|
|
|
|
2018-10-06 22:28:00 +00:00
|
|
|
@Override
|
2019-05-26 21:14:53 +03:00
|
|
|
public void log(PreparedStatement statement) throws SQLException {
|
|
|
|
statement.setInt(1, this.habbo.getHabboInfo().getId());
|
2018-10-06 22:28:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (this.targetHabbo != null)
|
2018-10-06 22:28:00 +00:00
|
|
|
statement.setInt(2, this.targetHabbo.getHabboInfo().getId());
|
|
|
|
else
|
|
|
|
statement.setInt(2, 0);
|
|
|
|
|
|
|
|
statement.setString(3, this.unfilteredMessage);
|
2018-11-17 13:28:00 +00:00
|
|
|
statement.setInt(4, this.timestamp);
|
2018-10-06 22:28:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (this.habbo.getHabboInfo().getCurrentRoom() != null) {
|
2018-10-06 22:28:00 +00:00
|
|
|
statement.setInt(5, this.habbo.getHabboInfo().getCurrentRoom().getId());
|
2019-05-26 21:14:53 +03:00
|
|
|
} else {
|
2018-10-06 22:28:00 +00:00
|
|
|
statement.setInt(5, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
statement.addBatch();
|
|
|
|
}
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|