X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FFcpInterface.java;h=bcd70a2bdf84f73f2051debe5417fd0df92d66e2;hb=b8628d48bb269c5acf67f84c078d92a132a630ff;hp=8854347e106b38f4100674dc68ebe61a18800cd7;hpb=867514c843526b7e3699e3e6073c01bae0813fc7;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 8854347..bcd70a2 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -47,6 +47,9 @@ public class FcpInterface { /** The logger. */ private static final Logger logger = Logging.getLogger(FcpInterface.class); + /** Whether the FCP interface is currently active. */ + private volatile boolean active; + /** All available FCP commands. */ private final Map commands = Collections.synchronizedMap(new HashMap()); @@ -59,10 +62,36 @@ public class FcpInterface { public FcpInterface(Core core) { commands.put("Version", new VersionCommand()); commands.put("GetLocalSones", new GetLocalSonesCommand(core)); + commands.put("GetPost", new GetPostCommand(core)); commands.put("GetPosts", new GetPostsCommand(core)); commands.put("GetPostFeed", new GetPostFeedCommand(core)); + commands.put("LikePost", new LikePostCommand(core)); + commands.put("LikeReply", new LikeReplyCommand(core)); + commands.put("CreatePost", new CreatePostCommand(core)); + commands.put("CreateReply", new CreateReplyCommand(core)); + commands.put("DeletePost", new DeletePostCommand(core)); } + // + // ACCESSORS + // + + /** + * Sets whether the FCP interface should handle requests. If {@code active} + * is {@code false}, all requests are answered with an error. + * + * @param active + * {@code true} to activate the FCP interface, {@code false} to + * deactivate the FCP interface + */ + public void setActive(boolean active) { + this.active = active; + } + + // + // ACTIONS + // + /** * Handles a plugin FCP request. * @@ -78,6 +107,14 @@ public class FcpInterface { * {@link FredPluginFCP#ACCESS_FCP_RESTRICTED} */ public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) { + if (!active) { + try { + sendReply(pluginReplySender, null, new ErrorResponse(400, "FCP Interface deactivated")); + } catch (PluginNotFoundException pnfe1) { + logger.log(Level.FINE, "Could not set error to plugin.", pnfe1); + } + return; + } Command command = commands.get(parameters.get("Message")); try { if (command == null) {