diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 54f8605e..51151023 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -81,6 +81,15 @@ message.recall_time_limit 120 ## 一般用于重要类型消息,比如交易、充值等,禁止客户端发送,仅限于服务器发送,提高安全性。 message.forbidden_client_send_types 3999,4000,4001 +## 当禁止发送消息时,允许例外发送的消息。这种一般用户需要被动回应的消息。比如群中被禁言的用户,他无法主动发起音视频,但可以接听未被禁言用户的音视频 +## 因为音视频使用了消息作为信令,所以就需要允许发送音视频信令。如果开发了其它场景也需要被动回应消息,可以加在这里。 +## 黑名单时允许发送的消息类型 +message.blacklist_exception_types 401,402,403,404,405,407,408,410,411 +## 群禁言或者聊天室或者频道禁言时允许发送的消息类型 +message.group_mute_exception_types 401,402,403,404,405,407,408,410,411 +## 用户被全局禁言时允许发送的消息类型 +message.global_mute_exception_types 401,402,403,404,405,407,408,410,411 + ##禁止搜索用户 friend.disable_search false diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 16626757..9351b439 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -157,6 +157,9 @@ public final class BrokerConstants { public static final String USER_HIDE_PROPERTIES = "user.hide_properties"; public static final String MESSAGES_FORBIDDEN_CLIENT_SEND_TYPES = "message.forbidden_client_send_types"; + public static final String MESSAGES_BLACKLIST_EXCEPTION_TYPES = "message.blacklist_exception_types"; + public static final String MESSAGES_GROUP_MUTE_EXCEPTION_TYPES = "message.group_mute_exception_types"; + public static final String MESSAGES_GLOBAL_MUTE_EXCEPTION_TYPES = "message.global_mute_exception_types"; public static final String MESSAGES_DISABLE_REMOTE_SEARCH = "message.disable_remote_search"; diff --git a/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java b/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java index 7aa7053f..bc123481 100644 --- a/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java +++ b/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java @@ -105,17 +105,21 @@ public class SendMessageHandler extends IMHandler { int userStatus = m_messagesStore.getUserStatus(fromUser); if (userStatus == ProtoConstants.UserStatus.Muted || userStatus == ProtoConstants.UserStatus.Forbidden) { - return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG; + if(!m_messagesStore.getGlobalMuteExceptionTypes().contains(message.getContent().getType())) { + return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG; + } } if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private) { - errorCode = m_messagesStore.isAllowUserMessage(message.getConversation().getTarget(), fromUser); - if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) { - if (errorCode == ErrorCode.ERROR_CODE_IN_BLACK_LIST && mBlacklistStrategy != ProtoConstants.BlacklistStrategy.Message_Reject) { - ignoreMsg = true; - errorCode = ErrorCode.ERROR_CODE_SUCCESS; - } else { - return errorCode; + if(!m_messagesStore.getBlackListExceptionTypes().contains(message.getContent().getType())) { + errorCode = m_messagesStore.isAllowUserMessage(message.getConversation().getTarget(), fromUser); + if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) { + if (errorCode == ErrorCode.ERROR_CODE_IN_BLACK_LIST && mBlacklistStrategy != ProtoConstants.BlacklistStrategy.Message_Reject) { + ignoreMsg = true; + errorCode = ErrorCode.ERROR_CODE_SUCCESS; + } else { + return errorCode; + } } } @@ -126,17 +130,23 @@ public class SendMessageHandler extends IMHandler { } if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group ) { - errorCode = m_messagesStore.canSendMessageInGroup(fromUser, message.getConversation().getTarget()); - if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) { - return errorCode; + if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) { + errorCode = m_messagesStore.canSendMessageInGroup(fromUser, message.getConversation().getTarget()); + if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) { + return errorCode; + } } } else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom) { - if(!m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) { - return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM; + if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) { + if (!m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) { + return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM; + } } } else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) { - if(!m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) { - return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL; + if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) { + if (!m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) { + return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL; + } } } } diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 25ee63b4..fc4592a6 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -139,6 +139,9 @@ public class MemoryMessagesStore implements IMessagesStore { private boolean mChatroomRejoinWhenActive = true; private List mForbiddenClientSendTypes = new ArrayList<>(); + private List mBlackListExceptionTypes = new ArrayList<>(); + private List mGroupMuteExceptionTypes = new ArrayList<>(); + private List mGlobalMuteExceptionTypes = new ArrayList<>(); private long mRecallTimeLimit = 300; @@ -275,7 +278,48 @@ public class MemoryMessagesStore implements IMessagesStore { } catch (Exception e) { } + try { + String strTypes = m_Server.getConfig().getProperty(BrokerConstants.MESSAGES_BLACKLIST_EXCEPTION_TYPES); + if(!StringUtil.isNullOrEmpty(strTypes)) { + for (String strType:strTypes.split(",")) { + try { + int type = Integer.parseInt(strType); + mBlackListExceptionTypes.add(type); + } catch (NumberFormatException e) { + } + } + } + } catch (Exception e) { + } + try { + String strTypes = m_Server.getConfig().getProperty(BrokerConstants.MESSAGES_GROUP_MUTE_EXCEPTION_TYPES); + if(!StringUtil.isNullOrEmpty(strTypes)) { + for (String strType:strTypes.split(",")) { + try { + int type = Integer.parseInt(strType); + mGroupMuteExceptionTypes.add(type); + } catch (NumberFormatException e) { + + } + } + } + } catch (Exception e) { + } + try { + String strTypes = m_Server.getConfig().getProperty(BrokerConstants.MESSAGES_GLOBAL_MUTE_EXCEPTION_TYPES); + if(!StringUtil.isNullOrEmpty(strTypes)) { + for (String strType:strTypes.split(",")) { + try { + int type = Integer.parseInt(strType); + mGlobalMuteExceptionTypes.add(type); + } catch (NumberFormatException e) { + + } + } + } + } catch (Exception e) { + } try { mGroupInfoUpdateCallback = server.getConfig().getProperty(GROUP_INFO_UPDATE_CALLBACK); @@ -3467,6 +3511,21 @@ public class MemoryMessagesStore implements IMessagesStore { return mForbiddenClientSendTypes; } + @Override + public List getBlackListExceptionTypes() { + return mBlackListExceptionTypes; + } + + @Override + public List getGroupMuteExceptionTypes() { + return mGroupMuteExceptionTypes; + } + + @Override + public List getGlobalMuteExceptionTypes() { + return mGlobalMuteExceptionTypes; + } + @Override public long getMessageHead(String user) { TreeMap maps = userMessages.get(user); diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index 643b0aa5..99e7b26a 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -220,6 +220,9 @@ public interface IMessagesStore { int getVisibleQuitKickoffNotification(); List getClientForbiddenSendTypes(); + List getBlackListExceptionTypes(); + List getGroupMuteExceptionTypes(); + List getGlobalMuteExceptionTypes(); long getMessageHead(String user); long getFriendHead(String user); diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index dac859d6..862f9846 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -76,6 +76,14 @@ message.recall_time_limit 120 ## 一般用于重要类型消息,比如交易、充值等,禁止客户端发送,仅限于服务器发送,提高安全性。 message.forbidden_client_send_types 3999,4000,4001 +## 当禁止发送消息时,允许例外发送的消息。这种一般用户需要被动回应的消息。比如群中被禁言的用户,他无法主动发起音视频,但可以接听未被禁言用户的音视频 +## 因为音视频使用了消息作为信令,所以就需要允许发送音视频信令。如果开发了其它场景也需要被动回应消息,可以加在这里。 +## 黑名单时允许发送的消息类型 +message.blacklist_exception_types 401,402,403,404,405,407,408,410,411 +## 群禁言或者聊天室或者频道禁言时允许发送的消息类型 +message.group_mute_exception_types 401,402,403,404,405,407,408,410,411 +## 用户被全局禁言时允许发送的消息类型 +message.global_mute_exception_types 401,402,403,404,405,407,408,410,411 ##禁止搜索用户 friend.disable_search false