Feature Friendlist Categories

This commit is contained in:
brenoepics 2022-03-19 19:34:21 +00:00 committed by Remco
parent 2fe1796804
commit 5a66c30e8d
9 changed files with 177 additions and 51 deletions

View File

@ -10,3 +10,14 @@ INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('console.mode', '1');
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('youtube.apikey', '');
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('hotel.gifts.length.max', '300');
-- Add friendship categories table
CREATE TABLE `messenger_categories` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(25) NOT NULL,
`user_id` int NOT NULL,
UNIQUE KEY `identifier` (`id`)
);
-- Set an ID (int) from category list items
ALTER TABLE messenger_friendships ADD category int NOT NULL DEFAULT '0' AFTER friends_since;

View File

@ -302,7 +302,7 @@ public class Messenger {
buddy.setLook(owner.getHabboInfo().getLook());
buddy.setGender(owner.getHabboInfo().getGender());
buddy.setUsername(owner.getHabboInfo().getUsername());
habbo.getClient().sendResponse(new UpdateFriendComposer(buddy));
habbo.getClient().sendResponse(new UpdateFriendComposer(habbo, buddy, 0));
}
}
}
@ -368,12 +368,12 @@ public class Messenger {
return;
}
habboTo.getClient().sendResponse(new UpdateFriendComposer(to));
habboFrom.getClient().sendResponse(new UpdateFriendComposer(from));
habboTo.getClient().sendResponse(new UpdateFriendComposer(habboTo, to, 1));
habboFrom.getClient().sendResponse(new UpdateFriendComposer(habboFrom, from, 1));
} else if (habboTo != null) {
habboTo.getClient().sendResponse(new UpdateFriendComposer(this.loadFriend(habboTo, userFrom)));
habboTo.getClient().sendResponse(new UpdateFriendComposer(habboTo, this.loadFriend(habboTo, userFrom), 1));
} else if (habboFrom != null) {
habboFrom.getClient().sendResponse(new UpdateFriendComposer(this.loadFriend(habboFrom, userTo)));
habboFrom.getClient().sendResponse(new UpdateFriendComposer(habboFrom, this.loadFriend(habboFrom, userTo), 1));
}
}
}

View File

@ -25,6 +25,7 @@ public class MessengerBuddy implements Runnable, ISerialize {
private String look = "";
private String motto = "";
private short relation;
private int categoryId = 0;
private boolean inRoom;
private int userOne = 0;
@ -37,6 +38,7 @@ public class MessengerBuddy implements Runnable, ISerialize {
this.motto = set.getString("motto");
this.look = set.getString("look");
this.relation = (short) set.getInt("relation");
this.categoryId = set.getInt("category");
this.userOne = set.getInt("user_one_id");
this.inRoom = false;
if (this.online == 1) {
@ -136,6 +138,8 @@ public class MessengerBuddy implements Runnable, ISerialize {
Emulator.getThreading().run(this);
}
public int getCategoryId() { return this.categoryId; }
public boolean inRoom() {
return this.inRoom;
}
@ -181,7 +185,7 @@ public class MessengerBuddy implements Runnable, ISerialize {
message.appendBoolean(this.online == 1);
message.appendBoolean(this.inRoom); //IN ROOM
message.appendString(this.look);
message.appendInt(0); // Friends category ID
message.appendInt(this.categoryId); // Friends category ID
message.appendString(this.motto);
message.appendString(""); //Last seen as DATETIMESTRING
message.appendString(""); // Realname or Facebookame as String

View File

@ -0,0 +1,31 @@
package com.eu.habbo.habbohotel.messenger;
public class MessengerCategory {
private int user_id;
private String name;
private int id;
public MessengerCategory(String name, int user_id, int id) {
this.name = name;
this.user_id = user_id;
this.id = id;
}
public String getName() {
return name;
}
public int getUserId() {
return user_id;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public void setId(int id) { this.id = id; }
}

View File

@ -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.messenger.MessengerCategory;
import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch;
import com.eu.habbo.habbohotel.permissions.Rank;
import com.eu.habbo.habbohotel.pets.PetTasks;
@ -55,6 +56,7 @@ public class HabboInfo implements Runnable {
private int webPublishTimestamp;
private String machineID;
private List<NavigatorSavedSearch> savedSearches = new ArrayList<>();
private List<MessengerCategory> messengerCategories = new ArrayList<>();
public HabboInfo(ResultSet set) {
try {
@ -88,6 +90,7 @@ public class HabboInfo implements Runnable {
this.loadCurrencies();
this.loadSavedSearches();
this.loadMessengerCategories();
}
private void loadCurrencies() {
@ -179,6 +182,56 @@ public class HabboInfo implements Runnable {
}
}
private void loadMessengerCategories() {
this.messengerCategories = new ArrayList<>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM messenger_categories WHERE user_id = ?")) {
statement.setInt(1, this.id);
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
this.messengerCategories.add(new MessengerCategory(set.getString("name"), set.getInt("user_id"), set.getInt("id")));
}
}
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
}
}
public void addMessengerCategory(MessengerCategory category) {
this.messengerCategories.add(category);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO messenger_categories (name, user_id) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS)) {
statement.setString(1, category.getName());
statement.setInt(2, this.id);
int affectedRows = statement.executeUpdate();
if (affectedRows == 0) {
throw new SQLException("Creating messenger category failed, no rows affected.");
}
try (ResultSet generatedKeys = statement.getGeneratedKeys()) {
if (generatedKeys.next()) {
category.setId(generatedKeys.getInt(1));
} else {
throw new SQLException("Creating messenger category failed, no ID found.");
}
}
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
}
}
public void deleteMessengerCategory(MessengerCategory category) {
this.messengerCategories.remove(category);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM messenger_categories WHERE id = ?")) {
statement.setInt(1, category.getId());
statement.execute();
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
}
}
public int getCurrencyAmount(int type) {
return this.currencies.get(type);
}
@ -478,6 +531,8 @@ public class HabboInfo implements Runnable {
return this.savedSearches;
}
public List<MessengerCategory> getMessengerCategories() { return this.messengerCategories; }
@Override
public void run() {
this.saveCurrencies();

View File

@ -16,7 +16,7 @@ public class ChangeRelationEvent extends MessageHandler {
UserRelationShipEvent event = new UserRelationShipEvent(this.client.getHabbo(), buddy, relationId);
if (!event.isCancelled()) {
buddy.setRelation(event.relationShip);
this.client.sendResponse(new UpdateFriendComposer(buddy));
this.client.sendResponse(new UpdateFriendComposer(this.client.getHabbo(), buddy, 0));
}
}
}

View File

@ -41,10 +41,10 @@ public class FriendsComposer extends MessageComposer {
this.response.appendBoolean(row.getOnline() == 1);
this.response.appendBoolean(row.inRoom()); //IN ROOM
this.response.appendString(row.getOnline() == 1 ? row.getLook() : "");
this.response.appendInt(0);
this.response.appendInt(row.getCategoryId()); //Friends category
this.response.appendString(row.getMotto());
this.response.appendString("");
this.response.appendString("");
this.response.appendString(""); //Last seen as DATETIMESTRING
this.response.appendString(""); //Realname or Facebookame as String
this.response.appendBoolean(false); //Offline messaging.
this.response.appendBoolean(false);
this.response.appendBoolean(false);

View File

@ -1,11 +1,15 @@
package com.eu.habbo.messages.outgoing.friends;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.messenger.Messenger;
import com.eu.habbo.habbohotel.messenger.MessengerCategory;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
import java.util.List;
public class MessengerInitComposer extends MessageComposer {
private final Habbo habbo;
@ -15,6 +19,7 @@ public class MessengerInitComposer extends MessageComposer {
@Override
protected ServerMessage composeInternal() {
this.response.init(Outgoing.MessengerInitComposer);
if (this.habbo.hasPermission("acc_infinite_friends")) {
this.response.appendInt(Integer.MAX_VALUE);
@ -25,9 +30,19 @@ public class MessengerInitComposer extends MessageComposer {
this.response.appendInt(1337);
this.response.appendInt(Messenger.MAXIMUM_FRIENDS_HC);
}
if (!this.habbo.getHabboInfo().getMessengerCategories().isEmpty()) {
//this.response.appendInt(1000);
this.response.appendInt(0);
List<MessengerCategory> messengerCategories = this.habbo.getHabboInfo().getMessengerCategories();
this.response.appendInt(messengerCategories.size());
for (MessengerCategory mc : messengerCategories) {
this.response.appendInt(mc.getId());
this.response.appendString(mc.getName());
}
} else {
this.response.appendInt(0);
}
return this.response;
}
}

View File

@ -1,6 +1,11 @@
package com.eu.habbo.messages.outgoing.friends;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
import com.eu.habbo.habbohotel.messenger.MessengerCategory;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.messages.ServerMessage;
@ -8,60 +13,65 @@ import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
public class UpdateFriendComposer extends MessageComposer {
private MessengerBuddy buddy;
private Collection<MessengerBuddy> buddies;
private Habbo habbo;
private int action;
public UpdateFriendComposer(MessengerBuddy buddy) {
this.buddy = buddy;
public UpdateFriendComposer(Habbo habbo, MessengerBuddy buddy, Integer action) {
this.habbo = habbo;
this.buddies = Collections.singletonList(buddy);
this.action = action;
}
public UpdateFriendComposer(Habbo habbo) {
public UpdateFriendComposer(Habbo habbo, Collection<MessengerBuddy> buddies, Integer action) {
this.habbo = habbo;
this.buddies = buddies;
this.action = action;
}
@Override
protected ServerMessage composeInternal() {
this.response.init(Outgoing.UpdateFriendComposer);
if (this.buddy != null) {
this.response.appendInt(0);
this.response.appendInt(1);
this.response.appendInt(0);
this.response.appendInt(this.buddy.getId());
this.response.appendString(this.buddy.getUsername());
this.response.appendInt(this.buddy.getGender().equals(HabboGender.M) ? 0 : 1);
this.response.appendBoolean(this.buddy.getOnline() == 1);
this.response.appendBoolean(this.buddy.inRoom()); //In room
this.response.appendString(this.buddy.getLook());
this.response.appendInt(0);
this.response.appendString(this.buddy.getMotto());
this.response.appendString("");
this.response.appendString("");
this.response.appendBoolean(false);
this.response.appendBoolean(false);
this.response.appendBoolean(false);
this.response.appendShort(this.buddy.getRelation());
if (this.habbo != null && !this.habbo.getHabboInfo().getMessengerCategories().isEmpty()) {
List<MessengerCategory> messengerCategories = this.habbo.getHabboInfo().getMessengerCategories();
this.response.appendInt(messengerCategories.size());
for (MessengerCategory mc : messengerCategories) {
this.response.appendInt(mc.getId());
this.response.appendString(mc.getName());
}
} else {
this.response.appendInt(0);
this.response.appendInt(1);
this.response.appendInt(0);
this.response.appendInt(-1);
this.response.appendString("Staff Chat");
this.response.appendInt(0);
this.response.appendBoolean(true);
this.response.appendBoolean(false); //In room
this.response.appendString(this.habbo.getHabboInfo().getLook());
this.response.appendInt(0);
this.response.appendString("");
this.response.appendString("");
this.response.appendString("");
this.response.appendBoolean(false);
this.response.appendBoolean(false);
this.response.appendBoolean(false);
this.response.appendShort(0);
}
this.response.appendInt(buddies.size()); // totalbuddies
for(MessengerBuddy buddy : buddies){
if (buddy != null) {
this.response.appendInt(this.action); // -1 = removed friendId / 0 = updated friend / 1 = added friend
this.response.appendInt(buddy.getId());
if (this.action == -1) {
continue;
}
this.response.appendString(buddy.getUsername());
this.response.appendInt(buddy.getGender().equals(HabboGender.M) ? 0 : 1);
this.response.appendBoolean(buddy.getOnline() == 1);
this.response.appendBoolean(buddy.inRoom()); //In room
this.response.appendString(buddy.getLook());
this.response.appendInt(buddy.getCategoryId());
this.response.appendString(buddy.getMotto());
this.response.appendString(""); //Last seen as DATETIMESTRING
this.response.appendString(""); //Realname or Facebookame as String
this.response.appendBoolean(false); //Offline messaging.
this.response.appendBoolean(false);
this.response.appendBoolean(false);
this.response.appendShort(buddy.getRelation());
}
}
return this.response;
}
}