3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Fixed even more Checkstyle issues, this time in the proxy components.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-10-28 01:02:54 -04:00
Ursprung 6467335f74
Commit 8a9d1b1ac9
34 geänderte Dateien mit 221 neuen und 142 gelöschten Zeilen

Datei anzeigen

@ -94,7 +94,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
if (PluginMessageUtil.isMCBrand(packet)) { if (PluginMessageUtil.isMCBrand(packet)) {
serverConn.getPlayer().getConnection().write(PluginMessageUtil.rewriteMCBrand(packet)); serverConn.getPlayer().getConnection().write(PluginMessageUtil.rewriteMinecraftBrand(packet));
return true; return true;
} }

Datei anzeigen

@ -103,11 +103,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
private String createBungeeForwardingAddress() { private String createBungeeForwardingAddress() {
// BungeeCord IP forwarding is simply a special injection after the "address" in the handshake, // BungeeCord IP forwarding is simply a special injection after the "address" in the handshake,
// separated by \0 (the null byte). In order, you send the original host, the player's IP, their // separated by \0 (the null byte). In order, you send the original host, the player's IP, their
// UUID (undashed), and if you are in online-mode, their login properties (retrieved from Mojang). // UUID (undashed), and if you are in online-mode, their login properties (from Mojang).
return registeredServer.getServerInfo().getAddress().getHostString() + "\0" + return registeredServer.getServerInfo().getAddress().getHostString() + "\0"
proxyPlayer.getRemoteAddress().getHostString() + "\0" + + proxyPlayer.getRemoteAddress().getHostString() + "\0"
proxyPlayer.getProfile().getId() + "\0" + + proxyPlayer.getProfile().getId() + "\0"
GSON.toJson(proxyPlayer.getProfile().getProperties()); + GSON.toJson(proxyPlayer.getProfile().getProperties());
} }
private void startHandshake() { private void startHandshake() {

Datei anzeigen

@ -182,7 +182,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
clientPluginMsgChannels.removeAll(channels); clientPluginMsgChannels.removeAll(channels);
backendConn.write(packet); backendConn.write(packet);
} else if (PluginMessageUtil.isMCBrand(packet)) { } else if (PluginMessageUtil.isMCBrand(packet)) {
backendConn.write(PluginMessageUtil.rewriteMCBrand(packet)); backendConn.write(PluginMessageUtil.rewriteMinecraftBrand(packet));
} else if (backendConn.isLegacyForge() && !serverConn.hasCompletedJoin()) { } else if (backendConn.isLegacyForge() && !serverConn.hasCompletedJoin()) {
if (packet.getChannel().equals(ForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) { if (packet.getChannel().equals(ForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
if (!player.getModInfo().isPresent()) { if (!player.getModInfo().isPresent()) {
@ -195,9 +195,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Always forward the FML handshake to the remote server. // Always forward the FML handshake to the remote server.
backendConn.write(packet); backendConn.write(packet);
} else { } else {
// The client is trying to send messages too early. This is primarily caused by mods, but it's further // The client is trying to send messages too early. This is primarily caused by mods, but
// aggravated by Velocity. To work around these issues, we will queue any non-FML handshake messages to // it's further aggravated by Velocity. To work around these issues, we will queue any
// be sent once the JoinGame packet has been received by the proxy. // non-FML handshake messages to be sent once the JoinGame packet has been received by the
// proxy.
loginPluginMessages.add(packet); loginPluginMessages.add(packet);
} }
} else { } else {
@ -287,12 +288,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
spawned = true; spawned = true;
player.getConnection().delayedWrite(joinGame); player.getConnection().delayedWrite(joinGame);
// We have something special to do for legacy Forge servers - during first connection the FML handshake // We have something special to do for legacy Forge servers - during first connection the FML
// will transition to complete regardless. Thus, we need to ensure that a reset packet is ALWAYS sent on // handshake will transition to complete regardless. Thus, we need to ensure that a reset
// first switch. // packet is ALWAYS sent on first switch.
// //
// As we know that calling this branch only happens on first join, we set that if we are a Forge // As we know that calling this branch only happens on first join, we set that if we are a
// client that we must reset on the next switch. // Forge client that we must reset on the next switch.
// //
// The call will handle if the player is not a Forge player appropriately. // The call will handle if the player is not a Forge player appropriately.
player.getConnection().setCanSendLegacyFMLResetPacket(true); player.getConnection().setCanSendLegacyFMLResetPacket(true);
@ -306,11 +307,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// - A respawn packet with a different dimension // - A respawn packet with a different dimension
// - Another respawn with the correct dimension // - Another respawn with the correct dimension
// //
// The two respawns with different dimensions are required, otherwise the client gets confused. // The two respawns with different dimensions are required, otherwise the client gets
// confused.
// //
// Most notably, by having the client accept the join game packet, we can work around the need to perform // Most notably, by having the client accept the join game packet, we can work around the need
// entity ID rewrites, eliminating potential issues from rewriting packets and improving compatibility with // to perform entity ID rewrites, eliminating potential issues from rewriting packets and
// mods. // improving compatibility with mods.
player.getConnection().delayedWrite(joinGame); player.getConnection().delayedWrite(joinGame);
int tempDim = joinGame.getDimension() == 0 ? -1 : 0; int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
player.getConnection().delayedWrite( player.getConnection().delayedWrite(
@ -360,12 +362,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// We only need to indicate we can send a reset packet if we complete a handshake, that is, // We only need to indicate we can send a reset packet if we complete a handshake, that is,
// logged onto a Forge server. // logged onto a Forge server.
// //
// The special case is if we log onto a Vanilla server as our first server, FML will treat this // The special case is if we log onto a Vanilla server as our first server, FML will treat
// as complete and **will** need a reset packet sending at some point. We will handle this // this as complete and **will** need a reset packet sending at some point. We will handle
// during initial player connection if the player is detected to be forge. // this during initial player connection if the player is detected to be forge.
// //
// This is why we use an if statement rather than the result of VelocityServerConnection#isLegacyForge() // We do not use the result of VelocityServerConnection#isLegacyForge() directly because we
// because we don't want to set it false if this is a first connection to a Vanilla server. // don't want to set it false if this is a first connection to a Vanilla server.
// //
// See LoginSessionHandler#handle for where the counterpart to this method is // See LoginSessionHandler#handle for where the counterpart to this method is
player.getConnection().setCanSendLegacyFMLResetPacket(true); player.getConnection().setCanSendLegacyFMLResetPacket(true);

Datei anzeigen

@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -174,8 +175,8 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
} }
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error while trying to handle a query packet from {}", msg.sender(), e); logger.warn("Error while trying to handle a query packet from {}", msg.sender(), e);
// NB: Only need to explicitly release upon exception, writing the response out will decrement the reference // NB: Only need to explicitly release upon exception, writing the response out will decrement
// count. // the reference count.
responsePacket.release(); responsePacket.release();
} }
} }
@ -265,9 +266,8 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
while (iterator.hasNext()) { while (iterator.hasNext()) {
QueryResponse.PluginInformation info = iterator.next(); QueryResponse.PluginInformation info = iterator.next();
pluginsString.append(info.getName()); pluginsString.append(info.getName());
if (info.getVersion() != null) { Optional<String> version = info.getVersion();
pluginsString.append(' ').append(info.getVersion()); version.ifPresent(s -> pluginsString.append(' ').append(s));
}
if (iterator.hasNext()) { if (iterator.hasNext()) {
pluginsString.append(';').append(' '); pluginsString.append(';').append(' ');
} }

Datei anzeigen

@ -85,15 +85,15 @@ public class BossBar implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "BossBar{" + return "BossBar{"
"uuid=" + uuid + + "uuid=" + uuid
", action=" + action + + ", action=" + action
", name='" + name + '\'' + + ", name='" + name + '\''
", percent=" + percent + + ", percent=" + percent
", color=" + color + + ", color=" + color
", overlay=" + overlay + + ", overlay=" + overlay
", flags=" + flags + + ", flags=" + flags
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -47,10 +47,10 @@ public class Chat implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "Chat{" + return "Chat{"
"message='" + message + '\'' + + "message='" + message + '\''
", type=" + type + + ", type=" + type
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -34,9 +34,9 @@ public class Disconnect implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "Disconnect{" + return "Disconnect{"
"reason='" + reason + '\'' + + "reason='" + reason + '\''
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -33,10 +33,10 @@ public class EncryptionRequest implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "EncryptionRequest{" + return "EncryptionRequest{"
"publicKey=" + Arrays.toString(publicKey) + + "publicKey=" + Arrays.toString(publicKey)
", verifyToken=" + Arrays.toString(verifyToken) + + ", verifyToken=" + Arrays.toString(verifyToken)
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -32,10 +32,10 @@ public class EncryptionResponse implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "EncryptionResponse{" + return "EncryptionResponse{"
"sharedSecret=" + Arrays.toString(sharedSecret) + + "sharedSecret=" + Arrays.toString(sharedSecret)
", verifyToken=" + Arrays.toString(verifyToken) + + ", verifyToken=" + Arrays.toString(verifyToken)
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -47,12 +47,12 @@ public class Handshake implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "Handshake{" + return "Handshake{"
"protocolVersion=" + protocolVersion + + "protocolVersion=" + protocolVersion
", serverAddress='" + serverAddress + '\'' + + ", serverAddress='" + serverAddress + '\''
", port=" + port + + ", port=" + port
", nextStatus=" + nextStatus + + ", nextStatus=" + nextStatus
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -78,15 +78,15 @@ public class JoinGame implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "JoinGame{" + return "JoinGame{"
"entityId=" + entityId + + "entityId=" + entityId
", gamemode=" + gamemode + + ", gamemode=" + gamemode
", dimension=" + dimension + + ", dimension=" + dimension
", difficulty=" + difficulty + + ", difficulty=" + difficulty
", maxPlayers=" + maxPlayers + + ", maxPlayers=" + maxPlayers
", levelType='" + levelType + '\'' + + ", levelType='" + levelType + '\''
", reducedDebugInfo=" + reducedDebugInfo + + ", reducedDebugInfo=" + reducedDebugInfo
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -22,9 +22,9 @@ public class KeepAlive implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "KeepAlive{" + return "KeepAlive{"
"randomId=" + randomId + + "randomId=" + randomId
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -7,10 +7,15 @@ public class LegacyDisconnect {
private final String reason; private final String reason;
public LegacyDisconnect(String reason) { private LegacyDisconnect(String reason) {
this.reason = reason; this.reason = reason;
} }
/**
* Converts a legacy response into a disconnect packet.
* @param response the response to convert
* @return the disconnect packet
*/
public static LegacyDisconnect fromPingResponse(LegacyPingResponse response) { public static LegacyDisconnect fromPingResponse(LegacyPingResponse response) {
String kickMessage = String.join("\0", String kickMessage = String.join("\0",
"§1", "§1",

Datei anzeigen

@ -45,15 +45,20 @@ public class LegacyPingResponse {
@Override @Override
public String toString() { public String toString() {
return "LegacyPingResponse{" + return "LegacyPingResponse{"
"protocolVersion=" + protocolVersion + + "protocolVersion=" + protocolVersion
", serverVersion='" + serverVersion + '\'' + + ", serverVersion='" + serverVersion + '\''
", motd='" + motd + '\'' + + ", motd='" + motd + '\''
", playersOnline=" + playersOnline + + ", playersOnline=" + playersOnline
", playersMax=" + playersMax + + ", playersMax=" + playersMax
'}'; + '}';
} }
/**
* Transforms a {@link ServerPing} into a legacy ping response.
* @param ping the response to transform
* @return the legacy ping response
*/
public static LegacyPingResponse from(ServerPing ping) { public static LegacyPingResponse from(ServerPing ping) {
return new LegacyPingResponse(ping.getVersion().getProtocol(), return new LegacyPingResponse(ping.getVersion().getProtocol(),
ping.getVersion().getName(), ping.getVersion().getName(),

Datei anzeigen

@ -41,11 +41,11 @@ public class LoginPluginMessage implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "LoginPluginMessage{" + return "LoginPluginMessage{"
"id=" + id + + "id=" + id
", channel='" + channel + '\'' + + ", channel='" + channel + '\''
", data=" + data + + ", data=" + data
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -39,11 +39,11 @@ public class LoginPluginResponse implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "LoginPluginResponse{" + return "LoginPluginResponse{"
"id=" + id + + "id=" + id
", success=" + success + + ", success=" + success
", data=" + data + + ", data=" + data
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -36,10 +36,10 @@ public class PluginMessage implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "PluginMessage{" + return "PluginMessage{"
"channel='" + channel + '\'' + + "channel='" + channel + '\''
", data=" + ByteBufUtil.hexDump(data) + + ", data=" + ByteBufUtil.hexDump(data)
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -57,12 +57,12 @@ public class Respawn implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "Respawn{" + return "Respawn{"
"dimension=" + dimension + + "dimension=" + dimension
", difficulty=" + difficulty + + ", difficulty=" + difficulty
", gamemode=" + gamemode + + ", gamemode=" + gamemode
", levelType='" + levelType + '\'' + + ", levelType='" + levelType + '\''
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -28,9 +28,9 @@ public class ServerLogin implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "ServerLogin{" + return "ServerLogin{"
"username='" + username + '\'' + + "username='" + username + '\''
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -37,10 +37,10 @@ public class ServerLoginSuccess implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "ServerLoginSuccess{" + return "ServerLoginSuccess{"
"uuid=" + uuid + + "uuid=" + uuid
", username='" + username + '\'' + + ", username='" + username + '\''
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -27,9 +27,9 @@ public class SetCompression implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "SetCompression{" + return "SetCompression{"
"threshold=" + threshold + + "threshold=" + threshold
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -27,9 +27,9 @@ public class StatusResponse implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "StatusResponse{" + return "StatusResponse{"
"status='" + status + '\'' + + "status='" + status + '\''
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -53,12 +53,12 @@ public class TabCompleteRequest implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "TabCompleteRequest{" + return "TabCompleteRequest{"
"command='" + command + '\'' + + "command='" + command + '\''
", assumeCommand=" + assumeCommand + + ", assumeCommand=" + assumeCommand
", hasPosition=" + hasPosition + + ", hasPosition=" + hasPosition
", position=" + position + + ", position=" + position
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -18,9 +18,9 @@ public class TabCompleteResponse implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "TabCompleteResponse{" + return "TabCompleteResponse{"
"offers=" + offers + + "offers=" + offers
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -141,13 +141,13 @@ public class TitlePacket implements MinecraftPacket {
@Override @Override
public String toString() { public String toString() {
return "TitlePacket{" + return "TitlePacket{"
"action=" + action + + "action=" + action
", component='" + component + '\'' + + ", component='" + component + '\''
", fadeIn=" + fadeIn + + ", fadeIn=" + fadeIn
", stay=" + stay + + ", stay=" + stay
", fadeOut=" + fadeOut + + ", fadeOut=" + fadeOut
'}'; + '}';
} }
@Override @Override

Datei anzeigen

@ -13,12 +13,12 @@ import java.util.List;
public class PluginMessageUtil { public class PluginMessageUtil {
public static final String BRAND_CHANNEL_LEGACY = "MC|Brand"; private static final String BRAND_CHANNEL_LEGACY = "MC|Brand";
public static final String BRAND_CHANNEL = "minecraft:brand"; private static final String BRAND_CHANNEL = "minecraft:brand";
public static final String REGISTER_CHANNEL_LEGACY = "REGISTER"; private static final String REGISTER_CHANNEL_LEGACY = "REGISTER";
public static final String REGISTER_CHANNEL = "minecraft:register"; private static final String REGISTER_CHANNEL = "minecraft:register";
public static final String UNREGISTER_CHANNEL_LEGACY = "UNREGISTER"; private static final String UNREGISTER_CHANNEL_LEGACY = "UNREGISTER";
public static final String UNREGISTER_CHANNEL = "minecraft:unregister"; private static final String UNREGISTER_CHANNEL = "minecraft:unregister";
private PluginMessageUtil() { private PluginMessageUtil() {
throw new AssertionError(); throw new AssertionError();
@ -62,7 +62,7 @@ public class PluginMessageUtil {
return message; return message;
} }
public static PluginMessage rewriteMCBrand(PluginMessage message) { public static PluginMessage rewriteMinecraftBrand(PluginMessage message) {
Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(message, "message");
Preconditions.checkArgument(isMCBrand(message), "message is not a MC Brand plugin message"); Preconditions.checkArgument(isMCBrand(message), "message is not a MC Brand plugin message");

Datei anzeigen

@ -1,4 +1,4 @@
package com.velocitypowered.proxy.server.ping; package com.velocitypowered.proxy.server;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
@ -20,7 +20,7 @@ public class PingSessionHandler implements MinecraftSessionHandler {
private final MinecraftConnection connection; private final MinecraftConnection connection;
private boolean completed = false; private boolean completed = false;
public PingSessionHandler(CompletableFuture<ServerPing> result, RegisteredServer server, PingSessionHandler(CompletableFuture<ServerPing> result, RegisteredServer server,
MinecraftConnection connection) { MinecraftConnection connection) {
this.result = result; this.result = result;
this.server = server; this.server = server;

Datei anzeigen

@ -21,6 +21,12 @@ public class ServerMap {
this.server = server; this.server = server;
} }
/**
* Returns the server associated with the given name.
*
* @param name the name to look up
* @return the server, if it exists
*/
public Optional<RegisteredServer> getServer(String name) { public Optional<RegisteredServer> getServer(String name) {
Preconditions.checkNotNull(name, "server"); Preconditions.checkNotNull(name, "server");
String lowerName = name.toLowerCase(Locale.US); String lowerName = name.toLowerCase(Locale.US);
@ -31,6 +37,12 @@ public class ServerMap {
return ImmutableList.copyOf(servers.values()); return ImmutableList.copyOf(servers.values());
} }
/**
* Registers a server with the proxy.
*
* @param serverInfo the server to register
* @return the registered server
*/
public RegisteredServer register(ServerInfo serverInfo) { public RegisteredServer register(ServerInfo serverInfo) {
Preconditions.checkNotNull(serverInfo, "serverInfo"); Preconditions.checkNotNull(serverInfo, "serverInfo");
String lowerName = serverInfo.getName().toLowerCase(Locale.US); String lowerName = serverInfo.getName().toLowerCase(Locale.US);
@ -47,6 +59,11 @@ public class ServerMap {
} }
} }
/**
* Unregisters the specified server from the proxy.
*
* @param serverInfo the server to unregister
*/
public void unregister(ServerInfo serverInfo) { public void unregister(ServerInfo serverInfo) {
Preconditions.checkNotNull(serverInfo, "serverInfo"); Preconditions.checkNotNull(serverInfo, "serverInfo");
String lowerName = serverInfo.getName().toLowerCase(Locale.US); String lowerName = serverInfo.getName().toLowerCase(Locale.US);

Datei anzeigen

@ -24,7 +24,6 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder;
import com.velocitypowered.proxy.server.ping.PingSessionHandler;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;

Datei anzeigen

@ -4,9 +4,17 @@ import com.google.common.base.Preconditions;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
public enum AddressUtil { public class AddressUtil {
; private AddressUtil() {
throw new AssertionError();
}
/**
* Attempts to parse an IP address of the form <code>127.0.0.1:25565</code>.
*
* @param ip the IP to parse
* @return the parsed address
*/
public static InetSocketAddress parseAddress(String ip) { public static InetSocketAddress parseAddress(String ip) {
Preconditions.checkNotNull(ip, "ip"); Preconditions.checkNotNull(ip, "ip");
URI uri = URI.create("tcp://" + ip); URI uri = URI.create("tcp://" + ip);

Datei anzeigen

@ -12,6 +12,12 @@ import javax.crypto.Cipher;
public enum EncryptionUtils { public enum EncryptionUtils {
; ;
/**
* Generates an RSA key pair.
*
* @param keysize the key size (in bits) for the RSA key pair
* @return the generated key pair
*/
public static KeyPair createRsaKeyPair(final int keysize) { public static KeyPair createRsaKeyPair(final int keysize) {
try { try {
final KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); final KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
@ -22,16 +28,37 @@ public enum EncryptionUtils {
} }
} }
/**
* Generates a hex digest in two's complement form for use with the Mojang joinedServer endpoint.
*
* @param digest the bytes to digest
* @return the hex digest
*/
public static String twosComplementHexdigest(byte[] digest) { public static String twosComplementHexdigest(byte[] digest) {
return new BigInteger(digest).toString(16); return new BigInteger(digest).toString(16);
} }
/**
* Decrypts an RSA message.
*
* @param keyPair the key pair to use
* @param bytes the bytes of the encrypted message
* @return the decrypted message
* @throws GeneralSecurityException if the message couldn't be decoded
*/
public static byte[] decryptRsa(KeyPair keyPair, byte[] bytes) throws GeneralSecurityException { public static byte[] decryptRsa(KeyPair keyPair, byte[] bytes) throws GeneralSecurityException {
Cipher cipher = Cipher.getInstance("RSA"); Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate()); cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate());
return cipher.doFinal(bytes); return cipher.doFinal(bytes);
} }
/**
* Generates the server ID for the hasJoined endpoint.
*
* @param sharedSecret the shared secret between the client and the proxy
* @param key the RSA public key
* @return the server ID
*/
public static String generateServerId(byte[] sharedSecret, PublicKey key) { public static String generateServerId(byte[] sharedSecret, PublicKey key) {
try { try {
MessageDigest digest = MessageDigest.getInstance("SHA-1"); MessageDigest digest = MessageDigest.getInstance("SHA-1");

Datei anzeigen

@ -8,6 +8,9 @@ import java.net.InetAddress;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/**
* A simple rate-limiter based on a Guava {@link Cache}.
*/
public class Ratelimiter { public class Ratelimiter {
private final Cache<InetAddress, Long> expiringCache; private final Cache<InetAddress, Long> expiringCache;
@ -32,6 +35,12 @@ public class Ratelimiter {
} }
} }
/**
* Attempts to rate-limit the client.
*
* @param address the address to rate limit
* @return true if we should allow the client, false if we should rate-limit
*/
public boolean attempt(InetAddress address) { public boolean attempt(InetAddress address) {
if (timeoutNanos == 0) { if (timeoutNanos == 0) {
return true; return true;

Datei anzeigen

@ -1,7 +1,9 @@
package com.velocitypowered.proxy.util; package com.velocitypowered.proxy.util;
public enum ThrowableUtils { public class ThrowableUtils {
; private ThrowableUtils() {
throw new AssertionError();
}
public static String briefDescription(Throwable throwable) { public static String briefDescription(Throwable throwable) {
return throwable.getClass().getSimpleName() + ": " + throwable.getMessage(); return throwable.getClass().getSimpleName() + ": " + throwable.getMessage();

Datei anzeigen

@ -46,6 +46,11 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
return ImmutableList.copyOf(identifierMap.keySet()); return ImmutableList.copyOf(identifierMap.keySet());
} }
/**
* Returns all channel IDs (as strings) for use with Minecraft 1.13 and above.
*
* @return the channel IDs for Minecraft 1.13 and above
*/
public Collection<String> getModernChannelIds() { public Collection<String> getModernChannelIds() {
Collection<String> ids = new ArrayList<>(); Collection<String> ids = new ArrayList<>();
for (ChannelIdentifier value : identifierMap.values()) { for (ChannelIdentifier value : identifierMap.values()) {