mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-31 12:22:36 +01:00
Add saved searches
This commit is contained in:
parent
8d63982a28
commit
4dbe78c4ad
7
sqlupdates/2_0_0_TO_2_1_0-RC-1.sql
Normal file
7
sqlupdates/2_0_0_TO_2_1_0-RC-1.sql
Normal file
@ -0,0 +1,7 @@
|
||||
CREATE TABLE `users_saved_searches` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`search_code` varchar(255) NOT NULL,
|
||||
`filter` varchar(255) NULL,
|
||||
`user_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
@ -0,0 +1,34 @@
|
||||
package com.eu.habbo.habbohotel.navigation;
|
||||
|
||||
public class NavigatorSavedSearch {
|
||||
private String searchCode;
|
||||
private String filter;
|
||||
private int id;
|
||||
|
||||
public NavigatorSavedSearch(String searchCode, String filter) {
|
||||
this.searchCode = searchCode;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public NavigatorSavedSearch(String searchCode, String filter, int id) {
|
||||
this.searchCode = searchCode;
|
||||
this.filter = filter;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSearchCode() {
|
||||
return searchCode;
|
||||
}
|
||||
|
||||
public String getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ 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.navigation.NavigatorSavedSearch;
|
||||
import com.eu.habbo.habbohotel.permissions.Rank;
|
||||
import com.eu.habbo.habbohotel.pets.PetTasks;
|
||||
import com.eu.habbo.habbohotel.pets.RideablePet;
|
||||
@ -14,11 +15,9 @@ import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
||||
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;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class HabboInfo implements Runnable {
|
||||
@ -51,6 +50,7 @@ public class HabboInfo implements Runnable {
|
||||
private String photoJSON;
|
||||
private int webPublishTimestamp;
|
||||
private String machineID;
|
||||
private HashSet<NavigatorSavedSearch> savedSearches = new HashSet<>();
|
||||
|
||||
public HabboInfo(ResultSet set) {
|
||||
try {
|
||||
@ -83,6 +83,7 @@ public class HabboInfo implements Runnable {
|
||||
}
|
||||
|
||||
this.loadCurrencies();
|
||||
this.loadSavedSearches();
|
||||
}
|
||||
|
||||
private void loadCurrencies() {
|
||||
@ -123,6 +124,57 @@ public class HabboInfo implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSavedSearches() {
|
||||
this.savedSearches = new HashSet<>();
|
||||
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users_saved_searches WHERE user_id = ?")) {
|
||||
statement.setInt(1, this.id);
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
while (set.next()) {
|
||||
this.savedSearches.add(new NavigatorSavedSearch(set.getString("search_code"), set.getString("filter"), set.getInt("id")));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSavedSearch(NavigatorSavedSearch search) {
|
||||
this.savedSearches.add(search);
|
||||
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_saved_searches (search_code, filter, user_id) VALUES (?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
|
||||
statement.setString(1, search.getSearchCode());
|
||||
statement.setString(2, search.getFilter());
|
||||
statement.setInt(3, this.id);
|
||||
int affectedRows = statement.executeUpdate();
|
||||
|
||||
if (affectedRows == 0) {
|
||||
throw new SQLException("Creating saved search failed, no rows affected.");
|
||||
}
|
||||
|
||||
try (ResultSet generatedKeys = statement.getGeneratedKeys()) {
|
||||
if (generatedKeys.next()) {
|
||||
search.setId(generatedKeys.getInt(1));
|
||||
} else {
|
||||
throw new SQLException("Creating saved search failed, no ID found.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteSavedSearch(NavigatorSavedSearch search) {
|
||||
this.savedSearches.remove(search);
|
||||
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_saved_searches WHERE id = ?")) {
|
||||
statement.setInt(1, search.getId());
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrencyAmount(int type) {
|
||||
return this.currencies.get(type);
|
||||
}
|
||||
@ -418,6 +470,10 @@ public class HabboInfo implements Runnable {
|
||||
this.machineID = machineID;
|
||||
}
|
||||
|
||||
public HashSet<NavigatorSavedSearch> getSavedSearches() {
|
||||
return this.savedSearches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.saveCurrencies();
|
||||
|
@ -316,6 +316,8 @@ public class PacketManager {
|
||||
this.registerHandler(Incoming.NavigatorCategoryListModeEvent, NavigatorCategoryListModeEvent.class);
|
||||
this.registerHandler(Incoming.NavigatorCollapseCategoryEvent, NavigatorCollapseCategoryEvent.class);
|
||||
this.registerHandler(Incoming.NavigatorUncollapseCategoryEvent, NavigatorUncollapseCategoryEvent.class);
|
||||
this.registerHandler(Incoming.AddSavedSearchEvent, AddSavedSearchEvent.class);
|
||||
this.registerHandler(Incoming.DeleteSavedSearchEvent, DeleteSavedSearchEvent.class);
|
||||
}
|
||||
|
||||
private void registerHotelview() throws Exception {
|
||||
|
@ -285,6 +285,8 @@ public class Incoming {
|
||||
public static final int UnbanRoomUserEvent = 992;
|
||||
public static final int RoomUserBanEvent = 1477;
|
||||
public static final int RequestNavigatorSettingsEvent = 1782;
|
||||
public static final int AddSavedSearchEvent = 2226;
|
||||
public static final int DeleteSavedSearchEvent = 1954;
|
||||
public static final int SaveWindowSettingsEvent = 3159;
|
||||
public static final int GetHabboGuildBadgesMessageEvent = 21;
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class SecureLoginEvent extends MessageHandler {
|
||||
this.client.sendResponse(new NewNavigatorMetaDataComposer());
|
||||
this.client.sendResponse(new NewNavigatorLiftedRoomsComposer());
|
||||
this.client.sendResponse(new NewNavigatorCollapsedCategoriesComposer());
|
||||
this.client.sendResponse(new NewNavigatorSavedSearchesComposer());
|
||||
this.client.sendResponse(new NewNavigatorSavedSearchesComposer(this.client.getHabbo().getHabboInfo().getSavedSearches()));
|
||||
this.client.sendResponse(new NewNavigatorEventCategoriesComposer());
|
||||
this.client.sendResponse(new InventoryRefreshComposer());
|
||||
//this.client.sendResponse(new ForumsTestComposer());
|
||||
|
@ -70,7 +70,7 @@ public class SecureLoginEvent_BACKUP extends MessageHandler {
|
||||
this.client.sendResponse(new NewNavigatorMetaDataComposer());
|
||||
this.client.sendResponse(new NewNavigatorLiftedRoomsComposer());
|
||||
this.client.sendResponse(new NewNavigatorCollapsedCategoriesComposer());
|
||||
this.client.sendResponse(new NewNavigatorSavedSearchesComposer());
|
||||
this.client.sendResponse(new NewNavigatorSavedSearchesComposer(this.client.getHabbo().getHabboInfo().getSavedSearches()));
|
||||
this.client.sendResponse(new NewNavigatorEventCategoriesComposer());
|
||||
//this.client.sendResponse(new HotelViewComposer());
|
||||
//this.client.sendResponse(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), this.client.getHabbo().getHabboInfo().getHomeRoom()));
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.eu.habbo.messages.incoming.navigator;
|
||||
|
||||
import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
import com.eu.habbo.messages.outgoing.navigator.NewNavigatorSavedSearchesComposer;
|
||||
|
||||
public class AddSavedSearchEvent extends MessageHandler {
|
||||
@Override
|
||||
public void handle() throws Exception {
|
||||
String searchCode = this.packet.readString();
|
||||
String filter = this.packet.readString();
|
||||
|
||||
if (searchCode.length() > 255) searchCode = searchCode.substring(0, 255);
|
||||
if (filter.length() > 255) filter = filter.substring(0, 255);
|
||||
|
||||
this.client.getHabbo().getHabboInfo().addSavedSearch(new NavigatorSavedSearch(searchCode, filter));
|
||||
|
||||
this.client.sendResponse(new NewNavigatorSavedSearchesComposer(this.client.getHabbo().getHabboInfo().getSavedSearches()));
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.eu.habbo.messages.incoming.navigator;
|
||||
|
||||
import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
import com.eu.habbo.messages.outgoing.navigator.NewNavigatorSavedSearchesComposer;
|
||||
|
||||
public class DeleteSavedSearchEvent extends MessageHandler {
|
||||
@Override
|
||||
public void handle() throws Exception {
|
||||
int searchId = this.packet.readInt();
|
||||
|
||||
NavigatorSavedSearch search = null;
|
||||
for (NavigatorSavedSearch savedSearch : this.client.getHabbo().getHabboInfo().getSavedSearches()) {
|
||||
if (savedSearch.getId() == searchId) {
|
||||
search = savedSearch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (search == null) return;
|
||||
|
||||
this.client.getHabbo().getHabboInfo().deleteSavedSearch(search);
|
||||
|
||||
this.client.sendResponse(new NewNavigatorSavedSearchesComposer(this.client.getHabbo().getHabboInfo().getSavedSearches()));
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ public class RequestNewNavigatorDataEvent extends MessageHandler {
|
||||
this.client.sendResponse(new NewNavigatorMetaDataComposer());
|
||||
this.client.sendResponse(new NewNavigatorLiftedRoomsComposer());
|
||||
this.client.sendResponse(new NewNavigatorCollapsedCategoriesComposer());
|
||||
this.client.sendResponse(new NewNavigatorSavedSearchesComposer());
|
||||
this.client.sendResponse(new NewNavigatorSavedSearchesComposer(this.client.getHabbo().getHabboInfo().getSavedSearches()));
|
||||
this.client.sendResponse(new NewNavigatorEventCategoriesComposer());
|
||||
this.client.sendResponse(new NewNavigatorSettingsComposer(this.client.getHabbo().getHabboStats().navigatorWindowSettings));
|
||||
}
|
||||
|
@ -58,10 +58,14 @@ public class RequestNewNavigatorRoomsEvent extends MessageHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (filter == null && category != null) {
|
||||
if (filter == null) {
|
||||
filter = Emulator.getGameEnvironment().getNavigatorManager().filters.get("hotel_view");
|
||||
}
|
||||
|
||||
if (category == null) {
|
||||
category = Emulator.getGameEnvironment().getRoomManager().getCategoryBySafeCaption("hotel_view");
|
||||
}
|
||||
|
||||
if (filter == null)
|
||||
return;
|
||||
|
||||
|
@ -1,34 +1,31 @@
|
||||
package com.eu.habbo.messages.outgoing.navigator;
|
||||
|
||||
import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch;
|
||||
import com.eu.habbo.messages.ServerMessage;
|
||||
import com.eu.habbo.messages.outgoing.MessageComposer;
|
||||
import com.eu.habbo.messages.outgoing.Outgoing;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class NewNavigatorSavedSearchesComposer extends MessageComposer {
|
||||
private final HashSet<NavigatorSavedSearch> searches;
|
||||
|
||||
public NewNavigatorSavedSearchesComposer(HashSet<NavigatorSavedSearch> searches) {
|
||||
this.searches = searches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerMessage compose() {
|
||||
this.response.init(Outgoing.NewNavigatorSavedSearchesComposer);
|
||||
this.response.appendInt(4);
|
||||
this.response.appendInt(this.searches.size());
|
||||
|
||||
this.response.appendInt(1);
|
||||
this.response.appendString("official");
|
||||
this.response.appendString("");
|
||||
for (NavigatorSavedSearch search : this.searches) {
|
||||
this.response.appendInt(search.getId());
|
||||
this.response.appendString(search.getSearchCode());
|
||||
this.response.appendString(search.getFilter() == null ? "" : search.getFilter());
|
||||
this.response.appendString("");
|
||||
}
|
||||
|
||||
this.response.appendInt(2);
|
||||
this.response.appendString("recommended");
|
||||
this.response.appendString("");
|
||||
this.response.appendString("");
|
||||
|
||||
this.response.appendInt(3);
|
||||
this.response.appendString("my");
|
||||
this.response.appendString("");
|
||||
this.response.appendString("");
|
||||
|
||||
this.response.appendInt(4);
|
||||
this.response.appendString("favorites");
|
||||
this.response.appendString("");
|
||||
this.response.appendString("");
|
||||
return this.response;
|
||||
}
|
||||
}
|
||||
|
@ -11,20 +11,20 @@ import com.eu.habbo.messages.outgoing.Outgoing;
|
||||
public class RoomDataComposer extends MessageComposer {
|
||||
private final Room room;
|
||||
private final Habbo habbo;
|
||||
private final boolean publicRoom;
|
||||
private final boolean unknown;
|
||||
private final boolean roomForward;
|
||||
private final boolean enterRoom;
|
||||
|
||||
public RoomDataComposer(Room room, Habbo habbo, boolean boolA, boolean boolB) {
|
||||
public RoomDataComposer(Room room, Habbo habbo, boolean roomForward, boolean enterRoom) {
|
||||
this.room = room;
|
||||
this.habbo = habbo;
|
||||
this.publicRoom = boolA;
|
||||
this.unknown = boolB;
|
||||
this.roomForward = roomForward;
|
||||
this.enterRoom = enterRoom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerMessage compose() {
|
||||
this.response.init(Outgoing.RoomDataComposer);
|
||||
this.response.appendBoolean(this.unknown);
|
||||
this.response.appendBoolean(this.enterRoom);
|
||||
this.response.appendInt(this.room.getId());
|
||||
this.response.appendString(this.room.getName());
|
||||
if (this.room.isPublicRoom()) {
|
||||
@ -92,10 +92,10 @@ public class RoomDataComposer extends MessageComposer {
|
||||
this.response.appendInt((this.room.getPromotion().getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60);
|
||||
}
|
||||
|
||||
this.response.appendBoolean(this.publicRoom);
|
||||
this.response.appendBoolean(this.room.isStaffPromotedRoom()); //staffpicked
|
||||
this.response.appendBoolean(this.room.isPublicRoom()); //ispublicroom
|
||||
this.response.appendBoolean(this.room.isMuted()); //isroommuted
|
||||
this.response.appendBoolean(this.roomForward);
|
||||
this.response.appendBoolean(this.room.isStaffPromotedRoom()); // staffpicked
|
||||
this.response.appendBoolean(this.room.hasGuild() && Emulator.getGameEnvironment().getGuildManager().getGuildMember(this.room.getGuildId(), this.habbo.getHabboInfo().getId()) != null); // is group member
|
||||
this.response.appendBoolean(this.room.isMuted()); // isroommuted
|
||||
|
||||
this.response.appendInt(this.room.getMuteOption());
|
||||
this.response.appendInt(this.room.getKickOption());
|
||||
|
Loading…
x
Reference in New Issue
Block a user