Added HTTP methods to Net

This commit is contained in:
Anuken
2018-02-03 00:57:42 -05:00
parent b83e552b5a
commit 608343b9d1
3 changed files with 29 additions and 0 deletions

View File

@@ -37,6 +37,8 @@ public class Vars{
public static final float enemyspawnspace = 65;
//discord group URL
public static final String discordURL = "https://discord.gg/r8BkXNd";
public static final String serverURL = "http://localhost:3000";
//directory for user-created map data
public static final FileHandle customMapDirectory = gwt ? null : UCore.isAssets ?
Gdx.files.local("../../desktop/mindustry-maps") : Gdx.files.local("mindustry-maps/");

View File

@@ -289,6 +289,7 @@ public class NetServer extends Module{
Net.send(packet, SendMode.udp);
}
if(Timers.get("serverBlockSync", blockSyncTime)){
Array<NetConnection> connections = Net.getConnections();

View File

@@ -1,5 +1,10 @@
package io.anuke.mindustry.net;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net.HttpRequest;
import com.badlogic.gdx.Net.HttpResponse;
import com.badlogic.gdx.Net.HttpResponseListener;
import com.badlogic.gdx.net.HttpRequestBuilder;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
@@ -242,6 +247,27 @@ public class Net{
active = false;
}
public static void http(String method, String content, Consumer<String> listener){
HttpRequest req = new HttpRequestBuilder().newRequest()
.method(method).content(content).url(serverURL + "/servers").build();
Gdx.net.sendHttpRequest(req, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
listener.accept(httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
Log.err("HTTP error:");
Log.err(t);
}
@Override
public void cancelled() {}
});
}
/**Client implementation.*/
public interface ClientProvider {
/**Connect to a server.*/