mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-17 18:13:22 +08:00
Merge pull request #2341
* enableRandomEncryptSeed * update config version * Merge branch 'Grasscutters:development' into random-seed * make the codes more beautiful * move KahnsSort to algorithms * rename variables * Merge branch 'development' into random-seed
This commit is contained in:
committed by
GitHub
Unverified
parent
b8f7aea168
commit
fb0c2dbc84
@@ -23,6 +23,9 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
@Getter @Setter private Account account;
|
||||
@Getter private Player player;
|
||||
|
||||
@Getter private long encryptSeed = Crypto.ENCRYPT_SEED;
|
||||
private byte[] encryptKey = Crypto.ENCRYPT_KEY;
|
||||
|
||||
@Setter private boolean useSecretKey;
|
||||
@Getter @Setter private SessionState state;
|
||||
|
||||
@@ -34,6 +37,11 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
this.server = server;
|
||||
this.state = SessionState.WAITING_FOR_TOKEN;
|
||||
this.lastPingTime = System.currentTimeMillis();
|
||||
|
||||
if (GAME_INFO.useUniquePacketKey) {
|
||||
this.encryptKey = new byte[4096];
|
||||
this.encryptSeed = Crypto.generateEncryptKeyAndSeed(this.encryptKey);
|
||||
}
|
||||
}
|
||||
|
||||
public GameServer getServer() {
|
||||
@@ -133,7 +141,12 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
event.call();
|
||||
if (!event.isCanceled()) { // If event is not cancelled, continue.
|
||||
try {
|
||||
tunnel.writeData(event.getPacket().build());
|
||||
packet = event.getPacket();
|
||||
var bytes = packet.build();
|
||||
if (packet.shouldEncrypt) {
|
||||
Crypto.xor(bytes, packet.useDispatchKey() ? Crypto.DISPATCH_KEY : this.encryptKey);
|
||||
}
|
||||
tunnel.writeData(bytes);
|
||||
} catch (Exception ignored) {
|
||||
Grasscutter.getLogger().debug("Unable to send packet to client.");
|
||||
}
|
||||
@@ -149,7 +162,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
@Override
|
||||
public void handleReceive(byte[] bytes) {
|
||||
// Decrypt and turn back into a packet
|
||||
Crypto.xor(bytes, useSecretKey() ? Crypto.ENCRYPT_KEY : Crypto.DISPATCH_KEY);
|
||||
Crypto.xor(bytes, useSecretKey() ? this.encryptKey : Crypto.DISPATCH_KEY);
|
||||
ByteBuf packet = Unpooled.wrappedBuffer(bytes);
|
||||
|
||||
// Log
|
||||
|
||||
Reference in New Issue
Block a user