44 lines
1.5 KiB
Java
44 lines
1.5 KiB
Java
package pro.gravit.launchserver.socket.response.auth;
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
import pro.gravit.launcher.base.events.request.SetProfileRequestEvent;
|
|
import pro.gravit.launcher.base.profiles.ClientProfile;
|
|
import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler;
|
|
import pro.gravit.launchserver.socket.Client;
|
|
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
|
import pro.gravit.utils.HookException;
|
|
|
|
import java.util.Collection;
|
|
|
|
public class SetProfileResponse extends SimpleResponse {
|
|
public String client;
|
|
|
|
@Override
|
|
public String getType() {
|
|
return "setProfile";
|
|
}
|
|
|
|
@Override
|
|
public void execute(ChannelHandlerContext ctx, Client client) {
|
|
try {
|
|
server.authHookManager.setProfileHook.hook(this, client);
|
|
} catch (HookException e) {
|
|
sendError(e.getMessage());
|
|
}
|
|
Collection<ClientProfile> profiles = server.getProfiles();
|
|
for (ClientProfile p : profiles) {
|
|
if (p.getTitle().equals(this.client)) {
|
|
if (server.config.protectHandler instanceof ProfilesProtectHandler profilesProtectHandler &&
|
|
!profilesProtectHandler.canChangeProfile(p, client)) {
|
|
sendError("Access denied");
|
|
return;
|
|
}
|
|
client.profile = p;
|
|
sendResult(new SetProfileRequestEvent(p));
|
|
return;
|
|
}
|
|
}
|
|
sendError("Profile not found");
|
|
}
|
|
}
|