change how cracked being handled

This commit is contained in:
2022-06-26 15:59:12 +04:00
parent c0fcc52053
commit 5d995022e7
6 changed files with 17 additions and 80 deletions

View File

@@ -16,7 +16,7 @@ public class ConfigLoader implements Configuration {
private final boolean replaceSpacesWithUnderscore;
private final boolean useTheContainMethod;
private final AntiBot antiBot;
private final String resetDomain;
private final String onlineModeDomain;
public ConfigLoader(File file) throws FileNotFoundException {
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
@@ -25,7 +25,7 @@ public class ConfigLoader implements Configuration {
this.useTheContainMethod = jsonObject.get("use-the-contain-method").getAsBoolean();
JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot");
this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES);
this.resetDomain = jsonObject.get("reset-domain").getAsString();
this.onlineModeDomain = jsonObject.get("online-mode-domain").getAsString();
}
@Override
@@ -54,7 +54,7 @@ public class ConfigLoader implements Configuration {
}
@Override
public String getResetDomain() {
return this.resetDomain;
public String getOnlineModeDomain() {
return this.onlineModeDomain;
}
}

View File

@@ -39,22 +39,12 @@ public class VelocityGalPlugin {
private final Logger logger;
private final File dataFolder;
private final ConfigLoader config;
private final Cache<String, Long> secondAttemptAsCrackedCache;
private final Cache<String, Object> offlineModePlayers;
@Inject
public VelocityGalPlugin(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataDirectory) {
this.proxyServer = proxyServer;
this.logger = logger;
this.dataFolder = dataDirectory.toFile();
this.offlineModePlayers = CacheBuilder.newBuilder()
.maximumSize(4000)
.expireAfterWrite(48, TimeUnit.HOURS)
.build();
this.secondAttemptAsCrackedCache = CacheBuilder.newBuilder()
.maximumSize(4000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
if (this.dataFolder.mkdir()) {
getLogger().info("Created Plugin data folder.");
}
@@ -82,30 +72,15 @@ public class VelocityGalPlugin {
@Subscribe(order = PostOrder.FIRST)
public void onPreLoginEvent(PreLoginEvent event) {
if (event.getConnection().getVirtualHost().get().getHostName().toLowerCase(Locale.ROOT).equals(config.getResetDomain())) {
secondAttemptAsCrackedCache.invalidate(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName());
offlineModePlayers.invalidate(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName());
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(Messages.RESET_MESSAGE)));
} else if (isCrackedPlayer(event.getUsername(), config)) {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
} else if (offlineModePlayers.getIfPresent(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName()) != null) {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
if (event.getConnection().getVirtualHost().get().getHostName().equalsIgnoreCase(this.config.getOnlineModeDomain())) {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
} else {
if (secondAttemptAsCrackedCache.getIfPresent(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName()) != null) {
if (offlineModePlayers.getIfPresent(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName()) == null) {
offlineModePlayers.put(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName(), new Object());
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
}
} else {
secondAttemptAsCrackedCache.put(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName(), System.currentTimeMillis());
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
}
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
}
}
@Subscribe
public void onGameProfileRequestEvent(GameProfileRequestEvent event) {
secondAttemptAsCrackedCache.invalidate(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName());
if (!event.isOnlineMode()) {
logger.info("handling " + event.getUsername());
String username = getCorrectCrackedUsername(event.getUsername(), config);
@@ -118,7 +93,7 @@ public class VelocityGalPlugin {
@Subscribe
public void onPostLoginEvent(PostLoginEvent event) {
if (offlineModePlayers.getIfPresent(getCorrectCrackedUsername(event.getPlayer().getUsername(), config) + event.getPlayer().getRemoteAddress().getHostName()) != null) {
if (isCrackedPlayer(event.getPlayer().getUsername(), this.config)) {
event.getPlayer().sendMessage(Component.text(Messages.cracked_disclaimer));
}
}