Jump to content

A Simple Login Handler


Explv

Recommended Posts

God damn so much spam on such an awesome thread. @progamerz you clearly have a problem in your getLobbyButton() method. Just catch that pesky nullPointer and wait until everything is loaded for it to execute properly. Here's mine

 public RS2Widget getLobbyButton() {
    	try {
    		RS2Widget lobbyButton = widgets.getWidgetContainingText("CLICK HERE TO PLAY");
    		if (lobbyButton != null) {
        		return lobbyButton;
        	}
    	} catch (NullPointerException e) {
    		s.log("Didn't find lobby button");
    	}
        return null;
    }

 

Link to comment
Share on other sites

1 minute ago, nosepicker said:

God damn so much spam on such an awesome thread. @progamerz you clearly have a problem in your getLobbyButton() method. Just catch that pesky nullPointer and wait until everything is loaded for it to execute properly. Here's mine


 public RS2Widget getLobbyButton() {
    	try {
    		RS2Widget lobbyButton = widgets.getWidgetContainingText("CLICK HERE TO PLAY");
    		if (lobbyButton != null) {
        		return lobbyButton;
        	}
    	} catch (NullPointerException e) {
    		s.log("Didn't find lobby button");
    	}
        return null;
    }

 

What u did before isn't considered as spam? thanks anyways.

Link to comment
Share on other sites

4 hours ago, nosepicker said:

God damn so much spam on such an awesome thread. @progamerz you clearly have a problem in your getLobbyButton() method. Just catch that pesky nullPointer and wait until everything is loaded for it to execute properly. Here's mine


 public RS2Widget getLobbyButton() {
    	try {
    		RS2Widget lobbyButton = widgets.getWidgetContainingText("CLICK HERE TO PLAY");
    		if (lobbyButton != null) {
        		return lobbyButton;
        	}
    	} catch (NullPointerException e) {
    		s.log("Didn't find lobby button");
    	}
        return null;
    }

 

 

1 hour ago, progamerz said:

Ok maybe next time

 

You could try moving the lobby button check inside of the isLoggedIn check:

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

 

Link to comment
Share on other sites

12 minutes ago, Explv said:

 

 

You could try moving the lobby button check inside of the isLoggedIn check:


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

 

Oh yup makes sense thanks boss :D, idk why i didn't think of doing it in that way lol

Link to comment
Share on other sites

1 hour ago, Colonel_Panic said:

Do I need to do something to actually get responseCodes when the account is locked?

My onResponseCode function is never being called, so it just sits looking at the login screen with the "Your account has been disabled" message.

Yeah you have to code the response codes. Theres 25of them but only like 7 of them are importsnt 

Link to comment
Share on other sites

12 minutes ago, Juggles said:

Yeah you have to code the response codes. Theres 25of them but only like 7 of them are importsnt 

No I mean onResponseCode itself is never being called.  I have a massive switch statement with all 25 included, but onResponseCode is never being called so the switch statement is never hit.  

Link to comment
Share on other sites

4 minutes ago, Colonel_Panic said:

No I mean onResponseCode itself is never being called.  I have a massive switch statement with all 25 included, but onResponseCode is never being called so the switch statement is never hit.  

Same problem with mine. Looks like response codes are never called during the event, only after the event has been executed. Had to make it extend MethodProvider and no longer event and run it like a script.

Edited by scape
Link to comment
Share on other sites

On 9/29/2017 at 12:38 AM, Colonel_Panic said:

No I mean onResponseCode itself is never being called.  I have a massive switch statement with all 25 included, but onResponseCode is never being called so the switch statement is never hit.  

 

On 9/29/2017 at 12:42 AM, scape said:

Same problem with mine. Looks like response codes are never called during the event, only after the event has been executed. Had to make it extend MethodProvider and no longer event and run it like a script.

This was giving me a huge headache :D onResponseCode() gets called at the end of loop iteration. 

Link to comment
Share on other sites

18 hours ago, nosepicker said:

 

This was giving me a huge headache :D onResponseCode() gets called at the end of loop iteration. 

Added the breakcondition for WalkingEvent and it seemed to fix the not logging issue for that. 

But sometimes I find accounts not logging back in and when i log in, they're at the dock fishing lobster so im not sure what would cause that to not log back in. 

So not sure what they could be getting stuck in to not call LoginEvent 

Link to comment
Share on other sites

  • 1 month later...
On 9/28/2017 at 11:38 PM, Colonel_Panic said:

No I mean onResponseCode itself is never being called.  I have a massive switch statement with all 25 included, but onResponseCode is never being called so the switch statement is never hit.  

 

On 9/28/2017 at 11:42 PM, scape said:

Same problem with mine. Looks like response codes are never called during the event, only after the event has been executed. Had to make it extend MethodProvider and no longer event and run it like a script.

 

On 9/30/2017 at 10:33 AM, nosepicker said:

 

This was giving me a huge headache :D onResponseCode() gets called at the end of loop iteration. 

I got exactly the same problem, how did you guys fix it? Everything is working except for the response method :( 

Link to comment
Share on other sites

  • 3 months later...

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)

 

Spoiler

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

 

 

Edited by gangsthurh
spoilerthing
  • Boge 1
Link to comment
Share on other sites

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...