[FEATURE] AuthProviderPair линковка

This commit is contained in:
Gravit 2020-01-19 13:50:48 +07:00
parent f81cdf6440
commit 9529017428
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -7,12 +7,15 @@
import pro.gravit.launchserver.auth.texture.TextureProvider; import pro.gravit.launchserver.auth.texture.TextureProvider;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class AuthProviderPair { public class AuthProviderPair {
public final AuthProvider provider; public AuthProvider provider;
public final AuthHandler handler; public AuthHandler handler;
public final TextureProvider textureProvider; public TextureProvider textureProvider;
public final HWIDHandler hwid; public HWIDHandler hwid;
public Map<String, String> links;
public final String name; public final String name;
public String displayName; public String displayName;
public final boolean isDefault = true; public final boolean isDefault = true;
@ -26,10 +29,45 @@ public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvi
} }
public void init(LaunchServer srv) { public void init(LaunchServer srv) {
if(links != null) link(srv);
if(provider == null) throw new NullPointerException(String.format("Auth %s provider null", name));
if(handler == null) throw new NullPointerException(String.format("Auth %s handler null", name));
if(textureProvider == null) throw new NullPointerException(String.format("Auth %s textureProvider null", name));
if(hwid == null) throw new NullPointerException(String.format("Auth %s hwid null", name));
provider.init(srv); provider.init(srv);
handler.init(srv); handler.init(srv);
hwid.init(); hwid.init();
} }
public void link(LaunchServer srv)
{
links.forEach((k,v) -> {
AuthProviderPair pair = srv.config.getAuthProviderPair(v);
if(pair == null)
{
throw new NullPointerException(String.format("Auth %s link failed. Pair %s not found", name, v));
}
if("provider".equals(k))
{
if(pair.provider == null) throw new NullPointerException(String.format("Auth %s link failed. %s.provider is null", name, v));
provider = pair.provider;
}
else if("handler".equals(k))
{
if(pair.handler == null) throw new NullPointerException(String.format("Auth %s link failed. %s.handler is null", name, v));
handler = pair.handler;
}
else if("textureProvider".equals(k))
{
if(pair.textureProvider == null) throw new NullPointerException(String.format("Auth %s link failed. %s.textureProvider is null", name, v));
textureProvider = pair.textureProvider;
}
else if("hwid".equals(k))
{
if(pair.hwid == null) throw new NullPointerException(String.format("Auth %s link failed. %s.hwid is null", name, v));
hwid = pair.hwid;
}
});
}
public void close() throws IOException { public void close() throws IOException {
provider.close(); provider.close();