Fix showing ban message box (#1826)

* fix: getplayertoken ban message popup

* feat: insure no packet handle when banned

* feat: using session state instead of account
This commit is contained in:
Dang Hoang Phuc 2022-10-07 22:07:20 +07:00 committed by GitHub
parent 0b9cab5ad5
commit a520bc9416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 22 deletions

View File

@ -4,6 +4,7 @@ import static emu.grasscutter.config.Configuration.*;
import java.util.Set;
import emu.grasscutter.game.Account;
import emu.grasscutter.server.event.game.ReceivePacketEvent;
import org.reflections.Reflections;
@ -68,6 +69,9 @@ public class GameServerPacketHandler {
if (state != SessionState.WAITING_FOR_TOKEN) {
return;
}
} else if (state == SessionState.ACCOUNT_BANNED) {
session.close();
return;
} else if (opcode == PacketOpcodes.PlayerLoginReq) {
if (state != SessionState.WAITING_FOR_LOGIN) {
return;
@ -83,7 +87,8 @@ public class GameServerPacketHandler {
}
// Invoke event.
ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload); event.call();
ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload);
event.call();
if (!event.isCanceled()) // If event is not canceled, continue.
handler.handle(session, header, event.getPacketData());
} catch (Exception ex) {

View File

@ -50,7 +50,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
public InetSocketAddress getAddress() {
try {
return tunnel.getAddress();
}catch (Throwable ignore) {
} catch (Throwable ignore) {
return null;
}
}
@ -96,10 +96,11 @@ public class GameSession implements GameSessionManager.KcpChannel {
send(basePacket);
}
public void logPacket( String sendOrRecv, int opcode, byte[] payload) {
public void logPacket(String sendOrRecv, int opcode, byte[] payload) {
Grasscutter.getLogger().info(sendOrRecv + ": " + PacketOpcodesUtils.getOpcodeName(opcode) + " (" + opcode + ")");
System.out.println(Utils.bytesToHex(payload));
}
public void send(BasePacket packet) {
// Test
if (packet.getOpcode() <= 0) {
@ -125,21 +126,23 @@ public class GameSession implements GameSessionManager.KcpChannel {
logPacket("SEND", packet.getOpcode(), packet.getData());
}
}
case WHITELIST-> {
case WHITELIST -> {
if (SERVER.debugWhitelist.contains(packet.getOpcode())) {
logPacket("SEND", packet.getOpcode(), packet.getData());
}
}
case BLACKLIST-> {
case BLACKLIST -> {
if (!SERVER.debugBlacklist.contains(packet.getOpcode())) {
logPacket("SEND", packet.getOpcode(), packet.getData());
}
}
default -> {}
default -> {
}
}
// Invoke event.
SendPacketEvent event = new SendPacketEvent(this, packet); event.call();
SendPacketEvent event = new SendPacketEvent(this, packet);
event.call();
if (!event.isCanceled()) { // If event is not cancelled, continue.
tunnel.writeData(event.getPacket().build());
}
@ -172,7 +175,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
int const1 = packet.readShort();
if (const1 != 17767) {
if (allDebug) {
Grasscutter.getLogger().error("Bad Data Package Received: got {} ,expect 17767",const1);
Grasscutter.getLogger().error("Bad Data Package Received: got {} ,expect 17767", const1);
}
return; // Bad packet
}
@ -189,7 +192,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
int const2 = packet.readShort();
if (const2 != -30293) {
if (allDebug) {
Grasscutter.getLogger().error("Bad Data Package Received: got {} ,expect -30293",const2);
Grasscutter.getLogger().error("Bad Data Package Received: got {} ,expect -30293", const2);
}
return; // Bad packet
}
@ -198,20 +201,21 @@ public class GameSession implements GameSessionManager.KcpChannel {
switch (GAME_INFO.logPackets) {
case ALL -> {
if (!PacketOpcodesUtils.LOOP_PACKETS.contains(opcode)) {
logPacket("RECV",opcode, payload);
logPacket("RECV", opcode, payload);
}
}
case WHITELIST-> {
case WHITELIST -> {
if (SERVER.debugWhitelist.contains(opcode)) {
logPacket("RECV",opcode, payload);
logPacket("RECV", opcode, payload);
}
}
case BLACKLIST-> {
case BLACKLIST -> {
if (!(SERVER.debugBlacklist.contains(opcode))) {
logPacket("RECV",opcode, payload);
logPacket("RECV", opcode, payload);
}
}
default -> {}
default -> {
}
}
// Handle
@ -238,8 +242,8 @@ public class GameSession implements GameSessionManager.KcpChannel {
}
try {
send(new BasePacket(PacketOpcodes.ServerDisconnectClientNotify));
}catch (Throwable ignore) {
Grasscutter.getLogger().warn("closing {} error",getAddress().getAddress().getHostAddress());
} catch (Throwable ignore) {
Grasscutter.getLogger().warn("closing {} error", getAddress().getAddress().getHostAddress());
}
tunnel = null;
}
@ -257,6 +261,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
WAITING_FOR_TOKEN,
WAITING_FOR_LOGIN,
PICKING_CHARACTER,
ACTIVE
ACTIVE,
ACCOUNT_BANNED
}
}

View File

@ -67,7 +67,8 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
}
// Call creation event.
PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call();
PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class);
event.call();
// Get player.
Player player = DatabaseHelper.getPlayerByAccount(account, event.getPlayerClass());
@ -87,8 +88,8 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
// Checks if the player is banned
if (session.getAccount().isBanned()) {
session.setState(SessionState.ACCOUNT_BANNED);
session.send(new PacketGetPlayerTokenRsp(session, 21, "FORBID_CHEATING_PLUGINS", session.getAccount().getBanEndTime()));
session.close();
return;
}
@ -132,8 +133,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
session.send(new PacketGetPlayerTokenRsp(session, base64str, "bm90aGluZyBoZXJl"));
}
}
else {
} else {
// Send packet
session.send(new PacketGetPlayerTokenRsp(session));
}