Update build files

This commit is contained in:
zontreck 2023-12-04 03:58:47 -07:00
parent bf74e122ce
commit ec0fd5285b
5 changed files with 137 additions and 30 deletions

6
.gitattributes vendored Executable file
View file

@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=lf

5
.gitignore vendored Normal file → Executable file
View file

@ -12,3 +12,8 @@ gradlew*
gradle-app.setting
.gradletasknamecache
gradle/wrapper/gradle-wrapper.properties
.vscode
# Ignore Gradle build output directory
build
bin

83
build.gradle Normal file → Executable file
View file

@ -1,38 +1,75 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.3/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id "com.github.johnrengelman.shadow" version "7.1.2"
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '4.0.4'
}
mainClassName = 'net.minecraft.launcher.Main'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
sourceCompatibility = '1.17'
targetCompatibility = '1.17'
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
jcenter()
maven {
name = "mojang"
url = "https://libraries.minecraft.net/"
}
gradlePluginPortal()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.3.1'
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0'
compile group: 'com.google.guava', name: 'guava', version: '18.0'
compile group: 'net.sf.jopt-simple', name: 'jopt-simple', version: '4.8'
implementation ("com.google.code.gson:gson:2.10.1")
//implementation ("com.google.code.findbugs:jsr305:3.0.2")
implementation ("com.google.guava:guava:31.1-jre")
implementation ("net.sf.jopt-simple:jopt-simple:5.0.4")
//implementation ("org.apache.commons:commons-lang3:3.12.0")
implementation ("org.apache.commons:commons-text:1.10.0")
implementation ("commons-io:commons-io:2.11.0")
implementation ("commons-codec:commons-codec:1.15")
implementation ("org.apache.logging.log4j:log4j-core:2.19.0")
implementation ("org.apache.logging.log4j:log4j-api:2.19.0")
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
//compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.5' // Not needed?
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5'
compile group: 'org.apache.maven.plugins', name: 'maven-shade-plugin', version: '3.1.0'
}
shadowJar {
exclude '**/Log4j2Plugins.dat'
//transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer) // Not needed?
application {
// Define the main class for the application.
mainClass = 'net.minecraft.launcher.Main'
}
configurations {
external.extendsFrom(implementation)
}
jar {
manifest {
attributes (
'Main-Class': application.mainClass,
'Multi-Release': 'true'
)
}
}
task jarjar(type: Jar) {
manifest {
attributes (
'Main-Class': application.mainClass,
'Multi-Release': 'true'
)
}
classifier = "AIO"
duplicatesStrategy = "exclude"
from { configurations.external.collect { it.isDirectory() ? it : zipTree(it) } }
exclude 'META-INF/*'
exclude 'META-INF/*'
exclude 'META-INF/*'
with jar
}

10
settings.gradle Normal file → Executable file
View file

@ -1,2 +1,10 @@
rootProject.name = 'mclaunch'
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/7.3/userguide/multi_project_builds.html
*/
rootProject.name = 'MinecraftLauncher'

View file

@ -14,11 +14,18 @@ import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import com.mojang.authlib.yggdrasil.request.AuthenticationRequest;
import com.mojang.authlib.yggdrasil.request.RefreshRequest;
import com.mojang.authlib.yggdrasil.request.ValidateRequest;
import com.mojang.authlib.yggdrasil.response.AccountRegistrationResponse;
import com.mojang.authlib.yggdrasil.response.AuthenticationResponse;
import com.mojang.authlib.yggdrasil.response.RefreshResponse;
import com.mojang.authlib.yggdrasil.response.Response;
import com.mojang.authlib.yggdrasil.response.User;
import net.minecraft.launcher.LauncherConstants;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
@ -26,16 +33,18 @@ import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.Message;
public class YggdrasilUserAuthentication
extends HttpUserAuthentication {
private static final Logger LOGGER = LogManager.getLogger();
private static final String BASE_URL = "https://authserver.mojang.com/";
private static final URL ROUTE_AUTHENTICATE = HttpAuthenticationService.constantURL("https://authserver.mojang.com/authenticate");
private static final URL ROUTE_REFRESH = HttpAuthenticationService.constantURL("https://authserver.mojang.com/refresh");
private static final URL ROUTE_VALIDATE = HttpAuthenticationService.constantURL("https://authserver.mojang.com/validate");
private static final URL ROUTE_INVALIDATE = HttpAuthenticationService.constantURL("https://authserver.mojang.com/invalidate");
private static final URL ROUTE_SIGNOUT = HttpAuthenticationService.constantURL("https://authserver.mojang.com/signout");
private static final String BASE_URL = LauncherConstants.URL_AUTHENTICATION;
private static final URL ROUTE_AUTHENTICATE = HttpAuthenticationService.constantURL(BASE_URL+"authenticate/");
private static final URL ROUTE_REFRESH = HttpAuthenticationService.constantURL(BASE_URL+"refresh/");
private static final URL ROUTE_VALIDATE = HttpAuthenticationService.constantURL(BASE_URL+"validate/");
private static final URL ROUTE_INVALIDATE = HttpAuthenticationService.constantURL(BASE_URL+"invalidate/");
private static final URL ROUTE_SIGNOUT = HttpAuthenticationService.constantURL(BASE_URL+"signout/");
private static final URL ROUTE_REGISTER = HttpAuthenticationService.constantURL(LauncherConstants.URL_REGISTER);
private static final String STORAGE_KEY_ACCESS_TOKEN = "accessToken";
private final Agent agent;
@ -67,6 +76,48 @@ extends HttpUserAuthentication {
}
}
@Override
public void doRegister(String username, String password) throws AuthenticationException{
if(StringUtils.isBlank(username)) throw new InvalidCredentialsException("Invalid username");
if(StringUtils.isNotBlank(password)){
// Register!
this.register(username, password);
}else throw new InvalidCredentialsException("Invalid password");
}
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
}
return new String(hexChars);
}
protected void register(String username,String password) throws AuthenticationException{
// No need to repeat the checks for values being blank
LOGGER.info("Registering username and password");
MessageDigest md5=null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
md5.update(password.getBytes());
String hash = bytesToHex(md5.digest()).toUpperCase();
AuthenticationRequest request = new AuthenticationRequest(this, username, hash);
AccountRegistrationResponse response = this.getAuthenticationService().makeRequest(ROUTE_REGISTER, request, AccountRegistrationResponse.class);
if(response.registered)
{
}
}
protected void logInWithPassword() throws AuthenticationException {
if (StringUtils.isBlank(this.getUsername())) {
throw new InvalidCredentialsException("Invalid username");