Возможность изменять профиль после авторизации

This commit is contained in:
Gravit 2018-10-20 15:57:30 +07:00
parent 830786614f
commit 8d7db40909
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 71 additions and 5 deletions

View file

@ -5,16 +5,13 @@
import java.util.concurrent.ConcurrentHashMap;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launchserver.response.auth.AuthServerResponse;
import ru.gravit.launchserver.response.auth.*;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.launcher.request.RequestException;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.response.auth.AuthResponse;
import ru.gravit.launchserver.response.auth.CheckServerResponse;
import ru.gravit.launchserver.response.auth.JoinServerResponse;
import ru.gravit.launchserver.response.profile.BatchProfileByUsernameResponse;
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse;
@ -55,6 +52,7 @@ public static void registerResponses() {
registerResponse(RequestType.UPDATE.getNumber(), UpdateResponse::new);
registerResponse(RequestType.PROFILES.getNumber(), ProfilesResponse::new);
registerResponse(RequestType.SERVERAUTH.getNumber(), AuthServerResponse::new);
registerResponse(RequestType.SETPROFILE.getNumber(), SetProfileResponse::new);
}

View file

@ -0,0 +1,38 @@
package ru.gravit.launchserver.response.auth;
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.response.Response;
import ru.gravit.launchserver.socket.Client;
import java.util.Collection;
public class SetProfileResponse extends Response {
public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
super(server, session, input, output, ip);
}
@Override
public void reply() throws Exception {
String client = input.readString(SerializeLimits.MAX_CLIENT);
Client clientData = server.sessionManager.getClient(session);
if(!clientData.isAuth) requestError("You not auth");
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles();
for (SignedObjectHolder<ClientProfile> p : profiles) {
if (p.object.getTitle().equals(client)) {
if (!p.object.isWhitelistContains(clientData.username)) {
requestError(server.config.whitelistRejectString);
return;
}
clientData.profile = p.object;
output.writeBoolean(true);
break;
}
}
}
}

View file

@ -0,0 +1,30 @@
package ru.gravit.launcher.request.auth;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
public class SetProfileRequest extends Request<Boolean> {
private ClientProfile profile;
public SetProfileRequest(LauncherConfig config, ClientProfile profile) {
super(config);
this.profile = profile;
}
@Override
public Integer getType() {
return RequestType.SETPROFILE.getNumber();
}
@Override
protected Boolean requestDo(HInput input, HOutput output) throws Exception {
output.writeString(profile.getTitle(), SerializeLimits.MAX_CLIENT);
readError(input);
return input.readBoolean();
}
}

View file

@ -11,7 +11,7 @@ public enum RequestType implements EnumSerializer.Itf {
LAUNCHER(1), UPDATE(2), UPDATE_LIST(3), // Update requests
AUTH(4), JOIN_SERVER(5), CHECK_SERVER(6), // Auth requests
PROFILE_BY_USERNAME(7), PROFILE_BY_UUID(8), BATCH_PROFILE_BY_USERNAME(9), // Profile requests
PROFILES(10),SERVERAUTH(11),
PROFILES(10),SERVERAUTH(11), SETPROFILE(12),
CUSTOM(255); // Custom requests
private static final EnumSerializer<RequestType> SERIALIZER = new EnumSerializer<>(RequestType.class);