mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-10 13:49:04 +01:00
Minor optimizations to mojang auth.
This commit is contained in:
parent
b80da2f097
commit
37b5484775
@ -1715,7 +1715,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
playerAbilitiesPacket.allowFlying = allowFlying;
|
||||
playerAbilitiesPacket.instantBreak = instantBreak;
|
||||
playerAbilitiesPacket.flyingSpeed = flyingSpeed;
|
||||
playerAbilitiesPacket.walkingSpeed = walkingSpeed;
|
||||
playerAbilitiesPacket.walkingSpeed = 0.1f;
|
||||
|
||||
playerConnection.sendPacket(playerAbilitiesPacket);
|
||||
}
|
||||
|
@ -14,85 +14,79 @@ public class MojangCrypt {
|
||||
|
||||
public static KeyPair generateKeyPair() {
|
||||
try {
|
||||
KeyPairGenerator keyPairGenerator1 = KeyPairGenerator.getInstance("RSA");
|
||||
keyPairGenerator1.initialize(1024);
|
||||
return keyPairGenerator1.generateKeyPair();
|
||||
} catch (NoSuchAlgorithmException var1) {
|
||||
var1.printStackTrace();
|
||||
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
|
||||
keyGen.initialize(1024);
|
||||
return keyGen.generateKeyPair();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Key pair generation failed!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] digestData(String string, PublicKey publicKey, SecretKey secretKey) {
|
||||
public static byte[] digestData(String data, PublicKey publicKey, SecretKey secretKey) {
|
||||
try {
|
||||
return digestData("SHA-1", string.getBytes("ISO_8859_1"), secretKey.getEncoded(), publicKey.getEncoded());
|
||||
} catch (UnsupportedEncodingException var4) {
|
||||
var4.printStackTrace();
|
||||
return digestData("SHA-1", data.getBytes("ISO_8859_1"), secretKey.getEncoded(), publicKey.getEncoded());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] digestData(String string, byte[]... arr) {
|
||||
private static byte[] digestData(String algorithm, byte[]... data) {
|
||||
try {
|
||||
MessageDigest messageDigest3 = MessageDigest.getInstance(string);
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm);
|
||||
|
||||
for(byte[] arr7 : arr) {
|
||||
messageDigest3.update(arr7);
|
||||
for(byte[] bytes : data) {
|
||||
digest.update(bytes);
|
||||
}
|
||||
|
||||
return messageDigest3.digest();
|
||||
} catch (NoSuchAlgorithmException var7) {
|
||||
var7.printStackTrace();
|
||||
return digest.digest();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static SecretKey decryptByteToSecretKey(PrivateKey privateKey, byte[] arr) {
|
||||
return new SecretKeySpec(decryptUsingKey(privateKey, arr), "AES");
|
||||
public static SecretKey decryptByteToSecretKey(PrivateKey privateKey, byte[] bytes) {
|
||||
return new SecretKeySpec(decryptUsingKey(privateKey, bytes), "AES");
|
||||
}
|
||||
|
||||
public static byte[] decryptUsingKey(Key key, byte[] arr) {
|
||||
return cipherData(2, key, arr);
|
||||
public static byte[] decryptUsingKey(Key key, byte[] bytes) {
|
||||
return cipherData(2, key, bytes);
|
||||
}
|
||||
|
||||
private static byte[] cipherData(int integer, Key key, byte[] arr) {
|
||||
private static byte[] cipherData(int mode, Key key, byte[] data) {
|
||||
try {
|
||||
return setupCipher(integer, key.getAlgorithm(), key).doFinal(arr);
|
||||
} catch (IllegalBlockSizeException var4) {
|
||||
return setupCipher(mode, key.getAlgorithm(), key).doFinal(data);
|
||||
} catch (IllegalBlockSizeException | BadPaddingException var4) {
|
||||
var4.printStackTrace();
|
||||
} catch (BadPaddingException var5) {
|
||||
var5.printStackTrace();
|
||||
}
|
||||
|
||||
LOGGER.error("Cipher data failed!");
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Cipher setupCipher(int integer, String string, Key key) {
|
||||
private static Cipher setupCipher(int mode, String transformation, Key key) {
|
||||
try {
|
||||
Cipher cipher4 = Cipher.getInstance(string);
|
||||
cipher4.init(integer, key);
|
||||
Cipher cipher4 = Cipher.getInstance(transformation);
|
||||
cipher4.init(mode, key);
|
||||
return cipher4;
|
||||
} catch (InvalidKeyException var4) {
|
||||
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException var4) {
|
||||
var4.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException var5) {
|
||||
var5.printStackTrace();
|
||||
} catch (NoSuchPaddingException var6) {
|
||||
var6.printStackTrace();
|
||||
}
|
||||
|
||||
LOGGER.error("Cipher creation failed!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Cipher getCipher(int integer, Key key) {
|
||||
public static Cipher getCipher(int mode, Key key) {
|
||||
try {
|
||||
Cipher cipher3 = Cipher.getInstance("AES/CFB8/NoPadding");
|
||||
cipher3.init(integer, key, new IvParameterSpec(key.getEncoded()));
|
||||
cipher3.init(mode, key, new IvParameterSpec(key.getEncoded()));
|
||||
return cipher3;
|
||||
} catch (GeneralSecurityException var3) {
|
||||
throw new RuntimeException(var3);
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
* @param chunk the chunk to send
|
||||
*/
|
||||
public void sendChunkUpdate(Player player, Chunk chunk) {
|
||||
player.getPlayerConnection().sendPacket(chunk.getFullDataPacket());
|
||||
player.getPlayerConnection().sendPacket(chunk.getFullDataPacket(), true);
|
||||
}
|
||||
|
||||
protected void sendChunkUpdate(Collection<Player> players, Chunk chunk) {
|
||||
@ -229,7 +229,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
if (!PlayerUtils.isNettyClient(player))
|
||||
return;
|
||||
|
||||
player.getPlayerConnection().sendPacket(chunkData);
|
||||
player.getPlayerConnection().sendPacket(chunkData, true);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class PacketWriterUtils {
|
||||
for (Player player : players) {
|
||||
PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
if (PlayerUtils.isNettyClient(player)) {
|
||||
playerConnection.writePacket(buffer);
|
||||
playerConnection.writePacket(buffer, true);
|
||||
} else {
|
||||
playerConnection.sendPacket(serverPacket);
|
||||
}
|
||||
@ -46,7 +46,7 @@ public class PacketWriterUtils {
|
||||
batchesPool.execute(() -> {
|
||||
if (PlayerUtils.isNettyClient(playerConnection)) {
|
||||
ByteBuf buffer = PacketUtils.writePacket(serverPacket);
|
||||
playerConnection.writePacket(buffer);
|
||||
playerConnection.writePacket(buffer, false);
|
||||
buffer.release();
|
||||
} else {
|
||||
playerConnection.sendPacket(serverPacket);
|
||||
|
@ -13,12 +13,12 @@ import java.net.SocketAddress;
|
||||
public class FakePlayerConnection extends PlayerConnection {
|
||||
|
||||
@Override
|
||||
public void sendPacket(ByteBuf buffer) {
|
||||
public void sendPacket(ByteBuf buffer, boolean copy) {
|
||||
throw new UnsupportedOperationException("FakePlayer cannot read Bytebuf");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(ByteBuf buffer) {
|
||||
public void writePacket(ByteBuf buffer, boolean copy) {
|
||||
throw new UnsupportedOperationException("FakePlayer cannot read Bytebuf");
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(ByteBuf buffer) {
|
||||
public void sendPacket(ByteBuf buffer, boolean copy) {
|
||||
//System.out.println(getConnectionState() + " out");
|
||||
if (encrypted) {
|
||||
buffer = buffer.copy();
|
||||
@ -49,7 +49,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(ByteBuf buffer) {
|
||||
public void writePacket(ByteBuf buffer, boolean copy) {
|
||||
if (encrypted) {
|
||||
buffer = buffer.copy();
|
||||
buffer.retain();
|
||||
@ -65,7 +65,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
public void sendPacket(ServerPacket serverPacket) {
|
||||
//System.out.println(serverPacket.getClass().getName() + " out");
|
||||
ByteBuf buffer = PacketUtils.writePacket(serverPacket);
|
||||
sendPacket(buffer);
|
||||
sendPacket(buffer, false);
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,19 @@ public abstract class PlayerConnection {
|
||||
this.connectionState = ConnectionState.UNKNOWN;
|
||||
}
|
||||
|
||||
public abstract void sendPacket(ByteBuf buffer);
|
||||
/**
|
||||
*
|
||||
* @param buffer The buffer to send.
|
||||
* @param copy Should be true unless your only using the ByteBuf once.
|
||||
*/
|
||||
public abstract void sendPacket(ByteBuf buffer, boolean copy);
|
||||
|
||||
public abstract void writePacket(ByteBuf buffer);
|
||||
/**
|
||||
*
|
||||
* @param buffer The buffer to send.
|
||||
* @param copy Should be true unless your only using the ByteBuf once.
|
||||
*/
|
||||
public abstract void writePacket(ByteBuf buffer, boolean copy);
|
||||
|
||||
public abstract void sendPacket(ServerPacket serverPacket);
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class Team {
|
||||
}
|
||||
|
||||
this.players.remove(player);
|
||||
player.getPlayerConnection().sendPacket(teamsDestroyPacket); // TODO do not destroy, simply remove the player from the team
|
||||
player.getPlayerConnection().sendPacket(teamsDestroyPacket, true); // TODO do not destroy, simply remove the player from the team
|
||||
|
||||
String[] entitiesCache = new String[entities.length - 1];
|
||||
int count = 0;
|
||||
@ -160,6 +160,6 @@ public class Team {
|
||||
updatePacket.teamPrefix = prefix.toString();
|
||||
updatePacket.teamSuffix = suffix.toString();
|
||||
ByteBuf buffer = PacketUtils.writePacket(updatePacket);
|
||||
players.forEach(p -> p.getPlayerConnection().sendPacket(buffer));
|
||||
players.forEach(p -> p.getPlayerConnection().sendPacket(buffer, true));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user