Advertisement
Guest User

Untitled

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