Fix all last edge cases.

This commit is contained in:
Mike 2020-05-10 00:11:56 +02:00
parent 463fb82654
commit 46ff22f720
7 changed files with 146 additions and 90 deletions

View File

@ -24,15 +24,18 @@ public class HotelAlertCommand extends Command {
} }
ServerMessage msg = new StaffAlertWithLinkComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername(), "").compose(); ServerMessage msg = new StaffAlertWithLinkComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername(), "").compose();
msg.retain();
try {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
Habbo habbo = set.getValue();
if (habbo.getHabboStats().blockStaffAlerts)
continue;
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { habbo.getClient().sendResponse(msg);
Habbo habbo = set.getValue(); }
if (habbo.getHabboStats().blockStaffAlerts) } finally {
continue; msg.release();
habbo.getClient().sendResponse(msg);
} }
} else { } else {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_ha.forgot_message"), RoomChatMessageBubbles.ALERT); gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_ha.forgot_message"), RoomChatMessageBubbles.ALERT);
} }

View File

@ -24,8 +24,13 @@ public class ReloadRoomCommand extends Command {
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId());
ServerMessage message = new ForwardToRoomComposer(room.getId()).compose(); ServerMessage message = new ForwardToRoomComposer(room.getId()).compose();
for (Habbo habbo : habbos) { message.retain();
habbo.getClient().sendResponse(message); try {
for (Habbo habbo : habbos) {
habbo.getClient().sendResponse(message);
}
} finally {
message.release();
} }
} }
}, 100); }, 100);

View File

@ -134,32 +134,47 @@ public class GameClientManager {
public void sendBroadcastResponse(ServerMessage message) { public void sendBroadcastResponse(ServerMessage message) {
for (GameClient client : this.clients.values()) { message.retain();
client.sendResponse(message); try {
for (GameClient client : this.clients.values()) {
client.sendResponse(message);
}
} finally {
message.release();
} }
} }
public void sendBroadcastResponse(ServerMessage message, GameClient exclude) { public void sendBroadcastResponse(ServerMessage message, GameClient exclude) {
for (GameClient client : this.clients.values()) { message.retain();
if (client.equals(exclude)) try {
continue; for (GameClient client : this.clients.values()) {
if (client.equals(exclude))
continue;
client.sendResponse(message); client.sendResponse(message);
}
} finally {
message.release();
} }
} }
public void sendBroadcastResponse(ServerMessage message, String minPermission, GameClient exclude) { public void sendBroadcastResponse(ServerMessage message, String minPermission, GameClient exclude) {
for (GameClient client : this.clients.values()) { message.retain();
if (client.equals(exclude)) try {
continue; for (GameClient client : this.clients.values()) {
if (client.equals(exclude))
continue;
if (client.getHabbo() != null) { if (client.getHabbo() != null) {
if (client.getHabbo().hasPermission(minPermission)) { if (client.getHabbo().hasPermission(minPermission)) {
client.sendResponse(message); client.sendResponse(message);
}
} }
} }
} finally {
message.release();
} }
} }
} }

View File

@ -3115,57 +3115,87 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
roomChatMessage.setMessage(trimmedMessage); roomChatMessage.setMessage(trimmedMessage);
if (chatType == RoomChatType.WHISPER) { if (prefixMessage != null) {
if (roomChatMessage.getTargetHabbo() == null) { prefixMessage.retain();
return; }
}
RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage); if (clearPrefixMessage != null) {
staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage()); clearPrefixMessage.retain();
}
final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose(); try {
final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose(); if (chatType == RoomChatType.WHISPER) {
if (roomChatMessage.getTargetHabbo() == null) {
return;
}
message.retain(); RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage);
staffMessage.retain(); staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage());
try { final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose();
for (Habbo h : this.getHabbos()) { final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose();
if (h == roomChatMessage.getTargetHabbo() || h == habbo) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { message.retain();
if (prefixMessage != null) { staffMessage.retain();
h.getClient().sendResponse(prefixMessage);
try {
for (Habbo h : this.getHabbos()) {
if (h == roomChatMessage.getTargetHabbo() || h == habbo) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
if (prefixMessage != null) {
h.getClient().sendResponse(prefixMessage);
}
h.getClient().sendResponse(message);
if (clearPrefixMessage != null) {
h.getClient().sendResponse(clearPrefixMessage);
}
} }
h.getClient().sendResponse(message);
if (clearPrefixMessage != null) { continue;
h.getClient().sendResponse(clearPrefixMessage); }
if (h.hasPermission("acc_see_whispers")) {
h.getClient().sendResponse(staffMessage);
}
}
} finally {
message.release();
staffMessage.release();
}
} else if (chatType == RoomChatType.TALK) {
ServerMessage message = new RoomUserTalkComposer(roomChatMessage).compose();
boolean noChatLimit = habbo.hasPermission("acc_chat_no_limit");
message.retain();
try {
for (Habbo h : this.getHabbos()) {
if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance ||
h.equals(habbo) ||
this.hasRights(h) ||
noChatLimit) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
if (prefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(prefixMessage);
}
h.getClient().sendResponse(message);
if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(clearPrefixMessage);
}
} }
} }
continue;
}
if (h.hasPermission("acc_see_whispers")) {
h.getClient().sendResponse(staffMessage);
} }
} finally {
message.release();
} }
} finally { } else if (chatType == RoomChatType.SHOUT) {
message.release(); ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose();
staffMessage.release();
}
} else if (chatType == RoomChatType.TALK) {
ServerMessage message = new RoomUserTalkComposer(roomChatMessage).compose();
boolean noChatLimit = habbo.hasPermission("acc_chat_no_limit");
message.retain(); message.retain();
try { try {
for (Habbo h : this.getHabbos()) { for (Habbo h : this.getHabbos()) {
if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance || if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) {
h.equals(habbo) ||
this.hasRights(h) ||
noChatLimit) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
if (prefixMessage != null && !h.getHabboStats().preferOldChat) { if (prefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(prefixMessage); h.getClient().sendResponse(prefixMessage);
} }
@ -3175,29 +3205,17 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
} }
} finally {
message.release();
} }
} finally {
message.release();
} }
} else if (chatType == RoomChatType.SHOUT) { } finally {
ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose(); if (prefixMessage != null) {
prefixMessage.release();
}
message.retain(); if (clearPrefixMessage != null) {
clearPrefixMessage.release();
try {
for (Habbo h : this.getHabbos()) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) {
if (prefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(prefixMessage);
}
h.getClient().sendResponse(message);
if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(clearPrefixMessage);
}
}
}
} finally {
message.release();
} }
} }

View File

@ -179,10 +179,15 @@ public class HabboManager {
public void sendPacketToHabbosWithPermission(ServerMessage message, String perm) { public void sendPacketToHabbosWithPermission(ServerMessage message, String perm) {
synchronized (this.onlineHabbos) { synchronized (this.onlineHabbos) {
for (Habbo habbo : this.onlineHabbos.values()) { message.retain();
if (habbo.hasPermission(perm)) { try {
habbo.getClient().sendResponse(message); for (Habbo habbo : this.onlineHabbos.values()) {
if (habbo.hasPermission(perm)) {
habbo.getClient().sendResponse(message);
}
} }
} finally {
message.release();
} }
} }
} }

View File

@ -148,8 +148,13 @@ public class FloorPlanEditorSaveEvent extends MessageHandler {
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId());
ServerMessage message = new ForwardToRoomComposer(room.getId()).compose(); ServerMessage message = new ForwardToRoomComposer(room.getId()).compose();
for (Habbo habbo : habbos) { message.retain();
habbo.getClient().sendResponse(message); try {
for (Habbo habbo : habbos) {
habbo.getClient().sendResponse(message);
}
} finally {
message.release();
} }
} }
} }

View File

@ -25,12 +25,17 @@ public class HotelAlert extends RCONMessage<HotelAlert.JSONHotelAlert> {
} }
if (serverMessage != null) { if (serverMessage != null) {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { serverMessage.retain();
Habbo habbo = set.getValue(); try {
if (habbo.getHabboStats().blockStaffAlerts) for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
continue; Habbo habbo = set.getValue();
if (habbo.getHabboStats().blockStaffAlerts)
continue;
habbo.getClient().sendResponse(serverMessage); habbo.getClient().sendResponse(serverMessage);
}
} finally {
serverMessage.release();
} }
} }
} }