2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.messenger ;
import com.eu.habbo.Emulator ;
2019-05-12 23:54:26 +02:00
import com.eu.habbo.habbohotel.modtool.WordFilter ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.users.Habbo ;
import com.eu.habbo.habbohotel.users.HabboGender ;
2019-05-12 23:54:26 +02:00
import com.eu.habbo.messages.ISerialize ;
import com.eu.habbo.messages.ServerMessage ;
import com.eu.habbo.messages.outgoing.friends.FriendChatMessageComposer ;
2018-07-06 15:30:00 +02:00
import java.sql.Connection ;
import java.sql.PreparedStatement ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
2019-05-12 23:54:26 +02:00
public class MessengerBuddy implements Runnable , ISerialize {
2018-07-06 15:30:00 +02:00
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 ;
2019-05-26 20:14:53 +02:00
public MessengerBuddy ( ResultSet set ) {
try {
2018-07-06 15:30:00 +02:00
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 ;
2019-05-26 20:14:53 +02:00
if ( this . online = = 1 ) {
2018-07-06 15:30:00 +02:00
Habbo habbo = Emulator . getGameServer ( ) . getGameClientManager ( ) . getHabbo ( this . username ) ;
2019-05-26 20:14:53 +02:00
if ( habbo ! = null ) {
2018-07-06 15:30:00 +02:00
this . inRoom = habbo . getHabboInfo ( ) . getCurrentRoom ( ) ! = null ;
}
}
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 MessengerBuddy ( ResultSet set , boolean value ) {
try {
2018-07-06 15:30:00 +02:00
this . id = set . getInt ( " id " ) ;
this . username = set . getString ( " username " ) ;
2019-08-05 18:52:28 +02:00
this . look = set . getString ( " look " ) ;
2018-07-06 15:30:00 +02:00
this . relation = 0 ;
this . userOne = 0 ;
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 MessengerBuddy ( int id , String username , String look , Short relation , int userOne ) {
2018-07-06 15:30:00 +02:00
this . id = id ;
this . username = username ;
this . gender = HabboGender . M ;
this . online = 0 ;
this . motto = " " ;
this . look = look ;
this . relation = relation ;
this . userOne = userOne ;
}
2019-05-26 20:14:53 +02:00
public MessengerBuddy ( Habbo habbo , int userOne ) {
2018-07-06 15:30:00 +02:00
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 ;
}
2019-05-26 20:14:53 +02:00
public int getId ( ) {
2018-07-06 15:30:00 +02:00
return this . id ;
}
2019-05-26 20:14:53 +02:00
public String getUsername ( ) {
2018-07-06 15:30:00 +02:00
return this . username ;
}
2019-05-26 20:14:53 +02:00
public void setUsername ( String username ) {
2018-07-06 15:30:00 +02:00
this . username = username ;
}
2019-05-26 20:14:53 +02:00
public HabboGender getGender ( ) {
2018-07-06 15:30:00 +02:00
return this . gender ;
}
2019-05-26 20:14:53 +02:00
public void setGender ( HabboGender gender ) {
2018-07-06 15:30:00 +02:00
this . gender = gender ;
}
2019-05-26 20:14:53 +02:00
public int getOnline ( ) {
2018-07-06 15:30:00 +02:00
return this . online ;
}
2019-05-26 20:14:53 +02:00
public void setOnline ( boolean value ) {
this . online = ( value ? 1 : 0 ) ;
}
public String getLook ( ) {
2018-07-06 15:30:00 +02:00
return this . look ;
}
2019-05-26 20:14:53 +02:00
public void setLook ( String look ) {
2018-07-06 15:30:00 +02:00
this . look = look ;
}
2019-05-26 20:14:53 +02:00
public String getMotto ( ) {
2018-07-06 15:30:00 +02:00
return this . motto ;
}
2019-05-26 20:14:53 +02:00
public short getRelation ( ) {
2018-07-06 15:30:00 +02:00
return this . relation ;
}
2019-05-26 20:14:53 +02:00
public void setRelation ( int relation ) {
this . relation = ( short ) relation ;
Emulator . getThreading ( ) . run ( this ) ;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public boolean inRoom ( ) {
return this . inRoom ;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void inRoom ( boolean value ) {
this . inRoom = value ;
2018-07-06 15:30:00 +02:00
}
@Override
public void run ( ) {
2019-05-26 20:14:53 +02:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " UPDATE messenger_friendships SET relation = ? WHERE user_one_id = ? AND user_two_id = ? " ) ) {
2018-07-06 15:30:00 +02:00
statement . setInt ( 1 , this . relation ) ;
statement . setInt ( 2 , this . userOne ) ;
statement . setInt ( 3 , this . id ) ;
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-12 23:54:26 +02:00
public void onMessageReceived ( Habbo from , String message ) {
Habbo habbo = Emulator . getGameServer ( ) . getGameClientManager ( ) . getHabbo ( this . id ) ;
2019-05-26 20:14:53 +02:00
if ( habbo = = null )
2019-05-12 23:54:26 +02:00
return ;
Message chatMessage = new Message ( from . getHabboInfo ( ) . getId ( ) , this . id , message ) ;
Emulator . getThreading ( ) . run ( chatMessage ) ;
2019-05-26 20:14:53 +02:00
if ( WordFilter . ENABLED_FRIENDCHAT ) {
2019-05-12 23:54:26 +02:00
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 ) ;
}
2018-07-06 15:30:00 +02:00
}