mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-10-24 11:43:06 +02:00
190 lines
5.8 KiB
Java
190 lines
5.8 KiB
Java
package com.eu.habbo.habbohotel.messenger;
|
|
|
|
import com.eu.habbo.Emulator;
|
|
import com.eu.habbo.habbohotel.modtool.WordFilter;
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
import com.eu.habbo.habbohotel.users.HabboGender;
|
|
import com.eu.habbo.messages.ISerialize;
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
import com.eu.habbo.messages.outgoing.friends.FriendChatMessageComposer;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
|
|
public class MessengerBuddy implements Runnable, ISerialize {
|
|
|
|
private int id;
|
|
private String username;
|
|
private HabboGender gender = HabboGender.M;
|
|
private int online = 0;
|
|
private String look = "";
|
|
private String motto = "";
|
|
private short relation;
|
|
private boolean inRoom;
|
|
private int userOne = 0;
|
|
|
|
public MessengerBuddy(ResultSet set) {
|
|
try {
|
|
this.id = set.getInt("id");
|
|
this.username = set.getString("username");
|
|
this.gender = HabboGender.valueOf(set.getString("gender"));
|
|
this.online = Integer.valueOf(set.getString("online"));
|
|
this.motto = set.getString("motto");
|
|
this.look = set.getString("look");
|
|
this.relation = (short) set.getInt("relation");
|
|
this.userOne = set.getInt("user_one_id");
|
|
this.inRoom = false;
|
|
if (this.online == 1) {
|
|
Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(this.username);
|
|
|
|
if (habbo != null) {
|
|
this.inRoom = habbo.getHabboInfo().getCurrentRoom() != null;
|
|
}
|
|
}
|
|
} catch (SQLException e) {
|
|
Emulator.getLogging().logSQLException(e);
|
|
}
|
|
}
|
|
|
|
public MessengerBuddy(ResultSet set, boolean value) {
|
|
try {
|
|
this.id = set.getInt("id");
|
|
this.username = set.getString("username");
|
|
this.look = set.getString("look");
|
|
this.relation = 0;
|
|
this.userOne = 0;
|
|
} catch (SQLException e) {
|
|
Emulator.getLogging().logSQLException(e);
|
|
}
|
|
}
|
|
|
|
public MessengerBuddy(int id, String username, String look, Short relation, int userOne) {
|
|
this.id = id;
|
|
this.username = username;
|
|
this.gender = HabboGender.M;
|
|
this.online = 0;
|
|
this.motto = "";
|
|
this.look = look;
|
|
this.relation = relation;
|
|
this.userOne = userOne;
|
|
}
|
|
|
|
public MessengerBuddy(Habbo habbo, int userOne) {
|
|
this.id = habbo.getHabboInfo().getId();
|
|
this.username = habbo.getHabboInfo().getUsername();
|
|
this.gender = habbo.getHabboInfo().getGender();
|
|
this.online = habbo.getHabboInfo().isOnline() ? 1 : 0;
|
|
this.motto = habbo.getHabboInfo().getMotto();
|
|
this.look = habbo.getHabboInfo().getLook();
|
|
this.relation = 0;
|
|
this.userOne = userOne;
|
|
this.inRoom = habbo.getHabboInfo().getCurrentRoom() != null;
|
|
}
|
|
|
|
public int getId() {
|
|
return this.id;
|
|
}
|
|
|
|
public String getUsername() {
|
|
return this.username;
|
|
}
|
|
|
|
public void setUsername(String username) {
|
|
this.username = username;
|
|
}
|
|
|
|
public HabboGender getGender() {
|
|
return this.gender;
|
|
}
|
|
|
|
public void setGender(HabboGender gender) {
|
|
this.gender = gender;
|
|
}
|
|
|
|
public int getOnline() {
|
|
return this.online;
|
|
}
|
|
|
|
public void setOnline(boolean value) {
|
|
this.online = (value ? 1 : 0);
|
|
}
|
|
|
|
public String getLook() {
|
|
return this.look;
|
|
}
|
|
|
|
public void setLook(String look) {
|
|
this.look = look;
|
|
}
|
|
|
|
public String getMotto() {
|
|
return this.motto;
|
|
}
|
|
|
|
public short getRelation() {
|
|
return this.relation;
|
|
}
|
|
|
|
public void setRelation(int relation) {
|
|
this.relation = (short) relation;
|
|
Emulator.getThreading().run(this);
|
|
}
|
|
|
|
public boolean inRoom() {
|
|
return this.inRoom;
|
|
}
|
|
|
|
public void inRoom(boolean value) {
|
|
this.inRoom = value;
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
|
|
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE messenger_friendships SET relation = ? WHERE user_one_id = ? AND user_two_id = ?")) {
|
|
statement.setInt(1, this.relation);
|
|
statement.setInt(2, this.userOne);
|
|
statement.setInt(3, this.id);
|
|
statement.execute();
|
|
} catch (SQLException e) {
|
|
Emulator.getLogging().logSQLException(e);
|
|
}
|
|
}
|
|
|
|
public void onMessageReceived(Habbo from, String message) {
|
|
Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(this.id);
|
|
|
|
if (habbo == null)
|
|
return;
|
|
|
|
Message chatMessage = new Message(from.getHabboInfo().getId(), this.id, message);
|
|
Emulator.getThreading().run(chatMessage);
|
|
|
|
if (WordFilter.ENABLED_FRIENDCHAT) {
|
|
chatMessage.setMessage(Emulator.getGameEnvironment().getWordFilter().filter(chatMessage.getMessage(), from));
|
|
}
|
|
|
|
habbo.getClient().sendResponse(new FriendChatMessageComposer(chatMessage));
|
|
}
|
|
|
|
@Override
|
|
public void serialize(ServerMessage message) {
|
|
message.appendInt(this.id);
|
|
message.appendString(this.username);
|
|
message.appendInt(this.gender.equals(HabboGender.M) ? 0 : 1);
|
|
message.appendBoolean(this.online == 1);
|
|
message.appendBoolean(this.inRoom); //IN ROOM
|
|
message.appendString(this.look);
|
|
message.appendInt(0);
|
|
message.appendString(this.motto);
|
|
message.appendString("");
|
|
message.appendString("");
|
|
message.appendBoolean(false); //Offline messaging.
|
|
message.appendBoolean(false);
|
|
message.appendBoolean(false);
|
|
message.appendShort(this.relation);
|
|
}
|
|
}
|