Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/rooms/RoomChatMessage.java

299 lines
9.2 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
2018-10-07 00:28:00 +02:00
import com.eu.habbo.core.Loggable;
2018-07-06 15:30:00 +02: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;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
2018-10-07 00:28:00 +02:00
public class RoomChatMessage implements Runnable, ISerialize, Loggable
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
public static String insertQuery = "INSERT INTO chatlogs_room (user_from_id, user_to_id, message, timestamp, room_id) VALUES (?, ?, ?, ?, ?)";
2018-09-28 21:25:00 +02:00
public static int MAXIMUM_LENGTH = 100;
2018-07-06 15:30:00 +02:00
//Configuration. Loaded from database & updated accordingly.
public static boolean SAVE_ROOM_CHATS = false;
public static int[] BANNED_BUBBLES = {};
2018-10-07 00:28:00 +02:00
private int roomUnitId;
2018-07-06 15:30:00 +02:00
private String message;
private String unfilteredMessage;
2018-11-17 14:28:00 +01:00
private int timestamp = 0;
2018-07-06 15:30:00 +02:00
private RoomChatMessageBubbles bubble;
private final Habbo habbo;
2018-10-07 00:28:00 +02:00
public int roomId;
2018-07-06 15:30:00 +02:00
private Habbo targetHabbo;
private byte emotion;
public boolean isCommand = false;
public boolean filtered = false;
private static final List<String> chatColors = Arrays.asList("@red@", "@cyan@", "@blue@", "@green@", "@purple@");
public RoomChatMessage(MessageHandler message)
{
2019-03-18 02:22:00 +01:00
if (message.packet.getMessageId() == Incoming.RoomUserWhisperEvent)
2018-07-06 15:30:00 +02:00
{
String data = message.packet.readString();
this.targetHabbo = message.client.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(data.split(" ")[0]);
2019-03-18 02:22:00 +01:00
this.message = data.substring(data.split(" ")[0].length() + 1);
2018-07-06 15:30:00 +02:00
}
else
{
this.message = message.packet.readString();
}
try
{
this.bubble = RoomChatMessageBubbles.getBubble(message.packet.readInt());
}
catch (Exception e)
{
this.bubble = RoomChatMessageBubbles.NORMAL;
}
2019-03-18 02:22:00 +01:00
if (!message.client.getHabbo().hasPermission("acc_anychatcolor"))
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
for (Integer i : RoomChatMessage.BANNED_BUBBLES)
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
if (i == this.bubble.getType())
2018-07-06 15:30:00 +02:00
{
this.bubble = RoomChatMessageBubbles.NORMAL;
}
}
}
this.habbo = message.client.getHabbo();
2019-03-18 02:22:00 +01:00
this.roomUnitId = this.habbo.getRoomUnit().getId();
this.unfilteredMessage = this.message;
2018-11-17 14:28:00 +01:00
this.timestamp = Emulator.getIntUnixTimestamp();
2018-07-06 15:30:00 +02:00
this.checkEmotion();
this.filter();
}
public RoomChatMessage(RoomChatMessage chatMessage)
{
this.message = chatMessage.getMessage();
this.unfilteredMessage = chatMessage.getUnfilteredMessage();
this.habbo = chatMessage.getHabbo();
this.targetHabbo = chatMessage.getTargetHabbo();
this.bubble = chatMessage.getBubble();
2018-10-07 00:28:00 +02:00
this.roomUnitId = chatMessage.roomUnitId;
2018-07-06 15:30:00 +02:00
this.emotion = (byte)chatMessage.getEmotion();
}
public RoomChatMessage(String message, RoomUnit roomUnit, RoomChatMessageBubbles bubble)
{
this.message = message;
this.unfilteredMessage = message;
this.habbo = null;
this.bubble = bubble;
2018-10-07 00:28:00 +02:00
this.roomUnitId = roomUnit.getId();
2018-07-06 15:30:00 +02:00
}
public RoomChatMessage(String message, Habbo habbo, RoomChatMessageBubbles bubble)
{
this.message = message;
this.unfilteredMessage = message;
this.habbo = habbo;
this.bubble = bubble;
this.checkEmotion();
2018-10-07 00:28:00 +02:00
this.roomUnitId = habbo.getRoomUnit().getId();
2018-07-06 15:30:00 +02:00
this.message = this.message.replace("\r", "").replace("\n", "");
if(this.bubble.isOverridable() && this.getHabbo().getHabboStats().chatColor != RoomChatMessageBubbles.NORMAL)
this.bubble = this.getHabbo().getHabboStats().chatColor;
}
public RoomChatMessage(String message, Habbo habbo, Habbo targetHabbo, RoomChatMessageBubbles bubble)
{
this.message = message;
this.unfilteredMessage = message;
this.habbo = habbo;
this.targetHabbo = targetHabbo;
this.bubble = bubble;
this.checkEmotion();
2018-10-07 00:28:00 +02:00
this.roomUnitId = this.habbo.getRoomUnit().getId();
2018-07-06 15:30:00 +02:00
this.message = this.message.replace("\r", "").replace("\n", "");
if(this.bubble.isOverridable() && this.getHabbo().getHabboStats().chatColor != RoomChatMessageBubbles.NORMAL)
this.bubble = this.getHabbo().getHabboStats().chatColor;
}
private void checkEmotion()
{
if(this.message.contains(":)") || this.message.contains(":-)") || this.message.contains(":]"))
{
this.emotion = 1;
}
else if(this.message.contains(":@") || this.message.contains(">:("))
{
this.emotion = 2;
}
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"))
{
this.emotion = 3;
}
else if(this.message.contains(":(") || this.message.contains(":-(") || this.message.contains(":["))
{
this.emotion = 4;
}
}
@Override
2018-12-22 11:39:00 +01:00
public void run()
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
if(this.habbo == null)
2018-07-06 15:30:00 +02:00
return;
2018-10-07 00:28:00 +02:00
if(this.message.length() > RoomChatMessage.MAXIMUM_LENGTH)
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
try
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
this.message = this.message.substring(0, RoomChatMessage.MAXIMUM_LENGTH-1);
2018-07-06 15:30:00 +02:00
}
2018-10-07 00:28:00 +02:00
catch (Exception e)
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
Emulator.getLogging().logErrorLine(e);
2018-07-06 15:30:00 +02:00
}
}
2018-10-07 00:28:00 +02:00
Emulator.getLogging().addChatLog(this);
2018-07-06 15:30:00 +02:00
}
public String getMessage()
{
return this.message;
}
public String getUnfilteredMessage()
{
return this.unfilteredMessage;
}
public void setMessage(String message)
{
this.message = message;
}
public RoomChatMessageBubbles getBubble()
{
return this.bubble;
}
public Habbo getHabbo() {
return this.habbo;
}
public Habbo getTargetHabbo()
{
return this.targetHabbo;
}
public int getEmotion()
{
return this.emotion;
}
@Override
public void serialize(ServerMessage message)
{
if(this.habbo != null && this.bubble.isOverridable())
{
if (!this.habbo.hasPermission("acc_anychatcolor"))
{
for (Integer i : RoomChatMessage.BANNED_BUBBLES)
{
if (i == this.bubble.getType())
{
this.bubble = RoomChatMessageBubbles.NORMAL;
break;
}
}
}
}
if (!this.getBubble().getPermission().isEmpty())
{
if (this.habbo != null && !this.habbo.hasPermission(this.getBubble().getPermission()))
{
this.bubble = RoomChatMessageBubbles.NORMAL;
}
}
try
{
2018-10-07 00:28:00 +02:00
message.appendInt(this.roomUnitId);
2018-07-06 15:30:00 +02:00
message.appendString(this.getMessage());
message.appendInt(this.getEmotion());
message.appendInt(this.getBubble().getType());
message.appendInt(0);
message.appendInt(this.getMessage().length());
}
catch(Exception e)
{
2019-03-18 02:22:00 +01:00
Emulator.getLogging().logErrorLine(e);
2018-07-06 15:30:00 +02:00
}
}
public void filter()
{
2019-03-18 02:22:00 +01:00
if(!this.habbo.getHabboStats().hasActiveClub())
2018-07-06 15:30:00 +02:00
{
for (String chatColor : chatColors) {
2019-03-18 02:22:00 +01:00
this.message = this.message.replace(chatColor, "");
2018-07-06 15:30:00 +02:00
}
}
if(Emulator.getConfig().getBoolean("hotel.wordfilter.enabled") && Emulator.getConfig().getBoolean("hotel.wordfilter.rooms"))
{
2019-03-18 02:22:00 +01:00
if(!this.habbo.hasPermission("acc_chat_no_filter"))
2018-07-06 15:30:00 +02:00
{
if (!Emulator.getGameEnvironment().getWordFilter().autoReportCheck(this))
{
if (!Emulator.getGameEnvironment().getWordFilter().hideMessageCheck(this.message))
{
Emulator.getGameEnvironment().getWordFilter().filter(this, this.habbo);
return;
}
}
else
{
2019-03-18 02:22:00 +01:00
this.habbo.mute(Emulator.getConfig().getInt("hotel.wordfilter.automute"));
2018-07-06 15:30:00 +02:00
}
this.message = "";
}
}
}
2018-10-07 00:28:00 +02:00
@Override
public void log(PreparedStatement statement) throws SQLException
{
statement.setInt(1,this.habbo.getHabboInfo().getId());
if(this.targetHabbo != null)
statement.setInt(2, this.targetHabbo.getHabboInfo().getId());
else
statement.setInt(2, 0);
statement.setString(3, this.unfilteredMessage);
2018-11-17 14:28:00 +01:00
statement.setInt(4, this.timestamp);
2018-10-07 00:28:00 +02:00
if(this.habbo.getHabboInfo().getCurrentRoom() != null)
{
statement.setInt(5, this.habbo.getHabboInfo().getCurrentRoom().getId());
}
else
{
statement.setInt(5, 0);
}
statement.addBatch();
}
2018-07-06 15:30:00 +02:00
}