2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.users ;
import com.eu.habbo.Emulator ;
import com.eu.habbo.habbohotel.catalog.CatalogItem ;
import com.eu.habbo.habbohotel.games.Game ;
import com.eu.habbo.habbohotel.games.GamePlayer ;
import com.eu.habbo.habbohotel.permissions.Rank ;
import com.eu.habbo.habbohotel.pets.HorsePet ;
2019-05-04 08:21:43 +02:00
import com.eu.habbo.habbohotel.pets.PetTasks ;
import com.eu.habbo.habbohotel.pets.RideablePet ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.rooms.Room ;
2019-05-04 08:21:43 +02:00
import com.eu.habbo.habbohotel.rooms.RoomTile ;
import com.eu.habbo.habbohotel.rooms.RoomUnit ;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer ;
import com.eu.habbo.threading.runnables.RoomUnitRidePet ;
2019-05-17 15:24:26 +02:00
import com.eu.habbo.util.figure.FigureUtil ;
2018-07-06 15:30:00 +02:00
import gnu.trove.map.hash.TIntIntHashMap ;
import gnu.trove.procedure.TIntIntProcedure ;
import java.sql.Connection ;
import java.sql.PreparedStatement ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
2019-05-04 08:21:43 +02:00
import java.util.ArrayList ;
import java.util.List ;
2018-07-06 15:30:00 +02:00
public class HabboInfo implements Runnable
{
private String username ;
private String motto ;
private String look ;
private HabboGender gender ;
private String mail ;
private String sso ;
private String ipRegister ;
private String ipLogin ;
private int id ;
private int accountCreated ;
private Rank rank ;
private int credits ;
private int lastOnline ;
private int homeRoom ;
private boolean online ;
private int loadingRoom ;
private Room currentRoom ;
private int roomQueueId ;
2019-05-04 08:21:43 +02:00
private RideablePet riding ;
2018-07-06 15:30:00 +02:00
private Class < ? extends Game > currentGame ;
private TIntIntHashMap currencies ;
private GamePlayer gamePlayer ;
private int photoRoomId ;
private int photoTimestamp ;
private String photoURL ;
private String photoJSON ;
private int webPublishTimestamp ;
private String machineID ;
2019-05-11 00:45:07 +02:00
public boolean firstVisit = false ;
2018-07-06 15:30:00 +02:00
public HabboInfo ( ResultSet set )
{
try
{
this . id = set . getInt ( " id " ) ;
this . username = set . getString ( " username " ) ;
this . motto = set . getString ( " motto " ) ;
this . look = set . getString ( " look " ) ;
this . gender = HabboGender . valueOf ( set . getString ( " gender " ) ) ;
this . mail = set . getString ( " mail " ) ;
this . sso = set . getString ( " auth_ticket " ) ;
this . ipRegister = set . getString ( " ip_register " ) ;
this . ipLogin = set . getString ( " ip_current " ) ;
this . rank = Emulator . getGameEnvironment ( ) . getPermissionsManager ( ) . getRank ( set . getInt ( " rank " ) ) ;
if ( this . rank = = null )
{
Emulator . getLogging ( ) . logErrorLine ( " No existing rank found with id " + set . getInt ( " rank " ) + " . Make sure an entry in the permissions table exists. " ) ;
2019-05-15 22:36:11 +02:00
Emulator . getLogging ( ) . logUserLine ( this . username + " has an invalid rank with id " + set . getInt ( " rank " ) + " . Make sure an entry in the permissions table exists. " ) ;
this . rank = Emulator . getGameEnvironment ( ) . getPermissionsManager ( ) . getRank ( 1 ) ;
2018-07-06 15:30:00 +02:00
}
this . accountCreated = set . getInt ( " account_created " ) ;
this . credits = set . getInt ( " credits " ) ;
this . homeRoom = set . getInt ( " home_room " ) ;
this . lastOnline = set . getInt ( " last_online " ) ;
this . machineID = set . getString ( " machine_id " ) ;
this . online = false ;
this . currentRoom = null ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
this . loadCurrencies ( ) ;
}
private void loadCurrencies ( )
{
this . currencies = new TIntIntHashMap ( ) ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " SELECT * FROM users_currency WHERE user_id = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
this . currencies . put ( set . getInt ( " type " ) , set . getInt ( " amount " ) ) ;
}
}
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
private void saveCurrencies ( )
{
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO users_currency (user_id, type, amount) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE amount = ? " ) )
{
this . currencies . forEachEntry ( new TIntIntProcedure ( )
{
@Override
public boolean execute ( int a , int b )
{
try
{
2019-03-18 02:22:00 +01:00
statement . setInt ( 1 , HabboInfo . this . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
statement . setInt ( 2 , a ) ;
statement . setInt ( 3 , b ) ;
statement . setInt ( 4 , b ) ;
statement . addBatch ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
return true ;
}
} ) ;
statement . executeBatch ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
public int getCurrencyAmount ( int type )
{
return this . currencies . get ( type ) ;
}
public TIntIntHashMap getCurrencies ( )
{
return this . currencies ;
}
public void addCurrencyAmount ( int type , int amount )
{
this . currencies . adjustOrPutValue ( type , amount , amount ) ;
this . run ( ) ;
}
public void setCurrencyAmount ( int type , int amount )
{
this . currencies . put ( type , amount ) ;
this . run ( ) ;
}
public int getId ( )
{
return this . id ;
}
public String getUsername ( )
{
return this . username ;
}
public void setUsername ( String username )
{
this . username = username ;
}
public String getMotto ( )
{
return this . motto ;
}
public void setMotto ( String motto )
{
this . motto = motto ;
}
public Rank getRank ( )
{
return this . rank ;
}
public void setRank ( Rank rank )
{
this . rank = rank ;
}
public String getLook ( )
{
return this . look ;
}
2019-05-17 15:24:26 +02:00
public void setLook ( String look ) {
this . look = look ;
}
2018-07-06 15:30:00 +02:00
public HabboGender getGender ( )
{
return this . gender ;
}
public void setGender ( HabboGender gender ) {
this . gender = gender ;
}
public String getMail ( ) {
2019-03-18 02:22:00 +01:00
return this . mail ;
2018-07-06 15:30:00 +02:00
}
public void setMail ( String mail ) {
this . mail = mail ;
}
public String getSso ( ) {
2019-03-18 02:22:00 +01:00
return this . sso ;
2018-07-06 15:30:00 +02:00
}
public void setSso ( String sso ) {
this . sso = sso ;
}
public String getIpRegister ( ) {
2019-03-18 02:22:00 +01:00
return this . ipRegister ;
2018-07-06 15:30:00 +02:00
}
public void setIpRegister ( String ipRegister ) {
this . ipRegister = ipRegister ;
}
public String getIpLogin ( )
{
return this . ipLogin ;
}
public void setIpLogin ( String ipLogin )
{
this . ipLogin = ipLogin ;
}
public int getAccountCreated ( )
{
return this . accountCreated ;
}
public void setAccountCreated ( int accountCreated ) {
this . accountCreated = accountCreated ;
}
public boolean canBuy ( CatalogItem item )
{
return this . credits > = item . getCredits ( ) & & this . getCurrencies ( ) . get ( item . getPointsType ( ) ) > = item . getPoints ( ) ;
}
public int getCredits ( )
{
2019-03-18 02:22:00 +01:00
return this . credits ;
2018-07-06 15:30:00 +02:00
}
public void setCredits ( int credits )
{
this . credits = credits ;
this . run ( ) ;
}
public void addCredits ( int credits )
{
this . credits + = credits ;
this . run ( ) ;
}
public int getPixels ( )
{
return this . getCurrencyAmount ( 0 ) ;
}
public void setPixels ( int pixels )
{
this . setCurrencyAmount ( 0 , pixels ) ;
this . run ( ) ;
}
public void addPixels ( int pixels )
{
this . addCurrencyAmount ( 0 , pixels ) ;
this . run ( ) ;
}
public int getLastOnline ( )
{
return this . lastOnline ;
}
public void setLastOnline ( int lastOnline )
{
this . lastOnline = lastOnline ;
}
public int getHomeRoom ( )
{
return this . homeRoom ;
}
public void setHomeRoom ( int homeRoom )
{
this . homeRoom = homeRoom ;
}
public boolean isOnline ( )
{
return this . online ;
}
public void setOnline ( boolean value )
{
this . online = value ;
}
public int getLoadingRoom ( )
{
return this . loadingRoom ;
}
public void setLoadingRoom ( int loadingRoom )
{
this . loadingRoom = loadingRoom ;
}
public Room getCurrentRoom ( )
{
return this . currentRoom ;
}
public void setCurrentRoom ( Room room )
{
this . currentRoom = room ;
}
public int getRoomQueueId ( )
{
return this . roomQueueId ;
}
public void setRoomQueueId ( int roomQueueId )
{
this . roomQueueId = roomQueueId ;
}
2019-05-04 08:21:43 +02:00
public RideablePet getRiding ( )
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
return this . riding ;
2018-07-06 15:30:00 +02:00
}
2019-05-04 08:21:43 +02:00
public void dismountPet ( ) {
this . dismountPet ( false ) ;
}
public void dismountPet ( boolean isRemoving ) {
if ( this . getRiding ( ) = = null )
return ;
Habbo habbo = this . getCurrentRoom ( ) . getHabbo ( this . getId ( ) ) ;
if ( habbo = = null )
return ;
RideablePet riding = this . getRiding ( ) ;
riding . setRider ( null ) ;
riding . setTask ( PetTasks . FREE ) ;
this . setRiding ( null ) ;
Room room = this . getCurrentRoom ( ) ;
if ( room ! = null )
room . giveEffect ( habbo , 0 , - 1 ) ;
RoomUnit roomUnit = habbo . getRoomUnit ( ) ;
if ( roomUnit = = null )
return ;
roomUnit . setZ ( riding . getRoomUnit ( ) . getZ ( ) ) ;
roomUnit . setPreviousLocationZ ( riding . getRoomUnit ( ) . getZ ( ) ) ;
roomUnit . stopWalking ( ) ;
room . sendComposer ( new RoomUserStatusComposer ( roomUnit ) . compose ( ) ) ;
List < RoomTile > availableTiles = isRemoving ? new ArrayList < > ( ) : this . getCurrentRoom ( ) . getLayout ( ) . getWalkableTilesAround ( roomUnit . getCurrentLocation ( ) ) ;
RoomTile tile = availableTiles . isEmpty ( ) ? roomUnit . getCurrentLocation ( ) : availableTiles . get ( 0 ) ;
roomUnit . setGoalLocation ( tile ) ;
roomUnit . statusUpdate ( true ) ;
}
public void setRiding ( RideablePet riding )
2018-07-06 15:30:00 +02:00
{
this . riding = riding ;
}
public Class < ? extends Game > getCurrentGame ( )
{
return this . currentGame ;
}
public void setCurrentGame ( Class < ? extends Game > currentGame )
{
this . currentGame = currentGame ;
}
public boolean isInGame ( )
{
return this . currentGame ! = null ;
}
public synchronized GamePlayer getGamePlayer ( )
{
return this . gamePlayer ;
}
public synchronized void setGamePlayer ( GamePlayer gamePlayer )
{
this . gamePlayer = gamePlayer ;
}
public int getPhotoRoomId ( )
{
return this . photoRoomId ;
}
public void setPhotoRoomId ( int roomId )
{
this . photoRoomId = roomId ;
}
public int getPhotoTimestamp ( )
{
return this . photoTimestamp ;
}
public void setPhotoTimestamp ( int photoTimestamp )
{
this . photoTimestamp = photoTimestamp ;
}
public String getPhotoURL ( )
{
return this . photoURL ;
}
public void setPhotoURL ( String photoURL )
{
this . photoURL = photoURL ;
}
public String getPhotoJSON ( )
{
return this . photoJSON ;
}
public void setPhotoJSON ( String photoJSON )
{
this . photoJSON = photoJSON ;
}
public int getWebPublishTimestamp ( )
{
return this . webPublishTimestamp ;
}
public void setWebPublishTimestamp ( int webPublishTimestamp )
{
this . webPublishTimestamp = webPublishTimestamp ;
}
public String getMachineID ( )
{
return this . machineID ;
}
public void setMachineID ( String machineID )
{
this . machineID = machineID ;
}
@Override
public void run ( )
{
this . saveCurrencies ( ) ;
2019-04-22 01:42:00 +02:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " UPDATE users SET motto = ?, online = ?, look = ?, gender = ?, credits = ?, last_login = ?, last_online = ?, home_room = ?, ip_current = ?, `rank` = ?, machine_id = ?, username = ? WHERE id = ? " ) )
2018-07-06 15:30:00 +02:00
{
statement . setString ( 1 , this . motto ) ;
statement . setString ( 2 , this . online ? " 1 " : " 0 " ) ;
statement . setString ( 3 , this . look ) ;
statement . setString ( 4 , this . gender . name ( ) ) ;
statement . setInt ( 5 , this . credits ) ;
statement . setInt ( 7 , this . lastOnline ) ;
statement . setInt ( 6 , Emulator . getIntUnixTimestamp ( ) ) ;
statement . setInt ( 8 , this . homeRoom ) ;
statement . setString ( 9 , this . ipLogin ) ;
2019-05-15 22:36:11 +02:00
statement . setInt ( 10 , this . rank ! = null ? this . rank . getId ( ) : 1 ) ;
2018-07-06 15:30:00 +02:00
statement . setString ( 11 , this . machineID ) ;
statement . setString ( 12 , this . username ) ;
statement . setInt ( 13 , this . id ) ;
statement . executeUpdate ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
public int getBonusRarePoints ( )
{
return this . getCurrencyAmount ( Emulator . getConfig ( ) . getInt ( " hotelview.promotional.points.type " ) ) ;
}
2019-05-11 00:45:07 +02:00
public HabboStats getHabboStats ( ) {
Habbo habbo = Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( this . getId ( ) ) ;
if ( habbo ! = null ) {
return habbo . getHabboStats ( ) ;
}
return HabboStats . load ( this ) ;
}
2018-07-06 15:30:00 +02:00
}