11
11
* @author Dvorak
12
12
*/
13
13
public class LoginListener implements Runnable {
14
- private static long loginCount = 0 ;
14
+ private static double loginCount = 0 ;
15
+ private static double sleepTime = 0.0 ;
15
16
private final Controller controller ;
16
17
17
18
public LoginListener (Controller _controller ) {
@@ -25,65 +26,32 @@ public void run() {
25
26
26
27
if (Main .isAutoLogin ()) {
27
28
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 ();
75
32
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 ;
78
50
}
79
-
80
- if (controller .getMoveCharacter ()) {
51
+ if (!controller .isAuthentic () && controller .getMoveCharacter ()) {
81
52
moveCharacter ();
82
53
controller .charactedMoved ();
83
54
}
84
- if (controller .isLoggedIn () && loginCount > 0 ) {
85
- loginCount = 0 ;
86
- }
87
55
Thread .sleep (1000 );
88
56
}
89
57
} catch (InterruptedException e ) {
0 commit comments