mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
Developers can now change some Floodgate related data during handshake
This commit is contained in:
@@ -27,6 +27,7 @@ package org.geysermc.floodgate.api;
|
||||
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.floodgate.api.handshake.HandshakeHandlers;
|
||||
import org.geysermc.floodgate.api.inject.PlatformInjector;
|
||||
import org.geysermc.floodgate.api.link.PlayerLink;
|
||||
|
||||
@@ -34,10 +35,16 @@ public final class InstanceHolder {
|
||||
@Getter private static FloodgateApi instance;
|
||||
@Getter private static PlayerLink playerLink;
|
||||
@Getter private static PlatformInjector injector;
|
||||
@Getter private static HandshakeHandlers handshakeHandlers;
|
||||
private static UUID key;
|
||||
|
||||
public static boolean setInstance(FloodgateApi floodgateApi, PlayerLink link,
|
||||
PlatformInjector platformInjector, UUID key) {
|
||||
public static boolean setInstance(
|
||||
FloodgateApi floodgateApi,
|
||||
PlayerLink link,
|
||||
PlatformInjector platformInjector,
|
||||
HandshakeHandlers handshakeHandlers,
|
||||
UUID key
|
||||
) {
|
||||
if (instance == null) {
|
||||
InstanceHolder.key = key;
|
||||
} else if (!InstanceHolder.key.equals(key)) {
|
||||
@@ -46,6 +53,7 @@ public final class InstanceHolder {
|
||||
instance = floodgateApi;
|
||||
playerLink = link;
|
||||
injector = platformInjector;
|
||||
InstanceHolder.handshakeHandlers = handshakeHandlers;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.api.handshake;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.geysermc.floodgate.util.BedrockData;
|
||||
import org.geysermc.floodgate.util.LinkedPlayer;
|
||||
import org.geysermc.floodgate.util.RawSkin;
|
||||
|
||||
/**
|
||||
* For advanced users only! You shouldn't play with this unless you know what you're doing.<br>
|
||||
* <br>
|
||||
* This class allows you change specific things of a Bedrock player before it is applied to the
|
||||
* server. Note that at the time I'm writing this that the HandshakeData is created after requesting
|
||||
* the player link. So the link is present here, if applicable.
|
||||
*/
|
||||
public interface HandshakeData {
|
||||
/**
|
||||
* Returns the Channel holding the connection between the client and the server.
|
||||
*/
|
||||
Channel getChannel();
|
||||
|
||||
/**
|
||||
* Returns true if the given player is a Floodgate player, false otherwise.
|
||||
*/
|
||||
boolean isFloodgatePlayer();
|
||||
|
||||
/**
|
||||
* Returns the decrypted BedrockData sent by Geyser or null if the player isn't a Floodgate
|
||||
* player.
|
||||
*/
|
||||
BedrockData getBedrockData();
|
||||
|
||||
/**
|
||||
* Returns the linked account associated with the client or null if the player isn't linked or
|
||||
* not a Floodgate player.
|
||||
*/
|
||||
LinkedPlayer getLinkedPlayer();
|
||||
|
||||
/**
|
||||
* Set the LinkedPlayer. This will be ignored if the player isn't a Floodgate player
|
||||
*
|
||||
* @param player the player to use as link
|
||||
*/
|
||||
void setLinkedPlayer(LinkedPlayer player);
|
||||
|
||||
/**
|
||||
* Returns the skin of the client. Can be null even though the player is a Floodgate player.
|
||||
*/
|
||||
RawSkin getRawSkin();
|
||||
|
||||
/**
|
||||
* Manually set the skin of the client.
|
||||
*
|
||||
* @param rawSkin the skin of the client
|
||||
*/
|
||||
void setRawSkin(RawSkin rawSkin);
|
||||
|
||||
/**
|
||||
* Returns the hostname used in the handshake packet. This is the hostname after Floodgate
|
||||
* removed the data.
|
||||
*/
|
||||
String getHostname();
|
||||
|
||||
/**
|
||||
* Set the hostname of the handshake packet. Changing it here will also change it in the
|
||||
* handshake packet.
|
||||
*
|
||||
* @param hostname the new hostname
|
||||
*/
|
||||
void setHostname(String hostname);
|
||||
|
||||
/**
|
||||
* Returns the reason to disconnect the current player.
|
||||
*/
|
||||
String getDisconnectReason();
|
||||
|
||||
/**
|
||||
* Set the reason to disconnect the current player.
|
||||
*
|
||||
* @param reason the reason to disconnect
|
||||
*/
|
||||
void setDisconnectReason(String reason);
|
||||
|
||||
/**
|
||||
* Returns if the player should be disconnected
|
||||
*/
|
||||
default boolean shouldDisconnect() {
|
||||
return getDisconnectReason() != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.api.handshake;
|
||||
|
||||
/**
|
||||
* This class allows you to change and/or get specific data of the Bedrock client before Floodgate
|
||||
* does something with this data. This means that Floodgate decrypts the data, then calls the
|
||||
* handshake handlers and then applies the data to the connection.<br>
|
||||
* <br>
|
||||
* /!\ Note that this class will be called for both Java and Bedrock connections, but {@link
|
||||
* HandshakeData#isFloodgatePlayer()} will be false and Floodgate related methods will return null
|
||||
* for Java players
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface HandshakeHandler {
|
||||
/**
|
||||
* Method that will be called during the time that Floodgate handles the handshake.
|
||||
*
|
||||
* @param data the data usable during the handshake
|
||||
*/
|
||||
void handle(HandshakeData data);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.api.handshake;
|
||||
|
||||
public interface HandshakeHandlers {
|
||||
/**
|
||||
* Register a custom handshake handler. This can be used to check and edit the player during the
|
||||
* handshake handling.
|
||||
*
|
||||
* @param handshakeHandler the handshake handler to register
|
||||
* @return a random (unique) int to identify this handshake handler or -1 if null
|
||||
*/
|
||||
int addHandshakeHandler(HandshakeHandler handshakeHandler);
|
||||
|
||||
/**
|
||||
* Removes a custom handshake handler by id.
|
||||
*
|
||||
* @param handshakeHandlerId the id of the handshake handler to remove
|
||||
*/
|
||||
void removeHandshakeHandler(int handshakeHandlerId);
|
||||
|
||||
/**
|
||||
* Remove a custom handshake handler by instance.
|
||||
*
|
||||
* @param handshakeHandler the instance to remove
|
||||
*/
|
||||
void removeHandshakeHandler(Class<? extends HandshakeHandler> handshakeHandler);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public interface PlatformInjector {
|
||||
*
|
||||
* @param addon the class of the addon to remove from the addon list
|
||||
* @param <T> the addon type
|
||||
* @return the instance that was present when removing
|
||||
* @return the removed addon instance
|
||||
*/
|
||||
<T extends InjectorAddon> T removeAddon(Class<T> addon);
|
||||
}
|
||||
|
||||
@@ -89,4 +89,9 @@ public interface FloodgateLogger {
|
||||
* this method, but they will be hidden from the console.
|
||||
*/
|
||||
void disableDebug();
|
||||
|
||||
/**
|
||||
* Returns if debugging is enabled
|
||||
*/
|
||||
boolean isDebug();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user