API updates

This commit is contained in:
Alfie Cleveland 2017-10-01 02:31:47 +01:00
parent 5270321c37
commit 2cdbba0c77
5 changed files with 74 additions and 4 deletions

View File

@ -68,10 +68,12 @@ import net.frozenorb.apiv3.web.route.ranks.POSTRanks;
import net.frozenorb.apiv3.web.route.serverGroups.DELETEServerGroupsId;
import net.frozenorb.apiv3.web.route.serverGroups.GETServerGroups;
import net.frozenorb.apiv3.web.route.serverGroups.GETServerGroupsId;
import net.frozenorb.apiv3.web.route.serverGroups.GETServerGroupsPlayerCount;
import net.frozenorb.apiv3.web.route.serverGroups.POSTServerGroups;
import net.frozenorb.apiv3.web.route.servers.DELETEServersId;
import net.frozenorb.apiv3.web.route.servers.GETServers;
import net.frozenorb.apiv3.web.route.servers.GETServersId;
import net.frozenorb.apiv3.web.route.servers.GETServersPlayerCountId;
import net.frozenorb.apiv3.web.route.servers.POSTServers;
import net.frozenorb.apiv3.web.route.servers.POSTServersHeartbeat;
import net.frozenorb.apiv3.web.route.users.GETStaff;
@ -189,7 +191,6 @@ public final class APIv3 {
//httpPut(router, "/ipBans/:ipBanId", PUTIpBansId.class);
httpDelete(router, "/ipBans/:ipBanId", DELETEIpBansId.class);
httpGet(router, "/ipLog/:id", GETIpLogId.class);
httpPost(router, "/lookup/byName", POSTLookupByName.class);
@ -217,12 +218,14 @@ public final class APIv3 {
httpDelete(router, "/ranks/:rankId", DELETERanksId.class);
httpGet(router, "/serverGroups/:serverGroupId", GETServerGroupsId.class);
httpGet(router, "/serverGroups/:serverGroupId/playerCount", GETServerGroupsPlayerCount.class);
httpGet(router, "/serverGroups", GETServerGroups.class);
httpPost(router, "/serverGroups", POSTServerGroups.class);
//httpPut(router, "/serverGroups/:serverGroupId", PUTServerGroupsId.class);
httpDelete(router, "/serverGroups/:serverGroupId", DELETEServerGroupsId.class);
httpGet(router, "/servers/:serverId", GETServersId.class);
httpGet(router, "/servers/:serverId/playerCount", GETServersPlayerCountId.class);
httpGet(router, "/servers", GETServers.class);
httpPost(router, "/servers/heartbeat", POSTServersHeartbeat.class);
httpPost(router, "/servers", POSTServers.class);

View File

@ -104,6 +104,9 @@ public final class POSTGrants implements Handler<RoutingContext> {
return;
}
}
} else if (rank.isGrantRequiresTotp()) {
ErrorUtils.respondInvalidInput(ctx, "Rank must be granted through API or website.");
return;
}
int storeItemId = requestBody.getInteger("storeItemId", -1);

View File

@ -1,18 +1,29 @@
package net.frozenorb.apiv3.web.route.serverGroups;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.domain.ServerGroup;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.stereotype.Component;
import com.google.common.base.Objects;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.domain.Server;
import net.frozenorb.apiv3.domain.ServerGroup;
@Component
public final class GETServerGroupsId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, 200, ServerGroup.findById(ctx.request().getParam("serverGroupId")));
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("serverGroupId"));
AtomicInteger totalOnline = new AtomicInteger();
Server.findAll().forEach(server -> {
if (serverGroup == null || Objects.equal(serverGroup.getId(), server.getServerGroup())) totalOnline.addAndGet(server.getPlayers().size());
});
APIv3.respondJson(ctx, 200, Integer.valueOf(totalOnline.intValue()));
}
}

View File

@ -0,0 +1,34 @@
package net.frozenorb.apiv3.web.route.serverGroups;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.stereotype.Component;
import com.google.common.collect.Maps;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.domain.Server;
@Component
public final class GETServerGroupsPlayerCount implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Map<String, Integer> map = Maps.newHashMap();
AtomicInteger total = new AtomicInteger();
Server.findAll().forEach(server -> {
int size;
Integer lastCount = null;
map.put(server.getServerGroup(), map.getOrDefault(server.getServerGroup(), 0) + (size = server.getPlayers().size()));
total.addAndGet(size);
});
map.put("total", Integer.valueOf(total.intValue()));
APIv3.respondJson(ctx, 200, map);
}
}

View File

@ -0,0 +1,19 @@
package net.frozenorb.apiv3.web.route.servers;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.domain.Server;
import org.springframework.stereotype.Component;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
@Component
public final class GETServersPlayerCountId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Server server = Server.findById(ctx.request().getParam("serverId"));
APIv3.respondJson(ctx, 200, server == null ? Integer.valueOf(0) : Integer.valueOf(server.getPlayers().size()));
}
}