diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 5cef84a8..f3dcf45d 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -78,6 +78,10 @@ message.disable_remote_search false ##允许客户端撤回消息时限,单位是秒。群组管理员或群主撤回群成员消息、server api不受此限制,可以撤回任意时限内的消息 message.recall_time_limit 120 +## 禁止客户端发送消息类型,消息类型以逗号分开,下面3个值为示例,可以删除。 +## 一般用于重要类型消息,比如交易、充值等,禁止客户端发送,仅限于服务器发送,提高安全性。 +message.forbidden_client_send_types 3999,4000,4001 + ##禁止搜索用户 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 994af5b0..3940c510 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -153,6 +153,8 @@ public final class BrokerConstants { public static final String GROUP_Allow_Client_Custom_Operation_Notification = "group.allow_client_custom_operation_notification"; + public static final String MESSAGES_FORBIDDEN_CLIENT_SEND_TYPES = "message.forbidden_client_send_types"; + public static final String MESSAGES_DISABLE_REMOTE_SEARCH = "message.disable_remote_search"; public static final String MESSAGES_RECALL_TIME_LIMIT = "message.recall_time_limit"; diff --git a/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java b/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java index dd05b197..17b1c6ca 100644 --- a/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java +++ b/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java @@ -58,9 +58,14 @@ public class SendMessageHandler extends IMHandler { boolean ignoreMsg = false; if (!isAdmin) { //admin do not check the right // 不能在端上直接发送撤回和群通知 - if (message.getContent().getType() == 80 || (message.getContent().getType() >= 100 && message.getContent().getType() < 200)) { + if (message.getContent().getType() == 80 || message.getContent().getType() == 81 || (message.getContent().getType() >= 100 && message.getContent().getType() < 200)) { return ErrorCode.INVALID_PARAMETER; } + + if(m_messagesStore.getClientForbiddenSendTypes().contains(message.getContent().getType())) { + return ErrorCode.ERROR_CODE_NOT_RIGHT; + } + int userStatus = m_messagesStore.getUserStatus(fromUser); if (userStatus == ProtoConstants.UserStatus.Muted || userStatus == ProtoConstants.UserStatus.Forbidden) { return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 1ec89d55..9168d1b6 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -141,6 +141,8 @@ public class MemoryMessagesStore implements IMessagesStore { private long mChatroomParticipantIdleTime = 900000; private boolean mChatroomRejoinWhenActive = true; + private List mForbiddenClientSendTypes = new ArrayList<>(); + private long mRecallTimeLimit = 300; private String mGroupInfoUpdateCallback; @@ -258,6 +260,23 @@ public class MemoryMessagesStore implements IMessagesStore { } catch (Exception e) { } + try { + String strTypes = m_Server.getConfig().getProperty(BrokerConstants.MESSAGES_FORBIDDEN_CLIENT_SEND_TYPES); + if(!StringUtil.isNullOrEmpty(strTypes)) { + for (String strType:strTypes.split(",")) { + try { + int type = Integer.parseInt(strType); + mForbiddenClientSendTypes.add(type); + } catch (NumberFormatException e) { + + } + } + } + } catch (Exception e) { + } + + + try { mGroupInfoUpdateCallback = server.getConfig().getProperty(GROUP_INFO_UPDATE_CALLBACK); } catch (Exception e) { @@ -3269,6 +3288,11 @@ public class MemoryMessagesStore implements IMessagesStore { return mGroupAllowClientCustomOperationNotification; } + @Override + public List getClientForbiddenSendTypes() { + return mForbiddenClientSendTypes; + } + @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 f7bb234d..be0d0ece 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -211,6 +211,7 @@ public interface IMessagesStore { WFCMessage.Message getMessage(long messageId); boolean isAllowClientCustomGroupNotification(); + List getClientForbiddenSendTypes(); 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 d1042a62..0c10d839 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -69,6 +69,10 @@ message.disable_remote_search false ##允许客户端撤回消息时限,单位是秒。群组管理员或群主撤回群成员消息、server api不受此限制,可以撤回任意时限内的消息 message.recall_time_limit 120 +## 禁止客户端发送消息类型,消息类型以逗号分开,下面3个值为示例,可以删除。 +## 一般用于重要类型消息,比如交易、充值等,禁止客户端发送,仅限于服务器发送,提高安全性。 +message.forbidden_client_send_types 3999,4000,4001 + ##禁止搜索用户 friend.disable_search false