From c3339de1843d75794552bb533df81bb14cdf57f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8E=E3=82=A8=E3=83=AB=E3=81=AE=E7=8A=AC?= <90658478+xlpmyxhdr@users.noreply.github.com> Date: Sat, 17 Jun 2023 02:27:14 +0800 Subject: [PATCH] Resume the app token exchanger (#2209) --- .../emu/grasscutter/server/game/GameSession.java | 3 +-- .../server/http/dispatch/RegionHandler.java | 14 ++++++++------ .../packet/send/PacketGetPlayerTokenRsp.java | 3 --- .../server/packet/send/PacketPlayerLoginRsp.java | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/emu/grasscutter/server/game/GameSession.java b/src/main/java/emu/grasscutter/server/game/GameSession.java index e21e0fb48..0cff31cd1 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSession.java +++ b/src/main/java/emu/grasscutter/server/game/GameSession.java @@ -149,8 +149,7 @@ public class GameSession implements GameSessionManager.KcpChannel { @Override public void handleReceive(byte[] bytes) { // Decrypt and turn back into a packet - if (this.getState() != SessionState.WAITING_FOR_TOKEN) - Crypto.xor(bytes, useSecretKey() ? Crypto.ENCRYPT_KEY : Crypto.DISPATCH_KEY); + Crypto.xor(bytes, useSecretKey() ? Crypto.ENCRYPT_KEY : Crypto.DISPATCH_KEY); ByteBuf packet = Unpooled.wrappedBuffer(bytes); // Log diff --git a/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java b/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java index 0993d8da5..6da4a141c 100644 --- a/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java +++ b/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java @@ -92,13 +92,15 @@ public final class RegionHandler implements Router { // Create a region info object. var regionInfo = - RegionInfo.newBuilder() - .setGateserverIp(region.Ip) - .setGateserverPort(region.Port) - .setSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) - .build(); + RegionInfo.newBuilder() + .setGateserverIp(region.Ip) + .setGateserverPort(region.Port) + .build(); // Create an updated region query. - var updatedQuery = QueryCurrRegionHttpRsp.newBuilder().setRegionInfo(regionInfo).build(); + var updatedQuery = QueryCurrRegionHttpRsp.newBuilder() + .setRegionInfo(regionInfo) + .setClientSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) + .build(); regions.put( region.Name, new RegionData( diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java index a85ef04d7..2f681d75c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java @@ -13,7 +13,6 @@ public class PacketGetPlayerTokenRsp extends BasePacket { super(PacketOpcodes.GetPlayerTokenRsp, true); this.setUseDispatchKey(true); - this.shouldEncrypt = false; GetPlayerTokenRsp p = GetPlayerTokenRsp.newBuilder() @@ -39,7 +38,6 @@ public class PacketGetPlayerTokenRsp extends BasePacket { super(PacketOpcodes.GetPlayerTokenRsp, true); this.setUseDispatchKey(true); - this.shouldEncrypt = false; GetPlayerTokenRsp p = GetPlayerTokenRsp.newBuilder() @@ -61,7 +59,6 @@ public class PacketGetPlayerTokenRsp extends BasePacket { super(PacketOpcodes.GetPlayerTokenRsp, true); this.setUseDispatchKey(true); - this.shouldEncrypt = false; GetPlayerTokenRsp p = GetPlayerTokenRsp.newBuilder() diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java index ad326aee8..83e101f7e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java @@ -35,12 +35,12 @@ public class PacketPlayerLoginRsp extends BasePacket { RegionInfo.newBuilder() .setGateserverIp(lr(GAME_INFO.accessAddress, GAME_INFO.bindAddress)) .setGateserverPort(lr(GAME_INFO.accessPort, GAME_INFO.bindPort)) - .setSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) .build(); - regionCache = + var regionCache = QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp.newBuilder() .setRegionInfo(serverRegion) + .setClientSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) .build(); } catch (Exception e) { Grasscutter.getLogger().error("Error while initializing region cache!", e);