mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] textureProvider внесен в AuthProviderPair
This commit is contained in:
parent
421fa07317
commit
5f252682f3
12 changed files with 35 additions and 36 deletions
|
@ -113,8 +113,6 @@ public AuthProviderPair getAuthProviderPair()
|
|||
|
||||
public PermissionsHandler permissionsHandler;
|
||||
|
||||
public TextureProvider textureProvider;
|
||||
|
||||
public HWIDHandler hwidHandler;
|
||||
|
||||
// Misc options
|
||||
|
@ -202,9 +200,6 @@ public void verify() {
|
|||
{
|
||||
throw new IllegalStateException("No auth pairs declared by default.");
|
||||
}
|
||||
if (textureProvider == null) {
|
||||
throw new NullPointerException("TextureProvider must not be null");
|
||||
}
|
||||
if (permissionsHandler == null) {
|
||||
throw new NullPointerException("PermissionsHandler must not be null");
|
||||
}
|
||||
|
@ -223,11 +218,6 @@ public void close()
|
|||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
try {
|
||||
textureProvider.close();
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
try {
|
||||
hwidHandler.close();
|
||||
} catch (Exception e) {
|
||||
|
@ -494,9 +484,9 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
|||
reloadManager.registerReloadable("auth.".concat(pair.name).concat(".provider"), (Reloadable) pair.provider);
|
||||
if (pair.handler instanceof Reloadable)
|
||||
reloadManager.registerReloadable("auth.".concat(pair.name).concat(".handler"), (Reloadable) pair.handler);
|
||||
if (pair.textureProvider instanceof Reloadable)
|
||||
reloadManager.registerReloadable("auth.".concat(pair.name).concat(".texture"), (Reloadable) pair.textureProvider);
|
||||
}
|
||||
if (config.textureProvider instanceof Reloadable)
|
||||
reloadManager.registerReloadable("textureProvider", (Reloadable) config.textureProvider);
|
||||
|
||||
Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror);
|
||||
|
||||
|
@ -508,9 +498,9 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
|||
reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".provider"), (Reconfigurable) pair.provider);
|
||||
if (pair.handler instanceof Reconfigurable)
|
||||
reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".handler"), (Reconfigurable) pair.handler);
|
||||
if (pair.textureProvider instanceof Reconfigurable)
|
||||
reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".texture"), (Reconfigurable) pair.textureProvider);
|
||||
}
|
||||
if (config.textureProvider instanceof Reconfigurable)
|
||||
reconfigurableManager.registerReconfigurable("textureProvider", (Reconfigurable) config.textureProvider);
|
||||
|
||||
Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror);
|
||||
|
||||
|
@ -617,8 +607,10 @@ private void generateConfigIfNotExists() throws IOException {
|
|||
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
||||
newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh";
|
||||
newConfig.hwidHandler = new AcceptHWIDHandler();
|
||||
newConfig.auth = new AuthProviderPair[]{ new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), new MemoryAuthHandler(), "std") };
|
||||
newConfig.textureProvider = new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png");
|
||||
newConfig.auth = new AuthProviderPair[]{ new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"),
|
||||
new MemoryAuthHandler(),
|
||||
new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png")
|
||||
, "std") };
|
||||
newConfig.permissionsHandler = new JsonFilePermissionsHandler();
|
||||
newConfig.port = 7240;
|
||||
newConfig.bindAddress = "0.0.0.0";
|
||||
|
|
|
@ -2,18 +2,21 @@
|
|||
|
||||
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||||
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
||||
import ru.gravit.launchserver.texture.TextureProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AuthProviderPair {
|
||||
public AuthProvider provider;
|
||||
public AuthHandler handler;
|
||||
public TextureProvider textureProvider;
|
||||
public String name;
|
||||
public boolean isDefault = true;
|
||||
|
||||
public AuthProviderPair(AuthProvider provider, AuthHandler handler, String name) {
|
||||
public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, String name) {
|
||||
this.provider = provider;
|
||||
this.handler = handler;
|
||||
this.textureProvider = textureProvider;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
@ -26,5 +29,6 @@ public void init()
|
|||
public void close() throws IOException {
|
||||
provider.close();
|
||||
handler.close();
|
||||
textureProvider.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ public void reply() throws Exception {
|
|||
}
|
||||
writeNoError(output);
|
||||
// Write profile and UUID
|
||||
ProfileByUUIDResponse.getProfile(server, uuid, result.username, client).write(output);
|
||||
ProfileByUUIDResponse.getProfile(server, uuid, result.username, client, clientData.auth.textureProvider).write(output);
|
||||
output.writeASCII(result.accessToken, -SecurityHelper.TOKEN_STRING_LENGTH);
|
||||
clientData.permissions.write(output);
|
||||
}
|
||||
|
|
|
@ -48,6 +48,6 @@ public void reply() throws IOException {
|
|||
// Write profile and UUID
|
||||
output.writeBoolean(uuid != null);
|
||||
if (uuid != null)
|
||||
ProfileByUUIDResponse.getProfile(server, uuid, username, client).write(output);
|
||||
ProfileByUUIDResponse.getProfile(server, uuid, username, client, clientData.auth.textureProvider).write(output);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,6 @@ public void reply() throws IOException {
|
|||
|
||||
// Respond with profiles array
|
||||
for (int i = 0; i < usernames.length; i++)
|
||||
ProfileByUsernameResponse.writeProfile(server, output, usernames[i], clients[i], clientData.auth.handler);
|
||||
ProfileByUsernameResponse.writeProfile(server, output, usernames[i], clients[i], clientData.auth);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.response.Response;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.texture.TextureProvider;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,11 +16,11 @@
|
|||
|
||||
public final class ProfileByUUIDResponse extends Response {
|
||||
|
||||
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) {
|
||||
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client, TextureProvider textureProvider) {
|
||||
// Get skin texture
|
||||
Texture skin;
|
||||
try {
|
||||
skin = server.config.textureProvider.getSkinTexture(uuid, username, client);
|
||||
skin = textureProvider.getSkinTexture(uuid, username, client);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(new IOException(String.format("Can't get skin texture: '%s'", username), e));
|
||||
skin = null;
|
||||
|
@ -28,7 +29,7 @@ public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String us
|
|||
// Get cloak texture
|
||||
Texture cloak;
|
||||
try {
|
||||
cloak = server.config.textureProvider.getCloakTexture(uuid, username, client);
|
||||
cloak = textureProvider.getCloakTexture(uuid, username, client);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(new IOException(String.format("Can't get cloak texture: '%s'", username), e));
|
||||
cloak = null;
|
||||
|
@ -56,6 +57,6 @@ public void reply() throws IOException {
|
|||
|
||||
// Write profile
|
||||
output.writeBoolean(true);
|
||||
getProfile(server, uuid, username, client).write(output);
|
||||
getProfile(server, uuid, username, client, clientData.auth.textureProvider).write(output);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import ru.gravit.launcher.serialize.HOutput;
|
||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.auth.AuthProviderPair;
|
||||
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||||
import ru.gravit.launchserver.response.Response;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
|
@ -14,8 +15,8 @@
|
|||
|
||||
public final class ProfileByUsernameResponse extends Response {
|
||||
|
||||
public static void writeProfile(LaunchServer server, HOutput output, String username, String client, AuthHandler handler) throws IOException {
|
||||
UUID uuid = handler.usernameToUUID(username);
|
||||
public static void writeProfile(LaunchServer server, HOutput output, String username, String client, AuthProviderPair pair) throws IOException {
|
||||
UUID uuid = pair.handler.usernameToUUID(username);
|
||||
if (uuid == null) {
|
||||
output.writeBoolean(false);
|
||||
return;
|
||||
|
@ -23,7 +24,7 @@ public static void writeProfile(LaunchServer server, HOutput output, String user
|
|||
|
||||
// Write profile
|
||||
output.writeBoolean(true);
|
||||
ProfileByUUIDResponse.getProfile(server, uuid, username, client).write(output);
|
||||
ProfileByUUIDResponse.getProfile(server, uuid, username, client, pair.textureProvider).write(output);
|
||||
}
|
||||
|
||||
public ProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||
|
@ -36,6 +37,6 @@ public void reply() throws IOException {
|
|||
debug("Username: " + username);
|
||||
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
||||
// Write response
|
||||
writeProfile(server, output, username, client, clientData.auth.handler);
|
||||
writeProfile(server, output, username, client, clientData.auth);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
clientData.updateAuth();
|
||||
result.accessToken = aresult.accessToken;
|
||||
result.permissions = clientData.permissions;
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,aresult.username,client);
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,aresult.username,client, clientData.auth.textureProvider);
|
||||
service.sendObject(ctx, result);
|
||||
} catch (AuthException | HWIDException e) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent(e.getMessage()));
|
||||
|
|
|
@ -27,7 +27,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
try {
|
||||
result.uuid = pClient.auth.handler.checkServer(username, serverID);
|
||||
if(result.uuid != null)
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,result.uuid,username,client);
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,result.uuid,username,client, pClient.auth.textureProvider);
|
||||
} catch (AuthException e) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent(e.getMessage()));
|
||||
return;
|
||||
|
|
|
@ -29,7 +29,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
for(int i=0;i<list.length;++i)
|
||||
{
|
||||
UUID uuid = client.auth.handler.usernameToUUID(list[i].username);
|
||||
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,list[i].username,list[i].client);
|
||||
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,list[i].username,list[i].client, client.auth.textureProvider);
|
||||
}
|
||||
service.sendObject(ctx, result);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
import ru.gravit.launchserver.texture.TextureProvider;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -16,11 +17,11 @@
|
|||
public class ProfileByUUIDResponse implements JsonResponseInterface {
|
||||
public UUID uuid;
|
||||
public String client;
|
||||
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) {
|
||||
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client, TextureProvider textureProvider) {
|
||||
// Get skin texture
|
||||
Texture skin;
|
||||
try {
|
||||
skin = server.config.textureProvider.getSkinTexture(uuid, username, client);
|
||||
skin = textureProvider.getSkinTexture(uuid, username, client);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(new IOException(String.format("Can't get skin texture: '%s'", username), e));
|
||||
skin = null;
|
||||
|
@ -29,7 +30,7 @@ public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String us
|
|||
// Get cloak texture
|
||||
Texture cloak;
|
||||
try {
|
||||
cloak = server.config.textureProvider.getCloakTexture(uuid, username, client);
|
||||
cloak = textureProvider.getCloakTexture(uuid, username, client);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(new IOException(String.format("Can't get cloak texture: '%s'", username), e));
|
||||
cloak = null;
|
||||
|
@ -47,6 +48,6 @@ public String getType() {
|
|||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
String username = client.auth.handler.uuidToUsername(uuid);
|
||||
service.sendObject(ctx, new ProfileByUUIDRequestEvent(getProfile(LaunchServer.server,uuid,username,this.client)));
|
||||
service.sendObject(ctx, new ProfileByUUIDRequestEvent(getProfile(LaunchServer.server,uuid,username,this.client, client.auth.textureProvider)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,6 @@ public String getType() {
|
|||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
UUID uuid = client.auth.handler.usernameToUUID(username);
|
||||
service.sendObject(ctx, new ProfileByUsernameRequestEvent(getProfile(LaunchServer.server,uuid,username,this.client)));
|
||||
service.sendObject(ctx, new ProfileByUsernameRequestEvent(getProfile(LaunchServer.server,uuid,username,this.client, client.auth.textureProvider)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue