Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.53 KB | None | 0 0
  1. package org.rsbot.script.randoms;
  2. import org.rsbot.Configuration;
  3. import org.rsbot.gui.AccountManager;
  4. import org.rsbot.script.Random;
  5. import org.rsbot.script.ScriptManifest;
  6. import org.rsbot.script.methods.Environment;
  7. import org.rsbot.script.methods.Game;
  8. import org.rsbot.script.methods.Lobby;
  9. import org.rsbot.script.wrappers.RSComponent;
  10. import java.awt.*;
  11. import static org.rsbot.script.methods.Environment.LOGIN_GAME;
  12. import static org.rsbot.script.methods.Environment.LOGIN_LOBBY;
  13. /**
  14. * A simple script to login to the game.
  15. *
  16. * @author Timer
  17. */
  18. @ScriptManifest(authors = {"Timer"}, name = "Improved Login", version = 0.1)
  19. public class ImprovedLoginBot extends Random {
  20. public static final int INTERFACE_LOGIN_SCREEN = 596;
  21. public static final int INTERFACE_LOGIN_SCREEN_ENTER_GAME = 60;
  22. public static final int INTERFACE_LOGIN_SCREEN_USERNAME_TEXT = 73;
  23. public static final int INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT = 79;
  24. public static final int INTERFACE_LOGIN_SCREEN_ALERT_TEXT = 14;
  25. public static final int INTERFACE_LOGIN_SCREEN_ALERT_BACK = 68;
  26. public static final int INTERFACE_GRAPHICS_NOTICE = 976;
  27. public static final int INTERFACE_GRAPHICS_LEAVE_ALONE = 6;
  28. public static final int INTERFACE_LOBBY_HIGH_RISK_WORLD_TEXT = 98;
  29. public static final int INTERFACE_LOBBY_HIGH_RISK_WORLD_LOGIN_BUTTON = 104;
  30. private int world = -1;
  31. private String cachePassword = "";
  32. private int stageFlags = LOGIN_LOBBY | LOGIN_GAME;
  33. private final solution[] loginSolutions = {new solution() {
  34. private int invalidCount = 0;
  35. public boolean canApply(String message) {
  36. return message.contains("no reply from login server");
  37. }
  38. public int apply() {
  39. if (invalidCount > 10) {
  40. log.severe("It seems the login server is down.");
  41. stopScript(false);
  42. }
  43. invalidCount++;
  44. return random(500, 2000);
  45. }
  46. }, new solution() {
  47. public boolean canApply(String message) {
  48. return message.contains("update");
  49. }
  50. public int apply() {
  51. log("The game has been updated, please reload " + Configuration.NAME);
  52. stopScript(false);
  53. return 0;
  54. }
  55. }, new solution() {
  56. public boolean canApply(String message) {
  57. return message.contains("disable");
  58. }
  59. public int apply() {
  60. log.severe("It seems that your account has been disabled, that's unfortunate.");
  61. stopScript(false);
  62. return 0;
  63. }
  64. }, new solution() {
  65. private int invalidCount = 0;
  66. public boolean canApply(String message) {
  67. return message.contains("your account has not logged out");
  68. }
  69. public int apply() {
  70. if (invalidCount > 10) {
  71. log.severe("Your account is already logged in, change your password!");
  72. stopScript(false);
  73. }
  74. invalidCount++;
  75. log.warning("Waiting for logout..");
  76. return random(5000, 15000);
  77. }
  78. }, new solution() {
  79. private int fails = 0;
  80. public boolean canApply(String message) {
  81. return message.contains("invalid") || message.contains("incorrect");
  82. }
  83. public int apply() {
  84. fails++;
  85. if (fails > 3) {
  86. stopScript(false);
  87. return 0;
  88. }
  89. log.info("Login information incorrect, attempting again.");
  90. return random(1200, 3000);
  91. }
  92. }, new solution() {
  93. public boolean canApply(String message) {
  94. return message.contains("error connecting");
  95. }
  96. public int apply() {
  97. log.severe("No internet connection.");
  98. stopScript(false);
  99. return 0;
  100. }
  101. }, new solution() {
  102. private int invalidCount = 0;
  103. public boolean canApply(String message) {
  104. return message.contains("login limit exceeded");
  105. }
  106. public int apply() {
  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. return random(5000, 15000);
  114. }
  115. }, new solution() {
  116. public boolean canApply(String message) {
  117. return message.contains("world") || message.contains("performing login");
  118. }
  119. public int apply() {
  120. return random(4000, 5000);
  121. }
  122. }};
  123. private final solution[] lobbySolutions = {new solution() {
  124. public boolean canApply(String message) {
  125. return message.contains("total skill level of");
  126. }
  127. public int apply() {
  128. log.severe("Your combat level does not meet this world's requirements, run a skilling bot!");
  129. stopScript(true);
  130. return 0;
  131. }
  132. }, new solution() {
  133. public boolean canApply(String message) {
  134. return message.contains("login limit exceeded");
  135. }
  136. public int apply() {
  137. return random(3000, 8000);
  138. }
  139. }, new solution() {
  140. private int invalidCount = 0;
  141. public boolean canApply(String message) {
  142. return message.contains("your account has not logged out");
  143. }
  144. public int apply() {
  145. if (invalidCount > 10) {
  146. log.severe("You're already logged in! Change your password!");
  147. stopScript(false);
  148. }
  149. invalidCount++;
  150. log.warning("Waiting for logout..");
  151. return random(5000, 15000);
  152. }
  153. }, new solution() {
  154. public boolean canApply(String message) {
  155. return message.contains("member");
  156. }
  157. public int apply() {
  158. log.severe("Please run on a non-members world.");
  159. stopScript(false);
  160. return 0;
  161. }
  162. }, new solution() {
  163. public boolean canApply(String message) {
  164. return interfaces.getComponent(Lobby.INTERFACE_LOBBY, INTERFACE_LOBBY_HIGH_RISK_WORLD_TEXT).getText().toLowerCase().trim().contains("high-risk wilderness world");
  165. }
  166. public int apply() {
  167. interfaces.getComponent(Lobby.INTERFACE_LOBBY, INTERFACE_LOBBY_HIGH_RISK_WORLD_LOGIN_BUTTON).doClick();
  168. return 500;
  169. }
  170. }};
  171. private interface solution {
  172. boolean canApply(final String message);
  173. int apply();
  174. }
  175. @Override
  176. public boolean activateCondition() {
  177. final int idx = game.getClientState();
  178. return (((idx == Game.INDEX_LOGIN_SCREEN && (stageFlags & Environment.LOGIN_LOBBY) != 0) ||
  179. (idx == Game.INDEX_LOBBY_SCREEN && (stageFlags & Environment.LOGIN_GAME) != 0)) &&
  180. !switchingWorlds() && account.getName() != null) || (idx == Game.INDEX_LOBBY_SCREEN && (cachePassword.isEmpty() || cachePassword == null));
  181. }
  182. @Override
  183. public int loop() {
  184. if (lobby.inLobby() && (stageFlags & Environment.LOGIN_GAME) != 0) {
  185. if (lobby.getSelectedTab() != Lobby.TAB_PLAYERS) {
  186. lobby.open(Lobby.TAB_PLAYERS);
  187. return random(500, 800);
  188. }
  189. if (world != -1 && lobby.getSelectedWorld() != world) {
  190. lobby.switchWorlds(world, false);
  191. return random(500, 800);
  192. }
  193. if (lobby.clickPlay()) {
  194. for (int i = 0; i < 4 && game.getClientState() == 6; i++) {
  195. sleep(500);
  196. }
  197. final String returnText = interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_TEXT).getText().toLowerCase().trim();
  198. if (interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_CLOSE).isValid()) {
  199. interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_CLOSE).doClick();
  200. }
  201. for (solution subSolution : lobbySolutions) {
  202. if (subSolution.canApply(returnText)) {
  203. return subSolution.apply();
  204. }
  205. }
  206. }
  207. }
  208. if (game.getClientState() == Game.INDEX_LOGIN_SCREEN && (stageFlags & Environment.LOGIN_LOBBY) != 0) {
  209. if (interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE, INTERFACE_GRAPHICS_LEAVE_ALONE).isValid()) {
  210. interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE, INTERFACE_GRAPHICS_LEAVE_ALONE).doClick();
  211. return random(500, 600);
  212. }
  213. final String returnText = interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_ALERT_TEXT).getText().toLowerCase().trim();
  214. if (interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_ALERT_BACK).isValid()) {
  215. interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_ALERT_BACK).doClick();
  216. }
  217. for (solution subSolution : loginSolutions) {
  218. if (subSolution.canApply(returnText)) {
  219. return subSolution.apply();
  220. }
  221. }
  222. if (isUsernameCorrect() && isPasswordValid()) {
  223. attemptLogin();
  224. return random(1200, 1500);
  225. }
  226. if (!isUsernameCorrect()) {
  227. final String username = account.getName().toLowerCase().trim();
  228. atLoginInterface(interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_USERNAME_TEXT));
  229. sleep(random(500, 700));
  230. final int textLength = interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_USERNAME_TEXT).getText().length();
  231. if (textLength > 0) {
  232. for (int i = 0; i <= textLength + random(1, 5); i++) {
  233. keyboard.sendText("\b", false);
  234. if (random(0, 2) == 1) {
  235. sleep(random(25, 100));
  236. }
  237. }
  238. return random(500, 600);
  239. }
  240. keyboard.sendText(username, false);
  241. return random(500, 600);
  242. }
  243. if (isUsernameCorrect() && !isPasswordValid()) {
  244. atLoginInterface(interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT));
  245. sleep(random(500, 700));
  246. final int textLength = interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT).getText().length();
  247. if (textLength > 0) {
  248. for (int i = 0; i <= textLength + random(1, 5); i++) {
  249. keyboard.sendText("\b", false);
  250. if (random(0, 2) == 1) {
  251. sleep(random(25, 100));
  252. }
  253. }
  254. return random(500, 600);
  255. }
  256. String passWord = AccountManager.getPassword(account.getName());
  257. if (passWord.isEmpty()) {
  258. passWord = cachePassword;
  259. }
  260. keyboard.sendText(passWord, false);
  261. return random(500, 600);
  262. }
  263. }
  264. final int idx = game.getClientState();
  265. return ((idx == Game.INDEX_LOGIN_SCREEN && (stageFlags & Environment.LOGIN_LOBBY) == 0) ||
  266. (idx == Game.INDEX_LOBBY_SCREEN && (stageFlags & Environment.LOGIN_GAME) == 0) ||
  267. (game.isLoggedIn())) ? -1 : random(100, 500);
  268. }
  269. private boolean switchingWorlds() {
  270. return interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_TEXT).isValid() &&
  271. interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_TEXT).containsText("just left another world");
  272. }
  273. private boolean atLoginInterface(final RSComponent i) {
  274. if (!i.isValid()) {
  275. return false;
  276. }
  277. final Rectangle pos = i.getArea();
  278. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  279. return false;
  280. }
  281. final int dy = (int) (pos.getHeight() - 4) / 2;
  282. final int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  283. final int midx = (int) pos.getCenterX();
  284. final int midy = (int) (pos.getMinY() + pos.getHeight() / 2);
  285. if (i.getIndex() == INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT) {
  286. mouse.click(minX(i), midy + random(-dy, dy), true);
  287. } else {
  288. mouse.click(midx + random(1, maxRandomX), midy + random(-dy, dy), true);
  289. }
  290. return true;
  291. }
  292. private int minX(final RSComponent a) {
  293. int x = 0;
  294. final Rectangle pos = a.getArea();
  295. final int dx = (int) (pos.getWidth() - 4) / 2;
  296. final int midx = (int) (pos.getMinX() + pos.getWidth() / 2);
  297. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  298. return 0;
  299. }
  300. for (int i = 0; i < interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT).getText().length(); i++) {
  301. x += 11;
  302. }
  303. if (x > 44) {
  304. return (int) (pos.getMinX() + x + 15);
  305. } else {
  306. return midx + random(-dx, dx);
  307. }
  308. }
  309. private void attemptLogin() {
  310. keyboard.sendKey('\n');
  311. }
  312. private boolean isUsernameCorrect() {
  313. final String userName = account.getName().toLowerCase().trim();
  314. return interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_USERNAME_TEXT).getText().toLowerCase().equalsIgnoreCase(userName);
  315. }
  316. private boolean isPasswordValid() {
  317. String passWord = AccountManager.getPassword(account.getName());
  318. if (passWord.isEmpty()) {
  319. passWord = cachePassword;
  320. }
  321. return interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT).getText().length() == (passWord == null ? 0 : passWord.length());
  322. }
  323. /**
  324. * Sets the world to login to.
  325. *
  326. * @param world The world.
  327. */
  328. public void setWorld(final int world) {
  329. this.world = world;
  330. }
  331. /**
  332. * Gets the current set world.
  333. *
  334. * @return The world currently designated to login to.
  335. */
  336. public int getWorld() {
  337. return this.world;
  338. }
  339. /**
  340. * Sets login mask.
  341. */
  342. public void setMask(final int mask) {
  343. this.stageFlags = mask;
  344. }
  345. /**
  346. * The current login mask.
  347. *
  348. * @return The bytes of the mask.
  349. */
  350. public int getMask() {
  351. return this.stageFlags;
  352. }
  353. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement