use of de.dytanic.cloudnetcore.network.components.ProxyServer 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.ProxyServer 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.ProxyServer in project CloudNet by Dytanic.
the class PacketInPlayerLoginRequest method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
if (!(packetSender instanceof ProxyServer) && packetUniqueId != null)
return;
PlayerConnection playerConnection = data.getObject("playerConnection", new TypeToken<PlayerConnection>() {
}.getType());
CloudNet.getInstance().getNetworkManager().handlePlayerLoginRequest(((ProxyServer) packetSender), playerConnection, packetUniqueId);
}
use of de.dytanic.cloudnetcore.network.components.ProxyServer in project CloudNet by Dytanic.
the class PacketInRemoveProxy method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
if (!(packetSender instanceof Wrapper))
return;
Wrapper cn = (Wrapper) packetSender;
ProxyInfo proxyInfo = data.getObject("proxyInfo", new TypeToken<ProxyInfo>() {
}.getType());
if (cn.getProxys().containsKey(proxyInfo.getServiceId().getServerId())) {
ProxyServer minecraftServer = cn.getProxys().get(proxyInfo.getServiceId().getServerId());
if (minecraftServer.getChannel() != null)
minecraftServer.getChannel().close();
cn.getProxys().remove(proxyInfo.getServiceId().getServerId());
CloudNet.getInstance().getNetworkManager().handleProxyRemove(minecraftServer);
CloudNet.getInstance().getScreenProvider().handleDisableScreen(proxyInfo.getServiceId());
}
}
use of de.dytanic.cloudnetcore.network.components.ProxyServer in project CloudNet by Dytanic.
the class CommandCmd method onExecuteCommand.
@Override
public void onExecuteCommand(CommandSender sender, String[] args) {
if (args.length > 1) {
for (Wrapper wrapper : CloudNet.getInstance().getWrappers().values()) {
for (MinecraftServer minecraftServer : wrapper.getServers().values()) {
if (minecraftServer.getServiceId().getServerId().equalsIgnoreCase(args[0])) {
StringBuilder stringBuilder = new StringBuilder();
for (short i = 1; i < args.length; i++) {
stringBuilder.append(args[i]).append(NetworkUtils.SPACE_STRING);
}
minecraftServer.getWrapper().writeServerCommand(stringBuilder.substring(0, stringBuilder.length() - 1), minecraftServer.getServerInfo());
sender.sendMessage("Sending command to " + minecraftServer.getServiceId().getServerId() + " with [\"" + stringBuilder.substring(0, stringBuilder.length() - 1) + "\"]");
return;
}
}
for (ProxyServer minecraftServer : wrapper.getProxys().values()) {
if (minecraftServer.getServiceId().getServerId().equalsIgnoreCase(args[0])) {
StringBuilder stringBuilder = new StringBuilder();
for (short i = 1; i < args.length; i++) {
stringBuilder.append(args[i]).append(NetworkUtils.SPACE_STRING);
}
minecraftServer.getWrapper().writeProxyCommand(stringBuilder.substring(0, stringBuilder.length() - 1), minecraftServer.getProxyInfo());
sender.sendMessage("Sending command to " + minecraftServer.getServiceId().getServerId() + " with [\"" + stringBuilder.substring(0, stringBuilder.length() - 1) + "\"]");
return;
}
}
}
} else {
sender.sendMessage("cmd <name> <command> | Executes a command, either from a proxy or game server");
}
}
Aggregations