use of de.dytanic.cloudnetcore.network.components.MinecraftServer in project CloudNet by Dytanic.
the class ServerLogManager method append.
public void append(String rnd, String serverId) {
for (String key : screenInfos.keySet()) {
if (this.screenInfos.getF(key).getFirst().equals(serverId)) {
screenInfos.add(rnd, new MultiValue<>(serverId, (System.currentTimeMillis() + 600000L)), new ConcurrentLinkedQueue<>(this.screenInfos.getS(key)));
return;
}
}
MinecraftServer minecraftServer = CloudNet.getInstance().getServer(serverId);
if (minecraftServer != null) {
minecraftServer.getWrapper().enableScreen(minecraftServer.getServerInfo());
screenInfos.add(rnd, new MultiValue<>(serverId, (System.currentTimeMillis() + 600000L)), new ConcurrentLinkedQueue<>());
return;
}
ProxyServer proxyServer = CloudNet.getInstance().getProxy(serverId);
if (proxyServer != null) {
proxyServer.getWrapper().enableScreen(proxyServer.getProxyInfo());
screenInfos.add(rnd, new MultiValue<>(serverId, (System.currentTimeMillis() + 600000L)), new ConcurrentLinkedQueue<>());
}
}
use of de.dytanic.cloudnetcore.network.components.MinecraftServer in project CloudNet by Dytanic.
the class PacketInAddServer method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
if (!(packetSender instanceof Wrapper))
return;
Wrapper cn = ((Wrapper) packetSender);
ServerInfo nullServerInfo = data.getObject("serverInfo", new TypeToken<ServerInfo>() {
}.getType());
ServerProcessMeta serverProcessMeta = data.getObject("serverProcess", new TypeToken<ServerProcessMeta>() {
}.getType());
MinecraftServer minecraftServer = new MinecraftServer(serverProcessMeta, cn, CloudNet.getInstance().getServerGroups().get(nullServerInfo.getServiceId().getGroup()), nullServerInfo);
cn.getServers().put(nullServerInfo.getServiceId().getServerId(), minecraftServer);
cn.getWaitingServices().remove(minecraftServer.getServerId());
{
if (serverProcessMeta.isPriorityStop()) {
ServerGroup serverGroup = CloudNet.getInstance().getServerGroups().get(serverProcessMeta.getServiceId().getGroup());
if (serverGroup != null) {
PriorityStopTask priorityStopTask = new PriorityStopTask(cn, minecraftServer, serverGroup.getPriorityService().getStopTimeInSeconds());
ScheduledTask scheduledTask = CloudNet.getInstance().getSubScheduler().runTaskRepeatSync(priorityStopTask, 0, 50);
priorityStopTask.setScheduledTask(scheduledTask);
}
}
}
CloudNet.getInstance().getNetworkManager().handleServerAdd(minecraftServer);
}
use of de.dytanic.cloudnetcore.network.components.MinecraftServer in project CloudNet by Dytanic.
the class PacketInCustomSubChannelMessage method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
DefaultType defaultType = data.getObject("defaultType", DefaultType.class);
String channel = data.getString("channel");
String message = data.getString("message");
Document document = data.getDocument("value");
if (defaultType.equals(DefaultType.BUKKIT)) {
if (data.contains("serverId")) {
MinecraftServer minecraftServer = CloudNet.getInstance().getServer(data.getString("serverId"));
if (minecraftServer != null) {
minecraftServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
return;
}
CloudServer cloudServer = CloudNet.getInstance().getCloudGameServer(data.getString("serverId"));
if (cloudServer != null) {
cloudServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
}
} else {
CloudNet.getInstance().getNetworkManager().sendAll(new PacketOutCustomSubChannelMessage(channel, message, document), new ChannelFilter() {
@Override
public boolean accept(INetworkComponent networkComponent) {
return networkComponent instanceof MinecraftServer || networkComponent instanceof CloudServer;
}
});
}
} else {
if (data.contains("serverId")) {
ProxyServer proxyServer = CloudNet.getInstance().getProxy(data.getString("serverId"));
if (proxyServer != null) {
proxyServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
}
} else {
CloudNet.getInstance().getNetworkManager().sendToProxy(new PacketOutCustomSubChannelMessage(channel, message, document));
}
}
}
use of de.dytanic.cloudnetcore.network.components.MinecraftServer in project CloudNet by Dytanic.
the class WebsiteUtils method get.
@Override
public FullHttpResponse get(ChannelHandlerContext channelHandlerContext, QueryDecoder queryDecoder, PathProvider path, HttpRequest httpRequest) throws Exception {
FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(httpRequest.getProtocolVersion(), HttpResponseStatus.UNAUTHORIZED);
fullHttpResponse.headers().set("Content-Type", "application/json");
Document dataDocument = new Document("success", false).append("reason", new ArrayList<>()).append("response", new Document());
if (!httpRequest.headers().contains("-Xcloudnet-user") || (!httpRequest.headers().contains("-Xcloudnet-token") && !httpRequest.headers().contains("-Xcloudnet-password")) || !httpRequest.headers().contains("-Xmessage")) {
dataDocument.append("reason", Arrays.asList("-Xcloudnet-user, -Xcloudnet-token or -Xmessage not found!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
return fullHttpResponse;
}
if (httpRequest.headers().contains("-Xcloudnet-token") ? !CloudNet.getInstance().authorization(httpRequest.headers().get("-Xcloudnet-user"), httpRequest.headers().get("-Xcloudnet-token")) : !CloudNet.getInstance().authorizationPassword(httpRequest.headers().get("-Xcloudnet-user"), httpRequest.headers().get("-Xcloudnet-password"))) {
dataDocument.append("reason", Arrays.asList("failed authorization!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
return fullHttpResponse;
}
User user = CloudNet.getInstance().getUser(httpRequest.headers().get("-Xcloudnet-user"));
switch(httpRequest.headers().get("-Xmessage").toLowerCase()) {
case "serverinfos":
{
if (!user.getPermissions().contains("cloudnet.web.serverinfos") && !user.getPermissions().contains("*")) {
dataDocument.append("reason", Arrays.asList("permission denied!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
return fullHttpResponse;
}
dataDocument.append("success", true);
Document response = new Document();
for (MinecraftServer minecraftServer : CloudNet.getInstance().getServers().values()) {
response.append(minecraftServer.getServiceId().getServerId(), minecraftServer.getServerInfo());
}
dataDocument.append("response", response);
fullHttpResponse.setStatus(HttpResponseStatus.OK);
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
return fullHttpResponse;
}
case "proxyinfos":
{
if (!user.getPermissions().contains("cloudnet.web.proxyinfos") && !user.getPermissions().contains("*")) {
dataDocument.append("reason", Arrays.asList("permission denied!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
return fullHttpResponse;
}
dataDocument.append("success", true);
Document response = new Document();
for (ProxyServer minecraftServer : CloudNet.getInstance().getProxys().values()) {
response.append(minecraftServer.getServiceId().getServerId(), minecraftServer.getProxyInfo());
}
dataDocument.append("response", response);
fullHttpResponse.setStatus(HttpResponseStatus.OK);
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
return fullHttpResponse;
}
case "onlinePlayers":
if (!user.getPermissions().contains("cloudnet.web.onlineplayers") && !user.getPermissions().contains("*")) {
dataDocument.append("reason", Arrays.asList("permission denied!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
return fullHttpResponse;
}
dataDocument.append("success", true);
Document response = new Document();
for (CloudPlayer cloudPlayer : CloudNet.getInstance().getNetworkManager().getOnlinePlayers().values()) {
response.append(cloudPlayer.getUniqueId().toString(), cloudPlayer);
}
dataDocument.append("response", response);
fullHttpResponse.setStatus(HttpResponseStatus.OK);
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
return fullHttpResponse;
case "statistic":
if (!user.getPermissions().contains("cloudnet.web.statistic") && !user.getPermissions().contains("*")) {
dataDocument.append("reason", Arrays.asList("permission denied!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
return fullHttpResponse;
}
dataDocument.append("success", true).append("response", StatisticManager.getInstance().getStatistics());
fullHttpResponse.setStatus(HttpResponseStatus.OK);
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
return fullHttpResponse;
case "cloudnetwork":
if (!user.getPermissions().contains("cloudnet.web.cloudnetwork") && !user.getPermissions().contains("*")) {
dataDocument.append("reason", Arrays.asList("permission denied!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
return fullHttpResponse;
}
dataDocument.append("success", true).append("response", CloudNet.getInstance().getNetworkManager().newCloudNetwork());
fullHttpResponse.setStatus(HttpResponseStatus.OK);
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
return fullHttpResponse;
case "startServer":
if (!user.getPermissions().contains("cloudnet.web.startserver") && !user.getPermissions().contains("*")) {
dataDocument.append("reason", Arrays.asList("permission denied!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
return fullHttpResponse;
}
dataDocument.append("success", true);
fullHttpResponse.setStatus(HttpResponseStatus.OK);
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
if (httpRequest.headers().contains("-Xvalue")) {
String group = httpRequest.headers().get("-Xvalue");
CloudNet.getInstance().getScheduler().runTaskSync(new Runnable() {
@Override
public void run() {
CloudNet.getInstance().startGameServer(CloudNet.getInstance().getServerGroup(group));
}
});
}
return fullHttpResponse;
case "startProxy":
if (!user.getPermissions().contains("cloudnet.web.startproxy") && !user.getPermissions().contains("*")) {
dataDocument.append("reason", Arrays.asList("permission denied!"));
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
return fullHttpResponse;
}
dataDocument.append("success", true);
fullHttpResponse.setStatus(HttpResponseStatus.OK);
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
if (httpRequest.headers().contains("-Xvalue")) {
String group = httpRequest.headers().get("-Xvalue");
CloudNet.getInstance().getScheduler().runTaskSync(new Runnable() {
@Override
public void run() {
CloudNet.getInstance().startProxy(CloudNet.getInstance().getProxyGroup(group));
}
});
}
return fullHttpResponse;
default:
{
dataDocument.append("success", true).append("reason", Arrays.asList("No available -Xmessage command found!"));
fullHttpResponse.setStatus(HttpResponseStatus.OK);
fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
return fullHttpResponse;
}
}
}
use of de.dytanic.cloudnetcore.network.components.MinecraftServer in project CloudNet by Dytanic.
the class PacketInRemoveServer method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
if (!(packetSender instanceof Wrapper))
return;
Wrapper cn = (Wrapper) packetSender;
ServerInfo serverInfo = data.getObject("serverInfo", new TypeToken<ServerInfo>() {
}.getType());
if (cn.getServers().containsKey(serverInfo.getServiceId().getServerId())) {
MinecraftServer minecraftServer = cn.getServers().get(serverInfo.getServiceId().getServerId());
if (minecraftServer.getChannel() != null)
minecraftServer.getChannel().close();
cn.getServers().remove(serverInfo.getServiceId().getServerId());
CloudNet.getInstance().getNetworkManager().handleServerRemove(minecraftServer);
CloudNet.getInstance().getScreenProvider().handleDisableScreen(serverInfo.getServiceId());
}
}
Aggregations