finish up player converter

This commit is contained in:
mohammed jasem alaajel 2021-12-14 23:03:58 +04:00
parent a5d0613c69
commit 562e8ff014
7 changed files with 81 additions and 18 deletions

View File

@ -11,17 +11,26 @@ public class Messages {
&2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040
&6- &a&lGovindas Limework&6 -
&c&oYour connection has failed to authenticate and cracked mode was enabled!
&c[&oIssue was detected in your last connection&c]
&c&ofailed to authenticate and offline mode (Cracked) was enabled for next 48 Hours!
&7&o This could happen because:
1. Mojang / Microsoft api is down\040\040\040\040\040\040\040\040\040
2. Using cracked minecraft (if you are using cracked Minecraft please relog!)
2. Disconnecting when connection to a server faster!
3. Using cracked minecraft (if you are using cracked Minecraft please reconnect!
&6If this a mistake and you own a Minecraft account\040
&cPlease connect to &a&lreset.limework.net\040\040
&7&oPro tip: use Direct connection
&2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m""".replace("&", "§");
public final static String RESET_MESSAGE = """
&2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m
&6- &a&lGovindas Limework&6 -
&aOffline mode has been disabled &l
&cNow try reconnecting to server now!
&2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m""".replace("&", "§");
}

View File

@ -21,6 +21,11 @@ public class PlayerNamesUtils {
if (username.length() >= 16) {
username = username.substring(0, 15);
}
if (configuration.useTheContainMethod() && !username.contains(configuration.getCrackedCharString())) {
username = configuration.getCrackedChar() + username;
} else if (username.charAt(0) != configuration.getCrackedChar()) {
username = configuration.getCrackedChar() + username;
}
return username;
}

View File

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

View File

@ -5,5 +5,6 @@
"simple-anti-bot": {
"max-connections": 590,
"reset": 10
}
},
"reset-domain": "reset.limework.net"
}

View File

@ -8,7 +8,7 @@
# 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
@ -19,13 +19,14 @@ replace-spaces-with-underscore: true
# 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 has - in middle or else like this:
# 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
# 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 simple anti bot
# 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!

View File

@ -16,6 +16,7 @@ public class ConfigLoader implements Configuration {
private final boolean replaceSpacesWithUnderscore;
private final boolean useTheContainMethod;
private final AntiBot antiBot;
private final String resetDomain;
public ConfigLoader(File file) throws FileNotFoundException {
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
@ -24,6 +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();
}
@Override
@ -50,4 +52,9 @@ public class ConfigLoader implements Configuration {
public AntiBot getAntiBot() {
return this.antiBot;
}
@Override
public String getResetDomain() {
return this.resetDomain;
}
}

View File

@ -1,7 +1,8 @@
package net.limework.gal;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Continuation;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PreLoginEvent;
@ -11,21 +12,25 @@ import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.util.GameProfile;
import net.limework.gal.utils.config.Configuration;
import net.kyori.adventure.text.Component;
import net.limework.gal.utils.Messages;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import static net.limework.gal.utils.PlayerUUIDUtils.*;
import static net.limework.gal.utils.PlayerNamesUtils.*;
@Plugin(name = "GreenAppleLogin", id = "greenapplelogin", version = "1.0.0", description = "Plugin that handle cracked + premium")
public class VelocityGalPlugin {
@ -33,13 +38,27 @@ 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;
private final Cache<String, Object> showFailedMessage;
@Inject
public VelocityGalPlugin(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataDirectory) {
this.proxyServer = proxyServer;
this.logger = logger;
this.dataFolder = dataDirectory.toFile();
this.showFailedMessage = CacheBuilder.newBuilder()
.maximumSize(4000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
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.");
}
@ -58,25 +77,44 @@ public class VelocityGalPlugin {
}
}
@Subscribe
public void onProxyInitializeEvent(ProxyInitializeEvent event) {
//this.proxyServer.getEventManager().register(this, this);
//this.proxyServer.getEventManager().register(this, this);
}
@Subscribe(order = PostOrder.FIRST)
public void onPreLoginEvent(PreLoginEvent event) {
if (isCrackedPlayer(event.getUsername(), config)){
if (event.getConnection().getVirtualHost().get().getHostName().toLowerCase(Locale.ROOT).equals(config.getResetDomain())) {
secondAttemptAsCrackedCache.invalidate(event.getUsername() + event.getConnection().getRemoteAddress().getHostName());
showFailedMessage.invalidate(event.getUsername() + event.getConnection().getRemoteAddress().getHostName());
offlineModePlayers.invalidate(event.getUsername() + 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 {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
} else if (offlineModePlayers.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) != null) {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
} else {
if (secondAttemptAsCrackedCache.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) != null) {
if (showFailedMessage.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) == null
&& offlineModePlayers.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) == null) {
showFailedMessage.put(event.getUsername() + event.getConnection().getRemoteAddress().getHostName(), new Object());
offlineModePlayers.put(event.getUsername() + event.getConnection().getRemoteAddress().getHostName(), new Object());
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(Messages.FAILED_CONNECTION)));
} else {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
}
} else {
secondAttemptAsCrackedCache.put(event.getUsername() + event.getConnection().getRemoteAddress().getHostName(), System.currentTimeMillis());
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
}
}
}
@Subscribe
public void onGameProfileRequestEvent(GameProfileRequestEvent event) {
secondAttemptAsCrackedCache.invalidate(event.getUsername() + event.getConnection().getRemoteAddress().getHostName());
if (!event.isOnlineMode()) {
logger.info("handling " + event.getUsername());
String username = getCorrectCrackedUsername(event.getUsername(), config);