mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-01 22:14:01 +03:00
Merge cf7c524a9d
into 36d97e7f8b
This commit is contained in:
commit
c503d43cde
80 changed files with 710 additions and 737 deletions
|
@ -3,6 +3,7 @@
|
|||
import com.google.gson.JsonElement;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launchserver.helper.HttpHelper;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
@ -17,25 +18,6 @@ public class HttpRequester {
|
|||
public HttpRequester() {
|
||||
}
|
||||
|
||||
public static class SimpleErrorHandler<T> implements HttpHelper.HttpJsonErrorHandler<T, SimpleError> {
|
||||
private final Type type;
|
||||
|
||||
private SimpleErrorHandler(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHelper.HttpOptional<T, SimpleError> applyJson(JsonElement response, int statusCode) {
|
||||
if(statusCode < 200 || statusCode >= 300) {
|
||||
return new HttpHelper.HttpOptional<>(null, Launcher.gsonManager.gson.fromJson(response, SimpleError.class), statusCode);
|
||||
}
|
||||
if(type == Void.class) {
|
||||
return new HttpHelper.HttpOptional<>(null, null, statusCode);
|
||||
}
|
||||
return new HttpHelper.HttpOptional<>(Launcher.gsonManager.gson.fromJson(response, type), null, statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> SimpleErrorHandler<T> makeEH(Class<T> clazz) {
|
||||
return new SimpleErrorHandler<>(clazz);
|
||||
}
|
||||
|
@ -47,8 +29,9 @@ public <T> HttpRequest get(String url, String token) {
|
|||
.uri(new URI(url))
|
||||
.header("Content-Type", "application/json; charset=UTF-8")
|
||||
.header("Accept", "application/json")
|
||||
.header("User-Agent", IOHelper.USER_AGENT)
|
||||
.timeout(Duration.ofMillis(10000));
|
||||
if(token != null) {
|
||||
if (token != null) {
|
||||
requestBuilder.header("Authorization", "Bearer ".concat(token));
|
||||
}
|
||||
return requestBuilder.build();
|
||||
|
@ -64,8 +47,9 @@ public <T> HttpRequest post(String url, T request, String token) {
|
|||
.uri(new URI(url))
|
||||
.header("Content-Type", "application/json; charset=UTF-8")
|
||||
.header("Accept", "application/json")
|
||||
.header("User-Agent", IOHelper.USER_AGENT)
|
||||
.timeout(Duration.ofMillis(10000));
|
||||
if(token != null) {
|
||||
if (token != null) {
|
||||
requestBuilder.header("Authorization", "Bearer ".concat(token));
|
||||
}
|
||||
return requestBuilder.build();
|
||||
|
@ -78,6 +62,25 @@ public <T> HttpHelper.HttpOptional<T, SimpleError> send(HttpRequest request, Cla
|
|||
return HttpHelper.send(httpClient, request, makeEH(clazz));
|
||||
}
|
||||
|
||||
public static class SimpleErrorHandler<T> implements HttpHelper.HttpJsonErrorHandler<T, SimpleError> {
|
||||
private final Type type;
|
||||
|
||||
private SimpleErrorHandler(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHelper.HttpOptional<T, SimpleError> applyJson(JsonElement response, int statusCode) {
|
||||
if (statusCode < 200 || statusCode >= 300) {
|
||||
return new HttpHelper.HttpOptional<>(null, Launcher.gsonManager.gson.fromJson(response, SimpleError.class), statusCode);
|
||||
}
|
||||
if (type == Void.class) {
|
||||
return new HttpHelper.HttpOptional<>(null, null, statusCode);
|
||||
}
|
||||
return new HttpHelper.HttpOptional<>(Launcher.gsonManager.gson.fromJson(response, type), null, statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleError {
|
||||
public String error;
|
||||
public int code;
|
||||
|
|
|
@ -67,7 +67,7 @@ private static void visit(ClassNode classNode, Map<String, Object> values) {
|
|||
List<MethodNode> constructors = classNode.methods.stream().filter(method -> "<init>".equals(method.name))
|
||||
.collect(Collectors.toList());
|
||||
MethodNode initMethod = constructors.stream().filter(method -> method.invisibleAnnotations != null
|
||||
&& method.invisibleAnnotations.stream().anyMatch(annotation -> INJECTED_CONSTRUCTOR_DESC.equals(annotation.desc))).findFirst()
|
||||
&& method.invisibleAnnotations.stream().anyMatch(annotation -> INJECTED_CONSTRUCTOR_DESC.equals(annotation.desc))).findFirst()
|
||||
.orElseGet(() -> constructors.stream().filter(method -> method.desc.equals("()V")).findFirst().orElse(null));
|
||||
classNode.fields.forEach(field -> {
|
||||
// Notice that fields that will be used with this algo should not have default
|
||||
|
|
|
@ -38,15 +38,6 @@ public static Set<String> getFeatures(Class<?> clazz) {
|
|||
return list;
|
||||
}
|
||||
|
||||
public void internalShowOAuthWarnMessage() {
|
||||
if(!warnOAuthShow) {
|
||||
if(!(core instanceof MySQLCoreProvider) && !(core instanceof PostgresSQLCoreProvider)) { // MySQL and PostgreSQL upgraded later
|
||||
logger.warn("AuthCoreProvider {} ({}) not supported OAuth. Legacy session system may be removed in next release", name, core.getClass().getName());
|
||||
}
|
||||
warnOAuthShow = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void getFeatures(Class<?> clazz, Set<String> list) {
|
||||
Features features = clazz.getAnnotation(Features.class);
|
||||
if (features != null) {
|
||||
|
@ -64,6 +55,15 @@ public static void getFeatures(Class<?> clazz, Set<String> list) {
|
|||
}
|
||||
}
|
||||
|
||||
public void internalShowOAuthWarnMessage() {
|
||||
if (!warnOAuthShow) {
|
||||
if (!(core instanceof MySQLCoreProvider) && !(core instanceof PostgresSQLCoreProvider)) { // MySQL and PostgreSQL upgraded later
|
||||
logger.warn("AuthCoreProvider {} ({}) not supported OAuth. Legacy session system may be removed in next release", name, core.getClass().getName());
|
||||
}
|
||||
warnOAuthShow = true;
|
||||
}
|
||||
}
|
||||
|
||||
public final <T> T isSupport(Class<T> clazz) {
|
||||
if (core == null) return null;
|
||||
T result = null;
|
||||
|
|
|
@ -91,7 +91,7 @@ public Map<String, Command> getCommands() {
|
|||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
AuthRequest.AuthPasswordInterface password = null;
|
||||
if(args.length > 1) {
|
||||
if (args.length > 1) {
|
||||
if (args[1].startsWith("{")) {
|
||||
password = Launcher.gsonManager.gson.fromJson(args[1], AuthRequest.AuthPasswordInterface.class);
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
public class HttpAuthCoreProvider extends AuthCoreProvider implements AuthSupportHardware {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
private transient HttpRequester requester;
|
||||
public String bearerToken;
|
||||
public String getUserByUsernameUrl;
|
||||
public String getUserByLoginUrl;
|
||||
|
@ -49,6 +48,7 @@ public class HttpAuthCoreProvider extends AuthCoreProvider implements AuthSuppor
|
|||
public String getUsersByHardwareInfoUrl;
|
||||
public String banHardwareUrl;
|
||||
public String unbanHardwareUrl;
|
||||
private transient HttpRequester requester;
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
|
@ -62,7 +62,7 @@ public User getUserByUsername(String username) {
|
|||
|
||||
@Override
|
||||
public User getUserByLogin(String login) {
|
||||
if(getUserByLoginUrl != null) {
|
||||
if (getUserByLoginUrl != null) {
|
||||
try {
|
||||
return requester.send(requester.get(CommonHelper.replace(getUserByLoginUrl, "login", login), null), HttpUser.class).getOrThrow();
|
||||
} catch (IOException e) {
|
||||
|
@ -85,7 +85,7 @@ public User getUserByUUID(UUID uuid) {
|
|||
|
||||
@Override
|
||||
public List<GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> getDetails(Client client) {
|
||||
if(getAuthDetailsUrl == null) {
|
||||
if (getAuthDetailsUrl == null) {
|
||||
return super.getDetails(client);
|
||||
}
|
||||
try {
|
||||
|
@ -99,14 +99,14 @@ public List<GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> getDetails(
|
|||
|
||||
@Override
|
||||
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired {
|
||||
if(getUserByTokenUrl == null) {
|
||||
if (getUserByTokenUrl == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
var result = requester.send(requester.get(getUserByTokenUrl, accessToken), HttpUserSession.class);
|
||||
if(!result.isSuccessful()) {
|
||||
if (!result.isSuccessful()) {
|
||||
var error = result.error().error;
|
||||
if(error.equals(AuthRequestEvent.OAUTH_TOKEN_EXPIRE)) {
|
||||
if (error.equals(AuthRequestEvent.OAUTH_TOKEN_EXPIRE)) {
|
||||
throw new OAuthAccessTokenExpired();
|
||||
}
|
||||
return null;
|
||||
|
@ -120,7 +120,7 @@ public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws O
|
|||
|
||||
@Override
|
||||
public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context) {
|
||||
if(refreshTokenUrl == null) {
|
||||
if (refreshTokenUrl == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
@ -136,9 +136,9 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon
|
|||
public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException {
|
||||
var result = requester.send(requester.post(authorizeUrl, new AuthorizeRequest(login, context, password, minecraftAccess),
|
||||
bearerToken), HttpAuthReport.class);
|
||||
if(!result.isSuccessful()) {
|
||||
if (!result.isSuccessful()) {
|
||||
var error = result.error().error;
|
||||
if(error != null) {
|
||||
if (error != null) {
|
||||
throw new AuthException(error);
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c
|
|||
|
||||
@Override
|
||||
public UserHardware getHardwareInfoByPublicKey(byte[] publicKey) {
|
||||
if(getHardwareInfoByPublicKeyUrl == null) {
|
||||
if (getHardwareInfoByPublicKeyUrl == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
@ -161,7 +161,7 @@ public UserHardware getHardwareInfoByPublicKey(byte[] publicKey) {
|
|||
|
||||
@Override
|
||||
public UserHardware getHardwareInfoByData(HardwareReportRequest.HardwareInfo info) {
|
||||
if(getHardwareInfoByDataUrl == null) {
|
||||
if (getHardwareInfoByDataUrl == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
@ -179,7 +179,7 @@ public UserHardware getHardwareInfoByData(HardwareReportRequest.HardwareInfo inf
|
|||
|
||||
@Override
|
||||
public UserHardware getHardwareInfoById(String id) {
|
||||
if(getHardwareInfoByIdUrl == null) {
|
||||
if (getHardwareInfoByIdUrl == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
@ -193,7 +193,7 @@ public UserHardware getHardwareInfoById(String id) {
|
|||
|
||||
@Override
|
||||
public UserHardware createHardwareInfo(HardwareReportRequest.HardwareInfo info, byte[] publicKey) {
|
||||
if(createHardwareInfoUrl == null) {
|
||||
if (createHardwareInfoUrl == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
@ -207,7 +207,7 @@ public UserHardware createHardwareInfo(HardwareReportRequest.HardwareInfo info,
|
|||
|
||||
@Override
|
||||
public void connectUserAndHardware(UserSession userSession, UserHardware hardware) {
|
||||
if(connectUserAndHardwareUrl == null) {
|
||||
if (connectUserAndHardwareUrl == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -219,11 +219,11 @@ public void connectUserAndHardware(UserSession userSession, UserHardware hardwar
|
|||
|
||||
@Override
|
||||
public void addPublicKeyToHardwareInfo(UserHardware hardware, byte[] publicKey) {
|
||||
if(addPublicKeyToHardwareInfoUrl == null) {
|
||||
if (addPublicKeyToHardwareInfoUrl == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
requester.send(requester.post(addPublicKeyToHardwareInfoUrl, new HardwareRequest((HttpUserHardware)hardware, publicKey), bearerToken), Void.class);
|
||||
requester.send(requester.post(addPublicKeyToHardwareInfoUrl, new HardwareRequest((HttpUserHardware) hardware, publicKey), bearerToken), Void.class);
|
||||
} catch (IOException e) {
|
||||
logger.error(e);
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ public void addPublicKeyToHardwareInfo(UserHardware hardware, byte[] publicKey)
|
|||
|
||||
@Override
|
||||
public Iterable<User> getUsersByHardwareInfo(UserHardware hardware) {
|
||||
if(getUsersByHardwareInfoUrl == null) {
|
||||
if (getUsersByHardwareInfoUrl == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
@ -245,7 +245,7 @@ public Iterable<User> getUsersByHardwareInfo(UserHardware hardware) {
|
|||
|
||||
@Override
|
||||
public void banHardware(UserHardware hardware) {
|
||||
if(banHardwareUrl == null) {
|
||||
if (banHardwareUrl == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -257,7 +257,7 @@ public void banHardware(UserHardware hardware) {
|
|||
|
||||
@Override
|
||||
public void unbanHardware(UserHardware hardware) {
|
||||
if(unbanHardwareUrl == null) {
|
||||
if (unbanHardwareUrl == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -267,14 +267,6 @@ public void unbanHardware(UserHardware hardware) {
|
|||
}
|
||||
}
|
||||
|
||||
public record HttpAuthReport(String minecraftAccessToken, String oauthAccessToken,
|
||||
String oauthRefreshToken, long oauthExpire,
|
||||
HttpUserSession session) {
|
||||
public AuthManager.AuthReport toAuthReport() {
|
||||
return new AuthManager.AuthReport(minecraftAccessToken, oauthAccessToken, oauthRefreshToken, oauthExpire, session);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateServerID(User user, String serverID) throws IOException {
|
||||
var result = requester.send(requester.post(updateServerIdUrl, new UpdateServerIdRequest(user.getUsername(), user.getUUID(), serverID),
|
||||
|
@ -293,6 +285,36 @@ public boolean joinServer(Client client, String username, String accessToken, St
|
|||
return result.isSuccessful();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer server) {
|
||||
requester = new HttpRequester();
|
||||
if (getUserByUsernameUrl == null) {
|
||||
throw new IllegalArgumentException("'getUserByUsernameUrl' can't be null");
|
||||
}
|
||||
if (getUserByUUIDUrl == null) {
|
||||
throw new IllegalArgumentException("'getUserByUUIDUrl' can't be null");
|
||||
}
|
||||
if (authorizeUrl == null) {
|
||||
throw new IllegalArgumentException("'authorizeUrl' can't be null");
|
||||
}
|
||||
if (checkServerUrl == null && joinServerUrl == null && updateServerIdUrl == null) {
|
||||
throw new IllegalArgumentException("Please set 'checkServerUrl' and 'joinServerUrl' or 'updateServerIdUrl'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
public record HttpAuthReport(String minecraftAccessToken, String oauthAccessToken,
|
||||
String oauthRefreshToken, long oauthExpire,
|
||||
HttpUserSession session) {
|
||||
public AuthManager.AuthReport toAuthReport() {
|
||||
return new AuthManager.AuthReport(minecraftAccessToken, oauthAccessToken, oauthRefreshToken, oauthExpire, session);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UpdateServerIdRequest {
|
||||
public String username;
|
||||
public UUID uuid;
|
||||
|
@ -331,28 +353,6 @@ public JoinServerRequest(String username, String accessToken, String serverId) {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer server) {
|
||||
requester = new HttpRequester();
|
||||
if(getUserByUsernameUrl == null) {
|
||||
throw new IllegalArgumentException("'getUserByUsernameUrl' can't be null");
|
||||
}
|
||||
if(getUserByUUIDUrl == null) {
|
||||
throw new IllegalArgumentException("'getUserByUUIDUrl' can't be null");
|
||||
}
|
||||
if(authorizeUrl == null) {
|
||||
throw new IllegalArgumentException("'authorizeUrl' can't be null");
|
||||
}
|
||||
if(checkServerUrl == null && joinServerUrl == null && updateServerIdUrl == null) {
|
||||
throw new IllegalArgumentException("Please set 'checkServerUrl' and 'joinServerUrl' or 'updateServerIdUrl'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
public static class AuthorizeRequest {
|
||||
public String login;
|
||||
public AuthResponse.AuthContext context;
|
||||
|
@ -400,153 +400,6 @@ public HardwareRequest(byte[] key) {
|
|||
|
||||
}
|
||||
|
||||
public class HttpUser implements User, UserSupportTextures, UserSupportProperties, UserSupportHardware {
|
||||
private String username;
|
||||
private UUID uuid;
|
||||
private String serverId;
|
||||
private String accessToken;
|
||||
private ClientPermissions permissions;
|
||||
@Deprecated
|
||||
private Texture skin;
|
||||
@Deprecated
|
||||
private Texture cloak;
|
||||
private Map<String, Texture> assets;
|
||||
private Map<String, String> properties;
|
||||
private long hwidId;
|
||||
private transient HttpUserHardware hardware;
|
||||
|
||||
public HttpUser() {
|
||||
}
|
||||
|
||||
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, long hwidId) {
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.serverId = serverId;
|
||||
this.accessToken = accessToken;
|
||||
this.permissions = permissions;
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, Texture skin, Texture cloak, long hwidId) {
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.serverId = serverId;
|
||||
this.accessToken = accessToken;
|
||||
this.permissions = permissions;
|
||||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, Texture skin, Texture cloak, Map<String, String> properties, long hwidId) {
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.serverId = serverId;
|
||||
this.accessToken = accessToken;
|
||||
this.permissions = permissions;
|
||||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
this.properties = properties;
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, Map<String, Texture> assets, Map<String, String> properties, long hwidId) {
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.serverId = serverId;
|
||||
this.accessToken = accessToken;
|
||||
this.permissions = permissions;
|
||||
this.assets = assets;
|
||||
this.properties = properties;
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Texture getSkinTexture() {
|
||||
if(assets == null) {
|
||||
return skin;
|
||||
}
|
||||
return assets.get("SKIN");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Texture getCloakTexture() {
|
||||
if(assets == null) {
|
||||
return cloak;
|
||||
}
|
||||
return assets.get("CAPE");
|
||||
}
|
||||
|
||||
public Map<String, Texture> getAssets() {
|
||||
if(assets == null) {
|
||||
Map<String, Texture> map = new HashMap<>();
|
||||
if(skin != null) {
|
||||
map.put("SKIN", skin);
|
||||
}
|
||||
if(cloak != null) {
|
||||
map.put("CAPE", cloak);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
return assets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getProperties() {
|
||||
if(properties == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HttpUser{" +
|
||||
"username='" + username + '\'' +
|
||||
", uuid=" + uuid +
|
||||
", serverId='" + serverId + '\'' +
|
||||
", accessToken='" + accessToken + '\'' +
|
||||
", permissions=" + permissions +
|
||||
", assets=" + getAssets() +
|
||||
", properties=" + properties +
|
||||
", hwidId=" + hwidId +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserHardware getHardware() {
|
||||
if (hardware != null) return hardware;
|
||||
HttpAuthCoreProvider.HttpUserHardware result = (HttpUserHardware) getHardwareInfoById(String.valueOf(hwidId));
|
||||
hardware = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HttpUserSession implements UserSession {
|
||||
private String id;
|
||||
private HttpUser user;
|
||||
|
@ -646,4 +499,151 @@ public String toString() {
|
|||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public class HttpUser implements User, UserSupportTextures, UserSupportProperties, UserSupportHardware {
|
||||
private String username;
|
||||
private UUID uuid;
|
||||
private String serverId;
|
||||
private String accessToken;
|
||||
private ClientPermissions permissions;
|
||||
@Deprecated
|
||||
private Texture skin;
|
||||
@Deprecated
|
||||
private Texture cloak;
|
||||
private Map<String, Texture> assets;
|
||||
private Map<String, String> properties;
|
||||
private long hwidId;
|
||||
private transient HttpUserHardware hardware;
|
||||
|
||||
public HttpUser() {
|
||||
}
|
||||
|
||||
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, long hwidId) {
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.serverId = serverId;
|
||||
this.accessToken = accessToken;
|
||||
this.permissions = permissions;
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, Texture skin, Texture cloak, long hwidId) {
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.serverId = serverId;
|
||||
this.accessToken = accessToken;
|
||||
this.permissions = permissions;
|
||||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, Texture skin, Texture cloak, Map<String, String> properties, long hwidId) {
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.serverId = serverId;
|
||||
this.accessToken = accessToken;
|
||||
this.permissions = permissions;
|
||||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
this.properties = properties;
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, Map<String, Texture> assets, Map<String, String> properties, long hwidId) {
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.serverId = serverId;
|
||||
this.accessToken = accessToken;
|
||||
this.permissions = permissions;
|
||||
this.assets = assets;
|
||||
this.properties = properties;
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Texture getSkinTexture() {
|
||||
if (assets == null) {
|
||||
return skin;
|
||||
}
|
||||
return assets.get("SKIN");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Texture getCloakTexture() {
|
||||
if (assets == null) {
|
||||
return cloak;
|
||||
}
|
||||
return assets.get("CAPE");
|
||||
}
|
||||
|
||||
public Map<String, Texture> getAssets() {
|
||||
if (assets == null) {
|
||||
Map<String, Texture> map = new HashMap<>();
|
||||
if (skin != null) {
|
||||
map.put("SKIN", skin);
|
||||
}
|
||||
if (cloak != null) {
|
||||
map.put("CAPE", cloak);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
return assets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getProperties() {
|
||||
if (properties == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HttpUser{" +
|
||||
"username='" + username + '\'' +
|
||||
", uuid=" + uuid +
|
||||
", serverId='" + serverId + '\'' +
|
||||
", accessToken='" + accessToken + '\'' +
|
||||
", permissions=" + permissions +
|
||||
", assets=" + getAssets() +
|
||||
", properties=" + properties +
|
||||
", hwidId=" + hwidId +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserHardware getHardware() {
|
||||
if (hardware != null) return hardware;
|
||||
HttpAuthCoreProvider.HttpUserHardware result = (HttpUserHardware) getHardwareInfoById(String.valueOf(hwidId));
|
||||
hardware = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,15 +13,19 @@
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MemoryAuthCoreProvider extends AuthCoreProvider {
|
||||
private transient final List<MemoryUser> memory = new ArrayList<>(16);
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
synchronized (memory) {
|
||||
for(MemoryUser u : memory) {
|
||||
if(u.username.equals(username)) {
|
||||
for (MemoryUser u : memory) {
|
||||
if (u.username.equals(username)) {
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +43,8 @@ public List<GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> getDetails(
|
|||
@Override
|
||||
public User getUserByUUID(UUID uuid) {
|
||||
synchronized (memory) {
|
||||
for(MemoryUser u : memory) {
|
||||
if(u.uuid.equals(uuid)) {
|
||||
for (MemoryUser u : memory) {
|
||||
if (u.uuid.equals(uuid)) {
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +55,8 @@ public User getUserByUUID(UUID uuid) {
|
|||
@Override
|
||||
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired {
|
||||
synchronized (memory) {
|
||||
for(MemoryUser u : memory) {
|
||||
if(u.accessToken.equals(accessToken)) {
|
||||
for (MemoryUser u : memory) {
|
||||
if (u.accessToken.equals(accessToken)) {
|
||||
return new MemoryUserSession(u);
|
||||
}
|
||||
}
|
||||
|
@ -67,23 +71,23 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon
|
|||
|
||||
@Override
|
||||
public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException {
|
||||
if(login == null) {
|
||||
if (login == null) {
|
||||
throw AuthException.userNotFound();
|
||||
}
|
||||
MemoryUser user = null;
|
||||
synchronized (memory) {
|
||||
for(MemoryUser u : memory) {
|
||||
if(u.username.equals(login)) {
|
||||
for (MemoryUser u : memory) {
|
||||
if (u.username.equals(login)) {
|
||||
user = u;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(user == null) {
|
||||
if (user == null) {
|
||||
user = new MemoryUser(login);
|
||||
memory.add(user);
|
||||
}
|
||||
}
|
||||
if(!minecraftAccess) {
|
||||
if (!minecraftAccess) {
|
||||
return AuthManager.AuthReport.ofOAuth(user.accessToken, null, 0, new MemoryUserSession(user));
|
||||
} else {
|
||||
return AuthManager.AuthReport.ofOAuthWithMinecraft(user.accessToken, user.accessToken, null, 0, new MemoryUserSession(user));
|
||||
|
@ -100,8 +104,8 @@ protected boolean updateServerID(User user, String serverID) throws IOException
|
|||
@Override
|
||||
public User checkServer(Client client, String username, String serverID) throws IOException {
|
||||
synchronized (memory) {
|
||||
for(MemoryUser u : memory) {
|
||||
if(u.username.equals(username)) {
|
||||
for (MemoryUser u : memory) {
|
||||
if (u.username.equals(username)) {
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Base64;
|
||||
import java.util.LinkedList;
|
||||
|
@ -107,7 +106,7 @@ public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws O
|
|||
try {
|
||||
var info = LegacySessionHelper.getJwtInfoFromAccessToken(accessToken, server.keyAgreementManager.ecdsaPublicKey);
|
||||
var user = (MySQLUser) getUserByUUID(info.uuid());
|
||||
if(user == null) {
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
return new MySQLUserSession(user);
|
||||
|
@ -121,17 +120,17 @@ public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws O
|
|||
@Override
|
||||
public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context) {
|
||||
String[] parts = refreshToken.split("\\.");
|
||||
if(parts.length != 2) {
|
||||
if (parts.length != 2) {
|
||||
return null;
|
||||
}
|
||||
String username = parts[0];
|
||||
String token = parts[1];
|
||||
var user = (MySQLUser) getUserByUsername(username);
|
||||
if(user == null || user.password == null) {
|
||||
if (user == null || user.password == null) {
|
||||
return null;
|
||||
}
|
||||
var realToken = LegacySessionHelper.makeRefreshTokenFromPassword(username, user.password, server.keyAgreementManager.legacySalt);
|
||||
if(!token.equals(realToken)) {
|
||||
if (!token.equals(realToken)) {
|
||||
return null;
|
||||
}
|
||||
var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey);
|
||||
|
@ -141,15 +140,15 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon
|
|||
@Override
|
||||
public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException {
|
||||
MySQLUser mySQLUser = (MySQLUser) getUserByLogin(login);
|
||||
if(mySQLUser == null) {
|
||||
if (mySQLUser == null) {
|
||||
throw AuthException.wrongPassword();
|
||||
}
|
||||
if(context != null) {
|
||||
if (context != null) {
|
||||
AuthPlainPassword plainPassword = (AuthPlainPassword) password;
|
||||
if(plainPassword == null) {
|
||||
if (plainPassword == null) {
|
||||
throw AuthException.wrongPassword();
|
||||
}
|
||||
if(!passwordVerifier.check(mySQLUser.password, plainPassword.password)) {
|
||||
if (!passwordVerifier.check(mySQLUser.password, plainPassword.password)) {
|
||||
throw AuthException.wrongPassword();
|
||||
}
|
||||
}
|
||||
|
@ -488,6 +487,31 @@ public String toString() {
|
|||
}
|
||||
}
|
||||
|
||||
public static class MySQLUserSession implements UserSession {
|
||||
private final MySQLUser user;
|
||||
private final String id;
|
||||
|
||||
public MySQLUserSession(MySQLUser user) {
|
||||
this.user = user;
|
||||
this.id = user.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getExpireIn() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class MySQLUser implements User, UserSupportHardware {
|
||||
protected UUID uuid;
|
||||
protected String username;
|
||||
|
@ -551,29 +575,4 @@ public String toString() {
|
|||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class MySQLUserSession implements UserSession {
|
||||
private final MySQLUser user;
|
||||
private final String id;
|
||||
|
||||
public MySQLUserSession(MySQLUser user) {
|
||||
this.user = user;
|
||||
this.id = user.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getExpireIn() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Clock;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
@ -85,7 +88,7 @@ public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws O
|
|||
try {
|
||||
var info = LegacySessionHelper.getJwtInfoFromAccessToken(accessToken, server.keyAgreementManager.ecdsaPublicKey);
|
||||
var user = (PostgresSQLUser) getUserByUUID(info.uuid());
|
||||
if(user == null) {
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
return new PostgresSQLCoreProvider.MySQLUserSession(user);
|
||||
|
@ -99,17 +102,17 @@ public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws O
|
|||
@Override
|
||||
public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context) {
|
||||
String[] parts = refreshToken.split("\\.");
|
||||
if(parts.length != 2) {
|
||||
if (parts.length != 2) {
|
||||
return null;
|
||||
}
|
||||
String username = parts[0];
|
||||
String token = parts[1];
|
||||
var user = (PostgresSQLUser) getUserByUsername(username);
|
||||
if(user == null || user.password == null) {
|
||||
if (user == null || user.password == null) {
|
||||
return null;
|
||||
}
|
||||
var realToken = LegacySessionHelper.makeRefreshTokenFromPassword(username, user.password, server.keyAgreementManager.legacySalt);
|
||||
if(!token.equals(realToken)) {
|
||||
if (!token.equals(realToken)) {
|
||||
return null;
|
||||
}
|
||||
var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey);
|
||||
|
@ -119,15 +122,15 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon
|
|||
@Override
|
||||
public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException {
|
||||
PostgresSQLUser postgresSQLUser = (PostgresSQLUser) getUserByLogin(login);
|
||||
if(postgresSQLUser == null) {
|
||||
if (postgresSQLUser == null) {
|
||||
throw AuthException.wrongPassword();
|
||||
}
|
||||
if(context != null) {
|
||||
if (context != null) {
|
||||
AuthPlainPassword plainPassword = (AuthPlainPassword) password;
|
||||
if(plainPassword == null) {
|
||||
if (plainPassword == null) {
|
||||
throw AuthException.wrongPassword();
|
||||
}
|
||||
if(!passwordVerifier.check(postgresSQLUser.password, plainPassword.password)) {
|
||||
if (!passwordVerifier.check(postgresSQLUser.password, plainPassword.password)) {
|
||||
throw AuthException.wrongPassword();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
public interface UserSessionSupportKeys {
|
||||
ClientProfileKeys getClientProfileKeys();
|
||||
record ClientProfileKeys(PublicKey publicKey, PrivateKey privateKey, byte[] signature /* V2 */, long expiresAt, long refreshedAfter) {
|
||||
|
||||
record ClientProfileKeys(PublicKey publicKey, PrivateKey privateKey, byte[] signature /* V2 */, long expiresAt,
|
||||
long refreshedAfter) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ default Map<String, Texture> getUserAssets() {
|
|||
var skin = getSkinTexture();
|
||||
var cape = getCloakTexture();
|
||||
Map<String, Texture> map = new HashMap<>();
|
||||
if(skin != null) {
|
||||
if (skin != null) {
|
||||
map.put("SKIN", skin);
|
||||
}
|
||||
if(cape != null) {
|
||||
if (cape != null) {
|
||||
map.put("CAPE", cape);
|
||||
}
|
||||
return map;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -19,29 +20,6 @@ public class JsonPasswordVerifier extends PasswordVerifier {
|
|||
public String url;
|
||||
public String bearerToken;
|
||||
|
||||
@Override
|
||||
public boolean check(String encryptedPassword, String password) {
|
||||
JsonPasswordResponse response = jsonRequest(new JsonPasswordRequest(encryptedPassword, password), url, bearerToken, JsonPasswordResponse.class, client);
|
||||
if (response != null) {
|
||||
return response.success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class JsonPasswordRequest {
|
||||
public String encryptedPassword;
|
||||
public String password;
|
||||
|
||||
public JsonPasswordRequest(String encryptedPassword, String password) {
|
||||
this.encryptedPassword = encryptedPassword;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsonPasswordResponse {
|
||||
public boolean success;
|
||||
}
|
||||
|
||||
public static <T, R> R jsonRequest(T request, String url, String bearerToken, Class<R> clazz, HttpClient client) {
|
||||
HttpRequest.BodyPublisher publisher;
|
||||
if (request != null) {
|
||||
|
@ -55,6 +33,7 @@ public static <T, R> R jsonRequest(T request, String url, String bearerToken, Cl
|
|||
.uri(new URI(url))
|
||||
.header("Content-Type", "application/json; charset=UTF-8")
|
||||
.header("Accept", "application/json")
|
||||
.header("User-Agent", IOHelper.USER_AGENT)
|
||||
.timeout(Duration.ofMillis(10000));
|
||||
if (bearerToken != null) {
|
||||
request1.header("Authorization", "Bearer ".concat(bearerToken));
|
||||
|
@ -78,4 +57,27 @@ public static <T, R> R jsonRequest(T request, String url, String bearerToken, Cl
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(String encryptedPassword, String password) {
|
||||
JsonPasswordResponse response = jsonRequest(new JsonPasswordRequest(encryptedPassword, password), url, bearerToken, JsonPasswordResponse.class, client);
|
||||
if (response != null) {
|
||||
return response.success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class JsonPasswordRequest {
|
||||
public String encryptedPassword;
|
||||
public String password;
|
||||
|
||||
public JsonPasswordRequest(String encryptedPassword, String password) {
|
||||
this.encryptedPassword = encryptedPassword;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsonPasswordResponse {
|
||||
public boolean success;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent;
|
||||
import pro.gravit.launcher.events.request.HardwareReportRequestEvent;
|
||||
import pro.gravit.launcher.events.request.VerifySecureLevelKeyRequestEvent;
|
||||
import pro.gravit.launcher.request.secure.HardwareReportRequest;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.UserHardware;
|
||||
|
@ -157,9 +156,9 @@ public boolean accept(Client client, AuthProviderPair pair, String extendedToken
|
|||
var parse = parser.parseClaimsJws(extendedToken);
|
||||
String hardwareInfoId = parse.getBody().get("hardware", String.class);
|
||||
if (hardwareInfoId == null) return false;
|
||||
if(client.auth == null) return false;
|
||||
if (client.auth == null) return false;
|
||||
var hardwareSupport = client.auth.core.isSupport(AuthSupportHardware.class);
|
||||
if(hardwareSupport == null) return false;
|
||||
if (hardwareSupport == null) return false;
|
||||
UserHardware hardware = hardwareSupport.getHardwareInfoById(hardwareInfoId);
|
||||
if (client.trustLevel == null) client.trustLevel = new Client.TrustLevel();
|
||||
client.trustLevel.hardwareInfo = hardware.getHardwareInfo();
|
||||
|
|
|
@ -27,7 +27,7 @@ public void checkLaunchServerLicense() {
|
|||
|
||||
@Override
|
||||
public void init(LaunchServer server) {
|
||||
if(profileWhitelist != null && profileWhitelist.size() > 0) {
|
||||
if (profileWhitelist != null && profileWhitelist.size() > 0) {
|
||||
logger.warn("profileWhitelist deprecated. Please use permission 'launchserver.profile.PROFILE_UUID.show' and 'launchserver.profile.PROFILE_UUID.enter'");
|
||||
}
|
||||
}
|
||||
|
@ -48,13 +48,13 @@ public boolean canGetUpdates(String updatesDirName, Client client) {
|
|||
}
|
||||
|
||||
private boolean isWhitelisted(String property, ClientProfile profile, Client client) {
|
||||
if(client.permissions != null) {
|
||||
if (client.permissions != null) {
|
||||
String permByUUID = String.format(property, profile.getUUID());
|
||||
if(client.permissions.hasPerm(permByUUID)) {
|
||||
if (client.permissions.hasPerm(permByUUID)) {
|
||||
return true;
|
||||
}
|
||||
String permByTitle = String.format(property, profile.getTitle().toLowerCase(Locale.ROOT));
|
||||
if(client.permissions.hasPerm(permByTitle)) {
|
||||
if (client.permissions.hasPerm(permByTitle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,10 @@
|
|||
import java.util.UUID;
|
||||
|
||||
public class JsonTextureProvider extends TextureProvider {
|
||||
public String url;
|
||||
private transient static final Type MAP_TYPE = new TypeToken<Map<String, Texture>>() {
|
||||
}.getType();
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
private transient static final Type MAP_TYPE = new TypeToken<Map<String, Texture>>() {}.getType();
|
||||
public String url;
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
@ -42,14 +43,14 @@ public Map<String, Texture> getAssets(UUID uuid, String username, String client)
|
|||
var result = HTTPRequest.jsonRequest(null, "GET", new URL(RequestTextureProvider.getTextureURL(url, uuid, username, client)));
|
||||
|
||||
Map<String, Texture> map = Launcher.gsonManager.gson.fromJson(result, MAP_TYPE);
|
||||
if(map == null) {
|
||||
if (map == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
if(map.get("skin") != null) { // Legacy script
|
||||
if (map.get("skin") != null) { // Legacy script
|
||||
map.put("SKIN", map.get("skin"));
|
||||
map.remove("skin");
|
||||
}
|
||||
if(map.get("cloak") != null) {
|
||||
if (map.get("cloak") != null) {
|
||||
map.put("CAPE", map.get("cloak"));
|
||||
map.remove("cloak");
|
||||
}
|
||||
|
|
|
@ -33,17 +33,6 @@ public static void registerProviders() {
|
|||
|
||||
public abstract Texture getSkinTexture(UUID uuid, String username, String client) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
public static class SkinAndCloakTextures {
|
||||
public final Texture skin;
|
||||
public final Texture cloak;
|
||||
|
||||
public SkinAndCloakTextures(Texture skin, Texture cloak) {
|
||||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SkinAndCloakTextures getTextures(UUID uuid, String username, String client) {
|
||||
|
||||
|
@ -83,13 +72,24 @@ public Map<String, Texture> getAssets(UUID uuid, String username, String client)
|
|||
}
|
||||
|
||||
Map<String, Texture> map = new HashMap<>();
|
||||
if(skin != null) {
|
||||
if (skin != null) {
|
||||
map.put("SKIN", skin);
|
||||
}
|
||||
if(cloak != null) {
|
||||
if (cloak != null) {
|
||||
map.put("CAPE", cloak);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class SkinAndCloakTextures {
|
||||
public final Texture skin;
|
||||
public final Texture cloak;
|
||||
|
||||
public SkinAndCloakTextures(Texture skin, Texture cloak) {
|
||||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -211,7 +211,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
try {
|
||||
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, sKeySpec, iKeySpec);
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException e) {
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException |
|
||||
InvalidAlgorithmParameterException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try (OutputStream stream = new CipherOutputStream(new NoCloseOutputStream(output), cipher)) {
|
||||
|
|
|
@ -40,7 +40,7 @@ public static CMSSignedDataGenerator gen(LaunchServerConfig.JarSignerConf config
|
|||
return SignHelper.createSignedDataGenerator(c,
|
||||
config.keyAlias, config.signAlgo, config.keyPass);
|
||||
} catch (CertificateEncodingException | UnrecoverableKeyException | KeyStoreException
|
||||
| OperatorCreationException | NoSuchAlgorithmException | CMSException e) {
|
||||
| OperatorCreationException | NoSuchAlgorithmException | CMSException e) {
|
||||
logger.error("Create signedDataGenerator failed", e);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
public class DebugCommand extends Command {
|
||||
private transient Logger logger = LogManager.getLogger();
|
||||
|
||||
public DebugCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
@ -34,7 +35,7 @@ public void invoke(String... args) throws Exception {
|
|||
LoggerConfig loggerConfig = config.getLoggerConfig("pro.gravit");
|
||||
loggerConfig.setLevel(value ? Level.TRACE : Level.DEBUG);
|
||||
ctx.updateLoggers();
|
||||
if(value) {
|
||||
if (value) {
|
||||
logger.info("Log level TRACE enabled");
|
||||
} else {
|
||||
logger.info("Log level TRACE disabled");
|
||||
|
|
|
@ -10,9 +10,7 @@
|
|||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.utils.Downloader;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import proguard.OutputWriter;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -22,11 +20,9 @@
|
|||
import java.util.List;
|
||||
|
||||
public final class DownloadAssetCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
private static final String MINECRAFT_VERSIONS_URL = "https://launchermeta.mojang.com/mc/game/version_manifest.json";
|
||||
|
||||
private static final String RESOURCES_DOWNLOAD_URL = "https://resources.download.minecraft.net/";
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public DownloadAssetCommand(LaunchServer server) {
|
||||
super(server);
|
||||
|
@ -52,23 +48,23 @@ public void invoke(String... args) throws Exception {
|
|||
Path assetDir = server.updatesDir.resolve(dirName);
|
||||
|
||||
// Create asset dir
|
||||
if(Files.notExists(assetDir)) {
|
||||
if (Files.notExists(assetDir)) {
|
||||
logger.info("Creating asset dir: '{}'", dirName);
|
||||
Files.createDirectory(assetDir);
|
||||
}
|
||||
|
||||
if(type.equals("mojang")) {
|
||||
if (type.equals("mojang")) {
|
||||
HttpRequester requester = new HttpRequester();
|
||||
logger.info("Fetch versions from {}", MINECRAFT_VERSIONS_URL);
|
||||
var versions = requester.send(requester.get(MINECRAFT_VERSIONS_URL, null), MinecraftVersions.class).getOrThrow();
|
||||
String profileUrl = null;
|
||||
for(var e : versions.versions) {
|
||||
if(e.id.equals(versionName)) {
|
||||
for (var e : versions.versions) {
|
||||
if (e.id.equals(versionName)) {
|
||||
profileUrl = e.url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(profileUrl == null) {
|
||||
if (profileUrl == null) {
|
||||
logger.error("Version {} not found", versionName);
|
||||
return;
|
||||
}
|
||||
|
@ -76,30 +72,30 @@ public void invoke(String... args) throws Exception {
|
|||
var profileInfo = requester.send(requester.get(profileUrl, null), MiniVersion.class).getOrThrow();
|
||||
String assetsIndexUrl = profileInfo.assetIndex.url;
|
||||
String assetIndex = profileInfo.assetIndex.id;
|
||||
Path indexPath = assetDir.resolve("indexes").resolve(assetIndex+".json");
|
||||
Path indexPath = assetDir.resolve("indexes").resolve(assetIndex + ".json");
|
||||
logger.info("Fetch asset index {} from {}", assetIndex, assetsIndexUrl);
|
||||
JsonObject assets = requester.send(requester.get(assetsIndexUrl, null), JsonObject.class).getOrThrow();
|
||||
JsonObject objects = assets.get("objects").getAsJsonObject();
|
||||
try(Writer writer = IOHelper.newWriter(indexPath)) {
|
||||
try (Writer writer = IOHelper.newWriter(indexPath)) {
|
||||
logger.info("Save {}", indexPath);
|
||||
Launcher.gsonManager.configGson.toJson(assets, writer);
|
||||
}
|
||||
if(!assetIndex.equals(versionName)) {
|
||||
Path targetPath = assetDir.resolve("indexes").resolve(versionName+".json");
|
||||
if (!assetIndex.equals(versionName)) {
|
||||
Path targetPath = assetDir.resolve("indexes").resolve(versionName + ".json");
|
||||
logger.info("Copy {} into {}", indexPath, targetPath);
|
||||
Files.copy(indexPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
List<AsyncDownloader.SizedFile> toDownload = new ArrayList<>(128);
|
||||
for(var e : objects.entrySet()) {
|
||||
for (var e : objects.entrySet()) {
|
||||
var value = e.getValue().getAsJsonObject();
|
||||
var hash = value.get("hash").getAsString();
|
||||
hash = hash.substring(0, 2) + "/" + hash;
|
||||
var size = value.get("size").getAsLong();
|
||||
var path = "objects/" + hash;
|
||||
var target = assetDir.resolve(path);
|
||||
if(Files.exists(target)) {
|
||||
if (Files.exists(target)) {
|
||||
long fileSize = Files.size(target);
|
||||
if(fileSize != size) {
|
||||
if (fileSize != size) {
|
||||
logger.warn("File {} corrupted. Size {}, expected {}", target, size, fileSize);
|
||||
} else {
|
||||
continue;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
public class TokenCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public TokenCommand(LaunchServer server) {
|
||||
super(server);
|
||||
this.childCommands.put("info", new SubCommand("[token]", "print token info") {
|
||||
|
@ -27,16 +28,16 @@ public void invoke(String... args) throws Exception {
|
|||
public void invoke(String... args) throws Exception {
|
||||
AuthProviderPair pair = args.length > 1 ? server.config.getAuthProviderPair(args[1]) : server.config.getAuthProviderPair();
|
||||
ClientProfile profile = null;
|
||||
for(ClientProfile p : server.getProfiles()) {
|
||||
if(p.getTitle().equals(args[0]) || p.getUUID().toString().equals(args[0])) {
|
||||
for (ClientProfile p : server.getProfiles()) {
|
||||
if (p.getTitle().equals(args[0]) || p.getUUID().toString().equals(args[0])) {
|
||||
profile = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(profile == null) {
|
||||
if (profile == null) {
|
||||
logger.warn("Profile {} not found", args[0]);
|
||||
}
|
||||
if(pair == null) {
|
||||
if (pair == null) {
|
||||
logger.error("AuthId {} not found", args[1]);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
import pro.gravit.utils.helper.UnpackHelper;
|
||||
import proguard.Configuration;
|
||||
import proguard.ConfigurationParser;
|
||||
import proguard.ParseException;
|
||||
import proguard.ProGuard;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -166,9 +166,9 @@ public void verify() {
|
|||
// Mirror check
|
||||
{
|
||||
boolean updateMirror = Boolean.getBoolean("launchserver.config.disableUpdateMirror");
|
||||
if(!updateMirror) {
|
||||
for(int i=0;i < mirrors.length;++i) {
|
||||
if("https://mirror.gravit.pro/5.2.x/".equals(mirrors[i])) {
|
||||
if (!updateMirror) {
|
||||
for (int i = 0; i < mirrors.length; ++i) {
|
||||
if ("https://mirror.gravit.pro/5.2.x/".equals(mirrors[i])) {
|
||||
logger.warn("Replace mirror 'https://mirror.gravit.pro/5.2.x/' to 'https://mirror.gravit.pro/5.3.x/'. If you really need to use original url, use '-Dlaunchserver.config.disableUpdateMirror=true'");
|
||||
mirrors[i] = "https://mirror.gravit.pro/5.3.x/";
|
||||
}
|
||||
|
|
|
@ -23,11 +23,61 @@
|
|||
|
||||
public final class HttpHelper {
|
||||
private static transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
private HttpHelper() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static class HttpOptional<T,E> {
|
||||
public static <T, E> HttpOptional<T, E> send(HttpClient client, HttpRequest request, HttpErrorHandler<T, E> handler) throws IOException {
|
||||
try {
|
||||
var response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
|
||||
return handler.apply(response);
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, E> CompletableFuture<HttpOptional<T, E>> sendAsync(HttpClient client, HttpRequest request, HttpErrorHandler<T, E> handler) throws IOException {
|
||||
return client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).thenApply(handler::apply);
|
||||
}
|
||||
|
||||
public static <T> HttpResponse.BodyHandler<T> ofJsonResult(Class<T> type) {
|
||||
return ofJsonResult((Type) type);
|
||||
}
|
||||
|
||||
public static <T> HttpResponse.BodyHandler<T> ofJsonResult(Type type) {
|
||||
return new JsonBodyHandler<>(HttpResponse.BodyHandlers.ofInputStream(), (input) -> {
|
||||
try (Reader reader = new InputStreamReader(input)) {
|
||||
return Launcher.gsonManager.gson.fromJson(reader, type);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> HttpRequest.BodyPublisher jsonBodyPublisher(T obj) {
|
||||
return HttpRequest.BodyPublishers.ofString(Launcher.gsonManager.gson.toJson(obj));
|
||||
}
|
||||
|
||||
|
||||
public interface HttpErrorHandler<T, E> {
|
||||
HttpOptional<T, E> apply(HttpResponse<InputStream> response);
|
||||
}
|
||||
|
||||
public interface HttpJsonErrorHandler<T, E> extends HttpErrorHandler<T, E> {
|
||||
HttpOptional<T, E> applyJson(JsonElement response, int statusCode);
|
||||
|
||||
default HttpOptional<T, E> apply(HttpResponse<InputStream> response) {
|
||||
try (Reader reader = new InputStreamReader(response.body())) {
|
||||
var element = Launcher.gsonManager.gson.fromJson(reader, JsonElement.class);
|
||||
return applyJson(element, response.statusCode());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class HttpOptional<T, E> {
|
||||
protected final T result;
|
||||
protected final E error;
|
||||
protected final int statusCode;
|
||||
|
@ -41,17 +91,21 @@ public HttpOptional(T result, E error, int statusCode) {
|
|||
public T result() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public E error() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public int statusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public boolean isSuccessful() {
|
||||
return statusCode >= 200 && statusCode < 300;
|
||||
}
|
||||
|
||||
public T getOrThrow() throws RequestException {
|
||||
if(isSuccessful()) {
|
||||
if (isSuccessful()) {
|
||||
return result;
|
||||
} else {
|
||||
throw new RequestException(error == null ? String.format("statusCode %d", statusCode) : error.toString());
|
||||
|
@ -59,22 +113,6 @@ public T getOrThrow() throws RequestException {
|
|||
}
|
||||
}
|
||||
|
||||
public interface HttpErrorHandler<T, E> {
|
||||
HttpOptional<T,E> apply(HttpResponse<InputStream> response);
|
||||
}
|
||||
|
||||
public interface HttpJsonErrorHandler<T, E> extends HttpErrorHandler<T,E> {
|
||||
HttpOptional<T,E> applyJson(JsonElement response, int statusCode);
|
||||
default HttpOptional<T,E> apply(HttpResponse<InputStream> response) {
|
||||
try(Reader reader = new InputStreamReader(response.body())) {
|
||||
var element = Launcher.gsonManager.gson.fromJson(reader, JsonElement.class);
|
||||
return applyJson(element, response.statusCode());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BasicJsonHttpErrorHandler<T> implements HttpJsonErrorHandler<T, Void> {
|
||||
private final Class<T> type;
|
||||
|
||||
|
@ -88,38 +126,6 @@ public HttpOptional<T, Void> applyJson(JsonElement response, int statusCode) {
|
|||
}
|
||||
}
|
||||
|
||||
public static<T,E> HttpOptional<T,E> send(HttpClient client, HttpRequest request, HttpErrorHandler<T,E> handler) throws IOException {
|
||||
try {
|
||||
var response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
|
||||
return handler.apply(response);
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static<T,E> CompletableFuture<HttpOptional<T,E>> sendAsync(HttpClient client, HttpRequest request, HttpErrorHandler<T,E> handler) throws IOException {
|
||||
return client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).thenApply(handler::apply);
|
||||
}
|
||||
|
||||
public static<T> HttpResponse.BodyHandler<T> ofJsonResult(Class<T> type) {
|
||||
return ofJsonResult((Type) type);
|
||||
}
|
||||
|
||||
public static<T> HttpResponse.BodyHandler<T> ofJsonResult(Type type) {
|
||||
return new JsonBodyHandler<>(HttpResponse.BodyHandlers.ofInputStream(), (input) -> {
|
||||
try(Reader reader = new InputStreamReader(input)) {
|
||||
return Launcher.gsonManager.gson.fromJson(reader, type);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static<T> HttpRequest.BodyPublisher jsonBodyPublisher(T obj) {
|
||||
return HttpRequest.BodyPublishers.ofString(Launcher.gsonManager.gson.toJson(obj));
|
||||
}
|
||||
|
||||
private static class JsonBodyHandler<T> implements HttpResponse.BodyHandler<T> {
|
||||
private final HttpResponse.BodyHandler<InputStream> delegate;
|
||||
private final Function<InputStream, T> func;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import java.security.interfaces.ECPrivateKey;
|
||||
import java.security.interfaces.ECPublicKey;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Date;
|
||||
|
@ -20,7 +19,7 @@ public static String makeAccessJwtTokenFromString(User user, LocalDateTime expir
|
|||
.setSubject(user.getUsername())
|
||||
.claim("uuid", user.getUUID().toString())
|
||||
.setExpiration(Date.from(expirationTime
|
||||
.toInstant(ZoneOffset.UTC)))
|
||||
.toInstant(ZoneOffset.UTC)))
|
||||
.signWith(privateKey)
|
||||
.compact();
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ public static JwtTokenInfo getJwtInfoFromAccessToken(String token, ECPublicKey p
|
|||
}
|
||||
|
||||
public static String makeRefreshTokenFromPassword(String username, String rawPassword, String secretSalt) {
|
||||
if(rawPassword == null) {
|
||||
if (rawPassword == null) {
|
||||
rawPassword = "";
|
||||
}
|
||||
return SecurityHelper.toHex(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256,
|
||||
|
|
|
@ -18,7 +18,7 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
|
|||
ClientProfileBuilder builder = new ClientProfileBuilder();
|
||||
builder.setVersion(version.name);
|
||||
builder.setDir(title);
|
||||
if(findOption(options, MakeProfileOptionGlobalAssets.class).isPresent()) {
|
||||
if (findOption(options, MakeProfileOptionGlobalAssets.class).isPresent()) {
|
||||
builder.setAssetDir("assets");
|
||||
} else {
|
||||
builder.setAssetDir("asset" + version.name);
|
||||
|
@ -46,10 +46,10 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
|
|||
Set<OptionalFile> optionals = new HashSet<>();
|
||||
jvmArgs.add("-XX:+DisableAttachMechanism");
|
||||
// Official Mojang launcher java arguments
|
||||
if(version.compareTo(ClientProfile.Version.MC112) <= 0) {
|
||||
if (version.compareTo(ClientProfile.Version.MC112) <= 0) {
|
||||
jvmArgs.add("-XX:+UseConcMarkSweepGC");
|
||||
jvmArgs.add("-XX:+CMSIncrementalMode");
|
||||
} else if(version.compareTo(ClientProfile.Version.MC118) <= 0) { // 1.13 - 1.16.5
|
||||
} else if (version.compareTo(ClientProfile.Version.MC118) <= 0) { // 1.13 - 1.16.5
|
||||
jvmArgs.add("-XX:+UseG1GC");
|
||||
jvmArgs.add("-XX:+UnlockExperimentalVMOptions");
|
||||
} else { // 1.18+
|
||||
|
@ -236,7 +236,7 @@ public static MakeProfileOption[] getMakeProfileOptionsFromDir(Path dir, ClientP
|
|||
if (Files.exists(dir.resolve("libraries/forge/launchwrapper-1.12-launcherfixed.jar.jar")) || Files.exists(dir.resolve("libraries/net/minecraft/launchwrapper"))) {
|
||||
options.add(new MakeProfileOptionLaunchWrapper());
|
||||
}
|
||||
if(globalAssets) {
|
||||
if (globalAssets) {
|
||||
options.add(new MakeProfileOptionGlobalAssets());
|
||||
}
|
||||
return options.toArray(new MakeProfileOption[0]);
|
||||
|
|
|
@ -27,13 +27,7 @@
|
|||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
|
||||
public class AuthManager {
|
||||
|
@ -60,9 +54,6 @@ public String newCheckServerToken(String serverName, String authId) {
|
|||
.compact();
|
||||
}
|
||||
|
||||
public record CheckServerTokenInfo(String serverName, String authId) {
|
||||
}
|
||||
|
||||
public CheckServerTokenInfo parseCheckServerToken(String token) {
|
||||
try {
|
||||
var jwt = checkServerTokenParser.parseClaimsJws(token).getBody();
|
||||
|
@ -72,29 +63,6 @@ public CheckServerTokenInfo parseCheckServerToken(String token) {
|
|||
}
|
||||
}
|
||||
|
||||
public static class CheckServerVerifier implements RestoreResponse.ExtendedTokenProvider {
|
||||
private final LaunchServer server;
|
||||
|
||||
public CheckServerVerifier(LaunchServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(Client client, AuthProviderPair pair, String extendedToken) {
|
||||
var info = server.authManager.parseCheckServerToken(extendedToken);
|
||||
if(info == null) {
|
||||
return false;
|
||||
}
|
||||
client.auth_id = info.authId;
|
||||
client.auth = server.config.getAuthProviderPair(info.authId);
|
||||
if(client.permissions == null) client.permissions = new ClientPermissions();
|
||||
client.permissions.addPerm("launchserver.checkserver");
|
||||
client.permissions.addPerm(String.format("launchserver.profile.%s.show", info.serverName));
|
||||
client.setProperty("launchserver.serverName", info.serverName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create AuthContext
|
||||
*
|
||||
|
@ -154,7 +122,7 @@ public AuthReport auth(AuthResponse.AuthContext context, AuthRequest.AuthPasswor
|
|||
String login = context.login;
|
||||
try {
|
||||
AuthReport result = provider.authorize(login, context, password, context.authType == AuthResponse.ConnectTypes.CLIENT && server.config.protectHandler.allowGetAccessToken(context));
|
||||
if(result == null || result.session == null || result.session.getUser() == null) {
|
||||
if (result == null || result.session == null || result.session.getUser() == null) {
|
||||
logger.error("AuthCoreProvider {} method 'authorize' return null", context.pair.name);
|
||||
throw new AuthException("Internal Auth Error");
|
||||
}
|
||||
|
@ -175,7 +143,7 @@ public AuthReport auth(AuthResponse.AuthContext context, AuthRequest.AuthPasswor
|
|||
* Writing authorization information to the Client object
|
||||
*/
|
||||
public void internalAuth(Client client, AuthResponse.ConnectTypes authType, AuthProviderPair pair, String username, UUID uuid, ClientPermissions permissions, boolean oauth) {
|
||||
if(!oauth) {
|
||||
if (!oauth) {
|
||||
throw new UnsupportedOperationException("Unsupported legacy session system");
|
||||
}
|
||||
client.isAuth = true;
|
||||
|
@ -265,7 +233,7 @@ public PlayerProfile getPlayerProfile(AuthProviderPair pair, UUID uuid, ClientPr
|
|||
|
||||
public PlayerProfile getPlayerProfile(AuthProviderPair pair, User user) {
|
||||
Map<String, String> properties;
|
||||
if(user instanceof UserSupportProperties userSupportProperties) {
|
||||
if (user instanceof UserSupportProperties userSupportProperties) {
|
||||
properties = userSupportProperties.getProperties();
|
||||
} else {
|
||||
properties = new HashMap<>();
|
||||
|
@ -325,6 +293,32 @@ private AuthRequest.AuthPasswordInterface tryDecryptPasswordPlain(AuthRequest.Au
|
|||
return password;
|
||||
}
|
||||
|
||||
public record CheckServerTokenInfo(String serverName, String authId) {
|
||||
}
|
||||
|
||||
public static class CheckServerVerifier implements RestoreResponse.ExtendedTokenProvider {
|
||||
private final LaunchServer server;
|
||||
|
||||
public CheckServerVerifier(LaunchServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(Client client, AuthProviderPair pair, String extendedToken) {
|
||||
var info = server.authManager.parseCheckServerToken(extendedToken);
|
||||
if (info == null) {
|
||||
return false;
|
||||
}
|
||||
client.auth_id = info.authId;
|
||||
client.auth = server.config.getAuthProviderPair(info.authId);
|
||||
if (client.permissions == null) client.permissions = new ClientPermissions();
|
||||
client.permissions.addPerm("launchserver.checkserver");
|
||||
client.permissions.addPerm(String.format("launchserver.profile.%s.show", info.serverName));
|
||||
client.setProperty("launchserver.serverName", info.serverName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CheckServerReport {
|
||||
public UUID uuid;
|
||||
public User user;
|
||||
|
|
|
@ -66,7 +66,7 @@ public KeyAgreementManager(Path keyDirectory) throws IOException, InvalidKeySpec
|
|||
IOHelper.write(rsaPrivateKeyPath, rsaPrivateKey.getEncoded());
|
||||
}
|
||||
Path legacySaltPath = keyDirectory.resolve("legacySalt");
|
||||
if(IOHelper.isFile(legacySaltPath)) {
|
||||
if (IOHelper.isFile(legacySaltPath)) {
|
||||
legacySalt = new String(IOHelper.read(legacySaltPath), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
legacySalt = SecurityHelper.randomStringToken();
|
||||
|
|
|
@ -33,8 +33,8 @@ public LaunchServerGsonManager(LaunchServerModulesManager modulesManager) {
|
|||
public void registerAdapters(GsonBuilder builder) {
|
||||
super.registerAdapters(builder);
|
||||
builder.registerTypeAdapterFactory(RecordTypeAdapterFactory.builder()
|
||||
.allowMissingComponentValues()
|
||||
.create());
|
||||
.allowMissingComponentValues()
|
||||
.create());
|
||||
builder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers));
|
||||
builder.registerTypeAdapter(AuthCoreProvider.class, new UniversalJsonAdapter<>(AuthCoreProvider.providers));
|
||||
builder.registerTypeAdapter(PasswordVerifier.class, new UniversalJsonAdapter<>(PasswordVerifier.providers));
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package pro.gravit.launchserver.manangers.hook;
|
||||
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
import pro.gravit.launchserver.manangers.AuthManager;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
|
||||
|
|
|
@ -65,12 +65,12 @@ public <T> void setProperty(String name, T object) {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public<T> T getStaticProperty(String name) {
|
||||
public <T> T getStaticProperty(String name) {
|
||||
if (staticProperties == null) staticProperties = new HashMap<>();
|
||||
return (T) staticProperties.get(name);
|
||||
}
|
||||
|
||||
public<T> void setStaticProperty(String name, T value) {
|
||||
public <T> void setStaticProperty(String name, T value) {
|
||||
if (staticProperties == null) staticProperties = new HashMap<>();
|
||||
staticProperties.put(name, value);
|
||||
}
|
||||
|
|
|
@ -93,6 +93,22 @@ public static void registerResponses() {
|
|||
providers.register("getPublicKey", GetPublicKeyResponse.class);
|
||||
}
|
||||
|
||||
public static String getIPFromContext(ChannelHandlerContext ctx) {
|
||||
var handler = ctx.pipeline().get(WebSocketFrameHandler.class);
|
||||
if (handler == null || handler.context == null || handler.context.ip == null) {
|
||||
return IOHelper.getIP(ctx.channel().remoteAddress());
|
||||
}
|
||||
return handler.context.ip;
|
||||
}
|
||||
|
||||
public static String getIPFromChannel(Channel channel) {
|
||||
var handler = channel.pipeline().get(WebSocketFrameHandler.class);
|
||||
if (handler == null || handler.context == null || handler.context.ip == null) {
|
||||
return IOHelper.getIP(channel.remoteAddress());
|
||||
}
|
||||
return handler.context.ip;
|
||||
}
|
||||
|
||||
public void forEachActiveChannels(BiConsumer<Channel, WebSocketFrameHandler> callback) {
|
||||
for (Channel channel : channels) {
|
||||
if (channel == null || channel.pipeline() == null) continue;
|
||||
|
@ -176,25 +192,9 @@ public void registerClient(Channel channel) {
|
|||
channels.add(channel);
|
||||
}
|
||||
|
||||
public static String getIPFromContext(ChannelHandlerContext ctx) {
|
||||
var handler = ctx.pipeline().get(WebSocketFrameHandler.class);
|
||||
if(handler == null || handler.context == null || handler.context.ip == null) {
|
||||
return IOHelper.getIP(ctx.channel().remoteAddress());
|
||||
}
|
||||
return handler.context.ip;
|
||||
}
|
||||
|
||||
public static String getIPFromChannel(Channel channel) {
|
||||
var handler = channel.pipeline().get(WebSocketFrameHandler.class);
|
||||
if(handler == null || handler.context == null || handler.context.ip == null) {
|
||||
return IOHelper.getIP(channel.remoteAddress());
|
||||
}
|
||||
return handler.context.ip;
|
||||
}
|
||||
|
||||
public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
||||
String msg = gson.toJson(obj, WebSocketEvent.class);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send to {}: {}", getIPFromContext(ctx), msg);
|
||||
}
|
||||
ctx.writeAndFlush(new TextWebSocketFrame(msg), ctx.voidPromise());
|
||||
|
@ -202,7 +202,7 @@ public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
|||
|
||||
public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) {
|
||||
String msg = gson.toJson(obj, type);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send to {}: {}", getIPFromContext(ctx), msg);
|
||||
}
|
||||
ctx.writeAndFlush(new TextWebSocketFrame(msg), ctx.voidPromise());
|
||||
|
@ -210,7 +210,7 @@ public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) {
|
|||
|
||||
public void sendObject(Channel channel, Object obj) {
|
||||
String msg = gson.toJson(obj, WebSocketEvent.class);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send to channel {}: {}", getIPFromChannel(channel), msg);
|
||||
}
|
||||
channel.writeAndFlush(new TextWebSocketFrame(msg), channel.voidPromise());
|
||||
|
@ -218,7 +218,7 @@ public void sendObject(Channel channel, Object obj) {
|
|||
|
||||
public void sendObject(Channel channel, Object obj, Type type) {
|
||||
String msg = gson.toJson(obj, type);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send to channel {}: {}", getIPFromChannel(channel), msg);
|
||||
}
|
||||
channel.writeAndFlush(new TextWebSocketFrame(msg), channel.voidPromise());
|
||||
|
@ -226,7 +226,7 @@ public void sendObject(Channel channel, Object obj, Type type) {
|
|||
|
||||
public void sendObjectAll(Object obj) {
|
||||
String msg = gson.toJson(obj, WebSocketEvent.class);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send to all: {}", msg);
|
||||
}
|
||||
for (Channel ch : channels) {
|
||||
|
@ -236,7 +236,7 @@ public void sendObjectAll(Object obj) {
|
|||
|
||||
public void sendObjectAll(Object obj, Type type) {
|
||||
String msg = gson.toJson(obj, type);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send to all: {}", msg);
|
||||
}
|
||||
for (Channel ch : channels) {
|
||||
|
@ -252,7 +252,7 @@ public void sendObjectToUUID(UUID userUuid, Object obj, Type type) {
|
|||
Client client = wsHandler.getClient();
|
||||
if (client == null || !userUuid.equals(client.uuid)) continue;
|
||||
String msg = gson.toJson(obj, type);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send to {}({}): {}", getIPFromChannel(ch), userUuid, msg);
|
||||
}
|
||||
ch.writeAndFlush(new TextWebSocketFrame(msg), ch.voidPromise());
|
||||
|
@ -320,7 +320,7 @@ public boolean kickByIP(String ip, boolean isClose) {
|
|||
|
||||
public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj) {
|
||||
String msg = gson.toJson(obj, WebSocketEvent.class);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send and close {}: {}", getIPFromContext(ctx), msg);
|
||||
}
|
||||
ctx.writeAndFlush(new TextWebSocketFrame(msg)).addListener(ChannelFutureListener.CLOSE);
|
||||
|
@ -328,7 +328,7 @@ public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj) {
|
|||
|
||||
public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj, Type type) {
|
||||
String msg = gson.toJson(obj, type);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send and close {}: {}", getIPFromContext(ctx), msg);
|
||||
}
|
||||
ctx.writeAndFlush(new TextWebSocketFrame(msg)).addListener(ChannelFutureListener.CLOSE);
|
||||
|
@ -337,7 +337,7 @@ public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj, Type type)
|
|||
@Deprecated
|
||||
public void sendEvent(EventResult obj) {
|
||||
String msg = gson.toJson(obj, WebSocketEvent.class);
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Send event: {}", msg);
|
||||
}
|
||||
channels.writeAndFlush(new TextWebSocketFrame(msg), ChannelMatchers.all(), true);
|
||||
|
|
|
@ -64,7 +64,7 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
|||
logger.error("WebSocket frame handler hook error", ex);
|
||||
}
|
||||
if (frame instanceof TextWebSocketFrame) {
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Message from {}: {}", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip, ((TextWebSocketFrame) frame).text());
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package pro.gravit.launchserver.socket.response.auth;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.ClientPermissions;
|
||||
import pro.gravit.launcher.events.request.AdditionalDataRequestEvent;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
||||
import pro.gravit.utils.HookException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuthResponse extends SimpleResponse {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
public String login;
|
||||
|
|
|
@ -31,7 +31,7 @@ public void execute(ChannelHandlerContext ctx, Client pClient) {
|
|||
try {
|
||||
server.authHookManager.checkServerHook.hook(this, pClient);
|
||||
AuthManager.CheckServerReport report = server.authManager.checkServer(pClient, username, serverID);
|
||||
if(report == null) {
|
||||
if (report == null) {
|
||||
sendError("User not verified");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public static void exit(LaunchServer server, WebSocketFrameHandler wsHandler, Ch
|
|||
Client chClient = wsHandler.getClient();
|
||||
Client newCusClient = new Client();
|
||||
newCusClient.checkSign = chClient.checkSign;
|
||||
if(chClient.staticProperties != null) {
|
||||
if (chClient.staticProperties != null) {
|
||||
newCusClient.staticProperties = new HashMap<>(chClient.staticProperties);
|
||||
}
|
||||
wsHandler.setClient(newCusClient);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.FetchClientProfileKeyRequestEvent;
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
import pro.gravit.launchserver.auth.core.UserSession;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportKeys;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
|
@ -22,7 +21,7 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
|
|||
}
|
||||
UserSession session = client.sessionObject;
|
||||
UserSessionSupportKeys.ClientProfileKeys keys;
|
||||
if(session instanceof UserSessionSupportKeys support) {
|
||||
if (session instanceof UserSessionSupportKeys support) {
|
||||
keys = support.getClientProfileKeys();
|
||||
} else {
|
||||
keys = server.authManager.createClientProfileKeys(client.uuid);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.RequestService;
|
||||
import pro.gravit.launcher.request.WebSocketEvent;
|
||||
import pro.gravit.launcher.request.websockets.ClientWebSocketService;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class BasicLauncherEventHandler implements RequestService.EventHandler {
|
||||
|
|
|
@ -140,7 +140,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
|
|||
if (context.memoryLimit != 0) {
|
||||
args.add(String.format("-Xmx%dM", context.memoryLimit));
|
||||
}
|
||||
if(customJvmOptions != null) {
|
||||
if (customJvmOptions != null) {
|
||||
args.addAll(customJvmOptions);
|
||||
}
|
||||
args.add("-cp");
|
||||
|
|
|
@ -246,14 +246,14 @@ public void start(String... args) throws Throwable {
|
|||
try {
|
||||
service = StdWebSocketService.initWebSockets(address).get();
|
||||
} catch (Throwable e) {
|
||||
if(LogHelper.isDebugEnabled()) {
|
||||
if (LogHelper.isDebugEnabled()) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
LogHelper.warning("Launcher in offline mode");
|
||||
service = initOffline();
|
||||
}
|
||||
Request.setRequestService(service);
|
||||
if(service instanceof StdWebSocketService) {
|
||||
if (service instanceof StdWebSocketService) {
|
||||
((StdWebSocketService) service).reconnectCallback = () ->
|
||||
{
|
||||
LogHelper.debug("WebSocket connect closed. Try reconnect");
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package pro.gravit.launcher.api;
|
||||
|
||||
import pro.gravit.launcher.LauncherEngine;
|
||||
import pro.gravit.launcher.profiles.ClientProfile;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class SystemService {
|
||||
private SystemService() {
|
||||
|
|
|
@ -121,7 +121,7 @@ public static void main(String[] args) throws Throwable {
|
|||
List<URL> classpathURLs = classpath.stream().map(IOHelper::toURL).collect(Collectors.toList());
|
||||
// Start client with WatchService monitoring
|
||||
RequestService service;
|
||||
if(params.offlineMode) {
|
||||
if (params.offlineMode) {
|
||||
service = initOffline(LauncherEngine.modulesManager, params);
|
||||
Request.setRequestService(service);
|
||||
} else {
|
||||
|
@ -231,13 +231,13 @@ public static RequestService initOffline(LauncherModulesManager modulesManager,
|
|||
|
||||
public static void applyClientOfflineProcessors(OfflineRequestService service, ClientLauncherProcess.ClientParams params) {
|
||||
service.registerRequestProcessor(ProfileByUsernameRequest.class, (r) -> {
|
||||
if(params.playerProfile.username.equals(r.username)) {
|
||||
if (params.playerProfile.username.equals(r.username)) {
|
||||
return new ProfileByUsernameRequestEvent(params.playerProfile);
|
||||
}
|
||||
throw new RequestException("User not found");
|
||||
});
|
||||
service.registerRequestProcessor(ProfileByUUIDRequest.class, (r) -> {
|
||||
if(params.playerProfile.uuid.equals(r.uuid)) {
|
||||
if (params.playerProfile.uuid.equals(r.uuid)) {
|
||||
return new ProfileByUUIDRequestEvent(params.playerProfile);
|
||||
}
|
||||
throw new RequestException("User not found");
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.LauncherConfig;
|
||||
import pro.gravit.launcher.LauncherEngine;
|
||||
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||
import pro.gravit.launcher.client.events.client.ClientProcessBuilderCreateEvent;
|
||||
import pro.gravit.launcher.client.events.client.ClientProcessBuilderLaunchedEvent;
|
||||
import pro.gravit.launcher.client.events.client.ClientProcessBuilderParamsWrittedEvent;
|
||||
|
@ -28,7 +27,6 @@
|
|||
import java.net.SocketAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -79,7 +77,7 @@ public ClientLauncherProcess(Path clientDir, Path assetDir, JavaHelper.JavaVersi
|
|||
this.params.resourcePackDir = resourcePackDir.toAbsolutePath().toString();
|
||||
this.params.assetDir = assetDir.toAbsolutePath().toString();
|
||||
Path nativesPath = workDir.resolve("natives").resolve(JVMHelper.OS_TYPE.name).resolve(javaVersion.arch.name);
|
||||
if(!Files.isDirectory(nativesPath)) {
|
||||
if (!Files.isDirectory(nativesPath)) {
|
||||
nativesPath = workDir.resolve("natives");
|
||||
}
|
||||
this.params.nativesDir = nativesPath.toString();
|
||||
|
@ -158,7 +156,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException {
|
|||
.map(Path::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
if(Launcher.getConfig().environment != LauncherConfig.LauncherEnvironment.PROD) {
|
||||
if (Launcher.getConfig().environment != LauncherConfig.LauncherEnvironment.PROD) {
|
||||
processArgs.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, String.valueOf(LogHelper.isDevEnabled())));
|
||||
processArgs.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, String.valueOf(LogHelper.isDebugEnabled())));
|
||||
processArgs.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, String.valueOf(LogHelper.isStacktraceEnabled())));
|
||||
|
@ -211,7 +209,7 @@ private void applyJava9Params(List<String> processArgs) {
|
|||
if (modulesAdd.length() > 0) modulesAdd.append(",");
|
||||
modulesAdd.append(moduleName);
|
||||
}
|
||||
for(String modulePath : jvmModulesPaths) {
|
||||
for (String modulePath : jvmModulesPaths) {
|
||||
if (modulesPath.length() > 0) modulesPath.append(File.pathSeparator);
|
||||
modulesPath.append(modulePath);
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ private Result modernPing(HInput input, HOutput output) throws IOException {
|
|||
|
||||
// Parse JSON response
|
||||
JsonObject object = JsonParser.parseString(response).getAsJsonObject();
|
||||
if(object.has("error")) {
|
||||
if (object.has("error")) {
|
||||
throw new IOException(object.get("error").getAsString());
|
||||
}
|
||||
JsonObject playersObject = object.get("players").getAsJsonObject();
|
||||
|
|
|
@ -24,10 +24,10 @@ public String getUsageDescription() {
|
|||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
for(LauncherModule module : LauncherEngine.modulesManager.getModules()) {
|
||||
for (LauncherModule module : LauncherEngine.modulesManager.getModules()) {
|
||||
LauncherModuleInfo info = module.getModuleInfo();
|
||||
LauncherTrustManager.CheckClassResult checkStatus = module.getCheckResult();
|
||||
if(!ConsoleManager.isConsoleUnlock) {
|
||||
if (!ConsoleManager.isConsoleUnlock) {
|
||||
LogHelper.info("[MODULE] %s v: %s", info.name, info.version.getVersionString());
|
||||
} else {
|
||||
LogHelper.info("[MODULE] %s v: %s p: %d deps: %s sig: %s", info.name, info.version.getVersionString(), info.priority, Arrays.toString(info.dependencies), checkStatus == null ? "null" : checkStatus.type);
|
||||
|
|
|
@ -57,7 +57,7 @@ public static void main(String[] args) throws Throwable {
|
|||
ConsoleManager.initConsole();
|
||||
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
|
||||
RequestService service;
|
||||
if(offlineMode) {
|
||||
if (offlineMode) {
|
||||
OfflineRequestService offlineRequestService = new OfflineRequestService();
|
||||
LauncherEngine.applyBasicOfflineProcessors(offlineRequestService);
|
||||
OfflineModeEvent event = new OfflineModeEvent(offlineRequestService);
|
||||
|
|
|
@ -18,7 +18,7 @@ public static void checkCertificatesSuccess(X509Certificate[] certs) throws Exce
|
|||
}
|
||||
|
||||
public static String findLibrary(ClassLoader classLoader, String library) {
|
||||
if(classLoader instanceof ClientClassLoader) {
|
||||
if (classLoader instanceof ClientClassLoader) {
|
||||
ClientClassLoader clientClassLoader = (ClientClassLoader) classLoader;
|
||||
return clientClassLoader.findLibrary(library);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package pro.gravit.launcher.utils;
|
||||
|
||||
import pro.gravit.launcher.AsyncDownloader;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.LauncherEngine;
|
||||
import pro.gravit.launcher.LauncherInject;
|
||||
import pro.gravit.launcher.events.request.LauncherRequestEvent;
|
||||
import pro.gravit.launcher.request.update.LauncherRequest;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -13,12 +11,10 @@
|
|||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -30,14 +26,16 @@
|
|||
public class LauncherUpdater {
|
||||
@LauncherInject("launcher.certificatePinning")
|
||||
private static boolean isCertificatePinning;
|
||||
|
||||
public static void nothing() {
|
||||
|
||||
}
|
||||
|
||||
private static Path getLauncherPath() {
|
||||
Path pathToCore = IOHelper.getCodeSource(IOHelper.class);
|
||||
Path pathToApi = IOHelper.getCodeSource(LauncherRequest.class);
|
||||
Path pathToSelf = IOHelper.getCodeSource(LauncherUpdater.class);
|
||||
if(pathToCore.equals(pathToApi) && pathToCore.equals(pathToSelf)) {
|
||||
if (pathToCore.equals(pathToApi) && pathToCore.equals(pathToSelf)) {
|
||||
return pathToCore;
|
||||
} else {
|
||||
throw new SecurityException("Found split-jar launcher");
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package pro.gravit.launcher.utils;
|
||||
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
public final class NativeJVMHalt {
|
||||
public final int haltCode;
|
||||
|
@ -30,7 +27,7 @@ public static void haltA(int code) {
|
|||
exitMethod.invoke(null, code);
|
||||
} catch (Throwable e) {
|
||||
th[1] = e;
|
||||
if(LogHelper.isDevEnabled()) {
|
||||
if (LogHelper.isDevEnabled()) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package pro.gravit.launcher;
|
||||
|
||||
import pro.gravit.launcher.serialize.HInput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class ClientPermissions {
|
||||
|
@ -71,7 +68,7 @@ public void addPerm(String perm) {
|
|||
perms = new ArrayList<>(1);
|
||||
}
|
||||
perms.add(perm);
|
||||
if(available == null) {
|
||||
if (available == null) {
|
||||
available = new ArrayList<>(1);
|
||||
}
|
||||
available.add(new PermissionPattern(perm));
|
||||
|
@ -81,7 +78,7 @@ public void removePerm(String action) {
|
|||
if (perms == null) {
|
||||
return;
|
||||
}
|
||||
if(available == null) {
|
||||
if (available == null) {
|
||||
return;
|
||||
}
|
||||
perms.remove(action);
|
||||
|
@ -110,11 +107,11 @@ public static class PermissionPattern {
|
|||
|
||||
public PermissionPattern(String pattern) {
|
||||
List<String> prepare = new ArrayList<>();
|
||||
for(int i=0;true;) {
|
||||
for (int i = 0; true; ) {
|
||||
int pos = pattern.indexOf("*", i);
|
||||
if(pos >= 0) {
|
||||
if (pos >= 0) {
|
||||
prepare.add(pattern.substring(i, pos));
|
||||
i = pos+1;
|
||||
i = pos + 1;
|
||||
} else {
|
||||
prepare.add(pattern.substring(i));
|
||||
break;
|
||||
|
@ -129,23 +126,23 @@ public int getPriority() {
|
|||
}
|
||||
|
||||
public boolean match(String str) {
|
||||
if(parts.length == 0) {
|
||||
if (parts.length == 0) {
|
||||
return true;
|
||||
}
|
||||
if(parts.length == 1) {
|
||||
if (parts.length == 1) {
|
||||
return parts[0].equals(str);
|
||||
}
|
||||
int offset = 0;
|
||||
if(!str.startsWith(parts[0])) {
|
||||
if (!str.startsWith(parts[0])) {
|
||||
return false;
|
||||
}
|
||||
if(!str.endsWith(parts[parts.length-1])) {
|
||||
if (!str.endsWith(parts[parts.length - 1])) {
|
||||
return false;
|
||||
}
|
||||
for(int i=1;i<parts.length-1;++i) {
|
||||
for (int i = 1; i < parts.length - 1; ++i) {
|
||||
int pos = str.indexOf(parts[i], offset);
|
||||
if(pos >= 0) {
|
||||
offset = pos+1;
|
||||
if (pos >= 0) {
|
||||
offset = pos + 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package pro.gravit.launcher.profiles;
|
||||
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -30,10 +29,10 @@ public PlayerProfile(UUID uuid, String username, Texture skin, Texture cloak, Ma
|
|||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
this.assets = new HashMap<>();
|
||||
if(skin != null) {
|
||||
if (skin != null) {
|
||||
this.assets.put("SKIN", skin);
|
||||
}
|
||||
if(cloak != null) {
|
||||
if (cloak != null) {
|
||||
this.assets.put("CAPE", cloak);
|
||||
}
|
||||
this.properties = properties;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
public class ArchTrigger extends OptionalTrigger {
|
||||
public JVMHelper.ARCH arch;
|
||||
|
||||
@Override
|
||||
protected boolean isTriggered(OptionalFile optional, OptionalTriggerContext context) {
|
||||
return context.getJavaVersion().arch == arch;
|
||||
|
|
|
@ -28,17 +28,17 @@ public abstract class Request<R extends WebSocketEvent> implements WebSocketRequ
|
|||
public final UUID requestUUID = UUID.randomUUID();
|
||||
private transient final AtomicBoolean started = new AtomicBoolean(false);
|
||||
|
||||
public static void setRequestService(RequestService service) {
|
||||
requestService = service;
|
||||
if(service instanceof StdWebSocketService) {
|
||||
Request.service = (StdWebSocketService) service;
|
||||
}
|
||||
}
|
||||
|
||||
public static RequestService getRequestService() {
|
||||
return requestService;
|
||||
}
|
||||
|
||||
public static void setRequestService(RequestService service) {
|
||||
requestService = service;
|
||||
if (service instanceof StdWebSocketService) {
|
||||
Request.service = (StdWebSocketService) service;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAvailable() {
|
||||
return requestService != null;
|
||||
}
|
||||
|
@ -121,22 +121,10 @@ public static RequestRestoreReport reconnect() throws Exception {
|
|||
return restore();
|
||||
}
|
||||
|
||||
public static class RequestRestoreReport {
|
||||
public final boolean legacySession;
|
||||
public final boolean refreshed;
|
||||
public final List<String> invalidExtendedTokens;
|
||||
|
||||
public RequestRestoreReport(boolean legacySession, boolean refreshed, List<String> invalidExtendedTokens) {
|
||||
this.legacySession = legacySession;
|
||||
this.refreshed = refreshed;
|
||||
this.invalidExtendedTokens = invalidExtendedTokens;
|
||||
}
|
||||
}
|
||||
|
||||
public static RequestRestoreReport restore() throws Exception {
|
||||
boolean refreshed = false;
|
||||
RestoreRequest request;
|
||||
if(oauth != null) {
|
||||
if (oauth != null) {
|
||||
if (isTokenExpired() || oauth.accessToken == null) {
|
||||
RefreshTokenRequest refreshRequest = new RefreshTokenRequest(authId, oauth.refreshToken);
|
||||
RefreshTokenRequestEvent event = refreshRequest.request();
|
||||
|
@ -197,7 +185,7 @@ public void removeOAuthChangeHandler(BiConsumer<String, AuthRequestEvent.OAuthRe
|
|||
public R request() throws Exception {
|
||||
if (!started.compareAndSet(false, true))
|
||||
throw new IllegalStateException("Request already started");
|
||||
if(!isAvailable()) {
|
||||
if (!isAvailable()) {
|
||||
throw new RequestException("RequestService not initialized");
|
||||
}
|
||||
return requestDo(requestService);
|
||||
|
@ -224,4 +212,16 @@ public interface ExtendedTokenCallback {
|
|||
String tryGetNewToken(String name);
|
||||
}
|
||||
|
||||
public static class RequestRestoreReport {
|
||||
public final boolean legacySession;
|
||||
public final boolean refreshed;
|
||||
public final List<String> invalidExtendedTokens;
|
||||
|
||||
public RequestRestoreReport(boolean legacySession, boolean refreshed, List<String> invalidExtendedTokens) {
|
||||
this.legacySession = legacySession;
|
||||
this.refreshed = refreshed;
|
||||
this.invalidExtendedTokens = invalidExtendedTokens;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,12 @@
|
|||
|
||||
public interface RequestService {
|
||||
<T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException;
|
||||
|
||||
void registerEventHandler(EventHandler handler);
|
||||
|
||||
void unregisterEventHandler(EventHandler handler);
|
||||
default <T extends WebSocketEvent> T requestSync(Request<T> request) throws IOException {
|
||||
|
||||
default <T extends WebSocketEvent> T requestSync(Request<T> request) throws IOException {
|
||||
try {
|
||||
return request(request).get();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -5,21 +5,13 @@
|
|||
import pro.gravit.launcher.events.request.LauncherRequestEvent;
|
||||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.RequestService;
|
||||
import pro.gravit.launcher.request.websockets.StdWebSocketService;
|
||||
import pro.gravit.launcher.request.websockets.WebSocketRequest;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class LauncherRequest extends Request<LauncherRequestEvent> implements WebSocketRequest {
|
||||
public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.websockets.WebSocketRequest;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
|
||||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.websockets.WebSocketRequest;
|
||||
import pro.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
public final class ProfileByUsernameRequest extends Request<ProfileByUsernameRequestEvent> implements WebSocketRequest {
|
||||
@LauncherNetworkAPI
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
@ -112,10 +111,10 @@ public void openAsync(Runnable onConnect, Consumer<Throwable> onFail) {
|
|||
uri, WebSocketVersion.V13, null, false, EmptyHttpHeaders.INSTANCE, 12800000), this);
|
||||
ChannelFuture future = bootstrap.connect(uri.getHost(), port);
|
||||
future.addListener((l) -> {
|
||||
if(l.isSuccess()) {
|
||||
if (l.isSuccess()) {
|
||||
ch = future.channel();
|
||||
webSocketClientHandler.handshakeFuture().addListener((e) -> {
|
||||
if(e.isSuccess()) {
|
||||
if (e.isSuccess()) {
|
||||
onConnect.run();
|
||||
} else {
|
||||
onFail.accept(webSocketClientHandler.handshakeFuture().cause());
|
||||
|
|
|
@ -82,7 +82,7 @@ public void registerRequests() {
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void registerResults() {
|
||||
if(!resultsRegistered) {
|
||||
if (!resultsRegistered) {
|
||||
results.register("auth", AuthRequestEvent.class);
|
||||
results.register("checkServer", CheckServerRequestEvent.class);
|
||||
results.register("joinServer", JoinServerRequestEvent.class);
|
||||
|
|
|
@ -16,26 +16,27 @@
|
|||
public class OfflineRequestService implements RequestService {
|
||||
private final HashSet<EventHandler> eventHandlers = new HashSet<>();
|
||||
private final Map<Class<?>, RequestProcessor<?, ?>> processors = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException {
|
||||
RequestProcessor<T, Request<T>> processor = (RequestProcessor<T, Request<T>>) processors.get(request.getClass());
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
if(processor == null) {
|
||||
if (processor == null) {
|
||||
future.completeExceptionally(new RequestException(String.format("Offline mode not support '%s'", request.getType())));
|
||||
return future;
|
||||
}
|
||||
if(LogHelper.isDevEnabled()) {
|
||||
if (LogHelper.isDevEnabled()) {
|
||||
LogHelper.dev("Request %s: %s", request.getType(), Launcher.gsonManager.gson.toJson(request));
|
||||
}
|
||||
try {
|
||||
T event = processor.process(request);
|
||||
if(LogHelper.isDevEnabled()) {
|
||||
if (LogHelper.isDevEnabled()) {
|
||||
LogHelper.dev("Response %s: %s", event.getType(), Launcher.gsonManager.gson.toJson(event));
|
||||
}
|
||||
future.complete(event);
|
||||
} catch (Throwable e) {
|
||||
if(e instanceof RequestException) {
|
||||
if (e instanceof RequestException) {
|
||||
future.completeExceptionally(e);
|
||||
} else {
|
||||
future.completeExceptionally(new RequestException(e));
|
||||
|
@ -59,11 +60,11 @@ public boolean isClosed() {
|
|||
return false;
|
||||
}
|
||||
|
||||
public<T extends WebSocketEvent, V extends WebSocketRequest> void registerRequestProcessor(Class<V> requestClazz, RequestProcessor<T, V> function) {
|
||||
public <T extends WebSocketEvent, V extends WebSocketRequest> void registerRequestProcessor(Class<V> requestClazz, RequestProcessor<T, V> function) {
|
||||
processors.put(requestClazz, function);
|
||||
}
|
||||
|
||||
public<T extends WebSocketEvent> void unregisterRequestProcessor(Class<Request<T>> requestClazz) {
|
||||
public <T extends WebSocketEvent> void unregisterRequestProcessor(Class<Request<T>> requestClazz) {
|
||||
processors.remove(requestClazz);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ public static CompletableFuture<StdWebSocketService> initWebSockets(String addre
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Deprecated
|
||||
public void registerEventHandler(ClientWebSocketService.EventHandler handler) {
|
||||
legacyEventHandlers.add(handler);
|
||||
|
|
|
@ -59,6 +59,7 @@ public static SSLContext makeSSLContext() throws NoSuchAlgorithmException, Certi
|
|||
public void downloadFile(URL url, Path target, long size) throws IOException {
|
||||
if (isClosed) throw new IOException("Download interrupted");
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.addRequestProperty("User-Agent", IOHelper.USER_AGENT);
|
||||
if (isCertificatePinning) {
|
||||
HttpsURLConnection connection1 = (HttpsURLConnection) connection;
|
||||
try {
|
||||
|
@ -74,6 +75,7 @@ public void downloadFile(URL url, Path target, long size) throws IOException {
|
|||
|
||||
public void downloadFile(URL url, Path target) throws IOException {
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.addRequestProperty("User-Agent", IOHelper.USER_AGENT);
|
||||
if (isCertificatePinning) {
|
||||
HttpsURLConnection connection1 = (HttpsURLConnection) connection;
|
||||
try {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -27,7 +28,7 @@ public static JsonElement jsonRequest(JsonElement request, String method, URL ur
|
|||
if (request != null) connection.setDoOutput(true);
|
||||
connection.setRequestMethod(method);
|
||||
if (request != null) connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||
if (request != null) connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36");
|
||||
if (request != null) connection.setRequestProperty("User-Agent", IOHelper.USER_AGENT);
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
if (TIMEOUT > 0)
|
||||
connection.setConnectTimeout(TIMEOUT);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
public class Downloader {
|
||||
private final CompletableFuture<Void> future;
|
||||
private final AsyncDownloader asyncDownloader;
|
||||
|
||||
private Downloader(CompletableFuture<Void> future, AsyncDownloader downloader) {
|
||||
this.future = future;
|
||||
this.asyncDownloader = downloader;
|
||||
|
|
|
@ -77,7 +77,7 @@ public void complete(LineReader reader, ParsedLine line, List<Candidate> candida
|
|||
});
|
||||
} else {
|
||||
Command target = findCommand(line.words().get(0));
|
||||
if(target == null) {
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
List<String> words = line.words();
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
import pro.gravit.utils.command.CommandException;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package pro.gravit.utils.helper;
|
||||
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
@ -39,11 +41,12 @@ public final class IOHelper {
|
|||
public static final FileSystem FS = FileSystems.getDefault();
|
||||
// Platform-dependent
|
||||
public static final String PLATFORM_SEPARATOR = FS.getSeparator();
|
||||
private static final Pattern PLATFORM_SEPARATOR_PATTERN = Pattern.compile(PLATFORM_SEPARATOR, Pattern.LITERAL);
|
||||
public static final boolean POSIX = FS.supportedFileAttributeViews().contains("posix") || FS.supportedFileAttributeViews().contains("Posix");
|
||||
public static final Path JVM_DIR = Paths.get(System.getProperty("java.home"));
|
||||
public static final Path HOME_DIR = Paths.get(System.getProperty("user.home"));
|
||||
public static final Path WORKING_DIR = Paths.get(System.getProperty("user.dir"));
|
||||
public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
|
||||
public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", String.format("GravitLauncher/%s", Version.getVersion()));
|
||||
// Open options - as arrays
|
||||
private static final OpenOption[] READ_OPTIONS = {StandardOpenOption.READ};
|
||||
private static final OpenOption[] WRITE_OPTIONS = {StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING};
|
||||
|
@ -54,7 +57,6 @@ public final class IOHelper {
|
|||
private static final Set<FileVisitOption> WALK_OPTIONS = Collections.singleton(FileVisitOption.FOLLOW_LINKS);
|
||||
// Other constants
|
||||
private static final Pattern CROSS_SEPARATOR_PATTERN = Pattern.compile(CROSS_SEPARATOR, Pattern.LITERAL);
|
||||
private static final Pattern PLATFORM_SEPARATOR_PATTERN = Pattern.compile(PLATFORM_SEPARATOR, Pattern.LITERAL);
|
||||
|
||||
private IOHelper() {
|
||||
}
|
||||
|
@ -221,6 +223,7 @@ public static URLConnection newConnection(URL url) throws IOException {
|
|||
connection.setReadTimeout(HTTP_TIMEOUT);
|
||||
connection.setConnectTimeout(HTTP_TIMEOUT);
|
||||
connection.addRequestProperty("User-Agent", USER_AGENT); // Fix for stupid servers
|
||||
connection.setConnectTimeout(10000);
|
||||
} else
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoInput(true);
|
||||
|
@ -232,6 +235,8 @@ public static HttpURLConnection newConnectionPost(URL url) throws IOException {
|
|||
HttpURLConnection connection = (HttpURLConnection) newConnection(url);
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("User-Agent", IOHelper.USER_AGENT);
|
||||
connection.setConnectTimeout(10000);
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,10 @@ public final class JVMHelper {
|
|||
public static final OperatingSystemMXBean OPERATING_SYSTEM_MXBEAN =
|
||||
ManagementFactory.getOperatingSystemMXBean();
|
||||
public static final OS OS_TYPE = OS.byName(OPERATING_SYSTEM_MXBEAN.getName());
|
||||
// System properties
|
||||
public static final String OS_VERSION = OPERATING_SYSTEM_MXBEAN.getVersion();
|
||||
|
||||
@Deprecated
|
||||
public static final int OS_BITS = getCorrectOSArch();
|
||||
|
||||
// System properties
|
||||
public static final String OS_VERSION = OPERATING_SYSTEM_MXBEAN.getVersion();
|
||||
public static final ARCH ARCH_TYPE = getArch(System.getProperty("os.arch"));
|
||||
public static final int JVM_BITS = Integer.parseInt(System.getProperty("sun.arch.data.model"));
|
||||
public static final SecurityManager SECURITY_MANAGER = System.getSecurityManager();
|
||||
|
@ -46,21 +44,11 @@ public final class JVMHelper {
|
|||
private JVMHelper() {
|
||||
}
|
||||
|
||||
public enum ARCH {
|
||||
X86("x86"), X86_64("x86-64"), ARM64("arm64"), ARM32("arm32");
|
||||
|
||||
public final String name;
|
||||
|
||||
ARCH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static ARCH getArch(String arch) {
|
||||
if(arch.equals("amd64") || arch.equals("x86-64") || arch.equals("x86_64")) return ARCH.X86_64;
|
||||
if(arch.equals("i386") || arch.equals("i686") || arch.equals("x86")) return ARCH.X86;
|
||||
if(arch.startsWith("armv8") || arch.startsWith("aarch64")) return ARCH.ARM64;
|
||||
if(arch.startsWith("arm") || arch.startsWith("aarch32")) return ARCH.ARM32;
|
||||
if (arch.equals("amd64") || arch.equals("x86-64") || arch.equals("x86_64")) return ARCH.X86_64;
|
||||
if (arch.equals("i386") || arch.equals("i686") || arch.equals("x86")) return ARCH.X86;
|
||||
if (arch.startsWith("armv8") || arch.startsWith("aarch64")) return ARCH.ARM64;
|
||||
if (arch.startsWith("arm") || arch.startsWith("aarch32")) return ARCH.ARM32;
|
||||
throw new InternalError(String.format("Unsupported arch '%s'", arch));
|
||||
}
|
||||
|
||||
|
@ -110,19 +98,16 @@ public static Class<?> firstClass(String... names) throws ClassNotFoundException
|
|||
throw new ClassNotFoundException(Arrays.toString(names));
|
||||
}
|
||||
|
||||
|
||||
public static void fullGC() {
|
||||
RUNTIME.gc();
|
||||
RUNTIME.runFinalization();
|
||||
LogHelper.debug("Used heap: %d MiB", RUNTIME.totalMemory() - RUNTIME.freeMemory() >> 20);
|
||||
}
|
||||
|
||||
|
||||
public static String[] getClassPath() {
|
||||
return System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
}
|
||||
|
||||
|
||||
public static URL[] getClassPathURL() {
|
||||
String[] cp = System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
URL[] list = new URL[cp.length];
|
||||
|
@ -164,35 +149,29 @@ private static int getCorrectOSArch() {
|
|||
return System.getProperty("os.arch").contains("64") ? 64 : 32;
|
||||
}
|
||||
|
||||
|
||||
public static String getEnvPropertyCaseSensitive(String name) {
|
||||
return System.getenv().get(name);
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static boolean isJVMMatchesSystemArch() {
|
||||
return JVM_BITS == OS_BITS;
|
||||
}
|
||||
|
||||
|
||||
public static String jvmProperty(String name, String value) {
|
||||
return String.format("-D%s=%s", name, value);
|
||||
}
|
||||
|
||||
|
||||
public static String systemToJvmProperty(String name) {
|
||||
return String.format("-D%s=%s", name, System.getProperties().getProperty(name));
|
||||
}
|
||||
|
||||
|
||||
public static void addSystemPropertyToArgs(Collection<String> args, String name) {
|
||||
String property = System.getProperty(name);
|
||||
if (property != null)
|
||||
args.add(String.format("-D%s=%s", name, property));
|
||||
}
|
||||
|
||||
|
||||
public static void verifySystemProperties(Class<?> mainClass, boolean requireSystem) {
|
||||
Locale.setDefault(Locale.US);
|
||||
// Verify class loader
|
||||
|
@ -204,6 +183,17 @@ public static void verifySystemProperties(Class<?> mainClass, boolean requireSys
|
|||
LogHelper.debug("Verifying JVM architecture");
|
||||
}
|
||||
|
||||
|
||||
public enum ARCH {
|
||||
X86("x86"), X86_64("x86-64"), ARM64("arm64"), ARM32("arm32");
|
||||
|
||||
public final String name;
|
||||
|
||||
ARCH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public enum OS {
|
||||
MUSTDIE("mustdie"), LINUX("linux"), MACOSX("macosx");
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
public class JavaHelper {
|
||||
private static List<JavaVersion> javaVersionsCache;
|
||||
|
||||
public static Path tryGetOpenJFXPath(Path jvmDir) {
|
||||
String dirName = jvmDir.getFileName().toString();
|
||||
Path parent = jvmDir.getParent();
|
||||
|
@ -57,7 +58,7 @@ public static boolean tryAddModule(List<Path> paths, String moduleName, StringBu
|
|||
}
|
||||
|
||||
public synchronized static List<JavaVersion> findJava() {
|
||||
if(javaVersionsCache != null) {
|
||||
if (javaVersionsCache != null) {
|
||||
return javaVersionsCache;
|
||||
}
|
||||
List<String> javaPaths = new ArrayList<>(4);
|
||||
|
@ -106,11 +107,11 @@ public synchronized static List<JavaVersion> findJava() {
|
|||
}
|
||||
|
||||
private static JavaVersion tryFindJavaByPath(Path path) {
|
||||
if(javaVersionsCache == null) {
|
||||
if (javaVersionsCache == null) {
|
||||
return null;
|
||||
}
|
||||
for(JavaVersion version : javaVersionsCache) {
|
||||
if(version.jvmDir.equals(path)) {
|
||||
for (JavaVersion version : javaVersionsCache) {
|
||||
if (version.jvmDir.equals(path)) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
@ -156,8 +157,8 @@ public static JavaVersionAndBuild getJavaVersion(String version) {
|
|||
result.build = Integer.parseInt(version.substring(dot + 1));
|
||||
} else {
|
||||
try {
|
||||
if(version.endsWith("-ea")) {
|
||||
version = version.substring(0, version.length()-3);
|
||||
if (version.endsWith("-ea")) {
|
||||
version = version.substring(0, version.length() - 3);
|
||||
}
|
||||
result.version = Integer.parseInt(version);
|
||||
result.build = 0;
|
||||
|
@ -232,7 +233,7 @@ private static boolean isCurrentJavaSupportJavaFX() {
|
|||
public static JavaVersion getByPath(Path jvmDir) throws IOException {
|
||||
{
|
||||
JavaVersion version = JavaHelper.tryFindJavaByPath(jvmDir);
|
||||
if(version != null) {
|
||||
if (version != null) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public static JsonElement jsonRequest(JsonElement request, String method, URL ur
|
|||
.uri(url.toURI())
|
||||
.header("Content-Type", "application/json; charset=UTF-8")
|
||||
.header("Accept", "application/json")
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36")
|
||||
.header("User-Agent", IOHelper.USER_AGENT)
|
||||
.timeout(Duration.ofMillis(TIMEOUT))
|
||||
.build();
|
||||
HttpResponse<InputStream> response = client.send(request1, HttpResponse.BodyHandlers.ofInputStream());
|
||||
|
|
|
@ -30,6 +30,7 @@ public class Downloader {
|
|||
protected final ExecutorService executor;
|
||||
protected final LinkedList<DownloadTask> tasks = new LinkedList<>();
|
||||
protected CompletableFuture<Void> future;
|
||||
|
||||
protected Downloader(HttpClient client, ExecutorService executor) {
|
||||
this.client = client;
|
||||
this.executor = executor;
|
||||
|
@ -149,7 +150,7 @@ protected HttpRequest makeHttpRequest(URI baseUri, String filePath) throws URISy
|
|||
return HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(new URI(scheme, host, path + filePath, "", ""))
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36")
|
||||
.header("User-Agent", IOHelper.USER_AGENT)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,10 @@ public final class JVMHelper {
|
|||
public static final OperatingSystemMXBean OPERATING_SYSTEM_MXBEAN =
|
||||
ManagementFactory.getOperatingSystemMXBean();
|
||||
public static final OS OS_TYPE = OS.byName(OPERATING_SYSTEM_MXBEAN.getName());
|
||||
// System properties
|
||||
public static final String OS_VERSION = OPERATING_SYSTEM_MXBEAN.getVersion();
|
||||
|
||||
@Deprecated
|
||||
public static final int OS_BITS = getCorrectOSArch();
|
||||
|
||||
// System properties
|
||||
public static final String OS_VERSION = OPERATING_SYSTEM_MXBEAN.getVersion();
|
||||
public static final ARCH ARCH_TYPE = getArch(System.getProperty("os.arch"));
|
||||
|
||||
public static final int JVM_BITS = Integer.parseInt(System.getProperty("sun.arch.data.model"));
|
||||
|
@ -46,21 +44,11 @@ public final class JVMHelper {
|
|||
private JVMHelper() {
|
||||
}
|
||||
|
||||
public enum ARCH {
|
||||
X86("x86"), X86_64("x86-64"), ARM64("arm64"), ARM32("arm32");
|
||||
|
||||
public final String name;
|
||||
|
||||
ARCH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static ARCH getArch(String arch) {
|
||||
if(arch.equals("amd64") || arch.equals("x86-64") || arch.equals("x86_64")) return ARCH.X86_64;
|
||||
if(arch.equals("i386") || arch.equals("i686") || arch.equals("x86")) return ARCH.X86;
|
||||
if(arch.startsWith("armv8") || arch.startsWith("aarch64")) return ARCH.ARM64;
|
||||
if(arch.startsWith("arm") || arch.startsWith("aarch32")) return ARCH.ARM32;
|
||||
if (arch.equals("amd64") || arch.equals("x86-64") || arch.equals("x86_64")) return ARCH.X86_64;
|
||||
if (arch.equals("i386") || arch.equals("i686") || arch.equals("x86")) return ARCH.X86;
|
||||
if (arch.startsWith("armv8") || arch.startsWith("aarch64")) return ARCH.ARM64;
|
||||
if (arch.startsWith("arm") || arch.startsWith("aarch32")) return ARCH.ARM32;
|
||||
throw new InternalError(String.format("Unsupported arch '%s'", arch));
|
||||
}
|
||||
|
||||
|
@ -87,19 +75,16 @@ public static Class<?> firstClass(String... names) throws ClassNotFoundException
|
|||
throw new ClassNotFoundException(Arrays.toString(names));
|
||||
}
|
||||
|
||||
|
||||
public static void fullGC() {
|
||||
RUNTIME.gc();
|
||||
RUNTIME.runFinalization();
|
||||
LogHelper.debug("Used heap: %d MiB", RUNTIME.totalMemory() - RUNTIME.freeMemory() >> 20);
|
||||
}
|
||||
|
||||
|
||||
public static String[] getClassPath() {
|
||||
return System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
}
|
||||
|
||||
|
||||
public static URL[] getClassPathURL() {
|
||||
String[] cp = System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
URL[] list = new URL[cp.length];
|
||||
|
@ -141,35 +126,29 @@ private static int getCorrectOSArch() {
|
|||
return System.getProperty("os.arch").contains("64") ? 64 : 32;
|
||||
}
|
||||
|
||||
|
||||
public static String getEnvPropertyCaseSensitive(String name) {
|
||||
return System.getenv().get(name);
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static boolean isJVMMatchesSystemArch() {
|
||||
return JVM_BITS == OS_BITS;
|
||||
}
|
||||
|
||||
|
||||
public static String jvmProperty(String name, String value) {
|
||||
return String.format("-D%s=%s", name, value);
|
||||
}
|
||||
|
||||
|
||||
public static String systemToJvmProperty(String name) {
|
||||
return String.format("-D%s=%s", name, System.getProperties().getProperty(name));
|
||||
}
|
||||
|
||||
|
||||
public static void addSystemPropertyToArgs(Collection<String> args, String name) {
|
||||
String property = System.getProperty(name);
|
||||
if (property != null)
|
||||
args.add(String.format("-D%s=%s", name, property));
|
||||
}
|
||||
|
||||
|
||||
public static void verifySystemProperties(Class<?> mainClass, boolean requireSystem) {
|
||||
Locale.setDefault(Locale.US);
|
||||
// Verify class loader
|
||||
|
@ -181,6 +160,17 @@ public static void verifySystemProperties(Class<?> mainClass, boolean requireSys
|
|||
LogHelper.debug("Verifying JVM architecture");
|
||||
}
|
||||
|
||||
|
||||
public enum ARCH {
|
||||
X86("x86"), X86_64("x86-64"), ARM64("arm64"), ARM32("arm32");
|
||||
|
||||
public final String name;
|
||||
|
||||
ARCH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public enum OS {
|
||||
MUSTDIE("mustdie"), LINUX("linux"), MACOSX("macosx");
|
||||
|
||||
|
|
|
@ -30,7 +30,10 @@
|
|||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
|
||||
public static final Path configFile = Paths.get(System.getProperty("serverwrapper.configFile", "ServerWrapperConfig.json"));
|
||||
|
@ -61,10 +64,10 @@ public static void main(String... args) throws Throwable {
|
|||
}
|
||||
|
||||
public void restore() throws Exception {
|
||||
if(config.oauth != null) {
|
||||
if (config.oauth != null) {
|
||||
Request.setOAuth(config.authId, config.oauth, config.oauthExpireTime);
|
||||
}
|
||||
if(config.extendedTokens != null) {
|
||||
if (config.extendedTokens != null) {
|
||||
Request.addAllExtendedToken(config.extendedTokens);
|
||||
}
|
||||
Request.restore();
|
||||
|
@ -111,7 +114,7 @@ public void run(String... args) throws Throwable {
|
|||
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||
loadConfig();
|
||||
InstallAuthlib command = new InstallAuthlib();
|
||||
command. run(args[1]);
|
||||
command.run(args[1]);
|
||||
System.exit(0);
|
||||
}
|
||||
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||
|
@ -136,7 +139,7 @@ public void run(String... args) throws Throwable {
|
|||
restore();
|
||||
getProfiles();
|
||||
}
|
||||
if(config.encodedServerRsaPublicKey != null) {
|
||||
if (config.encodedServerRsaPublicKey != null) {
|
||||
KeyService.serverRsaPublicKey = SecurityHelper.toPublicRSAKey(config.encodedServerRsaPublicKey);
|
||||
}
|
||||
String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass;
|
||||
|
@ -144,7 +147,7 @@ public void run(String... args) throws Throwable {
|
|||
LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument");
|
||||
System.exit(-1);
|
||||
}
|
||||
if(config.oauth == null && ( config.extendedTokens == null || config.extendedTokens.isEmpty())) {
|
||||
if (config.oauth == null && (config.extendedTokens == null || config.extendedTokens.isEmpty())) {
|
||||
LogHelper.error("Auth not configured. Please use 'java -jar ServerWrapper.jar setup'");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
@ -161,7 +164,7 @@ public void run(String... args) throws Throwable {
|
|||
LogHelper.info("ServerWrapper: LaunchServer address: %s. Title: %s", config.address, Launcher.profile != null ? Launcher.profile.getTitle() : "unknown");
|
||||
LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().name);
|
||||
String[] real_args;
|
||||
if(config.args != null && config.args.size() > 0) {
|
||||
if (config.args != null && config.args.size() > 0) {
|
||||
real_args = config.args.toArray(new String[0]);
|
||||
} else if (args.length > 0) {
|
||||
real_args = new String[args.length - 1];
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import pro.gravit.launcher.managers.GsonManager;
|
||||
import pro.gravit.launcher.modules.events.PreGsonPhase;
|
||||
import pro.gravit.launcher.request.websockets.ClientWebSocketService;
|
||||
|
||||
public class ServerWrapperGsonManager extends GsonManager {
|
||||
|
|
|
@ -7,17 +7,16 @@
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class DownloadContextModifier implements LibrariesHashFileModifier {
|
||||
@Override
|
||||
public byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) throws IOException {
|
||||
String[] lines = new String(data).split("\n");
|
||||
for(int i=0;i<lines.length;++i) {
|
||||
if(lines[i].contains("mojang_")) {
|
||||
for (int i = 0; i < lines.length; ++i) {
|
||||
if (lines[i].contains("mojang_")) {
|
||||
String[] separated = lines[i].split("\t");
|
||||
Path path = context.workdir.resolve("cache").resolve(separated[2]);
|
||||
if(Files.notExists(path)) {
|
||||
if (Files.notExists(path)) {
|
||||
LogHelper.warning("Unable to find %s. Maybe you should start the server at least once?", path);
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -15,19 +15,21 @@
|
|||
|
||||
public class InstallAuthlib {
|
||||
private static Map<String, LibrariesHashFileModifier> modifierMap;
|
||||
|
||||
static {
|
||||
modifierMap = new HashMap<>();
|
||||
modifierMap.put("META-INF/libraries.list", new LibrariesLstModifier());
|
||||
modifierMap.put("patch.properties", new PatchPropertiesModifier());
|
||||
modifierMap.put("META-INF/download-context", new DownloadContextModifier());
|
||||
}
|
||||
|
||||
public void run(String... args) throws Exception {
|
||||
boolean deleteAuthlibAfterInstall = false;
|
||||
InstallAuthlibContext context = new InstallAuthlibContext();
|
||||
if(args[0].startsWith("http://") || args[0].startsWith("https://")) {
|
||||
if (args[0].startsWith("http://") || args[0].startsWith("https://")) {
|
||||
Path tempAuthlib = Paths.get("authlib.jar");
|
||||
LogHelper.info("Download %s to %s", args[0], tempAuthlib);
|
||||
try(InputStream input = IOHelper.newInput(new URL(args[0]))) {
|
||||
try (InputStream input = IOHelper.newInput(new URL(args[0]))) {
|
||||
IOHelper.transfer(input, tempAuthlib);
|
||||
}
|
||||
context.pathToAuthlib = tempAuthlib;
|
||||
|
@ -35,7 +37,7 @@ public void run(String... args) throws Exception {
|
|||
} else {
|
||||
context.pathToAuthlib = Paths.get(args[0]);
|
||||
}
|
||||
if(Files.notExists(context.pathToAuthlib)) {
|
||||
if (Files.notExists(context.pathToAuthlib)) {
|
||||
throw new FileNotFoundException(context.pathToAuthlib.toString());
|
||||
}
|
||||
context.workdir = IOHelper.WORKING_DIR;
|
||||
|
@ -43,26 +45,26 @@ public void run(String... args) throws Exception {
|
|||
IOHelper.walk(context.workdir, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if(file.getFileName().toString().endsWith(".jar")) {
|
||||
if (file.getFileName().toString().endsWith(".jar")) {
|
||||
context.files.add(file);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}, true);
|
||||
LogHelper.info("Search authlib in %d files", context.files.size());
|
||||
for(Path path : context.files) {
|
||||
for (Path path : context.files) {
|
||||
boolean foundAuthlib = false;
|
||||
try(ZipInputStream input = IOHelper.newZipInput(path)) {
|
||||
try (ZipInputStream input = IOHelper.newZipInput(path)) {
|
||||
ZipEntry e = input.getNextEntry();
|
||||
while(e != null) {
|
||||
while (e != null) {
|
||||
String name = e.getName();
|
||||
if(!e.isDirectory() && name.contains("com/mojang/authlib") && !foundAuthlib) {
|
||||
if (!e.isDirectory() && name.contains("com/mojang/authlib") && !foundAuthlib) {
|
||||
boolean isJarFile = name.endsWith(".jar");
|
||||
String prefix = isJarFile ? name : name.substring(0, name.indexOf("com/mojang/authlib"));
|
||||
context.repack.add(new RepackInfo(path, prefix, isJarFile));
|
||||
foundAuthlib = true;
|
||||
}
|
||||
if(!e.isDirectory() && modifierMap.containsKey(name)) {
|
||||
if (!e.isDirectory() && modifierMap.containsKey(name)) {
|
||||
context.hashes.add(new HashFile(path, name, modifierMap.get(name)));
|
||||
}
|
||||
e = input.getNextEntry();
|
||||
|
@ -70,14 +72,14 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
}
|
||||
}
|
||||
Path tmpFile = Paths.get("repack.tmp");
|
||||
for(RepackInfo ri : context.repack) {
|
||||
for (RepackInfo ri : context.repack) {
|
||||
LogHelper.info("Found authlib in %s (prefix '%s' jar %s)", ri.path, ri.prefix, ri.isJarFile ? "true" : "false");
|
||||
try(ZipInputStream input = IOHelper.newZipInput(ri.path)) {
|
||||
try(ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(tmpFile))) {
|
||||
try (ZipInputStream input = IOHelper.newZipInput(ri.path)) {
|
||||
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(tmpFile))) {
|
||||
ZipEntry e;
|
||||
e = input.getNextEntry();
|
||||
while(e != null) {
|
||||
if(!e.getName().equals("META-INF") && !e.getName().equals("META-INF/") && !e.getName().equals("META-INF/MANIFEST.MF")) {
|
||||
while (e != null) {
|
||||
if (!e.getName().equals("META-INF") && !e.getName().equals("META-INF/") && !e.getName().equals("META-INF/MANIFEST.MF")) {
|
||||
break;
|
||||
}
|
||||
ZipEntry newEntry = IOHelper.newZipEntry(e);
|
||||
|
@ -85,11 +87,11 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
IOHelper.transfer(input, output);
|
||||
e = input.getNextEntry();
|
||||
}
|
||||
if(!ri.isJarFile) {
|
||||
try(ZipInputStream input2 = new ZipInputStream(IOHelper.newInput(context.pathToAuthlib))) {
|
||||
if (!ri.isJarFile) {
|
||||
try (ZipInputStream input2 = new ZipInputStream(IOHelper.newInput(context.pathToAuthlib))) {
|
||||
ZipEntry e2 = input2.getNextEntry();
|
||||
while(e2 != null) {
|
||||
if(e2.getName().startsWith("META-INF")) {
|
||||
while (e2 != null) {
|
||||
if (e2.getName().startsWith("META-INF")) {
|
||||
e2 = input2.getNextEntry();
|
||||
continue;
|
||||
}
|
||||
|
@ -102,10 +104,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
}
|
||||
}
|
||||
}
|
||||
while(e != null) {
|
||||
if(e.getName().startsWith(ri.prefix)) {
|
||||
if(ri.isJarFile) {
|
||||
if(context.repackedAuthlibBytes == null) {
|
||||
while (e != null) {
|
||||
if (e.getName().startsWith(ri.prefix)) {
|
||||
if (ri.isJarFile) {
|
||||
if (context.repackedAuthlibBytes == null) {
|
||||
byte[] orig = IOHelper.read(input);
|
||||
context.repackedAuthlibBytes = repackAuthlibJar(orig, context.pathToAuthlib);
|
||||
}
|
||||
|
@ -115,10 +117,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
e = input.getNextEntry();
|
||||
continue;
|
||||
} else {
|
||||
if(context.repackedAuthlibFiles == null) {
|
||||
if (context.repackedAuthlibFiles == null) {
|
||||
context.repackedAuthlibFiles = getNames(context.pathToAuthlib);
|
||||
}
|
||||
if(context.repackedAuthlibFiles.contains(e.getName().substring(ri.prefix.length()))) {
|
||||
if (context.repackedAuthlibFiles.contains(e.getName().substring(ri.prefix.length()))) {
|
||||
e = input.getNextEntry();
|
||||
continue;
|
||||
}
|
||||
|
@ -135,15 +137,15 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
Files.move(tmpFile, ri.path);
|
||||
}
|
||||
LogHelper.info("%d authlib files repacked", context.repack.size());
|
||||
for(HashFile hf : context.hashes) {
|
||||
for (HashFile hf : context.hashes) {
|
||||
LogHelper.info("Found hash file %s in %s", hf.prefix, hf.path);
|
||||
try(ZipInputStream input = IOHelper.newZipInput(hf.path)) {
|
||||
try (ZipInputStream input = IOHelper.newZipInput(hf.path)) {
|
||||
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(tmpFile))) {
|
||||
ZipEntry e = input.getNextEntry();
|
||||
while(e != null) {
|
||||
while (e != null) {
|
||||
ZipEntry newEntry = IOHelper.newZipEntry(e);
|
||||
output.putNextEntry(newEntry);
|
||||
if(e.getName().equals(hf.prefix)) {
|
||||
if (e.getName().equals(hf.prefix)) {
|
||||
byte[] orig = IOHelper.read(input);
|
||||
byte[] bytes = hf.modifier.apply(orig, context);
|
||||
output.write(bytes);
|
||||
|
@ -158,7 +160,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
Files.move(tmpFile, hf.path);
|
||||
}
|
||||
LogHelper.info("%d hash files repacked", context.hashes.size());
|
||||
if(deleteAuthlibAfterInstall) {
|
||||
if (deleteAuthlibAfterInstall) {
|
||||
LogHelper.info("Delete %s", context.pathToAuthlib);
|
||||
Files.delete(context.pathToAuthlib);
|
||||
}
|
||||
|
@ -167,10 +169,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
|
||||
private Set<String> getNames(Path path) throws IOException {
|
||||
Set<String> set = new HashSet<>();
|
||||
try(ZipInputStream input = IOHelper.newZipInput(path)) {
|
||||
try (ZipInputStream input = IOHelper.newZipInput(path)) {
|
||||
ZipEntry e = input.getNextEntry();
|
||||
while(e != null) {
|
||||
if(!e.getName().startsWith("META-INF")) {
|
||||
while (e != null) {
|
||||
if (!e.getName().startsWith("META-INF")) {
|
||||
set.add(e.getName());
|
||||
}
|
||||
e = input.getNextEntry();
|
||||
|
@ -180,14 +182,14 @@ private Set<String> getNames(Path path) throws IOException {
|
|||
}
|
||||
|
||||
private byte[] repackAuthlibJar(byte[] data, Path path) throws IOException {
|
||||
try(ZipInputStream input = new ZipInputStream(new ByteArrayInputStream(data))) {
|
||||
try (ZipInputStream input = new ZipInputStream(new ByteArrayInputStream(data))) {
|
||||
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||
try(ZipOutputStream output = new ZipOutputStream(result)) {
|
||||
try (ZipOutputStream output = new ZipOutputStream(result)) {
|
||||
Set<String> blacklist = new HashSet<>();
|
||||
try(ZipInputStream input2 = IOHelper.newZipInput(path)) {
|
||||
try (ZipInputStream input2 = IOHelper.newZipInput(path)) {
|
||||
ZipEntry e = input2.getNextEntry();
|
||||
while(e != null) {
|
||||
if(e.getName().startsWith("META-INF")) {
|
||||
while (e != null) {
|
||||
if (e.getName().startsWith("META-INF")) {
|
||||
e = input2.getNextEntry();
|
||||
continue;
|
||||
}
|
||||
|
@ -199,8 +201,8 @@ private byte[] repackAuthlibJar(byte[] data, Path path) throws IOException {
|
|||
}
|
||||
}
|
||||
ZipEntry e = input.getNextEntry();
|
||||
while(e != null) {
|
||||
if(blacklist.contains(e.getName())) {
|
||||
while (e != null) {
|
||||
if (blacklist.contains(e.getName())) {
|
||||
e = input.getNextEntry();
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ public class LibrariesLstModifier implements LibrariesHashFileModifier {
|
|||
@Override
|
||||
public byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) throws IOException {
|
||||
String[] lines = new String(data).split("\n");
|
||||
for(int i=0;i<lines.length;++i) {
|
||||
if(lines[i].contains("com.mojang:authlib")) {
|
||||
for (int i = 0; i < lines.length; ++i) {
|
||||
if (lines[i].contains("com.mojang:authlib")) {
|
||||
String[] separated = lines[i].split("\t");
|
||||
separated[0] = SecurityHelper.toHex(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, context.repackedAuthlibBytes));
|
||||
lines[i] = String.join("\t", separated);
|
||||
|
|
|
@ -15,34 +15,34 @@ public byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) t
|
|||
String version = null;
|
||||
int linePatchedHashIndex = -1;
|
||||
int lineOriginalHashIndex = -1;
|
||||
for(int i=0;i<lines.length;++i) {
|
||||
if(lines[i].startsWith("version=")) {
|
||||
for (int i = 0; i < lines.length; ++i) {
|
||||
if (lines[i].startsWith("version=")) {
|
||||
version = lines[i].split("=")[1];
|
||||
} else if(lines[i].startsWith("patchedHash=")) {
|
||||
} else if (lines[i].startsWith("patchedHash=")) {
|
||||
linePatchedHashIndex = i;
|
||||
} else if(lines[i].startsWith("originalHash=")) {
|
||||
} else if (lines[i].startsWith("originalHash=")) {
|
||||
lineOriginalHashIndex = i;
|
||||
}
|
||||
}
|
||||
if(version == null) {
|
||||
if (version == null) {
|
||||
LogHelper.warning("Unable to parse version from patch.properties");
|
||||
return data;
|
||||
}
|
||||
if(linePatchedHashIndex < 0) {
|
||||
if (linePatchedHashIndex < 0) {
|
||||
LogHelper.warning("Unable to parse patchedHash from patch.properties");
|
||||
return data;
|
||||
}
|
||||
if(lineOriginalHashIndex < 0) {
|
||||
if (lineOriginalHashIndex < 0) {
|
||||
LogHelper.warning("Unable to parse originalHash from patch.properties");
|
||||
return data;
|
||||
}
|
||||
Path patchedFile = context.workdir.resolve("cache").resolve("patched_".concat(version).concat(".jar"));
|
||||
Path originalFile = context.workdir.resolve("cache").resolve("mojang_".concat(version).concat(".jar"));
|
||||
if(Files.notExists(patchedFile)) {
|
||||
if (Files.notExists(patchedFile)) {
|
||||
LogHelper.warning("Unable to find %s. Maybe you should start the server at least once?", patchedFile);
|
||||
return data;
|
||||
}
|
||||
if(Files.notExists(originalFile)) {
|
||||
if (Files.notExists(originalFile)) {
|
||||
LogHelper.warning("Unable to find %s. Maybe you should start the server at least once?", originalFile);
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -11,14 +11,12 @@
|
|||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class ServerWrapperSetup {
|
||||
|
@ -62,7 +60,7 @@ public void run() throws Exception {
|
|||
wrapper.config.mainclass = mainClassName;
|
||||
boolean altMode = false;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if(!Request.isAvailable() || Request.getRequestService().isClosed()) {
|
||||
if (!Request.isAvailable() || Request.getRequestService().isClosed()) {
|
||||
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
||||
wrapper.config.address = commands.commandHandler.readLine();
|
||||
StdWebSocketService service;
|
||||
|
@ -87,12 +85,12 @@ public void run() throws Exception {
|
|||
break;
|
||||
} catch (Throwable e) {
|
||||
LogHelper.error(e);
|
||||
if(Request.isAvailable() && Request.getRequestService() instanceof AutoCloseable) {
|
||||
if (Request.isAvailable() && Request.getRequestService() instanceof AutoCloseable) {
|
||||
((AutoCloseable) Request.getRequestService()).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(wrapper.profile != null && wrapper.profile.getVersion().compareTo(ClientProfile.Version.MC118) >= 0) {
|
||||
if (wrapper.profile != null && wrapper.profile.getVersion().compareTo(ClientProfile.Version.MC118) >= 0) {
|
||||
LogHelper.info("Switch to alternative start mode (1.18)");
|
||||
wrapper.config.classpath.add(jarName);
|
||||
wrapper.config.classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER;
|
||||
|
@ -129,7 +127,7 @@ public void run() throws Exception {
|
|||
writer.append("-cp ");
|
||||
String pathServerWrapper = IOHelper.getCodeSource(ServerWrapper.class).getFileName().toString();
|
||||
writer.append(pathServerWrapper);
|
||||
if(!altMode) {
|
||||
if (!altMode) {
|
||||
if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) {
|
||||
writer.append(";");
|
||||
} else writer.append(":");
|
||||
|
@ -139,8 +137,8 @@ public void run() throws Exception {
|
|||
writer.append(ServerWrapper.class.getName());
|
||||
writer.append("\n");
|
||||
}
|
||||
if(JVMHelper.OS_TYPE != JVMHelper.OS.MUSTDIE) {
|
||||
if(!startScript.toFile().setExecutable(true)) {
|
||||
if (JVMHelper.OS_TYPE != JVMHelper.OS.MUSTDIE) {
|
||||
if (!startScript.toFile().setExecutable(true)) {
|
||||
LogHelper.error("Failed to set executable %s", startScript);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,16 @@
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModuleLaunch implements Launch {
|
||||
private static String getPackageFromClass(String clazz) {
|
||||
int index = clazz.lastIndexOf(".");
|
||||
if (index >= 0) {
|
||||
return clazz.substring(0, index);
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("ConfusingArgumentToVarargsMethod")
|
||||
public void run(ServerWrapper.Config config, String[] args) throws Throwable {
|
||||
|
@ -29,28 +36,28 @@ public void run(ServerWrapper.Config config, String[] args) throws Throwable {
|
|||
ModuleLayer.Controller controller = ModuleLayer.defineModulesWithOneLoader(configuration, List.of(bootLayer), ucl);
|
||||
ModuleLayer layer = controller.layer();
|
||||
// Configure exports / opens
|
||||
for(var e : config.moduleConf.exports.entrySet()) {
|
||||
for (var e : config.moduleConf.exports.entrySet()) {
|
||||
String[] split = e.getKey().split("\\\\");
|
||||
Module source = layer.findModule(split[0]).orElseThrow();
|
||||
String pkg = split[1];
|
||||
Module target = layer.findModule(e.getValue()).orElseThrow();
|
||||
controller.addExports(source, pkg, target);
|
||||
}
|
||||
for(var e : config.moduleConf.opens.entrySet()) {
|
||||
for (var e : config.moduleConf.opens.entrySet()) {
|
||||
String[] split = e.getKey().split("\\\\");
|
||||
Module source = layer.findModule(split[0]).orElseThrow();
|
||||
String pkg = split[1];
|
||||
Module target = layer.findModule(e.getValue()).orElseThrow();
|
||||
controller.addOpens(source, pkg, target);
|
||||
}
|
||||
for(var e : config.moduleConf.reads.entrySet()) {
|
||||
for (var e : config.moduleConf.reads.entrySet()) {
|
||||
Module source = layer.findModule(e.getKey()).orElseThrow();
|
||||
Module target = layer.findModule(e.getValue()).orElseThrow();
|
||||
controller.addReads(source, target);
|
||||
}
|
||||
Module mainModule = layer.findModule(config.moduleConf.mainModule).orElseThrow();
|
||||
Module unnamed = ModuleLaunch.class.getClassLoader().getUnnamedModule();
|
||||
if(unnamed != null) {
|
||||
if (unnamed != null) {
|
||||
controller.addOpens(mainModule, getPackageFromClass(config.mainclass), unnamed);
|
||||
}
|
||||
// Start main class
|
||||
|
@ -59,12 +66,4 @@ public void run(ServerWrapper.Config config, String[] args) throws Throwable {
|
|||
MethodHandle mainMethod = MethodHandles.lookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
|
||||
mainMethod.invoke(args);
|
||||
}
|
||||
|
||||
private static String getPackageFromClass(String clazz) {
|
||||
int index = clazz.lastIndexOf(".");
|
||||
if(index >= 0) {
|
||||
return clazz.substring(0, index);
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue