Jump to content

A Simple Login Handler


Recommended Posts

Posted
On 15/03/2018 at 9:33 PM, gangsthurh said:

hey boyz, i wrote an update to this login handler that fixes it for the march15 patch (is stopping people at the "click here to play" button)

 

  Hide contents


//https://osbot.org/forum/topic/109560-a-simple-login-handler/
//https://osbot.org/forum/topic/109560-a-simple-login-handler/
//patched version march15 2018

package bot.steven.LDirectives;

import java.awt.Color;

import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.constants.ResponseCode;
import org.osbot.rs07.event.Event;
import org.osbot.rs07.input.mouse.RectangleDestination;
import org.osbot.rs07.listener.LoginResponseCodeListener;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

public final class LoginEvent extends Event implements LoginResponseCodeListener {

    private String username, password;

    public LoginEvent(Script script) {
    	this.script = script;
    }
    Script script;
    
    public void setUsername(final String username) {
        this.username = username;
    }

    public void setPassword(final String password) {
        this.password = password;
    }

    
    public final int execute() throws InterruptedException {
        if (getClient().isLoggedIn() && getLobbyButton() == null) {
            setFinished();
        } else if (getLobbyButton() != null) {
            clickLobbyButton();
        } else if (isOnWorldSelectorScreen()) {
            cancelWorldSelection();
        } else {
            login();
        }
        return random(100, 150);
    }

    private boolean isOnWorldSelectorScreen() {
        return getColorPicker().isColorAt(50, 50, Color.BLACK);
    }

    private void cancelWorldSelection() {
        if (getMouse().click(new RectangleDestination(getBot(), 712, 8, 42, 8))) {
            new ConditionalSleep(3000) {
         
                public boolean condition() throws InterruptedException {
                    return !isOnWorldSelectorScreen();
                }
            }.sleep();
        }
    }

    private void login() {
        switch (getClient().getLoginUIState()) {
            case 0:
                clickExistingUsersButton();
                break;
            case 1:
                clickLoginButton();
                break;
            case 2:
                enterUserDetails();
                break;
        }
    }

    private void clickExistingUsersButton() {
        getMouse().click(new RectangleDestination(getBot(), 400, 280, 120, 20));
    }

    private void clickLoginButton() {
        getMouse().click(new RectangleDestination(getBot(), 240, 310, 120, 20));
    }

    private void enterUserDetails() {
        if (!getKeyboard().typeString(username)) {
            setFailed();
            return;
        }
        if (!getKeyboard().typeString(password)) {
            setFailed();
            return;
        }
        new ConditionalSleep(10_000) {
            
            public boolean condition() throws InterruptedException {
                return getLobbyButton() != null;
            }
        }.sleep();
    }

    private void clickLobbyButton() {
        if (getLobbyButton().interact()) {
            new ConditionalSleep(10_000) {
            
                public boolean condition() throws InterruptedException {
                    return getLobbyButton() == null;
                }
            }.sleep();
        }
    }

    private RS2Widget getLobbyButton() {
    	try{
        return script.widgets.get(378,76);//(gangsthurh) changed code here
    	//return getWidgets().getWidgetContainingText("CLICK HERE TO PLAY");
    	}catch(NullPointerException n){
    		return null;
    	}
    
    }


    public final void onResponseCode(final int responseCode) throws InterruptedException {
        if(ResponseCode.isDisabledError(responseCode)) {
            log("Login failed, account is disabled");
            setFailed();
            return;
        }

        if(ResponseCode.isConnectionError(responseCode)) {
            log("Connection error, attempts exceeded");
            setFailed();
            return;
        }
    }
}

 

 

you dont need to change the getwidgets code you can just add the try/catch and it works fine
 

Spoiler

    private RS2Widget getLobbyButton() {
    	try{
    	return getWidgets().getWidgetContainingText("CLICK HERE TO PLAY");
    	}catch(NullPointerException n){
    		return null;
    	}
    }

 

 

  • 3 weeks later...
  • 3 weeks later...
  • 2 months later...
Posted (edited)

When I run it, it shows NullPointerException immediately.

 

Script doesn't start if account hasn't logined / I turned off client auto login?:???:

onstart not being called before user is logged :feels:

Uncaught exception!
java.lang.NullPointerException
	at org.osbot.rs07.event.ScriptExecutor$3.run(kl:211)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

 

Edited by Pegasus
  • 3 weeks later...
  • 3 months later...
  • 3 weeks later...
Posted (edited)

I there a way I can get the password from Explv bot manager? Or do I have to type it as string and compile the jar again?

EDIT: I noticed by right clicking on my configuration and then "Show command", I see the email and pass. I just don't know how to retreive it in my script.

Edited by JoRouss
  • 2 months later...
Posted (edited)

getBot().isLoaded() is not working

 

 

@ Override
    public final int execute() throws InterruptedException {
        if (!getBot().isLoaded()) {
            return 1000;
        } else if (getClient().isLoggedIn() && getLobbyButton() == null) {
            getBot().getScriptExecutor().resume();
            setFinished();
        } else if (!getBot().getScriptExecutor().isPaused()) {
            getBot().getScriptExecutor().pause();
        } else if (getLobbyButton() != null) {
            clickLobbyButton();
        } else if (isOnWorldSelectorScreen()) {
            cancelWorldSelection();
        } else if (!isPasswordEmpty()) {
            clickCancelLoginButton();
        } else {
            login();
        }
        return random(100, 150);
    }

 

I got this NPE :

java.lang.NullPointerException
    at org.osbot.rs07.api.Widgets.getWidgetContainingText(tl:727)
    at com.iaox.farmer.handlers.LoginEvent.getLobbyButton(LoginEvent.java:140)
    at com.iaox.farmer.handlers.LoginEvent.execute(LoginEvent.java:37)
    at org.osbot.rs07.event.EventExecutor$2.run(zj:230)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Edited by Pegasus
Posted
27 minutes ago, Pegasus said:

getBot().isLoaded() is not working

 

 


@ Override
    public final int execute() throws InterruptedException {
        if (!getBot().isLoaded()) {
            return 1000;
        } else if (getClient().isLoggedIn() && getLobbyButton() == null) {
            getBot().getScriptExecutor().resume();
            setFinished();
        } else if (!getBot().getScriptExecutor().isPaused()) {
            getBot().getScriptExecutor().pause();
        } else if (getLobbyButton() != null) {
            clickLobbyButton();
        } else if (isOnWorldSelectorScreen()) {
            cancelWorldSelection();
        } else if (!isPasswordEmpty()) {
            clickCancelLoginButton();
        } else {
            login();
        }
        return random(100, 150);
    }

 

I got this NPE :

java.lang.NullPointerException
    at org.osbot.rs07.api.Widgets.getWidgetContainingText(tl:727)
    at com.iaox.farmer.handlers.LoginEvent.getLobbyButton(LoginEvent.java:140)
    at com.iaox.farmer.handlers.LoginEvent.execute(LoginEvent.java:37)
    at org.osbot.rs07.event.EventExecutor$2.run(zj:230)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

image.png.1800c28c880e7362f802586a65173b0b.png

What does your script look like? Does it just execute the login script immediately after the client begins launching?

Posted (edited)
16 hours ago, hreyvirtue said:

If the client isn't logged in, then the login event executes, that's the point of that script

Set it on loop and adds sleeps if you need to

 

I mean login event execute is not working.

It is because

getBot().isLoaded() is not working

it return true even the client is still downloading data from official game.

 

 

Edited by Pegasus
  • 2 months later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...