mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FEATURE] Портированы запросы профилей
This commit is contained in:
parent
a6686029a5
commit
52609413a2
4 changed files with 144 additions and 0 deletions
|
@ -17,6 +17,10 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
if(!client.isAuth)
|
||||
{
|
||||
service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied"));
|
||||
}
|
||||
service.sendObject(ctx, new Result((List<ClientProfile>) LaunchServer.server.getProfiles()));
|
||||
}
|
||||
public class Result
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.profile;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BatchProfileByUsername implements JsonResponseInterface {
|
||||
class Entry
|
||||
{
|
||||
String username;
|
||||
String client;
|
||||
}
|
||||
Entry[] list;
|
||||
@Override
|
||||
public String getType() {
|
||||
return "batchProfileByUsername";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
Result result = new Result();
|
||||
result.playerProfiles = new PlayerProfile[list.length];
|
||||
for(int i=0;i<list.length;++i)
|
||||
{
|
||||
UUID uuid = LaunchServer.server.config.authHandler.usernameToUUID(list[i].username);
|
||||
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,list[i].username,list[i].client);
|
||||
}
|
||||
service.sendObject(ctx, result);
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
String requesttype = "batchProfileByUsername";
|
||||
String error;
|
||||
PlayerProfile[] playerProfiles;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.profile;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||
import ru.gravit.launcher.profiles.Texture;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
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.socket.websocket.json.auth.ProfilesResponse;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ProfileByUUIDResponse implements JsonResponseInterface {
|
||||
public UUID uuid;
|
||||
public String client;
|
||||
public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) {
|
||||
// Get skin texture
|
||||
Texture skin;
|
||||
try {
|
||||
skin = server.config.textureProvider.getSkinTexture(uuid, username, client);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(new IOException(String.format("Can't get skin texture: '%s'", username), e));
|
||||
skin = null;
|
||||
}
|
||||
|
||||
// Get cloak texture
|
||||
Texture cloak;
|
||||
try {
|
||||
cloak = server.config.textureProvider.getCloakTexture(uuid, username, client);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(new IOException(String.format("Can't get cloak texture: '%s'", username), e));
|
||||
cloak = null;
|
||||
}
|
||||
|
||||
// Return combined profile
|
||||
return new PlayerProfile(uuid, username, skin, cloak);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "profileByUUID";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
String username = LaunchServer.server.config.authHandler.uuidToUsername(uuid);
|
||||
service.sendObject(ctx, new Result(getProfile(LaunchServer.server,uuid,username,this.client)));
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
String requesttype = "profileByUUID";
|
||||
String error;
|
||||
PlayerProfile playerProfile;
|
||||
|
||||
public Result(PlayerProfile playerProfile) {
|
||||
this.playerProfile = playerProfile;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.profile;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static ru.gravit.launchserver.socket.websocket.json.profile.ProfileByUUIDResponse.getProfile;
|
||||
|
||||
public class ProfileByUsername implements JsonResponseInterface {
|
||||
String username;
|
||||
String client;
|
||||
@Override
|
||||
public String getType() {
|
||||
return "profileByUsername";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
UUID uuid = LaunchServer.server.config.authHandler.usernameToUUID(username);
|
||||
service.sendObject(ctx, new Result(getProfile(LaunchServer.server,uuid,username,this.client)));
|
||||
}
|
||||
public class Result
|
||||
{
|
||||
String requesttype = "profileByUsername";
|
||||
String error;
|
||||
PlayerProfile playerProfile;
|
||||
|
||||
public Result(PlayerProfile playerProfile) {
|
||||
this.playerProfile = playerProfile;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue