2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.messenger;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
|
|
|
|
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 {
|
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) {
|
2018-07-06 15:30:00 +02:00
|
|
|
Emulator.getLogging().logSQLException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|