From 94d163279a528886819f3644065148163c0c90f7 Mon Sep 17 00:00:00 2001 From: Felix Date: Wed, 26 Jun 2019 18:15:01 +0200 Subject: [PATCH 1/3] Add RCON Support --- .../chatoverflow/api/io/output/RconOutput.java | 6 ++++++ .../api/plugin/configuration/Output.java | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java diff --git a/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java b/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java new file mode 100644 index 0000000..4640ab8 --- /dev/null +++ b/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java @@ -0,0 +1,6 @@ +package org.codeoverflow.chatoverflow.api.io.output; + +public interface RconOutput extends Output { + + String sendCommand(String command); +} diff --git a/src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Output.java b/src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Output.java index c8444a6..0aafc5e 100644 --- a/src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Output.java +++ b/src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Output.java @@ -1,6 +1,7 @@ package org.codeoverflow.chatoverflow.api.plugin.configuration; import org.codeoverflow.chatoverflow.api.io.output.FileOutput; +import org.codeoverflow.chatoverflow.api.io.output.RconOutput; import org.codeoverflow.chatoverflow.api.io.output.SerialOutput; import org.codeoverflow.chatoverflow.api.io.output.chat.DiscordChatOutput; import org.codeoverflow.chatoverflow.api.io.output.chat.TwitchChatOutput; @@ -62,6 +63,18 @@ public Requirement file(String uniqueRequirementId, String displayNa return requirements.requireOutput(uniqueRequirementId, displayName, isOptional, FileOutput.class); } + /** + * Requires a game server with enabled rcon + * + * @param uniqueRequirementId any unique id by which your plugin can identify the requirement + * @param displayName Is displayed to the framework user and to tell him what to enter + * @param isOptional true if this requirement is optional, false if mandatory + * @return the requirement object + */ + public Requirement rcon(String uniqueRequirementId, String displayName, boolean isOptional) { + return requirements.requireOutput(uniqueRequirementId, displayName, isOptional, RconOutput.class); + } + // Add more outputs here } From 85992f53a2e1c458b33cdffdd0cc6c86c4e2e448 Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 27 Jun 2019 20:00:13 +0200 Subject: [PATCH 2/3] Splitting RCON in Input and Output. While output only returns if command was successful Input will return RCON return message. (There is not often one. But e.g. while using /list in minecraft RCON). Input will return null will it was unsuccessful --- .../chatoverflow/api/io/input/RconInput.java | 5 +++++ .../chatoverflow/api/io/output/RconOutput.java | 2 +- .../api/plugin/configuration/Input.java | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/codeoverflow/chatoverflow/api/io/input/RconInput.java diff --git a/src/main/java/org/codeoverflow/chatoverflow/api/io/input/RconInput.java b/src/main/java/org/codeoverflow/chatoverflow/api/io/input/RconInput.java new file mode 100644 index 0000000..ee50a41 --- /dev/null +++ b/src/main/java/org/codeoverflow/chatoverflow/api/io/input/RconInput.java @@ -0,0 +1,5 @@ +package org.codeoverflow.chatoverflow.api.io.input; + +public interface RconInput extends Input { + String getCommandOutput(String command); +} diff --git a/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java b/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java index 4640ab8..54c7799 100644 --- a/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java +++ b/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java @@ -2,5 +2,5 @@ public interface RconOutput extends Output { - String sendCommand(String command); + boolean sendCommand(String command); } diff --git a/src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Input.java b/src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Input.java index 1aa7f1c..1b36847 100644 --- a/src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Input.java +++ b/src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Input.java @@ -1,6 +1,7 @@ package org.codeoverflow.chatoverflow.api.plugin.configuration; import org.codeoverflow.chatoverflow.api.io.input.FileInput; +import org.codeoverflow.chatoverflow.api.io.input.RconInput; import org.codeoverflow.chatoverflow.api.io.input.SampleInput; import org.codeoverflow.chatoverflow.api.io.input.SerialInput; import org.codeoverflow.chatoverflow.api.io.input.chat.DiscordChatInput; @@ -101,6 +102,18 @@ public Requirement file(String uniqueRequirementId, String displayNam return requirements.requireInput(uniqueRequirementId, displayName, isOptional, FileInput.class); } + /** + * Requires a connection to a RCON Server + * + * @param uniqueRequirementId any unique id by which your plugin can identify the requirement + * @param displayName Is displayed to the framework user and to tell him what to enter + * @param isOptional true if this requirement is optional, false if mandatory + * @return the requirement object + */ + public Requirement rcon(String uniqueRequirementId, String displayName, boolean isOptional) { + return requirements.requireInput(uniqueRequirementId, displayName, isOptional, RconInput.class); + } + // Add more inputs here } From 9c712ca4853782400bb7c152f8400b255124a36c Mon Sep 17 00:00:00 2001 From: Felix Date: Sun, 21 Jul 2019 13:01:10 +0200 Subject: [PATCH 3/3] Add JavaDoc for RCON connector --- .../chatoverflow/api/io/input/RconInput.java | 9 +++++++++ .../chatoverflow/api/io/output/RconOutput.java | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/org/codeoverflow/chatoverflow/api/io/input/RconInput.java b/src/main/java/org/codeoverflow/chatoverflow/api/io/input/RconInput.java index ee50a41..bda2ae9 100644 --- a/src/main/java/org/codeoverflow/chatoverflow/api/io/input/RconInput.java +++ b/src/main/java/org/codeoverflow/chatoverflow/api/io/input/RconInput.java @@ -1,5 +1,14 @@ package org.codeoverflow.chatoverflow.api.io.input; public interface RconInput extends Input { + + /** + * Get the output of a rcon command + * Command will be directly executed on the rcon server and the returned response will be returned + * If null is returned this means that there is some problem with the connection (typically the server is shut down or there is some other reason for a lost connection) + * Notice: There is no way of knowing that a command exists, which does not return a response. Every command without response will return an empty string. + * @param command the command which should be executed on the remote server + * @return response of the server or null + */ String getCommandOutput(String command); } diff --git a/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java b/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java index 54c7799..2e6d4be 100644 --- a/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java +++ b/src/main/java/org/codeoverflow/chatoverflow/api/io/output/RconOutput.java @@ -2,5 +2,12 @@ public interface RconOutput extends Output { + + /** + * Execute a command on a remote (rcon) server. + * Notice: There is no way of knowing if the commands exists. + * @param command the command which should be executed + * @return if the command was successfully sent to the server. (Returns false for e.g. a not anymore existent server) + */ boolean sendCommand(String command); }