mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FIX] Удаление хранения AuthProvider в []
This commit is contained in:
parent
dab4b21ae7
commit
f2c0815123
5 changed files with 25 additions and 29 deletions
|
@ -76,7 +76,7 @@ public interface LaunchServerConfigManager {
|
||||||
|
|
||||||
public void reload(ReloadType type) throws Exception {
|
public void reload(ReloadType type) throws Exception {
|
||||||
config.close(type);
|
config.close(type);
|
||||||
AuthProviderPair[] pairs = null;
|
Map<String, AuthProviderPair> pairs = null;
|
||||||
if (type.equals(ReloadType.NO_AUTH)) {
|
if (type.equals(ReloadType.NO_AUTH)) {
|
||||||
pairs = config.auth;
|
pairs = config.auth;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,19 +15,19 @@ public class AuthProviderPair {
|
||||||
public TextureProvider textureProvider;
|
public TextureProvider textureProvider;
|
||||||
public HWIDHandler hwid;
|
public HWIDHandler hwid;
|
||||||
public Map<String, String> links;
|
public Map<String, String> links;
|
||||||
public final String name;
|
public transient String name;
|
||||||
public String displayName;
|
public String displayName;
|
||||||
public final boolean isDefault = true;
|
public final boolean isDefault = true;
|
||||||
|
|
||||||
public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid, String name) {
|
public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.textureProvider = textureProvider;
|
this.textureProvider = textureProvider;
|
||||||
this.hwid = hwid;
|
this.hwid = hwid;
|
||||||
this.name = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(LaunchServer srv) {
|
public void init(LaunchServer srv, String name) {
|
||||||
|
this.name = name;
|
||||||
if(links != null) link(srv);
|
if(links != null) link(srv);
|
||||||
if(provider == null) throw new NullPointerException(String.format("Auth %s provider null", name));
|
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(handler == null) throw new NullPointerException(String.format("Auth %s handler null", name));
|
||||||
|
|
|
@ -39,7 +39,7 @@ public void invoke(String... args) {
|
||||||
commands += category.category.commandsMap().size();
|
commands += category.category.commandsMap().size();
|
||||||
}
|
}
|
||||||
LogHelper.info("Sessions: %d | Commands: %d(%d categories)", server.sessionManager.getSessions().size(), commands, server.commandHandler.getCategories().size() + 1);
|
LogHelper.info("Sessions: %d | Commands: %d(%d categories)", server.sessionManager.getSessions().size(), commands, server.commandHandler.getCategories().size() + 1);
|
||||||
for (AuthProviderPair pair : server.config.auth) {
|
for (AuthProviderPair pair : server.config.auth.values()) {
|
||||||
if (pair.handler instanceof CachedAuthHandler) {
|
if (pair.handler instanceof CachedAuthHandler) {
|
||||||
LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size());
|
LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,27 +47,21 @@ public LaunchServerConfig setLaunchServer(LaunchServer server) {
|
||||||
|
|
||||||
// Handlers & Providers
|
// Handlers & Providers
|
||||||
|
|
||||||
public AuthProviderPair[] auth;
|
public Map<String, AuthProviderPair> auth;
|
||||||
|
|
||||||
public DaoProvider dao;
|
public DaoProvider dao;
|
||||||
|
|
||||||
private transient AuthProviderPair authDefault;
|
private transient AuthProviderPair authDefault;
|
||||||
private transient Map<String, AuthProviderPair> authPairs = null;
|
|
||||||
|
|
||||||
public AuthProviderPair getAuthProviderPair(String name) {
|
public AuthProviderPair getAuthProviderPair(String name) {
|
||||||
if (authPairs == null) {
|
return auth.get(name);
|
||||||
Map<String, AuthProviderPair> pairs = new HashMap<>();
|
|
||||||
for (AuthProviderPair p : auth) pairs.put(p.name, p);
|
|
||||||
authPairs = pairs;
|
|
||||||
}
|
|
||||||
return authPairs.get(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtectHandler protectHandler;
|
public ProtectHandler protectHandler;
|
||||||
|
|
||||||
public AuthProviderPair getAuthProviderPair() {
|
public AuthProviderPair getAuthProviderPair() {
|
||||||
if (authDefault != null) return authDefault;
|
if (authDefault != null) return authDefault;
|
||||||
for (AuthProviderPair pair : auth) {
|
for (AuthProviderPair pair : auth.values()) {
|
||||||
if (pair.isDefault) {
|
if (pair.isDefault) {
|
||||||
authDefault = pair;
|
authDefault = pair;
|
||||||
return pair;
|
return pair;
|
||||||
|
@ -102,11 +96,12 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) {
|
||||||
|
|
||||||
|
|
||||||
public void verify() {
|
public void verify() {
|
||||||
if (auth == null || auth[0] == null) {
|
if (auth == null || auth.size() < 1) {
|
||||||
throw new NullPointerException("AuthHandler must not be null");
|
throw new NullPointerException("AuthProviderPair`s count should be at least one");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isOneDefault = false;
|
boolean isOneDefault = false;
|
||||||
for (AuthProviderPair pair : auth) {
|
for (AuthProviderPair pair : auth.values()) {
|
||||||
if (pair.isDefault) {
|
if (pair.isDefault) {
|
||||||
isOneDefault = true;
|
isOneDefault = true;
|
||||||
break;
|
break;
|
||||||
|
@ -128,9 +123,8 @@ public void verify() {
|
||||||
|
|
||||||
public void init(LaunchServer.ReloadType type) {
|
public void init(LaunchServer.ReloadType type) {
|
||||||
Launcher.applyLauncherEnv(env);
|
Launcher.applyLauncherEnv(env);
|
||||||
authPairs = null;
|
for (Map.Entry<String,AuthProviderPair> provider : auth.entrySet()) {
|
||||||
for (AuthProviderPair provider : auth) {
|
provider.getValue().init(server, provider.getKey());
|
||||||
provider.init(server);
|
|
||||||
}
|
}
|
||||||
if (dao != null)
|
if (dao != null)
|
||||||
dao.init(server);
|
dao.init(server);
|
||||||
|
@ -141,7 +135,7 @@ public void init(LaunchServer.ReloadType type) {
|
||||||
components.forEach((k, v) -> server.registerObject("component.".concat(k), v));
|
components.forEach((k, v) -> server.registerObject("component.".concat(k), v));
|
||||||
}
|
}
|
||||||
if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) {
|
if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) {
|
||||||
for (AuthProviderPair pair : auth) {
|
for (AuthProviderPair pair : auth.values()) {
|
||||||
server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
||||||
server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
||||||
server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
||||||
|
@ -154,7 +148,7 @@ public void init(LaunchServer.ReloadType type) {
|
||||||
public void close(LaunchServer.ReloadType type) {
|
public void close(LaunchServer.ReloadType type) {
|
||||||
try {
|
try {
|
||||||
if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) {
|
if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) {
|
||||||
for (AuthProviderPair pair : auth) {
|
for (AuthProviderPair pair : auth.values()) {
|
||||||
server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
||||||
server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
||||||
server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
||||||
|
@ -177,7 +171,7 @@ public void close(LaunchServer.ReloadType type) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
for (AuthProviderPair p : auth) p.close();
|
for (AuthProviderPair p : auth.values()) p.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
|
@ -282,11 +276,13 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
|
||||||
newConfig.launch4j.maxVersion = "1.8.999";
|
newConfig.launch4j.maxVersion = "1.8.999";
|
||||||
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
||||||
newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh";
|
newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh";
|
||||||
newConfig.auth = new AuthProviderPair[]{new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"),
|
newConfig.auth = new HashMap<>();
|
||||||
|
AuthProviderPair a = new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"),
|
||||||
new MemoryAuthHandler(),
|
new MemoryAuthHandler(),
|
||||||
new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png")
|
new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png")
|
||||||
, new AcceptHWIDHandler(), "std")};
|
, new AcceptHWIDHandler());
|
||||||
newConfig.auth[0].displayName = "Default";
|
a.displayName = "Default";
|
||||||
|
newConfig.auth.put("std", a);
|
||||||
newConfig.protectHandler = new StdProtectHandler();
|
newConfig.protectHandler = new StdProtectHandler();
|
||||||
if (env.equals(LaunchServer.LaunchServerEnv.TEST))
|
if (env.equals(LaunchServer.LaunchServerEnv.TEST))
|
||||||
newConfig.binaryName = "Launcher";
|
newConfig.binaryName = "Launcher";
|
||||||
|
|
|
@ -18,7 +18,7 @@ public String getType() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(ChannelHandlerContext ctx, Client client) {
|
public void execute(ChannelHandlerContext ctx, Client client) {
|
||||||
List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>();
|
List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>();
|
||||||
for (AuthProviderPair pair : server.config.auth) {
|
for (AuthProviderPair pair : server.config.auth.values()) {
|
||||||
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, pair.provider.getFirstAuthType(), pair.provider.getSecondAuthType()));
|
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, pair.provider.getFirstAuthType(), pair.provider.getSecondAuthType()));
|
||||||
}
|
}
|
||||||
sendResult(new GetAvailabilityAuthRequestEvent(list));
|
sendResult(new GetAvailabilityAuthRequestEvent(list));
|
||||||
|
|
Loading…
Reference in a new issue