可以系统设置里设置那么名字不能被使用

This commit is contained in:
heavyrian2012
2025-08-05 17:11:00 +08:00
parent bee03cd2f8
commit 2d7f344b1a
11 changed files with 100 additions and 29 deletions
@@ -1 +1 @@
CREATE INDEX `user_gid_mid_dt_index` ON `t_group_member` (`_gid`, `_mid`, `_dt`);
CREATE INDEX `user_gid_dt_index` ON `t_group_member` (`_gid`, `_dt`);
+1
View File
@@ -0,0 +1 @@
insert into t_settings(`id`, `_value`,`_desc`) values (2, '文件传输助手,客服,官方', '禁止使用名称,如果有多个,以英文逗号隔开。直接修改数据库,不用重启IM服务');
@@ -0,0 +1,2 @@
DROP INDEX `user_gid_mid_dt_index` ON `t_group_member`;
CREATE INDEX `user_gid_dt_index` ON `t_group_member` (`_gid`, `_dt`);
+1
View File
@@ -0,0 +1 @@
insert into t_settings(`id`, `_value`,`_desc`) values (2, '文件传输助手,客服,官方', '禁止使用名称,如果有多个,以英文逗号隔开。直接修改数据库,不用重启IM服务');
@@ -69,10 +69,16 @@ public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupReque
return ErrorCode.INVALID_PARAMETER;
}
if(!m_messagesStore.isSensitiveOnlyMessage() && !isAdmin && !StringUtil.isNullOrEmpty(request.getGroup().getGroupInfo().getName())) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getGroup().getGroupInfo().getName());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
if(!isAdmin && !StringUtil.isNullOrEmpty(request.getGroup().getGroupInfo().getName())) {
if(!m_messagesStore.isSensitiveOnlyMessage()) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getGroup().getGroupInfo().getName());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!m_messagesStore.isAllowName(request.getGroup().getGroupInfo().getName())) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
@@ -34,10 +34,16 @@ public class ModifyGroupAliasHandler extends GroupHandler<WFCMessage.ModifyGroup
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
if (!m_messagesStore.isSensitiveOnlyMessage() && !isAdmin && !StringUtil.isNullOrEmpty(request.getAlias())) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getAlias());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
if (!isAdmin && !StringUtil.isNullOrEmpty(request.getAlias())) {
if(!m_messagesStore.isSensitiveOnlyMessage()) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getAlias());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!m_messagesStore.isAllowName(request.getAlias())) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
@@ -32,10 +32,16 @@ public class ModifyGroupMemberAliasHandler extends GroupHandler<WFCMessage.Modif
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0 && requestSourceType == ProtoConstants.RequestSourceType.Request_From_Robot && !m_messagesStore.isAllowRobotCustomGroupNotification()) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
if (!m_messagesStore.isSensitiveOnlyMessage() && !isAdmin && !StringUtil.isNullOrEmpty(request.getAlias())) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getAlias());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
if (!isAdmin && !StringUtil.isNullOrEmpty(request.getAlias())) {
if(!m_messagesStore.isSensitiveOnlyMessage()) {
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getAlias());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!m_messagesStore.isAllowName(request.getAlias())) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
@@ -1980,10 +1980,16 @@ public class MemoryMessagesStore implements IMessagesStore {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
if (!mSensitiveOnlyMessage && modifyType == Modify_Group_Name && !StringUtil.isNullOrEmpty(value)) {
Set<String> matched = handleSensitiveWord(value);
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
if (modifyType == Modify_Group_Name && !StringUtil.isNullOrEmpty(value)) {
if(!mSensitiveOnlyMessage) {
Set<String> matched = handleSensitiveWord(value);
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!isAllowName(value)) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
}
@@ -2822,12 +2828,19 @@ public class MemoryMessagesStore implements IMessagesStore {
) {
switch (entry.getType()) {
case Modify_DisplayName:
if(!mSensitiveOnlyMessage) {
Set<String> matched = handleSensitiveWord(entry.getValue());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
if(!StringUtil.isNullOrEmpty(entry.getValue())) {
if (!mSensitiveOnlyMessage) {
Set<String> matched = handleSensitiveWord(entry.getValue());
if (matched != null && !matched.isEmpty()) {
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
}
}
if(!isAllowName(entry.getValue())) {
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
}
builder.setDisplayName(entry.getValue());
modified = true;
break;
@@ -3919,6 +3932,25 @@ public class MemoryMessagesStore implements IMessagesStore {
return ErrorCode.ERROR_CODE_SUCCESS;
}
@Override
public boolean isAllowName(String name) {
if(StringUtil.isNullOrEmpty(name)) {
return true;
}
name = name.trim();
SystemSettingPojo notAllowNameSetting = getSystemSetting(ProtoConstants.SystemSettingType.NOT_ALLOW_USER_NAMES);
if (notAllowNameSetting != null && !StringUtil.isNullOrEmpty(notAllowNameSetting.value)) {
String[] ss = notAllowNameSetting.value.split(",");
for (String s : ss) {
if(name.contains(s.trim())) {
return false;
}
}
}
return true;
}
@Override
public ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId) {
IMap<String, WFCMessage.ChatroomInfo> chatroomInfoMap = m_Server.getHazelcastInstance().getMap(CHATROOMS);
@@ -190,6 +190,8 @@ public interface IMessagesStore {
ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] head);
ErrorCode setFriendExtraRequest(String fromUser, String targetUserId, String extra, long[] head);
boolean isAllowName(String name);
ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId);
ErrorCode handleQuitChatroom(String userId, String clientId, String chatroomId);
@@ -226,6 +226,7 @@ public class ProtoConstants {
public interface SystemSettingType {
int Group_Max_Member_Count = 1;
int NOT_ALLOW_USER_NAMES = 2;
}
public interface SearchUserType {
@@ -58,6 +58,9 @@ public class Main {
//测试解析数据库中消息内容
testReadMessageContentFromDB();
//计算消息分表
testMessageSharding();
//Robot和Channel都是使用的80端口,第三方可以创建或者为第三方创建,第三方可以使用robot或者channel与IM系统进行对接。
testRobot();
testChannel();
@@ -616,7 +619,7 @@ public class Main {
System.exit(-1);
}
voidIMResult = GroupAdmin.setGroupMemberAlias("user1", groupInfo.getTarget_id(), "user3", "test user3", null, null);
voidIMResult = GroupAdmin.setGroupMemberAlias("user1", groupInfo.getTarget_id(), "user2", "test user2", null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("set group member alias success");
} else {
@@ -1003,13 +1006,24 @@ public class Main {
testStreamingText(sender, conversation);
}
static void testReadMessageContentFromDB() throws Exception {
//需要注意几点:
// 1 WFCMessage类不能混淆,如果混淆 WFCMessage.MessageContent.parseFrom(data) 就会失败。
// 2 MessageContentFactory方法会自动查找所有的消息类,包括文本/图片/语音等。也有可能在某些环境下找不到这些类。可以检查MessageContentFactory
// 类的源码,修改registerAllMessageContent方法,确保能找到所有的内容类。也可以显式调用注册的方法把所有已知消息都注册一遍,比如:
// MessageContentFactory.registerCustomMessageContent(TextMessageContent.class); //这里示例只写了文本的,其他所有已知消息都需要注册一遍。
//消息相关表分为2类,分表是:t_messages_x和t_user_messages_y,并且是分表存储的。表内存储数据和分表规则请参考 https://docs.wildfirechat.cn/faq/server.html 问题2
static void testMessageSharding() {
String userId = "user1";
int hashId = Math.abs(userId.hashCode())%128;
String userMessageTable = "t_user_messages_" + hashId;
System.out.println("user:" + userId + " user messages table is " + userMessageTable);
Calendar calendar = Calendar.getInstance();
Date date = new Date();
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
year %= 3;
String messageTable = "t_messages_" + (year * 12 + month);
System.out.println("This month save message to table " + messageTable);
}
static void testReadMessageContentFromDB() throws Exception {
//从数据库t_messages_x表中读取到消息内容字段_data的二进制数据为
byte[] data = {8,1,18,5,72,101,108,108,111,64,3};
//1. 先把二进制数据转化为协议栈消息内容。
@@ -1605,7 +1619,7 @@ public class Main {
System.exit(-1);
}
voidIMResult = robotService.setGroupMemberAlias(groupInfo.getTarget_id(), "user3", "test user3", null, null);
voidIMResult = robotService.setGroupMemberAlias(groupInfo.getTarget_id(), "user2", "test user2", null, null);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("set group member alias success");
} else {