11
11
import net .olympiccode .vhackos .bot .core .config .AdvancedConfigValues ;
12
12
import net .olympiccode .vhackos .bot .core .config .ConfigFile ;
13
13
import net .olympiccode .vhackos .bot .core .config .ConfigValues ;
14
+ import net .olympiccode .vhackos .bot .core .misc .MaintenanceService ;
14
15
import net .olympiccode .vhackos .bot .core .misc .MiscConfigValues ;
15
16
import net .olympiccode .vhackos .bot .core .misc .MiscService ;
16
17
import net .olympiccode .vhackos .bot .core .networking .NetworkingConfigValues ;
19
20
import net .olympiccode .vhackos .bot .core .updating .UpdateService ;
20
21
import okhttp3 .Request ;
21
22
import okhttp3 .Response ;
23
+ import org .json .JSONException ;
22
24
import org .json .JSONObject ;
23
25
import org .slf4j .Logger ;
24
26
import org .slf4j .LoggerFactory ;
@@ -37,10 +39,10 @@ public class vHackOSBot {
37
39
static Logger LOG = LoggerFactory .getLogger ("vHackOSBot" );
38
40
ConfigFile config = new ConfigFile ();
39
41
AdvancedConfigFile advConfig = new AdvancedConfigFile ();
40
- BotService updateService = new UpdateService ();
41
- MiscService miscService = new MiscService ();
42
- BotService networkingService = new NetworkingService ();
43
-
42
+ public static BotService updateService = new UpdateService ();
43
+ public static MiscService miscService = new MiscService ();
44
+ public static BotService networkingService = new NetworkingService ();
45
+ public static BotService maintenanceService = new MaintenanceService ();
44
46
public static void main (String [] args ) {
45
47
try {
46
48
new vHackOSBot ().run ();
@@ -49,7 +51,7 @@ public static void main(String[] args) {
49
51
} catch (InterruptedException e ) {
50
52
LOG .error ("There was a problem initializing the vHackOSBot." );
51
53
} catch (RuntimeException e ) {
52
- if (e .getMessage ().contains ("vhack account has been banned" )) {
54
+ if (e .getMessage () != null && e . getMessage () .contains ("vhack account has been banned" )) {
53
55
LOG .error ("Your vhack account has been banned." );
54
56
System .exit (0 );
55
57
} else {
@@ -101,6 +103,7 @@ public void run() throws LoginException, InterruptedException {
101
103
} else {
102
104
api = new vHackOSAPIBuilder ().setUsername (ConfigValues .username ).setPassword (ConfigValues .password ).buildBlocking ();
103
105
}
106
+ checkForUpdates ();
104
107
advConfig .getConfigJson ().addProperty ("login.accesstoken" , ((vHackOSAPIImpl ) api ).getAccessToken ());
105
108
advConfig .getConfigJson ().addProperty ("login.uid" , ((vHackOSAPIImpl ) api ).getUid ());
106
109
advConfig .save ();
@@ -115,7 +118,8 @@ public void run() throws LoginException, InterruptedException {
115
118
if (UpdateConfigValues .enabled ) updateService .setup ();
116
119
if (MiscConfigValues .enabled ) miscService .setup ();
117
120
if (NetworkingConfigValues .enabled ) networkingService .setup ();
118
-
121
+ maintenanceService .setup ();
122
+ networkingService .getService ().shutdownNow ();
119
123
} catch (Exception e ) {
120
124
Sentry .capture (e );
121
125
e .printStackTrace ();
@@ -149,7 +153,8 @@ public void run() throws LoginException, InterruptedException {
149
153
case "services" :
150
154
System .out .println ("NetworkingService: " + getStatus (networkingService .getService ()) + "\n " +
151
155
"UpdateService: " + getStatus (updateService .getService ()) + "\n " +
152
- "MiscService: " + getStatus (miscService .getService ()));
156
+ "MiscService: " + getStatus (miscService .getService ()) + "\n " +
157
+ "MainService: " + getStatus (maintenanceService .getService ()));
153
158
break ;
154
159
case "apps" :
155
160
System .out .println ("-------------------\n " + api .getAppManager ().getApps ().stream ().map (app -> app .getType ().getName () + ": " + (app .isInstalled () ? app .getLevel () : "Not installed" )).collect (Collectors .joining ("\n " )) + "\n -------------------" );
@@ -205,18 +210,24 @@ private String getProgressBar() {
205
210
builder .append ("] " + api .getStats ().getLevelPorcentage () + "%" );
206
211
return builder .toString ();
207
212
}
208
-
213
+ double curVersion = 1.8 ;
209
214
public void checkForUpdates () {
210
- //
211
- //
212
- Request request = (new Request .Builder ()).url ("https://api.github.com/repos/OlympicCode/vHackOSBot-Java/releases/latest" ).addHeader ("user-agent" , "Dalvik/1.6.0 (Linux; U; Android 4.4.4; SM-N935F Build/KTU84P)" ).addHeader ("Accept-Encoding" , "gzip" ).build ();
215
+ Request request = (new Request .Builder ()).url ("https://api.github.com/repos/OlympicCode/vHackOSBot-Java/releases/latest" ).addHeader ("user-agent" , "Dalvik/1.6.0 (Linux; U; Android 4.4.4; SM-N935F Build/KTU84P)" ).build ();
213
216
try {
214
217
Response r = ((vHackOSAPIImpl ) api ).getRequester ().getHttpClient ().newCall (request ).execute ();
215
218
if (r .isSuccessful ()) {
216
- JSONObject json = new JSONObject (r .body ());
219
+ String s = r .body ().string ();
220
+ JSONObject json = new JSONObject (s );
221
+ double version = json .getDouble ("tag_name" );
222
+ if (version != curVersion ) {
223
+ LOG .info ("ATTENTION: An update is avaliable for vHackOSBot: " + version + " (Running " + curVersion + ")" );
224
+ }
225
+
217
226
}
218
227
} catch (IOException e ) {
219
228
e .printStackTrace ();
229
+ } catch (JSONException e ) {
230
+ e .printStackTrace ();
220
231
}
221
232
}
222
233
}
0 commit comments