Skip to content

Commit 1448d5f

Browse files
committed
Small bug fixes
* Ignore exceptions when loading the account properties file, handle with smaller error checking. (there is already a fallback process). * mudclient move sleep counter below other bot paint elements to prevent overlap * Slow down multiple bot loading. * Copy hashes.properties from the jar to assets folder (if missing) * Fix fatigue alignment in the client Clean up autologin code * This implementation uses timers (checking system time) instead of controller.sleep() which may have been causing bugs for very long sleep times when client could not connect. This is also much cleaner and safer in edge cases. Waiting for autologin time has been slightly shortened.
1 parent 7e063a2 commit 1448d5f

File tree

9 files changed

+60
-72
lines changed

9 files changed

+60
-72
lines changed

.gitlab-ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ pages:
6060
artifacts:
6161
paths:
6262
- public
63+
64+
# TODO - upload readme and doc to wiki https://gitlab.com/open-runescape-classic/idlersc/-/wikis/pages

app/src/main/java/bot/Main.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,9 @@ public static void main(String[] args)
420420
log("WindowListener started.");
421421

422422
// give everything a nice synchronization break juuuuuuuuuuuuuust in case...
423-
Thread.sleep(800);
423+
Thread.sleep(1000);
424424

425+
controller.login();
425426
// start up our listener threads
426427
log("Initializing LoginListener...");
427428
loginListener = new Thread(new LoginListener(controller));
@@ -444,6 +445,7 @@ public static void main(String[] args)
444445
DrawCallback.setNextRefresh( // was 25k
445446
System.currentTimeMillis() + 25000L + (long) (Math.random() * 10000));
446447
}
448+
447449
// System.out.println("Next screen refresh at: " + DrawCallback.getNextRefresh());
448450
while (true) {
449451
if (isRunning()) {
@@ -711,6 +713,10 @@ private static void initializeBotFrame(JComponent botFrame) {
711713
resetXpButton.addActionListener(e -> DrawCallback.resetXpCounter());
712714
showIdButton.addActionListener(e -> controller.toggleViewId());
713715
takeScreenshotButton.addActionListener(e -> controller.takeScreenshot(""));
716+
autoLoginCheckbox.addActionListener(
717+
e -> {
718+
if (autoLoginCheckbox.isSelected()) controller.login();
719+
});
714720
graphicsCheckbox.addActionListener(
715721
e -> {
716722
if (controller != null) {

app/src/main/java/bot/cli/CLIParser.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ private static void parseAccountProperties(ParseResult parseResult, String accou
162162
p.getProperty("help", "").replace(" ", "").toLowerCase().contains("true"));
163163
parseResult.setVersion(
164164
p.getProperty("version", "").replace(" ", "").toLowerCase().contains("true"));
165-
} catch (final Throwable t) {
166-
System.out.println("Error loading account " + parseResult.getUsername() + ": " + t);
165+
} catch (Exception ignore) {
166+
if (!accountName.equalsIgnoreCase("username") && !accountName.isEmpty()) {
167+
System.out.println("Error loading account - " + accountName);
168+
System.out.println(accountName + ".properties file does not exist");
169+
}
167170
}
168171
}
169172

app/src/main/java/callbacks/DrawCallback.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private static void drawBotStatus(Controller c) {
137137
y += 14;
138138
if (c.isAuthentic()) { // hidden on coleslaw so that submenu ON, Npc Kill counts ON can show
139139
// Kill counter at that screen location! Uranium will still get fatigue.
140-
c.drawString("Fatigue: " + fatigue + "@red@%", 7, y, 0xFFFFFF, 1);
140+
c.drawString("Fatigue: " + fatigue + "@red@%", 7, 202, 0xFFFFFF, 1);
141141
}
142142
y += 14;
143143

app/src/main/java/callbacks/SleepCallback.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private static void copyResource(String res, String dest, Class c) throws IOExce
346346
private static boolean checkAssetFiles() {
347347
File sleepDirectory = new File("assets" + File.separator + "sleep");
348348
File[] sleepFilelist = sleepDirectory.listFiles();
349-
String[] fileNames = {"dictionary.txt", "model.txt"};
349+
String[] fileNames = {"dictionary.txt", "model.txt", "hashes.properties"};
350350
if (sleepFilelist != null) {
351351
if (sleepFilelist.length != 2) return false;
352352
String[] sleepNames = new String[sleepFilelist.length];
@@ -390,6 +390,16 @@ private static void createAssetFiles() {
390390
"/assets/sleep/model.txt",
391391
"." + File.separator + "assets" + File.separator + "sleep" + File.separator + "model.txt",
392392
SleepCallback.class);
393+
copyResource(
394+
"/assets/sleep/hashes.properties",
395+
"."
396+
+ File.separator
397+
+ "assets"
398+
+ File.separator
399+
+ "sleep"
400+
+ File.separator
401+
+ "hashes.properties",
402+
SleepCallback.class);
393403
} catch (IOException e) {
394404
e.printStackTrace();
395405
System.out.println(e.getMessage());

app/src/main/java/listeners/LoginListener.java

+23-55
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* @author Dvorak
1212
*/
1313
public class LoginListener implements Runnable {
14-
private static long loginCount = 0;
14+
private static double loginCount = 0;
15+
private static double sleepTime = 0.0;
1516
private final Controller controller;
1617

1718
public LoginListener(Controller _controller) {
@@ -25,65 +26,32 @@ public void run() {
2526

2627
if (Main.isAutoLogin()) {
2728
if (!controller.isLoggedIn()) {
28-
controller.log("Logged out! Logging back in...");
29-
controller.login();
30-
controller.sleep(640);
31-
/*
32-
* Math.random returns value between 0.0 and 1.0
33-
*
34-
* <p>for the following: (Math.random() * (30000)) + 30000; thus Max Sleep was 60
35-
* seconds and Min Sleep was 30 seconds
36-
*
37-
* <p>This MIGHT be causing connection issues with extended downtimes and large bot
38-
* counts on one computer.
39-
*
40-
* <p>Suggested Values calculated with Excel Spreadsheet, Available from Kaila at
41-
* request. Suggested change: Math.random() * 30000) + (((i * 15)/(i + 60)) * 30000) +
42-
* 30000
43-
*
44-
* <p>bot will slowly ramp up to 5 min delays after several hrs of no reconnect, anding
45-
* the cycle after 12-14 hrs and repeating
46-
*
47-
* <p>First 5 tries - Original Behavior, Min Sleep is 30 seconds and Max Sleep is 60
48-
* seconds After 6 tries (After 2.5 to 5 mins) - Min Sleep is 57 seconds and Max Sleep
49-
* is 87 seconds (0.95 to 1.45 mins each cycle) After 15 tries (After 11 to 18 mins) -
50-
* Min Sleep is 90 seconds and Max Sleep is 120 seconds (1.5 to 2 mins each cycle) After
51-
* 30 tries (After 33.5 to 48 mins) - Min Sleep is 130 seconds and Max Sleep is 160
52-
* seconds (2.1 to 2.7 mins each cycle) After 60 tries (After 1.5 hrs to 2 hrs) - Min
53-
* Sleep is 180 seconds and Max Sleep is 210 seconds (3 to 3.5 mins each cycle) After
54-
* 120 tries (After 4.6 hrs to 5.5 hrs) - Min Sleep is 230 seconds and Max Sleep is 260
55-
* seconds (3.8 to 4.3 mins each cycle) After 240 tries (After 12.2 hrs to 14 hrs) - Min
56-
* Sleep is 270 seconds and Max Sleep is 300 seconds (4.5 to 5 mins each cycle)
57-
*
58-
* <p>then it resets timer and repeats ramping up cycle...
59-
*
60-
* <p>~ Kaila ~
61-
*/
62-
if (!controller.isLoggedIn()) {
63-
int i = (int) loginCount;
64-
int sleepTime = (int) ((Math.random() * 20000) + 60000);
65-
if (loginCount > 10) {
66-
sleepTime = sleepTime + (((i * 30) / (i + 60)) * 30000);
67-
}
68-
int sleepTimeInSeconds = sleepTime / 1000;
69-
controller.log(
70-
"Looks like we could not login... trying again in "
71-
+ sleepTimeInSeconds
72-
+ " seconds...",
73-
"cya");
74-
controller.sleep(sleepTime);
29+
if (System.currentTimeMillis() > sleepTime) {
30+
controller.log("Logged out! Logging back in...");
31+
controller.login();
7532
loginCount++;
76-
} else loginCount = 0;
77-
}
33+
controller.sleep(640);
34+
// calc the next login time
35+
if (loginCount > 10)
36+
sleepTime =
37+
System.currentTimeMillis() + (((loginCount * 30) / (loginCount + 60)) * 20000);
38+
else
39+
sleepTime =
40+
System.currentTimeMillis() + ((Math.random() * 20000 * loginCount) + 20000);
41+
if (!controller.isLoggedIn()) {
42+
controller.log(
43+
"Looks like we could not login... trying again in "
44+
+ (int) ((sleepTime - System.currentTimeMillis()) / 1000)
45+
+ " seconds...",
46+
"cya");
47+
}
48+
}
49+
} else if (loginCount != 0) loginCount = 0;
7850
}
79-
80-
if (controller.getMoveCharacter()) {
51+
if (!controller.isAuthentic() && controller.getMoveCharacter()) {
8152
moveCharacter();
8253
controller.charactedMoved();
8354
}
84-
if (controller.isLoggedIn() && loginCount > 0) {
85-
loginCount = 0;
86-
}
8755
Thread.sleep(1000);
8856
}
8957
} catch (InterruptedException e) {

app/src/main/java/scripting/idlescript/AIOFighter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public void questMessageInterrupt(String message) {
677677
else if (message.equals("I can't get a clear shot from here")) {
678678
c.setStatus("@red@Walking to NPC to get a shot...");
679679
c.walktoNPCAsync(currentAttackingNpc);
680-
c.sleep(1280);
680+
c.sleep(2400);
681681
}
682682
}
683683

app/src/main/java/scripting/idlescript/K_NoBank_TavChaos.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,7 @@ private void hobsToChaos() {
561561
c.walkTo(377, 520);
562562
// check for needing more newts here
563563
doHerblawLoop();
564-
if (startUp
565-
|| (getNewtSecCount() == 0 && c.getInventoryItemCount(ItemId.EYE_OF_NEWT.getId()) > 5)) {
564+
if (startUp || (getNewtSecCount() == 0)) {
566565
c.atObject(376, 520);
567566
c.sleep(1280);
568567
c.walkTo(376, 3347);

scripts/run_multiple_clients.bat

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@
1616
TIMEOUT /t 1 > NUL
1717
start javaw -jar IdleRSC.jar --auto-start --account "name"
1818
echo Launched 1st Bot
19-
TIMEOUT /t 2 > NUL
19+
TIMEOUT /t 5 > NUL
2020
start javaw -jar IdleRSC.jar --auto-start --account "name"
2121
echo Launched 2nd Bot
22-
TIMEOUT /t 2 > NUL
22+
TIMEOUT /t 5 > NUL
2323
start javaw -jar IdleRSC.jar --auto-start --account "name"
2424
echo Launched 3rd Bot
25-
TIMEOUT /t 2 > NUL
25+
TIMEOUT /t 5 > NUL
2626
start javaw -jar IdleRSC.jar --auto-start --account "name"
2727
echo Launched 4th Bot
28-
TIMEOUT /t 2 > NUL
28+
TIMEOUT /t 5 > NUL
2929
start javaw -jar IdleRSC.jar --auto-start --account "name"
3030
echo Launched 5th Bot
31-
TIMEOUT /t 2 > NUL
31+
TIMEOUT /t 5 > NUL
3232
start javaw -jar IdleRSC.jar --auto-start --account "name"
3333
echo Launched 6th Bot
34-
TIMEOUT /t 2 > NUL
34+
TIMEOUT /t 5 > NUL
3535
start javaw -jar IdleRSC.jar --auto-start --account "name"
3636
echo Launched 7th Bot
37-
TIMEOUT /t 2 > NUL
37+
TIMEOUT /t 5 > NUL
3838
start javaw -jar IdleRSC.jar --auto-start --account "name"
3939
echo Launched 8th Bot
40-
TIMEOUT /t 2 > NUL
40+
TIMEOUT /t 5 > NUL
4141
start javaw -jar IdleRSC.jar --auto-start --account "name"
4242
echo Launched 9th Bot
43-
TIMEOUT /t 2 > NUL
43+
TIMEOUT /t 5 > NUL
4444
start javaw -jar IdleRSC.jar --auto-start --account "name"
4545
echo Launched 10th Bot
4646
TIMEOUT /t 5

0 commit comments

Comments
 (0)