Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.65 KB | None | 0 0
  1. package org.rsbot.script.randoms;
  2.  
  3. import org.rsbot.gui.AccountManager;
  4. import org.rsbot.script.Random;
  5. import org.rsbot.script.ScriptManifest;
  6. import org.rsbot.script.wrappers.RSComponent;
  7. import org.rsbot.script.wrappers.RSInterface;
  8.  
  9. import java.awt.*;
  10. import java.awt.event.KeyEvent;
  11.  
  12. /**
  13.  * @author Iscream, Aut0r, Doout, Pervy, jtryba
  14.  */
  15. @ScriptManifest(authors = {"Iscream", "Pervy Shuya", "Aut0r"}, name = "Login", version = 2.01)
  16. public class LoginBot extends Random {
  17.  
  18.     private static final int INTERFACE_MAIN = 905;
  19.     private static final int INTERFACE_MAIN_CHILD = 59;
  20.     private static final int INTERFACE_MAIN_CHILD_COMPONENT_ID = 4;
  21.     private static final int INTERFACE_LOGIN_SCREEN = 596;
  22.     private static final int INTERFACE_USERNAME = 65;
  23.     private static final int INTERFACE_USERNAME_WINDOW = 37;
  24.     private static final int INTERFACE_PASSWORD = 71;
  25.     private static final int INTERFACE_PASSWORD_WINDOW = 39;
  26.     private static final int INTERFACE_BUTTON_LOGIN = 42;
  27.     private static final int INTERFACE_TEXT_RETURN = 11;
  28.     private static final int INTERFACE_BUTTON_BACK = 60;
  29.     private static final int INTERFACE_WELCOME_SCREEN = 906;
  30.     private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1 = 160;
  31.     private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2 = 171;
  32.     //private static final int INTERFACE_WELCOME_SCREEN_BUTTON_LOGOUT = 193;
  33.     private static final int INTERFACE_WELCOME_SCREEN_TEXT_RETURN = 224;
  34.     private static final int INTERFACE_WELCOME_SCREEN_BUTTON_BACK = 231;
  35.     private static final int INTERFACE_WELCOME_SCREEN_HIGH_RISK_WORLD_TEXT = 86;
  36.     private static final int INTERFACE_WELCOME_SCREEN_HIGH_RISK_WORLD_LOGIN_BUTTON = 93;
  37.     private static final int INTERFACE_GRAPHICS_NOTICE = 976;
  38.     private static final int INTERFACE_GRAPHICS_LEAVE_ALONE = 6;
  39.  
  40.     private static final int INDEX_LOGGED_OUT = 3;
  41.     private static final int INDEX_LOBBY = 7;
  42.  
  43.     private int invalidCount, worldFullCount;
  44.  
  45.     public Random Rand;
  46.  
  47.     @Override
  48.     public boolean activateCondition() {
  49.         int idx = game.getClientState();
  50.         return (idx == INDEX_LOGGED_OUT || idx == INDEX_LOBBY)
  51.                 && !switchingWorlds() && account.getName() != null;
  52.     }
  53.  
  54.     @Override
  55.     public int loop() {
  56.         String username = account.getName().toLowerCase().trim();
  57.         String returnText = interfaces.get(INTERFACE_LOGIN_SCREEN)
  58.                 .getComponent(INTERFACE_TEXT_RETURN).getText().toLowerCase();
  59.         int textlength;
  60.         if (game.getClientState() != INDEX_LOGGED_OUT) {
  61.             if (!game.isWelcomeScreen()) {
  62.                 sleep(random(1000, 2000));
  63.             }
  64.             if (game.getClientState() == INDEX_LOBBY) {
  65.                 RSInterface welcome_screen = interfaces
  66.                         .get(INTERFACE_WELCOME_SCREEN);
  67.                 RSComponent welcome_screen_button_play_1 = welcome_screen
  68.                         .getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1);
  69.                 RSComponent welcome_screen_button_play_2 = welcome_screen
  70.                         .getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2);
  71.  
  72.                 mouse.click(welcome_screen_button_play_1.getAbsoluteX(),
  73.                         welcome_screen_button_play_1.getAbsoluteY(),
  74.                         welcome_screen_button_play_2.getAbsoluteX()
  75.                                 + welcome_screen_button_play_2.getWidth()
  76.                                 - welcome_screen_button_play_1.getAbsoluteX(),
  77.                         welcome_screen_button_play_1.getHeight(), true);
  78.  
  79.                 for (int i = 0; i < 4 && game.getClientState() == 6; i++) {
  80.                     sleep(500);
  81.                 }
  82.                 returnText = interfaces.get(INTERFACE_WELCOME_SCREEN)
  83.                         .getComponent(INTERFACE_WELCOME_SCREEN_TEXT_RETURN)
  84.                         .getText().toLowerCase();
  85.  
  86.                 if (returnText.contains("total skill level of")
  87.                         && !AccountManager.isMember(account.getName())) {
  88.                     log("Log back in when you total level of 1000+");
  89.                     interfaces.getComponent(INTERFACE_WELCOME_SCREEN,
  90.                             INTERFACE_WELCOME_SCREEN_BUTTON_BACK).doClick();
  91.                     stopScript(false);
  92.                 } else if (returnText.contains("total skill level of")
  93.                         && AccountManager.isMember(account.getName())) {
  94.                     log("Log back in when you total level of 1500+");
  95.                     interfaces.getComponent(INTERFACE_WELCOME_SCREEN,
  96.                             INTERFACE_WELCOME_SCREEN_BUTTON_BACK).doClick();
  97.                     stopScript(false);
  98.                 }
  99.  
  100.                 if (returnText.contains("login limit exceeded")) {
  101.                     if (interfaces.getComponent(INTERFACE_WELCOME_SCREEN, INTERFACE_WELCOME_SCREEN_BUTTON_BACK).isValid()) {
  102.                         interfaces.getComponent(INTERFACE_WELCOME_SCREEN, INTERFACE_WELCOME_SCREEN_BUTTON_BACK).doClick();
  103.                     }
  104.                 }
  105.  
  106.                 if (returnText.contains("your account has not logged out")) {
  107.                     if (invalidCount > 10) {
  108.                         log.warning("Unable to login after 10 attempts. Stopping script.");
  109.                         log.severe("It seems you are actually already logged in?");
  110.                         stopScript(false);
  111.                     }
  112.                     invalidCount++;
  113.                     log.severe("Waiting for logout..");
  114.                     sleep(5000, 15000);
  115.                 }
  116.  
  117.                 if (returnText.contains("member")) {
  118.                     log("Unable to login to a members world. Stopping script.");
  119.                     RSComponent back_button1 = interfaces.get(
  120.                             INTERFACE_WELCOME_SCREEN).getComponent(228);
  121.                     RSComponent back_button2 = interfaces.get(
  122.                             INTERFACE_WELCOME_SCREEN).getComponent(231);
  123.                     mouse.click(
  124.                             back_button1.getAbsoluteX(),
  125.                             back_button1.getAbsoluteY(),
  126.                             back_button2.getAbsoluteX()
  127.                                     + back_button2.getWidth()
  128.                                     - back_button1.getAbsoluteX(),
  129.                             back_button1.getHeight(), true);
  130.                     interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(203)
  131.                             .doClick();
  132.                     stopScript(false);
  133.                 }
  134.  
  135.                 if (interfaces
  136.                         .get(INTERFACE_WELCOME_SCREEN)
  137.                         .getComponent(
  138.                                 INTERFACE_WELCOME_SCREEN_HIGH_RISK_WORLD_TEXT)
  139.                         .getText().toLowerCase().trim()
  140.                         .contains("high-risk wilderness world")) {
  141.                     interfaces
  142.                             .get(INTERFACE_WELCOME_SCREEN)
  143.                             .getComponent(
  144.                                     INTERFACE_WELCOME_SCREEN_HIGH_RISK_WORLD_LOGIN_BUTTON)
  145.                             .doClick();
  146.                 }
  147.             }
  148.             return -1;
  149.         }
  150.         if (!game.isLoggedIn()) {
  151.             if (interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK).isValid()) {
  152.                 interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK).doClick();
  153.             }
  154.             if (returnText.contains("no reply from login server")) {
  155.                 if (invalidCount > 10) {
  156.                     log.warning("Unable to login after 10 attempts. Stopping script.");
  157.                     log.severe("It seems the login server is down.");
  158.                     stopScript(false);
  159.                 }
  160.                 invalidCount++;
  161.                 return random(500, 2000);
  162.             }
  163.             if (returnText.contains("update")) {
  164.                 log("Runescape has been updated, please reload RSBot.");
  165.                 stopScript(false);
  166.             }
  167.             if (returnText.contains("disable")) {
  168.                 log.severe("Your account is banned/disabled.");
  169.                 stopScript(false);
  170.             }
  171.             if (returnText.contains("your account has not logged out")) {
  172.                 if (invalidCount > 10) {
  173.                     log.warning("Unable to login after 10 attempts. Stopping script.");
  174.                     log.severe("It seems you are actually already logged in?");
  175.                     stopScript(false);
  176.                 }
  177.                 invalidCount++;
  178.                 log.severe("Waiting for logout..");
  179.                 sleep(5000, 15000);
  180.             }
  181.             if (returnText.contains("incorrect")) {
  182.                 log.warning("Failed to login five times in a row. Stopping script.");
  183.                 stopScript(false);
  184.             }
  185.             if (returnText.contains("invalid")) {
  186.                 if (invalidCount > 6) {
  187.                     log.warning("Unable to login after 6 attempts. Stopping script.");
  188.                     log("Please verify that your RSBot account profile is correct.");
  189.                     stopScript(false);
  190.                 }
  191.                 invalidCount++;
  192.                 return random(500, 2000);
  193.             }
  194.             if (returnText.contains("error connecting")) {
  195.                 interfaces.get(INTERFACE_LOGIN_SCREEN)
  196.                         .getComponent(INTERFACE_BUTTON_BACK).doClick();
  197.                 stopScript(false);
  198.                 return random(500, 2000);
  199.             }
  200.             if (returnText.contains("full")) {
  201.                 if (worldFullCount > 30) {
  202.                     log("World Is Full. Waiting for 15 seconds.");
  203.                     sleep(random(10000, 15000));
  204.                     worldFullCount = 0;
  205.                 }
  206.                 sleep(random(1000, 1200));
  207.                 worldFullCount++;
  208.             }
  209.             if (returnText.contains("login limit exceeded")) {
  210.                 if (invalidCount > 10) {
  211.                     log.warning("Unable to login after 10 attempts. Stopping script.");
  212.                     log.severe("It seems you are actually already logged in?");
  213.                     stopScript(false);
  214.                 }
  215.                 invalidCount++;
  216.                 sleep(5000, 15000);
  217.             }
  218.             if (returnText.contains("world")) {
  219.                 return random(1500, 2000);
  220.             }
  221.             if (returnText.contains("performing login")) {
  222.                 return random(1500, 2000);
  223.             }
  224.         }
  225.         if (game.getClientState() == INDEX_LOGGED_OUT) {
  226.             if (interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE,
  227.                     INTERFACE_GRAPHICS_LEAVE_ALONE).isValid()) {
  228.                 interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE,
  229.                         INTERFACE_GRAPHICS_LEAVE_ALONE).doClick();
  230.                 if (interfaces.getComponent(INTERFACE_BUTTON_BACK).isValid()) {
  231.                     interfaces.getComponent(INTERFACE_BUTTON_BACK).doClick();
  232.                 }
  233.                 return random(500, 600);
  234.             }
  235.             if (!atLoginScreen()) {
  236.                 interfaces.getComponent(INTERFACE_MAIN, INTERFACE_MAIN_CHILD)
  237.                         .getComponent(INTERFACE_MAIN_CHILD_COMPONENT_ID)
  238.                         .doAction("");
  239.                 return random(500, 600);
  240.             }
  241.             if (isUsernameFilled() && isPasswordFilled()) {
  242.                 if (random(0, 2) == 0) {
  243.                     keyboard.pressKey((char) KeyEvent.VK_ENTER);
  244.                 } else {
  245.                     interfaces.get(INTERFACE_LOGIN_SCREEN)
  246.                             .getComponent(INTERFACE_BUTTON_LOGIN).doClick();
  247.                 }
  248.                 return random(500, 600);
  249.             }
  250.             if (!isUsernameFilled()) {
  251.                 atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN)
  252.                         .getComponent(INTERFACE_USERNAME_WINDOW));
  253.                 sleep(random(500, 700));
  254.                 textlength = interfaces.get(INTERFACE_LOGIN_SCREEN)
  255.                         .getComponent(INTERFACE_USERNAME).getText().length()
  256.                         + random(3, 5);
  257.                 for (int i = 0; i <= textlength + random(1, 5); i++) {
  258.                     keyboard.sendText("\b", false);
  259.                     if (random(0, 2) == 1) {
  260.                         sleep(random(25, 100));
  261.                     }
  262.                 }
  263.                 keyboard.sendText(username, false);
  264.                 return random(500, 600);
  265.             }
  266.             if (isUsernameFilled() && !isPasswordFilled()) {
  267.                 atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN)
  268.                         .getComponent(INTERFACE_PASSWORD_WINDOW));
  269.                 sleep(random(500, 700));
  270.                 textlength = interfaces.get(INTERFACE_LOGIN_SCREEN)
  271.                         .getComponent(INTERFACE_PASSWORD).getText().length()
  272.                         + random(3, 5);
  273.                 for (int i = 0; i <= textlength + random(1, 5); i++) {
  274.                     keyboard.sendText("\b", false);
  275.                     if (random(0, 2) == 1) {
  276.                         sleep(random(25, 100));
  277.                     }
  278.                 }
  279.                 keyboard.sendText(AccountManager.getPassword(account.getName()), false);
  280.             }
  281.         }
  282.         return random(500, 2000);
  283.     }
  284.  
  285.     private boolean switchingWorlds() {
  286.         return interfaces.get(INTERFACE_WELCOME_SCREEN)
  287.                 .getComponent(INTERFACE_WELCOME_SCREEN_TEXT_RETURN).isValid()
  288.                 && interfaces.get(INTERFACE_WELCOME_SCREEN)
  289.                 .getComponent(INTERFACE_WELCOME_SCREEN_TEXT_RETURN)
  290.                 .containsText("just left another world");
  291.     }
  292.  
  293.     // Clicks past all of the letters
  294.     private boolean atLoginInterface(RSComponent i) {
  295.         if (!i.isValid()) {
  296.             return false;
  297.         }
  298.         Rectangle pos = i.getArea();
  299.         if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  300.             return false;
  301.         }
  302.         int dy = (int) (pos.getHeight() - 4) / 2;
  303.         int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  304.         int midx = (int) (pos.getCenterX());
  305.         int midy = (int) (pos.getMinY() + pos.getHeight() / 2);
  306.         if (i.getIndex() == INTERFACE_PASSWORD_WINDOW) {
  307.             mouse.click(minX(i), midy + random(-dy, dy), true);
  308.         } else {
  309.             mouse.click(midx + random(1, maxRandomX), midy + random(-dy, dy),
  310.                     true);
  311.         }
  312.         return true;
  313.     }
  314.  
  315.     /*
  316.           * Returns x int based on the letters in a Child Only the password text is
  317.           * needed as the username text cannot reach past the middle of the interface
  318.           */
  319.     private int minX(RSComponent a) {
  320.         int x = 0;
  321.         Rectangle pos = a.getArea();
  322.         int dx = (int) (pos.getWidth() - 4) / 2;
  323.         int midx = (int) (pos.getMinX() + pos.getWidth() / 2);
  324.         if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  325.             return 0;
  326.         }
  327.         for (int i = 0; i < interfaces.get(INTERFACE_LOGIN_SCREEN)
  328.                 .getComponent(INTERFACE_PASSWORD).getText().length(); i++) {
  329.             x += 11;
  330.         }
  331.         if (x > 44) {
  332.             return (int) (pos.getMinX() + x + 15);
  333.         } else {
  334.             return midx + random(-dx, dx);
  335.         }
  336.     }
  337.  
  338.     private boolean atLoginScreen() {
  339.         return interfaces.get(596).isValid();
  340.     }
  341.  
  342.     private boolean isUsernameFilled() {
  343.         String username = account.getName().toLowerCase().trim();
  344.         return interfaces.get(INTERFACE_LOGIN_SCREEN)
  345.                 .getComponent(INTERFACE_USERNAME).getText().toLowerCase()
  346.                 .equalsIgnoreCase(username);
  347.     }
  348.  
  349.     private boolean isPasswordFilled() {
  350.         String passWord = AccountManager.getPassword(account.getName());
  351.         return interfaces.get(INTERFACE_LOGIN_SCREEN)
  352.                 .getComponent(INTERFACE_PASSWORD).getText().toLowerCase()
  353.                 .length() == (passWord == null ? 0 : passWord.length());
  354.     }
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement