public void updateNetwork() { isOnline = false; Gdx.net.sendHttpRequest(new HttpRequestBuilder().newRequest().method(Net.HttpMethods.GET).url("http://checkip.amazonaws.com").build(), new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { try { ip = new BufferedReader(new InputStreamReader(httpResponse.getResultAsStream())).readLine(); isOnline = true; //client.connect(5000, "99.36.127.68", Networking.PORT); //client.reconnect(); } catch (IOException e) { Gdx.app.error("HTTP", e.toString()); } } @Override public void failed(Throwable t) { Gdx.app.log("Update Network", t.toString()); } @Override public void cancelled() { } }); }
public static void getTicket(final WebSocketLocal webSocket){ final JSONObject[] finalResult = new JSONObject[1]; String accesToken = Gdx.app.getPreferences("informationLog").getString("accesstoken"); HttpRequestBuilder buider = new HttpRequestBuilder(); Net.HttpRequest request = buider.newRequest().url(api_url + d_login).method(Net.HttpMethods.POST).build(); request.setHeader("Authorization", "Bearer " + accesToken); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { String r = httpResponse.getResultAsString(); webSocket.connectWebSocket(new JSONObject(r)); Gdx.app.log("response", "ticket "+r); } @Override public void failed(Throwable t) { webSocket.connectWebSocket(new JSONObject()); } @Override public void cancelled() { webSocket.connectWebSocket(new JSONObject()); } }); }
public void makeRequestEnklave(){ Preferences pref = Gdx.app.getPreferences("informationLog"); String acces = pref.getString("accesstoken"); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.GET).url(url + enkNearby).build(); request.setHeader("Authorization", "Bearer " + acces); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { String response = httpResponse.getResultAsString(); JSONArray jsonArray = new JSONArray(response); ListEnklaves.getInstance().setListEnklave(jsonArray); Gdx.app.log("response enklave : " + httpResponse.getStatus().getStatusCode(), " message " +response); } @Override public void failed(Throwable t) { Gdx.app.log("response : " + t.getMessage(), "fdg " + t.getLocalizedMessage()); } @Override public void cancelled() { Gdx.app.log("response ","cancelled"); } }); }
public void sendMessage(String message){ final Preferences pref = Gdx.app.getPreferences("informationLog"); String acces = pref.getString("accesstoken"); JSONObject json = new JSONObject(); json.accumulate("txt",message); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + join).build(); request.setHeader("Authorization", "Bearer " + acces); request.setHeader("Content-type", "application/json"); request.setContent(json.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { //Gdx.app.log("response :"+httpResponse.getStatus().getStatusCode(),"message "+httpResponse.getResultAsString()); } @Override public void failed(Throwable t) { //Gdx.app.log("response :","failed "+t); } @Override public void cancelled() { //Gdx.app.log("response :","cancel "); } }); }
public void sendMessage(String message){ final Preferences pref = Gdx.app.getPreferences("informationLog"); String acces = pref.getString("accesstoken"); JSONObject json = new JSONObject(); json.accumulate("txt",message); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + join).build(); request.setHeader("Authorization", "Bearer " + acces); request.setHeader("Content-type", "application/json"); request.setContent(json.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { // Gdx.app.log("response :"+httpResponse.getStatus().getStatusCode(),"message "+httpResponse.getResultAsString()); } @Override public void failed(Throwable t) { //Gdx.app.log("response :","failed "+t); } @Override public void cancelled() { //Gdx.app.log("response :","cancel "); } }); }
public void makeRequest(int id){ final Preferences pref = Gdx.app.getPreferences("informationLog"); String acces = pref.getString("accesstoken"); JSONObject json = new JSONObject(); json.accumulate("faction_id",id); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + join).build(); request.setHeader("Authorization", "Bearer " + acces); request.setHeader("Content-type", "application/json"); request.setContent(json.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { //Gdx.app.log("response :","message "+httpResponse.getResultAsString()); } @Override public void failed(Throwable t) { //Gdx.app.log("response :","failed "); } @Override public void cancelled() { //Gdx.app.log("response :","cancel "); } }); }
public void makeRequest(int id, final ScreenCombat screenCombat){ final Preferences pref = Gdx.app.getPreferences("informationLog"); final String acces = pref.getString("accesstoken"); JSONObject parameters = new JSONObject(); parameters.accumulate("enklave_combat_id",id); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); request.setHeader("Content-type", "application/json"); request.setContent(parameters.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { screenCombat.showCover(); Gdx.app.log("raspuns hit Enklave cod :"+httpResponse.getStatus().getStatusCode()," message : "+httpResponse.getResultAsString()); } @Override public void failed(Throwable t) { } @Override public void cancelled() { } }); }
public void makeRequest(int id, final ScreenCombat screenCombat){ final Preferences pref = Gdx.app.getPreferences("informationLog"); final String acces = pref.getString("accesstoken"); JSONObject jsonObject = new JSONObject(); jsonObject.accumulate("enklave_id", id); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); request.setHeader("Content-type", "application/json"); request.setContent(jsonObject.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { String res = httpResponse.getResultAsString(); Gdx.app.log("raspuns start code "+httpResponse.getStatus().getStatusCode(),"rasp mess: "+res); if(httpResponse.getStatus().getStatusCode()<300){ JSONObject j = new JSONObject(res); informationProfile.getDateUserGame().setEnklaveCombatId(j.getInt("enklave_combatant_id")); InformationEnklave.getInstance().setCombatId(j.getInt("enklave_combat_id")); informationProfile.getDateUserGame().setInCombat(true); }else{ JSONObject json = new JSONObject(res); if(json.getString("detail").contentEquals("You already joined this combat once")) InformationProfile.getInstance().getDateUserGame().setEnklaveCombatId(-1); informationProfile.getDateUserGame().setInCombat(true); screenCombat.dialogExit(json.getString("detail").substring(0,20)+"\n"+json.getString("detail").substring(21)); } } @Override public void failed(Throwable t) { Gdx.app.log("error parse data : ","err: "+t); } @Override public void cancelled() { } }); }
public void makeRequest(int id){ final Preferences pref = Gdx.app.getPreferences("informationLog"); final String acces = pref.getString("accesstoken"); JSONObject parameters = new JSONObject(); parameters.accumulate("enklave_id",id); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); request.setHeader("Content-type", "application/json"); request.setContent(parameters.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { Gdx.app.log("raspuns unsubscribe cod :"," message : "+httpResponse.getResultAsString()); } @Override public void failed(Throwable t) { } @Override public void cancelled() { } }); }
public void makeRequest(int id, final ScreenCombat screenCombat){ final Preferences pref = Gdx.app.getPreferences("informationLog"); final String acces = pref.getString("accesstoken"); JSONObject parameters = new JSONObject(); parameters.accumulate("enklave_combatant_id",id); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); request.setHeader("Content-type", "application/json"); request.setContent(parameters.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { screenCombat.showCover(); Gdx.app.log("raspuns hit user cod :"+httpResponse.getStatus().getStatusCode()," message : "+httpResponse.getResultAsString()); } @Override public void failed(Throwable t) { } @Override public void cancelled() { } }); }
public void makeRequest(final int id){ final Preferences pref = Gdx.app.getPreferences("informationLog"); final String acces = pref.getString("accesstoken"); JSONObject parameters = new JSONObject(); parameters.accumulate("enklave_id",id); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); request.setHeader("Content-type", "application/json"); request.setContent(parameters.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { // Gdx.app.log("response "+httpResponse.getStatus().getStatusCode()," subscribe "+httpResponse.getResultAsString()); if(httpResponse.getStatus().getStatusCode()<300){ new CheckStatus().makeRequest(id); }else{ } } @Override public void failed(Throwable t) { } @Override public void cancelled() { } }); }
public void addScore(AddScoreListener listener, int score, String name) { HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("name", name); parameters.put("score", "" + score); Net.HttpRequest httpRequest = requestBuilder.newRequest() .method(Net.HttpMethods.POST) .formEncodedContent(parameters) .url("https://www.fluffybalance.nl/api/1.0/score") .build(); Gdx.net.sendHttpRequest(httpRequest, new AddScoreResponseListener(listener)); }
public void GET(String query) { if (work) return; work = true; HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); HttpRequest request = requestBuilder.newRequest().url(urlString).timeout(timeout).content(query).method(HttpMethods.GET).build(); final WWW my = this; Gdx.net.sendHttpRequest(request, new HttpResponseListener() { public void handleHttpResponse(HttpResponse httpResponse) { responseBytes = httpResponse.getResult(); // Gdx.app.log("WWW", "Response: " + responseBytes.length); // Gdx.app.log("WWW", "Status: " + httpResponse.getStatus().getStatusCode()); work = false; if (wwwResponseListener != null) { Gdx.app.postRunnable(new Runnable() { public void run() { wwwResponseListener.httpResponseListener(my); } }); } } public void failed(Throwable t) { Gdx.app.error(WWW.class.getSimpleName(), "failed: " + t); work = false; } public void cancelled() { Gdx.app.error(WWW.class.getSimpleName(), "cancelled"); work = false; } }); }
private void sendRequest(final TwitterRequest twitterRequest, final TwitterResponseListener listener) { HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); HttpRequest httpRequest = requestBuilder.newRequest().method(twitterRequest.getRequestType().name()).url(twitterRequest.getUrl()).build(); // System.out.println(twitterRequest.build().getHeader()); twitterRequest.build(); httpRequest.setHeader("Authorization", twitterRequest.getHeader()); httpRequest.setContent(twitterRequest.getData()); httpRequest.setTimeOut(config.TWITTER_REQUEST_TIMEOUT); Gdx.net.sendHttpRequest(httpRequest, new HttpResponseListener() { @Override public void handleHttpResponse(HttpResponse httpResponse) { if (httpResponse.getStatus().getStatusCode() == 200) { listener.success(httpResponse.getResultAsString()); } else { listener.apiError(httpResponse.getStatus(), httpResponse.getResultAsString()); } } @Override public void failed(Throwable t) { listener.httpError(t); } @Override public void cancelled() { listener.cancelled(); } }); }
public void makeRequest(final int idEnklave, final ManagerAssets manager){ Preferences pref = Gdx.app.getPreferences("informationLog"); String acces = pref.getString("accesstoken"); HashMap parameters = new HashMap<String,String>(); parameters.put("enklave_id",String.valueOf(idEnklave)); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.GET).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); request.setContent(HttpParametersUtils.convertHttpParameters(parameters)); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { if(httpResponse.getStatus().getStatusCode()<300) { String s = httpResponse.getResultAsString(); JSONObject json = new JSONObject(s); enklave.setBricks(json.getInt("nr_bricks")); if (json.getString("faction").contentEquals("null")) { enklave.setFaction(0); } else { enklave.setFaction(json.getInt("faction")); } enklave.setId(json.getInt("id")); enklave.setRooms(json.getInt("rooms")); enklave.setName(json.getString("name")); if(!json.isNull("created_by")) enklave.setUsercreate(json.getJSONObject("created_by").getString("username")); enklave.setLatitude((float) json.getDouble("latitude")); enklave.setLongitude((float) json.getDouble("longitude")); enklave.setExtensions(json.getInt("extensions")); enklave.setTurrets(json.getInt("cells")); if(json.getString("status").contentEquals("InCombat")) { enklave.setStatusCombat(true); enklave.setShields(json.getInt("shield")); enklave.setEnergyBrick(json.getInt("brick_last")); }else{ enklave.setShields(json.getInt("shield_full")); enklave.setEnergyBrick(json.getInt("brick_last")); } enklave.setEnergyBrickfull(json.getInt("brick_full")); enklave.setEnergyfullshield(json.getInt("shield_full")); manager.getAssertEnklaveScreen().setIsupdate(true); Gdx.app.log("information enklave ", "succes " + json); }else{ Gdx.app.log("eroare"+httpResponse.getStatus().getStatusCode(),"meassajul :"+httpResponse.getResultAsString()); new GetEnklaveDetails().makeRequest(ListEnklaves.getInstance().get(idEnklave).id, manager); } } @Override public void failed(Throwable t) { Gdx.app.log("information error failed"," "+ t); new GetEnklaveDetails().makeRequest(ListEnklaves.getInstance().get(idEnklave).id, manager); } @Override public void cancelled() { Gdx.app.log("information error cancelled","cancel"); } }); }
public void makeRequestProfile(){ final Preferences pref = Gdx.app.getPreferences("informationLog"); final String acces = pref.getString("accesstoken"); // Gdx.app.log("response "," access token "+acces); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.GET).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { if(httpResponse.getStatus().getStatusCode()<300) { JSONObject json = new JSONObject(httpResponse.getResultAsString()); profile.getDateUser().setId(json.getInt("id")); profile.getDateUser().setUserName(json.getString("username")); profile.getDateUser().setFristName(json.getString("first_name")); profile.getDateUser().setLastName(json.getString("last_name")); profile.getDateUser().setEmail(json.getString("email")); profile.getDateUser().setPhoneNumber(json.getString("phone_number")); if (json.getString("faction") == "null") { profile.getDateUserGame().setFaction(0); } else { profile.getDateUserGame().setFaction(json.getInt("faction")); } profile.getDateUserGame().setScrap(json.getInt("scrap")); profile.getDateUserGame().setLevel(json.getInt("level")); profile.getDateUserGame().setEnergyProgress(json.getJSONObject("energy_config").getInt("PLAYER_RECHARGE_PROGRESSION")); profile.getDateUserGame().setEnergyLevel(json.getJSONObject("energy_config").getInt("PLAYER_ENERGY_PROGRESSION")); profile.getDateUserGame().setEnergy(json.getInt("energy")); profile.getDateUserGame().setExperienceLevel(json.getJSONObject("xp_for_level").getInt("PLAYER_XP_PROGRESSION")); profile.getDateUserGame().setExperience(json.getInt("experience")); profile.getDateUserGame().setDistanceWalked(json.getInt("distance_walked")); // profile.getDateUserGame().setElectronics(json.getInt("electronics")); profile.getDateBrick().setNumber(json.getInt("nr_bricks")); profile.getDateBrick().setRateEnergy(json.getJSONObject("brick_config").getInt("CRAFT_BRICK_ENERGY_COST")); profile.getDateBrick().setRateScrap(json.getJSONObject("brick_config").getInt("CRAFT_BRICK_SCRAP_COST")); profile.getDateBrick().setRateTime(json.getJSONObject("brick_config").getInt("CRAFT_BRICK_TIME_COST")); profile.getDateBrick().setUsageEnergy(json.getJSONObject("place_brick_config").getInt("PLACE_BRICK_ENERGY_COST")); profile.getDateBrick().setUsageTime(json.getJSONObject("place_brick_config").getInt("PLACE_BRICK_TIME_COST")); profile.getDateCell().setCellNumber(json.getInt("nr_cells")); profile.getDateCell().setCellValue(json.getJSONObject("cell_configs").getInt("ENERGY_CELL_RECHARGE_VALUE")); profile.getDateCell().setCellRateTime(json.getJSONObject("cell_configs").getInt("CRAFTING_TIME_CELL")); profile.getDateCell().setCellRateScrap(json.getJSONObject("cell_configs").getInt("CONVERSION_RATE_CELL")); profile.getDateCell().setCellRateEnergy(profile.getDateCell().getCellValue() * (json.getJSONObject("cell_configs").getInt("CELL_ENERGY_PERCENTAGE_COST") / 100) + profile.getDateCell().getCellValue()); profile.getDateCell().setCellUsageEnergy(json.getJSONObject("cell_configs").getInt("PLAYER_CELL_RELOAD_TIME")); profile.getDateCell().setCellUsageTime(json.getJSONObject("cell_configs").getInt("PLAYER_ENERGY_CELL_USAGE_COST")); Gdx.app.log("response profil " + "status : " + httpResponse.getStatus().getStatusCode(), acces + " message " + json.toString()); new Thread(new Runnable() { @Override public void run() { Gdx.app.postRunnable(new Runnable() { @Override public void run() { new CombatUserCheck().makeRequest(); } }); } }).start(); }else{ if(httpResponse.getStatus().getStatusCode() == 401){ } } } @Override public void failed(Throwable t) { Gdx.app.log("response : " + t.getMessage(), "fdg " + t.getLocalizedMessage()); new GetProfile().makeRequestProfile(); } @Override public void cancelled() { } }); }
public void makeRequestProfile() { final Preferences pref = Gdx.app.getPreferences("informationLog"); final String acces = pref.getString("accesstoken"); Gdx.app.log("response ", " access token " + acces); JSONObject jsonObject = new JSONObject(); jsonObject.accumulate("client_id", "EeTst6oR0udDrcKUScROksiDKiBPdUvp8leTWVVO"); jsonObject.accumulate("client_secret", "goGcpJ1QPiAoTTOQRIGya6cCau0TTNpcrpzKudHynfPvcmYHKuWh0IpH8vEB2ZHYVAt6qOKdNXQZkMP1yKUYYDXX5sEu8ACr9mthmgR9ytaDqoXindSbX568r45saSiN"); jsonObject.accumulate("grant_type", "refresh_token"); jsonObject.accumulate("username", pref.getString("username")); jsonObject.accumulate("refresh_token", pref.getString("refreshToken")); final String json = jsonObject.toString(); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build(); request.setHeader("Content-type", "application/json"); request.setContent(json.toString()); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { if(httpResponse.getStatus().getStatusCode()<300) { JSONObject jsonObj = new JSONObject(httpResponse.getResultAsString()); pref.putString("accesstoken",jsonObj.getString("access_token")); pref.putString("refreshToken",jsonObj.getString("refresh_token")); pref.putLong("timeout", (System.currentTimeMillis() +((jsonObj.getLong("expires_in") - 1000) * 1000))); pref.flush(); new GetProfile().makeRequestProfile(); }else{ System.exit(0); } } @Override public void failed(Throwable t) { Gdx.app.log("response failed","error : "+t.getMessage()+" localizedMessage: "+t.getLocalizedMessage()); } @Override public void cancelled() { Gdx.app.log("response cancelled","eror"); } }); }
public void makeRequest(final GameManager game, final QueueBuildCraft queue){ Preferences pref = Gdx.app.getPreferences("informationLog"); String acces = pref.getString("accesstoken"); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); updateprofile(-1); queue.getElement(); final long startTime = System.currentTimeMillis(); try { Thread.sleep((System.currentTimeMillis() > queue.dateStartLastAction) ? 0 : (queue.dateStartLastAction - System.currentTimeMillis())); } catch (InterruptedException e) { e.printStackTrace(); Gdx.app.log("intra brick ","error"); } queue.dateStartLastAction = System.currentTimeMillis() + (informationProfile.getDateBrick().getRateTime()*1000); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { JSONObject json = new JSONObject(httpResponse.getResultAsString()); if(httpResponse.getStatus().getStatusCode()<300){ if(json.has("duration")) { new Timer().schedule(new Timer.Task() { @Override public void run() { informationProfile.getDateBrick().setNumber(informationProfile.getDateBrick().getNumber() + 1); queueDisplay.labelfinishaction.setText("Brick"); queueDisplay.labelcurrentaction.setText(""); queueDisplay.labelnextaction.setText(""); game.screenCrafting.updateDisplay(); Gdx.app.log("number bricks", "ga " + informationProfile.getDateBrick().getNumber()); if(!queue.forcestopcrafting) queue.startThread(); } },informationProfile.getDateBrick().getRateTime()); }else { Gdx.app.log("response error create bricks "+httpResponse.getStatus().getStatusCode()," "+json); // game.screenCrafting.createDialog("Error create brick "+json); updateprofile(1); queue.clearQueue(); queueDisplay.labelfinishaction.setText(""); queueDisplay.labelcurrentaction.setText("brick error"); queueDisplay.labelnextaction.setText(""); } }else{ // game.screenCrafting.createDialog("Error create brick " +json); Gdx.app.log("response error create bricks "+httpResponse.getStatus().getStatusCode()," "+json); updateprofile(1); queue.clearQueue(); queueDisplay.labelfinishaction.setText(""); queueDisplay.labelcurrentaction.setText("brick error "); queueDisplay.labelnextaction.setText(""); } } @Override public void failed(Throwable t) { Gdx.app.log("response create bricks","failed "); } @Override public void cancelled() { Gdx.app.log("response create bricks"," canceled"); } }); new Timer().scheduleTask(new Timer.Task() { @Override public void run() { // if(!queue.forcestopcrafting) // queue.startThread(); } },informationProfile.getDateBrick().getRateTime() + 0.5f); }
public void makeRequest(final GameManager game, final QueueBuildCraft queue){ Preferences pref = Gdx.app.getPreferences("informationLog"); String acces = pref.getString("accesstoken"); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); updateprofile(-1); queue.getElement(); final long startTime = System.currentTimeMillis(); try { Thread.sleep((System.currentTimeMillis() > queue.dateStartLastAction) ? 0 : (queue.dateStartLastAction - System.currentTimeMillis())); } catch (InterruptedException e) { e.printStackTrace(); } queue.dateStartLastAction = System.currentTimeMillis() + (informationProfile.getDateCell().getCellRateTime() * 1000); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { JSONObject json = new JSONObject(httpResponse.getResultAsString()); if (httpResponse.getStatus().getStatusCode() < 300) { if (json.has("duration")) { new Timer().schedule(new Timer.Task() { @Override public void run() { informationProfile.getDateCell().setCellNumber(informationProfile.getDateCell().getCellNumber() + 1); queueDisplay.labelfinishaction.setText("Cell"); queueDisplay.labelcurrentaction.setText(""); queueDisplay.labelnextaction.setText(""); game.screenCrafting.updateDisplay(); Gdx.app.log("number cell", "ga " + informationProfile.getDateBrick().getNumber()); if(!queue.forcestopcrafting) queue.startThread(); } }, informationProfile.getDateCell().getCellRateTime()); } else { Gdx.app.log("response error create cell " + httpResponse.getStatus().getStatusCode(), " " + json); // game.screenCrafting.createDialog(json.getString("detail")); updateprofile(1); queue.clearQueue(); queueDisplay.labelfinishaction.setText(""); queueDisplay.labelcurrentaction.setText("cell error"); queueDisplay.labelnextaction.setText(""); } } else { Gdx.app.log("response error create cell " + httpResponse.getStatus().getStatusCode(), " " + json); // game.screenCrafting.createDialog("Error create Cell!"); updateprofile(1); queue.clearQueue(); queueDisplay.labelfinishaction.setText(""); queueDisplay.labelcurrentaction.setText("cell error"); queueDisplay.labelnextaction.setText(""); } } @Override public void failed(Throwable t) { } @Override public void cancelled() { } }); new Timer().scheduleTask(new Timer.Task() { @Override public void run() { // if(!queue.forcestopcrafting) // queue.startThread(); } },informationProfile.getDateCell().getCellRateTime() + 0.5f); }
public void makeRequest(){ final Preferences pref = Gdx.app.getPreferences("informationLog"); final String acces = pref.getString("accesstoken"); HttpRequestBuilder builder = new HttpRequestBuilder(); final Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.GET).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { if(httpResponse.getStatus().getStatusCode()<300){ new Thread(new Runnable() { @Override public void run() { Gdx.app.postRunnable(new Runnable() { @Override public void run() { new NearbyEnklave().makeRequestEnklave(); } }); } }).start(); String res = httpResponse.getResultAsString(); if(!res.contentEquals("\"user is not in combat\"")){ InformationProfile.getInstance().getDateUserGame().setInCombat(true); JSONObject json = new JSONObject(res); InformationEnklave.getInstance().setId(json.getInt("enklave_id")); InformationEnklave.getInstance().setCombatId(json.getInt("combatant_id")); } Gdx.app.log("response check combat user ","correct is: "+res); } } @Override public void failed(Throwable t) { } @Override public void cancelled() { } }); }
public void fetchLeaderBoard(FetchLeaderBoardListener listener) { HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); Net.HttpRequest httpRequest = requestBuilder.newRequest().method(Net.HttpMethods.GET).url( "https://www.fluffybalance.nl/api/1.0/leaderboard").build(); Gdx.net.sendHttpRequest(httpRequest, new GetLeaderBoardResponseListener(listener)); }
public void POST(Object form) { if (work) return; work = true; HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); HttpRequest request = requestBuilder.newRequest().url(urlString).timeout(timeout).jsonContent(form).method(HttpMethods.POST) .build(); final WWW my = this; Gdx.net.sendHttpRequest(request, new HttpResponseListener() { public void handleHttpResponse(final HttpResponse httpResponse) { responseBytes = httpResponse.getResult(); // Gdx.app.log(WWW.class.getSimpleName(), "response bytes: " + responseBytes.length + " response string: " // + httpResponse.getResultAsString() + " Code: " + httpResponse.getStatus().getStatusCode()); statusCode = httpResponse.getStatus().getStatusCode(); work = false; if (wwwResponseListener != null) { Gdx.app.postRunnable(new Runnable() { public void run() { wwwResponseListener.httpResponseListener(my); } }); } } public void failed(Throwable t) { Gdx.app.error(WWW.class.getSimpleName(), "failed: " + t); work = false; } public void cancelled() { Gdx.app.error(WWW.class.getSimpleName(), "cancelled"); work = false; } }); }
synchronized public void requestRefreshRepository() { if (checkingInProgress) return; Gdx.app.log(TAG, "Requesting new data from remote server."); checkingInProgress = true; eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.REFRESH_STARTED)); Gdx.net.sendHttpRequest(new HttpRequestBuilder().newRequest() .method(Net.HttpMethods.GET) .url(getRelativeUrl("modules.json")) .timeout(10000) .header(HttpRequestHeader.CacheControl, "no-cache") .build(), new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { try { String result = httpResponse.getResultAsString(); // Cache result into local file FileUtils.saveTextToFile(repoCacheFile, result); // Update in-memory data Array<RepositoryModuleData> newArray = json.fromJson(Array.class, RepositoryModuleData.class, result); repositoryModules.clear(); for (RepositoryModuleData moduleData : newArray) { repositoryModules.put(moduleData.name, moduleData); } prefsCommon.putLong(PREF_KEY_LAST_CHECK, new Date().getTime()).flush(); Gdx.app.log(TAG, "Data was loaded from remote server."); checkingInProgress = false; eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.REFRESH_FINISHED)); eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.FINISHED_SUCCESS)); } catch (Exception e) { checkingInProgress = false; eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.REFRESH_FINISHED)); eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.FINISHED_ERROR)); } } @Override public void failed(Throwable t) { checkingInProgress = false; eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.REFRESH_FINISHED)); eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.FINISHED_ERROR)); } @Override public void cancelled() { checkingInProgress = false; eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.REFRESH_FINISHED)); eventDispatcher.postEvent(new ModuleRepositoryRefreshEvent(ModuleRepositoryRefreshEvent.Action.FINISHED_ERROR)); } }); }
private ScoreRestClient() { requestBuilder = new HttpRequestBuilder(); }