Jump to content
Sign in to follow this  
JoeDezzy1

Login Helper

Recommended Posts

In the past, I've experienced consistency issues with certain methods in the API that return false/inconsistent information on certain occasions, especially upon logins.

Here is something I've created a while ago that became very useful to combat that issue.

 

import org.tribot.api.General;
import org.tribot.api2007.Game;
import org.tribot.api2007.Login;

/**
 * @author JDezzy1
 */
public class LoginAccess extends Login implements Access {
	/**
	 * The amount of settings in the gamesettings array to confirm consistency
	 * in ingame data
	 */
	public static final transient int settingsArrayLength = 70;
	/**
	 * The ban message upon logging in
	 */
	public static final transient String BAN_HOOK = "Your account has been disabled. Please check your message-centre for details.";

	/*
	 * (non-Javadoc)
	 * 
	 * @see scripts.dezapi.wrappers.accessor.Access#access()
	 */
	@Override
	public Class<Login> access() {
		return Login.class;
	}

	/**
	 * @return true if in game
	 */
	public static boolean inGame() {
		final STATE ST8 = getLoginState();
		return ST8 != null && ST8.equals(STATE.INGAME);
	}

	/**
	 * @return true if at the login screen
	 */
	public static boolean inLoginScreen() {
		final STATE ST8 = getLoginState();
		return ST8 != null && ST8.equals(STATE.LOGINSCREEN);
	}

	/**
	 * @return true if at the welcome screen
	 */
	public static boolean inWelcomeScreen() {
		final STATE ST8 = getLoginState();
		return ST8 != null && ST8.equals(STATE.WELCOMESCREEN);
	}

	/**
	 * @return true if there is a ban message
	 */
	public static boolean banMessage() {
		final String response = Login.getLoginResponse();
		return response != null && response.equals(BAN_HOOK);
	}

	/**
	 * Does what it says
	 * 
	 * @return Game setting.length > ~70 plus all other hooks
	 */
	public static boolean isEverythingFuckingLoadedAndReadyToBeRead() {
		return !inWelcomeScreen() && inGame() && Game.getGameState() == 30
				&& Game.getSettingsArray().length >= settingsArrayLength;
	}

	/**
	 * @return true if the login was successful
	 */
	public static boolean waitLogin() {
		return Waiting07.waitCondition(() -> {
			return isEverythingFuckingLoadedAndReadyToBeRead();
		}, System.currentTimeMillis() + General.randomSD(35000, 45000, 4250));
	}

	/**
	 * @return true if the logout was successful
	 */
	public static boolean waitLogout() {
		return Waiting07.waitCondition(() -> {
			return inLoginScreen();
		}, System.currentTimeMillis() + General.randomSD(35000, 45000, 4250));
	}

	/**
	 * 
	 * @param user
	 * @param pass
	 * @return
	 */
	public static boolean handleLogin(final String user, final String pass) {
		General.println("Login => attempting login => " + user);
		if (login(user, pass)) {
			General.println("Login => waiting for login...");
			if (waitLogin()) {
				General.println("Login => logging in => successful login");
				return true;
			}
		}
		return false;
	}
}

 

Share this post


Link to post
Share on other sites

Good snippet, but let me add some suggestions.

 

Some of the methods aren't needed. I'm pretty sure "getLoginState" can't return null, so you don't need all that extra calculation. It would make more sense to just do "Login.getLoginState() == [state]". Plus, if you are checking to see what state you're in, calling these methods recalculates the login state each time, when it would be easier to call it once and do a switch statement.

 

Also, not a single comment in this code is needed. Proper policy would suggest you either use them to explain the "why" and "when to use", not the "how". And empty comments or "does what it says" just gets in the way. I know this might sound nitpicky, but it's common courtesy when posting public code. The only comments that do this are your "wait..." method comments.

 

I do quite like the ban-detecting snippet, though. I might add that into my framework.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×