[FIX] Удаление хранения AuthProvider в []

This commit is contained in:
Zaxar163 2020-02-11 06:08:35 +01:00
parent dab4b21ae7
commit f2c0815123
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B
5 changed files with 25 additions and 29 deletions

View file

@ -76,7 +76,7 @@ public interface LaunchServerConfigManager {
public void reload(ReloadType type) throws Exception {
config.close(type);
AuthProviderPair[] pairs = null;
Map<String, AuthProviderPair> pairs = null;
if (type.equals(ReloadType.NO_AUTH)) {
pairs = config.auth;
}

View file

@ -15,19 +15,19 @@ public class AuthProviderPair {
public TextureProvider textureProvider;
public HWIDHandler hwid;
public Map<String, String> links;
public final String name;
public transient String name;
public String displayName;
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.handler = handler;
this.textureProvider = textureProvider;
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(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));

View file

@ -39,7 +39,7 @@ public void invoke(String... args) {
commands += category.category.commandsMap().size();
}
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) {
LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size());
}

View file

@ -47,27 +47,21 @@ public LaunchServerConfig setLaunchServer(LaunchServer server) {
// Handlers & Providers
public AuthProviderPair[] auth;
public Map<String, AuthProviderPair> auth;
public DaoProvider dao;
private transient AuthProviderPair authDefault;
private transient Map<String, AuthProviderPair> authPairs = null;
public AuthProviderPair getAuthProviderPair(String name) {
if (authPairs == null) {
Map<String, AuthProviderPair> pairs = new HashMap<>();
for (AuthProviderPair p : auth) pairs.put(p.name, p);
authPairs = pairs;
}
return authPairs.get(name);
return auth.get(name);
}
public ProtectHandler protectHandler;
public AuthProviderPair getAuthProviderPair() {
if (authDefault != null) return authDefault;
for (AuthProviderPair pair : auth) {
for (AuthProviderPair pair : auth.values()) {
if (pair.isDefault) {
authDefault = pair;
return pair;
@ -102,11 +96,12 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) {
public void verify() {
if (auth == null || auth[0] == null) {
throw new NullPointerException("AuthHandler must not be null");
if (auth == null || auth.size() < 1) {
throw new NullPointerException("AuthProviderPair`s count should be at least one");
}
boolean isOneDefault = false;
for (AuthProviderPair pair : auth) {
for (AuthProviderPair pair : auth.values()) {
if (pair.isDefault) {
isOneDefault = true;
break;
@ -128,9 +123,8 @@ public void verify() {
public void init(LaunchServer.ReloadType type) {
Launcher.applyLauncherEnv(env);
authPairs = null;
for (AuthProviderPair provider : auth) {
provider.init(server);
for (Map.Entry<String,AuthProviderPair> provider : auth.entrySet()) {
provider.getValue().init(server, provider.getKey());
}
if (dao != null)
dao.init(server);
@ -141,7 +135,7 @@ public void init(LaunchServer.ReloadType type) {
components.forEach((k, v) -> server.registerObject("component.".concat(k), v));
}
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(".handler"), pair.handler);
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) {
try {
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(".handler"), pair.handler);
server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
@ -177,7 +171,7 @@ public void close(LaunchServer.ReloadType type) {
LogHelper.error(e);
}
try {
for (AuthProviderPair p : auth) p.close();
for (AuthProviderPair p : auth.values()) p.close();
} catch (IOException e) {
LogHelper.error(e);
}
@ -282,11 +276,13 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
newConfig.launch4j.maxVersion = "1.8.999";
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
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 RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png")
, new AcceptHWIDHandler(), "std")};
newConfig.auth[0].displayName = "Default";
, new AcceptHWIDHandler());
a.displayName = "Default";
newConfig.auth.put("std", a);
newConfig.protectHandler = new StdProtectHandler();
if (env.equals(LaunchServer.LaunchServerEnv.TEST))
newConfig.binaryName = "Launcher";

View file

@ -18,7 +18,7 @@ public String getType() {
@Override
public void execute(ChannelHandlerContext ctx, Client client) {
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()));
}
sendResult(new GetAvailabilityAuthRequestEvent(list));