From 979a51e843ef6c205ad839317f99ac6a7ea76062 Mon Sep 17 00:00:00 2001 From: mohammed jasem alaajel <34905970+ham1255@users.noreply.github.com> Date: Mon, 14 Jun 2021 22:27:22 +0400 Subject: [PATCH] Added old commits from forked repo Fastlogin commits: \nAuto-add - character for offline mode users\nFix empty database getting users marked as cracked falsely\nDon't save offline mode user to database\nalways use false to fix an error\nsome debug stuff...\nadd GovindasPreSecondAttemptEvent\nshade sqlite so we can stop using mariadb for fastlogin diff --git a/bungee/pom.xml b/bungee/pom.xml index 2e6f977..9f9c28a 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -170,5 +170,11 @@ true provided + + org.xerial + sqlite-jdbc + 3.34.0 + compile + diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java index 8a81b14..db8f269 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java @@ -42,6 +42,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; import java.util.UUID; import net.md_5.bungee.api.connection.PendingConnection; @@ -167,6 +168,52 @@ public class ConnectListener implements Listener { } } } + // LimeLogin start + //start of Govindas code to auto-add "-" character for offline mode users differentiation from online mode + else { + if (!connection.getName().contains("-")) { + InitialHandler initialHandler = (InitialHandler) loginEvent.getConnection(); + //TODO add bedrock check of player and don't trigger this for bedrock users + LoginSession session = plugin.getSession().get(connection); + String username = connection.getName(); + + //for bedrock support, this opens up vulnerability, so cracked players with * can join without auth + //but that isn't a problem as we're handling * in LimeworkProxy instead + //but it would be better to handle it here, just need to debug it further + + //debug, we can remove after + UUID checkUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + connection.getName()).getBytes(StandardCharsets.UTF_8)); + System.out.println("Profile uuid: " + session.getProfile().getId()); + System.out.println("Session uuid: " + session.getUuid()); + System.out.println("Offline uuid: " + checkUUID); + if (username.contains("*")) { + + if (checkUUID.equals(session.getProfile().getId())) { + System.out.println("IT EQUALS!"); + } + return; + } + if (username.length() >= 16) { + username = username.substring(0, 15); + } + + session.setVerifiedUsername("-" + username); + initialHandler.getLoginRequest().setData("-" + username); + UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + connection.getName()).getBytes(StandardCharsets.UTF_8)); + plugin.getLog().info("Govindas system has converted username to contain - character: " + username); + try { + uniqueIdSetter.invokeExact(initialHandler, uuid); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + session.getProfile().setPremium(false); + session.getProfile().setPlayerName(connection.getName()); + session.setUuid(uuid); + session.getProfile().setId(uuid); + } + } + //end of Govindas code + // LimeLogin end } private void setOfflineId(InitialHandler connection, String username) { diff --git a/bungee/src/main/resources/bungee.yml b/bungee/src/main/resources/bungee.yml index c52f41a..1d1c8d9 100644 --- a/bungee/src/main/resources/bungee.yml +++ b/bungee/src/main/resources/bungee.yml @@ -3,10 +3,10 @@ # This make it easy to combine BungeeCord and Bukkit support in one plugin name: ${project.parent.name} # ${-} will be automatically replaced by Maven -main: ${project.groupId}.${project.artifactId}.${project.name} +main: com.github.games647.fastlogin.bungee.FastLoginBungee -version: ${project.version}-${git.commit.id.abbrev} -author: games647, https://github.com/games647/FastLogin/graphs/contributors +version: ${project.version} +author: games647, https://github.com/games647/FastLogin/graphs/contributors, Limework.net softDepends: # BungeeCord auth plugins diff --git a/core/pom.xml b/core/pom.xml index ccdc63a..3491ef0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -81,7 +81,7 @@ net.md-5 bungeecord-config - 1.12-SNAPSHOT + 1.16-R0.5-SNAPSHOT * @@ -90,6 +90,13 @@ + + net.md-5 + bungeecord-proxy + 1.16-R0.5-SNAPSHOT + provided + + org.geysermc.floodgate diff --git a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java index 94500cb..b304559 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java @@ -142,9 +142,8 @@ public class AuthStorage { + "`Name` VARCHAR(16) NOT NULL, " + "`Premium` BOOLEAN NOT NULL, " + "`LastIp` VARCHAR(255) NOT NULL, " - + "`LastLogin` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " + + "`LastLogin` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAM" //the premium shouldn't steal the cracked account by changing the name - + "UNIQUE (`Name`) " + ')'; if (dataSource.getJdbcUrl().contains("sqlite")) { @@ -208,7 +207,13 @@ public class AuthStorage { public void save(StoredProfile playerProfile) { try (Connection con = dataSource.getConnection()) { String uuid = playerProfile.getOptId().map(UUIDAdapter::toMojangId).orElse(null); + // LimeLogin start + //start of Govindas code + if (!playerProfile.getName().contains("-")) { playerProfile.setPremium(true); } + //end of Govindas code + + // LimeLogin end playerProfile.getSaveLock().lock(); try { if (playerProfile.isSaved()) { @@ -222,6 +227,13 @@ public class AuthStorage { saveStmt.execute(); } } else { + // LimeLogin start + + //start of Govindas code + if (!playerProfile.getName().contains("-")) { playerProfile.setPremium(true); } + //end of Govindas code + + // LimeLogin end try (PreparedStatement saveStmt = con.prepareStatement(INSERT_PROFILE, RETURN_GENERATED_KEYS)) { saveStmt.setString(1, uuid); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/ForceLoginManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/ForceLoginManagement.java index 7efb157..b417e64 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/ForceLoginManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/ForceLoginManagement.java @@ -92,7 +92,13 @@ public abstract class ForceLoginManagement

{ } } else { if (core.getPendingLogin().remove(ip + username) != null && config.get("secondAttemptCracked", false)) { - core.getPlugin().getLog().info("Second attempt login -> cracked {}", username); - - //first login request failed so make a cracked session - startCrackedSession(source, profile, username); - return; + // LimeLogin start + GovindasPreSecondAttemptEvent event = new GovindasPreSecondAttemptEvent(ip, username); + ProxyServer.getInstance().getPluginManager().callEvent(event); + if (!event.isCancelled()) { + core.getPlugin().getLog().info("Second attempt login -> cracked {}", username); + //first login request failed so make a cracked session + startCrackedSession(source, profile, username); + return; + } + // LimeLogin start } Optional premiumUUID = Optional.empty(); @@ -116,8 +123,17 @@ public abstract class JoinManagement

{ private boolean checkPremiumName(S source, String username, StoredProfile profile) throws Exception { core.getPlugin().getLog().info("GameProfile {} uses a premium username", username); - if (core.getConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) { - requestPremiumLogin(source, profile, username, false); + // LimeLogin start + + //start of Govindas comment, THIS IS NEEDED to be commented if FastLogin database gets emptied, to not get premium users counted as cracked + //if (core.getConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) { + //end of Govindas comment + + // LimeLogin end + if (core.getConfig().get("autoRegister", false) && (authHook == null)) { + // LimeLogin start + requestPremiumLogin(source, profile, username, false); //Comment: always use false to fix an error XD + // LimeLogin end return true; } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/event/GovindasPreSecondAttemptEvent.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/event/GovindasPreSecondAttemptEvent.java new file mode 100644 index 0000000..007083e --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/event/GovindasPreSecondAttemptEvent.java @@ -0,0 +1,36 @@ +// LimeLogin start +package com.github.games647.fastlogin.core.shared.event; + +import net.md_5.bungee.api.plugin.Cancellable; +import net.md_5.bungee.api.plugin.Event; + +public class GovindasPreSecondAttemptEvent extends Event implements Cancellable { + + private final String ip; + private final String username; + private boolean cancelled; + + public GovindasPreSecondAttemptEvent(String ip, String username) { + this.ip = ip; + this.username = username; + } + public String getIP() { + return ip; + } + + + public String getUsername() { + return username; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } +} +// LimeLogin end \ No newline at end of file diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index ecb1c44..477c026 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -235,7 +235,7 @@ autoRegisterFloodgate: false # Recommended is the use of MariaDB (a better version of MySQL) # Single file SQLite database -driver: 'org.sqlite.JDBC' +driver: 'fastlogin.sqlite.JDBC' # File location database: '{pluginDir}/FastLogin.db' -- 2.32.0.windows.1