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 &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 - &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: &7&o This could happen because:
1. Mojang / Microsoft api is down\040\040\040\040\040\040\040\040\040 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 &6If this a mistake and you own a Minecraft account\040
&cPlease connect to &a&lreset.limework.net\040\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("&", "§"); &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) { if (username.length() >= 16) {
username = username.substring(0, 15); 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; return username;
} }

View File

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

View File

@ -5,5 +5,6 @@
"simple-anti-bot": { "simple-anti-bot": {
"max-connections": 590, "max-connections": 590,
"reset": 10 "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. # Warning: if you put more than 1 character it will use the first one and the rest is ignored.
default-cracked-char: "-" default-cracked-char: "-"
# its recommended being true -ham1255
# if the cracked player name is like this # if the cracked player name is like this
# Ham 1255 system will convert it to Ham_1255 # Ham 1255 system will convert it to Ham_1255
# Default: true # Default: true
@ -19,13 +19,14 @@ replace-spaces-with-underscore: true
# I don't recommend using this. -ham1255 # I don't recommend using this. -ham1255
# Example: # Example:
# true: when joining it checks the whole username if it has Cracked character or not! # 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 # [ Ham-1255 Ham1255- Ha-m1255 -Ham1255 ] will work
# in java syntax: .contains(DEFAULT_CRACKED_CHAR) # 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 use-the-contain-method: false
# Just simple anti bot # Just a simple anti bot
# example: # example:
# when a player joins a server it makes request to mojang api which has 600 per 10 minutes # 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! # 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 replaceSpacesWithUnderscore;
private final boolean useTheContainMethod; private final boolean useTheContainMethod;
private final AntiBot antiBot; private final AntiBot antiBot;
private final String resetDomain;
public ConfigLoader(File file) throws FileNotFoundException { public ConfigLoader(File file) throws FileNotFoundException {
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject(); 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(); this.useTheContainMethod = jsonObject.get("use-the-contain-method").getAsBoolean();
JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot"); JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot");
this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES); this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES);
this.resetDomain = jsonObject.get("reset-domain").getAsString();
} }
@Override @Override
@ -50,4 +52,9 @@ public class ConfigLoader implements Configuration {
public AntiBot getAntiBot() { public AntiBot getAntiBot() {
return this.antiBot; return this.antiBot;
} }
@Override
public String getResetDomain() {
return this.resetDomain;
}
} }

View File

@ -1,7 +1,8 @@
package net.limework.gal; package net.limework.gal;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.event.Continuation;
import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PreLoginEvent; 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.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.util.GameProfile; 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.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger; import java.util.logging.Logger;
import static net.limework.gal.utils.PlayerUUIDUtils.*; import static net.limework.gal.utils.PlayerUUIDUtils.*;
import static net.limework.gal.utils.PlayerNamesUtils.*; import static net.limework.gal.utils.PlayerNamesUtils.*;
@Plugin(name = "GreenAppleLogin", id = "greenapplelogin", version = "1.0.0", description = "Plugin that handle cracked + premium") @Plugin(name = "GreenAppleLogin", id = "greenapplelogin", version = "1.0.0", description = "Plugin that handle cracked + premium")
public class VelocityGalPlugin { public class VelocityGalPlugin {
@ -33,13 +38,27 @@ public class VelocityGalPlugin {
private final Logger logger; private final Logger logger;
private final File dataFolder; private final File dataFolder;
private final ConfigLoader config; private final ConfigLoader config;
private final Cache<String, Long> secondAttemptAsCrackedCache;
private final Cache<String, Object> offlineModePlayers;
private final Cache<String, Object> showFailedMessage;
@Inject @Inject
public VelocityGalPlugin(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataDirectory) { public VelocityGalPlugin(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataDirectory) {
this.proxyServer = proxyServer; this.proxyServer = proxyServer;
this.logger = logger; this.logger = logger;
this.dataFolder = dataDirectory.toFile(); 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()) { if (this.dataFolder.mkdir()) {
getLogger().info("Created Plugin data folder."); getLogger().info("Created Plugin data folder.");
} }
@ -58,25 +77,44 @@ public class VelocityGalPlugin {
} }
} }
@Subscribe @Subscribe
public void onProxyInitializeEvent(ProxyInitializeEvent event) { public void onProxyInitializeEvent(ProxyInitializeEvent event) {
//this.proxyServer.getEventManager().register(this, this); //this.proxyServer.getEventManager().register(this, this);
} }
@Subscribe(order = PostOrder.FIRST) @Subscribe(order = PostOrder.FIRST)
public void onPreLoginEvent(PreLoginEvent event) { 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()); event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
}else { } else if (offlineModePlayers.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) != null) {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode()); 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 @Subscribe
public void onGameProfileRequestEvent(GameProfileRequestEvent event) { public void onGameProfileRequestEvent(GameProfileRequestEvent event) {
secondAttemptAsCrackedCache.invalidate(event.getUsername() + event.getConnection().getRemoteAddress().getHostName());
if (!event.isOnlineMode()) { if (!event.isOnlineMode()) {
logger.info("handling " + event.getUsername()); logger.info("handling " + event.getUsername());
String username = getCorrectCrackedUsername(event.getUsername(), config); String username = getCorrectCrackedUsername(event.getUsername(), config);