Skip to content

Commit

Permalink
maybe check index before sending the encryption request packet
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Apr 17, 2022
1 parent a642159 commit 6e5e602
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,22 @@ public static PacketSender getAnyPacketSenderOrNull() {

@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
PlayerImpl player = PlayerImpl.of(e.getPlayer());
player.setEncrypted(false);
player.setRemotePublicKeyInternal(null);
int i = player.joins.incrementAndGet();
Bukkit.getScheduler().runTaskLaterAsynchronously(this, () -> {
if (player.joins.get() != i) {
return;
}

KeyPair keyPair;
try {
// generate keypair
keyPair = EncryptionUtil.generateKeyPair(2048);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
PlayerImpl player = PlayerImpl.of(e.getPlayer());

// set keypair
player.setKeyPair(keyPair);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

public class PlayerImpl implements Player, PacketSender {
private static final Map<UUID, PlayerImpl> MAP = new ConcurrentHashMap<>();
Expand All @@ -23,6 +24,7 @@ public class PlayerImpl implements Player, PacketSender {
private PublicKey remotePublicKey;
private boolean encrypted = false;
public String challenge = null;
public AtomicInteger joins = new AtomicInteger();

@Contract(value = "null -> fail", pure = true)
private PlayerImpl(@Nullable org.bukkit.entity.Player handle) {
Expand Down

0 comments on commit 6e5e602

Please sign in to comment.