diff --git a/src/main/java/dev/elijahr/CollabVM4j/CollabVMClient.java b/src/main/java/dev/elijahr/CollabVM4j/CollabVMClient.java index fe9c2f0..4ba9437 100644 --- a/src/main/java/dev/elijahr/CollabVM4j/CollabVMClient.java +++ b/src/main/java/dev/elijahr/CollabVM4j/CollabVMClient.java @@ -4,6 +4,7 @@ import org.apache.commons.text.StringEscapeUtils; import org.java_websocket.handshake.ServerHandshake; import javax.imageio.ImageIO; +import javax.security.auth.login.CredentialException; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -34,7 +35,8 @@ public class CollabVMClient { private ResetVote _currentVote; private boolean _usesAccountAuth; // Futures - private CompletableFuture _loginFuture; + private CompletableFuture _accountLoginFuture; + private CompletableFuture _passwordLoginFuture; // Constructor @SuppressWarnings("unchecked") @@ -90,13 +92,21 @@ public class CollabVMClient { * @return A CompletableFuture that will complete when the login attempt is finished */ public CompletableFuture loginAccount(String token) { - this._loginFuture = new CompletableFuture<>(); + this._accountLoginFuture = new CompletableFuture<>(); this.sendGuac("login", token); - return this._loginFuture; + return this._accountLoginFuture; } - - // Getters and setters + /** + * Log into the VM using a staff password + * @param password The password to log in with + * @return A CompletableFuture that will complete when the login attempt is finished with the new rank + */ + public CompletableFuture loginPassword(String password) { + this._passwordLoginFuture = new CompletableFuture<>(); + this.sendGuac("admin", "2", password); + return this._passwordLoginFuture; + } /** * If not connected, sets the username to request when connecting. @@ -310,7 +320,7 @@ public class CollabVMClient { } case "login": { boolean success = msgArr[1].equals("1"); - this._loginFuture.complete(new AccountLoginResult(success, success ? null : msgArr[2])); + this._accountLoginFuture.complete(new AccountLoginResult(success, success ? null : msgArr[2])); break; } case "auth": { @@ -342,6 +352,23 @@ public class CollabVMClient { } case "admin": { switch (msgArr[1]) { + case "0": + switch (msgArr[2]) { + case "0": + this._passwordLoginFuture.completeExceptionally(new CredentialException("Invalid password")); + break; + case "1": + this._rank = Rank.Admin; + this._permissions = Permissions.All(); + this._passwordLoginFuture.complete(Rank.Admin); + break; + case "3": + this._rank = Rank.Moderator; + this._permissions = new Permissions(Integer.parseInt(msgArr[3])); + this._passwordLoginFuture.complete(Rank.Moderator); + break; + } + break; } break;