Merge pull request #1 from kashike/stuff

various things
This commit is contained in:
Andrew Steinborn 2018-07-26 02:01:41 -04:00 committed by GitHub
commit 8f4da04a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 61 additions and 52 deletions

View File

@ -7,17 +7,20 @@ group 'com.velocitypowered'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'io.netty:netty-handler:4.1.27.Final'
compile 'com.google.code.gson:gson:2.8.5'
compile 'com.google.guava:guava:25.1-jre'
compile 'io.netty:netty-codec:4.1.27.Final'
compile 'io.netty:netty-codec-http:4.1.27.Final'
compile 'com.google.guava:guava:25.1-jre'
compile 'com.google.code.gson:gson:2.8.5'
compile 'io.netty:netty-handler:4.1.27.Final'
compile 'net.kyori:text:1.12-1.5.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.0-M1'
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.3.0-M1'
}

View File

@ -1,2 +1 @@
rootProject.name = 'velocity'

View File

@ -5,9 +5,6 @@ public class Velocity {
VelocityServer server = new VelocityServer();
server.initialize();
while (true) {
// temporary until jline is added.
Thread.sleep(999999);
}
Thread.currentThread().join();
}
}

View File

@ -1,6 +1,8 @@
package com.velocitypowered.proxy.protocol;
import com.velocitypowered.proxy.protocol.packets.*;
import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap;
import java.util.HashMap;
import java.util.Map;
@ -49,7 +51,7 @@ public enum StateRegistry {
public static class ProtocolMappings {
private final ProtocolConstants.Direction direction;
private final StateRegistry state;
private final Map<Integer, Supplier<? extends MinecraftPacket>> idsToSuppliers = new HashMap<>();
private final IntObjectMap<Supplier<? extends MinecraftPacket>> idsToSuppliers = new IntObjectHashMap<>();
private final Map<Class<? extends MinecraftPacket>, Integer> packetClassesToIds = new HashMap<>();
public ProtocolMappings(ProtocolConstants.Direction direction, StateRegistry state) {

View File

@ -6,22 +6,32 @@ import io.netty.handler.timeout.ReadTimeoutHandler;
import java.util.concurrent.TimeUnit;
public class MinecraftPipelineUtils {
public static void strapPipelineForProxy(Channel ch) {
ch.pipeline().addLast("read-timeout", new ReadTimeoutHandler(30, TimeUnit.SECONDS));
ch.pipeline().addLast("legacy-ping-decode", new LegacyPingDecoder());
ch.pipeline().addLast("frame-decoder", new MinecraftVarintFrameDecoder());
ch.pipeline().addLast("legacy-ping-encode", LegacyPingEncoder.INSTANCE);
ch.pipeline().addLast("frame-encoder", MinecraftVarintLengthEncoder.INSTANCE);
ch.pipeline().addLast("minecraft-decoder", new MinecraftDecoder(ProtocolConstants.Direction.TO_SERVER));
ch.pipeline().addLast("minecraft-encoder", new MinecraftEncoder(ProtocolConstants.Direction.TO_CLIENT));
public interface MinecraftPipelineUtils {
String FRAME_DECODER = "frame-decoder";
String FRAME_ENCODER = "frame-encoder";
String LEGACY_PING_DECODER = "legacy-ping-decoder";
String LEGACY_PING_ENCODER = "legacy-ping-encoder";
String MINECRAFT_DECODER = "minecraft-decoder";
String MINECRAFT_ENCODER = "minecraft-encoder";
String READ_TIMEOUT = "read-timeout";
static void strapPipelineForProxy(Channel ch) {
ch.pipeline()
.addLast(READ_TIMEOUT, new ReadTimeoutHandler(30, TimeUnit.SECONDS))
.addLast(LEGACY_PING_DECODER, new LegacyPingDecoder())
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
.addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE)
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
.addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolConstants.Direction.TO_SERVER))
.addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolConstants.Direction.TO_CLIENT));
}
public static void strapPipelineForBackend(Channel ch) {
ch.pipeline().addLast("read-timeout", new ReadTimeoutHandler(30, TimeUnit.SECONDS));
ch.pipeline().addLast("frame-decoder", new MinecraftVarintFrameDecoder());
ch.pipeline().addLast("frame-encoder", MinecraftVarintLengthEncoder.INSTANCE);
ch.pipeline().addLast("minecraft-decoder", new MinecraftDecoder(ProtocolConstants.Direction.TO_CLIENT));
ch.pipeline().addLast("minecraft-encoder", new MinecraftEncoder(ProtocolConstants.Direction.TO_SERVER));
static void strapPipelineForBackend(Channel ch) {
ch.pipeline()
.addLast(READ_TIMEOUT, new ReadTimeoutHandler(30, TimeUnit.SECONDS))
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
.addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolConstants.Direction.TO_CLIENT))
.addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolConstants.Direction.TO_SERVER));
}
}

View File

@ -3,20 +3,18 @@ package com.velocitypowered.proxy.util;
import com.google.common.base.Preconditions;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
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 fromUndashed(final String string) {
Objects.requireNonNull(string, "string");
Preconditions.checkArgument(string.length() == 32, "Length is incorrect");
return new UUID(
Long.parseUnsignedLong(string.substring(0, 16), 16),
Long.parseUnsignedLong(string.substring(16), 16)
);
}

View File

@ -1,19 +1,20 @@
package com.velocitypowered.proxy.util;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
public class EncryptionUtilsTest {
import static org.junit.jupiter.api.Assertions.assertEquals;
class EncryptionUtilsTest {
@Test
public void twoComplementsSha1Digest() throws Exception {
void twoComplementsSha1Digest() throws Exception {
String notchHash = hexDigest("Notch");
Assert.assertEquals("4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48", notchHash);
assertEquals("4ed1f46bbe04bc756bcb17c0c7ce3e4632f06a48", notchHash);
String jebHash = hexDigest("jeb_");
Assert.assertEquals("-7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1", jebHash);
assertEquals("-7c9d5b0044c130109a5d7b5fb5c317c02b4e28c1", jebHash);
}
private String hexDigest(String str) throws Exception {
@ -22,4 +23,4 @@ public class EncryptionUtilsTest {
byte[] digested = digest.digest();
return EncryptionUtils.twoComplementsSha1Digest(digested);
}
}
}

View File

@ -1,26 +1,25 @@
package com.velocitypowered.proxy.util;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class UuidUtilsTest {
private static final UUID VALID_UUID = UUID.fromString("6b501978-d3be-4f33-bcf6-6e7808f37a0d");
private static final String VALID_MOJANG_UUID = "6b501978d3be4f33bcf66e7808f37a0d";
class UuidUtilsTest {
private static final UUID EXPECTED_DASHED_UUID = UUID.fromString("6b501978-d3be-4f33-bcf6-6e7808f37a0d");
private static final String ACTUAL_UNDASHED_UUID = EXPECTED_DASHED_UUID.toString().replace("-", "");
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));
void testFromUndashed() {
assertEquals(EXPECTED_DASHED_UUID, UuidUtils.fromUndashed(ACTUAL_UNDASHED_UUID), "UUIDs do not match");
}
@Test
public void generateOfflinePlayerUuid() {
Assert.assertEquals("UUIDs do not match", TEST_OFFLINE_PLAYER_UUID, UuidUtils.generateOfflinePlayerUuid(TEST_OFFLINE_PLAYER));
void generateOfflinePlayerUuid() {
assertEquals(TEST_OFFLINE_PLAYER_UUID, UuidUtils.generateOfflinePlayerUuid(TEST_OFFLINE_PLAYER), "UUIDs do not match");
}
}
}