Replace PacketOpcodes references with strings (#130)

Replace
session.send(new BasePacket(PacketOpcodes.Packet));
with
session.send(new BasePacket(session.getPackageIdProvider().getPacketId("Packet")));
This commit is contained in:
Nazrin 2024-08-03 00:36:08 -07:00 committed by GitHub
parent 41308312c5
commit 9a0bdc5c79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 12 additions and 13 deletions

View File

@ -245,8 +245,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
player.onLogout();
}
try {
val disconnectPacketId = getPackageIdProvider().getPacketId("ServerDisconnectClientNotify");
send(new BasePacket(disconnectPacketId));
send(new BasePacket(getPackageIdProvider().getPacketId("ServerDisconnectClientNotify")));
} catch (Throwable ignore) {
Grasscutter.getLogger().warn("closing {} error", getAddress().getAddress().getHostAddress());
}

View File

@ -11,7 +11,7 @@ public class HandlerPlayerForceExitReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
// Client should auto disconnect right now
session.send(new BasePacket(PacketOpcodes.PlayerForceExitRsp));
session.send(new BasePacket(session.getPackageIdProvider().getPacketId("PlayerForceExitRsp")));
new Thread(){
@Override
public void run() {

View File

@ -31,7 +31,7 @@ public class HandlerPlayerLoginReq extends TypedPacketHandler<PlayerLoginReq> {
if (player.getAvatars().getAvatarCount() == 0) {
// Pick character
session.setState(SessionState.PICKING_CHARACTER);
session.send(new BasePacket(PacketOpcodes.DoSetPlayerBornDataNotify));
session.send(new BasePacket(session.getPackageIdProvider().getPacketId("DoSetPlayerBornDataNotify")));
} else {
// Login done
session.getPlayer().onLogin();

View File

@ -14,6 +14,6 @@ public class HandlerPlayerQuitDungeonReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
val req = PlayerQuitDungeonReq.parseFrom(payload);
session.getPlayer().getServer().getDungeonSystem().exitDungeon(session.getPlayer(), req.getIsQuitImmediately());
session.getPlayer().sendPacket(new BasePacket(PacketOpcodes.PlayerQuitDungeonRsp));
session.getPlayer().sendPacket(new BasePacket(session.getPackageIdProvider().getPacketId("PlayerQuitDungeonRsp")));
}
}

View File

@ -43,7 +43,7 @@ public class HandlerQuickUseWidgetReq extends PacketHandler {
}
proto.setMaterialId(materialId);
inventory.removeItem(item,1);// decrease count
BasePacket rsp = new BasePacket(PacketOpcodes.QuickUseWidgetRsp);
BasePacket rsp = new BasePacket(session.getPackageIdProvider().getPacketId("QuickUseWidgetRsp"));
rsp.setData(proto);
session.send(rsp);
Grasscutter.getLogger().warn("class has no effects in the game, feel free to implement it");

View File

@ -24,7 +24,7 @@ public class HandlerSceneInitFinishReq extends TypedPacketHandler<SceneInitFinis
session.send(new PacketWorldDataNotify(session.getPlayer().getWorld()));
session.send(new PacketWorldOwnerBlossomBriefInfoNotify(session.getPlayer().getWorld()));
session.send(new PacketPlayerWorldSceneInfoListNotify(session.getPlayer()));
session.send(new BasePacket(PacketOpcodes.SceneForceUnlockNotify));
session.send(new BasePacket(session.getPackageIdProvider().getPacketId("SceneForceUnlockNotify")));
session.send(new PacketHostPlayerNotify(session.getPlayer().getWorld()));
session.send(new PacketSceneDataNotify(session.getPlayer()));
session.send(new PacketSceneTimeNotify(session.getPlayer()));

View File

@ -20,7 +20,7 @@ public class HandlerSetEntityClientDataNotify extends PacketHandler {
// Make sure packet is a valid proto before replaying it to the other players
SetEntityClientDataNotify notif = SetEntityClientDataNotify.parseFrom(payload);
BasePacket packet = new BasePacket(PacketOpcodes.SetEntityClientDataNotify, true);
BasePacket packet = new BasePacket(session.getPackageIdProvider().getPacketId("SetEntityClientDataNotify"), true);
packet.setData(notif);
session.getPlayer().getScene().broadcastPacket(packet);

View File

@ -64,7 +64,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
session.getPlayer().onPlayerBorn();
// Born resp packet
session.send(new BasePacket(PacketOpcodes.SetPlayerBornDataRsp));
session.send(new BasePacket(session.getPackageIdProvider().getPacketId("SetPlayerBornDataRsp")));
// Default mail
var welcomeMail = GAME_INFO.joinOptions.welcomeMail;