mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE][EXP][NEEDS TEST] Отказ от статического поля инстанции в LaunchServer.
This commit is contained in:
parent
a4d4aa834d
commit
b21b6c2362
33 changed files with 106 additions and 113 deletions
|
@ -97,11 +97,13 @@ public void reload() throws Exception {
|
|||
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
||||
config = Launcher.gsonManager.gson.fromJson(reader, Config.class);
|
||||
}
|
||||
config.server = this;
|
||||
config.verify();
|
||||
config.init();
|
||||
}
|
||||
|
||||
public static final class Config {
|
||||
private transient LaunchServer server = null;
|
||||
public int legacyPort;
|
||||
|
||||
private String legacyAddress;
|
||||
|
@ -236,30 +238,30 @@ public void verify() {
|
|||
public void init() {
|
||||
Launcher.applyLauncherEnv(env);
|
||||
for (AuthProviderPair provider : auth) {
|
||||
provider.init();
|
||||
provider.init(server);
|
||||
}
|
||||
permissionsHandler.init();
|
||||
hwidHandler.init();
|
||||
if (protectHandler != null) {
|
||||
protectHandler.checkLaunchServerLicense();
|
||||
}
|
||||
LaunchServer.server.registerObject("permissionsHandler", permissionsHandler);
|
||||
server.registerObject("permissionsHandler", permissionsHandler);
|
||||
for (AuthProviderPair pair : auth) {
|
||||
LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
||||
LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
||||
LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
||||
server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
||||
server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
||||
server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
||||
}
|
||||
|
||||
Arrays.stream(mirrors).forEach(LaunchServer.server.mirrorManager::addMirror);
|
||||
Arrays.stream(mirrors).forEach(server.mirrorManager::addMirror);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
LaunchServer.server.unregisterObject("permissionsHandler", permissionsHandler);
|
||||
server.unregisterObject("permissionsHandler", permissionsHandler);
|
||||
for (AuthProviderPair pair : auth) {
|
||||
LaunchServer.server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
||||
LaunchServer.server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
||||
LaunchServer.server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
||||
server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
||||
server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
||||
server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogHelper.error(e);
|
||||
|
@ -426,7 +428,7 @@ public static void main(String... args) throws Throwable {
|
|||
|
||||
public final Path updatesDir;
|
||||
|
||||
public static LaunchServer server = null;
|
||||
//public static LaunchServer server = null;
|
||||
|
||||
public final Path profilesDir;
|
||||
// Server config
|
||||
|
@ -509,7 +511,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
Response.registerResponses();
|
||||
Component.registerComponents();
|
||||
ProtectHandler.registerHandlers();
|
||||
LaunchServer.server = this;
|
||||
//LaunchServer.server = this;
|
||||
|
||||
// Set command handler
|
||||
CommandHandler localCommandHandler;
|
||||
|
@ -526,7 +528,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
localCommandHandler = new StdCommandHandler(true);
|
||||
LogHelper.warning("JLine2 isn't in classpath, using std");
|
||||
}
|
||||
pro.gravit.launchserver.command.handler.CommandHandler.registerCommands(localCommandHandler);
|
||||
pro.gravit.launchserver.command.handler.CommandHandler.registerCommands(localCommandHandler, this);
|
||||
commandHandler = localCommandHandler;
|
||||
|
||||
// Set key pair
|
||||
|
@ -568,6 +570,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
||||
config = Launcher.gsonManager.gson.fromJson(reader, Config.class);
|
||||
}
|
||||
config.server = this;
|
||||
if (!Files.exists(runtimeConfigFile)) {
|
||||
LogHelper.info("Reset LaunchServer runtime config file");
|
||||
runtime = new LaunchServerRuntimeConfig();
|
||||
|
@ -582,7 +585,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
config.verify();
|
||||
Launcher.applyLauncherEnv(config.env);
|
||||
for (AuthProviderPair provider : config.auth) {
|
||||
provider.init();
|
||||
provider.init(this);
|
||||
}
|
||||
config.permissionsHandler.init();
|
||||
config.hwidHandler.init();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.handler.AuthHandler;
|
||||
import pro.gravit.launchserver.auth.provider.AuthProvider;
|
||||
import pro.gravit.launchserver.auth.texture.TextureProvider;
|
||||
|
@ -21,8 +22,8 @@ public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvi
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
provider.init();
|
||||
public void init(LaunchServer srv) {
|
||||
provider.init(srv);
|
||||
handler.init();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ public final class AcceptAuthProvider extends AuthProvider {
|
|||
|
||||
@Override
|
||||
public AuthProviderResult auth(String login, String password, String ip) {
|
||||
return new AuthProviderResult(login, SecurityHelper.randomStringToken()); // Same as login
|
||||
return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); // Same as login
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.utils.ProviderMap;
|
||||
|
||||
public abstract class AuthProvider implements AutoCloseable {
|
||||
public static ProviderMap<AuthProvider> providers = new ProviderMap<>("AuthProvider");
|
||||
private static boolean registredProv = false;
|
||||
|
||||
protected transient LaunchServer srv = null;
|
||||
public static AuthProviderResult authError(String message) throws AuthException {
|
||||
throw new AuthException(message);
|
||||
}
|
||||
|
@ -34,7 +35,7 @@ public void preAuth(String login, String password, String customText, String ip)
|
|||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
public void init() {
|
||||
|
||||
public void init(LaunchServer srv) {
|
||||
this.srv = srv;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ public class AuthProviderResult {
|
|||
public final String accessToken;
|
||||
public final ClientPermissions permissions;
|
||||
|
||||
public AuthProviderResult(String username, String accessToken) {
|
||||
public AuthProviderResult(String username, String accessToken, LaunchServer server) {
|
||||
this.username = username;
|
||||
this.accessToken = accessToken;
|
||||
permissions = LaunchServer.server.config.permissionsHandler.getPermissions(username);
|
||||
permissions = server.config.permissionsHandler.getPermissions(username);
|
||||
}
|
||||
|
||||
public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) {
|
||||
|
|
|
@ -21,7 +21,8 @@ public final class MySQLAuthProvider extends AuthProvider {
|
|||
private boolean usePermission;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
public void init(LaunchServer srv) {
|
||||
super.init(srv);
|
||||
if (query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null");
|
||||
if (message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null");
|
||||
if (mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null");
|
||||
|
@ -38,7 +39,7 @@ public AuthProviderResult auth(String login, String password, String ip) throws
|
|||
// Execute SQL query
|
||||
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
||||
try (ResultSet set = s.executeQuery()) {
|
||||
return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : LaunchServer.server.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message);
|
||||
return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : srv.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public AuthProviderResult auth(String login, String password, String ip) throws
|
|||
if (whitelist != null) {
|
||||
for (String username : whitelist) {
|
||||
if (login.equals(username)) {
|
||||
return new AuthProviderResult(login, SecurityHelper.randomStringToken());
|
||||
return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ public final class RequestAuthProvider extends AuthProvider {
|
|||
private boolean usePermission;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
public void init(LaunchServer srv) {
|
||||
super.init(srv);
|
||||
if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null");
|
||||
if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null");
|
||||
pattern = Pattern.compile(response);
|
||||
|
@ -32,7 +33,7 @@ public AuthProviderResult auth(String login, String password, String ip) throws
|
|||
// Match username
|
||||
Matcher matcher = pattern.matcher(currentResponse);
|
||||
return matcher.matches() && matcher.groupCount() >= 1 ?
|
||||
new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(Long.getLong(matcher.group("permission"))) : LaunchServer.server.config.permissionsHandler.getPermissions(login)) :
|
||||
new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(Long.getLong(matcher.group("permission"))) : srv.config.permissionsHandler.getPermissions(login)) :
|
||||
authError(currentResponse);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public void genWords(boolean force) throws IOException {
|
|||
SecureRandom rand = SecurityHelper.newRandom();
|
||||
rand.setSeed(SecureRandom.getSeed(32));
|
||||
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(IOHelper.newOutput(words), IOHelper.UNICODE_CHARSET))) {
|
||||
String projectName = LaunchServer.server.config.projectName.replaceAll("\\W", "");
|
||||
String projectName = srv.config.projectName.replaceAll("\\W", "");
|
||||
String lowName = projectName.toLowerCase();
|
||||
String upName = projectName.toUpperCase();
|
||||
for (int i = 0; i < Short.MAX_VALUE; i++) out.println(generateString(rand, lowName, upName, 3));
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.launchserver.websocket.NettyServerSocketHandler;
|
||||
import pro.gravit.launchserver.websocket.WebSocketFrameHandler;
|
||||
import pro.gravit.utils.helper.CommonHelper;
|
||||
|
||||
public class TestCommand extends Command {
|
||||
|
@ -36,7 +35,7 @@ public void invoke(String... args) throws Exception {
|
|||
handler.close();
|
||||
}
|
||||
if (args[0].equals("eventAll")) {
|
||||
WebSocketFrameHandler.service.sendObjectAll(new PingEvent());
|
||||
handler.nettyServer.frameHandler.service.sendObjectAll(new PingEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,8 +48,7 @@
|
|||
import pro.gravit.utils.command.basic.HelpCommand;
|
||||
|
||||
public abstract class CommandHandler extends pro.gravit.utils.command.CommandHandler {
|
||||
public static void registerCommands(pro.gravit.utils.command.CommandHandler handler) {
|
||||
LaunchServer server = LaunchServer.server;
|
||||
public static void registerCommands(pro.gravit.utils.command.CommandHandler handler, LaunchServer server) {
|
||||
BaseCommandCategory basic = new BaseCommandCategory();
|
||||
// Register basic commands
|
||||
basic.registerCommand("help", new HelpCommand(handler));
|
||||
|
|
|
@ -21,6 +21,6 @@ public String getUsageDescription() {
|
|||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
LogHelper.info("You publickey modulus: %s", LaunchServer.server.publicKey.getModulus().toString(16));
|
||||
LogHelper.info("You publickey modulus: %s", server.publicKey.getModulus().toString(16));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
public class CommandRemoverComponent extends Component implements AutoCloseable {
|
||||
public String[] removeList = new String[]{};
|
||||
public transient Map<String, Command> commandsList = new HashMap<>();
|
||||
private transient LaunchServer server = null;
|
||||
|
||||
@Override
|
||||
public void preInit(LaunchServer launchServer) {
|
||||
|
||||
server = launchServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +33,7 @@ public void postInit(LaunchServer launchServer) {
|
|||
@Override
|
||||
public void close() {
|
||||
for (Map.Entry<String, Command> e : commandsList.entrySet()) {
|
||||
LaunchServer.server.commandHandler.registerCommand(e.getKey(), e.getValue());
|
||||
server.commandHandler.registerCommand(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ public void up() {
|
|||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void updateAuth() {
|
||||
public void updateAuth(LaunchServer server) {
|
||||
if (!isAuth) return;
|
||||
if (auth_id.isEmpty()) auth = LaunchServer.server.config.getAuthProviderPair();
|
||||
else auth = LaunchServer.server.config.getAuthProviderPair(auth_id);
|
||||
if (auth_id.isEmpty()) auth = server.config.getAuthProviderPair();
|
||||
else auth = server.config.getAuthProviderPair(auth_id);
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
|
|
|
@ -26,10 +26,11 @@ public class LauncherNettyServer implements AutoCloseable {
|
|||
public final ServerBootstrap serverBootstrap;
|
||||
public final EventLoopGroup bossGroup;
|
||||
public final EventLoopGroup workerGroup;
|
||||
public WebSocketFrameHandler frameHandler = null;
|
||||
private static final String WEBSOCKET_PATH = "/api";
|
||||
|
||||
public LauncherNettyServer() {
|
||||
LaunchServer.NettyConfig config = LaunchServer.server.config.netty;
|
||||
public LauncherNettyServer(LaunchServer server) {
|
||||
LaunchServer.NettyConfig config = server.config.netty;
|
||||
bossGroup = new NioEventLoopGroup(config.performance.bossThread);
|
||||
workerGroup = new NioEventLoopGroup(config.performance.workerThread);
|
||||
serverBootstrap = new ServerBootstrap();
|
||||
|
@ -44,13 +45,14 @@ public void initChannel(NioSocketChannel ch) {
|
|||
//p.addLast(new LoggingHandler(LogLevel.INFO));
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast(new HttpObjectAggregator(65536));
|
||||
if (LaunchServer.server.config.netty.ipForwarding)
|
||||
if (server.config.netty.ipForwarding)
|
||||
pipeline.addLast(new NettyIpForwardHandler(context));
|
||||
pipeline.addLast(new WebSocketServerCompressionHandler());
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
|
||||
if (LaunchServer.server.config.netty.fileServerEnabled)
|
||||
pipeline.addLast(new FileServerHandler(LaunchServer.server.updatesDir, true));
|
||||
pipeline.addLast(new WebSocketFrameHandler(context));
|
||||
if (server.config.netty.fileServerEnabled)
|
||||
pipeline.addLast(new FileServerHandler(server.updatesDir, true));
|
||||
frameHandler = new WebSocketFrameHandler(context, server);
|
||||
pipeline.addLast(frameHandler);
|
||||
}
|
||||
});
|
||||
if (config.proxy != null && config.proxy.enabled) {
|
||||
|
|
|
@ -33,11 +33,11 @@
|
|||
|
||||
@SuppressWarnings({"unused", "rawtypes"})
|
||||
public final class NettyServerSocketHandler implements Runnable, AutoCloseable {
|
||||
private static SSLServerSocketFactory ssf;
|
||||
private SSLServerSocketFactory ssf;
|
||||
|
||||
public volatile boolean logConnections = Boolean.getBoolean("launcher.logConnections");
|
||||
|
||||
public static LauncherNettyServer nettyServer;
|
||||
public LauncherNettyServer nettyServer;
|
||||
|
||||
private final AtomicReference<ServerSocket> serverSocket = new AtomicReference<>();
|
||||
|
||||
|
@ -47,9 +47,10 @@ public final class NettyServerSocketHandler implements Runnable, AutoCloseable {
|
|||
private Set<Socket> sockets;
|
||||
private volatile Listener listener;
|
||||
|
||||
private transient final LaunchServer server;
|
||||
|
||||
public NettyServerSocketHandler(LaunchServer server) {
|
||||
// Instance
|
||||
LaunchServer server1 = server;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,9 +110,8 @@ public void run() {
|
|||
LogHelper.info("Starting netty server socket thread");
|
||||
//SSLEngine engine = sc.createSSLEngine();
|
||||
//engine.setUseClientMode(false);
|
||||
WebSocketFrameHandler.server = LaunchServer.server;
|
||||
nettyServer = new LauncherNettyServer();
|
||||
for (LaunchServer.NettyBindAddress address : LaunchServer.server.config.netty.binds) {
|
||||
nettyServer = new LauncherNettyServer(server);
|
||||
for (LaunchServer.NettyBindAddress address : server.config.netty.binds) {
|
||||
nettyServer.bind(new InetSocketAddress(address.address, address.port));
|
||||
}
|
||||
/*
|
||||
|
|
|
@ -20,19 +20,21 @@
|
|||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
||||
public static LaunchServer server;
|
||||
public final LaunchServer srv;
|
||||
public static GsonBuilder builder = CommonHelper.newBuilder();
|
||||
public static WebSocketService service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), LaunchServer.server, builder);
|
||||
public final WebSocketService service;
|
||||
public NettyConnectContext context;
|
||||
|
||||
public WebSocketFrameHandler(NettyConnectContext context) {
|
||||
public WebSocketFrameHandler(NettyConnectContext context, LaunchServer srv) {
|
||||
this.context = context;
|
||||
this.srv = srv;
|
||||
service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), srv, builder);
|
||||
service.registerResponses();
|
||||
}
|
||||
|
||||
private Client client;
|
||||
|
||||
static {
|
||||
service.registerResponses();
|
||||
}
|
||||
|
||||
public void setClient(Client client) {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.ExecCommandRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
||||
|
@ -20,7 +19,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
sendError("Access denied");
|
||||
return;
|
||||
}
|
||||
LaunchServer.server.commandHandler.eval(cmd, false);
|
||||
server.commandHandler.eval(cmd, false);
|
||||
sendResult(new ExecCommandRequestEvent(true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
import pro.gravit.launcher.OshiHWID;
|
||||
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
||||
import pro.gravit.launcher.profiles.ClientProfile;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.auth.hwid.HWIDException;
|
||||
|
@ -68,13 +67,13 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
|
|||
}
|
||||
if (password == null) {
|
||||
try {
|
||||
password = IOHelper.decode(SecurityHelper.newRSADecryptCipher(LaunchServer.server.privateKey).
|
||||
password = IOHelper.decode(SecurityHelper.newRSADecryptCipher(server.privateKey).
|
||||
doFinal(encryptedPassword));
|
||||
} catch (IllegalBlockSizeException | BadPaddingException ignored) {
|
||||
throw new AuthException("Password decryption error");
|
||||
}
|
||||
}
|
||||
clientData.permissions = LaunchServer.server.config.permissionsHandler.getPermissions(login);
|
||||
clientData.permissions = server.config.permissionsHandler.getPermissions(login);
|
||||
if (authType == ConnectTypes.BOT && !clientData.permissions.canBot) {
|
||||
AuthProvider.authError("authType: BOT not allowed for this account");
|
||||
}
|
||||
|
@ -82,22 +81,22 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
|
|||
AuthProvider.authError("authType: SERVER not allowed for this account");
|
||||
}
|
||||
AuthProviderPair pair;
|
||||
if (auth_id.isEmpty()) pair = LaunchServer.server.config.getAuthProviderPair();
|
||||
else pair = LaunchServer.server.config.getAuthProviderPair(auth_id);
|
||||
if (auth_id.isEmpty()) pair = server.config.getAuthProviderPair();
|
||||
else pair = server.config.getAuthProviderPair(auth_id);
|
||||
AuthContext context = new AuthContext(0, login, password.length(), customText, client, ip, null, false);
|
||||
AuthProvider provider = pair.provider;
|
||||
LaunchServer.server.authHookManager.preHook.hook(context, clientData);
|
||||
server.authHookManager.preHook.hook(context, clientData);
|
||||
provider.preAuth(login, password, customText, ip);
|
||||
AuthProviderResult aresult = provider.auth(login, password, ip);
|
||||
if (!VerifyHelper.isValidUsername(aresult.username)) {
|
||||
AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username));
|
||||
return;
|
||||
}
|
||||
Collection<ClientProfile> profiles = LaunchServer.server.getProfiles();
|
||||
Collection<ClientProfile> profiles = server.getProfiles();
|
||||
for (ClientProfile p : profiles) {
|
||||
if (p.getTitle().equals(client)) {
|
||||
if (!p.isWhitelistContains(login)) {
|
||||
throw new AuthException(LaunchServer.server.config.whitelistRejectString);
|
||||
throw new AuthException(server.config.whitelistRejectString);
|
||||
}
|
||||
clientData.profile = p;
|
||||
}
|
||||
|
@ -106,18 +105,18 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
|
|||
// throw new AuthException("You profile not found");
|
||||
//}
|
||||
if (authType == ConnectTypes.CLIENT)
|
||||
LaunchServer.server.config.hwidHandler.check(hwid, aresult.username);
|
||||
LaunchServer.server.authHookManager.postHook.hook(context, clientData);
|
||||
server.config.hwidHandler.check(hwid, aresult.username);
|
||||
server.authHookManager.postHook.hook(context, clientData);
|
||||
clientData.isAuth = true;
|
||||
clientData.permissions = aresult.permissions;
|
||||
clientData.auth_id = auth_id;
|
||||
clientData.updateAuth();
|
||||
clientData.updateAuth(server);
|
||||
result.accessToken = aresult.accessToken;
|
||||
result.permissions = clientData.permissions;
|
||||
if (getSession) {
|
||||
if (clientData.session == 0) {
|
||||
clientData.session = random.nextLong();
|
||||
LaunchServer.server.sessionManager.addClient(clientData);
|
||||
server.sessionManager.addClient(clientData);
|
||||
}
|
||||
result.session = clientData.session;
|
||||
}
|
||||
|
@ -125,9 +124,9 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
|
|||
if (!clientData.permissions.canProxy) throw new AuthException("initProxy not allow");
|
||||
clientData.proxy = true;
|
||||
}
|
||||
if (LaunchServer.server.config.protectHandler.allowGetAccessToken(context)) {
|
||||
if (server.config.protectHandler.allowGetAccessToken(context)) {
|
||||
UUID uuid = pair.handler.auth(aresult);
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, aresult.username, client, clientData.auth.textureProvider);
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(server, uuid, aresult.username, client, clientData.auth.textureProvider);
|
||||
LogHelper.debug("Auth: %s accessToken %s uuid: %s", login, result.accessToken, uuid.toString());
|
||||
}
|
||||
sendResult(result);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.CheckServerRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
@ -27,7 +26,7 @@ public void execute(ChannelHandlerContext ctx, Client pClient) {
|
|||
server.authHookManager.checkServerHook.hook(this, pClient);
|
||||
result.uuid = pClient.auth.handler.checkServer(username, serverID);
|
||||
if (result.uuid != null)
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, result.uuid, username, client, pClient.auth.textureProvider);
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(server, result.uuid, username, client, pClient.auth.textureProvider);
|
||||
LogHelper.debug("checkServer: %s uuid: %s serverID: %s", result.playerProfile.username, result.uuid.toString(), serverID);
|
||||
} catch (AuthException | HookException e) {
|
||||
sendError(e.getMessage());
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
@ -19,7 +18,7 @@ public String getType() {
|
|||
@Override
|
||||
public void execute(ChannelHandlerContext ctx, Client client) {
|
||||
List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>();
|
||||
for (AuthProviderPair pair : LaunchServer.server.config.auth) {
|
||||
for (AuthProviderPair pair : server.config.auth) {
|
||||
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName));
|
||||
}
|
||||
sendResult(new GetAvailabilityAuthRequestEvent(list));
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.JoinServerRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
@ -26,7 +25,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
server.authHookManager.joinServerHook.hook(this, client);
|
||||
if (client.auth == null) {
|
||||
LogHelper.warning("Client auth is null. Using default.");
|
||||
success = LaunchServer.server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID);
|
||||
success = server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID);
|
||||
} else success = client.auth.handler.joinServer(username, accessToken, serverID);
|
||||
LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID);
|
||||
} catch (AuthException | HookException e) {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.ErrorRequestEvent;
|
||||
import pro.gravit.launcher.events.request.ProfilesRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
||||
|
@ -19,6 +18,6 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
||||
return;
|
||||
}
|
||||
sendResult(new ProfilesRequestEvent(LaunchServer.server.getProfiles()));
|
||||
sendResult(new ProfilesRequestEvent(server.getProfiles()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||
import pro.gravit.launcher.events.request.RestoreSessionRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.WebSocketFrameHandler;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
@ -19,7 +18,7 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
public void execute(ChannelHandlerContext ctx, Client client) {
|
||||
Client rClient = LaunchServer.server.sessionManager.getClient(session);
|
||||
Client rClient = server.sessionManager.getClient(session);
|
||||
if (rClient == null) {
|
||||
sendError("Session invalid");
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.SetProfileRequestEvent;
|
||||
import pro.gravit.launcher.profiles.ClientProfile;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
import pro.gravit.utils.HookException;
|
||||
|
@ -29,11 +28,11 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
} catch (HookException e) {
|
||||
sendError(e.getMessage());
|
||||
}
|
||||
Collection<ClientProfile> profiles = LaunchServer.server.getProfiles();
|
||||
Collection<ClientProfile> profiles = server.getProfiles();
|
||||
for (ClientProfile p : profiles) {
|
||||
if (p.getTitle().equals(this.client)) {
|
||||
if (!p.isWhitelistContains(client.username)) {
|
||||
sendError(LaunchServer.server.config.whitelistRejectString);
|
||||
sendError(server.config.whitelistRejectString);
|
||||
return;
|
||||
}
|
||||
client.profile = p;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent;
|
||||
import pro.gravit.launcher.profiles.PlayerProfile;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -31,9 +30,9 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
|
|||
UUID uuid;
|
||||
if (client.auth == null) {
|
||||
LogHelper.warning("Client auth is null. Using default.");
|
||||
uuid = LaunchServer.server.config.getAuthProviderPair().handler.usernameToUUID(list[i].username);
|
||||
uuid = server.config.getAuthProviderPair().handler.usernameToUUID(list[i].username);
|
||||
} else uuid = client.auth.handler.usernameToUUID(list[i].username);
|
||||
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, list[i].username, list[i].client, client.auth.textureProvider);
|
||||
result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(server, uuid, list[i].username, list[i].client, client.auth.textureProvider);
|
||||
}
|
||||
sendResult(result);
|
||||
}
|
||||
|
|
|
@ -50,8 +50,8 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
|
|||
String username;
|
||||
if (client.auth == null) {
|
||||
LogHelper.warning("Client auth is null. Using default.");
|
||||
username = LaunchServer.server.config.getAuthProviderPair().handler.uuidToUsername(uuid);
|
||||
username = server.config.getAuthProviderPair().handler.uuidToUsername(uuid);
|
||||
} else username = client.auth.handler.uuidToUsername(uuid);
|
||||
sendResult(new ProfileByUUIDRequestEvent(getProfile(LaunchServer.server, uuid, username, this.client, client.auth.textureProvider)));
|
||||
sendResult(new ProfileByUUIDRequestEvent(getProfile(server, uuid, username, this.client, client.auth.textureProvider)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -23,8 +22,8 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
|
|||
UUID uuid;
|
||||
if (client.auth == null) {
|
||||
LogHelper.warning("Client auth is null. Using default.");
|
||||
uuid = LaunchServer.server.config.getAuthProviderPair().handler.usernameToUUID(username);
|
||||
uuid = server.config.getAuthProviderPair().handler.usernameToUUID(username);
|
||||
} else uuid = client.auth.handler.usernameToUUID(username);
|
||||
sendResult(new ProfileByUsernameRequestEvent(ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, username, this.client, client.auth.textureProvider)));
|
||||
sendResult(new ProfileByUsernameRequestEvent(ProfileByUUIDResponse.getProfile(server, uuid, username, this.client, client.auth.textureProvider)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.GetSecureTokenRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
||||
|
@ -14,7 +13,7 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
public void execute(ChannelHandlerContext ctx, Client client) {
|
||||
String secureToken = LaunchServer.server.config.protectHandler.generateClientSecureToken();
|
||||
String secureToken = server.config.protectHandler.generateClientSecureToken();
|
||||
client.verifyToken = secureToken;
|
||||
sendResult(new GetSecureTokenRequestEvent(secureToken));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.VerifySecureTokenRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
||||
|
@ -16,7 +15,7 @@ public String getType() {
|
|||
|
||||
@Override
|
||||
public void execute(ChannelHandlerContext ctx, Client client) {
|
||||
boolean success = LaunchServer.server.config.protectHandler.verifyClientSecureToken(secureToken, client.verifyToken);
|
||||
boolean success = server.config.protectHandler.verifyClientSecureToken(secureToken, client.verifyToken);
|
||||
if (success) client.isSecure = true;
|
||||
sendResult(new VerifySecureTokenRequestEvent(success));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.LauncherRequestEvent;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
import pro.gravit.utils.Version;
|
||||
|
@ -15,9 +14,6 @@ public class LauncherResponse extends SimpleResponse {
|
|||
public String hash;
|
||||
public byte[] digest;
|
||||
public int launcher_type;
|
||||
//REPLACED TO REAL URL
|
||||
public static final String JAR_URL = LaunchServer.server.config.netty.launcherURL;
|
||||
public static final String EXE_URL = LaunchServer.server.config.netty.launcherEXEURL;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
|
@ -33,23 +29,23 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
bytes = digest;
|
||||
if (launcher_type == 1) // JAR
|
||||
{
|
||||
byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest();
|
||||
if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, JAR_URL));
|
||||
byte[] hash = server.launcherBinary.getBytes().getDigest();
|
||||
if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, server.config.netty.launcherURL));
|
||||
if (Arrays.equals(bytes, hash)) {
|
||||
client.checkSign = true;
|
||||
sendResult(new LauncherRequestEvent(false, JAR_URL));
|
||||
sendResult(new LauncherRequestEvent(false, server.config.netty.launcherURL));
|
||||
} else {
|
||||
sendResultAndClose(new LauncherRequestEvent(true, JAR_URL));
|
||||
sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherURL));
|
||||
}
|
||||
} else if (launcher_type == 2) //EXE
|
||||
{
|
||||
byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest();
|
||||
if (hash == null) sendResultAndClose(new LauncherRequestEvent(true, EXE_URL));
|
||||
byte[] hash = server.launcherEXEBinary.getBytes().getDigest();
|
||||
if (hash == null) sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL));
|
||||
if (Arrays.equals(bytes, hash)) {
|
||||
client.checkSign = true;
|
||||
sendResult(new LauncherRequestEvent(false, EXE_URL));
|
||||
sendResult(new LauncherRequestEvent(false, server.config.netty.launcherEXEURL));
|
||||
} else {
|
||||
sendResultAndClose(new LauncherRequestEvent(true, EXE_URL));
|
||||
sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL));
|
||||
}
|
||||
} else sendError("Request launcher type error");
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import pro.gravit.launcher.events.request.UpdateListRequestEvent;
|
||||
import pro.gravit.launcher.hasher.HashedDir;
|
||||
import pro.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.websocket.json.SimpleResponse;
|
||||
|
||||
|
@ -25,7 +24,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
return;
|
||||
}
|
||||
HashSet<String> set = new HashSet<>();
|
||||
for (Map.Entry<String, SignedObjectHolder<HashedDir>> entry : LaunchServer.server.updatesDirMap.entrySet())
|
||||
for (Map.Entry<String, SignedObjectHolder<HashedDir>> entry : server.updatesDirMap.entrySet())
|
||||
set.add(entry.getKey());
|
||||
sendResult(new UpdateListRequestEvent(set));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
return;
|
||||
}
|
||||
if (!client.permissions.canAdmin) {
|
||||
for (ClientProfile p : LaunchServer.server.getProfiles()) {
|
||||
for (ClientProfile p : server.getProfiles()) {
|
||||
if (!client.profile.getTitle().equals(p.getTitle())) continue;
|
||||
if (!p.isWhitelistContains(client.username)) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent("You don't download this folder"));
|
||||
|
@ -33,12 +33,12 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
}
|
||||
}
|
||||
}
|
||||
SignedObjectHolder<HashedDir> dir = LaunchServer.server.updatesDirMap.get(dirName);
|
||||
SignedObjectHolder<HashedDir> dir = server.updatesDirMap.get(dirName);
|
||||
if (dir == null) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent(String.format("Directory %s not found", dirName)));
|
||||
return;
|
||||
}
|
||||
String url = LaunchServer.server.config.netty.downloadURL.replace("%dirname%", dirName);
|
||||
String url = server.config.netty.downloadURL.replace("%dirname%", dirName);
|
||||
boolean zip = false;
|
||||
if (server.config.netty.bindings.get(dirName) != null) {
|
||||
LaunchServer.NettyUpdatesBind bind = server.config.netty.bindings.get(dirName);
|
||||
|
|
Loading…
Reference in a new issue