mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
Чистка LauncherAPI
This commit is contained in:
parent
bae9a511bc
commit
311fee0443
28 changed files with 182 additions and 186 deletions
|
@ -68,39 +68,39 @@
|
|||
|
||||
public final class LaunchServer implements Runnable, AutoCloseable {
|
||||
public static final class Config extends ConfigObject {
|
||||
@LauncherAPI
|
||||
|
||||
public final int port;
|
||||
|
||||
// Handlers & Providers
|
||||
@LauncherAPI
|
||||
|
||||
public final AuthHandler[] authHandler;
|
||||
@LauncherAPI
|
||||
|
||||
public final AuthProvider[] authProvider;
|
||||
@LauncherAPI
|
||||
|
||||
public final TextureProvider textureProvider;
|
||||
@LauncherAPI
|
||||
|
||||
public final HWIDHandler hwidHandler;
|
||||
|
||||
// Misc options
|
||||
@LauncherAPI
|
||||
|
||||
public final ExeConf launch4j;
|
||||
@LauncherAPI
|
||||
|
||||
public final SignConf sign;
|
||||
@LauncherAPI
|
||||
|
||||
public final boolean compress;
|
||||
@LauncherAPI
|
||||
|
||||
public final int authRateLimit;
|
||||
@LauncherAPI
|
||||
|
||||
public final int authRateLimitMilis;
|
||||
@LauncherAPI
|
||||
|
||||
public final String authRejectString;
|
||||
@LauncherAPI
|
||||
|
||||
public final String projectName;
|
||||
@LauncherAPI
|
||||
|
||||
public final String whitelistRejectString;
|
||||
@LauncherAPI
|
||||
|
||||
public final boolean genMappings;
|
||||
@LauncherAPI
|
||||
|
||||
public final String binaryName;
|
||||
private final StringConfigEntry address;
|
||||
private final String bindAddress;
|
||||
|
@ -143,27 +143,27 @@ private Config(BlockConfigEntry block, Path coredir,LaunchServer server) {
|
|||
compress = block.getEntryValue("compress", BooleanConfigEntry.class);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public String getAddress() {
|
||||
return address.getValue();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public String getBindAddress() {
|
||||
return bindAddress;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public SocketAddress getSocketAddress() {
|
||||
return new InetSocketAddress(bindAddress, port);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address.setValue(address);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void verify() {
|
||||
VerifyHelper.verify(getAddress(), VerifyHelper.NOT_EMPTY, "LaunchServer address can't be empty");
|
||||
}
|
||||
|
@ -276,53 +276,53 @@ public static void main(String... args) throws Throwable {
|
|||
}
|
||||
|
||||
// Constant paths
|
||||
@LauncherAPI
|
||||
|
||||
public final Path dir;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final Path configFile;
|
||||
@LauncherAPI
|
||||
|
||||
public final Path publicKeyFile;
|
||||
@LauncherAPI
|
||||
|
||||
public final Path privateKeyFile;
|
||||
@LauncherAPI
|
||||
|
||||
public final Path updatesDir;
|
||||
public static LaunchServer server;
|
||||
@LauncherAPI
|
||||
|
||||
public final Path profilesDir;
|
||||
// Server config
|
||||
@LauncherAPI
|
||||
|
||||
public final Config config;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final RSAPublicKey publicKey;
|
||||
@LauncherAPI
|
||||
|
||||
public final RSAPrivateKey privateKey;
|
||||
@LauncherAPI
|
||||
|
||||
public final boolean portable;
|
||||
// Launcher binary
|
||||
@LauncherAPI
|
||||
|
||||
public final LauncherBinary launcherBinary;
|
||||
@LauncherAPI
|
||||
|
||||
public final LauncherBinary launcherEXEBinary;
|
||||
// HWID ban + anti-brutforce
|
||||
@LauncherAPI
|
||||
|
||||
public final AuthLimiter limiter;
|
||||
@LauncherAPI
|
||||
|
||||
public final SessionManager sessionManager;
|
||||
// Server
|
||||
@LauncherAPI
|
||||
|
||||
public final ModulesManager modulesManager;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final BuildHookManager buildHookManager;
|
||||
@LauncherAPI
|
||||
|
||||
public final ProguardConf proguardConf;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final CommandHandler commandHandler;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final ServerSocketHandler serverSocketHandler;
|
||||
|
||||
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
|
@ -445,7 +445,7 @@ private LauncherBinary binary() {
|
|||
return new EXELauncherBinary(this);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void buildLauncherBinaries() throws IOException {
|
||||
launcherBinary.build();
|
||||
launcherEXEBinary.build();
|
||||
|
@ -504,23 +504,23 @@ private void generateConfigIfNotExists() throws IOException {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
@SuppressWarnings("ReturnOfCollectionOrArrayField")
|
||||
public Collection<SignedObjectHolder<ClientProfile>> getProfiles() {
|
||||
return profilesList;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public SignedObjectHolder<HashedDir> getUpdateDir(String name) {
|
||||
return updatesDirMap.get(name);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public Set<Entry<String, SignedObjectHolder<HashedDir>>> getUpdateDirs() {
|
||||
return updatesDirMap.entrySet();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void rebindServerSocket() {
|
||||
serverSocketHandler.close();
|
||||
CommonHelper.newThread("Server Socket Thread", false, serverSocketHandler).start();
|
||||
|
@ -539,7 +539,7 @@ public void run() {
|
|||
rebindServerSocket();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void syncLauncherBinaries() throws IOException {
|
||||
LogHelper.info("Syncing launcher binaries");
|
||||
|
||||
|
@ -554,7 +554,7 @@ public void syncLauncherBinaries() throws IOException {
|
|||
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void syncProfilesDir() throws IOException {
|
||||
LogHelper.info("Syncing profiles dir");
|
||||
List<SignedObjectHolder<ClientProfile>> newProfies = new LinkedList<>();
|
||||
|
@ -565,7 +565,7 @@ public void syncProfilesDir() throws IOException {
|
|||
profilesList = Collections.unmodifiableList(newProfies);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void syncUpdatesDir(Collection<String> dirs) throws IOException {
|
||||
LogHelper.info("Syncing updates dir");
|
||||
Map<String, SignedObjectHolder<HashedDir>> newUpdatesDirMap = new HashMap<>(16);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
public final class AuthException extends IOException {
|
||||
private static final long serialVersionUID = -2586107832847245863L;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public AuthException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public String toString() {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static final long TIMEOUT = 10 * 60 * 1000; //10 минут
|
||||
public final int rateLimit;
|
||||
public final int rateLimitMilis;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
|
||||
|
||||
public final class MySQLSourceConfig extends ConfigObject implements AutoCloseable {
|
||||
@LauncherAPI
|
||||
|
||||
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
||||
Integer.parseUnsignedInt(System.getProperty("launcher.mysql.idleTimeout", Integer.toString(5000))),
|
||||
VerifyHelper.POSITIVE, "launcher.mysql.idleTimeout can't be <= 5000");
|
||||
|
@ -44,7 +44,7 @@ public final class MySQLSourceConfig extends ConfigObject implements AutoCloseab
|
|||
private DataSource source;
|
||||
private boolean hikari;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public MySQLSourceConfig(String poolName, BlockConfigEntry block) {
|
||||
super(block);
|
||||
this.poolName = poolName;
|
||||
|
@ -70,7 +70,7 @@ public synchronized void close() {
|
|||
((HikariDataSource) source).close();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public synchronized Connection getConnection() throws SQLException {
|
||||
if (source == null) { // New data source
|
||||
MysqlDataSource mysqlSource = new MysqlDataSource();
|
||||
|
|
|
@ -17,19 +17,19 @@ public abstract class AuthHandler extends ConfigObject implements AutoCloseable
|
|||
private static final Map<String, Adapter<AuthHandler>> AUTH_HANDLERS = new ConcurrentHashMap<>(4);
|
||||
private static boolean registredHandl = false;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static UUID authError(String message) throws AuthException {
|
||||
throw new AuthException(message);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static AuthHandler newHandler(String name, BlockConfigEntry block) {
|
||||
Adapter<AuthHandler> authHandlerAdapter = VerifyHelper.getMapValue(AUTH_HANDLERS, name,
|
||||
String.format("Unknown auth handler: '%s'", name));
|
||||
return authHandlerAdapter.convert(block);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static void registerHandler(String name, Adapter<AuthHandler> adapter) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(AUTH_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
|
@ -50,26 +50,26 @@ public static void registerHandlers() {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected AuthHandler(BlockConfigEntry block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract UUID auth(AuthProviderResult authResult) throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract UUID checkServer(String username, String serverID) throws IOException;
|
||||
|
||||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract boolean joinServer(String username, String accessToken, String serverID) throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract UUID usernameToUUID(String username) throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract String uuidToUsername(UUID uuid) throws IOException;
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
|
||||
public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection {
|
||||
public static final class Entry {
|
||||
@LauncherAPI
|
||||
|
||||
public final UUID uuid;
|
||||
private String username;
|
||||
private String accessToken;
|
||||
private String serverID;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public Entry(UUID uuid, String username, String accessToken, String serverID) {
|
||||
this.uuid = Objects.requireNonNull(uuid, "uuid");
|
||||
this.username = Objects.requireNonNull(username, "username");
|
||||
|
@ -37,14 +37,14 @@ public Entry(UUID uuid, String username, String accessToken, String serverID) {
|
|||
|
||||
private final Map<String, UUID> usernamesCache = new HashMap<>(1024);
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected CachedAuthHandler(BlockConfigEntry block) {
|
||||
super(block);
|
||||
if (block.hasEntry("garbage"))
|
||||
if (block.getEntryValue("garbage", BooleanConfigEntry.class)) GarbageManager.registerNeedGC(this);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected void addEntry(Entry entry) {
|
||||
Entry previous = entryCache.put(entry.uuid, entry);
|
||||
if (previous != null)
|
||||
|
@ -72,10 +72,10 @@ public synchronized UUID checkServer(String username, String serverID) throws IO
|
|||
serverID.equals(entry.serverID) ? entry.uuid : null;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected abstract Entry fetchEntry(String username) throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected abstract Entry fetchEntry(UUID uuid) throws IOException;
|
||||
|
||||
private Entry getEntry(String username) throws IOException {
|
||||
|
@ -118,10 +118,10 @@ public synchronized void garbageCollection() {
|
|||
entryCache.clear();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected abstract boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected abstract boolean updateServerID(UUID uuid, String serverID) throws IOException;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,7 +31,7 @@ public static final class Entry extends StreamObject {
|
|||
private String accessToken;
|
||||
private String serverID;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public Entry(HInput input) throws IOException {
|
||||
username = VerifyHelper.verifyUsername(input.readString(64));
|
||||
if (input.readBoolean()) {
|
||||
|
@ -41,12 +41,12 @@ public Entry(HInput input) throws IOException {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public Entry(String username) {
|
||||
this.username = VerifyHelper.verifyUsername(username);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public Entry(String username, String accessToken, String serverID) {
|
||||
this(username);
|
||||
if (accessToken == null && serverID != null)
|
||||
|
@ -67,17 +67,17 @@ private boolean checkServer(String username, String serverID) {
|
|||
return username.equals(this.username) && serverID.equals(this.serverID);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public String getServerID() {
|
||||
return serverID;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
@ -104,12 +104,12 @@ public void write(HOutput output) throws IOException {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final Path file;
|
||||
@LauncherAPI
|
||||
|
||||
public final Path fileTmp;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final boolean offlineUUIDs;
|
||||
// Instance
|
||||
private final SecureRandom random = SecurityHelper.newRandom();
|
||||
|
@ -120,7 +120,7 @@ public void write(HOutput output) throws IOException {
|
|||
|
||||
private final Map<String, UUID> usernamesMap = new HashMap<>(256);
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected FileAuthHandler(BlockConfigEntry block) {
|
||||
super(block);
|
||||
file = IOHelper.toPath(block.getEntryValue("file", StringConfigEntry.class));
|
||||
|
@ -138,7 +138,7 @@ protected FileAuthHandler(BlockConfigEntry block) {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final void addAuth(UUID uuid, Entry entry) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
|
@ -202,7 +202,7 @@ public final void close() throws IOException {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final Set<Map.Entry<UUID, Entry>> entrySet() {
|
||||
return Collections.unmodifiableMap(entryMap).entrySet();
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ public final boolean joinServer(String username, String accessToken, String serv
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected abstract void readAuthFile() throws IOException;
|
||||
|
||||
@Override
|
||||
|
@ -258,6 +258,6 @@ public final String uuidToUsername(UUID uuid) {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected abstract void writeAuthFileTmp() throws IOException;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public boolean joinServer(String username, String accessToken, String serverID)
|
|||
return getHandler().joinServer(username, accessToken, serverID);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void setBackend(AuthHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
|
|
@ -15,14 +15,14 @@ public abstract class HWIDHandler extends ConfigObject implements AutoCloseable
|
|||
public static final HWID nullHWID = HWID.gen(0, 0, 0);
|
||||
private static boolean registredHandl = false;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static HWIDHandler newHandler(String name, BlockConfigEntry block) {
|
||||
Adapter<HWIDHandler> authHandlerAdapter = VerifyHelper.getMapValue(HW_HANDLERS, name,
|
||||
String.format("Unknown HWID handler: '%s'", name));
|
||||
return authHandlerAdapter.convert(block);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static void registerHandler(String name, Adapter<HWIDHandler> adapter) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(HW_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
|
|
|
@ -18,12 +18,12 @@ public abstract class AuthProvider extends ConfigObject implements AutoCloseable
|
|||
private static boolean registredProv = false;
|
||||
private LaunchServer server;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static AuthProviderResult authError(String message) throws AuthException {
|
||||
throw new AuthException(message);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static AuthProvider newProvider(String name, BlockConfigEntry block,LaunchServer server) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
ServerAdapter<AuthProvider> authHandlerAdapter = VerifyHelper.getMapValue(AUTH_PROVIDERS, name,
|
||||
|
@ -31,7 +31,7 @@ public static AuthProvider newProvider(String name, BlockConfigEntry block,Launc
|
|||
return authHandlerAdapter.convert(block,server);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static void registerProvider(String name, ServerAdapter<AuthProvider> adapter) {
|
||||
VerifyHelper.putIfAbsent(AUTH_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
String.format("Auth provider has been already registered: '%s'", name));
|
||||
|
@ -57,20 +57,20 @@ public AuthHandler getAccociateHandler(int this_position)
|
|||
return server.config.authHandler[this_position];
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected AuthProvider(BlockConfigEntry block, LaunchServer launchServer) {
|
||||
super(block);
|
||||
server = launchServer;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract AuthProviderResult auth(String login, String password, String ip) throws Exception;
|
||||
|
||||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
@FunctionalInterface
|
||||
public interface ServerAdapter<O extends ConfigObject> {
|
||||
@LauncherAPI
|
||||
|
||||
O convert(BlockConfigEntry entry,LaunchServer server);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
public abstract class DigestAuthProvider extends AuthProvider {
|
||||
private final DigestAlgorithm digest;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected DigestAuthProvider(BlockConfigEntry block, LaunchServer server) {
|
||||
super(block,server);
|
||||
digest = DigestAlgorithm.byName(block.getEntryValue("digest", StringConfigEntry.class));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final void verifyDigest(String validDigest, String password) throws AuthException {
|
||||
boolean valid;
|
||||
if (digest == DigestAlgorithm.PLAIN)
|
||||
|
|
|
@ -31,7 +31,7 @@ private AuthProvider getProvider() {
|
|||
return VerifyHelper.verify(provider, Objects::nonNull, "Backend auth provider wasn't set");
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void setBackend(AuthProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public void clear() {
|
|||
// File constants
|
||||
private final Path faviconFile;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public EXEL4JLauncherBinary(LaunchServer server) {
|
||||
super(server, server.dir.resolve(server.config.binaryName + ".exe"));
|
||||
faviconFile = server.dir.resolve("favicon.ico");
|
||||
|
|
|
@ -71,17 +71,17 @@ private static ZipEntry newEntry(String fileName) {
|
|||
return newZipEntry(Launcher.RUNTIME_DIR + IOHelper.CROSS_SEPARATOR + fileName);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final Path runtimeDir;
|
||||
public final Path guardDir;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final Path initScriptFile;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final Path obfJar;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||
super(server, server.dir.resolve(server.config.binaryName + ".jar"),
|
||||
server.dir.resolve(server.config.binaryName + (server.config.sign.enabled ? "-sign.jar" : "-obf.jar")));
|
||||
|
@ -252,7 +252,7 @@ private void stdBuild() throws IOException {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void tryUnpackRuntime() throws IOException {
|
||||
// Verify is runtime dir unpacked
|
||||
if (IOHelper.isDir(runtimeDir))
|
||||
|
@ -271,7 +271,7 @@ public void tryUnpackRuntime() throws IOException {
|
|||
}
|
||||
}
|
||||
}
|
||||
@LauncherAPI
|
||||
|
||||
public void tryUnpackGuard() throws IOException {
|
||||
// Verify is runtime dir unpacked
|
||||
if (IOHelper.isDir(guardDir))
|
||||
|
|
|
@ -10,46 +10,46 @@
|
|||
import ru.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
public abstract class LauncherBinary {
|
||||
@LauncherAPI
|
||||
|
||||
protected final LaunchServer server;
|
||||
@LauncherAPI
|
||||
|
||||
protected final Path binaryFile;
|
||||
protected final Path syncBinaryFile;
|
||||
private volatile SignedBytesHolder binary;
|
||||
private volatile byte[] hash;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected LauncherBinary(LaunchServer server, Path binaryFile) {
|
||||
this.server = server;
|
||||
this.binaryFile = binaryFile;
|
||||
syncBinaryFile = binaryFile;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected LauncherBinary(LaunchServer server, Path binaryFile, Path syncBinaryFile) {
|
||||
this.server = server;
|
||||
this.binaryFile = binaryFile;
|
||||
this.syncBinaryFile = syncBinaryFile;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract void build() throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final boolean exists() {
|
||||
return IOHelper.isFile(syncBinaryFile);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final SignedBytesHolder getBytes() {
|
||||
return binary;
|
||||
}
|
||||
@LauncherAPI
|
||||
|
||||
public final byte[] getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final boolean sync() throws IOException {
|
||||
boolean exists = exists();
|
||||
binary = exists ? new SignedBytesHolder(IOHelper.read(syncBinaryFile), server.privateKey) : null;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import ru.gravit.launchserver.LaunchServer;
|
||||
|
||||
public abstract class Command {
|
||||
@LauncherAPI
|
||||
|
||||
protected static String parseUsername(String username) throws CommandException {
|
||||
try {
|
||||
return VerifyHelper.verifyUsername(username);
|
||||
|
@ -16,7 +16,7 @@ protected static String parseUsername(String username) throws CommandException {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected static UUID parseUUID(String s) throws CommandException {
|
||||
try {
|
||||
return UUID.fromString(s);
|
||||
|
@ -25,24 +25,24 @@ protected static UUID parseUUID(String s) throws CommandException {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final LaunchServer server;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected Command(LaunchServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract String getArgsDescription(); // "<required> [optional]"
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract String getUsageDescription();
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract void invoke(String... args) throws Exception;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final void verifyArgs(String[] args, int min) throws CommandException {
|
||||
if (args.length < min)
|
||||
throw new CommandException("Command usage: " + getArgsDescription());
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
public final class CommandException extends Exception {
|
||||
private static final long serialVersionUID = -6588814993972117772L;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public CommandException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public CommandException(Throwable exc) {
|
||||
super(exc);
|
||||
}
|
||||
|
|
|
@ -120,18 +120,18 @@ protected CommandHandler(LaunchServer server) {
|
|||
registerCommand("unban", new UnbanCommand(server));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract void bell() throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract void clear() throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final Map<String, Command> commandsMap() {
|
||||
return Collections.unmodifiableMap(commands);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final void eval(String line, boolean bell) {
|
||||
LogHelper.info("Command '%s'", line);
|
||||
|
||||
|
@ -148,7 +148,7 @@ public final void eval(String line, boolean bell) {
|
|||
eval(args, bell);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final void eval(String[] args, boolean bell) {
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
@ -171,7 +171,7 @@ public final void eval(String[] args, boolean bell) {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final Command lookup(String name) throws CommandException {
|
||||
Command command = commands.get(name);
|
||||
if (command == null)
|
||||
|
@ -179,7 +179,7 @@ public final Command lookup(String name) throws CommandException {
|
|||
return command;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract String readLine() throws IOException;
|
||||
|
||||
private void readLoop() throws IOException {
|
||||
|
@ -187,7 +187,7 @@ private void readLoop() throws IOException {
|
|||
eval(line, true);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public final void registerCommand(String name, Command command) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(commands, name, Objects.requireNonNull(command, "command"),
|
||||
|
|
|
@ -54,12 +54,12 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
|
||||
private static final String JSON_EXTENSION = ".json";
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static Path resolveIndexFile(Path assetDir, String name) {
|
||||
return assetDir.resolve(INDEXES_DIR).resolve(name + JSON_EXTENSION);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static Path resolveObjectFile(Path assetDir, String hash) {
|
||||
return assetDir.resolve(OBJECTS_DIR).resolve(hash.substring(0, 2)).resolve(hash);
|
||||
}
|
||||
|
|
|
@ -8,32 +8,32 @@
|
|||
import ru.gravit.launchserver.socket.Client;
|
||||
|
||||
public class SessionManager implements NeedGarbageCollection {
|
||||
@LauncherAPI
|
||||
|
||||
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
|
||||
public static final boolean NON_GARBAGE_SERVER = true;
|
||||
private Set<Client> clientSet = new HashSet<>(128);
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public boolean addClient(Client client) {
|
||||
clientSet.add(client);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void garbageCollection() {
|
||||
long time = System.currentTimeMillis();
|
||||
clientSet.removeIf(c -> (c.timestamp + SESSION_TIMEOUT < time) && ((c.type == Client.Type.USER) || ((c.type == Client.Type.SERVER) && !NON_GARBAGE_SERVER ) ));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public Client getClient(long session) {
|
||||
for (Client c : clientSet)
|
||||
if (c.session == session) return c;
|
||||
return null;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public Client getOrNewClient(long session) {
|
||||
for (Client c : clientSet)
|
||||
if (c.session == session) return c;
|
||||
|
@ -42,7 +42,7 @@ public Client getOrNewClient(long session) {
|
|||
return newClient;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void updateClient(long session) {
|
||||
for (Client c : clientSet) {
|
||||
if (c.session == session) {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
public abstract class Response {
|
||||
@FunctionalInterface
|
||||
public interface Factory<R> {
|
||||
@LauncherAPI
|
||||
|
||||
Response newResponse(LaunchServer server, long id, HInput input, HOutput output, String ip);
|
||||
}
|
||||
|
||||
|
@ -57,24 +57,24 @@ public static void registerResponses() {
|
|||
registerResponse(RequestType.SERVERAUTH.getNumber(), AuthServerResponse::new);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static void requestError(String message) throws RequestException {
|
||||
throw new RequestException(message);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final LaunchServer server;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final HInput input;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final HOutput output;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final String ip;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final long session;
|
||||
|
||||
protected Response(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
||||
|
@ -85,20 +85,20 @@ protected Response(LaunchServer server, long session, HInput input, HOutput outp
|
|||
this.session = session;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final void debug(String message) {
|
||||
LogHelper.subDebug("#%d %s", session, message);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected final void debug(String message, Object... args) {
|
||||
debug(String.format(message, args));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract void reply() throws Exception;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic") // Intentionally not static
|
||||
protected final void writeNoError(HOutput output) throws IOException {
|
||||
output.writeString("", 0);
|
||||
|
|
|
@ -51,7 +51,7 @@ public final class NettyServerSocketHandler implements Runnable, AutoCloseable {
|
|||
private static final String WEBSOCKET_PATH = "/api";
|
||||
private static SSLServerSocketFactory ssf;
|
||||
private static final ThreadFactory THREAD_FACTORY = r -> CommonHelper.newThread("Network Thread", true, r);
|
||||
@LauncherAPI
|
||||
|
||||
public volatile boolean logConnections = Boolean.getBoolean("launcher.logConnections");
|
||||
|
||||
private final AtomicReference<ServerSocket> serverSocket = new AtomicReference<>();
|
||||
|
@ -191,14 +191,14 @@ public void initChannel(NioSocketChannel ch) {
|
|||
*/
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void registerCustomResponse(String name, Response.Factory factory) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(customResponses, name, Objects.requireNonNull(factory, "factory"),
|
||||
String.format("Custom response has been already registered: '%s'", name));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
@ -214,13 +214,13 @@ public void setListener(Listener listener) {
|
|||
}
|
||||
|
||||
public interface Listener {
|
||||
@LauncherAPI
|
||||
|
||||
boolean onConnect(long id, InetAddress address);
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
void onDisconnect(long id, Exception e);
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
boolean onHandshake(long id, Integer type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,19 +19,19 @@
|
|||
|
||||
public final class ServerSocketHandler implements Runnable, AutoCloseable {
|
||||
public interface Listener {
|
||||
@LauncherAPI
|
||||
|
||||
boolean onConnect(InetAddress address);
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
void onDisconnect(Exception e);
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
boolean onHandshake(long session, Integer type);
|
||||
}
|
||||
|
||||
private static final ThreadFactory THREAD_FACTORY = r -> CommonHelper.newThread("Network Thread", true, r);
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public volatile boolean logConnections = Boolean.getBoolean("launcher.logConnections");
|
||||
// Instance
|
||||
private final LaunchServer server;
|
||||
|
@ -109,7 +109,7 @@ public void run() {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public Texture getSkinTexture(UUID uuid, String username, String client) throws
|
|||
return getProvider().getSkinTexture(uuid, username, client);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void setBackend(TextureProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public abstract class TextureProvider extends ConfigObject implements AutoClosea
|
|||
private static final Map<String, Adapter<TextureProvider>> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2);
|
||||
private static boolean registredProv = false;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static TextureProvider newProvider(String name, BlockConfigEntry block) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
Adapter<TextureProvider> authHandlerAdapter = VerifyHelper.getMapValue(TEXTURE_PROVIDERS, name,
|
||||
|
@ -24,7 +24,7 @@ public static TextureProvider newProvider(String name, BlockConfigEntry block) {
|
|||
return authHandlerAdapter.convert(block);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static void registerProvider(String name, Adapter<TextureProvider> adapter) {
|
||||
VerifyHelper.putIfAbsent(TEXTURE_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
String.format("Texture provider has been already registered: '%s'", name));
|
||||
|
@ -41,7 +41,7 @@ public static void registerProviders() {
|
|||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
protected TextureProvider(BlockConfigEntry block) {
|
||||
super(block);
|
||||
}
|
||||
|
@ -49,9 +49,9 @@ protected TextureProvider(BlockConfigEntry block) {
|
|||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract Texture getCloakTexture(UUID uuid, String username, String client) throws IOException;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public abstract Texture getSkinTexture(UUID uuid, String username, String client) throws IOException;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public final class LauncherConfig extends StreamObject {
|
|||
public static final String ADDRESS_OVERRIDE = System.getProperty(ADDRESS_OVERRIDE_PROPERTY, null);
|
||||
private static final AutogenConfig config = new AutogenConfig();
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static AutogenConfig getAutogenConfig() {
|
||||
return config;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
public PublicURLClassLoader classloader;
|
||||
protected ModuleContext context;
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public void autoload(Path dir) throws IOException {
|
||||
LogHelper.info("Load modules");
|
||||
if (Files.notExists(dir)) Files.createDirectory(dir);
|
||||
|
@ -70,7 +70,7 @@ public void close() {
|
|||
}
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void initModules() {
|
||||
for (Module m : modules) {
|
||||
m.init(context);
|
||||
|
@ -79,13 +79,13 @@ public void initModules() {
|
|||
}
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void load(Module module) {
|
||||
modules.add(module);
|
||||
}
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void load(Module module, boolean preload) {
|
||||
load(module);
|
||||
if (!preload) module.init(context);
|
||||
|
@ -93,7 +93,7 @@ public void load(Module module, boolean preload) {
|
|||
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void loadModule(URL jarpath, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException, URISyntaxException, IOException {
|
||||
JarFile f = new JarFile(Paths.get(jarpath.toURI()).toString());
|
||||
Manifest m = f.getManifest();
|
||||
|
@ -103,7 +103,7 @@ public void loadModule(URL jarpath, boolean preload) throws ClassNotFoundExcepti
|
|||
}
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void loadModule(URL jarpath, String classname, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||
classloader.addURL(jarpath);
|
||||
Class<?> moduleclass = Class.forName(classname, true, classloader);
|
||||
|
@ -124,7 +124,7 @@ public void postInitModules() {
|
|||
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void preInitModules() {
|
||||
for (Module m : modules) {
|
||||
m.preInit(context);
|
||||
|
@ -133,7 +133,7 @@ public void preInitModules() {
|
|||
}
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void printModules() {
|
||||
for (Module m : modules)
|
||||
LogHelper.info("Module %s version: %s", m.getName(), m.getVersion());
|
||||
|
@ -141,7 +141,7 @@ public void printModules() {
|
|||
}
|
||||
|
||||
@Override
|
||||
@LauncherAPI
|
||||
|
||||
public void registerModule(Module module, boolean preload) {
|
||||
load(module, preload);
|
||||
LogHelper.info("Module %s version: %s registered", module.getName(), module.getVersion());
|
||||
|
|
|
@ -39,10 +39,8 @@ public static OS byName(String name) {
|
|||
}
|
||||
|
||||
// MXBeans exports
|
||||
@LauncherAPI
|
||||
public static final RuntimeMXBean RUNTIME_MXBEAN = ManagementFactory.getRuntimeMXBean();
|
||||
|
||||
@LauncherAPI
|
||||
public static final OperatingSystemMXBean OPERATING_SYSTEM_MXBEAN =
|
||||
ManagementFactory.getOperatingSystemMXBean();
|
||||
// System properties
|
||||
|
@ -60,10 +58,8 @@ public static OS byName(String name) {
|
|||
@LauncherAPI
|
||||
public static final SecurityManager SECURITY_MANAGER = System.getSecurityManager();
|
||||
// Public static fields
|
||||
@LauncherAPI
|
||||
public static final Runtime RUNTIME = Runtime.getRuntime();
|
||||
|
||||
@LauncherAPI
|
||||
public static final ClassLoader LOADER = ClassLoader.getSystemClassLoader();
|
||||
|
||||
static {
|
||||
|
@ -76,18 +72,18 @@ public static OS byName(String name) {
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
@LauncherAPI
|
||||
|
||||
public static void addClassPath(URL url) {
|
||||
throw new IllegalArgumentException("Method Deprecated");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@LauncherAPI
|
||||
|
||||
public static void addNativePath(Path path) {
|
||||
throw new IllegalArgumentException("Method Deprecated");
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static void appendVars(ProcessBuilder builder, Map<String, String> vars) {
|
||||
builder.environment().putAll(vars);
|
||||
}
|
||||
|
@ -111,17 +107,17 @@ public static void fullGC() {
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
@LauncherAPI
|
||||
|
||||
public static Certificate[] getCertificates(String resource) {
|
||||
throw new IllegalArgumentException("Method Deprecated");
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static String[] getClassPath() {
|
||||
return System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static URL[] getClassPathURL() {
|
||||
String[] cp = System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
URL[] list = new URL[cp.length];
|
||||
|
@ -175,7 +171,7 @@ public static String systemToJvmProperty(String name) {
|
|||
return String.format("-D%s=%s", name, System.getProperties().getProperty(name));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
||||
public static void verifySystemProperties(Class<?> mainClass, boolean requireSystem) {
|
||||
Locale.setDefault(Locale.US);
|
||||
// Verify class loader
|
||||
|
|
Loading…
Reference in a new issue