1111import net .olympiccode .vhackos .bot .core .config .AdvancedConfigValues ;
1212import net .olympiccode .vhackos .bot .core .config .ConfigFile ;
1313import net .olympiccode .vhackos .bot .core .config .ConfigValues ;
14+ import net .olympiccode .vhackos .bot .core .misc .MaintenanceService ;
1415import net .olympiccode .vhackos .bot .core .misc .MiscConfigValues ;
1516import net .olympiccode .vhackos .bot .core .misc .MiscService ;
1617import net .olympiccode .vhackos .bot .core .networking .NetworkingConfigValues ;
1920import net .olympiccode .vhackos .bot .core .updating .UpdateService ;
2021import okhttp3 .Request ;
2122import okhttp3 .Response ;
23+ import org .json .JSONException ;
2224import org .json .JSONObject ;
2325import org .slf4j .Logger ;
2426import org .slf4j .LoggerFactory ;
@@ -37,10 +39,10 @@ public class vHackOSBot {
3739 static Logger LOG = LoggerFactory .getLogger ("vHackOSBot" );
3840 ConfigFile config = new ConfigFile ();
3941 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 ();
4446 public static void main (String [] args ) {
4547 try {
4648 new vHackOSBot ().run ();
@@ -49,7 +51,7 @@ public static void main(String[] args) {
4951 } catch (InterruptedException e ) {
5052 LOG .error ("There was a problem initializing the vHackOSBot." );
5153 } 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" )) {
5355 LOG .error ("Your vhack account has been banned." );
5456 System .exit (0 );
5557 } else {
@@ -101,6 +103,7 @@ public void run() throws LoginException, InterruptedException {
101103 } else {
102104 api = new vHackOSAPIBuilder ().setUsername (ConfigValues .username ).setPassword (ConfigValues .password ).buildBlocking ();
103105 }
106+ checkForUpdates ();
104107 advConfig .getConfigJson ().addProperty ("login.accesstoken" , ((vHackOSAPIImpl ) api ).getAccessToken ());
105108 advConfig .getConfigJson ().addProperty ("login.uid" , ((vHackOSAPIImpl ) api ).getUid ());
106109 advConfig .save ();
@@ -115,7 +118,8 @@ public void run() throws LoginException, InterruptedException {
115118 if (UpdateConfigValues .enabled ) updateService .setup ();
116119 if (MiscConfigValues .enabled ) miscService .setup ();
117120 if (NetworkingConfigValues .enabled ) networkingService .setup ();
118-
121+ maintenanceService .setup ();
122+ networkingService .getService ().shutdownNow ();
119123 } catch (Exception e ) {
120124 Sentry .capture (e );
121125 e .printStackTrace ();
@@ -149,7 +153,8 @@ public void run() throws LoginException, InterruptedException {
149153 case "services" :
150154 System .out .println ("NetworkingService: " + getStatus (networkingService .getService ()) + "\n " +
151155 "UpdateService: " + getStatus (updateService .getService ()) + "\n " +
152- "MiscService: " + getStatus (miscService .getService ()));
156+ "MiscService: " + getStatus (miscService .getService ()) + "\n " +
157+ "MainService: " + getStatus (maintenanceService .getService ()));
153158 break ;
154159 case "apps" :
155160 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() {
205210 builder .append ("] " + api .getStats ().getLevelPorcentage () + "%" );
206211 return builder .toString ();
207212 }
208-
213+ double curVersion = 1.8 ;
209214 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 ();
213216 try {
214217 Response r = ((vHackOSAPIImpl ) api ).getRequester ().getHttpClient ().newCall (request ).execute ();
215218 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+
217226 }
218227 } catch (IOException e ) {
219228 e .printStackTrace ();
229+ } catch (JSONException e ) {
230+ e .printStackTrace ();
220231 }
221232 }
222233}
0 commit comments