Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.

Commit 9b4466e

Browse files
committed
Update enchancement and more stats
Updates are now faster as it doesn't wait until all are finished Added last 5, 10, 15 and 30 minutes tournament position to stats
1 parent 64ca40c commit 9b4466e

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies {
2020
compile 'com.google.code.gson:gson:2.8.2'
2121
compile 'ch.qos.logback:logback-classic:1.2.3'
2222
compile 'com.google.guava:guava:24.0-jre'
23-
compile 'net.olympiccode:vHackOSAPI-Java:master-SNAPSHOT'
23+
compile 'net.olympiccode:vHackOSAPI-Java:437c7fc33f'
2424
compile 'io.sentry:sentry:1.7.1'
2525
}
2626
mainClassName = "net.olympiccode.vhackos.bot.core.vHackOSBot"

src/main/java/net/olympiccode/vhackos/bot/core/misc/MiscService.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.sentry.Sentry;
44
import net.olympiccode.vhackos.api.entities.AppType;
5-
import net.olympiccode.vhackos.api.network.ExploitedTarget;
65
import net.olympiccode.vhackos.bot.core.BotService;
76
import net.olympiccode.vhackos.bot.core.vHackOSBot;
87
import org.slf4j.Logger;
@@ -14,6 +13,7 @@
1413
import java.util.concurrent.TimeUnit;
1514

1615
public class MiscService implements BotService {
16+
1717
ScheduledExecutorService miscService;
1818
Logger LOG = LoggerFactory.getLogger("MiscService");
1919

@@ -29,10 +29,11 @@ public ScheduledExecutorService getService() {
2929

3030
public void setup() {
3131
LOG.info("Setting up MiscSerice...");
32-
miscService.scheduleAtFixedRate(() -> runService(), 0, 60000 * 60, TimeUnit.MILLISECONDS);
32+
miscService.scheduleAtFixedRate(() -> runLongService(), 0, 60000 * 60, TimeUnit.MILLISECONDS);
33+
miscService.scheduleAtFixedRate(() -> runService(), 0, 60000 * 5, TimeUnit.MILLISECONDS);
3334
}
34-
35-
public void runService() {
35+
public static int[] history = {0, 0, 0, 0, 0, 0};
36+
public void runLongService() {
3637
try {
3738
if (MiscConfigValues.enableMiner) {
3839
if (vHackOSBot.api.getAppManager().getApp(AppType.NCMiner).isInstalled()) {
@@ -53,6 +54,22 @@ public void runService() {
5354
}
5455
}
5556

57+
public void runService() {
58+
try {
59+
history[5] = history[4];
60+
history[4] = history[3];
61+
history[3] = history[2];
62+
history[2] = history[1];
63+
history[1] = history[0];
64+
history[0] = vHackOSBot.api.getLeaderboards().getTournamentRank();
65+
} catch (Exception e) {
66+
Sentry.capture(e);
67+
e.printStackTrace();
68+
miscService.shutdownNow();
69+
LOG.warn("The misc service has been shutdown due to an error.");
70+
}
71+
}
72+
5673
public class MiscServiceFactory implements ThreadFactory {
5774
public Thread newThread(Runnable r) {
5875
return new Thread(r, "vHackOSBot-MiscService");

src/main/java/net/olympiccode/vhackos/bot/core/updating/UpdateService.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,25 @@ public void runService() {
105105
List<Task> activetasks = vHackOSBot.api.getTaskManager().getActiveTasks();
106106
if (activetasks.size() < 1) {
107107
App app = getNextApp();
108-
LOG.info("Starting update of " + app.getType() + " for " + app.getPrice() + ".");
108+
if (app.getPrice() > vHackOSBot.api.getStats().getMoney()) LOG.warn("Could not start update: Out of money");
109+
LOG.info("Starting 10 updates of " + app.getType() + " for " + app.getPrice() + ".");
109110
if (app.getAsUpdateable().fillTasks()) {
110111
proccessBoosts();
111112
} else {
112113
LOG.warn("Failed to start update of " + app.getType() + " could be out of money or there are already tasks running.");
113114
}
114-
} else {
115+
} else if (activetasks.size() >= 10) {
115116
LOG.info("There are already updates running, trying to boost them..");
116117
proccessBoosts();
118+
} else {
119+
int missing = 10 - activetasks.size();
120+
App app = getNextApp();
121+
if (app.getPrice() > vHackOSBot.api.getStats().getMoney()) LOG.warn("Could not start update: Out of money");
122+
LOG.info("Starting " + missing + " updates of " + app.getType() + " for " + app.getPrice() + ".");
123+
if (!app.getAsUpdateable().fillTasks()) {
124+
LOG.warn("Failed to start update of " + app.getType() + " could be out of money or there are already tasks running.");
125+
}
126+
proccessBoosts();
117127
}
118128
} catch (Exception e) {
119129
Sentry.capture(e);

src/main/java/net/olympiccode/vhackos/bot/core/vHackOSBot.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class vHackOSBot {
3838
ConfigFile config = new ConfigFile();
3939
AdvancedConfigFile advConfig = new AdvancedConfigFile();
4040
BotService updateService = new UpdateService();
41-
BotService miscService = new MiscService();
41+
MiscService miscService = new MiscService();
4242
BotService networkingService = new NetworkingService();
4343

4444
public static void main(String[] args) {
@@ -141,7 +141,7 @@ public void run() throws LoginException, InterruptedException {
141141
"Level: " + api.getStats().getLevel() + getProgressBar());
142142
break;
143143
case "tasks":
144-
System.out.println("-------------------\n" + "Boosters: " + api.getTaskManager().getBoosters() + "\n-------------------\n" + api.getTaskManager().getActiveTasks().stream().map(task -> task.getType() + ": " + task.getLevel() + " " + ((task.getEndTimestamp() - System.currentTimeMillis()) / 1000) + "sec left.").collect(Collectors.joining("\n")) + "\n-------------------");
144+
System.out.println("-------------------\n" + "Boosters: " + api.getTaskManager().getBoosters() + "\n-------------------\n" + api.getTaskManager().getActiveTasks().stream().map(task -> task.getType() + ": " + task.getLevel() + " " + getTimeLeft((task.getEndTimestamp() - System.currentTimeMillis()) ) + " left.").collect(Collectors.joining("\n")) + "\n-------------------");
145145
break;
146146
case "brutes":
147147
System.out.println("-------------------\n" + api.getTaskManager().getActiveBrutes().stream().map(bruteForce -> bruteForce.getUsername() + ": " + bruteForce.getState()).collect(Collectors.joining("\n")) + "\n-------------------");
@@ -157,7 +157,9 @@ public void run() throws LoginException, InterruptedException {
157157
case "leader":
158158
case "leaders":
159159
case "leaderboards":
160-
System.out.println("-------------------\n" + "Current tournament pos: " + api.getLeaderboards().getTournamentRank() + "\nTournament ends in: " + getTimeLeft() + "\nCurrent global pos: " + api.getLeaderboards().getRank() + "\n-------------------");
160+
System.out.println("-------------------\n" + "Current tournament pos: " + api.getLeaderboards().getTournamentRank() +
161+
"\nTournament history (5, 10, 15, 30 min): " + miscService.history[0] + ", " + miscService.history[1] + ", " + miscService.history[2] + ", " + miscService.history[5] +
162+
"\nTournament ends in: " + getTimeLeft(api.getLeaderboards().getTournamentEndTimestamp() - System.currentTimeMillis()) + "\nCurrent global pos: " + api.getLeaderboards().getRank() + "\n-------------------");
161163
break;
162164
case "quit":
163165
System.exit(0);
@@ -176,9 +178,7 @@ private String getStatus(ScheduledExecutorService service) {
176178
return "Running.";
177179
}
178180

179-
private String getTimeLeft() {
180-
long time = api.getLeaderboards().getTournamentEndTimestamp();
181-
long millis = time - System.currentTimeMillis();
181+
private String getTimeLeft(long millis) {
182182
return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
183183
TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
184184
TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));

0 commit comments

Comments
 (0)