Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-24 23:30:26 +01:00
Introduce some UUID utilities for eventual auth support.
Dieser Commit ist enthalten in:
Ursprung
d89a4c4807
Commit
8139ac35d9
@ -1,7 +1,5 @@
|
|||||||
package com.velocitypowered.proxy;
|
package com.velocitypowered.proxy;
|
||||||
|
|
||||||
import com.velocitypowered.proxy.connection.VelocityServer;
|
|
||||||
|
|
||||||
public class Velocity {
|
public class Velocity {
|
||||||
public static void main(String... args) throws InterruptedException {
|
public static void main(String... args) throws InterruptedException {
|
||||||
VelocityServer server = new VelocityServer();
|
VelocityServer server = new VelocityServer();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.velocitypowered.proxy.connection;
|
package com.velocitypowered.proxy;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.netty.MinecraftPipelineUtils;
|
import com.velocitypowered.proxy.protocol.netty.MinecraftPipelineUtils;
|
||||||
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
|
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
|
||||||
@ -10,11 +11,16 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
|||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.KeyPairGenerator;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
public class VelocityServer {
|
public class VelocityServer {
|
||||||
private static VelocityServer server;
|
private static VelocityServer server;
|
||||||
|
|
||||||
private EventLoopGroup bossGroup;
|
private EventLoopGroup bossGroup;
|
||||||
private EventLoopGroup childGroup;
|
private EventLoopGroup childGroup;
|
||||||
|
private KeyPair serverKeyPair;
|
||||||
|
|
||||||
public VelocityServer() {
|
public VelocityServer() {
|
||||||
|
|
||||||
@ -25,6 +31,16 @@ public class VelocityServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
// Create a key pair
|
||||||
|
try {
|
||||||
|
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
|
||||||
|
generator.initialize(1024);
|
||||||
|
serverKeyPair = generator.generateKeyPair();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException("Unable to generate server encryption key", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
bossGroup = new NioEventLoopGroup();
|
bossGroup = new NioEventLoopGroup();
|
||||||
childGroup = new NioEventLoopGroup();
|
childGroup = new NioEventLoopGroup();
|
||||||
server = this;
|
server = this;
|
@ -6,7 +6,7 @@ import com.velocitypowered.proxy.connection.MinecraftConnection;
|
|||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import com.velocitypowered.proxy.data.ServerInfo;
|
import com.velocitypowered.proxy.data.ServerInfo;
|
||||||
import com.velocitypowered.proxy.protocol.netty.MinecraftPipelineUtils;
|
import com.velocitypowered.proxy.protocol.netty.MinecraftPipelineUtils;
|
||||||
import com.velocitypowered.proxy.connection.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
|
|
||||||
|
@ -7,13 +7,12 @@ import com.velocitypowered.proxy.protocol.packets.ServerLogin;
|
|||||||
import com.velocitypowered.proxy.protocol.packets.ServerLoginSuccess;
|
import com.velocitypowered.proxy.protocol.packets.ServerLoginSuccess;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
import com.velocitypowered.proxy.connection.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
import com.velocitypowered.proxy.connection.backend.ServerConnection;
|
import com.velocitypowered.proxy.connection.backend.ServerConnection;
|
||||||
import com.velocitypowered.proxy.data.ServerInfo;
|
import com.velocitypowered.proxy.data.ServerInfo;
|
||||||
|
import com.velocitypowered.proxy.util.UuidUtils;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class LoginSessionHandler implements MinecraftSessionHandler {
|
public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||||
private final MinecraftConnection inbound;
|
private final MinecraftConnection inbound;
|
||||||
@ -32,7 +31,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
String username = ((ServerLogin) packet).getUsername();
|
String username = ((ServerLogin) packet).getUsername();
|
||||||
ServerLoginSuccess success = new ServerLoginSuccess();
|
ServerLoginSuccess success = new ServerLoginSuccess();
|
||||||
success.setUsername(username);
|
success.setUsername(username);
|
||||||
success.setUuid(generateOfflinePlayerUuid(username));
|
success.setUuid(UuidUtils.generateOfflinePlayerUuid(username));
|
||||||
inbound.write(success);
|
inbound.write(success);
|
||||||
|
|
||||||
// Initiate a regular connection and move over to it.
|
// Initiate a regular connection and move over to it.
|
||||||
@ -45,7 +44,4 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
connection.connect();
|
connection.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UUID generateOfflinePlayerUuid(String username) {
|
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
26
src/main/java/com/velocitypowered/proxy/util/UuidUtils.java
Normale Datei
26
src/main/java/com/velocitypowered/proxy/util/UuidUtils.java
Normale Datei
@ -0,0 +1,26 @@
|
|||||||
|
package com.velocitypowered.proxy.util;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public enum UuidUtils {
|
||||||
|
;
|
||||||
|
|
||||||
|
public static UUID fromMojang(String id) {
|
||||||
|
Preconditions.checkNotNull(id, "id");
|
||||||
|
Preconditions.checkArgument(id.length() == 32, "Length is incorrect");
|
||||||
|
return UUID.fromString(
|
||||||
|
id.substring(0, 8) + "-" +
|
||||||
|
id.substring(8, 12) + "-" +
|
||||||
|
id.substring(12, 16) + "-" +
|
||||||
|
id.substring(16, 20) + "-" +
|
||||||
|
id.substring(20, 32)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID generateOfflinePlayerUuid(String username) {
|
||||||
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
}
|
26
src/test/java/com/velocitypowered/proxy/util/UuidUtilsTest.java
Normale Datei
26
src/test/java/com/velocitypowered/proxy/util/UuidUtilsTest.java
Normale Datei
@ -0,0 +1,26 @@
|
|||||||
|
package com.velocitypowered.proxy.util;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class UuidUtilsTest {
|
||||||
|
private static final UUID VALID_UUID = UUID.fromString("6b501978-d3be-4f33-bcf6-6e7808f37a0d");
|
||||||
|
private static final String VALID_MOJANG_UUID = "6b501978d3be4f33bcf66e7808f37a0d";
|
||||||
|
|
||||||
|
private static final UUID TEST_OFFLINE_PLAYER_UUID = UUID.fromString("708f6260-183d-3912-bbde-5e279a5e739a");
|
||||||
|
private static final String TEST_OFFLINE_PLAYER = "tuxed";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromMojang() {
|
||||||
|
Assert.assertEquals("UUIDs do not match", VALID_UUID, UuidUtils.fromMojang(VALID_MOJANG_UUID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateOfflinePlayerUuid() {
|
||||||
|
Assert.assertEquals("UUIDs do not match", TEST_OFFLINE_PLAYER_UUID, UuidUtils.generateOfflinePlayerUuid(TEST_OFFLINE_PLAYER));
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren