From 20e092d9587937b63daee8f0faff4d1d1c68d5b9 Mon Sep 17 00:00:00 2001 From: azurejelly <178000437+azurejelly@users.noreply.github.com> Date: Tue, 31 Dec 2024 04:12:00 -0500 Subject: [PATCH] build: remove `fabric` and `sponge` --- fabric/build.gradle.kts | 74 ---- .../votifier/fabric/NuVotifier.java | 270 --------------- .../votifier/fabric/SLF4JLogger.java | 47 --- .../fabric/cmd/NuVotifierCommand.java | 66 ---- .../votifier/fabric/config/ConfigLoader.java | 54 --- .../votifier/fabric/config/FabricConfig.java | 35 -- .../votifier/fabric/event/VoteListener.java | 17 - .../FabricMessagingForwardingSink.java | 39 --- fabric/src/main/resources/fabric.mod.json | 23 -- sponge/build.gradle.kts | 97 ------ .../votifier/sponge/NuVotifier.java | 326 ------------------ .../votifier/sponge/SLF4JLogger.java | 47 --- .../votifier/sponge/SpongeScheduler.java | 43 --- .../votifier/sponge/cmd/NVReloadCmd.java | 28 -- .../votifier/sponge/cmd/TestVoteCmd.java | 40 --- .../votifier/sponge/config/ConfigLoader.java | 40 --- .../votifier/sponge/config/SpongeConfig.java | 106 ------ .../votifier/sponge/event/VotifierEvent.java | 28 -- .../SpongePluginMessagingForwardingSink.java | 52 --- .../votifier/sponge/spongeConfig.yml | 40 --- 20 files changed, 1472 deletions(-) delete mode 100644 fabric/build.gradle.kts delete mode 100644 fabric/src/main/java/com/vexsoftware/votifier/fabric/NuVotifier.java delete mode 100644 fabric/src/main/java/com/vexsoftware/votifier/fabric/SLF4JLogger.java delete mode 100644 fabric/src/main/java/com/vexsoftware/votifier/fabric/cmd/NuVotifierCommand.java delete mode 100644 fabric/src/main/java/com/vexsoftware/votifier/fabric/config/ConfigLoader.java delete mode 100644 fabric/src/main/java/com/vexsoftware/votifier/fabric/config/FabricConfig.java delete mode 100644 fabric/src/main/java/com/vexsoftware/votifier/fabric/event/VoteListener.java delete mode 100644 fabric/src/main/java/com/vexsoftware/votifier/fabric/forwarding/FabricMessagingForwardingSink.java delete mode 100644 fabric/src/main/resources/fabric.mod.json delete mode 100644 sponge/build.gradle.kts delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/NuVotifier.java delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/SLF4JLogger.java delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/SpongeScheduler.java delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/cmd/NVReloadCmd.java delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/cmd/TestVoteCmd.java delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/config/ConfigLoader.java delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/config/SpongeConfig.java delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/event/VotifierEvent.java delete mode 100644 sponge/src/main/java/com/vexsoftware/votifier/sponge/forwarding/SpongePluginMessagingForwardingSink.java delete mode 100644 sponge/src/main/resources/com/vexsoftware/votifier/sponge/spongeConfig.yml diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts deleted file mode 100644 index bd1cd0aa..00000000 --- a/fabric/build.gradle.kts +++ /dev/null @@ -1,74 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import net.fabricmc.loom.task.RemapJarTask - -plugins { - `java-library` - id("fabric-loom") -} - -applyPlatformAndCoreConfiguration() -applyCommonArtifactoryConfig() -applyShadowConfiguration() - -configurations { - compileClasspath.get().extendsFrom(create("shadeOnly")) -} - -dependencies { - minecraft("com.mojang:minecraft:1.19.4") - mappings(loom.officialMojangMappings()) - modImplementation("net.fabricmc:fabric-loader:0.14.19") - - // Make a set of all api modules we wish to use - setOf( - "fabric-api-base", - "fabric-command-api-v2", - "fabric-lifecycle-events-v1", - "fabric-networking-api-v1" - ).forEach { - // Add each module as a dependency - modImplementation(fabricApi.module(it, "0.80.0+1.19.4")) - } - - "implementation"("org.yaml:snakeyaml:2.0") - "modImplementation"("me.lucko:fabric-permissions-api:0.2-SNAPSHOT") - "include"("me.lucko:fabric-permissions-api:0.2-SNAPSHOT") - - - "api"(project(":nuvotifier-api")) - "api"(project(":nuvotifier-common")) -} - -tasks.named("processResources") { - val internalVersion = project.ext["internalVersion"] - inputs.property("internalVersion", internalVersion) - filesMatching("fabric.mod.json") { - expand("internalVersion" to internalVersion) - } -} - -tasks.named("shadowJar") { - configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"]) - - archiveClassifier.set("dist-dev") - - dependencies { - relocate("org.yaml", "com.vexsoftware.votifier.libs.org.yaml") - include(dependency(":nuvotifier-api")) - include(dependency(":nuvotifier-common")) - include(dependency("org.yaml:snakeyaml:")) - } - exclude("mappings/mappings.tiny") -} - -tasks.register("remapShadowJar") { - val shadowJar = tasks.getByName("shadowJar") - dependsOn(shadowJar) - inputFile.set(shadowJar.archiveFile) - archiveFileName.set(shadowJar.archiveFileName.get().replace(Regex("-dev\\.jar$"), ".jar")) - addNestedDependencies.set(true) -} - -tasks.named("assemble").configure { - dependsOn("remapShadowJar") -} diff --git a/fabric/src/main/java/com/vexsoftware/votifier/fabric/NuVotifier.java b/fabric/src/main/java/com/vexsoftware/votifier/fabric/NuVotifier.java deleted file mode 100644 index 435364d8..00000000 --- a/fabric/src/main/java/com/vexsoftware/votifier/fabric/NuVotifier.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.vexsoftware.votifier.fabric; - -import com.vexsoftware.votifier.VoteHandler; -import com.vexsoftware.votifier.fabric.cmd.NuVotifierCommand; -import com.vexsoftware.votifier.fabric.config.ConfigLoader; -import com.vexsoftware.votifier.fabric.event.VoteListener; -import com.vexsoftware.votifier.fabric.forwarding.FabricMessagingForwardingSink; -import com.vexsoftware.votifier.model.Vote; -import com.vexsoftware.votifier.net.VotifierServerBootstrap; -import com.vexsoftware.votifier.net.VotifierSession; -import com.vexsoftware.votifier.net.protocol.v1crypto.RSAIO; -import com.vexsoftware.votifier.net.protocol.v1crypto.RSAKeygen; -import com.vexsoftware.votifier.platform.LoggingAdapter; -import com.vexsoftware.votifier.platform.VotifierPlugin; -import com.vexsoftware.votifier.platform.scheduler.ScheduledExecutorServiceVotifierScheduler; -import com.vexsoftware.votifier.platform.scheduler.VotifierScheduler; -import com.vexsoftware.votifier.support.forwarding.ForwardedVoteListener; -import com.vexsoftware.votifier.support.forwarding.ForwardingVoteSink; -import com.vexsoftware.votifier.util.KeyCreator; -import net.fabricmc.api.DedicatedServerModInitializer; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.server.MinecraftServer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.security.Key; -import java.security.KeyPair; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Executors; - -public class NuVotifier implements VoteHandler, VotifierPlugin, ForwardedVoteListener, DedicatedServerModInitializer { - - public static final Logger LOGGER = LoggerFactory.getLogger("nuvotifier"); - - private SLF4JLogger loggerAdapter; - - - public File configDir = FabricLoader.getInstance().getConfigDir().toFile(); - - private VotifierScheduler scheduler; - - private boolean loadAndBind() { - // Load configuration. - ConfigLoader.loadConfig(this); - - /* - * Create RSA directory and keys if it does not exist; otherwise, read - * keys. - */ - File rsaDirectory = new File(configDir, "rsa"); - try { - if (!rsaDirectory.exists()) { - if (!rsaDirectory.mkdir()) { - throw new RuntimeException("Unable to create the RSA key folder " + rsaDirectory); - } - keyPair = RSAKeygen.generate(2048); - RSAIO.save(rsaDirectory, keyPair); - } else { - keyPair = RSAIO.load(rsaDirectory); - } - } catch (Exception ex) { - LOGGER.error("Error creating or reading RSA tokens", ex); - return false; - } - - debug = ConfigLoader.getFabricConfig().debug; - - // Load Votifier tokens. - ConfigLoader.getFabricConfig().tokens.forEach((s, s2) -> { - tokens.put(s, KeyCreator.createKeyFrom(s2)); - LOGGER.info("Loaded token for website: " + s); - }); - - // Initialize the receiver. - final String host = ConfigLoader.getFabricConfig().host; - final int port = ConfigLoader.getFabricConfig().port; - - if (!debug) - LOGGER.info("QUIET mode enabled!"); - - if (port >= 0) { - final boolean disablev1 = ConfigLoader.getFabricConfig().disableV1Protocol; - if (disablev1) { - LOGGER.info("------------------------------------------------------------------------------"); - LOGGER.info("Votifier protocol v1 parsing has been disabled. Most voting websites do not"); - LOGGER.info("currently support the modern Votifier protocol in NuVotifier."); - LOGGER.info("------------------------------------------------------------------------------"); - } - - this.bootstrap = new VotifierServerBootstrap(host, port, this, disablev1); - this.bootstrap.start(err -> { - }); - } else { - LOGGER.info("------------------------------------------------------------------------------"); - LOGGER.info("Your Votifier port is less than 0, so we assume you do NOT want to start the"); - LOGGER.info("votifier port server! Votifier will not listen for votes over any port, and"); - LOGGER.info("will only listen for pluginMessaging forwarded votes!"); - LOGGER.info("------------------------------------------------------------------------------"); - } - - if (ConfigLoader.getFabricConfig().forwarding != null) { - String method = ConfigLoader.getFabricConfig().forwarding.method.toLowerCase(); //Default to lower case for case-insensitive searches - if ("none".equals(method)) { - LOGGER.info("Method none selected for vote forwarding: Votes will not be received from a forwarder."); - } else if ("pluginmessaging".equals(method)) { - String channel = ConfigLoader.getFabricConfig().forwarding.pluginMessaging.channel; - try { - forwardingMethod = new FabricMessagingForwardingSink(channel, this); - LOGGER.info("Receiving votes over PluginMessaging channel '" + channel + "'."); - } catch (RuntimeException e) { - LOGGER.error("NuVotifier could not set up PluginMessaging for vote forwarding!", e); - } - } else { - LOGGER.error("No vote forwarding method '" + method + "' known. Defaulting to noop implementation."); - } - } - return true; - } - - private void halt() { - // Shut down the network handlers. - if (bootstrap != null) { - bootstrap.shutdown(); - bootstrap = null; - } - - if (forwardingMethod != null) { - forwardingMethod.halt(); - forwardingMethod = null; - } - } - - public boolean reload() { - try { - halt(); - } catch (Exception ex) { - LOGGER.error("On halt, an exception was thrown. This may be fine!", ex); - } - - if (loadAndBind()) { - LOGGER.info("Reload was successful."); - return true; - } else { - try { - halt(); - LOGGER.error("On reload, there was a problem with the configuration. Votifier currently does nothing!"); - } catch (Exception ex) { - LOGGER.error("On reload, there was a problem loading, and we could not re-halt the server. Votifier is in an unstable state!", ex); - } - return false; - } - } - - /** - * The server bootstrap. - */ - private VotifierServerBootstrap bootstrap; - - /** - * The RSA key pair. - */ - private KeyPair keyPair; - - /** - * Debug mode flag - */ - private boolean debug; - - /** - * Keys used for websites. - */ - private final Map tokens = new HashMap<>(); - - private ForwardingVoteSink forwardingMethod; - - private MinecraftServer server; - - @Override - public void onInitializeServer() { - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> NuVotifierCommand.register(this, dispatcher)); - ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, success) -> this.reload()); - ServerLifecycleEvents.SERVER_STARTING.register(this::onServerStart); - ServerLifecycleEvents.SERVER_STOPPING.register(this::onServerStop); - } - - private void onServerStart(MinecraftServer server) { - this.server = server; - this.scheduler = new ScheduledExecutorServiceVotifierScheduler(Executors.newScheduledThreadPool(1)); - this.loggerAdapter = new SLF4JLogger(LOGGER); - if (!loadAndBind()) { - LOGGER.error("Votifier did not initialize properly!"); - } - } - - private void onServerStop(MinecraftServer server) { - halt(); - LOGGER.info("Votifier disabled."); - } - - public File getConfigDir() { - return configDir; - } - - @Override - public void onVoteReceived(Vote vote, VotifierSession.ProtocolVersion protocolVersion, String remoteAddress) { - if (debug) { - if (protocolVersion == VotifierSession.ProtocolVersion.ONE) { - LOGGER.info("Got a protocol v1 vote record from " + remoteAddress + " -> " + vote); - } else { - LOGGER.info("Got a protocol v2 vote record from " + remoteAddress + " -> " + vote); - } - } - this.fireVoteEvent(vote); - } - - @Override - public void onError(Throwable throwable, boolean alreadyHandledVote, String remoteAddress) { - if (debug) { - if (alreadyHandledVote) { - LOGGER.warn("Vote processed, however an exception " + - "occurred with a vote from " + remoteAddress, throwable); - } else { - LOGGER.warn("Unable to process vote from " + remoteAddress, throwable); - } - } else if (!alreadyHandledVote) { - LOGGER.warn("Unable to process vote from " + remoteAddress); - } - } - - @Override - public Map getTokens() { - return tokens; - } - - @Override - public KeyPair getProtocolV1Key() { - return keyPair; - } - - @Override - public LoggingAdapter getPluginLogger() { - return loggerAdapter; - } - - @Override - public VotifierScheduler getScheduler() { - return scheduler; - } - - @Override - public boolean isDebug() { - return debug; - } - - @Override - public void onForward(final Vote v) { - if (debug) { - LOGGER.info("Got a forwarded vote -> " + v); - } - fireVoteEvent(v); - } - - private void fireVoteEvent(final Vote vote) { - server.submit(() -> VoteListener.EVENT.invoker().onVote(vote)); - } -} diff --git a/fabric/src/main/java/com/vexsoftware/votifier/fabric/SLF4JLogger.java b/fabric/src/main/java/com/vexsoftware/votifier/fabric/SLF4JLogger.java deleted file mode 100644 index 7e9782ad..00000000 --- a/fabric/src/main/java/com/vexsoftware/votifier/fabric/SLF4JLogger.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.vexsoftware.votifier.fabric; - -import com.vexsoftware.votifier.platform.LoggingAdapter; -import org.slf4j.Logger; - -public class SLF4JLogger implements LoggingAdapter { - - private final Logger l; - public SLF4JLogger(Logger l) { - this.l = l; - } - - @Override - public void error(String s) { - l.error(s); - } - - @Override - public void error(String s, Object... o) { - l.error(s, o); - } - - @Override - public void error(String s, Throwable e, Object... o) { - l.error(s, e, o); - } - - @Override - public void warn(String s) { - l.warn(s); - } - - @Override - public void warn(String s, Object... o) { - l.warn(s, o); - } - - @Override - public void info(String s) { - l.info(s); - } - - @Override - public void info(String s, Object... o) { - l.info(s, o); - } -} diff --git a/fabric/src/main/java/com/vexsoftware/votifier/fabric/cmd/NuVotifierCommand.java b/fabric/src/main/java/com/vexsoftware/votifier/fabric/cmd/NuVotifierCommand.java deleted file mode 100644 index 41e984c2..00000000 --- a/fabric/src/main/java/com/vexsoftware/votifier/fabric/cmd/NuVotifierCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.vexsoftware.votifier.fabric.cmd; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.vexsoftware.votifier.fabric.NuVotifier; -import com.vexsoftware.votifier.model.Vote; -import com.vexsoftware.votifier.net.VotifierSession; -import com.vexsoftware.votifier.util.ArgsToVote; -import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.ChatFormatting; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.network.chat.Component; - -import java.util.function.Predicate; - -import static net.minecraft.commands.Commands.argument; -import static net.minecraft.commands.Commands.literal; - -public class NuVotifierCommand { - - private static NuVotifier plugin; - - public static void register(NuVotifier plugin, CommandDispatcher dispatcher) { - NuVotifierCommand.plugin = plugin; - Predicate reloadPerm = Permissions.require("nuvotifier.reload", 2); - Predicate testVotePerm = Permissions.require("nuvotifier.testvote", 2); - dispatcher.register( - literal("nuvotifier").requires(reloadPerm.or(testVotePerm)) - .then( - literal("reload").requires(reloadPerm) - .executes(NuVotifierCommand::reload) - ).then( - literal("testvote").then( - argument("args", StringArgumentType.greedyString()).requires(testVotePerm) - .executes(NuVotifierCommand::sendTestVote) - ) - ) - ); - } - - private static int reload(CommandContext ctx) { - ctx.getSource().sendSuccess(Component.literal("Reloading NuVotifier...").withStyle(ChatFormatting.GRAY), false); - if (plugin.reload()) { - return 1; - } else { - return 0; - } - } - - private static int sendTestVote(CommandContext ctx) { - Vote v; - try { - String args = StringArgumentType.getString(ctx, "args"); - v = ArgsToVote.parse(args.split(" ")); - } catch (IllegalArgumentException e) { - ctx.getSource().sendFailure(Component.literal("Error while parsing arguments to create test vote: " + e.getMessage()).withStyle(ChatFormatting.DARK_RED)); - ctx.getSource().sendFailure(Component.literal("Usage hint: /testvote [username] [serviceName=?] [username=?] [address=?] [localTimestamp=?] [timestamp=?]").withStyle(ChatFormatting.GRAY)); - return 0; - } - plugin.onVoteReceived(v, VotifierSession.ProtocolVersion.TEST, "localhost.test"); - - return 1; - } - -} diff --git a/fabric/src/main/java/com/vexsoftware/votifier/fabric/config/ConfigLoader.java b/fabric/src/main/java/com/vexsoftware/votifier/fabric/config/ConfigLoader.java deleted file mode 100644 index fd9d3643..00000000 --- a/fabric/src/main/java/com/vexsoftware/votifier/fabric/config/ConfigLoader.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.vexsoftware.votifier.fabric.config; - -import com.vexsoftware.votifier.fabric.NuVotifier; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.nodes.Tag; -import org.yaml.snakeyaml.representer.Representer; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; - -public class ConfigLoader { - - private static FabricConfig fabricConfig; - private static Yaml yaml; - - public static void loadConfig(NuVotifier pl) { - DumperOptions options = new DumperOptions(); - options.setPrettyFlow(true); - - Representer representer = new Representer(options); - representer.addClassTag(FabricConfig.class, Tag.MAP); - yaml = new Yaml(representer, options); - - if (!pl.getConfigDir().exists()) { - if (!pl.getConfigDir().mkdirs()) { - throw new RuntimeException("Unable to create the plugin data folder " + pl.getConfigDir()); - } - } - try { - File config = new File(pl.getConfigDir(), "nuvotifier.yml"); - if (!config.exists()) { - if (!config.createNewFile()) { - throw new IOException("Unable to create the config file at " + config); - } - FileWriter fileWriter = new FileWriter(config); - // Save the default config - yaml.dump(new FabricConfig(), fileWriter); - fileWriter.flush(); - } - fabricConfig = yaml.loadAs(Files.newInputStream(config.toPath()), FabricConfig.class); - } catch (Exception e) { - NuVotifier.LOGGER.error("Could not load config.", e); - } - } - - public static FabricConfig getFabricConfig() { - return fabricConfig; - } - - -} diff --git a/fabric/src/main/java/com/vexsoftware/votifier/fabric/config/FabricConfig.java b/fabric/src/main/java/com/vexsoftware/votifier/fabric/config/FabricConfig.java deleted file mode 100644 index 39429701..00000000 --- a/fabric/src/main/java/com/vexsoftware/votifier/fabric/config/FabricConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.vexsoftware.votifier.fabric.config; - -import com.vexsoftware.votifier.util.TokenUtil; - -import java.util.Collections; -import java.util.Map; - -public class FabricConfig { - - public String host = "0.0.0.0"; - - public int port = 8192; - - public boolean debug = true; - - public boolean disableV1Protocol = false; - - public Map tokens = Collections.singletonMap("default", TokenUtil.newToken()); - - public Forwarding forwarding = new Forwarding(); - - public static class Forwarding { - - public String method = "none"; - - public PluginMessaging pluginMessaging = new PluginMessaging(); - - public static class PluginMessaging { - - public String channel = "nuvotifier:votes"; - - } - } - -} diff --git a/fabric/src/main/java/com/vexsoftware/votifier/fabric/event/VoteListener.java b/fabric/src/main/java/com/vexsoftware/votifier/fabric/event/VoteListener.java deleted file mode 100644 index 4e3058e8..00000000 --- a/fabric/src/main/java/com/vexsoftware/votifier/fabric/event/VoteListener.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.vexsoftware.votifier.fabric.event; - -import com.vexsoftware.votifier.model.Vote; -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; - -public interface VoteListener { - - Event EVENT = EventFactory.createArrayBacked(VoteListener.class, (voteListeners) -> (vote) -> { - for (VoteListener voteListener : voteListeners) { - voteListener.onVote(vote); - } - }); - - void onVote(Vote vote); - -} diff --git a/fabric/src/main/java/com/vexsoftware/votifier/fabric/forwarding/FabricMessagingForwardingSink.java b/fabric/src/main/java/com/vexsoftware/votifier/fabric/forwarding/FabricMessagingForwardingSink.java deleted file mode 100644 index 3ca42f41..00000000 --- a/fabric/src/main/java/com/vexsoftware/votifier/fabric/forwarding/FabricMessagingForwardingSink.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.vexsoftware.votifier.fabric.forwarding; - -import com.vexsoftware.votifier.fabric.NuVotifier; -import com.vexsoftware.votifier.support.forwarding.AbstractPluginMessagingForwardingSink; -import com.vexsoftware.votifier.support.forwarding.ForwardedVoteListener; -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; - -public class FabricMessagingForwardingSink extends AbstractPluginMessagingForwardingSink implements ServerPlayNetworking.PlayChannelHandler { - - private final String channel; - - public FabricMessagingForwardingSink(String channel, ForwardedVoteListener listener) { - super(listener); - this.channel = channel; - ServerPlayNetworking.registerGlobalReceiver(new ResourceLocation(channel), this); - } - - @Override - public void halt() { - ServerPlayNetworking.unregisterGlobalReceiver(new ResourceLocation(channel)); - } - - @Override - public void receive(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl handler, FriendlyByteBuf buf, PacketSender responseSender) { - byte[] data = new byte[buf.readableBytes()]; - buf.readBytes(data); - try { - this.handlePluginMessage(data); - } catch (Exception e) { - NuVotifier.LOGGER.error("There was an unknown error when processing a forwarded vote.", e); - } - } -} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json deleted file mode 100644 index 96db1715..00000000 --- a/fabric/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "schemaVersion": 1, - "id": "nuvotifier", - "version": "${internalVersion}", - "name": "NuVotifier", - "description": "Safe, smart, and secure Votifier server mod", - "authors": [ - "Drex" - ], - "license": "GPLv3", - "environment": "server", - "entrypoints": { - "server": [ - "com.vexsoftware.votifier.fabric.NuVotifier" - ] - }, - "depends": { - "fabric-api-base": "*", - "fabric-command-api-v2": "*", - "fabric-lifecycle-events-v1": "*", - "fabric-networking-api-v1": "*" - } -} diff --git a/sponge/build.gradle.kts b/sponge/build.gradle.kts deleted file mode 100644 index c84c6ef4..00000000 --- a/sponge/build.gradle.kts +++ /dev/null @@ -1,97 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import org.spongepowered.gradle.plugin.config.PluginLoaders -import org.spongepowered.plugin.metadata.model.PluginDependency - -plugins { - `java-library` - id("org.spongepowered.gradle.plugin") - id("net.kyori.blossom") -} - -applyPlatformAndCoreConfiguration() -applyCommonArtifactoryConfig() -applyShadowConfiguration() - -blossom { - replaceToken("@version@", project.ext["internalVersion"]) -} - -sponge { - apiVersion("7.2.0") - loader { - name(PluginLoaders.JAVA_PLAIN) - version("1.0") - } - - license("GNU General Public License v3.0") - - plugin("nuvotifier") { - displayName("NuVotifier") - entrypoint("com.vexsoftware.votifier.sponge.NuVotifier") - description("Safe, smart, and secure Votifier server plugin") - links { - source("https://github.com/NuVotifier/NuVotifier") - issues("https://github.com/NuVotifier/NuVotifier") - } - contributor("Ichbinjoe") { - description("Lead Developer") - } - dependency("spongeapi") { - loadOrder(PluginDependency.LoadOrder.AFTER) - optional(false) - version("7.2.0") - } - } -} - -repositories { - maven { - name = "sponge" - url = uri("https://repo.spongepowered.org/maven/") - } - mavenCentral() -} - -configurations { - compileClasspath.get().extendsFrom(create("shadeOnly")) -} - -dependencies { - compileOnly("org.spongepowered:spongeapi:7.2.0") - - "api"(project(":nuvotifier-api")) - "api"(project(":nuvotifier-common")) - "implementation"("redis.clients:jedis:${Versions.JEDIS}") -} - -tasks.named("jar") { - val projectVersion = project.version - inputs.property("projectVersion", projectVersion) - manifest { - attributes("Implementation-Version" to projectVersion) - } -} - -tasks.named("shadowJar") { - configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"]) - - dependencies { - include(dependency(":nuvotifier-api")) - include(dependency(":nuvotifier-common")) - } - - exclude("GradleStart**") - exclude(".cache") - exclude("LICENSE*") - exclude("META-INF/services/**") - exclude("META-INF/maven/**") - exclude("META-INF/versions/**") - exclude("org/intellij/**") - exclude("org/jetbrains/**") - exclude("**/module-info.class") - exclude("*.yml") -} - -tasks.named("assemble").configure { - dependsOn("shadowJar") -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/NuVotifier.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/NuVotifier.java deleted file mode 100644 index 89295eda..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/NuVotifier.java +++ /dev/null @@ -1,326 +0,0 @@ -package com.vexsoftware.votifier.sponge; - -import com.google.inject.Inject; -import com.vexsoftware.votifier.VoteHandler; -import com.vexsoftware.votifier.model.Vote; -import com.vexsoftware.votifier.net.VotifierServerBootstrap; -import com.vexsoftware.votifier.net.VotifierSession; -import com.vexsoftware.votifier.net.protocol.v1crypto.RSAIO; -import com.vexsoftware.votifier.net.protocol.v1crypto.RSAKeygen; -import com.vexsoftware.votifier.platform.LoggingAdapter; -import com.vexsoftware.votifier.platform.VotifierPlugin; -import com.vexsoftware.votifier.platform.scheduler.VotifierScheduler; -import com.vexsoftware.votifier.sponge.cmd.NVReloadCmd; -import com.vexsoftware.votifier.sponge.cmd.TestVoteCmd; -import com.vexsoftware.votifier.sponge.config.ConfigLoader; -import com.vexsoftware.votifier.sponge.event.VotifierEvent; -import com.vexsoftware.votifier.sponge.forwarding.SpongePluginMessagingForwardingSink; -import com.vexsoftware.votifier.support.forwarding.ForwardedVoteListener; -import com.vexsoftware.votifier.support.forwarding.ForwardingVoteSink; -import com.vexsoftware.votifier.support.forwarding.redis.*; -import com.vexsoftware.votifier.util.KeyCreator; -import org.slf4j.Logger; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.command.args.GenericArguments; -import org.spongepowered.api.command.spec.CommandSpec; -import org.spongepowered.api.config.ConfigDir; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.game.GameReloadEvent; -import org.spongepowered.api.event.game.state.GameStartedServerEvent; -import org.spongepowered.api.event.game.state.GameStoppingServerEvent; -import org.spongepowered.api.plugin.Plugin; -import org.spongepowered.api.text.Text; - -import java.io.File; -import java.security.Key; -import java.security.KeyPair; -import java.util.HashMap; -import java.util.Map; - -@Plugin(id = "nuvotifier", name = "NuVotifier", version = "@version@", authors = "Ichbinjoe", - description = "Safe, smart, and secure Votifier server plugin") -public class NuVotifier implements VoteHandler, VotifierPlugin, ForwardedVoteListener { - - @Inject - public Logger logger; - - private SLF4JLogger loggerAdapter; - - @Inject - @ConfigDir(sharedRoot = false) - public File configDir; - - private VotifierScheduler scheduler; - - private boolean loadAndBind() { - // Load configuration. - ConfigLoader.loadConfig(this); - - /* - * Create RSA directory and keys if it does not exist; otherwise, read - * keys. - */ - File rsaDirectory = new File(configDir, "rsa"); - try { - if (!rsaDirectory.exists()) { - if (!rsaDirectory.mkdir()) { - throw new RuntimeException("Unable to create the RSA key folder " + rsaDirectory); - } - keyPair = RSAKeygen.generate(2048); - RSAIO.save(rsaDirectory, keyPair); - } else { - keyPair = RSAIO.load(rsaDirectory); - } - } catch (Exception ex) { - logger.error("Error creating or reading RSA tokens", ex); - return false; - } - - debug = ConfigLoader.getSpongeConfig().debug; - - // Load Votifier tokens. - ConfigLoader.getSpongeConfig().tokens.forEach((s, s2) -> { - tokens.put(s, KeyCreator.createKeyFrom(s2)); - logger.info("Loaded token for website: " + s); - }); - - // Initialize the receiver. - final String host = ConfigLoader.getSpongeConfig().host; - final int port = ConfigLoader.getSpongeConfig().port; - - if (!debug) - logger.info("QUIET mode enabled!"); - - if (port >= 0) { - final boolean disablev1 = ConfigLoader.getSpongeConfig().disableV1Protocol; - if (disablev1) { - logger.info("------------------------------------------------------------------------------"); - logger.info("Votifier protocol v1 parsing has been disabled. Most voting websites do not"); - logger.info("currently support the modern Votifier protocol in NuVotifier."); - logger.info("------------------------------------------------------------------------------"); - } - - this.bootstrap = new VotifierServerBootstrap(host, port, this, disablev1); - this.bootstrap.start(err -> { - }); - } else { - getLogger().info("------------------------------------------------------------------------------"); - getLogger().info("Your Votifier port is less than 0, so we assume you do NOT want to start the"); - getLogger().info("votifier port server! Votifier will not listen for votes over any port, and"); - getLogger().info("will only listen for pluginMessaging forwarded votes!"); - getLogger().info("------------------------------------------------------------------------------"); - } - - if (ConfigLoader.getSpongeConfig().forwarding != null) { - String method = ConfigLoader.getSpongeConfig().forwarding.method.toLowerCase(); //Default to lower case for case-insensitive searches - if ("none".equals(method)) { - getLogger().info("Method none selected for vote forwarding: Votes will not be received from a forwarder."); - } else if ("pluginmessaging".equals(method)) { - String channel = ConfigLoader.getSpongeConfig().forwarding.pluginMessaging.channel; - try { - forwardingMethod = new SpongePluginMessagingForwardingSink(this, channel, this); - getLogger().info("Receiving votes over PluginMessaging channel '" + channel + "'."); - } catch (RuntimeException e) { - logger.error("NuVotifier could not set up PluginMessaging for vote forwarding!", e); - } - } else if ("redis".equals(method)) { - - // Load redis credentials - RedisCredentials redisCredentials = RedisCredentials.builder() - .host(ConfigLoader.getSpongeConfig().forwarding.redis.address) - .port(ConfigLoader.getSpongeConfig().forwarding.redis.port) - .password(ConfigLoader.getSpongeConfig().forwarding.redis.password) - .channel(ConfigLoader.getSpongeConfig().forwarding.redis.channel) - .build(); - - // Load redis pool parameters - RedisPoolConfiguration redisPoolConfiguration = RedisPoolConfiguration.builder() - .timeout(ConfigLoader.getSpongeConfig().forwarding.redis.poolSettings.timeout) - .maxTotal(ConfigLoader.getSpongeConfig().forwarding.redis.poolSettings.maxTotal) - .maxIdle(ConfigLoader.getSpongeConfig().forwarding.redis.poolSettings.maxIdle) - .minIdle(ConfigLoader.getSpongeConfig().forwarding.redis.poolSettings.minIdle) - .minEvictableIdleTime(ConfigLoader.getSpongeConfig().forwarding.redis.poolSettings.minEvictableIdleTime) - .timeBetweenEvictionRuns(ConfigLoader.getSpongeConfig().forwarding.redis.poolSettings.timeBetweenEvictionRuns) - .numTestsPerEvictionRun(ConfigLoader.getSpongeConfig().forwarding.redis.poolSettings.numTestsPerEvictionRun) - .blockWhenExhausted(ConfigLoader.getSpongeConfig().forwarding.redis.poolSettings.blockWhenExhausted) - .build(); - - forwardingMethod = new RedisForwardingSink(redisCredentials, redisPoolConfiguration, this); - } else { - logger.error("No vote forwarding method '" + method + "' known. Defaulting to noop implementation."); - } - } - return true; - } - - private void halt() { - // Shut down the network handlers. - if (bootstrap != null) { - bootstrap.shutdown(); - bootstrap = null; - } - - if (forwardingMethod != null) { - forwardingMethod.halt(); - forwardingMethod = null; - } - } - - public boolean reload() { - try { - halt(); - } catch (Exception ex) { - logger.error("On halt, an exception was thrown. This may be fine!", ex); - } - - if (loadAndBind()) { - logger.info("Reload was successful."); - return true; - } else { - try { - halt(); - logger.error("On reload, there was a problem with the configuration. Votifier currently does nothing!"); - } catch (Exception ex) { - logger.error("On reload, there was a problem loading, and we could not re-halt the server. Votifier is in an unstable state!", ex); - } - return false; - } - } - - @Listener - public void onServerStart(GameStartedServerEvent event) { - this.scheduler = new SpongeScheduler(this); - this.loggerAdapter = new SLF4JLogger(logger); - - CommandSpec nvreloadSpec = CommandSpec.builder() - .description(Text.of("Reloads NuVotifier")) - .permission("nuvotifier.reload") - .executor(new NVReloadCmd(this)).build(); - - Sponge.getCommandManager().register(this, nvreloadSpec, "nvreload"); - - CommandSpec testvoteSpec = CommandSpec.builder() - .arguments(GenericArguments.allOf(GenericArguments.string(Text.of("args")))) - .description(Text.of("Sends a test vote to the server's listeners")) - .permission("nuvotifier.testvote") - .executor(new TestVoteCmd(this)).build(); - - Sponge.getCommandManager().register(this, testvoteSpec, "testvote"); - - if (!loadAndBind()) { - gracefulExit(); - } - } - - @Listener - public void onGameReload(GameReloadEvent event) { - this.reload(); - } - - @Listener - public void onServerStop(GameStoppingServerEvent event) { - halt(); - logger.info("Votifier disabled."); - } - - public Logger getLogger() { - return logger; - } - - /** - * The server bootstrap. - */ - private VotifierServerBootstrap bootstrap; - - /** - * The RSA key pair. - */ - private KeyPair keyPair; - - /** - * Debug mode flag - */ - private boolean debug; - - /** - * Keys used for websites. - */ - private Map tokens = new HashMap<>(); - - private ForwardingVoteSink forwardingMethod; - - private void gracefulExit() { - logger.error("Votifier did not initialize properly!"); - } - - @Override - public LoggingAdapter getPluginLogger() { - return loggerAdapter; - } - - @Override - public VotifierScheduler getScheduler() { - return scheduler; - } - - public boolean isDebug() { - return debug; - } - - @Override - public Map getTokens() { - return tokens; - } - - @Override - public KeyPair getProtocolV1Key() { - return keyPair; - } - - public File getConfigDir() { - return configDir; - } - - @Override - public void onVoteReceived(final Vote vote, VotifierSession.ProtocolVersion protocolVersion, String remoteAddress) { - if (debug) { - if (protocolVersion == VotifierSession.ProtocolVersion.ONE) { - logger.info("Got a protocol v1 vote record from " + remoteAddress + " -> " + vote); - } else { - logger.info("Got a protocol v2 vote record from " + remoteAddress + " -> " + vote); - } - } - this.fireVoteEvent(vote); - } - - @Override - public void onError(Throwable throwable, boolean alreadyHandledVote, String remoteAddress) { - if (debug) { - if (alreadyHandledVote) { - logger.warn("Vote processed, however an exception " + - "occurred with a vote from " + remoteAddress, throwable); - } else { - logger.warn("Unable to process vote from " + remoteAddress, throwable); - } - } else if (!alreadyHandledVote) { - logger.warn("Unable to process vote from " + remoteAddress); - } - } - - @Override - public void onForward(final Vote v) { - if (debug) { - logger.info("Got a forwarded vote -> " + v); - } - fireVoteEvent(v); - } - - private void fireVoteEvent(final Vote vote) { - Sponge.getScheduler().createTaskBuilder() - .execute(() -> { - VotifierEvent event = new VotifierEvent(vote, Sponge.getCauseStackManager().getCurrentCause()); - Sponge.getEventManager().post(event); - }) - .submit(this); - } -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/SLF4JLogger.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/SLF4JLogger.java deleted file mode 100644 index 6375a172..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/SLF4JLogger.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.vexsoftware.votifier.sponge; - -import com.vexsoftware.votifier.platform.LoggingAdapter; -import org.slf4j.Logger; - -public class SLF4JLogger implements LoggingAdapter { - - private final Logger l; - public SLF4JLogger(Logger l) { - this.l = l; - } - - @Override - public void error(String s) { - l.error(s); - } - - @Override - public void error(String s, Object... o) { - l.error(s, o); - } - - @Override - public void error(String s, Throwable e, Object... o) { - l.error(s, e, o); - } - - @Override - public void warn(String s) { - l.warn(s); - } - - @Override - public void warn(String s, Object... o) { - l.warn(s, o); - } - - @Override - public void info(String s) { - l.info(s); - } - - @Override - public void info(String s, Object... o) { - l.info(s, o); - } -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/SpongeScheduler.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/SpongeScheduler.java deleted file mode 100644 index f58dc5fa..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/SpongeScheduler.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.vexsoftware.votifier.sponge; - -import com.vexsoftware.votifier.platform.scheduler.ScheduledVotifierTask; -import com.vexsoftware.votifier.platform.scheduler.VotifierScheduler; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.scheduler.Task; - -import java.util.concurrent.TimeUnit; - -class SpongeScheduler implements VotifierScheduler { - private final NuVotifier plugin; - - SpongeScheduler(NuVotifier plugin) { - this.plugin = plugin; - } - - private Task.Builder taskBuilder(Runnable runnable) { - return Sponge.getScheduler().createTaskBuilder().execute(runnable); - } - - @Override - public ScheduledVotifierTask delayedOnPool(Runnable runnable, int delay, TimeUnit unit) { - return new TaskWrapper(taskBuilder(runnable).delay(delay, unit).async().submit(plugin)); - } - - @Override - public ScheduledVotifierTask repeatOnPool(Runnable runnable, int delay, int repeat, TimeUnit unit) { - return new TaskWrapper(taskBuilder(runnable).delay(delay, unit).interval(repeat, unit).submit(plugin)); - } - - private static class TaskWrapper implements ScheduledVotifierTask { - private final Task task; - - private TaskWrapper(Task task) { - this.task = task; - } - - @Override - public void cancel() { - task.cancel(); - } - } -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/cmd/NVReloadCmd.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/cmd/NVReloadCmd.java deleted file mode 100644 index 56145531..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/cmd/NVReloadCmd.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vexsoftware.votifier.sponge.cmd; - -import com.vexsoftware.votifier.sponge.NuVotifier; -import org.spongepowered.api.command.CommandException; -import org.spongepowered.api.command.CommandResult; -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.command.args.CommandContext; -import org.spongepowered.api.command.spec.CommandExecutor; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.text.format.TextColors; - -public class NVReloadCmd implements CommandExecutor { - - private final NuVotifier plugin; - - public NVReloadCmd(NuVotifier plugin) { - this.plugin = plugin; - } - - @Override - public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { - src.sendMessage(Text.builder("Reloading NuVotifier...").color(TextColors.GRAY).build()); - if (plugin.reload()) - return CommandResult.success(); - else - return CommandResult.empty(); - } -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/cmd/TestVoteCmd.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/cmd/TestVoteCmd.java deleted file mode 100644 index 3aac7f1a..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/cmd/TestVoteCmd.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.vexsoftware.votifier.sponge.cmd; - -import com.vexsoftware.votifier.model.Vote; -import com.vexsoftware.votifier.net.VotifierSession; -import com.vexsoftware.votifier.sponge.NuVotifier; -import com.vexsoftware.votifier.util.ArgsToVote; -import org.spongepowered.api.command.CommandException; -import org.spongepowered.api.command.CommandResult; -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.command.args.CommandContext; -import org.spongepowered.api.command.spec.CommandExecutor; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.text.format.TextColors; - -import java.util.Collection; - -public class TestVoteCmd implements CommandExecutor { - - private final NuVotifier plugin; - - public TestVoteCmd(NuVotifier plugin) { - this.plugin = plugin; - } - - @Override - public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { - Vote v; - try { - Collection a = args.getAll("args"); - v = ArgsToVote.parse(a.toArray(new String[0])); - } catch (IllegalArgumentException e) { - sender.sendMessage(Text.builder("Error while parsing arguments to create test vote: " + e.getMessage()).color(TextColors.DARK_RED).build()); - sender.sendMessage(Text.builder("Usage hint: /testvote [username] [serviceName=?] [username=?] [address=?] [localTimestamp=?] [timestamp=?]").color(TextColors.GRAY).build()); - return CommandResult.empty(); - } - - plugin.onVoteReceived(v, VotifierSession.ProtocolVersion.TEST, "localhost.test"); - return CommandResult.success(); - } -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/config/ConfigLoader.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/config/ConfigLoader.java deleted file mode 100644 index 0ea0f594..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/config/ConfigLoader.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.vexsoftware.votifier.sponge.config; - -import com.google.common.reflect.TypeToken; -import com.vexsoftware.votifier.sponge.NuVotifier; -import ninja.leaping.configurate.ConfigurationNode; -import ninja.leaping.configurate.ConfigurationOptions; -import ninja.leaping.configurate.loader.ConfigurationLoader; -import ninja.leaping.configurate.yaml.YAMLConfigurationLoader; - -import java.io.File; -import java.io.IOException; - -public class ConfigLoader { - - private static SpongeConfig spongeConfig; - - public static void loadConfig(NuVotifier pl) { - if (!pl.getConfigDir().exists()) { - if (!pl.getConfigDir().mkdirs()) { - throw new RuntimeException("Unable to create the plugin data folder " + pl.getConfigDir()); - } - } - try { - File config = new File(pl.getConfigDir(), "config.yml"); - if (!config.exists() && !config.createNewFile()) { - throw new IOException("Unable to create the config file at " + config); - } - ConfigurationLoader loader = YAMLConfigurationLoader.builder().setFile(config).build(); - ConfigurationNode configNode = loader.load(ConfigurationOptions.defaults().setShouldCopyDefaults(true)); - spongeConfig = configNode.getValue(TypeToken.of(SpongeConfig.class), new SpongeConfig()); - loader.save(configNode); - } catch (Exception e) { - pl.getLogger().error("Could not load config.", e); - } - } - - public static SpongeConfig getSpongeConfig() { - return spongeConfig; - } -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/config/SpongeConfig.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/config/SpongeConfig.java deleted file mode 100644 index d92c3d11..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/config/SpongeConfig.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.vexsoftware.votifier.sponge.config; - -import com.vexsoftware.votifier.util.TokenUtil; -import ninja.leaping.configurate.objectmapping.Setting; -import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import org.spongepowered.api.Sponge; - -import java.util.Collections; -import java.util.Map; - -@ConfigSerializable -public class SpongeConfig { - - @Setting(comment = "The IP to listen to. Use 0.0.0.0 if you wish to listen to all interfaces on your server. (All IP addresses)\n" + - "This defaults to the IP you have configured your server to listen on, or 0.0.0.0 if you have not configured this.") - public String host = Sponge.getServer().getBoundAddress().isPresent() ? Sponge.getServer().getBoundAddress().get().getAddress().getHostAddress() : "0.0.0.0"; - - @Setting(comment = "Port to listen for new votes on") - public int port = 8192; - - @Setting(comment = "Whether or not to print debug messages. In a production system, this should be set to false.\n" + - "This is useful when initially setting up NuVotifier to ensure votes are being delivered.") - public boolean debug = true; - - @Setting( value = "disable-v1-protocol", comment = "Setting this option to true will disable handling of Protocol v1 packets. While the old protocol is not secure, this\n" + - "option is currently not recommended as most voting sites only support the old protocol at present. However, if you are\n" + - "using NuVotifier's proxy forwarding mechanism, enabling this option will increase your server's security.") - public boolean disableV1Protocol = false; - - @Setting(comment = "All tokens, labeled by the serviceName of each server list.\n" + - "Default token for all server lists, if another isn't supplied.") - public Map tokens = Collections.singletonMap("default", TokenUtil.newToken()); - - @Setting(comment = "Configuration section for all vote forwarding to NuVotifier") - public Forwarding forwarding = new Forwarding(); - - @ConfigSerializable - public static class Forwarding { - - @Setting(comment = "Sets whether to set up a remote method for fowarding. Supported methods:\n" + - "- none - Does not set up a forwarding method.\n" + - "- pluginMessaging - Sets up plugin messaging\n" + - "- redis - Sets up redis forwarding.") - public String method = "none"; - - @Setting - public PluginMessaging pluginMessaging = new PluginMessaging(); - @Setting - public Redis redis = new Redis(); - - @ConfigSerializable - public static class PluginMessaging { - - @Setting - public String channel = "nuvotifier:votes"; - } - - @ConfigSerializable - public static class Redis { - - @Setting - public String address = "127.0.0.1"; - - @Setting - public int port = 6379; - - @Setting - public String password = "your-redis-password-here"; - - @Setting - public String channel = "nuvotifier:votes"; - - @Setting(value = "pool-settings") - public PoolSettings poolSettings = new PoolSettings(); - - @ConfigSerializable - public class PoolSettings { - - @Setting - public int timeout = 5000; - - @Setting(value = "max-total") - public int maxTotal = 128; - - @Setting(value = "max-idle") - public int maxIdle = 128; - - @Setting(value = "min-idle") - public int minIdle = 16; - - @Setting(value = "min-evictable-idle-time") - public int minEvictableIdleTime = 60000; - - @Setting(value = "time-between-eviction-runs") - public int timeBetweenEvictionRuns = 30000; - - @Setting(value = "num-tests-per-eviction-run") - public int numTestsPerEvictionRun = 3; - - @Setting(value = "block-when-exhausted") - public boolean blockWhenExhausted = true; - - } - } - } -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/event/VotifierEvent.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/event/VotifierEvent.java deleted file mode 100644 index d225cf72..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/event/VotifierEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vexsoftware.votifier.sponge.event; - -import com.vexsoftware.votifier.model.Vote; -import org.spongepowered.api.event.cause.Cause; -import org.spongepowered.api.event.impl.AbstractEvent; - -/** - * This event is posted whenever a vote is received and processed by NuVotifier. Note that NuVotifier posts this event - * synchronously. - */ -public class VotifierEvent extends AbstractEvent { - private final Vote vote; - private final Cause cause; - - public VotifierEvent(Vote vote, Cause cause) { - this.vote = vote; - this.cause = cause; - } - - @Override - public Cause getCause() { - return cause; - } - - public Vote getVote() { - return vote; - } -} diff --git a/sponge/src/main/java/com/vexsoftware/votifier/sponge/forwarding/SpongePluginMessagingForwardingSink.java b/sponge/src/main/java/com/vexsoftware/votifier/sponge/forwarding/SpongePluginMessagingForwardingSink.java deleted file mode 100644 index d0d4d1b4..00000000 --- a/sponge/src/main/java/com/vexsoftware/votifier/sponge/forwarding/SpongePluginMessagingForwardingSink.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.vexsoftware.votifier.sponge.forwarding; - -import com.vexsoftware.votifier.sponge.NuVotifier; -import com.vexsoftware.votifier.support.forwarding.AbstractPluginMessagingForwardingSink; -import com.vexsoftware.votifier.support.forwarding.ForwardedVoteListener; -import org.spongepowered.api.Platform; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.network.ChannelBinding; -import org.spongepowered.api.network.ChannelBuf; -import org.spongepowered.api.network.RawDataListener; -import org.spongepowered.api.network.RemoteConnection; - -import java.util.Optional; - -public class SpongePluginMessagingForwardingSink extends AbstractPluginMessagingForwardingSink implements RawDataListener { - - private final NuVotifier p; - private final ChannelBinding.RawDataChannel channelBinding; - - public SpongePluginMessagingForwardingSink(NuVotifier p, String channel, ForwardedVoteListener listener) { - super(listener); - - Optional binding = Sponge.getChannelRegistrar().getChannel(channel); - if (binding.isPresent()) { - if (binding.get() instanceof ChannelBinding.RawDataChannel) { - this.channelBinding = (ChannelBinding.RawDataChannel) binding.get(); - } else { - throw new IllegalStateException("Found an indexed channel - this is a problem."); - } - } else { - this.channelBinding = Sponge.getChannelRegistrar().createRawChannel(p, channel); - } - - this.channelBinding.addListener(Platform.Type.SERVER, this); - this.p = p; - } - - @Override - public void halt() { - channelBinding.removeListener(this); - } - - @Override - public void handlePayload(ChannelBuf channelBuf, RemoteConnection remoteConnection, Platform.Type type) { - byte[] msgDirBuf = channelBuf.readBytes(channelBuf.available()); - try { - this.handlePluginMessage(msgDirBuf); - } catch (Exception e) { - p.getLogger().error("There was an unknown error when processing a forwarded vote.", e); - } - } -} diff --git a/sponge/src/main/resources/com/vexsoftware/votifier/sponge/spongeConfig.yml b/sponge/src/main/resources/com/vexsoftware/votifier/sponge/spongeConfig.yml deleted file mode 100644 index a194d979..00000000 --- a/sponge/src/main/resources/com/vexsoftware/votifier/sponge/spongeConfig.yml +++ /dev/null @@ -1,40 +0,0 @@ -# The IP to listen to. Use 0.0.0.0 if you wish to listen to all interfaces on your server. (All IP addresses) -# This defaults to the IP you have configured your server to listen on, or 0.0.0.0 if you have not configured this. -host: %ip% - -# Port to listen for new votes on -port: 8192 - -# Setting this option to true will disable handling of Protocol v1 packets. While the old protocol is not secure, this -# option is currently not recommended as most voting sites only support the old protocol at present. However, if you are -# using NuVotifier's proxy forwarding mechanism, enabling this option will increase your server's security. -disable-v1-protocol: false - -# All tokens, labeled by the serviceName of each server list. -tokens: - # Default token for all server lists, if another isn't supplied. - default: %default_token% - -# Configuration section for all vote forwarding to NuVotifier -forwarding: - # Sets whether to set up a remote method for fowarding. Supported methods: - # - none - Does not set up a forwarding method. - # - pluginMessaging - Sets up plugin messaging - # - redis - Sets up redis forwarding. - method: none - pluginMessaging: - channel: nuvotifier:votes - redis: - address: 127.0.0.1 - port: 6379 - password: your-redis-password-here - channel: nuvotifier:votes - pool-settings: - timeout: 5000 - max-total: 128 - max-idle: 128 - min-idle: 16 - min-evictable-idle-time: 60000 - time-between-eviction-runs: 30000 - num-tests-per-eviction-run: 3 - block-when-exhausted: true \ No newline at end of file