1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Merge remote-tracking branch 'origin/feature/transfer-players'

This commit is contained in:
Tim203
2021-09-24 20:29:16 +02:00
6 changed files with 118 additions and 0 deletions

View File

@@ -95,6 +95,8 @@ public interface FloodgateApi {
boolean sendForm(UUID uuid, FormBuilder<?, ?> formBuilder);
boolean transferPlayer(UUID uuid, String address, int port);
/**
* Get the xuid of the user that has the given gamertag.
*

View File

@@ -119,6 +119,10 @@ public interface FloodgatePlayer {
return sendForm(formBuilder.build());
}
default boolean transfer(String address, int port) {
return FloodgateApi.getInstance().transferPlayer(getCorrectUniqueId(), address, port);
}
boolean hasProperty(PropertyKey key);
boolean hasProperty(String key);

View File

@@ -28,6 +28,7 @@ package org.geysermc.floodgate.pluginmessage;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.ServerConnection;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -96,4 +97,19 @@ public final class BungeePluginMessageUtils extends PluginMessageUtils implement
logger.error(reason + " Closing connection");
source.disconnect(new TextComponent(reason));
}
@Override
public boolean sendMessage(UUID player, boolean toServer, String channel, byte[] data) {
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(player);
if (proxiedPlayer == null) {
return false;
}
if (toServer) {
proxiedPlayer.getServer().sendData(channel, data);
} else {
proxiedPlayer.sendData(channel, data);
}
return true;
}
}

View File

@@ -41,6 +41,7 @@ import org.geysermc.floodgate.config.FloodgateConfigHolder;
import org.geysermc.floodgate.player.FloodgatePlayerImpl;
import org.geysermc.floodgate.pluginmessage.PluginMessageManager;
import org.geysermc.floodgate.pluginmessage.channel.FormChannel;
import org.geysermc.floodgate.pluginmessage.channel.TransferChannel;
import org.geysermc.floodgate.util.Constants;
import org.geysermc.floodgate.util.HttpUtils;
import org.geysermc.floodgate.util.Utils;
@@ -109,6 +110,13 @@ public class SimpleFloodgateApi implements FloodgateApi {
return sendForm(uuid, formBuilder.build());
}
@Override
public boolean transferPlayer(UUID uuid, String address, int port) {
return pluginMessageManager
.getChannel(TransferChannel.class)
.sendTransfer(uuid, address, port);
}
@Override
public CompletableFuture<Long> getXuidFor(String gamertag) {
if (gamertag == null || gamertag.isEmpty() || gamertag.length() > 16) {

View File

@@ -31,6 +31,7 @@ import com.google.inject.multibindings.ProvidesIntoSet;
import org.geysermc.floodgate.pluginmessage.PluginMessageChannel;
import org.geysermc.floodgate.pluginmessage.channel.FormChannel;
import org.geysermc.floodgate.pluginmessage.channel.SkinChannel;
import org.geysermc.floodgate.pluginmessage.channel.TransferChannel;
import org.geysermc.floodgate.register.PluginMessageRegister;
public final class PluginMessageModule extends AbstractModule {
@@ -50,4 +51,10 @@ public final class PluginMessageModule extends AbstractModule {
public PluginMessageChannel skinChannel() {
return new SkinChannel();
}
@Singleton
@ProvidesIntoSet
public PluginMessageChannel transferChannel() {
return new TransferChannel();
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Floodgate
*/
package org.geysermc.floodgate.pluginmessage.channel;
import com.google.inject.Inject;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import org.geysermc.floodgate.platform.pluginmessage.PluginMessageUtils;
import org.geysermc.floodgate.pluginmessage.PluginMessageChannel;
public class TransferChannel implements PluginMessageChannel {
@Inject private PluginMessageUtils pluginMessageUtils;
@Override
public String getIdentifier() {
return "floodgate:transfer";
}
@Override
public Result handleProxyCall(
byte[] data,
UUID targetUuid,
String targetUsername,
Identity targetIdentity,
UUID sourceUuid,
String sourceUsername,
Identity sourceIdentity) {
if (sourceIdentity == Identity.SERVER) {
// send it to the client
return Result.forward();
}
if (sourceIdentity == Identity.PLAYER) {
handleServerCall(data, targetUuid, targetUsername);
}
return Result.handled();
}
@Override
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) {
return Result.kick("I'm sorry, I'm unable to transfer a server :(");
}
public boolean sendTransfer(UUID player, String address, int port) {
byte[] addressBytes = address.getBytes(StandardCharsets.UTF_8);
byte[] data = new byte[addressBytes.length + 4];
data[0] = (byte) (port >> 24);
data[1] = (byte) (port >> 16);
data[2] = (byte) (port >> 8);
data[3] = (byte) (port);
System.arraycopy(addressBytes, 0, data, 4, addressBytes.length);
return pluginMessageUtils.sendMessage(player, false, getIdentifier(), data);
}
}