mirror of
https://github.com/Anime-Game-Servers/Grasscutter-Quests.git
synced 2024-11-23 04:29:42 +00:00
[Proto] replaced some hardcoded PacketOpcodesopcode comparisons with string comparisons using multiproto for now
This commit is contained in:
parent
b075ad5a81
commit
67599e89af
@ -95,8 +95,8 @@ public class ConfigContainer {
|
||||
}
|
||||
|
||||
public static class Server {
|
||||
public Set<Integer> debugWhitelist = Set.of();
|
||||
public Set<Integer> debugBlacklist = Set.of();
|
||||
public Set<String> debugWhitelist = Set.of();
|
||||
public Set<String> debugBlacklist = Set.of();
|
||||
public ServerRunMode runMode = ServerRunMode.HYBRID;
|
||||
public boolean logCommands = false;
|
||||
|
||||
|
@ -20,24 +20,24 @@ import messages.VERSION;
|
||||
public class PacketOpcodesUtils {
|
||||
private static Int2ObjectMap<String> opcodeMap;
|
||||
|
||||
public static final Set<Integer> BANNED_PACKETS = Set.of(
|
||||
PacketOpcodes.WindSeedClientNotify,
|
||||
PacketOpcodes.PlayerLuaShellNotify
|
||||
public static final Set<String> BANNED_PACKETS = Set.of(
|
||||
"WindSeedClientNotify",
|
||||
"PlayerLuaShellNotify"
|
||||
);
|
||||
|
||||
public static final Set<Integer> LOOP_PACKETS = Set.of(
|
||||
PacketOpcodes.PingReq,
|
||||
PacketOpcodes.PingRsp,
|
||||
PacketOpcodes.WorldPlayerRTTNotify,
|
||||
PacketOpcodes.UnionCmdNotify,
|
||||
PacketOpcodes.QueryPathReq,
|
||||
PacketOpcodes.QueryPathRsp,
|
||||
public static final Set<String> LOOP_PACKETS = Set.of(
|
||||
"PingReq",
|
||||
"PingRsp",
|
||||
"WorldPlayerRTTNotify",
|
||||
"UnionCmdNotify",
|
||||
"QueryPathReq",
|
||||
"QueryPathRsp",
|
||||
|
||||
// Satiation sends these every tick
|
||||
PacketOpcodes.PlayerTimeNotify,
|
||||
PacketOpcodes.PlayerGameTimeNotify,
|
||||
PacketOpcodes.AvatarPropNotify,
|
||||
PacketOpcodes.AvatarSatiationDataNotify
|
||||
"PlayerTimeNotify",
|
||||
"PlayerGameTimeNotify",
|
||||
"AvatarPropNotify",
|
||||
"AvatarSatiationDataNotify"
|
||||
);
|
||||
|
||||
static {
|
||||
|
@ -2,8 +2,6 @@ package emu.grasscutter.server.game;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -14,7 +12,6 @@ import emu.grasscutter.server.event.game.ReceivePacketEvent;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
||||
import emu.grasscutter.server.game.GameSession.SessionState;
|
||||
import interfaces.ProtoModel;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
@ -77,34 +74,34 @@ public class GameServerPacketHandler {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PacketHandler getHandler(GameSession session, int opcode) {
|
||||
String name = session.getPackageIdProvider().getPacketName(opcode);
|
||||
PacketHandler handler = this.versionHandlers.get(name);
|
||||
private PacketHandler getHandler(String packageName, int opcode) {
|
||||
PacketHandler handler = this.versionHandlers.get(packageName);
|
||||
return handler!= null ? handler : this.handlers.get(opcode);
|
||||
}
|
||||
|
||||
public void handle(GameSession session, int opcode, byte[] header, byte[] payload) {
|
||||
PacketHandler handler = getHandler(session, opcode);
|
||||
String packageName = session.getPackageIdProvider().getPacketName(opcode);
|
||||
PacketHandler handler = getHandler(packageName, opcode);
|
||||
|
||||
if (handler != null) {
|
||||
try {
|
||||
// Make sure session is ready for packets
|
||||
SessionState state = session.getState();
|
||||
|
||||
if (opcode == PacketOpcodes.PingReq) {
|
||||
if ("PingReq".equals(packageName)) {
|
||||
// Always continue if packet is ping request
|
||||
} else if (opcode == PacketOpcodes.GetPlayerTokenReq) {
|
||||
} else if ("GetPlayerTokenReq".equals(packageName)) {
|
||||
if (state != SessionState.WAITING_FOR_TOKEN) {
|
||||
return;
|
||||
}
|
||||
} else if (state == SessionState.ACCOUNT_BANNED) {
|
||||
session.close();
|
||||
return;
|
||||
} else if (opcode == PacketOpcodes.PlayerLoginReq) {
|
||||
} else if ("PlayerLoginReq".equals(packageName)) {
|
||||
if (state != SessionState.WAITING_FOR_LOGIN) {
|
||||
return;
|
||||
}
|
||||
} else if (opcode == PacketOpcodes.SetPlayerBornDataReq) {
|
||||
} else if ("SetPlayerBornDataReq".equals(packageName)) {
|
||||
if (state != SessionState.PICKING_CHARACTER) {
|
||||
return;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import emu.grasscutter.Grasscutter.ServerDebugMode;
|
||||
import emu.grasscutter.game.Account;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.packet.PacketOpcodesUtils;
|
||||
import emu.grasscutter.server.event.game.SendPacketEvent;
|
||||
import emu.grasscutter.utils.Crypto;
|
||||
@ -20,6 +19,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.val;
|
||||
import org.anime_game_servers.core.base.Version;
|
||||
import packet_id.PacketIds;
|
||||
|
||||
@ -124,19 +124,20 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
}
|
||||
|
||||
// Log
|
||||
val paketName = PacketOpcodesUtils.getOpcodeName(packet.getOpcode(this), this);
|
||||
switch (GAME_INFO.logPackets) {
|
||||
case ALL -> {
|
||||
if (!PacketOpcodesUtils.LOOP_PACKETS.contains(packet.getOpcode(this)) || GAME_INFO.isShowLoopPackets) {
|
||||
if (!PacketOpcodesUtils.LOOP_PACKETS.contains(paketName) || GAME_INFO.isShowLoopPackets) {
|
||||
logPacket("SEND", packet.getOpcode(this), packet.getData(version));
|
||||
}
|
||||
}
|
||||
case WHITELIST -> {
|
||||
if (SERVER.debugWhitelist.contains(packet.getOpcode(this))) {
|
||||
if (SERVER.debugWhitelist.contains(paketName)) {
|
||||
logPacket("SEND", packet.getOpcode(this), packet.getData(version));
|
||||
}
|
||||
}
|
||||
case BLACKLIST -> {
|
||||
if (!SERVER.debugBlacklist.contains(packet.getOpcode(this))) {
|
||||
if (!SERVER.debugBlacklist.contains(paketName)) {
|
||||
logPacket("SEND", packet.getOpcode(this), packet.getData(version));
|
||||
}
|
||||
}
|
||||
@ -244,7 +245,8 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
player.onLogout();
|
||||
}
|
||||
try {
|
||||
send(new BasePacket(PacketOpcodes.ServerDisconnectClientNotify));
|
||||
val disconnectPacketId = getPackageIdProvider().getPacketId("ServerDisconnectClientNotify");
|
||||
send(new BasePacket(disconnectPacketId));
|
||||
} catch (Throwable ignore) {
|
||||
Grasscutter.getLogger().warn("closing {} error", getAddress().getAddress().getHostAddress());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user