com.badlogic.gdx.Net Java Examples
The following examples show how to use
com.badlogic.gdx.Net.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
protected Net.HttpRequest buildRequest(String component, Map<String, String> params) { String request = GJ_GATEWAY + component; request += HttpParametersUtils.convertHttpParameters(params); /* Generate signature */ final String signature; try { signature = md5(request + gjAppPrivateKey); } catch (Exception e) { /* Do not leak 'gamePrivateKey' in log */ Gdx.app.error(GAMESERVICE_ID, "Cannot honor request: " + request, e); return null; } /* Append signature */ String complete = request; complete += "&"; complete += "signature"; complete += "="; complete += signature; final Net.HttpRequest http = new Net.HttpRequest(); http.setMethod(Net.HttpMethods.GET); http.setUrl(complete); return http; }
Example #2
Source File: GpgsClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
protected void downloadFileFromDrive(String url, final ILoadGameStateResponseListener responseListener) { Net.HttpRequest httpRequest = new Net.HttpRequest(Net.HttpMethods.GET); httpRequest.setUrl(url); httpRequest.setHeader("Authorization", "Bearer " + oAuthToken); Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { byte[] result = httpResponse.getResultAsString().getBytes(); responseListener.gsGameStateLoaded(result); } @Override public void failed(Throwable t) { responseListener.gsGameStateLoaded(null); } @Override public void cancelled() { responseListener.gsGameStateLoaded(null); } }); }
Example #3
Source File: GpgsClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
/** * this can be used instead of loadFileFromDrive/downloadFileFromDrive... but it does not work on Firefox * Firefox does not follow a redirect that is given back to the real download url * @param driveFileId * @param responseListener */ protected void loadFileFromDriveV3(String driveFileId, final ILoadGameStateResponseListener responseListener) { Net.HttpRequest httpRequest = new Net.HttpRequest(Net.HttpMethods.GET); httpRequest.setUrl("https://content.googleapis.com/drive/v3/files/" + driveFileId + "?alt=media"); httpRequest.setHeader("Authorization", "Bearer " + oAuthToken); Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { byte[] result = httpResponse.getResultAsString().getBytes(); responseListener.gsGameStateLoaded(result); } @Override public void failed(Throwable t) { responseListener.gsGameStateLoaded(null); } @Override public void cancelled() { responseListener.gsGameStateLoaded(null); } }); }
Example #4
Source File: CardshifterNonGWTClient.java From Cardshifter with Apache License 2.0 | 6 votes |
public CardshifterNonGWTClient(CardshifterPlatform platform, String host, int port, CardshifterMessageHandler handler, LoginMessage loginMessage) { socket = Gdx.net.newClientSocket(Net.Protocol.TCP, host, port, new SocketHints()); output = socket.getOutputStream(); input = socket.getInputStream(); transformer = new ByteTransformer(new GdxLogger(), new GdxReflection()); this.handler = handler; try { output.write("{ \"command\": \"serial\", \"type\": \"1\" }".getBytes()); output.flush(); Gdx.app.log("Client", "Sent serial type"); platform.setupLogging(); send(loginMessage); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } new Thread(this).start(); }
Example #5
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
protected void sendOpenSessionEvent() { if (!isSessionActive()) return; Map<String, String> params = new HashMap<String, String>(); addGameIDUserNameUserToken(params); final Net.HttpRequest http = buildJsonRequest("sessions/open/", params); if (http != null) Gdx.net.sendHttpRequest(http, new NoOpResponseListener()); pingTask = Timer.schedule(new Timer.Task() { @Override public void run() { sendKeepSessionOpenEvent(); } }, GJ_PING_INTERVAL, GJ_PING_INTERVAL); }
Example #6
Source File: LobbyScreen.java From riiablo with Apache License 2.0 | 6 votes |
private void connect() { new Thread(new Runnable() { @Override public void run() { try { socket = Gdx.net.newClientSocket(Net.Protocol.TCP, Riiablo.client.getRealm(), 6113, new SocketHints()); in = IOUtils.buffer(new InputStreamReader(socket.getInputStream())); out = new PrintWriter(socket.getOutputStream(), true); } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage()); taChatOutput.appendText(t.getMessage()); taChatOutput.appendText("\n"); } } }).start(); }
Example #7
Source File: Commands.java From riiablo with Apache License 2.0 | 6 votes |
@Override public void onExecuted(Command.Instance instance) { int port = instance.numArgs() == 1 ? 6114 : NumberUtils.toInt(instance.getArg(1), 6114); Socket socket = null; try { socket = Gdx.net.newClientSocket(Net.Protocol.TCP, instance.getArg(0), port, null); final Socket socketRef = socket; Gdx.app.postRunnable(new Runnable() { @Override public void run() { Riiablo.client.clearAndSet(new SelectCharacterScreen3(socketRef)); } }); } catch (Throwable t) { Gdx.app.error("Command", t.getMessage(), t); if (socket != null) socket.dispose(); } }
Example #8
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
/** * Use careful! It resets your event to 0. Needed for first time initialization. * * @param eventId */ public void initializeOrResetEventKey(String eventId) { if (!initialized) { Gdx.app.error(GAMESERVICE_ID, "Cannot submit event: set app ID via initialize() first"); return; } if (eventKeyPrefix == null) { Gdx.app.log(GAMESERVICE_ID, "No event key prefix provided."); return; } // no user name or token added! We want to use the global storage. // http://gamejolt.com/api/doc/game/data-store/set Net.HttpRequest http = buildStoreDataRequest(eventKeyPrefix + eventId, true, "0"); if (http != null) Gdx.net.sendHttpRequest(http, new NoOpResponseListener()); }
Example #9
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
/** * content must be without special chars ampersand or question mark - use Base64 when not sure! */ protected Net.HttpRequest buildStoreDataRequest(String dataKey, boolean globalKey, String content) { Map<String, String> params = new HashMap<String, String>(); if (globalKey) params.put("game_id", gjAppId); else addGameIDUserNameUserToken(params); params.put("key", dataKey); final Net.HttpRequest http = buildJsonRequest("data-store/set/", params); if (http == null) return null; http.setMethod(Net.HttpMethods.POST); http.setHeader("Content-Type", "application/x-www-form-urlencoded"); http.setContent("data=" + content); return http; }
Example #10
Source File: MSI.java From riiablo with Apache License 2.0 | 6 votes |
@Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); final Calendar calendar = Calendar.getInstance(); DateFormat format = DateFormat.getDateTimeInstance(); Gdx.app.log(TAG, format.format(calendar.getTime())); try { InetAddress address = InetAddress.getLocalHost(); Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT); Gdx.app.log(TAG, "Host Name: " + address.getHostName()); } catch (UnknownHostException e) { Gdx.app.error(TAG, e.getMessage(), e); } Gdx.app.log(TAG, "Starting server..."); server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null); buffer = BufferUtils.newByteBuffer(4096); }
Example #11
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
@Override public boolean submitEvent(String eventId, int increment) { if (!initialized) { Gdx.app.error(GAMESERVICE_ID, "Cannot submit event: set app ID via initialize() first"); return false; } if (eventKeyPrefix == null) { Gdx.app.log(GAMESERVICE_ID, "No event logged - no event key prefix provided."); return false; } Map<String, String> params = new HashMap<String, String>(); // no user name or token added! We want to use the global storage. // http://gamejolt.com/api/doc/game/data-store/update params.put("game_id", gjAppId); params.put("key", eventKeyPrefix + eventId); params.put("value", Integer.toString(increment)); params.put("operation", "add"); final Net.HttpRequest http = buildJsonRequest("data-store/update/", params); if (http == null) return false; Gdx.net.sendHttpRequest(http, new NoOpResponseListener()); return true; }
Example #12
Source File: KongClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
/** * override this method for tunneling through own server or other needs */ protected Net.HttpRequest buildQueryStatRequest(Integer statId, boolean playerRelated) { String url = "https://api.kongregate.com/api/high_scores/" + (playerRelated && isSessionActive() ? "friends/" + statId.toString() + "/" + Integer.toString(getUserId()) : "https://api.kongregate.com/api/high_scores/lifetime/" + statId.toString()) + ".json"; Net.HttpRequest http = new Net.HttpRequest(); http.setMethod(Net.HttpMethods.GET); http.setUrl(url); return http; }
Example #13
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
/** * Load data is done with dump format */ protected Net.HttpRequest buildLoadDataRequest(String dataKey, boolean globalKey) { Map<String, String> params = new HashMap<String, String>(); if (globalKey) params.put("game_id", gjAppId); else addGameIDUserNameUserToken(params); params.put("key", dataKey); final Net.HttpRequest http = buildRequest("data-store/?format=dump&", params); return http; }
Example #14
Source File: MCP.java From riiablo with Apache License 2.0 | 5 votes |
private void StartInstance(CreateGame createGame, ResponseListener listener) { Gdx.app.debug(TAG, "Requesting game instance for " + createGame); FlatBufferBuilder builder = new FlatBufferBuilder(); StartInstance.startStartInstance(builder); int startInstanceOffset = StartInstance.endStartInstance(builder); int id = MSI.createMSI(builder, MSIData.StartInstance, startInstanceOffset); builder.finish(id); ByteBuffer data = builder.dataBuffer(); Socket socket = null; try { socket = Gdx.net.newClientSocket(Net.Protocol.TCP, "localhost", com.riiablo.server.mcp.MSI.PORT, null); OutputStream out = socket.getOutputStream(); WritableByteChannel channelOut = Channels.newChannel(out); channelOut.write(data); buffer.clear(); buffer.mark(); InputStream in = socket.getInputStream(); ReadableByteChannel channelIn = Channels.newChannel(in); channelIn.read(buffer); buffer.limit(buffer.position()); buffer.reset(); MSI packet = MSI.getRootAsMSI(buffer); Gdx.app.log(TAG, "packet type " + MCPData.name(packet.dataType())); listener.handleResponse(packet); } catch (Throwable t) { listener.failed(t); } finally { if (socket != null) socket.dispose(); } }
Example #15
Source File: Main.java From skin-composer with MIT License | 5 votes |
public static void checkForUpdates(Main main) { Thread thread = new Thread(new Runnable() { @Override public void run() { HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); HttpRequest httpRequest = requestBuilder.newRequest().method(HttpMethods.GET).url("https://raw.githubusercontent.com/raeleus/skin-composer/master/version").build(); Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { newVersion = httpResponse.getResultAsString(); Gdx.app.postRunnable(new Runnable() { @Override public void run() { main.rootTable.fire(new RootTable.RootTableEvent(RootTable.RootTableEnum.CHECK_FOR_UPDATES_COMPLETE)); } }); } @Override public void failed(Throwable t) { newVersion = VERSION; } @Override public void cancelled() { newVersion = VERSION; } }); } }); thread.start(); }
Example #16
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
@Override public boolean unlockAchievement(String achievementId) { if (trophyMapper == null) { Gdx.app.log(GAMESERVICE_ID, "Cannot unlock achievement: No mapper for trophy ids provided."); return false; } if (!isSessionActive()) return false; Integer trophyId = trophyMapper.mapToGsId(achievementId); // no board available or not connected if (trophyId == null) return false; Map<String, String> params = new HashMap<String, String>(); addGameIDUserNameUserToken(params); params.put("trophy_id", String.valueOf(trophyId)); final Net.HttpRequest http = buildJsonRequest("trophies/add-achieved/", params); if (http == null) return false; Gdx.net.sendHttpRequest(http, new NoOpResponseListener()); return true; }
Example #17
Source File: LocalMultiplayer.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public void init() { if (initialized) return; invitesWindow = new InvitesWindow(); playersWindow = new InvitesWindow(); initialized = true; try { socket = Gdx.net.newClientSocket(Net.Protocol.TCP, "localhost", 1337, new SocketHints()); } catch (Exception e) { return; } new Thread(new Runnable() { @Override public void run() { final BufferedReader r = new BufferedReader(new InputStreamReader(socket.getInputStream())); while (true) { try { final String msg = r.readLine(); Gdx.app.postRunnable(new Runnable() { @Override public void run() { ClientServerMessage message = ClientServerMessage.json.fromJson(ClientServerMessage.class, msg); receive(message); } }); } catch (IOException ignored) { System.out.println(ignored.getMessage()); } } } }).start(); sendToServer(ClientServerMessage.Type.loadPlayersToInvite); sendToServer(ClientServerMessage.Type.loadInvites); }
Example #18
Source File: GDXFacebookMultiPartRequest.java From gdx-facebook with Apache License 2.0 | 4 votes |
@Override public final String getMethod() { return Net.HttpMethods.POST; }
Example #19
Source File: Main.java From riiablo with Apache License 2.0 | 4 votes |
@Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); final Calendar calendar = Calendar.getInstance(); DateFormat format = DateFormat.getDateTimeInstance(); Gdx.app.log(TAG, format.format(calendar.getTime())); try { InetAddress address = InetAddress.getLocalHost(); Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT); Gdx.app.log(TAG, "Host Name: " + address.getHostName()); } catch (UnknownHostException e) { Gdx.app.error(TAG, e.getMessage(), e); } clientThreads = new ThreadGroup("D2CSClients"); Gdx.app.log(TAG, "Starting server..."); server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null); buffer = BufferUtils.newByteBuffer(4096); kill = new AtomicBoolean(false); main = new Thread(new Runnable() { @Override public void run() { while (!kill.get()) { Gdx.app.log(TAG, "waiting..."); Socket socket = server.accept(null); Gdx.app.log(TAG, "connection from " + socket.getRemoteAddress()); synchronized (clients) { if (clients.size >= MAX_CLIENTS) { try { ConnectionDenied(socket, "Server is Full"); } catch (Throwable ignored) { } finally { socket.dispose(); } } else { try { ConnectionAccepted(socket); int id = clients.size; Client client = new Client(id, socket); clients.add(client); client.start(); } catch (Throwable ignored) { socket.dispose(); } } } } Gdx.app.log(TAG, "killing child threads..."); synchronized (clients) { for (Client client : clients) { if (client != null) { client.kill.set(true); } } clients.clear(); } Gdx.app.log(TAG, "killing thread..."); } }); main.setName("D2CS"); main.start(); }
Example #20
Source File: HTMLGDXFacebook.java From gdx-facebook with Apache License 2.0 | 4 votes |
private void validatePermissions(final Array<String> permissions, final GDXFacebookCallback<SignInResult> callback) { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Checking for permissions"); GDXFacebookGraphRequest request = new GDXFacebookGraphRequest(); request.setMethod(Net.HttpMethods.GET); request.setNode("me/permissions"); request.useCurrentAccessToken(); graph(request, new GDXFacebookCallback<JsonResult>() { @Override public void onSuccess(JsonResult result) { JsonValue value = result.getJsonValue(); if (value != null && value.has("data")) { JsonValue dataValue = value.get("data"); if (dataValue != null && dataValue.isArray()) { grantedPermissions.clear(); for (int i = 0; i < dataValue.size; i++) { JsonValue permission = dataValue.get(i); if (permission.getString("status").equals("granted")) { grantedPermissions.add(permission.getString("permission").toLowerCase()); } } if (areSamePermissionsOrMore(permissions, grantedPermissions)) { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "AccessToken and permissions are valid."); callback.onSuccess(new SignInResult(accessToken, "AccessToken and permissions are valid.")); return; } } } guiLogin(permissions, callback); } @Override public void onError(GDXFacebookError error) { guiLogin(permissions, callback); } @Override public void onFail(Throwable t) { guiLogin(permissions, callback); } @Override public void onCancel() { guiLogin(permissions, callback); } }); }
Example #21
Source File: MCP.java From riiablo with Apache License 2.0 | 4 votes |
@Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); final Calendar calendar = Calendar.getInstance(); DateFormat format = DateFormat.getDateTimeInstance(); Gdx.app.log(TAG, format.format(calendar.getTime())); try { InetAddress address = InetAddress.getLocalHost(); Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT); Gdx.app.log(TAG, "Host Name: " + address.getHostName()); } catch (UnknownHostException e) { Gdx.app.error(TAG, e.getMessage(), e); } clientThreads = new ThreadGroup("MCPClients"); Gdx.app.log(TAG, "Starting server..."); server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null); buffer = BufferUtils.newByteBuffer(4096); kill = new AtomicBoolean(false); main = new Thread(new Runnable() { @Override public void run() { while (!kill.get()) { Gdx.app.log(TAG, "waiting..."); Socket socket = server.accept(null); Gdx.app.log(TAG, "connection from " + socket.getRemoteAddress()); if (CLIENTS.size() >= MAX_CLIENTS) { try { ConnectionDenied(socket, "Server is Full"); } catch (Throwable ignored) { } finally { socket.dispose(); } } else { try { ConnectionAccepted(socket); new Client(socket).start(); } catch (Throwable ignored) { socket.dispose(); } } } Gdx.app.log(TAG, "killing child threads..."); for (Client client : CLIENTS) { if (client != null) { client.kill.set(true); } } Gdx.app.log(TAG, "killing thread..."); } }); main.setName("MCP"); main.start(); cli = new Thread(new Runnable() { @Override public void run() { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (!kill.get()) { try { if (!reader.ready()) continue; String in = reader.readLine(); if (in.equalsIgnoreCase("exit")) { Gdx.app.exit(); } else if (in.equalsIgnoreCase("games")) { Gdx.app.log(TAG, "games:"); for (GameSession session : sessions.values()) { Gdx.app.log(TAG, " " + session); } } } catch (Throwable t) { Gdx.app.log(TAG, t.getMessage()); } } } }); cli.setName("CLI"); cli.start(); }
Example #22
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 4 votes |
protected /* @Nullable */ Net.HttpRequest buildJsonRequest(String component, Map<String, String> params) { component = component + "?format=json&"; return buildRequest(component, params); }
Example #23
Source File: BNLS.java From riiablo with Apache License 2.0 | 4 votes |
@Override public void create() { Gdx.app.setLogLevel(Application.LOG_DEBUG); final Calendar calendar = Calendar.getInstance(); DateFormat format = DateFormat.getDateTimeInstance(); Gdx.app.log(TAG, format.format(calendar.getTime())); try { InetAddress address = InetAddress.getLocalHost(); Gdx.app.log(TAG, "IP Address: " + address.getHostAddress() + ":" + PORT); Gdx.app.log(TAG, "Host Name: " + address.getHostName()); } catch (UnknownHostException e) { Gdx.app.error(TAG, e.getMessage(), e); } clientThreads = new ThreadGroup("BNLSClients"); Gdx.app.log(TAG, "Starting server..."); server = Gdx.net.newServerSocket(Net.Protocol.TCP, PORT, null); buffer = BufferUtils.newByteBuffer(4096); kill = new AtomicBoolean(false); main = new Thread(new Runnable() { @Override public void run() { while (!kill.get()) { Gdx.app.log(TAG, "waiting..."); Socket socket = server.accept(null); Gdx.app.log(TAG, "connection from " + socket.getRemoteAddress()); if (CLIENTS.size() >= MAX_CLIENTS) { try { ConnectionDenied(socket, "Server is Full"); } catch (Throwable ignored) { } finally { socket.dispose(); } } else { try { ConnectionAccepted(socket); new Client(socket).start(); } catch (Throwable ignored) { socket.dispose(); } } } Gdx.app.log(TAG, "killing child threads..."); for (Client client : CLIENTS) { if (client != null) { client.kill.set(true); } } Gdx.app.log(TAG, "killing thread..."); } }); main.setName("BNLS"); main.start(); cli = new Thread(new Runnable() { @Override public void run() { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (!kill.get()) { try { if (!reader.ready()) continue; String in = reader.readLine(); if (in.equalsIgnoreCase("exit")) { Gdx.app.exit(); } else if (in.equalsIgnoreCase("realms")) { Gdx.app.log(TAG, "realms:"); for (String[] realms : REALMS) { Gdx.app.log(TAG, " " + realms[0] + " " + realms[1]); } } } catch (Throwable t) { Gdx.app.log(TAG, t.getMessage()); } } } }); cli.setName("CLI"); cli.start(); }
Example #24
Source File: DesktopMini2DxGame.java From mini2Dx with Apache License 2.0 | 4 votes |
@Override public Net getNet() { return net; }
Example #25
Source File: GDXFacebookUnitTests.java From gdx-facebook with Apache License 2.0 | 4 votes |
@Before public void setup() { fixture = new GDXFacebookStub(new GDXFacebookConfig()); Gdx.net = mock(Net.class); }
Example #26
Source File: GdxDemoActivity.java From thunderboard-android with Apache License 2.0 | 4 votes |
public Net getNet() { return this.net; }
Example #27
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 4 votes |
@Override public void handleHttpResponse(Net.HttpResponse httpResponse) { Gdx.app.debug(GAMESERVICE_ID, httpResponse.getResultAsString()); }
Example #28
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 4 votes |
@Override public void loadGameState(String fileId, final ILoadGameStateResponseListener listener) { if (!isSessionActive()) { listener.gsGameStateLoaded(null); return; } Net.HttpRequest http = buildLoadDataRequest(fileId, false); Gdx.net.sendHttpRequest(http, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { String response = httpResponse.getResultAsString(); if (response == null || !response.startsWith("SUCCESS")) { // just log, no error because loading a nonexistant gamestate fails but is no error Gdx.app.log(GAMESERVICE_ID, "Gamestate load failed: " + response); listener.gsGameStateLoaded(null); } else { // indexOf is twice to cut first two lines. First one is success message, // second one is progressValue byte[] gs = Base64Coder.decode(response.substring( response.indexOf('\n', response.indexOf('\n') + 1) + 1)); listener.gsGameStateLoaded(gs); } } @Override public void failed(Throwable t) { Gdx.app.error(GAMESERVICE_ID, "Gamestate load failed", t); listener.gsGameStateLoaded(null); } @Override public void cancelled() { Gdx.app.error(GAMESERVICE_ID, "Gamestate load cancelled"); listener.gsGameStateLoaded(null); } }); }
Example #29
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 4 votes |
@Override public boolean deleteGameState(String fileId, final ISaveGameStateResponseListener successListener) { if (!isSessionActive()) return false; Map<String, String> params = new HashMap<String, String>(); addGameIDUserNameUserToken(params); params.put("key", fileId); final Net.HttpRequest http = buildJsonRequest("data-store/remove/", params); if (http == null) return false; Gdx.net.sendHttpRequest(http, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { String json = httpResponse.getResultAsString(); boolean success = parseSuccessFromResponse(json); // just log, no error because deleting a nonexistant gamestate fails but is no error if (!success) Gdx.app.log(GAMESERVICE_ID, "Failed to delete gamestate: " + json); if (successListener != null) successListener.onGameStateSaved(success, null); } @Override public void failed(Throwable t) { Gdx.app.error(GAMESERVICE_ID, "Error deleting gamestate", t); if (successListener != null) successListener.onGameStateSaved(false, null); } @Override public void cancelled() { Gdx.app.error(GAMESERVICE_ID, "Error deleting gamestate: Cancelled"); if (successListener != null) successListener.onGameStateSaved(false, null); } }); return true; }
Example #30
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 4 votes |
@Override public void saveGameState(String fileId, byte[] gameState, long progressValue, final ISaveGameStateResponseListener listener) { if (!isSessionActive()) { if (listener != null) listener.onGameStateSaved(false, "NOT_CONNECTED"); return; } //TODO progressValue is saved for future use, but should be checked before overwriting existing values Net.HttpRequest http = buildStoreDataRequest(fileId, false, Long.toString(progressValue) + "\n" + new String(Base64Coder.encode(gameState))); Gdx.net.sendHttpRequest(http, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { String json = httpResponse.getResultAsString(); boolean success = parseSuccessFromResponse(json); if (!success) Gdx.app.error(GAMESERVICE_ID, "Error saving gamestate: " + json); if (listener != null) listener.onGameStateSaved(success, null); } @Override public void failed(Throwable t) { Gdx.app.error(GAMESERVICE_ID, "Error saving gamestate", t); if (listener != null) listener.onGameStateSaved(false, null); } @Override public void cancelled() { Gdx.app.error(GAMESERVICE_ID, "Error saving gamestate: Cancelled"); if (listener != null) listener.onGameStateSaved(false, null); } }); }