gradle sucks etc
This commit is contained in:
parent
72b4edf48b
commit
b0d4a7d061
25 changed files with 463 additions and 123 deletions
|
|
@ -4,7 +4,6 @@ plugins {
|
|||
}
|
||||
|
||||
group = "de.kentoj.scrow"
|
||||
version = "0.1"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
@ -25,4 +24,27 @@ dependencies {
|
|||
|
||||
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-velocity
|
||||
implementation("de.kentoj.scrow:kencommandapi-velocity")
|
||||
}
|
||||
|
||||
val generateBuildInfo by tasks.registering {
|
||||
val outputDir = layout.buildDirectory.dir("generated/sources/buildInfo")
|
||||
outputs.dir(outputDir)
|
||||
doLast {
|
||||
val file = outputDir.get()
|
||||
.file("de/kentoj/scrow/generated/BuildInfo.java")
|
||||
.asFile
|
||||
file.parentFile.mkdirs()
|
||||
file.writeText(
|
||||
"""
|
||||
package de.kentoj.scrow.generated;
|
||||
public final class BuildInfo {
|
||||
private BuildInfo() {}
|
||||
public static final String VERSION = "${project.version}";
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
sourceSets.main {
|
||||
java.srcDir(generateBuildInfo)
|
||||
}
|
||||
|
|
@ -7,13 +7,16 @@ import de.kentoj.scrow.corevelocity.command.OnlineCommand;
|
|||
import de.kentoj.scrow.corevelocity.privmsg.LastTargetCache;
|
||||
import de.kentoj.scrow.corevelocity.privmsg.MsgCommand;
|
||||
import de.kentoj.scrow.corevelocity.privmsg.ReplyCommand;
|
||||
import de.kentoj.scrow.corevelocity.server.SendPlayerWatchdog;
|
||||
import de.kentoj.scrow.corevelocity.server.ServerRegisterWatchdog;
|
||||
import de.kentoj.scrow.generated.BuildInfo; // may not resolve until building for the first time
|
||||
import de.kentoj.scrow.velocity.ScrowAPI;
|
||||
import lombok.extern.java.Log;
|
||||
|
||||
@Plugin(
|
||||
id = "corevelocity",
|
||||
name = "CoreVelocity",
|
||||
version = "0.1"
|
||||
version = BuildInfo.VERSION // may not resolve until building for the first time
|
||||
)
|
||||
@Log
|
||||
public class CoreVelocityPlugin {
|
||||
|
|
|
|||
|
|
@ -1,29 +1,22 @@
|
|||
package de.kentoj.scrow.corevelocity;
|
||||
|
||||
import com.mongodb.ConnectionString;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.reactivestreams.client.MongoClient;
|
||||
import com.mongodb.reactivestreams.client.MongoClients;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.kentoj.kencommandapi.VelocityKenCommandApi;
|
||||
import de.kentoj.scrow.velocity.ScrowAPI;
|
||||
import de.kentoj.scrowlib.connection.DatabaseConnectionFactoryImpl;
|
||||
import de.kentoj.scrowlib.servermanager.ServerManagerImpl;
|
||||
import io.nats.client.Nats;
|
||||
import io.nats.client.Options;
|
||||
import io.r2dbc.spi.ConnectionFactories;
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bson.UuidRepresentation;
|
||||
import org.bson.codecs.configuration.CodecRegistries;
|
||||
import org.bson.codecs.pojo.PojoCodecProvider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class ScrowAPISurface {
|
||||
|
||||
private static @Nullable MongoClient mongoClient;
|
||||
|
||||
public static void initScrowAPI(ProxyServer server, boolean enableDatabase) {
|
||||
try {
|
||||
String natsHost = System.getenv("HOST_NATS");
|
||||
|
|
@ -37,20 +30,8 @@ public class ScrowAPISurface {
|
|||
}
|
||||
|
||||
if (enableDatabase) {
|
||||
var pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
|
||||
var codecRegistry = CodecRegistries.fromRegistries(
|
||||
MongoClientSettings.getDefaultCodecRegistry(),
|
||||
CodecRegistries.fromProviders(pojoCodecProvider)
|
||||
);
|
||||
String mongoHost = System.getenv("HOST_MONGO");
|
||||
var settings = MongoClientSettings.builder()
|
||||
.codecRegistry(codecRegistry)
|
||||
.uuidRepresentation(UuidRepresentation.STANDARD)
|
||||
.applyConnectionString(new ConnectionString(mongoHost))
|
||||
.build();
|
||||
|
||||
mongoClient = MongoClients.create(settings);
|
||||
ScrowAPI.setDatabase(mongoClient.getDatabase("scrow"));
|
||||
ConnectionFactory factory = ConnectionFactories.get(System.getenv("HOST_POSTGRES"));
|
||||
ScrowAPI.setDbConFactory(new DatabaseConnectionFactoryImpl(factory));
|
||||
}
|
||||
|
||||
ScrowAPI.setServerManager(new ServerManagerImpl(ScrowAPI.getNats()));
|
||||
|
|
@ -59,8 +40,10 @@ public class ScrowAPISurface {
|
|||
}
|
||||
|
||||
public static void destroyScrowAPI() {
|
||||
if (mongoClient != null) {
|
||||
mongoClient.close();
|
||||
try {
|
||||
ScrowAPI.getDbConFactory().close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.scrow.corevelocity;
|
||||
package de.kentoj.scrow.corevelocity.server;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.kentoj.scrowlib.messaging.NatsRepository;
|
||||
|
|
@ -22,10 +22,8 @@ public class SendPlayerWatchdog {
|
|||
|
||||
public void listen() {
|
||||
natsRepo.subscribe("proxy.send-player")
|
||||
.flatMap(msg ->
|
||||
handleSendPlayer(SafeResult.unwrap(msg))
|
||||
.flatMap(result -> natsRepo.publishSafeResult(msg.getReplyTo(), SafeResult.wrap(result)))
|
||||
.onErrorResume(err -> natsRepo.publishSafeResult(msg.getReplyTo(), SafeResult.wrap(err)))
|
||||
.flatMap(ctx ->
|
||||
SafeResult.mono(handleSendPlayer(ctx.getDocument()))
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
|
@ -1,13 +1,14 @@
|
|||
package de.kentoj.scrow.corevelocity;
|
||||
package de.kentoj.scrow.corevelocity.server;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import de.kentoj.scrowlib.messaging.DocumentRepository;
|
||||
import de.kentoj.scrowlib.messaging.NatsRepository;
|
||||
import de.kentoj.scrowlib.messaging.SubscriptionContext;
|
||||
import de.kentoj.scrowlib.messaging.respose.SafeResult;
|
||||
import de.kentoj.scrowlib.servermanager.ServerManager;
|
||||
import io.nats.client.Connection;
|
||||
import lombok.extern.java.Log;
|
||||
import org.bson.Document;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
|
@ -28,28 +29,26 @@ public class ServerRegisterWatchdog {
|
|||
|
||||
public void listen() {
|
||||
natsRepo.subscribe("crown.set-state")
|
||||
.map(SafeResult::unwrap)
|
||||
.concatMap(doc -> {
|
||||
var state = doc.getString("state");
|
||||
var handle = doc.getString("handle");
|
||||
return handleStateChange(state, handle);
|
||||
.flatMap(ctx -> {
|
||||
var state = ctx.getDocument().getString("state");
|
||||
var handle = ctx.getDocument().getString("handle");
|
||||
return handleStateChange(ctx, state, handle)
|
||||
.then(Mono.fromRunnable(() -> {
|
||||
natsRepo.publishSafeResult(ctx.getMsg().getReplyTo(), SafeResult.wrap(new Document()));
|
||||
}));
|
||||
})
|
||||
.subscribe(null, e -> log.throwing(getClass().getName(), "listen", e));
|
||||
}
|
||||
|
||||
private @NotNull Mono<@NotNull Void> handleStateChange(String state, String handle) {
|
||||
private @NotNull Mono<@NotNull Void> handleStateChange(SubscriptionContext ctx, String state, String handle) {
|
||||
return switch (state) {
|
||||
case "UP" -> serverManager.getInfo(handle)
|
||||
.doOnNext(instance -> {
|
||||
log.info("registering " + handle);
|
||||
server.registerServer(new ServerInfo(handle, new InetSocketAddress(instance.getPort())));
|
||||
})
|
||||
.doOnNext(instance ->
|
||||
server.registerServer(new ServerInfo(handle, new InetSocketAddress(instance.getPort()))))
|
||||
.then();
|
||||
case "DOWN" -> serverManager.getInfo(handle)
|
||||
.doOnNext(instance -> {
|
||||
log.info("unregistering " + handle);
|
||||
server.unregisterServer(new ServerInfo(handle, new InetSocketAddress(instance.getPort())));
|
||||
})
|
||||
.doOnNext(instance ->
|
||||
server.unregisterServer(new ServerInfo(handle, new InetSocketAddress(instance.getPort()))))
|
||||
.then();
|
||||
default -> Mono.empty();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue