From 6e5257514e0a776b02282166c21614b9a5033842 Mon Sep 17 00:00:00 2001 From: samolego <34912839+samolego@users.noreply.github.com> Date: Tue, 26 Jan 2021 11:45:48 +0100 Subject: [PATCH] Both can start! --- common/build.gradle | 4 +++ .../simpleauth/mixin/MixinPlayerEntity.java | 3 +-- .../mixin/MixinServerLoginNetworkHandler.java | 27 +++---------------- .../src/main/resources/mixins.simpleauth.json | 3 +-- .../main/resources/simpleauth.accesswidener | 3 +++ fabric/build.gradle | 27 +++++++++++++++++-- .../simpleauth/SimpleAuthFabric.java | 6 ++--- .../src/main/resources/fabric.mod.json | 10 +++---- forge/build.gradle | 26 +++++++++++++++++- .../samo_lego/simpleauth/SimpleAuthForge.java | 5 +--- gradle.properties | 6 ++--- 11 files changed, 72 insertions(+), 48 deletions(-) create mode 100644 common/src/main/resources/simpleauth.accesswidener rename {common => fabric}/src/main/resources/fabric.mod.json (79%) diff --git a/common/build.gradle b/common/build.gradle index c24e194..e043178 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -4,6 +4,10 @@ repositories { } } +loom { + accessWidener("src/main/resources/simpleauth.accesswidener") +} + dependencies { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" mappings("net.fabricmc:yarn:${rootProject.yarn_mappings}:v2") diff --git a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java index 68f74ba..cb1d1a7 100644 --- a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java @@ -1,7 +1,6 @@ package org.samo_lego.simpleauth.mixin; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; import org.samo_lego.simpleauth.event.AuthEventHandler; import org.spongepowered.asm.mixin.Mixin; @@ -16,7 +15,7 @@ public class MixinPlayerEntity { // Player item dropping @Inject(method = "dropSelectedItem(Z)Z", at = @At("HEAD"), cancellable = true) private void dropSelectedItem(boolean dropEntireStack, CallbackInfoReturnable cir) { - ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; + PlayerEntity player = (PlayerEntity) (Object) this; ActionResult result = AuthEventHandler.onDropItem(player); if (result == ActionResult.FAIL) { diff --git a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java index e199e54..ede0dfb 100644 --- a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java @@ -27,31 +27,10 @@ public abstract class MixinServerLoginNetworkHandler { @Shadow private GameProfile profile; - @Shadow - private int loginTicks; @Shadow protected abstract GameProfile toOfflineProfile(GameProfile profile); - /** - * Fake state of current player. - */ - @Unique - private boolean acceptCrackedPlayer = false; - - /** - * Mimicks the ticking if autologin is enabled. - * @param ci - */ - @Inject(method = "tick()V", at = @At("HEAD"), cancellable = true) - private void preTick(CallbackInfo ci) { - if (this.acceptCrackedPlayer && config.main.premiumAutologin) { - ((ServerLoginNetworkHandler) (Object) this).acceptPlayer(); - - if (this.loginTicks++ == 600) - ((ServerLoginNetworkHandler) (Object) this).disconnect(new TranslatableText("multiplayer.disconnect.slow_login")); - ci.cancel(); - } - } + @Shadow private ServerLoginNetworkHandler.State state; @Inject(method = "acceptPlayer()V", at = @At("HEAD")) private void acceptPlayer(CallbackInfo ci) { @@ -84,7 +63,7 @@ public abstract class MixinServerLoginNetworkHandler { Matcher matcher = pattern.matcher(playername); if(playerCacheMap.containsKey(PlayerEntity.getOfflinePlayerUuid(playername).toString()) || !matcher.matches() || config.main.forcedOfflinePlayers.contains(playername)) { // Player definitely doesn't have a mojang account - this.acceptCrackedPlayer = true; + state = ServerLoginNetworkHandler.State.READY_TO_ACCEPT; this.profile = packet.getProfile(); ci.cancel(); @@ -109,7 +88,7 @@ public abstract class MixinServerLoginNetworkHandler { else if(response == HttpURLConnection.HTTP_NO_CONTENT) { // Player doesn't have a Mojang account httpsURLConnection.disconnect(); - this.acceptCrackedPlayer = true; + state = ServerLoginNetworkHandler.State.READY_TO_ACCEPT; this.profile = packet.getProfile(); ci.cancel(); diff --git a/common/src/main/resources/mixins.simpleauth.json b/common/src/main/resources/mixins.simpleauth.json index d62843d..d7e8f40 100644 --- a/common/src/main/resources/mixins.simpleauth.json +++ b/common/src/main/resources/mixins.simpleauth.json @@ -2,8 +2,7 @@ "required": true, "package": "org.samo_lego.simpleauth.mixin", "compatibilityLevel": "JAVA_8", - "mixins": [], - "server": [ + "mixins": [ "MixinPlayerAdvancementTracker", "MixinPlayerEntity", "MixinPlayerManager", diff --git a/common/src/main/resources/simpleauth.accesswidener b/common/src/main/resources/simpleauth.accesswidener new file mode 100644 index 0000000..3e8d38c --- /dev/null +++ b/common/src/main/resources/simpleauth.accesswidener @@ -0,0 +1,3 @@ +accessWidener v1 named + +accessible class net/minecraft/server/network/ServerLoginNetworkHandler$State diff --git a/fabric/build.gradle b/fabric/build.gradle index 46a45d7..c58aec5 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -25,8 +25,6 @@ dependencies { mappings("net.fabricmc:yarn:${rootProject.yarn_mappings}:v2") modImplementation("net.fabricmc:fabric-loader:${rootProject.loader_version}") modImplementation("net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}") - // Remove the next line if you don't want to depend on the API - modImplementation("me.shedaniel:architectury:${rootProject.architectury_version}:fabric") compileOnly(project(path: ":common")) { transitive = false @@ -44,6 +42,31 @@ dependencies { //modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}" // jitpack for quicker updating modImplementation "com.github.gnembon:fabric-carpet:${project.carpet_branch}-SNAPSHOT" + + // Password hashing + // Argon2 + implementation "de.mkammerer:argon2-jvm:${argon2_version}" + include "de.mkammerer:argon2-jvm:${argon2_version}" + + // BCrypt + implementation "at.favre.lib:bcrypt:${bcrypt_version}" + implementation "at.favre.lib:bytes:${bytes_version}" + include "at.favre.lib:bcrypt:${bcrypt_version}" + include "at.favre.lib:bytes:${bytes_version}" + + // Storage + // LevelDB database + implementation 'org.iq80.leveldb:leveldb:0.12' + implementation 'org.iq80.leveldb:leveldb-api:0.12' + include 'org.iq80.leveldb:leveldb:0.12' + include 'org.iq80.leveldb:leveldb-api:0.12' + + // MongoDB driver + implementation 'org.mongodb:mongodb-driver-sync:4.1.0' + include 'org.mongodb:mongodb-driver-sync:4.1.0' + + // JNA lib + include 'net.java.dev.jna:jna:5.5.0' } processResources { diff --git a/fabric/src/main/java/org/samo_lego/simpleauth/SimpleAuthFabric.java b/fabric/src/main/java/org/samo_lego/simpleauth/SimpleAuthFabric.java index 06c4fb9..e70fb87 100644 --- a/fabric/src/main/java/org/samo_lego/simpleauth/SimpleAuthFabric.java +++ b/fabric/src/main/java/org/samo_lego/simpleauth/SimpleAuthFabric.java @@ -1,6 +1,6 @@ package org.samo_lego.simpleauth; -import net.fabricmc.api.DedicatedServerModInitializer; +import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.player.*; @@ -9,10 +9,10 @@ import net.minecraft.server.MinecraftServer; import org.samo_lego.simpleauth.commands.*; import org.samo_lego.simpleauth.event.AuthEventHandler; -public class SimpleAuthFabric implements DedicatedServerModInitializer { +public class SimpleAuthFabric implements ModInitializer { @Override - public void onInitializeServer() { + public void onInitialize() { SimpleAuth.init(FabricLoader.getInstance().getGameDir()); //FabricLoader.getInstance().isModLoaded("carpet"); diff --git a/common/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json similarity index 79% rename from common/src/main/resources/fabric.mod.json rename to fabric/src/main/resources/fabric.mod.json index 9bb28ee..beed51e 100644 --- a/common/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -14,16 +14,12 @@ }, "license": "MIT", - "environment": "server", + "environment": "*", "entrypoints": { - "server": [ - "org.samo_lego.simpleauth.SimpleAuth" + "main": [ + "org.samo_lego.simpleauth.SimpleAuthFabric" ] }, - "mixins": [ - "mixins.simpleauth.json" - ], - "depends": { "fabricloader": ">=0.8.8", "fabric": "*" diff --git a/forge/build.gradle b/forge/build.gradle index c293707..cf590f8 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -21,7 +21,6 @@ dependencies { minecraft("com.mojang:minecraft:${rootProject.minecraft_version}") mappings("net.fabricmc:yarn:${rootProject.yarn_mappings}:v2") forge("net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}") - // Remove the next line if you don't want to depend on the API modCompile("me.shedaniel:architectury:${rootProject.architectury_version}:forge") compileOnly(project(path: ":common")) { @@ -33,6 +32,31 @@ dependencies { shadow(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } + + // Password hashing + // Argon2 + implementation "de.mkammerer:argon2-jvm:${argon2_version}" + include "de.mkammerer:argon2-jvm:${argon2_version}" + + // BCrypt + implementation "at.favre.lib:bcrypt:${bcrypt_version}" + implementation "at.favre.lib:bytes:${bytes_version}" + include "at.favre.lib:bcrypt:${bcrypt_version}" + include "at.favre.lib:bytes:${bytes_version}" + + // Storage + // LevelDB database + implementation 'org.iq80.leveldb:leveldb:0.12' + implementation 'org.iq80.leveldb:leveldb-api:0.12' + include 'org.iq80.leveldb:leveldb:0.12' + include 'org.iq80.leveldb:leveldb-api:0.12' + + // MongoDB driver + implementation 'org.mongodb:mongodb-driver-sync:4.1.0' + include 'org.mongodb:mongodb-driver-sync:4.1.0' + + // JNA lib + include 'net.java.dev.jna:jna:5.5.0' } shadowJar { diff --git a/forge/src/main/java/org/samo_lego/simpleauth/SimpleAuthForge.java b/forge/src/main/java/org/samo_lego/simpleauth/SimpleAuthForge.java index e215f75..c6922c8 100644 --- a/forge/src/main/java/org/samo_lego/simpleauth/SimpleAuthForge.java +++ b/forge/src/main/java/org/samo_lego/simpleauth/SimpleAuthForge.java @@ -19,7 +19,6 @@ public class SimpleAuthForge { SimpleAuth.init(FMLPaths.GAMEDIR.get()); } - // Registering the commands @SubscribeEvent public void registerCommands(RegisterCommandsEvent event) { CommandDispatcher dispatcher = event.getDispatcher(); @@ -31,9 +30,7 @@ public class SimpleAuthForge { AuthCommand.registerCommand(dispatcher); } - /** - * Called on server stop. - */ + @SubscribeEvent public void onStopServer(FMLServerStoppedEvent event) { SimpleAuth.stop(); diff --git a/gradle.properties b/gradle.properties index 57a3d20..764bd07 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G # Fabric properties minecraft_version=1.16.5 -yarn_mappings=1.16.5+build.1 +yarn_mappings=1.16.5+build.3 loader_version=0.11.1 #Fabric api -fabric_version=0.29.3+1.16 +fabric_version=0.29.4+1.16 # Forge -forge_version=36.0.1 +forge_version=36.0.4 # Mod Properties