Launcher/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java

111 lines
3.3 KiB
Java
Raw Normal View History

package pro.gravit.launchserver.socket;
2018-09-17 10:07:32 +03:00
import pro.gravit.launcher.ClientPermissions;
import pro.gravit.launcher.profiles.ClientProfile;
2020-05-18 15:26:38 +03:00
import pro.gravit.launcher.request.secure.HardwareReportRequest;
import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.dao.User;
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
2018-09-27 00:18:26 +03:00
2020-08-27 17:25:14 +03:00
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
2018-09-17 10:07:32 +03:00
public class Client {
public UUID session;
public boolean useOAuth;
public String auth_id;
2018-09-17 10:07:32 +03:00
public long timestamp;
public AuthResponse.ConnectTypes type;
2018-09-27 00:18:26 +03:00
public ClientProfile profile;
public boolean isAuth;
public boolean checkSign;
2018-10-01 13:08:16 +03:00
public ClientPermissions permissions;
public String username;
2020-11-21 16:08:39 +03:00
public UUID uuid;
2020-03-20 04:44:24 +03:00
public TrustLevel trustLevel;
2018-09-22 17:33:00 +03:00
public transient AuthProviderPair auth;
2021-05-16 16:07:44 +03:00
@Deprecated
public transient User daoObject;
2021-05-16 16:07:44 +03:00
public transient pro.gravit.launchserver.auth.core.User coreObject;
public transient pro.gravit.launchserver.auth.core.UserSession sessionObject;
public transient Map<String, Object> properties;
public Map<String, String> serializableProperties;
public transient AtomicInteger refCount = new AtomicInteger(1);
public Client(UUID session) {
2018-09-17 10:07:32 +03:00
this.session = session;
timestamp = System.currentTimeMillis();
type = null;
2018-09-27 00:18:26 +03:00
isAuth = false;
2018-10-01 13:08:16 +03:00
permissions = ClientPermissions.DEFAULT;
username = "";
checkSign = false;
2018-09-17 10:07:32 +03:00
}
2018-11-08 15:30:16 +03:00
//Данные авторизации
2018-09-17 10:07:32 +03:00
public void up() {
timestamp = System.currentTimeMillis();
}
2019-04-03 16:27:40 +03:00
public void updateAuth(LaunchServer server) {
2019-04-03 16:27:40 +03:00
if (!isAuth) return;
if (auth_id.isEmpty()) auth = server.config.getAuthProviderPair();
else auth = server.config.getAuthProviderPair(auth_id);
}
2018-11-08 15:30:16 +03:00
2020-08-27 17:25:14 +03:00
@SuppressWarnings("unchecked")
2020-09-25 18:48:33 +03:00
public <T> T getProperty(String name) {
if (properties == null) properties = new HashMap<>();
2020-08-27 17:25:14 +03:00
return (T) properties.get(name);
}
2020-09-25 18:48:33 +03:00
public <T> void setProperty(String name, T object) {
if (properties == null) properties = new HashMap<>();
2020-08-27 17:25:14 +03:00
properties.put(name, object);
}
public String getSerializableProperty(String name) {
if (serializableProperties == null) serializableProperties = new HashMap<>();
return serializableProperties.get(name);
}
public void setSerializableProperty(String name, String value) {
if (serializableProperties == null) serializableProperties = new HashMap<>();
properties.put(name, value);
}
2021-03-20 11:53:22 +03:00
2021-05-16 16:07:44 +03:00
public pro.gravit.launchserver.auth.core.User getUser() {
2021-05-25 12:17:29 +03:00
if (coreObject != null) return coreObject;
if (auth != null && uuid != null && auth.isUseCore()) {
2021-05-16 16:07:44 +03:00
coreObject = auth.core.getUserByUUID(uuid);
}
return coreObject;
}
2021-03-20 11:53:22 +03:00
@Deprecated
public enum Type {
SERVER,
USER
}
public static class TrustLevel {
public byte[] verifySecureKey;
public boolean keyChecked;
public byte[] publicKey;
public HardwareReportRequest.HardwareInfo hardwareInfo;
// May be used later
public double rating;
public long latestMillis;
}
2018-09-17 10:07:32 +03:00
}