Search in sources :

Example 16 with ServerConnection

use of com.velocitypowered.api.proxy.ServerConnection in project ResourcepacksPlugins by Phoenix616.

the class PluginMessageListener method pluginMessageReceived.

@Subscribe
public void pluginMessageReceived(PluginMessageEvent event) {
    if (!plugin.isEnabled() || !event.getIdentifier().getId().equals("rp:plugin") || !(event.getSource() instanceof ServerConnection))
        return;
    ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
    String subchannel = in.readUTF();
    if ("authMeLogin".equals(subchannel)) {
        String playerName = in.readUTF();
        UUID playerId = UUID.fromString(in.readUTF());
        plugin.setAuthenticated(playerId, true);
        if (!plugin.hasBackend(playerId) && plugin.getConfig().getBoolean("use-auth-plugin", plugin.getConfig().getBoolean("useauth", false))) {
            Optional<Player> player = plugin.getProxy().getPlayer(playerId);
            if (player.isPresent()) {
                String serverName = "";
                Optional<ServerConnection> server = player.get().getCurrentServer();
                if (server.isPresent()) {
                    serverName = server.get().getServerInfo().getName();
                }
                long sendDelay = plugin.getPackManager().getAssignment(serverName).getSendDelay();
                if (sendDelay < 0) {
                    sendDelay = plugin.getPackManager().getGlobalAssignment().getSendDelay();
                }
                if (sendDelay > 0) {
                    String finalServerName = serverName;
                    plugin.getProxy().getScheduler().buildTask(plugin, () -> plugin.getPackManager().applyPack(playerId, finalServerName)).delay(sendDelay * 20, TimeUnit.MILLISECONDS);
                } else {
                    plugin.getPackManager().applyPack(playerId, serverName);
                }
            }
        }
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) ServerConnection(com.velocitypowered.api.proxy.ServerConnection) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) UUID(java.util.UUID) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 17 with ServerConnection

use of com.velocitypowered.api.proxy.ServerConnection in project 2FA by LielAmar.

the class OnPluginMessage method sendResponse.

public void sendResponse(UUID messageUUID, Player player, AuthCommunicationHandler.MessageType messageType) {
    AuthHandler.AuthState authState = this.plugin.getAuthHandler().getAuthState(player.getUniqueId());
    ByteArrayDataOutput response = ByteStreams.newDataOutput();
    response.writeUTF(Constants.PROXY_SUB_CHANNEL_NAME);
    response.writeUTF(messageUUID.toString());
    response.writeUTF(player.getUniqueId().toString());
    ByteArrayOutputStream msgBody = new ByteArrayOutputStream();
    DataOutputStream msgBodyData = new DataOutputStream(msgBody);
    try {
        msgBodyData.writeUTF(messageType.name());
        msgBodyData.writeUTF(authState.name());
    } catch (IOException exception) {
        exception.printStackTrace();
    }
    response.writeShort(msgBody.toByteArray().length);
    response.write(msgBody.toByteArray());
    Optional<ServerConnection> optionalServer = player.getCurrentServer();
    optionalServer.ifPresent(serverConnection -> serverConnection.sendPluginMessage(this.plugin.getOUTGOING(), response.toByteArray()));
}
Also used : AuthHandler(com.lielamar.auth.shared.handlers.AuthHandler) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) ServerConnection(com.velocitypowered.api.proxy.ServerConnection)

Example 18 with ServerConnection

use of com.velocitypowered.api.proxy.ServerConnection in project Floodgate by GeyserMC.

the class VelocityPluginMessageUtils method onPluginMessage.

@Subscribe
public void onPluginMessage(PluginMessageEvent event) {
    String channelId = event.getIdentifier().getId();
    PluginMessageChannel channel = pluginMessageManager.getChannel(channelId);
    if (channel == null) {
        return;
    }
    UUID targetUuid = null;
    String targetUsername = null;
    Identity targetIdentity = Identity.UNKNOWN;
    ChannelMessageSink target = event.getTarget();
    if (target instanceof Player) {
        Player player = (Player) target;
        targetUuid = player.getUniqueId();
        targetUsername = player.getUsername();
        targetIdentity = Identity.PLAYER;
    } else if (target instanceof ServerConnection) {
        targetIdentity = Identity.SERVER;
    }
    UUID sourceUuid = null;
    String sourceUsername = null;
    Identity sourceIdentity = Identity.UNKNOWN;
    ChannelMessageSource source = event.getSource();
    if (source instanceof Player) {
        Player player = (Player) source;
        sourceUuid = player.getUniqueId();
        sourceUsername = player.getUsername();
        sourceIdentity = Identity.PLAYER;
    } else if (source instanceof ServerConnection) {
        sourceIdentity = Identity.SERVER;
    }
    Result result = channel.handleProxyCall(event.getData(), targetUuid, targetUsername, targetIdentity, sourceUuid, sourceUsername, sourceIdentity);
    event.setResult(result.isAllowed() ? ForwardResult.forward() : ForwardResult.handled());
    if (!result.isAllowed() && result.getReason() != null) {
        logKick(source, result.getReason());
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) ServerConnection(com.velocitypowered.api.proxy.ServerConnection) UUID(java.util.UUID) Identity(org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Identity) ChannelMessageSink(com.velocitypowered.api.proxy.messages.ChannelMessageSink) ChannelMessageSource(com.velocitypowered.api.proxy.messages.ChannelMessageSource) Result(org.geysermc.floodgate.pluginmessage.PluginMessageChannel.Result) ForwardResult(com.velocitypowered.api.event.connection.PluginMessageEvent.ForwardResult) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 19 with ServerConnection

use of com.velocitypowered.api.proxy.ServerConnection in project XConomy by YiC200333.

the class Vsync method on.

@SuppressWarnings(value = { "UnstableApiUsage", "unused" })
@Subscribe
public void on(PluginMessageEvent event) {
    if (event.getSource() instanceof Player) {
        return;
    }
    if (!event.getIdentifier().getId().equals(XConomyVelocity.acb.getId())) {
        return;
    }
    ByteArrayDataInput input = ByteStreams.newDataInput(event.getData());
    ServerConnection senderServer = (ServerConnection) event.getSource();
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeUTF(input.readUTF());
    String sv = input.readUTF();
    output.writeUTF(sv);
    String svv = sv;
    if (svv.contains(".")) {
        svv = "versions §f" + svv;
    } else {
        svv = "§fold versions";
    }
    if (!sv.equals(XConomyVelocity.syncversion)) {
        XConomyVelocity.getInstance().logger.warn("§cReceived data from " + svv + ", §cunable to synchronize, Current plugin version §f" + XConomyVelocity.syncversion);
        return;
    }
    String type = input.readUTF();
    if (type.equalsIgnoreCase("updateplayer")) {
        output.writeUTF("updateplayer");
        output.writeUTF(input.readUTF());
    } else if (type.equalsIgnoreCase("message") || type.equalsIgnoreCase("message#semi")) {
        output.writeUTF("message");
        String uid = input.readUTF();
        Optional<Player> p = XConomyVelocity.getInstance().server.getPlayer(UUID.fromString(uid));
        if (type.equalsIgnoreCase("message") && !p.isPresent()) {
            return;
        }
        output.writeUTF(uid);
        output.writeUTF(input.readUTF());
    } else if (type.equalsIgnoreCase("balanceall")) {
        output.writeUTF("balanceall");
        output.writeUTF(input.readUTF());
        output.writeUTF(input.readUTF());
        output.writeUTF(input.readUTF());
    } else if (type.equalsIgnoreCase("broadcast")) {
        output.writeUTF("broadcast");
        output.writeUTF(input.readUTF());
    } else if (type.equalsIgnoreCase("syncOnlineUUID")) {
        output.writeUTF("syncOnlineUUID");
        output.writeUTF(input.readUTF());
        output.writeUTF(input.readUTF());
        output.writeUTF(input.readUTF());
    }
    for (RegisteredServer s : XConomyVelocity.getInstance().server.getAllServers()) {
        if (!s.equals(senderServer.getServer()) && s.getPlayersConnected().size() > 0) {
            XConomyVelocity.getInstance().server.getScheduler().buildTask(XConomyVelocity.getInstance(), () -> SendMessTaskB(s, output)).schedule();
        }
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) Optional(java.util.Optional) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) ServerConnection(com.velocitypowered.api.proxy.ServerConnection) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 20 with ServerConnection

use of com.velocitypowered.api.proxy.ServerConnection in project ProxyQueues by JLyne.

the class ProxyQueueImpl method shouldAddPlayer.

private CompletableFuture<Boolean> shouldAddPlayer(Player player) {
    PlayerQueueEvent event = new PlayerQueueEvent(player, server);
    return proxyQueues.getProxyServer().getEventManager().fire(event).thenApply((PlayerQueueEvent result) -> {
        // Don't add to queue if event cancelled, show player the reason
        if (result.isCancelled()) {
            String reason = result.getReason() != null ? result.getReason() : "An unexpected error occurred. Please try again later";
            ServerConnection currentServer = player.getCurrentServer().orElse(null);
            RegisteredServer waitingServer = proxyQueues.getWaitingServer().orElse(null);
            proxyQueues.getLogger().info(player.getUsername() + "'s PlayerQueueEvent cancelled");
            if (currentServer == null || currentServer.getServer().equals(waitingServer)) {
                player.disconnect(Messages.getComponent("errors.queue-cannot-join", Collections.singletonMap("reason", reason), Collections.emptyMap()));
            } else {
                proxyQueues.sendMessage(player, MessageType.ERROR, "errors.queue-cannot-join", Collections.singletonMap("reason", reason));
            }
        }
        return !result.isCancelled();
    });
}
Also used : PlayerQueueEvent(uk.co.notnull.proxyqueues.api.events.PlayerQueueEvent) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) ServerConnection(com.velocitypowered.api.proxy.ServerConnection)

Aggregations

ServerConnection (com.velocitypowered.api.proxy.ServerConnection)21 Subscribe (com.velocitypowered.api.event.Subscribe)12 Player (com.velocitypowered.api.proxy.Player)12 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)8 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)6 UUID (java.util.UUID)6 Component (net.kyori.adventure.text.Component)5 File (java.io.File)4 InputStreamReader (java.io.InputStreamReader)4 TimeUnit (java.util.concurrent.TimeUnit)4 Inject (com.google.inject.Inject)3 CommandSource (com.velocitypowered.api.command.CommandSource)3 PostOrder (com.velocitypowered.api.event.PostOrder)3 DisconnectEvent (com.velocitypowered.api.event.connection.DisconnectEvent)3 ServerPostConnectEvent (com.velocitypowered.api.event.player.ServerPostConnectEvent)3 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)3 IOException (java.io.IOException)3 TextComponent (net.kyori.adventure.text.TextComponent)3 HoverEvent (net.kyori.adventure.text.event.HoverEvent)3 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)2