From df22cb8a9894b046391ea71647ab677daed15ec7 Mon Sep 17 00:00:00 2001 From: zsrv Date: Mon, 15 May 2023 14:41:33 +0000 Subject: [PATCH] RememberMyLogin plugin: Save and load credentials based on the server hostname and port --- .../src/main/kotlin/RememberMyLogin/plugin.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugin-playground/src/main/kotlin/RememberMyLogin/plugin.kt b/plugin-playground/src/main/kotlin/RememberMyLogin/plugin.kt index 8da104f..05cb30c 100644 --- a/plugin-playground/src/main/kotlin/RememberMyLogin/plugin.kt +++ b/plugin-playground/src/main/kotlin/RememberMyLogin/plugin.kt @@ -6,20 +6,25 @@ import plugin.api.API import rt4.Component import rt4.JagString import rt4.Player +import rt4.client @PluginMeta ( author = "Ceikry", - description = "Stores your last used login for automatic reuse", - version = 1.0 + description = "Stores your last used login for automatic reuse, per server", + version = 1.1 ) class plugin : Plugin() { var hasRan = false + var credentials = HashMap>() + var server = "" var username = "" var password = "" override fun Init() { - username = API.GetData("login-user") as? String ?: "" - password = API.GetData("login-pass") as? String ?: "" + server = client.hostname + ":" + client.port + credentials = API.GetData("login-credentials") as? HashMap> ?: HashMap() + username = credentials.get(server)?.get("username") ?: "" + password = credentials.get(server)?.get("password") ?: "" } override fun ComponentDraw(componentIndex: Int, component: Component?, screenX: Int, screenY: Int) { @@ -34,8 +39,10 @@ class plugin : Plugin() { override fun OnLogin() { username = String(Player.usernameInput.chars) password = String(Player.password.chars) - API.StoreData("login-user", username) - API.StoreData("login-pass", password) + + credentials[server] = mapOf("username" to username, "password" to password) as HashMap + + API.StoreData("login-credentials", credentials) } override fun OnLogout() {