aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/rbwrl
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-02-17 22:49:19 +0100
committerLinnea Gräf <nea@nea.moe>2024-02-17 22:52:35 +0100
commitc888c5569f8573a93d9e57555d94ddadd909c008 (patch)
treeaba8ebe925ada2925af2fc1d2a14925e6cc2282d /src/main/java/moe/nea/rbwrl
downloadrbw-bitwarden-runelite-c888c5569f8573a93d9e57555d94ddadd909c008.tar.gz
rbw-bitwarden-runelite-c888c5569f8573a93d9e57555d94ddadd909c008.tar.bz2
rbw-bitwarden-runelite-c888c5569f8573a93d9e57555d94ddadd909c008.zip
Initial commitHEADmaster
Diffstat (limited to 'src/main/java/moe/nea/rbwrl')
-rw-r--r--src/main/java/moe/nea/rbwrl/UnofficialBitwardenCliConfig.java19
-rw-r--r--src/main/java/moe/nea/rbwrl/UnofficialBitwardenCliPlugin.java83
2 files changed, 102 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/rbwrl/UnofficialBitwardenCliConfig.java b/src/main/java/moe/nea/rbwrl/UnofficialBitwardenCliConfig.java
new file mode 100644
index 0000000..c328be7
--- /dev/null
+++ b/src/main/java/moe/nea/rbwrl/UnofficialBitwardenCliConfig.java
@@ -0,0 +1,19 @@
+package moe.nea.rbwrl;
+
+import net.runelite.client.config.Config;
+import net.runelite.client.config.ConfigGroup;
+import net.runelite.client.config.ConfigItem;
+
+@ConfigGroup("unofficialbitwardencli")
+public interface UnofficialBitwardenCliConfig extends Config
+{
+ @ConfigItem(
+ keyName = "rbwBinary",
+ name = "Binary Path",
+ description = "Set the path to the rbw binary here, or leave it empty to default to \"rbw\"."
+ )
+ default String getBinaryPath()
+ {
+ return "rbw";
+ }
+}
diff --git a/src/main/java/moe/nea/rbwrl/UnofficialBitwardenCliPlugin.java b/src/main/java/moe/nea/rbwrl/UnofficialBitwardenCliPlugin.java
new file mode 100644
index 0000000..e4e8f80
--- /dev/null
+++ b/src/main/java/moe/nea/rbwrl/UnofficialBitwardenCliPlugin.java
@@ -0,0 +1,83 @@
+package moe.nea.rbwrl;
+
+import com.google.inject.Provides;
+import lombok.extern.slf4j.Slf4j;
+import net.runelite.api.Client;
+import net.runelite.api.GameState;
+import net.runelite.api.events.UsernameChanged;
+import net.runelite.client.config.ConfigManager;
+import net.runelite.client.eventbus.Subscribe;
+import net.runelite.client.plugins.Plugin;
+import net.runelite.client.plugins.PluginDescriptor;
+
+import javax.inject.Inject;
+
+@Slf4j
+@PluginDescriptor(
+ name = "Unofficial Bitwarden CLI"
+)
+public class UnofficialBitwardenCliPlugin extends Plugin {
+ @Inject
+ private Client client;
+
+ @Inject
+ private UnofficialBitwardenCliConfig config;
+
+ @Override
+ protected void startUp() throws Exception {
+ log.info("Unofficial Bitwarden CLI started!");
+ tryInjectPassword();
+ }
+
+ @Override
+ protected void shutDown() throws Exception {
+ log.info("Unofficial Bitwarden CLI stopped!");
+ }
+
+ private void tryInjectPassword() {
+ log.info("Trying to inject password!");
+ if (passwordFetchingThread != null) passwordFetchingThread.interrupt();
+ passwordFetchingThread = new Thread(() -> {
+ try {
+ String password = getPasswordForName(client.getUsername());
+ client.setPassword(password);
+ } catch (Exception e) {
+ log.error("Exception while fetching password", e);
+ }
+ });
+ passwordFetchingThread.setName("RBW Fetching thread");
+ passwordFetchingThread.start();
+ }
+
+ @Subscribe
+ public void onUsernameChanged(UsernameChanged event) {
+ if (client.getGameState() != GameState.LOGIN_SCREEN) {
+ return;
+ }
+ tryInjectPassword();
+ }
+
+ private String getPasswordForName(String username) {
+ try {
+ String binaryPath = config.getBinaryPath();
+ if (binaryPath == null || binaryPath.isBlank())
+ binaryPath = "rbw";
+ ProcessBuilder pb = new ProcessBuilder(binaryPath, "get", "Runescape", username);
+ pb.inheritIO().redirectOutput(ProcessBuilder.Redirect.PIPE);
+ Process proc = pb.start();
+ if (proc.waitFor() == 0) {
+ return new String(proc.getInputStream().readAllBytes()).strip();
+ }
+ throw new RuntimeException(new String(proc.getInputStream().readAllBytes()));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ Thread passwordFetchingThread;
+
+ @Provides
+ UnofficialBitwardenCliConfig provideConfig(ConfigManager configManager) {
+ return configManager.getConfig(UnofficialBitwardenCliConfig.class);
+ }
+}