Skip to content

Commit

Permalink
Add support for proxies running in offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Jul 3, 2018
1 parent f74f3cd commit 5e7fe5a
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Objects;

/**
* Extension of {@link LoginResult} which returns a modified Property array when
Expand Down Expand Up @@ -61,8 +62,28 @@ private Property[] getSpoofedProperties(Property[] properties) {
return newProperties;
}

@Override
public String getId() {
// assert non-null
return Objects.requireNonNull(super.getId());
}

@Override
public String getName() {
// assert non-null
return Objects.requireNonNull(super.getName());
}

static void inject(InitialHandler handler, String token) {
LoginResult profile = handler.getLoginProfile();

// profile is null for offline mode servers
// we should be safe to just init using null values, all (current) usages
// of LoginResult in InitialHandler only query the properties.
if (profile == null) {
profile = new LoginResult(null, null, new Property[0]);
}

LoginResult newProfile = new SpoofedLoginResult(profile.getId(), profile.getName(), profile.getProperties(), token);
try {
PROFILE_FIELD.set(handler, newProfile);
Expand Down

0 comments on commit 5e7fe5a

Please sign in to comment.