Merge branch 'entity-meta' into render

This commit is contained in:
Bixilon 2020-11-21 17:13:46 +01:00
commit c065c01361
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 19 additions and 21 deletions

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.config; package de.bixilon.minosoft.config;
import com.google.common.base.StandardSystemProperty;
import de.bixilon.minosoft.util.OSUtil; import de.bixilon.minosoft.util.OSUtil;
import java.io.File; import java.io.File;
@ -29,7 +30,7 @@ public class StaticConfiguration {
static { static {
// Sets Config.homeDir to the correct folder per OS // Sets Config.homeDir to the correct folder per OS
String homeDir; String homeDir;
homeDir = System.getProperty("user.home"); homeDir = System.getProperty(StandardSystemProperty.USER_HOME.key());
if (!homeDir.endsWith(File.separator)) { if (!homeDir.endsWith(File.separator)) {
homeDir += "/"; homeDir += "/";
} }

View File

@ -42,7 +42,7 @@ public class PacketPlayerPositionAndRotationSending implements ServerboundPacket
public PacketPlayerPositionAndRotationSending(double x, double feetY, double z, float yaw, float pitch, boolean onGround) { public PacketPlayerPositionAndRotationSending(double x, double feetY, double z, float yaw, float pitch, boolean onGround) {
this.x = x; this.x = x;
this.feetY = feetY; this.feetY = feetY;
this.headY = feetY - 1.62F; this.headY = feetY + 1.62F;
this.z = z; this.z = z;
this.yaw = yaw; this.yaw = yaw;
this.pitch = pitch; this.pitch = pitch;

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.protocol.protocol;
import javax.crypto.*; import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.security.*; import java.security.*;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
@ -29,8 +29,8 @@ public class CryptManager {
return key.generateKey(); return key.generateKey();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e);
} }
return null;
} }
public static KeyPair createNewKeyPair() { public static KeyPair createNewKeyPair() {
@ -40,17 +40,11 @@ public class CryptManager {
return keyPair.generateKeyPair(); return keyPair.generateKeyPair();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e);
} }
return null;
} }
public static byte[] getServerHash(String serverId, PublicKey publicKey, SecretKey secretKey) { public static byte[] getServerHash(String serverId, PublicKey publicKey, SecretKey secretKey) {
try { return digestOperation(serverId.getBytes(StandardCharsets.ISO_8859_1), secretKey.getEncoded(), publicKey.getEncoded());
return digestOperation(serverId.getBytes("ISO_8859_1"), secretKey.getEncoded(), publicKey.getEncoded());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
} }
static byte[] digestOperation(byte[]... bytes) { static byte[] digestOperation(byte[]... bytes) {
@ -62,8 +56,8 @@ public class CryptManager {
return disgest.digest(); return disgest.digest();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e);
} }
return null;
} }
public static PublicKey decodePublicKey(byte[] key) { public static PublicKey decodePublicKey(byte[] key) {
@ -73,32 +67,32 @@ public class CryptManager {
return keyFactory.generatePublic(keySpec); return keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) { } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e);
} }
return null;
} }
public static byte[] encryptData(Key key, byte[] data) { public static byte[] encryptData(Key key, byte[] data) {
return cipherOperation(1, key, data); return cipherOperation(1, key, data);
} }
static byte[] cipherOperation(int p_75885_0_, Key key, byte[] data) { static byte[] cipherOperation(int opMode, Key key, byte[] data) {
try { try {
return createTheCipherInstance(p_75885_0_, key.getAlgorithm(), key).doFinal(data); return createTheCipherInstance(opMode, key.getAlgorithm(), key).doFinal(data);
} catch (IllegalBlockSizeException | BadPaddingException e) { } catch (IllegalBlockSizeException | BadPaddingException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e);
} }
return null;
} }
static Cipher createTheCipherInstance(int p_75886_0_, String transformation, Key key) { static Cipher createTheCipherInstance(int opMode, String transformation, Key key) {
try { try {
Cipher cipher = Cipher.getInstance(transformation); Cipher cipher = Cipher.getInstance(transformation);
cipher.init(p_75886_0_, key); cipher.init(opMode, key);
return cipher; return cipher;
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) { } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e);
} }
return null;
} }
public static Cipher createNetCipherInstance(int opMode, Key key) { public static Cipher createNetCipherInstance(int opMode, Key key) {

View File

@ -65,7 +65,10 @@ public class PacketHandler {
// now we know the version, set it, if the config allows it // now we know the version, set it, if the config allows it
Version version; Version version;
int protocolId = connection.getDesiredVersionNumber(); int protocolId = -1;
if (connection.getDesiredVersionNumber() != -1) {
protocolId = Versions.getVersionById(connection.getDesiredVersionNumber()).getProtocolId();
}
if (protocolId == -1) { if (protocolId == -1) {
protocolId = pkg.getResponse().getProtocolId(); protocolId = pkg.getResponse().getProtocolId();
} }