Plugins can now create friend list entries - See Arcturus Extended for examples

This commit is contained in:
Beny 2019-05-12 22:54:26 +01:00
parent 2b19bdd0d6
commit 4fb9cd8d5c
5 changed files with 50 additions and 35 deletions

View File

@ -49,9 +49,6 @@ public final class Emulator
public static String build = ""; public static String build = "";
public static MessengerBuddy publicChatBuddy;
public static boolean isReady = false; public static boolean isReady = false;
public static boolean isShuttingDown = false; public static boolean isShuttingDown = false;
@ -100,7 +97,6 @@ public final class Emulator
Emulator.getLogging().logStart("\r" + Emulator.logo + Emulator.getLogging().logStart("\r" + Emulator.logo +
" Build: " + build + "\n"); " Build: " + build + "\n");
random = new Random(); random = new Random();
publicChatBuddy = new MessengerBuddy(-1, "Staff Chat", "", (short) 0, 0);
long startTime = System.nanoTime(); long startTime = System.nanoTime();
Emulator.runtime = Runtime.getRuntime(); Emulator.runtime = Runtime.getRuntime();

View File

@ -124,6 +124,11 @@ public class Messenger
this.friends.remove(habbo.getHabboInfo().getId()); this.friends.remove(habbo.getHabboInfo().getId());
} }
public void addBuddy(MessengerBuddy buddy)
{
this.friends.put(buddy.getId(), buddy);
}
public static void unfriend(int userOne, int userTwo) public static void unfriend(int userOne, int userTwo)
{ {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM messenger_friendships WHERE (user_one_id = ? AND user_two_id = ?) OR (user_one_id = ? AND user_two_id = ?)")) try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM messenger_friendships WHERE (user_one_id = ? AND user_two_id = ?) OR (user_one_id = ? AND user_two_id = ?)"))

View File

@ -1,15 +1,19 @@
package com.eu.habbo.habbohotel.messenger; package com.eu.habbo.habbohotel.messenger;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.modtool.WordFilter;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender; import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.friends.FriendChatMessageComposer;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
public class MessengerBuddy implements Runnable { public class MessengerBuddy implements Runnable, ISerialize {
private int id; private int id;
private String username; private String username;
@ -176,4 +180,39 @@ public class MessengerBuddy implements Runnable {
Emulator.getLogging().logSQLException(e); Emulator.getLogging().logSQLException(e);
} }
} }
public void onMessageReceived(Habbo from, String message) {
Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(this.id);
if(habbo == null)
return;
Message chatMessage = new Message(from.getHabboInfo().getId(), this.id, message);
Emulator.getThreading().run(chatMessage);
if (WordFilter.ENABLED_FRIENDCHAT)
{
chatMessage.setMessage(Emulator.getGameEnvironment().getWordFilter().filter(chatMessage.getMessage(), from));
}
habbo.getClient().sendResponse(new FriendChatMessageComposer(chatMessage));
}
@Override
public void serialize(ServerMessage message) {
message.appendInt(this.id);
message.appendString(this.username);
message.appendInt(this.gender.equals(HabboGender.M) ? 0 : 1);
message.appendBoolean(this.online == 1);
message.appendBoolean(this.inRoom); //IN ROOM
message.appendString(this.look);
message.appendInt(0);
message.appendString(this.motto);
message.appendString("");
message.appendString("");
message.appendBoolean(false); //Offline messaging.
message.appendBoolean(false);
message.appendBoolean(false);
message.appendShort(this.relation);
}
} }

View File

@ -30,40 +30,14 @@ public class FriendPrivateMessageEvent extends MessageHandler
} }
this.client.getHabbo().getHabboStats().lastChat = millis; this.client.getHabbo().getHabboStats().lastChat = millis;
if(userId == Emulator.publicChatBuddy.getId())
{
if(message.startsWith(":"))
{
CommandHandler.handleCommand(this.client, message);
return;
}
Emulator.getGameServer().getGameClientManager().sendBroadcastResponse(new FriendChatMessageComposer(new Message(this.client.getHabbo().getHabboInfo().getId(), -1, message)).compose(), "acc_staff_chat", this.client);
return;
}
MessengerBuddy buddy = this.client.getHabbo().getMessenger().getFriend(userId); MessengerBuddy buddy = this.client.getHabbo().getMessenger().getFriend(userId);
if (buddy == null) if (buddy == null)
{
return; return;
}
UserFriendChatEvent event = new UserFriendChatEvent(this.client.getHabbo(), buddy, message); UserFriendChatEvent event = new UserFriendChatEvent(this.client.getHabbo(), buddy, message);
if(Emulator.getPluginManager().fireEvent(event).isCancelled()) if(Emulator.getPluginManager().fireEvent(event).isCancelled())
return; return;
Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(userId); buddy.onMessageReceived(this.client.getHabbo(), message);
if(habbo == null)
return;
Message chatMessage = new Message(this.client.getHabbo().getHabboInfo().getId(), userId, event.message);
Emulator.getThreading().run(chatMessage);
if (WordFilter.ENABLED_FRIENDCHAT)
{
chatMessage.setMessage(Emulator.getGameEnvironment().getWordFilter().filter(chatMessage.getMessage(), this.client.getHabbo()));
}
habbo.getClient().sendResponse(new FriendChatMessageComposer(chatMessage));
} }
} }

View File

@ -32,7 +32,7 @@ public class FriendsComposer extends MessageComposer
//this.response.appendInt(3); //Club level //this.response.appendInt(3); //Club level
this.response.appendInt(this.habbo.hasPermission("acc_infinite_friends") ? Integer.MAX_VALUE : Messenger.MAXIMUM_FRIENDS); this.response.appendInt(this.habbo.hasPermission("acc_infinite_friends") ? Integer.MAX_VALUE : Messenger.MAXIMUM_FRIENDS);
this.response.appendInt(this.habbo.hasPermission("acc_infinite_friends") ? Integer.MAX_VALUE : Messenger.MAXIMUM_FRIENDS); this.response.appendInt(this.habbo.hasPermission("acc_infinite_friends") ? Integer.MAX_VALUE : Messenger.MAXIMUM_FRIENDS);
this.response.appendInt(this.habbo.getMessenger().getFriends().size() + (this.habbo.hasPermission("acc_staff_chat") ? 1 : 0)); this.response.appendInt(this.habbo.getMessenger().getFriends().size()/* + (this.habbo.hasPermission("acc_staff_chat") ? 1 : 0)*/);
for (Map.Entry<Integer, MessengerBuddy> row : this.habbo.getMessenger().getFriends().entrySet()) { for (Map.Entry<Integer, MessengerBuddy> row : this.habbo.getMessenger().getFriends().entrySet()) {
this.response.appendInt(row.getKey()); this.response.appendInt(row.getKey());
@ -51,7 +51,7 @@ public class FriendsComposer extends MessageComposer
this.response.appendShort(row.getValue().getRelation()); this.response.appendShort(row.getValue().getRelation());
} }
if(this.habbo.hasPermission("acc_staff_chat")) /*if(this.habbo.hasPermission("acc_staff_chat"))
{ {
this.response.appendInt(-1); this.response.appendInt(-1);
this.response.appendString("Staff Chat"); this.response.appendString("Staff Chat");
@ -67,7 +67,8 @@ public class FriendsComposer extends MessageComposer
this.response.appendBoolean(false); this.response.appendBoolean(false);
this.response.appendBoolean(false); this.response.appendBoolean(false);
this.response.appendShort(0); this.response.appendShort(0);
} }*/
return this.response; return this.response;
} }
catch(Exception e) catch(Exception e)