Search in sources :

Example 11 with CloudPlayer

use of de.dytanic.cloudnet.lib.player.CloudPlayer in project CloudNet by Dytanic.

the class CloudAPI method getOnlinePlayer.

/**
 * Retuns a online CloudPlayer on network or null if the player isn't online
 */
public CloudPlayer getOnlinePlayer(UUID uniqueId) {
    CloudPlayer instance = checkAndGet(uniqueId);
    if (instance != null)
        return instance;
    Result result = networkConnection.getPacketManager().sendQuery(new PacketAPIOutGetPlayer(uniqueId), networkConnection);
    CloudPlayer cloudPlayer = result.getResult().getObject("player", CloudPlayer.TYPE);
    if (cloudPlayer == null)
        return null;
    cloudPlayer.setPlayerExecutor(PlayerExecutorBridge.INSTANCE);
    return cloudPlayer;
}
Also used : CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) Result(de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)

Example 12 with CloudPlayer

use of de.dytanic.cloudnet.lib.player.CloudPlayer in project CloudNet by Dytanic.

the class PacketInLoginPlayer method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (CloudAPI.getInstance() != null) {
        CloudPlayer cloudPlayer = data.getObject("player", CloudPlayer.TYPE);
        CloudAPI.getInstance().getNetworkHandlerProvider().iterator(new Runnabled<NetworkHandler>() {

            @Override
            public void run(NetworkHandler obj) {
                obj.onPlayerLoginNetwork(cloudPlayer);
            }
        });
    }
}
Also used : CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) NetworkHandler(de.dytanic.cloudnet.api.handlers.NetworkHandler)

Example 13 with CloudPlayer

use of de.dytanic.cloudnet.lib.player.CloudPlayer 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;
            }
    }
}
Also used : User(de.dytanic.cloudnet.lib.user.User) ArrayList(java.util.ArrayList) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) Document(de.dytanic.cloudnet.lib.utility.document.Document) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 14 with CloudPlayer

use of de.dytanic.cloudnet.lib.player.CloudPlayer in project CloudNet by Dytanic.

the class PlayerExample method examplePlayer.

public void examplePlayer() {
    // Returns the CloudPlayer if the play is online or null if isn't online
    CloudPlayer cloudPlayer = CloudAPI.getInstance().getOnlinePlayer(UUID.fromString("e71d69dd-058f-4319-9ae9-8c8f0a7a61f5"));
    {
        // Returns the online player connection metadata
        PlayerConnection playerConnection = cloudPlayer.getPlayerConnection();
        // Returns the IP
        playerConnection.getHost();
        // Returns the port of the last connection
        playerConnection.getPort();
        // Returns the UUID of the connection
        playerConnection.getUniqueId();
        // Returns the legacy version
        playerConnection.getVersion();
        // Returns if the player was in onlinemode
        playerConnection.isOnlineMode();
    }
    System.out.println("The player " + cloudPlayer.getName() + " is on " + cloudPlayer.getProxy() + NetworkUtils.SLASH_STRING + cloudPlayer.getServer() + " and connected at " + cloudPlayer.getLoginTimeStamp().getTime());
    // Returns a util Class for some network methods
    PlayerExecutor playerExecutor = cloudPlayer.getPlayerExecutor();
    // writes a message to the player if the player is online
    playerExecutor.sendMessage(cloudPlayer, "Hello world!");
    // send a player to a some server
    playerExecutor.sendPlayer(cloudPlayer, "Lobby-2");
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // Kick a player from the network
            playerExecutor.kickPlayer(cloudPlayer, "you are a cool guy for the network");
        }
    }).start();
    OfflinePlayer offlinePlayer = CloudAPI.getInstance().getOfflinePlayer("Dytanic");
    if (// If the player is registered
    offlinePlayer != null) {
        // Returns the permissionentity for manage some permission systems
        PermissionEntity permissionEntity = offlinePlayer.getPermissionEntity();
        // add a permission group with the delay of 30 days
        permissionEntity.getGroups().add(new GroupEntityData("VIP", System.currentTimeMillis() + TimeUnit.DAYS.toMillis(30)));
        // add a permission for this player
        permissionEntity.getPermissions().put("minecraft.command.tp", true);
        if (permissionEntity.isInGroup("VIP")) {
            System.out.println("The player " + offlinePlayer.getUniqueId() + NetworkUtils.SLASH_STRING + offlinePlayer.getName() + " is in the group VIP");
        }
        PlayerConnection playerConnection = offlinePlayer.getLastPlayerConnection();
        // Returns the IP
        playerConnection.getHost();
        // Returns the port of the last connection
        playerConnection.getPort();
        // Returns the UUID of the connection
        playerConnection.getUniqueId();
        // Returns the legacy version
        playerConnection.getVersion();
        // Returns if the player was in onlinemode
        playerConnection.isOnlineMode();
    }
    // update the player
    // cloudplayer update
    CloudAPI.getInstance().updatePlayer(cloudPlayer);
    // update the offline player
    CloudAPI.getInstance().updatePlayer(offlinePlayer);
}
Also used : PlayerExecutor(de.dytanic.cloudnet.lib.player.PlayerExecutor) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) OfflinePlayer(de.dytanic.cloudnet.lib.player.OfflinePlayer) PermissionEntity(de.dytanic.cloudnet.lib.player.permission.PermissionEntity) PlayerConnection(de.dytanic.cloudnet.lib.player.PlayerConnection) GroupEntityData(de.dytanic.cloudnet.lib.player.permission.GroupEntityData)

Example 15 with CloudPlayer

use of de.dytanic.cloudnet.lib.player.CloudPlayer in project CloudNet by Dytanic.

the class ProxiedListener method handleDisconnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void handleDisconnect(PlayerDisconnectEvent e) {
    CloudPlayer cloudPlayer = CloudProxy.getInstance().getCloudPlayers().get(e.getPlayer().getUniqueId());
    if (cloudPlayer != null) {
        CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutLogoutPlayer(cloudPlayer, e.getPlayer().getUniqueId()));
    } else {
        CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutLogoutPlayer(null, e.getPlayer().getUniqueId()));
    }
    CloudProxy.getInstance().getCloudPlayers().remove(e.getPlayer().getUniqueId());
    ProxyServer.getInstance().getScheduler().schedule(CloudProxy.getInstance().getPlugin(), new Runnable() {

        @Override
        public void run() {
            CloudProxy.getInstance().update();
        }
    }, 250, TimeUnit.MILLISECONDS);
}
Also used : CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)19 TypeToken (com.google.gson.reflect.TypeToken)5 Result (de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)4 OfflinePlayer (de.dytanic.cloudnet.lib.player.OfflinePlayer)3 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)3 Document (de.dytanic.cloudnet.lib.utility.document.Document)3 EventHandler (net.md_5.bungee.event.EventHandler)3 PlayerConnection (de.dytanic.cloudnet.lib.player.PlayerConnection)2 GroupEntityData (de.dytanic.cloudnet.lib.player.permission.GroupEntityData)2 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)2 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)2 NetworkHandler (de.dytanic.cloudnet.api.handlers.NetworkHandler)1 PlayerExecutorBridge (de.dytanic.cloudnet.api.player.PlayerExecutorBridge)1 CloudPermissble (de.dytanic.cloudnet.bridge.internal.util.CloudPermissble)1 CloudPlayerCommandSender (de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender)1 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)1 WrapperInfo (de.dytanic.cloudnet.lib.network.WrapperInfo)1 PlayerExecutor (de.dytanic.cloudnet.lib.player.PlayerExecutor)1 PermissionEntity (de.dytanic.cloudnet.lib.player.permission.PermissionEntity)1 AutoSlot (de.dytanic.cloudnet.lib.proxylayout.AutoSlot)1