change how cracked being handled

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

View File

@ -34,14 +34,14 @@ public class Messages {
public final static String cracked_disclaimer = """
&c&l============================
&c&oYou have been found using Offline Minecraft (Cracked)
&7&o This could happen because:
1. Mojang / Microsoft servers are down
2. Reconnecting too quickly
3. Using cracked Minecraft
&6If this a mistake and you own a Minecraft account\s
&cPlease disconnect from the server and connect to
&6&lreset.limework.net""".replace("&", "§");
&cIf this a mistake and you own a Minecraft account\s
&ePlease disconnect from the server and connect to
&eIP: p.limework.net
&c&l============================
""".replace("&", "§");
}

View File

@ -11,7 +11,7 @@ public interface Configuration {
AntiBot getAntiBot();
String getResetDomain();
String getOnlineModeDomain();

View File

@ -6,5 +6,5 @@
"max-connections": 590,
"reset": 10
},
"reset-domain": "reset.limework.net"
"online-mode-domain": "p.limework.net"
}

View File

@ -1,38 +0,0 @@
# This message handles what type of char the system should use
# like if its - Cracked players will have it in the name
# example:
# Ham1255 is a cracked player want to join mc.limework.net
# when system checks if he is cracked then if the name does not contain -
# system will replace the name to -Ham1255
# Default: "-"
# Warning: if you put more than 1 character it will use the first one and the rest is ignored.
default-cracked-char: "-"
# its recommended being true -ham1255
# if the cracked player name is like this
# Ham 1255 system will convert it to Ham_1255
# Default: true
replace-spaces-with-underscore: true
# Notice:
# I don't recommend using this. -ham1255
# Example:
# true: when joining it checks the whole username if it has Cracked character or not!
# so Players who have - in middle or else like this:
# [ Ham-1255 Ham1255- Ha-m1255 -Ham1255 ] will work
# in java syntax: .contains(DEFAULT_CRACKED_CHAR)
# false: when joining it checks the first character if its equals default cracked char
# in java syntax .chatAt(0) == DEFAULT_CRACKED_CHAR
use-the-contain-method: false
# Just a simple anti bot
# example:
# when a player joins a server it makes request to mojang api which has 600 per 10 minutes
# if the server reach's the limits players can no longer join + possibility of getting banned by mojang api for a day!
# default:
# max: 590
# reset: 10
simple-anti-bot:
max-connections: 590
reset: 10

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());
} 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());
if (event.getConnection().getVirtualHost().get().getHostName().equalsIgnoreCase(this.config.getOnlineModeDomain())) {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
}
} else {
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));
}
}