Skip to content

Commit

Permalink
新增 autoNameChange 配置
Browse files Browse the repository at this point in the history
  • Loading branch information
CaaMoe committed May 19, 2023
1 parent 623ca43 commit 0868228
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public class ValidateContext {

private final GameProfile inGameProfile;
private String disallowMessage;

private boolean needWait;
private boolean onlineNameUpdated = false;


protected ValidateContext(BaseServiceAuthenticationResult baseServiceAuthenticationResult) {
this.baseServiceAuthenticationResult = baseServiceAuthenticationResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public Signal run(ValidateContext validateContext) {
inGameUUID);
}
}
if (core.getPluginConfig().isAutoNameChange() && validateContext.isOnlineNameUpdated()) {
String username = core.getSqlManager().getInGameProfileTable().getUsername(inGameUUID);
if (!ValueUtil.isEmpty(username)) {
core.getSqlManager().getInGameProfileTable().eraseUsername(username);
}
}

// 身份卡UUID数据存在,看看数据库中有没有对应的记录
boolean exist = core.getSqlManager().getInGameProfileTable().dataExists(inGameUUID);
if (exist) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package moe.caa.multilogin.core.auth.validate.entry;

import lombok.SneakyThrows;
import moe.caa.multilogin.api.util.There;
import moe.caa.multilogin.core.auth.validate.ValidateContext;
import moe.caa.multilogin.core.database.table.UserDataTableV3;
import moe.caa.multilogin.core.main.MultiCore;
import moe.caa.multilogin.flows.workflows.BaseFlows;
import moe.caa.multilogin.flows.workflows.Signal;

import java.util.UUID;

public class InitialLoginDataFlows extends BaseFlows<ValidateContext> {
private final MultiCore core;

Expand All @@ -18,22 +21,24 @@ public InitialLoginDataFlows(MultiCore core) {
@Override
public Signal run(ValidateContext validateContext) {
UserDataTableV3 dataTable = core.getSqlManager().getUserDataTable();
if (!dataTable.dataExists(
validateContext.getBaseServiceAuthenticationResult().getResponse().getId(),
validateContext.getBaseServiceAuthenticationResult().getServiceConfig().getId()
)) {
There<String, UUID, Boolean> there = dataTable.get(validateContext.getBaseServiceAuthenticationResult().getResponse().getId(),
validateContext.getBaseServiceAuthenticationResult().getServiceConfig().getId());
if (there == null) {
dataTable.insertNewData(
validateContext.getBaseServiceAuthenticationResult().getResponse().getId(),
validateContext.getBaseServiceAuthenticationResult().getServiceConfig().getId(),
validateContext.getBaseServiceAuthenticationResult().getResponse().getName(),
null
);
} else {
dataTable.setOnlineName(
validateContext.getBaseServiceAuthenticationResult().getResponse().getId(),
validateContext.getBaseServiceAuthenticationResult().getServiceConfig().getId(),
validateContext.getBaseServiceAuthenticationResult().getResponse().getName()
);
if (!validateContext.getBaseServiceAuthenticationResult().getResponse().getName().equals(there.getValue1())) {
dataTable.setOnlineName(
validateContext.getBaseServiceAuthenticationResult().getResponse().getId(),
validateContext.getBaseServiceAuthenticationResult().getServiceConfig().getId(),
validateContext.getBaseServiceAuthenticationResult().getResponse().getName()
);
validateContext.setOnlineNameUpdated(true);
}
}
return Signal.PASSED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class PluginConfig {
@Getter
private boolean floodgateSupport;
@Getter
private boolean autoNameChange;
@Getter
private SqlConfig sqlConfig;
@Getter
private String nameAllowedRegular;
Expand Down Expand Up @@ -98,6 +100,7 @@ public void reload() throws IOException, URISyntaxException {
floodgateSupport = configConfigurationNode.node("floodgateSupport").getBoolean(false);
welcomeMsg = configConfigurationNode.node("welcomeMsg").getBoolean(true);
nameCorrect = configConfigurationNode.node("nameCorrect").getBoolean(true);
autoNameChange = configConfigurationNode.node("autoNameChange").getBoolean(true);

Map<Integer, BaseServiceConfig> idMap = new HashMap<>();
try (Stream<Path> list = Files.list(servicesFolder.toPath())) {
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ nameAllowedRegular: '^[0-9a-zA-Z_]{3,16}$'
# 默认值 true
nameCorrect: true

# 当在线档案改名后是否自动 erase 老的档案用户名称并且分配在线档案用户名给当前档案使用(不忽略重名检查)
#
# 默认值 true
autoNameChange: true

# 插件数据设置
sql:

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
plugin_version=0.6.3
plugin_version=0.6.4
org.gradle.jvmargs=-Xmx1024m
2 changes: 1 addition & 1 deletion latest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.2
0.6.4

0 comments on commit 0868228

Please sign in to comment.