Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.29 KB | None | 0 0
  1. package org.rsbot.script.randoms;
  2.  
  3. import org.rsbot.script.Random;
  4. import org.rsbot.script.ScriptManifest;
  5. import org.rsbot.script.wrappers.RSInterface;
  6. import org.rsbot.script.wrappers.RSComponent;
  7.  
  8. import java.awt.*;
  9.  
  10. /**
  11.  * @author Iscream
  12.  */
  13. @ScriptManifest(authors = {"Iscream", "Kahzel"}, name = "Login", version = 1.22)
  14. public class LoginBot extends Random {
  15.  
  16.     private static final int INTERFACE_MAIN = 905;
  17.     private static final int INTERFACE_MAIN_CHILD = 59;
  18.     private static final int INTERFACE_MAIN_CHILD_COMPONENT_ID = 4;
  19.     private static final int INTERFACE_LOGIN_SCREEN = 596;
  20.     private static final int INTERFACE_USERNAME = 65;
  21.     private static final int INTERFACE_USERNAME_WINDOW = 37;
  22.     private static final int INTERFACE_PASSWORD = 71;
  23.     private static final int INTERFACE_PASSWORD_WINDOW = 39;
  24.     private static final int INTERFACE_BUTTON_LOGIN = 42;
  25.     private static final int INTERFACE_TEXT_RETURN = 11;
  26.     private static final int INTERFACE_BUTTON_BACK = 53;
  27.     private static final int INTERFACE_BUTTON_BACK_2 = 58;
  28.     private static final int INTERFACE_WELCOME_SCREEN = 906;
  29.     private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1 = 145;
  30.     private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2 = 155;
  31.     private static final int INTERFACE_WELCOME_SCREEN_TEXT_RETURN = 221;
  32.     private static final int INDEX_LOGGED_OUT = 3;
  33.     private static final int INDEX_LOBBY = 7;
  34.     private int invalidCount, worldFullCount;
  35.  
  36.     public boolean activateCondition() {
  37.         int idx = game.getClientState();
  38.         return (idx == INDEX_LOGGED_OUT || idx == INDEX_LOBBY) && account.getName() != null;
  39.     }
  40.  
  41.     public int loop() {
  42.         String username = account.getName().replaceAll("_", " ").toLowerCase().trim();
  43.         String returnText = interfaces.get(INTERFACE_LOGIN_SCREEN).
  44.                 getComponent(INTERFACE_TEXT_RETURN).getText().toLowerCase();
  45.         int textlength;
  46.         if (game.getClientState() != INDEX_LOGGED_OUT) {
  47.             if (!game.isWelcomeScreen()) {
  48.                 sleep(random(1000, 2000));
  49.             }
  50.             if (game.getClientState() == INDEX_LOBBY) {
  51.                 RSInterface welcome_screen = interfaces.get(INTERFACE_WELCOME_SCREEN);
  52.                 RSComponent welcome_screen_button_play_1 = welcome_screen.getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1);
  53.                 RSComponent welcome_screen_button_play_2 = welcome_screen.getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2);
  54.  
  55.                 mouse.click(
  56.                         welcome_screen_button_play_1.getAbsoluteX(),
  57.                         welcome_screen_button_play_1.getAbsoluteY(),
  58.                         welcome_screen_button_play_2.getAbsoluteX() + welcome_screen_button_play_2.getWidth() - welcome_screen_button_play_1.getAbsoluteX(),
  59.                         welcome_screen_button_play_1.getHeight(),
  60.                         true);
  61.  
  62.                 for (int i = 0; i < 4 && game.getClientState() == 6; i++) {
  63.                     sleep(500);
  64.                 }
  65.                 returnText = interfaces.get(INTERFACE_WELCOME_SCREEN).
  66.                         getComponent(INTERFACE_WELCOME_SCREEN_TEXT_RETURN).getText().toLowerCase();
  67.  
  68.                 if (returnText.contains("member's")) {
  69.                     log("Unable to login to a members world. Stopping script.");
  70.                     RSComponent back_button1 = interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(38);
  71.                     RSComponent back_button2 = interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(41);
  72.                     mouse.click(back_button1.getAbsoluteX(), back_button1.getAbsoluteY(),
  73.                             back_button2.getAbsoluteX() + back_button2.getWidth() - back_button1.getAbsoluteX(),
  74.                             back_button1.getHeight(), true);
  75.                     interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(203).doClick();
  76.                     stopScript(false);
  77.                 }
  78.             }
  79.             return -1;
  80.         }
  81.         if (!game.isLoggedIn()) {
  82.             if (returnText.contains("update")) {
  83.                 log("Runescape has been updated, please reload RSBot.");
  84.                 stopScript(false);
  85.             }
  86.             if (returnText.contains("not logged out")) {
  87.                 log("Account already logged in. Waiting a few seconds before trying again.");
  88.                 interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK_2).doClick();
  89.                 sleep(1000, 5000);
  90.             }
  91.             if (returnText.contains("disable")) {
  92.                 log("Your account is banned/disabled.");
  93.                 stopScript(false);
  94.             }
  95.             if (returnText.contains("incorrect")) {
  96.                 log("Failed to login five times in a row. Stopping script.");
  97.                 stopScript(false);
  98.             }
  99.             if (returnText.contains("invalid")) {
  100.                 if (invalidCount > 6) {
  101.                     log("Unable to login after 6 attempts. Stopping script.");
  102.                     log("Please verify that your RSBot account profile is correct.");
  103.                     stopScript(false);
  104.                 }
  105.                 interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK).doClick();
  106.                 invalidCount++;
  107.                 return random(500, 2000);
  108.             }
  109.             if (returnText.contains("error connecting")) {
  110.                 interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK).doClick();
  111.                 stopScript(false);
  112.                 return random(500, 2000);
  113.             }
  114.             if (returnText.contains("full")) {
  115.                 if (worldFullCount > 30) {
  116.                     log("World Is Full. Waiting for 15 seconds.");
  117.                     sleep(random(10000, 15000));
  118.                     worldFullCount = 0;
  119.                 }
  120.                 sleep(random(1000, 1200));
  121.                 worldFullCount++;
  122.             }
  123.             if (returnText.contains("world")) {
  124.                 return random(1000, 1200);
  125.             }
  126.             if (returnText.contains("logging in")) {
  127.                 return random(1000, 1200);
  128.             }
  129.         }
  130.         if (game.getClientState() == INDEX_LOGGED_OUT) {
  131.             if (!atLoginScreen()) {
  132.                 interfaces.getComponent(INTERFACE_MAIN, INTERFACE_MAIN_CHILD).getComponent(INTERFACE_MAIN_CHILD_COMPONENT_ID).doAction("");
  133.                 return random(500, 600);
  134.             }
  135.             if (isUsernameFilled() && isPasswordFilled()) {
  136.                 interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_LOGIN).doClick();
  137.                 return random(500, 600);
  138.             }
  139.             if (!isUsernameFilled()) {
  140.                 atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME_WINDOW));
  141.                 sleep(random(500, 700));
  142.                 textlength = interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME).getText().length() + random(3, 5);
  143.                 for (int i = 0; i <= textlength + random(1, 5); i++) {
  144.                     keyboard.sendText("\b", false);
  145.                     if (random(0, 2) == 1) {
  146.                         sleep(random(25, 100));
  147.                     }
  148.                 }
  149.                 keyboard.sendText(username, false);
  150.                 return random(500, 600);
  151.             }
  152.             if (isUsernameFilled() && !isPasswordFilled()) {
  153.                 atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD_WINDOW));
  154.                 sleep(random(500, 700));
  155.                 textlength = interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().length() + random(3, 5);
  156.                 for (int i = 0; i <= textlength + random(1, 5); i++) {
  157.                     keyboard.sendText("\b", false);
  158.                     if (random(0, 2) == 1) {
  159.                         sleep(random(25, 100));
  160.                     }
  161.                 }
  162.                 keyboard.sendText(account.getPassword(), false);
  163.             }
  164.         }
  165.         return random(500, 2000);
  166.     }
  167.  
  168.     // Clicks past all of the letters
  169.     private boolean atLoginInterface(RSComponent i) {
  170.         if (!i.isValid()) {
  171.             return false;
  172.         }
  173.         Rectangle pos = i.getArea();
  174.         if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  175.             return false;
  176.         }
  177.         int dy = (int) (pos.getHeight() - 4) / 2;
  178.         int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  179.         int midx = (int) (pos.getCenterX());
  180.         int midy = (int) (pos.getMinY() + pos.getHeight() / 2);
  181.         if (i.getIndex() == INTERFACE_PASSWORD_WINDOW) {
  182.             mouse.click(minX(i), midy + random(-dy, dy), true);
  183.         } else {
  184.             mouse.click(midx + random(1, maxRandomX), midy + random(-dy, dy), true);
  185.         }
  186.         return true;
  187.     }
  188.  
  189.     /*
  190.      * Returns x int based on the letters in a Child
  191.      * Only the password text is needed as the username text cannot reach past the middle of the interface
  192.      */
  193.     private int minX(RSComponent a) {
  194.         int x = 0;
  195.         Rectangle pos = a.getArea();
  196.         int dx = (int) (pos.getWidth() - 4) / 2;
  197.         int midx = (int) (pos.getMinX() + pos.getWidth() / 2);
  198.         if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  199.             return 0;
  200.         }
  201.         for (int i = 0; i < interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().length(); i++) {
  202.             x += 11;
  203.         }
  204.         if (x > 44) {
  205.             return (int) (pos.getMinX() + x + 15);
  206.         } else {
  207.             return midx + random(-dx, dx);
  208.         }
  209.     }
  210.  
  211.     private boolean atLoginScreen() {
  212.         return interfaces.get(596).isValid();
  213.     }
  214.  
  215.     private boolean isUsernameFilled() {
  216.         String username = account.getName().replaceAll("_", " ").toLowerCase().trim();
  217.         return interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME).getText().toLowerCase().equalsIgnoreCase(username);
  218.     }
  219.  
  220.     private boolean isPasswordFilled() {
  221.         return interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().toLowerCase().length() == account.getPassword().length();
  222.     }
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement