Jump to content

A Simple Login Handler


Explv

Recommended Posts

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;
    	}
    }

 

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...
  • 2 months later...

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
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...
  • 3 weeks later...

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
Link to comment
Share on other sites

  • 2 months later...

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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