Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/messenger/Message.java

63 lines
1.7 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.messenger;
import com.eu.habbo.Emulator;
2020-05-04 22:24:09 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2018-07-06 15:30:00 +02:00
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class Message implements Runnable {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(Message.class);
2018-07-06 15:30:00 +02:00
private final int fromId;
private final int toId;
private final int timestamp;
2019-05-26 20:14:53 +02:00
private String message;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public Message(int fromId, int toId, String message) {
2018-07-06 15:30:00 +02:00
this.fromId = fromId;
this.toId = toId;
this.message = message;
this.timestamp = Emulator.getIntUnixTimestamp();
}
@Override
2019-05-26 20:14:53 +02:00
public void run() {
2018-07-06 15:30:00 +02:00
//TODO Turn into scheduler
2019-05-26 20:14:53 +02:00
if (Messenger.SAVE_PRIVATE_CHATS) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO chatlogs_private (user_from_id, user_to_id, message, timestamp) VALUES (?, ?, ?, ?)")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, this.fromId);
statement.setInt(2, this.toId);
statement.setString(3, this.message);
statement.setInt(4, this.timestamp);
statement.execute();
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught SQL exception", e);
2018-07-06 15:30:00 +02:00
}
}
}
2019-05-26 20:14:53 +02:00
public int getToId() {
2018-07-06 15:30:00 +02:00
return this.toId;
}
public int getFromId() {
return this.fromId;
}
public String getMessage() {
return this.message;
}
2019-05-26 20:14:53 +02:00
public void setMessage(String message) {
2018-07-06 15:30:00 +02:00
this.message = message;
}
public int getTimestamp() {
return this.timestamp;
}
}