init player
This commit is contained in:
parent
0c86573013
commit
d94b679e2e
2 changed files with 113 additions and 1 deletions
39
src/main/java/com/epita/creeps/Basics.java
Normal file
39
src/main/java/com/epita/creeps/Basics.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package com.epita.creeps;
|
||||
|
||||
import kong.unirest.core.HttpResponse;
|
||||
import kong.unirest.core.JsonNode;
|
||||
import kong.unirest.core.Unirest;
|
||||
import kong.unirest.core.UnirestException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class Basics {
|
||||
|
||||
private Logger logger;
|
||||
private String srvUrl;
|
||||
|
||||
public void connectAccount(String login) {
|
||||
HttpResponse<JsonNode> response;
|
||||
try {
|
||||
response = Unirest.post(srvUrl + "/init/" + login).asJson();
|
||||
logger.debug(response.getBody().toPrettyString());
|
||||
} catch (UnirestException e) {
|
||||
logger.error("Cannot create account.");
|
||||
}
|
||||
}
|
||||
|
||||
public void getReport (String reportId) {
|
||||
HttpResponse<JsonNode> response;
|
||||
try {
|
||||
response = Unirest.get(srvUrl + "/report/" + reportId).asJson();
|
||||
logger.debug(response.getBody().toPrettyString());
|
||||
} catch (UnirestException e) {
|
||||
logger.error("Could not retrieve report");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,81 @@
|
|||
package com.epita.creeps;
|
||||
|
||||
import kong.unirest.core.HttpResponse;
|
||||
import kong.unirest.core.JsonNode;
|
||||
import kong.unirest.core.Unirest;
|
||||
import kong.unirest.core.UnirestException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.ConnectException;
|
||||
|
||||
public class Program {
|
||||
|
||||
private static String srvUrl;
|
||||
private static Logger logger;
|
||||
private static String login;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
|
||||
//Initialization
|
||||
|
||||
// Default Vars
|
||||
srvUrl = "http://localhost:1664";
|
||||
login = "marion.mavie";
|
||||
|
||||
// Classes
|
||||
logger = LoggerFactory.getLogger(Program.class);
|
||||
Basics basics = new Basics(logger, srvUrl);
|
||||
logger.info("Initializing");
|
||||
|
||||
if (args.length == 3) {
|
||||
srvUrl = args[0] + args[1];
|
||||
login = args[2];
|
||||
} else {
|
||||
logger.warn("No given args: using the default values");
|
||||
}
|
||||
|
||||
// Test
|
||||
HttpResponse<JsonNode> response;
|
||||
try {
|
||||
response = Unirest.get(srvUrl + "/status").asJson();
|
||||
} catch (UnirestException e) {
|
||||
logger.error("Cannot connect to the server. Aborting...");
|
||||
throw e;
|
||||
}
|
||||
// JsonNode jsonNode = response.getBody();
|
||||
// System.out.println(jsonNode);
|
||||
|
||||
logger.info("Creating account");
|
||||
basics.connectAccount(login);
|
||||
|
||||
logger.info("Done");
|
||||
}
|
||||
|
||||
// ### Get statistics
|
||||
//GET http://localhost:1664/statistics
|
||||
//
|
||||
//### Get status
|
||||
//GET http://localhost:1664/status
|
||||
//
|
||||
//### Get report
|
||||
//GET http://localhost:1664/report/148997e9b
|
||||
//
|
||||
//### Login with user login_l
|
||||
//POST http://localhost:1664/init/login_l
|
||||
//
|
||||
//> {%
|
||||
//client.global.set("baseId", response.body.baseId);
|
||||
//client.global.set("probeId", response.body.probeId);
|
||||
//client.global.set("login", response.body.login);
|
||||
//%}
|
||||
//
|
||||
//### Post noop commande
|
||||
//POST http://localhost:1664/command/{{login}}/{{probeId}}/noop
|
||||
//
|
||||
//###
|
||||
//POST http://localhost:1664/command/dumeig_a/8d87eea10/inspect
|
||||
//
|
||||
//###
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue