Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java

1791 lines
59 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
import com.eu.habbo.core.RoomUserPetComposer;
import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot;
2019-05-04 22:41:18 +02:00
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame;
import com.eu.habbo.habbohotel.games.football.FootballGame;
import com.eu.habbo.habbohotel.games.freeze.FreezeGame;
import com.eu.habbo.habbohotel.games.tag.BunnyrunGame;
import com.eu.habbo.habbohotel.games.tag.IceTagGame;
import com.eu.habbo.habbohotel.games.tag.RollerskateGame;
import com.eu.habbo.habbohotel.games.tag.TagGame;
import com.eu.habbo.habbohotel.games.wired.WiredGame;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.guilds.Guild;
2018-09-28 21:25:00 +02:00
import com.eu.habbo.habbohotel.items.interactions.InteractionWired;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
import com.eu.habbo.habbohotel.navigation.NavigatorFilterComparator;
import com.eu.habbo.habbohotel.navigation.NavigatorFilterField;
import com.eu.habbo.habbohotel.navigation.NavigatorManager;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.pets.Pet;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.pets.PetData;
import com.eu.habbo.habbohotel.pets.PetTasks;
import com.eu.habbo.habbohotel.polls.Poll;
import com.eu.habbo.habbohotel.polls.PollManager;
import com.eu.habbo.habbohotel.users.*;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.incoming.users.UserNuxEvent;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericErrorMessagesComposer;
import com.eu.habbo.messages.outgoing.hotelview.HotelViewComposer;
import com.eu.habbo.messages.outgoing.polls.PollStartComposer;
import com.eu.habbo.messages.outgoing.polls.infobus.SimplePollAnswersComposer;
import com.eu.habbo.messages.outgoing.polls.infobus.SimplePollStartComposer;
import com.eu.habbo.messages.outgoing.rooms.*;
import com.eu.habbo.messages.outgoing.rooms.items.RoomFloorItemsComposer;
import com.eu.habbo.messages.outgoing.rooms.items.RoomWallItemsComposer;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer;
import com.eu.habbo.messages.outgoing.rooms.promotions.RoomPromotionMessageComposer;
import com.eu.habbo.messages.outgoing.rooms.users.*;
import com.eu.habbo.messages.outgoing.users.MutedWhisperComposer;
import com.eu.habbo.plugin.events.navigator.NavigatorRoomCreatedEvent;
import com.eu.habbo.plugin.events.rooms.RoomUncachedEvent;
import com.eu.habbo.plugin.events.users.UserEnterRoomEvent;
2018-11-17 14:28:00 +01:00
import com.eu.habbo.plugin.events.users.UserExitRoomEvent;
2018-07-06 15:30:00 +02:00
import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.hash.THashMap;
import gnu.trove.procedure.TIntProcedure;
import gnu.trove.procedure.TObjectProcedure;
import gnu.trove.set.hash.THashSet;
import java.sql.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class RoomManager
{
//Configuration. Loaded from database & updated accordingly.
public static int MAXIMUM_ROOMS_USER = 25;
public static int MAXIMUM_ROOMS_VIP = 35;
public static int HOME_ROOM_ID = 0;
2019-04-22 01:42:00 +02:00
public static boolean SHOW_PUBLIC_IN_POPULAR_TAB = false;
2018-07-06 15:30:00 +02:00
private final THashMap<Integer, RoomCategory> roomCategories;
private final List<String> mapNames;
private final ConcurrentHashMap<Integer, Room> activeRooms;
2019-05-04 22:41:18 +02:00
private final ArrayList<Class<? extends Game>> gameTypes;
2018-07-06 15:30:00 +02:00
public RoomManager()
{
long millis = System.currentTimeMillis();
2018-09-28 21:25:00 +02:00
this.roomCategories = new THashMap<>();
this.mapNames = new ArrayList<>();
this.activeRooms = new ConcurrentHashMap<>();
2018-07-06 15:30:00 +02:00
this.loadRoomCategories();
this.loadRoomModels();
2019-05-04 22:41:18 +02:00
this.gameTypes = new ArrayList<>();
registerGameType(BattleBanzaiGame.class);
registerGameType(FreezeGame.class);
registerGameType(WiredGame.class);
registerGameType(FootballGame.class);
registerGameType(BunnyrunGame.class);
registerGameType(IceTagGame.class);
registerGameType(RollerskateGame.class);
2018-07-06 15:30:00 +02:00
Emulator.getLogging().logStart("Room Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)");
}
public void loadRoomModels()
{
this.mapNames.clear();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM room_models"))
{
while(set.next())
{
this.mapNames.add(set.getString("name"));
}
}
catch(SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
public CustomRoomLayout loadCustomLayout(Room room)
{
2018-10-07 00:28:00 +02:00
CustomRoomLayout layout = null;
2018-07-06 15:30:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_models_custom WHERE id = ? LIMIT 1"))
{
statement.setInt(1, room.getId());
try (ResultSet set = statement.executeQuery())
{
if (set.next())
{
layout = new CustomRoomLayout(set, room);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
2018-10-07 00:28:00 +02:00
return layout;
2018-07-06 15:30:00 +02:00
}
private void loadRoomCategories()
{
this.roomCategories.clear();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM navigator_flatcats"))
{
while(set.next())
{
this.roomCategories.put(set.getInt("id"), new RoomCategory(set));
}
}
catch(SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
public void loadPublicRooms()
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM rooms WHERE is_public = ? OR is_staff_picked = ? ORDER BY id DESC"))
{
statement.setString(1, "1");
statement.setString(2, "1");
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
Room room = new Room(set);
room.preventUncaching = true;
this.activeRooms.put(set.getInt("id"), room);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
private static final int page = 0;
2018-10-07 00:28:00 +02:00
public THashMap<Integer, List<Room>> findRooms(NavigatorFilterField filterField, String value, int category, boolean showInvisible)
2018-07-06 15:30:00 +02:00
{
2018-09-28 21:25:00 +02:00
THashMap<Integer, List<Room>> rooms = new THashMap<>();
2018-10-07 00:28:00 +02:00
String query = filterField.databaseQuery + " AND rooms.state NOT LIKE " + (showInvisible ? "''" : "'invisible'") + (category >= 0 ? "AND rooms.category = '" + category + "'" : "") + " ORDER BY rooms.users, rooms.id DESC LIMIT " + (page * NavigatorManager.MAXIMUM_RESULTS_PER_PAGE) + "" + ((page * NavigatorManager.MAXIMUM_RESULTS_PER_PAGE) + NavigatorManager.MAXIMUM_RESULTS_PER_PAGE);
2018-07-06 15:30:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(query))
{
statement.setString(1, (filterField.comparator == NavigatorFilterComparator.EQUALS ? value : "%" + value + "%"));
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
Room room = this.activeRooms.get(set.getInt("id"));
if (room == null)
{
room = new Room(set);
this.activeRooms.put(set.getInt("id"), room);
}
if (!rooms.containsKey(set.getInt("category")))
{
2018-09-28 21:25:00 +02:00
rooms.put(set.getInt("category"), new ArrayList<>());
2018-07-06 15:30:00 +02:00
}
rooms.get(set.getInt("category")).add(room);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return rooms;
}
public RoomCategory getCategory(int id)
{
for (RoomCategory category : this.roomCategories.values())
{
if (category.getId() == id)
return category;
}
return null;
}
public RoomCategory getCategory(String name)
{
for (RoomCategory category : this.roomCategories.values())
{
if (category.getCaption().equalsIgnoreCase(name))
{
return category;
}
}
return null;
}
public RoomCategory getCategoryBySafeCaption(String safeCaption)
{
for (RoomCategory category : this.roomCategories.values())
{
if (category.getCaptionSave().equalsIgnoreCase(safeCaption))
{
return category;
}
}
return null;
}
public List<RoomCategory> roomCategoriesForHabbo(Habbo habbo)
{
2018-09-28 21:25:00 +02:00
List<RoomCategory> categories = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(RoomCategory category : this.roomCategories.values())
{
if(category.getMinRank() <= habbo.getHabboInfo().getRank().getId())
categories.add(category);
}
Collections.sort(categories);
return categories;
}
public boolean hasCategory(int categoryId, Habbo habbo)
{
for(RoomCategory category : this.roomCategories.values())
{
if(category.getId() == categoryId)
{
if(category.getMinRank() <= habbo.getHabboInfo().getRank().getId())
{
return true;
}
}
}
return false;
}
public THashMap<Integer, RoomCategory> getRoomCategories()
{
return this.roomCategories;
}
public List<Room> getRoomsByScore()
{
2019-03-18 02:22:00 +01:00
List<Room> rooms = new ArrayList<>(this.activeRooms.values());
rooms.sort(Room.SORT_SCORE);
2018-07-06 15:30:00 +02:00
return rooms;
}
public List<Room> getActiveRooms(int categoryId)
{
2018-09-28 21:25:00 +02:00
List<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for (Room room : this.activeRooms.values())
{
if (categoryId == room.getCategory() || categoryId == -1)
rooms.add(room);
}
Collections.sort(rooms);
return rooms;
}
//TODO Move to HabboInfo class.
public List<Room> getRoomsForHabbo(Habbo habbo)
{
2018-09-28 21:25:00 +02:00
List<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : this.activeRooms.values())
{
if(room.getOwnerId() == habbo.getHabboInfo().getId())
rooms.add(room);
}
2019-03-18 02:22:00 +01:00
rooms.sort(Room.SORT_ID);
2018-07-06 15:30:00 +02:00
return rooms;
}
public List<Room> getRoomsForHabbo(String username)
{
Habbo h = Emulator.getGameEnvironment().getHabboManager().getHabbo(username);
if(h != null)
{
2019-03-18 02:22:00 +01:00
return this.getRoomsForHabbo(h);
2018-07-06 15:30:00 +02:00
}
2018-09-28 21:25:00 +02:00
List<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM rooms WHERE owner_name = ? ORDER BY id DESC LIMIT 25"))
{
statement.setString(1, username);
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
rooms.add(this.loadRoom(set.getInt("id")));
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return rooms;
}
public Room loadRoom(int id)
2019-04-22 01:42:00 +02:00
{
return loadRoom(id, false);
}
public Room loadRoom(int id, boolean loadData)
2018-07-06 15:30:00 +02:00
{
Room room = null;
if(this.activeRooms.containsKey(id))
{
room = this.activeRooms.get(id);
2019-04-22 01:42:00 +02:00
if (loadData)
2018-07-06 15:30:00 +02:00
{
2019-04-22 01:42:00 +02:00
if (room.isPreLoaded() && !room.isLoaded())
{
room.loadData();
}
2018-07-06 15:30:00 +02:00
}
return room;
}
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM rooms WHERE id = ? LIMIT 1"))
{
statement.setInt(1, id);
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
room = new Room(set);
2019-04-22 01:42:00 +02:00
if (loadData)
{
room.loadData();
}
2018-07-06 15:30:00 +02:00
}
}
if(room != null)
{
this.activeRooms.put(room.getId(), room);
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return room;
}
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public Room createRoom(int ownerId, String ownerName, String name, String description, String modelName, int usersMax, int categoryId)
{
Room room = null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO rooms (owner_id, owner_name, name, description, model, users_max, category) VALUES (?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS))
{
statement.setInt(1, ownerId);
statement.setString(2, ownerName);
statement.setString(3, name);
statement.setString(4, description);
statement.setString(5, modelName);
statement.setInt(6, usersMax);
statement.setInt(7, categoryId);
statement.execute();
try (ResultSet set = statement.getGeneratedKeys())
{
if (set.next())
room = this.loadRoom(set.getInt(1));
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return room;
}
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public Room createRoomForHabbo(Habbo habbo, String name, String description, String modelName, int usersMax, int categoryId)
{
Room room = this.createRoom(habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername(), name, description, modelName, usersMax, categoryId);
Emulator.getPluginManager().fireEvent(new NavigatorRoomCreatedEvent(habbo, room));
return room;
}
public void loadRoomsForHabbo(Habbo habbo)
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM rooms WHERE owner_id = ?"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
if (!this.activeRooms.containsKey(set.getInt("id")))
this.activeRooms.put(set.getInt("id"), new Room(set));
}
}
}
catch(SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
public void unloadRoomsForHabbo(Habbo habbo)
{
2018-09-28 21:25:00 +02:00
List<Room> roomsToDispose = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : this.activeRooms.values())
{
2019-03-18 02:22:00 +01:00
if(!room.isPublicRoom() && !room.isStaffPromotedRoom() && room.getOwnerId() == habbo.getHabboInfo().getId() && room.getUserCount() == 0 && !this.roomCategories.get(room.getCategory()).isPublic())
2018-07-06 15:30:00 +02:00
{
roomsToDispose.add(room);
}
}
for(Room room : roomsToDispose)
{
if (Emulator.getPluginManager().fireEvent(new RoomUncachedEvent(room)).isCancelled())
continue;
this.activeRooms.remove(room.getId());
room.dispose();
}
}
public void clearInactiveRooms()
{
2018-09-28 21:25:00 +02:00
THashSet<Room> roomsToDispose = new THashSet<>();
2018-07-06 15:30:00 +02:00
for(Room room : this.activeRooms.values())
{
2019-03-18 02:22:00 +01:00
if(!room.isPublicRoom() && !room.isStaffPromotedRoom() && !Emulator.getGameServer().getGameClientManager().containsHabbo(room.getOwnerId()) && room.isPreLoaded() && !this.roomCategories.get(room.getCategory()).isPublic())
2018-07-06 15:30:00 +02:00
{
roomsToDispose.add(room);
}
}
for(Room room : roomsToDispose)
{
2018-12-22 11:39:00 +01:00
room.dispose();
2018-07-06 15:30:00 +02:00
if(room.getUserCount() == 0)
this.activeRooms.remove(room.getId());
}
}
public boolean layoutExists(String name)
{
return this.mapNames.contains(name);
}
public RoomLayout loadLayout(String name, Room room)
{
RoomLayout layout = null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_models WHERE name LIKE ? LIMIT 1"))
{
statement.setString(1, name);
try (ResultSet set = statement.executeQuery())
{
if (set.next())
{
layout = new RoomLayout(set, room);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return layout;
}
public void unloadRoom(Room room)
{
room.dispose();
}
2018-09-12 18:45:00 +02:00
public void uncacheRoom(Room room)
{
this.activeRooms.remove(room.getId());
}
2018-07-06 15:30:00 +02:00
public void voteForRoom(Habbo habbo, Room room)
{
if(habbo.getHabboInfo().getCurrentRoom() != null && room != null && habbo.getHabboInfo().getCurrentRoom() == room)
{
if(this.hasVotedForRoom(habbo, room))
return;
room.setScore(room.getScore() + 1);
room.setNeedsUpdate(true);
habbo.getHabboStats().votedRooms.push(room.getId());
for(Habbo h : room.getHabbos())
{
h.getClient().sendResponse(new RoomScoreComposer(room.getScore(), !this.hasVotedForRoom(h, room)));
}
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_votes VALUES (?, ?)"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(2, room.getId());
statement.execute();
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
}
boolean hasVotedForRoom(Habbo habbo, Room room)
{
if(room.getOwnerId() == habbo.getHabboInfo().getId())
return true;
for(int i : habbo.getHabboStats().votedRooms.toArray())
{
if(i == room.getId())
return true;
}
return false;
}
public Room getRoom(int roomId)
{
return this.activeRooms.get(roomId);
}
public ArrayList<Room> getActiveRooms()
{
2018-09-28 21:25:00 +02:00
return new ArrayList<>(this.activeRooms.values());
2018-07-06 15:30:00 +02:00
}
public int loadedRoomsCount()
{
return this.activeRooms.size();
}
public void enterRoom(Habbo habbo, int roomId, String password)
{
this.enterRoom(habbo, roomId, password, false, null);
}
public void enterRoom(Habbo habbo, int roomId, String password, boolean overrideChecks)
{
this.enterRoom(habbo, roomId, password, overrideChecks, null);
}
public void enterRoom(Habbo habbo, int roomId, String password, boolean overrideChecks, RoomTile doorLocation)
{
2019-04-22 01:42:00 +02:00
Room room = this.loadRoom(roomId, true);
2018-07-06 15:30:00 +02:00
if(room == null)
return;
if (habbo.getHabboInfo().getLoadingRoom() != 0 && room.getId() != habbo.getHabboInfo().getLoadingRoom())
{
habbo.getClient().sendResponse(new HotelViewComposer());
habbo.getHabboInfo().setLoadingRoom(0);
return;
}
if(Emulator.getPluginManager().fireEvent(new UserEnterRoomEvent(habbo, room)).isCancelled())
{
if(habbo.getHabboInfo().getCurrentRoom() == null)
{
habbo.getClient().sendResponse(new HotelViewComposer());
habbo.getHabboInfo().setLoadingRoom(0);
return;
}
}
2018-09-12 18:45:00 +02:00
if (room.isBanned(habbo) && !habbo.hasPermission(Permission.ACC_ANYROOMOWNER) && !habbo.hasPermission("acc_enteranyroom"))
2018-07-06 15:30:00 +02:00
{
habbo.getClient().sendResponse(new RoomEnterErrorComposer(RoomEnterErrorComposer.ROOM_ERROR_BANNED));
return;
}
if (habbo.getHabboInfo().getRoomQueueId() != roomId)
{
Room queRoom = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId);
if (queRoom != null)
{
queRoom.removeFromQueue(habbo);
}
}
if(overrideChecks ||
room.isOwner(habbo) ||
room.getState() == RoomState.OPEN ||
room.getState() == RoomState.INVISIBLE ||
2018-09-12 18:45:00 +02:00
habbo.hasPermission(Permission.ACC_ANYROOMOWNER) ||
2018-07-06 15:30:00 +02:00
habbo.hasPermission("acc_enteranyroom") ||
room.hasRights(habbo) ||
(room.hasGuild() && room.guildRightLevel(habbo) > 2))
{
this.openRoom(habbo, room, doorLocation);
}
else if(room.getState() == RoomState.LOCKED)
{
boolean rightsFound = false;
synchronized (room.roomUnitLock)
{
for (Habbo current : room.getHabbos())
{
if (room.hasRights(current) || current.getHabboInfo().getId() == room.getOwnerId() || (room.hasGuild() && room.guildRightLevel(current) >= 2))
{
current.getClient().sendResponse(new DoorbellAddUserComposer(habbo.getHabboInfo().getUsername()));
rightsFound = true;
}
}
}
if(!rightsFound)
{
habbo.getClient().sendResponse(new RoomAccessDeniedComposer(""));
habbo.getClient().sendResponse(new HotelViewComposer());
habbo.getHabboInfo().setLoadingRoom(0);
return;
}
habbo.getHabboInfo().setRoomQueueId(roomId);
habbo.getClient().sendResponse(new DoorbellAddUserComposer(""));
room.addToQueue(habbo);
}
else if(room.getState() == RoomState.PASSWORD)
{
if(room.getPassword().equalsIgnoreCase(password))
this.openRoom(habbo, room, doorLocation);
else
{
habbo.getClient().sendResponse(new GenericErrorMessagesComposer(-100002));
habbo.getClient().sendResponse(new HotelViewComposer());
habbo.getHabboInfo().setLoadingRoom(0);
}
}
}
void openRoom(Habbo habbo, Room room, RoomTile doorLocation)
{
2018-09-28 21:25:00 +02:00
if (room == null || room.getLayout() == null)
2018-07-06 15:30:00 +02:00
return;
if (Emulator.getConfig().getBoolean("hotel.room.enter.logs"))
{
this.logEnter(habbo, room);
}
if (habbo.getHabboInfo().getRoomQueueId() > 0)
{
Room r = Emulator.getGameEnvironment().getRoomManager().getRoom(habbo.getHabboInfo().getRoomQueueId());
if (r != null)
{
r.removeFromQueue(habbo);
}
}
habbo.getHabboInfo().setRoomQueueId(0);
habbo.getClient().sendResponse(new HideDoorbellComposer(""));
habbo.setRoomUnit(new RoomUnit());
2018-07-06 15:30:00 +02:00
2018-09-12 18:45:00 +02:00
habbo.getRoomUnit().clearStatus();
2018-07-06 15:30:00 +02:00
if (habbo.getRoomUnit().getCurrentLocation() == null)
{
habbo.getRoomUnit().setLocation(doorLocation != null ? doorLocation : room.getLayout().getDoorTile());
habbo.getRoomUnit().setZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight());
if(doorLocation == null) {
habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
}
else {
habbo.getRoomUnit().isTeleporting = true;
HabboItem topItem = room.getTopItemAt(doorLocation.x, doorLocation.y);
if(topItem != null) {
habbo.getRoomUnit().setRotation(RoomUserRotation.values()[topItem.getRotation()]);
}
}
2018-07-06 15:30:00 +02:00
}
2018-07-06 15:30:00 +02:00
habbo.getRoomUnit().setRoomUnitType(RoomUnitType.USER);
if(room.isBanned(habbo))
{
habbo.getClient().sendResponse(new RoomEnterErrorComposer(RoomEnterErrorComposer.ROOM_ERROR_BANNED));
return;
}
if (room.getUserCount() >= room.getUsersMax() && !habbo.hasPermission("acc_fullrooms") && !room.hasRights(habbo))
{
habbo.getClient().sendResponse(new RoomEnterErrorComposer(RoomEnterErrorComposer.ROOM_ERROR_GUESTROOM_FULL));
return;
}
2018-09-12 18:45:00 +02:00
habbo.getRoomUnit().clearStatus();
2018-07-06 15:30:00 +02:00
habbo.getRoomUnit().cmdTeleport = false;
habbo.getClient().sendResponse(new RoomOpenComposer());
habbo.getRoomUnit().setInRoom(true);
if (habbo.getHabboInfo().getCurrentRoom() != room && habbo.getHabboInfo().getCurrentRoom() != null)
{
habbo.getHabboInfo().getCurrentRoom().removeHabbo(habbo);
}
else if (!habbo.getHabboStats().blockFollowing && habbo.getHabboInfo().getCurrentRoom() == null)
2018-07-06 15:30:00 +02:00
{
habbo.getMessenger().connectionChanged(habbo, true, true);
}
if (habbo.getHabboInfo().getLoadingRoom() != 0)
{
Room oldRoom = Emulator.getGameEnvironment().getRoomManager().getRoom(habbo.getHabboInfo().getLoadingRoom());
if (oldRoom != null)
{
oldRoom.removeFromQueue(habbo);
}
}
habbo.getHabboInfo().setLoadingRoom(room.getId());
habbo.getClient().sendResponse(new RoomModelComposer(room));
if (!room.getWallPaint().equals("0.0"))
habbo.getClient().sendResponse(new RoomPaintComposer("wallpaper", room.getWallPaint()));
if (!room.getFloorPaint().equals("0.0"))
habbo.getClient().sendResponse(new RoomPaintComposer("floor", room.getFloorPaint()));
habbo.getClient().sendResponse(new RoomPaintComposer("landscape", room.getBackgroundPaint()));
room.refreshRightsForHabbo(habbo);
habbo.getClient().sendResponse(new RoomScoreComposer(room.getScore(), !this.hasVotedForRoom(habbo, room)));
2018-11-17 14:28:00 +01:00
habbo.getRoomUnit().setFastWalk(habbo.getRoomUnit().isFastWalk() && habbo.hasPermission("cmd_fastwalk", room.hasRights(habbo)));
2018-07-06 15:30:00 +02:00
if (room.isPromoted())
{
habbo.getClient().sendResponse(new RoomPromotionMessageComposer(room, room.getPromotion()));
}
else
{
habbo.getClient().sendResponse(new RoomPromotionMessageComposer(null, null));
}
if(room.getOwnerId() != habbo.getHabboInfo().getId())
{
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomEntry"));
}
}
public void enterRoom(final Habbo habbo, final Room room)
{
if (habbo.getHabboInfo().getLoadingRoom() != room.getId())
{
if (habbo.getHabboInfo().getLoadingRoom() != 0)
{
habbo.getClient().sendResponse(new HotelViewComposer());
}
return;
}
2018-09-28 21:25:00 +02:00
habbo.getRoomUnit().removeStatus(RoomUnitStatus.FLAT_CONTROL);
2018-07-06 15:30:00 +02:00
habbo.getHabboInfo().setLoadingRoom(0);
habbo.getHabboInfo().setCurrentRoom(room);
habbo.getRoomUnit().setPathFinderRoom(room);
habbo.getRoomUnit().setHandItem(0);
habbo.getRoomUnit().setRightsLevel(RoomRightLevels.NONE);
room.refreshRightsForHabbo(habbo);
if (habbo.getRoomUnit().isKicked && !habbo.getRoomUnit().canWalk())
{
habbo.getRoomUnit().setCanWalk(true);
}
habbo.getRoomUnit().isKicked = false;
if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting)
2018-07-06 15:30:00 +02:00
{
RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY());
if (doorTile != null)
{
2019-05-04 02:23:58 +02:00
habbo.getRoomUnit().setLocation(doorTile);
2018-07-06 15:30:00 +02:00
habbo.getRoomUnit().setZ(doorTile.getStackHeight());
}
habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
}
2018-07-06 15:30:00 +02:00
habbo.getRoomUnit().setPathFinderRoom(room);
habbo.getRoomUnit().resetIdleTimer();
2018-09-28 21:25:00 +02:00
habbo.getRoomUnit().setInvisible(false);
2018-07-06 15:30:00 +02:00
room.addHabbo(habbo);
2018-09-28 21:25:00 +02:00
List<Habbo> habbos = new ArrayList<>();
2018-07-06 15:30:00 +02:00
if (!room.getCurrentHabbos().isEmpty())
{
2018-09-28 21:25:00 +02:00
2018-07-06 15:30:00 +02:00
room.sendComposer(new RoomUsersComposer(habbo).compose());
room.sendComposer(new RoomUserStatusComposer(habbo.getRoomUnit()).compose());
2018-09-28 21:25:00 +02:00
for (Habbo h : room.getHabbos())
{
if (!h.getRoomUnit().isInvisible())
{
habbos.add(h);
}
}
2018-07-06 15:30:00 +02:00
synchronized (room.roomUnitLock)
{
2018-09-28 21:25:00 +02:00
habbo.getClient().sendResponse(new RoomUsersComposer(habbos));
habbo.getClient().sendResponse(new RoomUserStatusComposer(habbos));
2018-07-06 15:30:00 +02:00
}
if (habbo.getHabboStats().guild != 0)
{
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(habbo.getHabboStats().guild);
if (guild != null)
{
room.sendComposer(new RoomUsersAddGuildBadgeComposer(guild).compose());
}
}
2019-03-18 02:22:00 +01:00
int effect = habbo.getInventory().getEffectsComponent().activatedEffect;
2018-07-06 15:30:00 +02:00
if (effect == 0)
{
effect = habbo.getHabboInfo().getRank().getRoomEffect();
}
2019-03-18 02:22:00 +01:00
room.giveEffect(habbo.getRoomUnit(), effect, -1);
2018-07-06 15:30:00 +02:00
}
habbo.getClient().sendResponse(new RoomUsersComposer(room.getCurrentBots().valueCollection(), true));
if (!room.getCurrentBots().isEmpty())
{
TIntObjectIterator<Bot> botIterator = room.getCurrentBots().iterator();
for (int i = room.getCurrentBots().size(); i-- > 0; )
{
try
{
botIterator.advance();
}
catch (NoSuchElementException e)
{
break;
}
Bot bot = botIterator.value();
if (!bot.getRoomUnit().getDanceType().equals(DanceType.NONE))
{
habbo.getClient().sendResponse(new RoomUserDanceComposer(bot.getRoomUnit()));
}
habbo.getClient().sendResponse(new RoomUserStatusComposer(bot.getRoomUnit()));
}
}
habbo.getClient().sendResponse(new RoomPaneComposer(room, room.isOwner(habbo)));
habbo.getClient().sendResponse(new RoomThicknessComposer(room));
habbo.getClient().sendResponse(new RoomDataComposer(room, habbo.getClient().getHabbo(), false, true));
habbo.getClient().sendResponse(new RoomWallItemsComposer(room));
{
2018-09-28 21:25:00 +02:00
final THashSet<HabboItem> floorItems = new THashSet<>();
2018-07-06 15:30:00 +02:00
room.getFloorItems().forEach(new TObjectProcedure<HabboItem>()
{
@Override
public boolean execute(HabboItem object)
{
2018-09-28 21:25:00 +02:00
if (room.isHideWired() && object instanceof InteractionWired)
return true;
2018-07-06 15:30:00 +02:00
floorItems.add(object);
if (floorItems.size() == 250)
{
habbo.getClient().sendResponse(new RoomFloorItemsComposer(room.getFurniOwnerNames(), floorItems));
floorItems.clear();
}
return true;
}
});
habbo.getClient().sendResponse(new RoomFloorItemsComposer(room.getFurniOwnerNames(), floorItems));
floorItems.clear();
}
if (!room.getCurrentPets().isEmpty())
{
habbo.getClient().sendResponse(new RoomPetComposer(room.getCurrentPets()));
2018-09-12 18:45:00 +02:00
for (Pet pet : room.getCurrentPets().valueCollection())
2018-07-06 15:30:00 +02:00
{
habbo.getClient().sendResponse(new RoomUserStatusComposer(pet.getRoomUnit()));
}
}
if (!habbo.getHabboStats().allowTalk())
{
habbo.getHabboStats().mutedBubbleTracker = true;
int remainingMuteTime = habbo.getHabboStats().remainingMuteTime();
habbo.getClient().sendResponse(new FloodCounterComposer(remainingMuteTime));
habbo.getClient().sendResponse(new MutedWhisperComposer(remainingMuteTime));
room.sendComposer(new RoomUserIgnoredComposer(habbo, RoomUserIgnoredComposer.MUTED).compose());
}
else if (habbo.getHabboStats().mutedBubbleTracker)
{
habbo.getHabboStats().mutedBubbleTracker = false;
}
2018-09-28 21:25:00 +02:00
THashMap<Integer, String> guildBadges = new THashMap<>();
for (Habbo roomHabbo : habbos)
2018-07-06 15:30:00 +02:00
{
{
if (roomHabbo.getRoomUnit().getDanceType().getType() > 0)
{
habbo.getClient().sendResponse(new RoomUserDanceComposer(roomHabbo.getRoomUnit()));
}
if (roomHabbo.getRoomUnit().getHandItem() > 0)
{
habbo.getClient().sendResponse(new RoomUserHandItemComposer(roomHabbo.getRoomUnit()));
}
if (roomHabbo.getRoomUnit().getEffectId() > 0)
{
habbo.getClient().sendResponse(new RoomUserEffectComposer(roomHabbo.getRoomUnit()));
}
if (roomHabbo.getRoomUnit().isIdle())
{
habbo.getClient().sendResponse(new RoomUnitIdleComposer(roomHabbo.getRoomUnit()));
}
2018-10-07 00:28:00 +02:00
if (roomHabbo.getHabboStats().userIgnored(habbo.getHabboInfo().getId()))
2018-07-06 15:30:00 +02:00
{
roomHabbo.getClient().sendResponse(new RoomUserIgnoredComposer(habbo, RoomUserIgnoredComposer.IGNORED));
}
if (!roomHabbo.getHabboStats().allowTalk())
{
habbo.getClient().sendResponse(new RoomUserIgnoredComposer(roomHabbo, RoomUserIgnoredComposer.MUTED));
}
2018-10-07 00:28:00 +02:00
else if (habbo.getHabboStats().userIgnored(roomHabbo.getHabboInfo().getId()))
2018-07-06 15:30:00 +02:00
{
habbo.getClient().sendResponse(new RoomUserIgnoredComposer(roomHabbo, RoomUserIgnoredComposer.IGNORED));
}
if (roomHabbo.getHabboStats().guild != 0 && !guildBadges.containsKey(roomHabbo.getHabboStats().guild))
{
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(roomHabbo.getHabboStats().guild);
if (guild != null)
{
guildBadges.put(roomHabbo.getHabboStats().guild, guild.getBadge());
}
}
if (roomHabbo.getRoomUnit().getRoomUnitType().equals(RoomUnitType.PET))
{
try
{
habbo.getClient().sendResponse(new RoomUserRemoveComposer(roomHabbo.getRoomUnit()));
habbo.getClient().sendResponse(new RoomUserPetComposer(((PetData)roomHabbo.getHabboStats().cache.get("pet_type")).getType(), (Integer)roomHabbo.getHabboStats().cache.get("pet_race"), (String)roomHabbo.getHabboStats().cache.get("pet_color"), roomHabbo));
}
catch (Exception e)
{
}
}
}
}
habbo.getClient().sendResponse(new RoomUsersGuildBadgesComposer(guildBadges));
if (room.hasRights(habbo) || (room.hasGuild() && room.guildRightLevel(habbo) >= 2))
{
if (!room.getHabboQueue().isEmpty())
{
for (Habbo waiting : room.getHabboQueue().valueCollection())
{
habbo.getClient().sendResponse(new DoorbellAddUserComposer(waiting.getHabboInfo().getUsername()));
}
}
}
if (room.getPollId() > 0)
{
if (!PollManager.donePoll(habbo.getClient().getHabbo(), room.getPollId()))
{
Poll poll = Emulator.getGameEnvironment().getPollManager().getPoll(room.getPollId());
if (poll != null)
{
habbo.getClient().sendResponse(new PollStartComposer(poll));
}
}
}
if (room.hasActiveWordQuiz())
{
habbo.getClient().sendResponse(new SimplePollStartComposer((Emulator.getIntUnixTimestamp() - room.wordQuizEnd) * 1000, room.wordQuiz));
if (room.hasVotedInWordQuiz(habbo))
{
2019-03-18 02:22:00 +01:00
habbo.getClient().sendResponse(new SimplePollAnswersComposer(room.noVotes, room.yesVotes));
2018-07-06 15:30:00 +02:00
}
}
WiredHandler.handle(WiredTriggerType.ENTER_ROOM, habbo.getRoomUnit(), room, null);
room.habboEntered(habbo);
2018-10-07 00:28:00 +02:00
if (!habbo.getHabboStats().nux && (room.isOwner(habbo) || room.isPublicRoom()))
2018-07-06 15:30:00 +02:00
{
UserNuxEvent.handle(habbo);
}
}
void logEnter(Habbo habbo, Room room)
{
habbo.getHabboStats().roomEnterTimestamp = Emulator.getIntUnixTimestamp();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_enter_log (room_id, user_id, timestamp) VALUES(?, ?, ?)"))
{
statement.setInt(1, room.getId());
statement.setInt(2, habbo.getHabboInfo().getId());
statement.setInt(3, (int)(habbo.getHabboStats().roomEnterTimestamp));
statement.execute();
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
public void leaveRoom(Habbo habbo, Room room)
2018-11-17 14:28:00 +01:00
{
2019-03-18 02:22:00 +01:00
this.leaveRoom(habbo, room, true);
2018-11-17 14:28:00 +01:00
}
public void leaveRoom(Habbo habbo, Room room, boolean redirectToHotelView)
2018-07-06 15:30:00 +02:00
{
if(habbo.getHabboInfo().getCurrentRoom() != null && habbo.getHabboInfo().getCurrentRoom() == room)
{
habbo.getRoomUnit().setPathFinderRoom(null);
this.logExit(habbo);
room.removeHabbo(habbo, true);
2018-11-17 14:28:00 +01:00
if (redirectToHotelView)
{
habbo.getClient().sendResponse(new HotelViewComposer());
}
2018-07-06 15:30:00 +02:00
habbo.getHabboInfo().setCurrentRoom(null);
habbo.getRoomUnit().isKicked = false;
if (room.getOwnerId() != habbo.getHabboInfo().getId())
{
AchievementManager.progressAchievement(room.getOwnerId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"), (int)Math.floor((Emulator.getIntUnixTimestamp() - habbo.getHabboStats().roomEnterTimestamp) / 60000));
}
}
}
public void logExit(Habbo habbo)
{
2018-11-17 14:28:00 +01:00
Emulator.getPluginManager().fireEvent(new UserExitRoomEvent(habbo, UserExitRoomEvent.UserExitRoomReason.DOOR));
2018-07-06 15:30:00 +02:00
if(habbo.getRoomUnit().getCacheable().containsKey("control"))
{
Habbo control = (Habbo)habbo.getRoomUnit().getCacheable().remove("control");
control.getRoomUnit().getCacheable().remove("controller");
}
if (habbo.getHabboInfo().getRiding() != null)
{
if (habbo.getHabboInfo().getRiding().getRoomUnit() != null)
{
habbo.getHabboInfo().getRiding().getRoomUnit().setGoalLocation(habbo.getHabboInfo().getRiding().getRoomUnit().getCurrentLocation());
}
habbo.getHabboInfo().getRiding().setTask(PetTasks.FREE);
habbo.getHabboInfo().getRiding().setRider(null);
habbo.getHabboInfo().setRiding(null);
}
2018-07-06 15:30:00 +02:00
Room room = habbo.getHabboInfo().getCurrentRoom();
if(room != null)
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE room_enter_log SET exit_timestamp = ? WHERE user_id = ? AND room_id = ? ORDER BY timestamp DESC LIMIT 1"))
{
statement.setInt(1, Emulator.getIntUnixTimestamp());
statement.setInt(2, habbo.getHabboInfo().getId());
statement.setInt(3, room.getId());
statement.execute();
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
}
public Set<String> getTags()
{
2018-09-28 21:25:00 +02:00
Map<String, Integer> tagCount = new HashMap<>();
2018-07-06 15:30:00 +02:00
for(Room room : this.activeRooms.values())
{
for(String s : room.getTags().split(";"))
{
int i = 0;
if(tagCount.get(s) != null)
i++;
tagCount.put(s, i++);
}
}
2018-09-28 21:25:00 +02:00
return new TreeMap<>(tagCount).keySet();
2018-07-06 15:30:00 +02:00
}
public ArrayList<Room> getPublicRooms()
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : this.activeRooms.values())
{
2019-03-18 02:22:00 +01:00
if(room.isPublicRoom())
2018-07-06 15:30:00 +02:00
{
rooms.add(room);
}
}
return rooms;
}
public ArrayList<Room> getPopularRooms(int count)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for (Room room : this.activeRooms.values())
{
2019-04-22 01:42:00 +02:00
if (room.getUserCount() > 0)
2018-07-06 15:30:00 +02:00
{
2019-04-22 01:42:00 +02:00
if (!RoomManager.SHOW_PUBLIC_IN_POPULAR_TAB && room.isPublicRoom()) continue;
2018-07-06 15:30:00 +02:00
rooms.add(room);
}
}
if (rooms.isEmpty())
{
return rooms;
}
Collections.sort(rooms);
2018-09-28 21:25:00 +02:00
return new ArrayList<>(rooms.subList(0, (rooms.size() < count ? rooms.size() : count)));
2018-07-06 15:30:00 +02:00
}
public ArrayList<Room> getPopularRooms(int count, int category)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for (Room room : this.activeRooms.values())
{
if (!room.isPublicRoom() && room.getCategory() == category)
{
rooms.add(room);
}
}
if (rooms.isEmpty())
{
return rooms;
}
Collections.sort(rooms);
2018-09-28 21:25:00 +02:00
return new ArrayList<>(rooms.subList(0, (rooms.size() < count ? rooms.size() : count)));
2018-07-06 15:30:00 +02:00
}
public Map<Integer, List<Room>> getPopularRoomsByCategory(int count)
{
2018-09-28 21:25:00 +02:00
Map<Integer, List<Room>> rooms = new HashMap<>();
2018-07-06 15:30:00 +02:00
for (Room room : this.activeRooms.values())
{
if (!room.isPublicRoom())
{
if (!rooms.containsKey(room.getCategory()))
{
2018-09-28 21:25:00 +02:00
rooms.put(room.getCategory(), new ArrayList<>());
2018-07-06 15:30:00 +02:00
}
rooms.get(room.getCategory()).add(room);
}
}
2018-09-28 21:25:00 +02:00
Map<Integer, List<Room>> result = new HashMap<>();
2018-07-06 15:30:00 +02:00
for (Map.Entry<Integer, List<Room>> set : rooms.entrySet())
{
if (set.getValue().isEmpty())
continue;
Collections.sort(set.getValue());
2018-09-28 21:25:00 +02:00
result.put(set.getKey(), new ArrayList<>(set.getValue().subList(0, (set.getValue().size() < count ? set.getValue().size() : count))));
2018-07-06 15:30:00 +02:00
}
return result;
}
public ArrayList<Room> getRoomsWithName(String name)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for (Room room : this.activeRooms.values())
{
if (room.getName().toLowerCase().contains(name.toLowerCase()))
{
rooms.add(room);
}
}
if(rooms.size() < 25)
{
2019-03-18 02:22:00 +01:00
rooms.addAll(this.getOfflineRoomsWithName(name));
2018-07-06 15:30:00 +02:00
}
Collections.sort(rooms);
return rooms;
}
private ArrayList<Room> getOfflineRoomsWithName(String name)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, rooms.* FROM rooms INNER JOIN users ON owner_id = users.id WHERE name LIKE ? ORDER BY id DESC LIMIT 25"))
{
statement.setString(1, "%"+name+"%");
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
if (this.activeRooms.containsKey(set.getInt("id")))
continue;
Room r = new Room(set);
rooms.add(r);
this.activeRooms.put(r.getId(), r);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return rooms;
}
public ArrayList<Room> getRoomsWithTag(String tag)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for (Room room : this.activeRooms.values())
{
for (String s : room.getTags().split(";"))
{
if (s.toLowerCase().equals(tag.toLowerCase()))
{
rooms.add(room);
break;
}
}
}
Collections.sort(rooms);
return rooms;
}
public ArrayList<Room> getGroupRoomsWithName(String name)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for (Room room : this.activeRooms.values())
{
if (room.getGuildId() == 0)
continue;
if (room.getName().toLowerCase().contains(name.toLowerCase()))
rooms.add(room);
}
if(rooms.size() < 25)
{
rooms.addAll(this.getOfflineGroupRoomsWithName(name));
}
Collections.sort(rooms);
return rooms;
}
private ArrayList<Room> getOfflineGroupRoomsWithName(String name)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, rooms.* FROM rooms INNER JOIN users ON rooms.owner_id = users.id WHERE name LIKE ? AND guild_id != 0 ORDER BY id DESC LIMIT 25"))
{
statement.setString(1, "%"+name+"%");
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
if (this.activeRooms.containsKey(set.getInt("id")))
continue;
Room r = new Room(set);
rooms.add(r);
this.activeRooms.put(r.getId(), r);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return rooms;
}
public ArrayList<Room> getRoomsFriendsNow(Habbo habbo)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(MessengerBuddy buddy : habbo.getMessenger().getFriends().values())
{
if(buddy.getOnline() == 0)
continue;
Habbo friend = Emulator.getGameEnvironment().getHabboManager().getHabbo(buddy.getId());
if(friend == null || friend.getHabboInfo().getCurrentRoom() == null)
continue;
rooms.add(friend.getHabboInfo().getCurrentRoom());
}
Collections.sort(rooms);
return rooms;
}
public ArrayList<Room> getRoomsFriendsOwn(Habbo habbo)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(MessengerBuddy buddy : habbo.getMessenger().getFriends().values())
{
if(buddy.getOnline() == 0)
continue;
Habbo friend = Emulator.getGameEnvironment().getHabboManager().getHabbo(buddy.getId());
if(friend == null)
continue;
rooms.addAll(this.getRoomsForHabbo(friend));
}
Collections.sort(rooms);
return rooms;
}
public ArrayList<Room> getRoomsVisited(Habbo habbo, boolean includeSelf, int limit)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.* FROM room_enter_log INNER JOIN rooms ON room_enter_log.room_id = rooms.id WHERE user_id = ? AND timestamp >= ? AND rooms.owner_id != ? GROUP BY rooms.id ORDER BY timestamp DESC LIMIT " + limit))
{
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(2, Emulator.getIntUnixTimestamp() - 259200);
statement.setInt(3, (includeSelf ? 0 : habbo.getHabboInfo().getId()));
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
Room room = this.activeRooms.get(set.getInt("id"));
if (room == null)
{
room = new Room(set);
this.activeRooms.put(room.getId(), room);
}
rooms.add(room);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
Collections.sort(rooms);
return rooms;
}
public ArrayList<Room> getRoomsFavourite(Habbo habbo)
{
2018-09-28 21:25:00 +02:00
final ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
habbo.getHabboStats().getFavoriteRooms().forEach(new TIntProcedure()
{
@Override
public boolean execute(int value)
{
2019-04-22 01:42:00 +02:00
Room room = RoomManager.this.getRoom(value);
2018-07-06 15:30:00 +02:00
if (room != null)
{
2019-04-22 01:42:00 +02:00
if (room.getState() == RoomState.INVISIBLE)
{
room.loadData();
if (!room.hasRights(habbo)) return true;
}
2018-07-06 15:30:00 +02:00
rooms.add(room);
}
return true;
}
});
return rooms;
}
public List<Room> getGroupRooms(Habbo habbo, int limit)
{
2018-09-28 21:25:00 +02:00
final ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for (Guild guild : Emulator.getGameEnvironment().getGuildManager().getGuilds(habbo.getHabboInfo().getId()))
{
if (guild.getOwnerId() != habbo.getHabboInfo().getId())
{
2018-12-22 11:39:00 +01:00
Room room = this.getRoom(guild.getRoomId());
2018-07-06 15:30:00 +02:00
if (room != null)
{
rooms.add(room);
}
}
}
Collections.sort(rooms);
return rooms.subList(0, (rooms.size() > limit ? limit : rooms.size()));
}
public ArrayList<Room> getRoomsWithRights(Habbo habbo)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> rooms = new ArrayList<>();
2018-07-06 15:30:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.* FROM rooms INNER JOIN room_rights ON room_rights.room_id = rooms.id WHERE room_rights.user_id = ? ORDER BY rooms.id DESC LIMIT 30"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
if (this.activeRooms.containsKey(set.getInt("id")))
{
rooms.add(this.activeRooms.get(set.getInt("id")));
}
else
{
rooms.add(new Room(set));
}
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return rooms;
}
public ArrayList<Room> getRoomsWithAdminRights(Habbo habbo)
{
ArrayList<Room> rooms = new ArrayList<>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT * FROM rooms INNER JOIN guilds_members ON guilds_members.guild_id = rooms.guild_id WHERE guilds_members.user_id = ? AND level_id = 0"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
try (ResultSet set = statement.executeQuery())
{
while (set.next())
{
if (this.activeRooms.containsKey(set.getInt("id")))
{
rooms.add(this.activeRooms.get(set.getInt("id")));
}
else
{
rooms.add(new Room(set));
}
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return rooms;
}
public ArrayList<Room> getRoomsInGroup(Habbo habbo)
{
2018-09-28 21:25:00 +02:00
return new ArrayList<>();
2018-07-06 15:30:00 +02:00
}
public ArrayList<Room> getRoomsPromoted()
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> r = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : this.getActiveRooms())
{
if(room.isPromoted())
{
r.add(room);
}
}
return r;
}
public List<Room> filterRoomsByOwner(List<Room> rooms, String filter)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> r = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : rooms)
{
if(room.getOwnerName().equalsIgnoreCase(filter))
r.add(room);
}
return r;
}
public List<Room> filterRoomsByName(List<Room> rooms, String filter)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> r = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : rooms)
{
if(room.getName().toLowerCase().contains(filter.toLowerCase()))
r.add(room);
}
return r;
}
public List<Room> filterRoomsByNameAndDescription(List<Room> rooms, String filter)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> r = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : rooms)
{
if(room.getName().toLowerCase().contains(filter.toLowerCase()) || room.getDescription().toLowerCase().contains(filter.toLowerCase()))
r.add(room);
}
return r;
}
public List<Room> filterRoomsByTag(List<Room> rooms, String filter)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> r = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : rooms)
{
if(room.getTags().split(";").length == 0)
continue;
for(String s : room.getTags().split(";"))
{
if(s.equalsIgnoreCase(filter))
r.add(room);
}
}
return r;
}
public List<Room> filterRoomsByGroup(List<Room> rooms, String filter)
{
2018-09-28 21:25:00 +02:00
ArrayList<Room> r = new ArrayList<>();
2018-07-06 15:30:00 +02:00
for(Room room : rooms)
{
if(room.getGuildId() == 0)
continue;
if(Emulator.getGameEnvironment().getGuildManager().getGuild(room.getGuildId()).getName().toLowerCase().contains(filter.toLowerCase()))
r.add(room);
}
return r;
}
public synchronized void dispose()
{
for (Room room : this.activeRooms.values())
{
room.dispose();
}
this.activeRooms.clear();
Emulator.getLogging().logShutdownLine("Room Manager -> Disposed!");
}
public CustomRoomLayout insertCustomLayout(Room room, String map, int doorX, int doorY, int doorDirection)
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_models_custom (id, name, door_x, door_y, door_dir, heightmap) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE door_x = ?, door_y = ?, door_dir = ?, heightmap = ?"))
{
statement.setInt(1, room.getId());
statement.setString(2, "custom_" + room.getId());
statement.setInt(3, doorX);
statement.setInt(4, doorY);
statement.setInt(5, doorDirection);
statement.setString(6, map);
statement.setInt(7, doorX);
statement.setInt(8, doorY);
statement.setInt(9, doorDirection);
statement.setString(10, map);
statement.execute();
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return this.loadCustomLayout(room);
}
public void banUserFromRoom(Habbo rights, int userId, int roomId, RoomBanTypes length)
{
Room room = this.getRoom(roomId);
if (room == null)
return;
if (rights != null && !room.hasRights(rights))
return;
String name = "";
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
if (habbo != null)
{
2018-09-12 18:45:00 +02:00
if (habbo.hasPermission(Permission.ACC_UNKICKABLE))
2018-07-06 15:30:00 +02:00
{
return;
}
name = habbo.getHabboInfo().getUsername();
}
else
{
HabboInfo info = HabboManager.getOfflineHabboInfo(userId);
if (info != null)
{
2018-09-12 18:45:00 +02:00
if (info.getRank().hasPermission(Permission.ACC_UNKICKABLE, false))
2018-07-06 15:30:00 +02:00
{
return;
}
name = info.getUsername();
}
}
if (name.isEmpty())
{
return;
}
RoomBan roomBan = new RoomBan(roomId, userId, name, Emulator.getIntUnixTimestamp() + length.duration);
roomBan.insert();
room.addRoomBan(roomBan);
if (habbo != null)
{
if (habbo.getHabboInfo().getCurrentRoom() == room)
{
room.removeHabbo(habbo);
habbo.getClient().sendResponse(new RoomEnterErrorComposer(RoomEnterErrorComposer.ROOM_ERROR_BANNED));
}
}
}
public enum RoomBanTypes
{
RWUAM_BAN_USER_HOUR(60 * 60),
RWUAM_BAN_USER_DAY(24 * 60 * 60),
RWUAM_BAN_USER_PERM(10 * 365 * 24 * 60 * 60);
public int duration;
RoomBanTypes(int duration)
{
this.duration = duration;
}
}
2019-05-04 22:41:18 +02:00
public void registerGameType(Class<? extends Game> gameClass) {
gameTypes.add(gameClass);
}
public void unregisterGameType(Class<? extends Game> gameClass) {
gameTypes.remove(gameClass);
}
public ArrayList<Class<? extends Game>> getGameTypes() {
return gameTypes;
}
2018-07-06 15:30:00 +02:00
}