Merge pull request #8978 from deathbeam/otp-paste-public

Add support for pasting authenticator code on login screen
This commit is contained in:
Adam
2019-06-03 11:37:05 -04:00
committed by GitHub
4 changed files with 50 additions and 10 deletions

View File

@@ -151,6 +151,13 @@ public interface Client extends GameEngine
*/ */
void setPassword(String password); void setPassword(String password);
/**
* Sets the 6 digit pin used for authenticator on login screen.
*
* @param otp one time password
*/
void setOtp(String otp);
/** /**
* Gets currently selected login field. 0 is username, and 1 is password. * Gets currently selected login field. 0 is username, and 1 is password.
* *
@@ -158,6 +165,13 @@ public interface Client extends GameEngine
*/ */
int getCurrentLoginField(); int getCurrentLoginField();
/**
* Gets index of current login state. 2 is username/password form, 4 is authenticator form
*
* @return current login state index
*/
int getLoginIndex();
/** /**
* Gets the account type of the logged in player. * Gets the account type of the logged in player.
* *

View File

@@ -41,6 +41,10 @@ public enum GameState
* The client is at the login screen. * The client is at the login screen.
*/ */
LOGIN_SCREEN(10), LOGIN_SCREEN(10),
/**
* The client is at the login screen entering authenticator code.
*/
LOGIN_SCREEN_AUTHENTICATOR(11),
/** /**
* There is a player logging in. * There is a player logging in.
*/ */

View File

@@ -54,6 +54,7 @@ public class LoginScreenPlugin extends Plugin implements KeyListener
{ {
private static final int MAX_USERNAME_LENGTH = 254; private static final int MAX_USERNAME_LENGTH = 254;
private static final int MAX_PASSWORD_LENGTH = 20; private static final int MAX_PASSWORD_LENGTH = 20;
private static final int MAX_PIN_LENGTH = 6;
@Inject @Inject
private Client client; private Client client;
@@ -163,7 +164,9 @@ public class LoginScreenPlugin extends Plugin implements KeyListener
@Override @Override
public void keyPressed(KeyEvent e) public void keyPressed(KeyEvent e)
{ {
if (!config.pasteEnabled() || client.getGameState() != GameState.LOGIN_SCREEN) if (!config.pasteEnabled() || (
client.getGameState() != GameState.LOGIN_SCREEN &&
client.getGameState() != GameState.LOGIN_SCREEN_AUTHENTICATOR))
{ {
return; return;
} }
@@ -182,16 +185,27 @@ public class LoginScreenPlugin extends Plugin implements KeyListener
.toString() .toString()
.trim(); .trim();
// 0 is username, 1 is password switch (client.getLoginIndex())
if (client.getCurrentLoginField() == 0)
{ {
// Truncate data to maximum username length if necessary // Username/password form
client.setUsername(data.substring(0, Math.min(data.length(), MAX_USERNAME_LENGTH))); case 2:
} if (client.getCurrentLoginField() == 0)
else {
{ // Truncate data to maximum username length if necessary
// Truncate data to maximum password length if necessary client.setUsername(data.substring(0, Math.min(data.length(), MAX_USERNAME_LENGTH)));
client.setPassword(data.substring(0, Math.min(data.length(), MAX_PASSWORD_LENGTH))); }
else
{
// Truncate data to maximum password length if necessary
client.setPassword(data.substring(0, Math.min(data.length(), MAX_PASSWORD_LENGTH)));
}
break;
// Authenticator form
case 4:
// Truncate data to maximum OTP code length if necessary
client.setOtp(data.substring(0, Math.min(data.length(), MAX_PIN_LENGTH)));
break;
} }
} }
catch (UnsupportedFlavorException | IOException ex) catch (UnsupportedFlavorException | IOException ex)

View File

@@ -248,10 +248,18 @@ public interface RSClient extends RSGameEngine, Client
@Override @Override
void setPassword(String password); void setPassword(String password);
@Import("otp")
@Override
void setOtp(String otp);
@Import("currentLoginField") @Import("currentLoginField")
@Override @Override
int getCurrentLoginField(); int getCurrentLoginField();
@Import("loginIndex")
@Override
int getLoginIndex();
@Import("playerOptions") @Import("playerOptions")
@Override @Override
String[] getPlayerOptions(); String[] getPlayerOptions();