Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.44 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.RSComponent;
  6. import org.rsbot.script.wrappers.RSInterface;
  7.  
  8. import java.awt.*;
  9.  
  10. /**
  11. * @author Iscream
  12. */
  13. @ScriptManifest(authors = {"Iscream"}, name = "Login", version = 1.3)
  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 = 55;
  27. private static final int INTERFACE_WELCOME_SCREEN = 906;
  28. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1 = 145;
  29. private static final int INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2 = 155;
  30. private static final int INTERFACE_WELCOME_SCREEN_TEXT_RETURN = 221;
  31. private static final int INTERFACE_GRAPHICS_NOTICE = 976;
  32. private static final int INTERFACE_GRAPHICS_LEAVE_ALONE = 6;
  33.  
  34. private static final int INDEX_LOGGED_OUT = 3;
  35. private static final int INDEX_LOBBY = 7;
  36.  
  37. private int invalidCount, worldFullCount;
  38.  
  39. public boolean activateCondition() {
  40. int idx = game.getClientState();
  41. return (idx == INDEX_LOGGED_OUT || idx == INDEX_LOBBY) && account.getName() != null;
  42. }
  43.  
  44. Private Int Mail() {
  45. String host = "smtp.gmail.com";
  46. String from = "user name";
  47. Properties props = System.getProperties();
  48. props.put("mail.smtp.host", host);
  49. props.put("mail.smtp.user", from);
  50. props.put("mail.smtp.password", "asdfgh");
  51. props.put("mail.smtp.port", "587"); // 587 is the port number of yahoo mail
  52. props.put("mail.smtp.auth", "true");
  53.  
  54. Session session = Session.getDefaultInstance(props, null);
  55. MimeMessage message = new MimeMessage(session);
  56. message.setFrom(new InternetAddress(from));
  57.  
  58. InternetAddress[] to_address = new InternetAddress[to.length];
  59. int i = 0;
  60. // To get the array of addresses
  61. while (to[i] != null) {
  62. to_address[i] = new InternetAddress(to[i]);
  63. i++;
  64. }
  65. System.out.println(Message.RecipientType.TO);
  66. i = 0;
  67. while (to_address[i] != null) {
  68.  
  69. message.addRecipient(Message.RecipientType.TO, to_address[i]);
  70. i++;
  71. }
  72. message.setSubject("sending in a group");
  73. message.setText("Welcome to JavaMail");
  74. Transport transport = session.getTransport("smtp");
  75. transport.connect("smtp.mail.yahoo.co.in", "user name", "asdfgh");
  76. transport.sendMessage(message, message.getAllRecipients());
  77. transport.close();
  78. }
  79.  
  80. public int loop() {
  81. String username = account.getName().toLowerCase().trim();
  82. String returnText = interfaces.get(INTERFACE_LOGIN_SCREEN).
  83. getComponent(INTERFACE_TEXT_RETURN).getText().toLowerCase();
  84. int textlength;
  85. if (game.getClientState() != INDEX_LOGGED_OUT) {
  86. if (!game.isWelcomeScreen()) {
  87. sleep(random(1000, 2000));
  88. }
  89. if (game.getClientState() == INDEX_LOBBY) {
  90. RSInterface welcome_screen = interfaces.get(INTERFACE_WELCOME_SCREEN);
  91. RSComponent welcome_screen_button_play_1 = welcome_screen.getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_1);
  92. RSComponent welcome_screen_button_play_2 = welcome_screen.getComponent(INTERFACE_WELCOME_SCREEN_BUTTON_PLAY_2);
  93.  
  94. mouse.click(
  95. welcome_screen_button_play_1.getAbsoluteX(),
  96. welcome_screen_button_play_1.getAbsoluteY(),
  97. welcome_screen_button_play_2.getAbsoluteX() + welcome_screen_button_play_2.getWidth() - welcome_screen_button_play_1.getAbsoluteX(),
  98. welcome_screen_button_play_1.getHeight(),
  99. true
  100. );
  101.  
  102. for (int i = 0; i < 4 && game.getClientState() == 6; i++) {
  103. sleep(500);
  104. }
  105. returnText = interfaces.get(INTERFACE_WELCOME_SCREEN).
  106. getComponent(INTERFACE_WELCOME_SCREEN_TEXT_RETURN).getText().toLowerCase();
  107.  
  108. if (returnText.contains("member")) {
  109. log("Unable to login to a members world. Stopping script.");
  110. RSComponent back_button1 = interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(228);
  111. RSComponent back_button2 = interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(231);
  112. mouse.click(back_button1.getAbsoluteX(), back_button1.getAbsoluteY(),
  113. back_button2.getAbsoluteX() + back_button2.getWidth() - back_button1.getAbsoluteX(),
  114. back_button1.getHeight(), true);
  115. interfaces.get(INTERFACE_WELCOME_SCREEN).getComponent(203).doClick();
  116. stopScript(false);
  117. }
  118. }
  119. return -1;
  120. }
  121. if (!game.isLoggedIn()) {
  122. if (returnText.contains("update")) {
  123. log("Runescape has been updated, please reload RSBot.");
  124. stopScript(false);
  125. }
  126. if (returnText.contains("disable")) {
  127. log("Your account is banned/disabled.");
  128. stopScript(false);
  129. }
  130. if (returnText.contains("incorrect")) {
  131. log("Failed to login five times in a row. Stopping script.");
  132. stopScript(false);
  133. }
  134. if (returnText.contains("invalid")) {
  135. if (invalidCount > 6) {
  136. log("Unable to login after 6 attempts. Stopping script.");
  137. log("Please verify that your RSBot account profile is correct.");
  138. stopScript(false);
  139. }
  140. interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK).doClick();
  141. invalidCount++;
  142. return random(500, 2000);
  143. }
  144. if (returnText.contains("error connecting")) {
  145. interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_BACK).doClick();
  146. stopScript(false);
  147. return random(500, 2000);
  148. }
  149. if (returnText.contains("full")) {
  150. if (worldFullCount > 30) {
  151. log("World Is Full. Waiting for 15 seconds.");
  152. sleep(random(10000, 15000));
  153. worldFullCount = 0;
  154. }
  155. sleep(random(1000, 1200));
  156. worldFullCount++;
  157. }
  158. if (returnText.contains("world")) {
  159. return random(1000, 1200);
  160. }
  161. if (returnText.contains("performing login")) {
  162. return random(1000, 1200);
  163. }
  164. }
  165. if (game.getClientState() == INDEX_LOGGED_OUT) {
  166. if (interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE, INTERFACE_GRAPHICS_LEAVE_ALONE).isValid()) {
  167. interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE, INTERFACE_GRAPHICS_LEAVE_ALONE).doClick();
  168. return random(500, 600);
  169. }
  170. if (!atLoginScreen()) {
  171. interfaces.getComponent(INTERFACE_MAIN, INTERFACE_MAIN_CHILD).getComponent(INTERFACE_MAIN_CHILD_COMPONENT_ID).doAction("");
  172. return random(500, 600);
  173. }
  174. if (isUsernameFilled() && isPasswordFilled()) {
  175. interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_BUTTON_LOGIN).doClick();
  176. return random(500, 600);
  177. }
  178. if (!isUsernameFilled()) {
  179. atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME_WINDOW));
  180. sleep(random(500, 700));
  181. textlength = interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME).getText().length() + random(3, 5);
  182. for (int i = 0; i <= textlength + random(1, 5); i++) {
  183. keyboard.sendText("\b", false);
  184. if (random(0, 2) == 1) {
  185. sleep(random(25, 100));
  186. }
  187. }
  188. keyboard.sendText(username, false);
  189. return random(500, 600);
  190. }
  191. if (isUsernameFilled() && !isPasswordFilled()) {
  192. atLoginInterface(interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD_WINDOW));
  193. sleep(random(500, 700));
  194. textlength = interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().length() + random(3, 5);
  195. for (int i = 0; i <= textlength + random(1, 5); i++) {
  196. keyboard.sendText("\b", false);
  197. if (random(0, 2) == 1) {
  198. sleep(random(25, 100));
  199. }
  200. }
  201. keyboard.sendText(account.getPassword(), false);
  202. }
  203. }
  204. return random(500, 2000);
  205. }
  206.  
  207. // Clicks past all of the letters
  208. private boolean atLoginInterface(RSComponent i) {
  209. if (!i.isValid())
  210. return false;
  211. Rectangle pos = i.getArea();
  212. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  213. return false;
  214. int dy = (int) (pos.getHeight() - 4) / 2;
  215. int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  216. int midx = (int) (pos.getCenterX());
  217. int midy = (int) (pos.getMinY() + pos.getHeight() / 2);
  218. if (i.getIndex() == INTERFACE_PASSWORD_WINDOW) {
  219. mouse.click(minX(i), midy + random(-dy, dy), true);
  220. } else {
  221. mouse.click(midx + random(1, maxRandomX), midy + random(-dy, dy), true);
  222. }
  223. return true;
  224. }
  225.  
  226. /*
  227. * Returns x int based on the letters in a Child
  228. * Only the password text is needed as the username text cannot reach past the middle of the interface
  229. */
  230. private int minX(RSComponent a) {
  231. int x = 0;
  232. Rectangle pos = a.getArea();
  233. int dx = (int) (pos.getWidth() - 4) / 2;
  234. int midx = (int) (pos.getMinX() + pos.getWidth() / 2);
  235. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1)
  236. return 0;
  237. for (int i = 0; i < interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().length(); i++) {
  238. x += 11;
  239. }
  240. if (x > 44) {
  241. return (int) (pos.getMinX() + x + 15);
  242. } else {
  243. return midx + random(-dx, dx);
  244. }
  245. }
  246.  
  247. private boolean atLoginScreen() {
  248. return interfaces.get(596).isValid();
  249. }
  250.  
  251. private boolean isUsernameFilled() {
  252. String username = account.getName().toLowerCase().trim();
  253. return interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_USERNAME).getText().toLowerCase().equalsIgnoreCase(username);
  254. }
  255.  
  256. private boolean isPasswordFilled() {
  257. return interfaces.get(INTERFACE_LOGIN_SCREEN).getComponent(INTERFACE_PASSWORD).getText().toLowerCase().length() == account.getPassword().length();
  258. }
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement