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

Commit 687400f

Browse files
committed
Servers, sleep time and more
- Added server automation - Added costumization for the sleep time - Added configuration for minimum boosters - Fixed miner wasting time - Fixed failed withdraws
1 parent ba6eef5 commit 687400f

File tree

9 files changed

+165
-45
lines changed

9 files changed

+165
-45
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:c761a2bb4'
23+
compile 'net.olympiccode:vHackOSAPI-Java:1e05dd5a3c'
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/config/AdvancedConfigValues.java

+6
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ public class AdvancedConfigValues {
1212

1313
@AdvancedConfigOption(path = "login.uid", defaultValue = "---", options = {""})
1414
public static String uid;
15+
16+
@AdvancedConfigOption(path = "request.waitTimeMin", defaultValue = "1000", options = {""})
17+
public static int waitMin;
18+
19+
@AdvancedConfigOption(path = "request.waitTimeMax", defaultValue = "1500", options = {""})
20+
public static int waitMax;
1521
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
99

10+
import java.util.Random;
1011
import java.util.concurrent.Executors;
1112
import java.util.concurrent.ScheduledExecutorService;
1213
import java.util.concurrent.ThreadFactory;
@@ -32,7 +33,7 @@ public void setup() {
3233
if (miscService.isTerminated() || miscService.isShutdown()) {
3334
miscService = Executors.newScheduledThreadPool(1, new MiscServiceFactory());
3435
}
35-
miscService.scheduleAtFixedRate(() -> runLongService(), 0, 60000 * 60, TimeUnit.MILLISECONDS);
36+
miscService.scheduleAtFixedRate(() -> runLongService(), 0, 60000 * 60 + 5000 * 60, TimeUnit.MILLISECONDS);
3637
miscService.scheduleAtFixedRate(() -> runService(), 0, 60000 * 5, TimeUnit.MILLISECONDS);
3738
}
3839
public static int[] history = {0, 0, 0, 0, 0, 0};

src/main/java/net/olympiccode/vhackos/bot/core/networking/NetworkingService.java

+35-33
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,47 @@ public void setup() {
4949

5050
public void runService() {
5151
try {
52-
((ArrayList<BruteForce>) ((ArrayList) vHackOSBot.api.getTaskManager().getActiveBrutes()).clone()).forEach(bruteForce -> {
53-
if (cache.asMap().containsKey(bruteForce.getIp())) return;
54-
if (bruteForce.getState() == BruteForceState.SUCCESS) {
55-
cache.put(bruteForce.getIp(), "");
56-
ExploitedTarget etarget = bruteForce.exploit();
57-
ExploitedTarget.Banking banking = etarget.getBanking();
52+
if (!(vHackOSBot.api.getStats().getMoney() == 999999999L)) {
53+
((ArrayList<BruteForce>) ((ArrayList) vHackOSBot.api.getTaskManager().getActiveBrutes()).clone()).forEach(bruteForce -> {
54+
if (cache.asMap().containsKey(bruteForce.getIp())) return;
55+
if (bruteForce.getState() == BruteForceState.SUCCESS) {
56+
cache.put(bruteForce.getIp(), "");
57+
ExploitedTarget etarget = bruteForce.exploit();
58+
ExploitedTarget.Banking banking = etarget.getBanking();
5859

59-
if (banking.isBruteForced()) {
60-
if (banking.canAttack()) {
61-
long av = banking.getAvaliableMoney();
62-
if (av > 0 && banking.withdraw(NetworkingConfigValues.withdrawPorcentage)) {
63-
LOG.info("Withdrawed " + av + " of " + banking.getTotal() + " from " + etarget.getIp() + ".");
64-
} else {
65-
LOG.error("Failed to withdraw from " + etarget.getIp() + ".");
60+
if (banking.isBruteForced()) {
61+
if (banking.canAttack()) {
62+
long av = banking.getAvaliableMoney();
63+
if (av > 10000 && banking.withdraw(NetworkingConfigValues.withdrawPorcentage)) {
64+
LOG.info("Withdrawed " + av + " of " + banking.getTotal() + " from " + etarget.getIp() + ".");
65+
} else {
66+
LOG.error("Failed to withdraw from " + etarget.getIp() + ".");
67+
}
68+
if (eval(etarget)) {
69+
LOG.info("Removing bruteforce from " + etarget.getIp() + ".");
70+
bruteForce.remove();
71+
}
6672
}
67-
if (eval(etarget)) {
68-
LOG.info("Removing bruteforce from " + etarget.getIp() + ".");
69-
bruteForce.remove();
73+
} else {
74+
if (banking.startBruteForce()) {
75+
LOG.info("Started bruteforce at " + etarget.getIp());
76+
} else {
77+
LOG.error("Failed to start bruteforce at " + etarget.getIp());
7078
}
7179
}
72-
} else {
73-
if (banking.startBruteForce()) {
74-
LOG.info("Started bruteforce at " + etarget.getIp());
75-
} else {
76-
LOG.error("Failed to start bruteforce at " + etarget.getIp());
80+
etarget.setSystemLog(NetworkingConfigValues.logMessage.replaceAll("%username%", vHackOSBot.api.getStats().getUsername()));
81+
} else if (bruteForce.getState() == BruteForceState.FAILED) {
82+
switch (NetworkingConfigValues.onFail) {
83+
case "retry":
84+
LOG.info("Retrying bruteforce at " + bruteForce.getIp() + " has it failed.");
85+
bruteForce.retry();
86+
case "remove":
87+
LOG.info("Removing bruteforce from " + bruteForce.getIp() + " has it failed.");
88+
bruteForce.remove();
7789
}
7890
}
79-
etarget.setSystemLog(NetworkingConfigValues.logMessage.replaceAll("%username%", vHackOSBot.api.getStats().getUsername()));
80-
} else if (bruteForce.getState() == BruteForceState.FAILED) {
81-
switch (NetworkingConfigValues.onFail) {
82-
case "retry":
83-
LOG.info("Retrying bruteforce at " + bruteForce.getIp() + " has it failed.");
84-
bruteForce.retry();
85-
case "remove":
86-
LOG.info("Removing bruteforce from " + bruteForce.getIp() + " has it failed.");
87-
bruteForce.remove();
88-
}
89-
}
90-
});
91+
});
92+
}
9193
if (vHackOSBot.api.getStats().getExploits() > 0) {
9294
int success = 0;
9395
int tries = 6 * 3;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package net.olympiccode.vhackos.bot.core.server;
2+
3+
import net.olympiccode.vhackos.bot.core.config.ConfigOption;
4+
5+
public class ServerConfigValues {
6+
7+
@ConfigOption(path = "networking.enabled", defaultValue = "true", options = {"true", "false"})
8+
public static boolean enabled;
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package net.olympiccode.vhackos.bot.core.server;
2+
3+
import io.sentry.Sentry;
4+
import net.olympiccode.vhackos.api.server.Server;
5+
import net.olympiccode.vhackos.bot.core.BotService;
6+
import net.olympiccode.vhackos.bot.core.vHackOSBot;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
import java.util.Arrays;
11+
import java.util.concurrent.Executors;
12+
import java.util.concurrent.ScheduledExecutorService;
13+
import java.util.concurrent.ThreadFactory;
14+
import java.util.concurrent.TimeUnit;
15+
16+
public class ServerService implements BotService {
17+
18+
public static ScheduledExecutorService serverService;
19+
Logger LOG = LoggerFactory.getLogger("ServerService");
20+
21+
public ServerService() {
22+
LOG.info("Creating ServerService...");
23+
serverService = Executors.newScheduledThreadPool(1, new ServerServiceFactory());
24+
}
25+
26+
27+
@Override
28+
public ScheduledExecutorService getService() {
29+
return serverService;
30+
}
31+
32+
@Override
33+
public void setup() {
34+
LOG.info("Setting up ServerSerice...");
35+
if (serverService.isTerminated() || serverService.isShutdown()) {
36+
serverService = Executors.newScheduledThreadPool(1, new ServerServiceFactory());
37+
}
38+
serverService.scheduleAtFixedRate(() -> runService(), 0, 330000, TimeUnit.MILLISECONDS);
39+
}
40+
41+
@Override
42+
public void runService() {
43+
try {
44+
Server server = vHackOSBot.api.getServer();
45+
server.update();
46+
if (server.getPackages() > 0) {
47+
Server.OpenResult result = server.openAllPacks();
48+
LOG.info("Opened " + server.getPackages() + " server packages, got " + result.getServer() + " server, " + result.getAv() + " av, " + result.getFw() + " fw and " + result.getBoost() + " boosters.");
49+
}
50+
server.update();
51+
while (server.getServerPieces() > 9 && (server.getServerStrength() < server.getServerStrengthMax())) {
52+
LOG.info("Upgrading server's server...");
53+
if (server.upgrade(Server.NODE_TYPE.SERVER, 1)) LOG.info("Upgraded server's server.");
54+
else LOG.info("Failed to upgrade server's server...");
55+
}
56+
server.update();
57+
int fwNodes = (int) Arrays.stream(server.getFirewallStrength()).filter(value -> value != 0).count();
58+
for (int i = 0; i < fwNodes; i++) {
59+
LOG.info("Upgrading server's firewall node " + (i + 1) + "...");
60+
while (server.getFirewallPieces() > 9 && (server.getFirewallStrength()[i] < server.getFirewallStrengthMax()[i])) {
61+
if (server.upgrade(Server.NODE_TYPE.FW, i + 1))
62+
LOG.info("Upgraded server's firewall node " + (i + 1) + ".");
63+
else LOG.info("Failed to upgrade server's firewall node " + (i + 1) + ".");
64+
}
65+
}
66+
67+
server.update();
68+
int avNodes = (int) Arrays.stream(server.getAntivirusStrength()).filter(value -> value != 0).count();
69+
for (int i = 0; i < avNodes; i++) {
70+
LOG.info("Upgrading server's antivirus node " + (i + 1) + "...");
71+
while (server.getAntivirusPieces() > 9 && (server.getAntivirusStrength()[i] < server.getAntivirusStrengthMax()[i])) {
72+
if (server.upgrade(Server.NODE_TYPE.AV, i + 1))
73+
LOG.info("Upgraded server's antivirus node " + (i + 1) + ".");
74+
else LOG.info("Failed to upgrade server's antivirus node " + (i + 1) + ".");
75+
}
76+
}
77+
78+
} catch (Exception e) {
79+
Sentry.capture(e);
80+
LOG.warn("The server service has been shutdown due to an error.");
81+
e.printStackTrace();
82+
serverService.shutdownNow();
83+
}
84+
}
85+
86+
public class ServerServiceFactory implements ThreadFactory {
87+
public Thread newThread(Runnable r) {
88+
return new Thread(r, "vHackOSBot-ServerService");
89+
}
90+
}
91+
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class UpdateConfigValues {
1919
@ConfigOption(path = "update.minNetcoins", defaultValue = "1000", options = {""})
2020
public static int minNetcoins;
2121

22+
@ConfigOption(path = "update.minBoosters", defaultValue = "0", options = {""})
23+
public static int minBoosters;
24+
2225
@ConfigOption(path = "update.prioritymode", defaultValue = "lowerfirst", options={"lowerfirst", "higherfirst", "random"})
2326
public static String priorityMode;
2427

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void runService() {
136136
}
137137

138138
void proccessBoosts() {
139-
if (UpdateConfigValues.useBoosters && vHackOSBot.api.getTaskManager().getBoosters() > 0) {
139+
if (UpdateConfigValues.useBoosters && vHackOSBot.api.getTaskManager().getBoosters() > UpdateConfigValues.minBoosters) {
140140
if (vHackOSBot.api.getTaskManager().boostAll()) {
141141
LOG.info("Boosted the update.");
142142
} else {

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
import net.olympiccode.vhackos.api.vHackOSAPI;
88
import net.olympiccode.vhackos.api.vHackOSAPIBuilder;
99
import net.olympiccode.vhackos.api.vHackOSInfo;
10-
import net.olympiccode.vhackos.bot.core.config.AdvancedConfigFile;
11-
import net.olympiccode.vhackos.bot.core.config.AdvancedConfigValues;
12-
import net.olympiccode.vhackos.bot.core.config.ConfigFile;
13-
import net.olympiccode.vhackos.bot.core.config.ConfigValues;
10+
import net.olympiccode.vhackos.bot.core.config.*;
1411
import net.olympiccode.vhackos.bot.core.misc.MaintenanceService;
1512
import net.olympiccode.vhackos.bot.core.misc.MiscConfigValues;
1613
import net.olympiccode.vhackos.bot.core.misc.MiscService;
1714
import net.olympiccode.vhackos.bot.core.networking.NetworkingConfigValues;
1815
import net.olympiccode.vhackos.bot.core.networking.NetworkingService;
16+
import net.olympiccode.vhackos.bot.core.server.ServerConfigValues;
17+
import net.olympiccode.vhackos.bot.core.server.ServerService;
1918
import net.olympiccode.vhackos.bot.core.updating.UpdateConfigValues;
2019
import net.olympiccode.vhackos.bot.core.updating.UpdateService;
2120
import okhttp3.Request;
@@ -40,10 +39,11 @@ public class vHackOSBot {
4039
public static MiscService miscService = new MiscService();
4140
public static BotService networkingService = new NetworkingService();
4241
public static BotService maintenanceService = new MaintenanceService();
42+
public static BotService serverService = new ServerService();
4343
static Logger LOG = LoggerFactory.getLogger("vHackOSBot");
4444
ConfigFile config = new ConfigFile();
4545
AdvancedConfigFile advConfig = new AdvancedConfigFile();
46-
double curVersion = 1.12;
46+
double curVersion = 1.13;
4747
private long startTime = 0;
4848

4949
public static void main(String[] args) {
@@ -69,7 +69,7 @@ public static void main(String[] args) {
6969

7070
public void run() throws LoginException, InterruptedException {
7171
Sentry.init("https://36b5e13fe253466f8b98b5adacb2aa32:[email protected]/303008");
72-
Sentry.getContext().addExtra("version", vHackOSInfo.API_PREFIX);
72+
Sentry.getContext().addExtra("version", vHackOSInfo.API_PREFIX + "(" + curVersion + ")");
7373
Sentry.getContext().recordBreadcrumb(
7474
new BreadcrumbBuilder().setMessage("Starting...").build()
7575
);
@@ -102,9 +102,9 @@ public void run() throws LoginException, InterruptedException {
102102
System.exit(0);
103103
}
104104
if (!AdvancedConfigValues.token.equals("---") && !AdvancedConfigValues.token.equals("---")) {
105-
api = new vHackOSAPIBuilder().setUsername(ConfigValues.username).setPassword(ConfigValues.password).setPreLogin(AdvancedConfigValues.token, AdvancedConfigValues.uid).buildBlocking();
105+
api = new vHackOSAPIBuilder().setSleepTime(AdvancedConfigValues.waitMin, AdvancedConfigValues.waitMax).setUsername(ConfigValues.username).setPassword(ConfigValues.password).setPreLogin(AdvancedConfigValues.token, AdvancedConfigValues.uid).buildBlocking();
106106
} else {
107-
api = new vHackOSAPIBuilder().setUsername(ConfigValues.username).setPassword(ConfigValues.password).buildBlocking();
107+
api = new vHackOSAPIBuilder().setSleepTime(AdvancedConfigValues.waitMin, AdvancedConfigValues.waitMax).setUsername(ConfigValues.username).setPassword(ConfigValues.password).buildBlocking();
108108
}
109109
checkForUpdates();
110110
advConfig.getConfigJson().addProperty("login.accesstoken", ((vHackOSAPIImpl) api).getAccessToken());
@@ -121,6 +121,7 @@ public void run() throws LoginException, InterruptedException {
121121
if (UpdateConfigValues.enabled) updateService.setup();
122122
if (MiscConfigValues.enabled) miscService.setup();
123123
if (NetworkingConfigValues.enabled) networkingService.setup();
124+
if (ServerConfigValues.enabled) serverService.setup();
124125
maintenanceService.setup();
125126
} catch (Exception e) {
126127
Sentry.capture(e);
@@ -171,8 +172,14 @@ public void run() throws LoginException, InterruptedException {
171172
case "quit":
172173
System.exit(0);
173174
break;
175+
case "server":
176+
api.getServer().update();
177+
System.out.print("Server: " + api.getServer().getServerStrength() + "/" + api.getServer().getServerStrengthMax() + "\n" +
178+
"Firewall: " + api.getServer().getFirewallStrength()[0] + "/" + api.getServer().getFirewallStrengthMax()[0] + " | " + api.getServer().getFirewallStrength()[1] + "/" + api.getServer().getFirewallStrengthMax()[1] + " | " + api.getServer().getFirewallStrength()[2] + "/" + api.getServer().getFirewallStrengthMax()[2] + "\n" +
179+
"Antivirus: " + api.getServer().getAntivirusStrength()[0] + "/" + api.getServer().getAntivirusStrengthMax()[0] + " | " + api.getServer().getAntivirusStrength()[1] + "/" + api.getServer().getAntivirusStrengthMax()[1] + " | " + api.getServer().getAntivirusStrength()[2] + "/" + api.getServer().getAntivirusStrengthMax()[2] + "\nPackages: " + api.getServer().getPackages());
180+
break;
174181
default:
175-
System.out.println("Unkown command, use \"help\" to list all commands.");
182+
System.out.println("Unknown command, use \"help\" to list all commands.");
176183
}
177184
} catch (IOException e) {
178185
e.printStackTrace();

0 commit comments

Comments
 (0)