Add country whitelist for GUI captcha

This commit is contained in:
HaHaWTH 2023-11-19 10:58:47 +08:00
parent 1f88b3bc12
commit eed1c5aedc
2 changed files with 100 additions and 87 deletions

View File

@ -30,12 +30,14 @@ import org.bukkit.inventory.meta.ItemMeta;
import javax.inject.Inject; import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level; import java.util.logging.Level;
import static fr.xephi.authme.util.PlayerUtils.getPlayerIp;
import static fr.xephi.authme.util.PlayerUtils.isNpc; import static fr.xephi.authme.util.PlayerUtils.isNpc;
import static org.bukkit.Bukkit.getLogger; import static org.bukkit.Bukkit.getLogger;
import static org.bukkit.Bukkit.getServer; import static org.bukkit.Bukkit.getServer;
@ -108,6 +110,9 @@ public class GuiCaptchaHandler implements Listener {
Player playerunreg = event.getPlayer(); Player playerunreg = event.getPlayer();
String name = playerunreg.getName(); String name = playerunreg.getName();
if (!authmeApi.isRegistered(name) && !isNpc(playerunreg)) { if (!authmeApi.isRegistered(name) && !isNpc(playerunreg)) {
String ip = getPlayerIp(playerunreg);
List<String> whiteList = settings.getProperty(SecuritySettings.GUI_CAPTCHA_COUNTRY_WHITELIST);
if (whiteList.isEmpty() || !whiteList.contains(authmeApi.getCountryCode(ip))) {
if (isBedrockPlayer(playerunreg.getUniqueId())) { if (isBedrockPlayer(playerunreg.getUniqueId())) {
closeReasonMap.put(playerunreg, "verified"); closeReasonMap.put(playerunreg, "verified");
messages.send(playerunreg, MessageKey.GUI_CAPTCHA_VERIFIED_AUTO_BEDROCK); messages.send(playerunreg, MessageKey.GUI_CAPTCHA_VERIFIED_AUTO_BEDROCK);
@ -213,6 +218,7 @@ public class GuiCaptchaHandler implements Listener {
}); });
} }
} }
}
private void deletePlayerData(UUID playerUUID) { private void deletePlayerData(UUID playerUUID) {
// 获取服务器的存储文件夹路径 // 获取服务器的存储文件夹路径

View File

@ -6,8 +6,10 @@ import ch.jalu.configme.properties.Property;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.EnumSetProperty; import fr.xephi.authme.settings.EnumSetProperty;
import java.util.List;
import java.util.Set; import java.util.Set;
import static ch.jalu.configme.properties.PropertyInitializer.newListProperty;
import static ch.jalu.configme.properties.PropertyInitializer.newLowercaseStringSetProperty; import static ch.jalu.configme.properties.PropertyInitializer.newLowercaseStringSetProperty;
import static ch.jalu.configme.properties.PropertyInitializer.newProperty; import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
@ -19,6 +21,11 @@ public final class SecuritySettings implements SettingsHolder {
public static final Property<Boolean> STOP_SERVER_ON_PROBLEM = public static final Property<Boolean> STOP_SERVER_ON_PROBLEM =
newProperty("Security.SQLProblem.stopServer", false); newProperty("Security.SQLProblem.stopServer", false);
@Comment({"Should send GUI captcha by country code whitelist?",
"If the country of the player is in this list, the captcha won't be sent."})
public static final Property<List<String>> GUI_CAPTCHA_COUNTRY_WHITELIST =
newListProperty("3rdPartyFeature.captcha.whitelist");
@Comment({"Should we let Bedrock players login automatically?", @Comment({"Should we let Bedrock players login automatically?",
"(Requires hookFloodgate to be true & floodgate loaded)"}) "(Requires hookFloodgate to be true & floodgate loaded)"})
public static final Property<Boolean> FORCE_LOGIN_BEDROCK = newProperty("3rdPartyFeature.features.bedrockAutoLogin", false); public static final Property<Boolean> FORCE_LOGIN_BEDROCK = newProperty("3rdPartyFeature.features.bedrockAutoLogin", false);