Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Authentication implementation. #321

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bf45491
auth
sadcenter Nov 17, 2021
ffe3898
auth
sadcenter Nov 17, 2021
8e7d64f
auth skull
sadcenter Nov 18, 2021
a18ed72
Improvements, Ignore case in map, 1 save/tick, fixed code-style, code…
sadcenter Nov 18, 2021
a777e51
Improvements, Ignore case in map, 1 save/tick, fixed code-style, code…
sadcenter Nov 18, 2021
c352589
Improvements, UUID storage deletion, Add config support, Import optim…
sadcenter Nov 18, 2021
f37d76e
Code style fixes
sadcenter Nov 18, 2021
2632d90
Removes useless abstract types
sadcenter Nov 18, 2021
70946b2
Package name change
sadcenter Nov 18, 2021
8c528c7
Cache storage fix.
sadcenter Nov 19, 2021
312c0a7
final commit
sadcenter Jan 3, 2022
d4e2b9b
method rename
sadcenter Jan 3, 2022
6513ee1
useless async deletion
sadcenter Jan 3, 2022
a8e01fe
comments fix
sadcenter Jan 9, 2022
af1db4e
Optimize imports, name changes, exception logging & useless utils del…
sadcenter Jan 18, 2022
fbfe538
minor code style fixes, using mojang api if ashcon's api fails
sadcenter Jan 19, 2022
c0cb883
auth
sadcenter Nov 17, 2021
a35e135
auth
sadcenter Nov 17, 2021
453bbce
auth skull
sadcenter Nov 18, 2021
278ac2c
Improvements, Ignore case in map, 1 save/tick, fixed code-style, code…
sadcenter Nov 18, 2021
976e51b
Improvements, Ignore case in map, 1 save/tick, fixed code-style, code…
sadcenter Nov 18, 2021
61189ca
Improvements, UUID storage deletion, Add config support, Import optim…
sadcenter Nov 18, 2021
d78218f
Code style fixes
sadcenter Nov 18, 2021
adb8667
Removes useless abstract types
sadcenter Nov 18, 2021
acbd54c
Package name change
sadcenter Nov 18, 2021
8f6ef1a
Cache storage fix.
sadcenter Nov 19, 2021
729cd4e
final commit
sadcenter Jan 3, 2022
6eb2219
method rename
sadcenter Jan 3, 2022
bfe289f
useless async deletion
sadcenter Jan 3, 2022
94f022d
comments fix
sadcenter Jan 9, 2022
70e5743
Optimize imports, name changes, exception logging & useless utils del…
sadcenter Jan 18, 2022
b006697
minor code style fixes, using mojang api if ashcon's api fails
sadcenter Jan 19, 2022
ac984c2
conflict resolved, config features
sadcenter Jan 20, 2022
d426c3a
Merge remote-tracking branch 'origin/auth-v2' into auth-v2
sadcenter Jan 20, 2022
f837b67
Merge branch 'master' into auth-v2
sadcenter Feb 23, 2022
6b46a29
duh
sadcenter Feb 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class NachoAuthenticationService implements AuthenticationService {

private final LoadingCache<String, CompletableFuture<GameProfile>> gameProfileCache = CacheBuilder.newBuilder()
.expireAfterWrite(3, TimeUnit.HOURS)
.maximumSize(5000) //idk what's size is the best so you can give some advices
.maximumSize(5000)
.build(new CacheLoader<String, CompletableFuture<GameProfile>>() {
@Override
public CompletableFuture<GameProfile> load(String key) {
Expand Down Expand Up @@ -118,18 +118,13 @@ public GameProfile getPresentProfile(String name) {
profile.getNow(null);
}

public CompletableFuture<UUID> getUuid(String name) {
return this.getUuidFromApi(name, NachoConfig.alwaysUseMojang).exceptionallyCompose(throwable -> this.getUuidFromApi(name, !NachoConfig.alwaysUseMojang));
}

private CompletableFuture<GameProfile> getProfileFromApi(String name) {
return this.getProfileFromApi(name, NachoConfig.alwaysUseMojang)
.exceptionallyComposeAsync(throwable -> this.getProfileFromApi(name, !NachoConfig.alwaysUseMojang), EXECUTOR);
}

private CompletableFuture<UUID> getUuidFromApi(String name, boolean mojang) {
return mojang ? this.get(BACKUP_UUID_API + name, UUID.class) :
this.get(UUID_API + name, UUID.class);
CompletableFuture<GameProfile> profileFuture = this.getProfileFromApi(name, NachoConfig.texturesMojangPriority);
if (NachoConfig.backups) {
return profileFuture
.exceptionallyComposeAsync(throwable -> this.getProfileFromApi(name, !NachoConfig.texturesMojangPriority), EXECUTOR);
}
return profileFuture;
}

private CompletableFuture<GameProfile> getProfileFromApi(String name, boolean mojang) {
Expand All @@ -142,6 +137,20 @@ private CompletableFuture<GameProfile> getProfileFromApi(String name, boolean mo
}
}

public CompletableFuture<UUID> getUuidFromApi(String name) {
CompletableFuture<UUID> uuidFuture = this.getUuidFromApi(name, NachoConfig.uuidMojangPriority);
if (NachoConfig.backups) {
return uuidFuture
.exceptionallyCompose(throwable -> this.getUuidFromApi(name, !NachoConfig.uuidMojangPriority));
}
return uuidFuture;
}

private CompletableFuture<UUID> getUuidFromApi(String name, boolean mojang) {
return mojang ? this.get(BACKUP_UUID_API + name, UUID.class) :
this.get(UUID_API + name, UUID.class);
}

public <T> CompletableFuture<T> get(String url, Class<T> type) {
return CompletableFuture.supplyAsync(() -> {
String result = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void findProfilesByNames(String[] names, Agent agent, ProfileLookupCallba
}

GameProfile gameProfile = new GameProfile(null, name);
this.authenticator.getUuid(name)
this.authenticator.getUuidFromApi(name)
.thenApply(uuid -> new GameProfile(uuid, name))
.thenAccept(callback::onProfileLookupSucceeded)
.exceptionally(throwable -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ static void loadComments() {
c.addComment("settings.commands.permissions.version", "Enables a required permission to use /version");
c.addComment("settings.commands.permissions.plugins", "Enables a required permission to use /plugins");
c.addComment("settings.commands.enable-help-command", "Toggles the /help command");
c.addComment("settings.authenticator.use-nacho-authenticator", "Enables our own authentication system which uses Electroid's Mojang API.");
c.addComment("settings.authenticator.always-use-mojang", "Force to use mojang api no matter what");
c.addComment("settings.authenticator.use-nacho-authentication", "Enables our own authentication system.");
c.addComment("settings.authenticator.backups", "Should backup calls be enabled (recommended)");
c.addComment("settings.authenticator.uuid-priority", "What api should be used first in uuid fetching stage (ashcon, mojang)");
c.addComment("settings.authenticator.textures-priority", "What api should be used first in textures downloading stage (ashcon, mojang)");
NachoWorldConfig.loadComments();
}

Expand Down Expand Up @@ -384,7 +386,7 @@ private static void modeTcpFastOpen() {

private static void enableProtocolShim() {
if (config.contains("settings.enable-protocolib-shim")) getBoolean("settings.enable-protocol-shim", config.getBoolean("settings.enable-protocolib-shim")); else
enableProtocolShim = getBoolean("settings.enable-protocol-shim", true);
enableProtocolShim = getBoolean("settings.enable-protocol-shim", true);
}

public static boolean instantPlayInUseEntity;
Expand All @@ -394,14 +396,17 @@ private static void instantPlayInUseEntity() {
}

public static boolean useNachoAuthenticator;
public static boolean backups;
public static boolean uuidMojangPriority;
public static boolean texturesMojangPriority;

private static void useNachoAuthenticator() {
useNachoAuthenticator = getBoolean("settings.authenticator.use-nacho-authenticator", false);
private static void authentication() {
useNachoAuthenticator = getBoolean("settings.authenticator.use-nacho-authentication", false);
backups = getBoolean("settings.authenticator.backups", true);
uuidMojangPriority = getString("settings.authenticator.uuid-priority", "ashcon")
.equalsIgnoreCase("ashcon");
texturesMojangPriority = getString("settings.authenticator.textures-priority", "mojang")
Copy link

@ghost ghost Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use integers booleans to specify the api

.equalsIgnoreCase("ashcon");
}

public static boolean alwaysUseMojang;

private static void alwaysUseMojang() {
alwaysUseMojang = getBoolean("settings.authenticator.always-use-mojang", true);
}
}