diff --git a/gal-api/src/main/java/net/limework/gal/utils/PlayerNamesUtils.java b/gal-api/src/main/java/net/limework/gal/utils/PlayerNamesUtils.java
new file mode 100644
index 0000000..ac9fdab
--- /dev/null
+++ b/gal-api/src/main/java/net/limework/gal/utils/PlayerNamesUtils.java
@@ -0,0 +1,28 @@
+package net.limework.gal.utils;
+
+import net.limework.gal.utils.config.Configuration;
+
+public class PlayerNamesUtils {
+
+
+ public static boolean isCrackedPlayer(String username, Configuration configuration) {
+ if (configuration.useTheContainMethod()) {
+ return username.contains(configuration.getCrackedCharString());
+ } else {
+ return username.charAt(0) == configuration.getCrackedChar();
+ }
+ }
+
+
+ public static String getCorrectCrackedUsername(String username, Configuration configuration) {
+ if (configuration.doReplaceSpacesWithUnderscore()) {
+ username = username.replace(" ", "_");
+ }
+ if (username.length() >= 16) {
+ username = username.substring(0, 15);
+ }
+ return username;
+ }
+
+
+}
diff --git a/gal-api/src/main/java/net/limework/gal/utils/PlayerUUIDUtils.java b/gal-api/src/main/java/net/limework/gal/utils/PlayerUUIDUtils.java
new file mode 100644
index 0000000..3ab947e
--- /dev/null
+++ b/gal-api/src/main/java/net/limework/gal/utils/PlayerUUIDUtils.java
@@ -0,0 +1,13 @@
+package net.limework.gal.utils;
+
+import java.nio.charset.StandardCharsets;
+import java.util.UUID;
+
+public class PlayerUUIDUtils {
+
+ // source -> https://www.spigotmc.org/threads/how-uuid-is-generated-for-offline-mode-nicknames.347835/
+ public static UUID getCrackedPlayerUUIDByName(String name) {
+ return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
+ }
+
+}
diff --git a/gal-api/src/main/java/net/limework/gal/utils/config/Configuration.java b/gal-api/src/main/java/net/limework/gal/utils/config/Configuration.java
index bbae70a..072dcd6 100644
--- a/gal-api/src/main/java/net/limework/gal/utils/config/Configuration.java
+++ b/gal-api/src/main/java/net/limework/gal/utils/config/Configuration.java
@@ -2,8 +2,12 @@ package net.limework.gal.utils.config;
public interface Configuration {
- String getCrackedChar();
+ char getCrackedChar();
+ String getCrackedCharString();
+ boolean doReplaceSpacesWithUnderscore();
+
+ boolean useTheContainMethod();
AntiBot getAntiBot();
diff --git a/gal-api/src/main/resources/config.json b/gal-api/src/main/resources/config.json
index 1e8a247..55accea 100644
--- a/gal-api/src/main/resources/config.json
+++ b/gal-api/src/main/resources/config.json
@@ -1,7 +1,9 @@
{
"default-cracked-char": "-",
+ "replace-spaces-with-underscore": true,
+ "use-the-contain-method": false,
"simple-anti-bot": {
- "max-connections" : 590,
- "reset" : 10
+ "max-connections": 590,
+ "reset": 10
}
}
\ No newline at end of file
diff --git a/gal-api/src/main/resources/config.yaml b/gal-api/src/main/resources/config.yaml
index 5cf0cb5..418cd63 100644
--- a/gal-api/src/main/resources/config.yaml
+++ b/gal-api/src/main/resources/config.yaml
@@ -4,13 +4,34 @@
# 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: "-"
+# 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 has - 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
+use-the-contain-method: false
+
# Just simple anti bot
# example:
-# when a player joins a server it makes request to mojang api which has 600 per 10 mins
+# 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
diff --git a/gal-velocity/pom.xml b/gal-velocity/pom.xml
index b209a10..4fe2b76 100644
--- a/gal-velocity/pom.xml
+++ b/gal-velocity/pom.xml
@@ -18,6 +18,27 @@
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.3
+
+ false
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
diff --git a/gal-velocity/src/main/java/net/limework/gal/ConfigLoader.java b/gal-velocity/src/main/java/net/limework/gal/ConfigLoader.java
index 301ad34..c2243ba 100644
--- a/gal-velocity/src/main/java/net/limework/gal/ConfigLoader.java
+++ b/gal-velocity/src/main/java/net/limework/gal/ConfigLoader.java
@@ -12,21 +12,40 @@ import java.util.concurrent.TimeUnit;
public class ConfigLoader implements Configuration {
- private final String crackedChar;
+ private final char crackedChar;
+ private final boolean replaceSpacesWithUnderscore;
+ private final boolean useTheContainMethod;
private final AntiBot antiBot;
public ConfigLoader(File file) throws FileNotFoundException {
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
- this.crackedChar = jsonObject.get("default-cracked-char").getAsString();
+ this.crackedChar = (jsonObject.get("default-cracked-char").getAsString().charAt(0));
+ this.replaceSpacesWithUnderscore = jsonObject.get("replace-spaces-with-underscore").getAsBoolean();
+ 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);
}
@Override
- public String getCrackedChar() {
+ public char getCrackedChar() {
return this.crackedChar;
}
+ @Override
+ public String getCrackedCharString() {
+ return String.valueOf(this.crackedChar);
+ }
+
+ @Override
+ public boolean doReplaceSpacesWithUnderscore() {
+ return this.replaceSpacesWithUnderscore;
+ }
+
+ @Override
+ public boolean useTheContainMethod() {
+ return this.useTheContainMethod;
+ }
+
@Override
public AntiBot getAntiBot() {
return this.antiBot;
diff --git a/gal-velocity/src/main/java/net/limework/gal/VelocityGalPlugin.java b/gal-velocity/src/main/java/net/limework/gal/VelocityGalPlugin.java
index b337f74..06d22ad 100644
--- a/gal-velocity/src/main/java/net/limework/gal/VelocityGalPlugin.java
+++ b/gal-velocity/src/main/java/net/limework/gal/VelocityGalPlugin.java
@@ -1,19 +1,31 @@
package net.limework.gal;
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;
+import com.velocitypowered.api.event.player.GameProfileRequestEvent;
+import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
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 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.Objects;
+import java.util.UUID;
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 {
@@ -49,6 +61,31 @@ public class VelocityGalPlugin {
}
+ @Subscribe
+ public void onProxyInitializeEvent(ProxyInitializeEvent event) {
+ //this.proxyServer.getEventManager().register(this, this);
+ }
+
+ @Subscribe(order = PostOrder.FIRST)
+ public void onPreLoginEvent(PreLoginEvent event) {
+ if (isCrackedPlayer(event.getUsername(), config)){
+ event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
+ }else {
+ event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
+ }
+ }
+
+ @Subscribe
+ public void onGameProfileRequestEvent(GameProfileRequestEvent event) {
+ if (!event.isOnlineMode()) {
+ logger.info("handling " + event.getUsername());
+ String username = getCorrectCrackedUsername(event.getUsername(), config);
+ logger.info("new username -> " + username);
+ List properties = event.getGameProfile().getProperties();
+ UUID uuid = getCrackedPlayerUUIDByName(username);
+ event.setGameProfile(new GameProfile(uuid, username, properties));
+ }
+ }
public ProxyServer getProxyServer() {