mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-10 12:42:52 +08:00
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:
parent
0b9cab5ad5
commit
a520bc9416
@ -4,6 +4,7 @@ import static emu.grasscutter.config.Configuration.*;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import emu.grasscutter.game.Account;
|
||||||
import emu.grasscutter.server.event.game.ReceivePacketEvent;
|
import emu.grasscutter.server.event.game.ReceivePacketEvent;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
@ -68,6 +69,9 @@ public class GameServerPacketHandler {
|
|||||||
if (state != SessionState.WAITING_FOR_TOKEN) {
|
if (state != SessionState.WAITING_FOR_TOKEN) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (state == SessionState.ACCOUNT_BANNED) {
|
||||||
|
session.close();
|
||||||
|
return;
|
||||||
} else if (opcode == PacketOpcodes.PlayerLoginReq) {
|
} else if (opcode == PacketOpcodes.PlayerLoginReq) {
|
||||||
if (state != SessionState.WAITING_FOR_LOGIN) {
|
if (state != SessionState.WAITING_FOR_LOGIN) {
|
||||||
return;
|
return;
|
||||||
@ -83,7 +87,8 @@ public class GameServerPacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invoke event.
|
// 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.
|
if (!event.isCanceled()) // If event is not canceled, continue.
|
||||||
handler.handle(session, header, event.getPacketData());
|
handler.handle(session, header, event.getPacketData());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -100,6 +100,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
|||||||
Grasscutter.getLogger().info(sendOrRecv + ": " + PacketOpcodesUtils.getOpcodeName(opcode) + " (" + opcode + ")");
|
Grasscutter.getLogger().info(sendOrRecv + ": " + PacketOpcodesUtils.getOpcodeName(opcode) + " (" + opcode + ")");
|
||||||
System.out.println(Utils.bytesToHex(payload));
|
System.out.println(Utils.bytesToHex(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(BasePacket packet) {
|
public void send(BasePacket packet) {
|
||||||
// Test
|
// Test
|
||||||
if (packet.getOpcode() <= 0) {
|
if (packet.getOpcode() <= 0) {
|
||||||
@ -135,11 +136,13 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
|||||||
logPacket("SEND", packet.getOpcode(), packet.getData());
|
logPacket("SEND", packet.getOpcode(), packet.getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default -> {}
|
default -> {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke event.
|
// 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.
|
if (!event.isCanceled()) { // If event is not cancelled, continue.
|
||||||
tunnel.writeData(event.getPacket().build());
|
tunnel.writeData(event.getPacket().build());
|
||||||
}
|
}
|
||||||
@ -211,7 +214,8 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
|||||||
logPacket("RECV", opcode, payload);
|
logPacket("RECV", opcode, payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default -> {}
|
default -> {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle
|
// Handle
|
||||||
@ -257,6 +261,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
|||||||
WAITING_FOR_TOKEN,
|
WAITING_FOR_TOKEN,
|
||||||
WAITING_FOR_LOGIN,
|
WAITING_FOR_LOGIN,
|
||||||
PICKING_CHARACTER,
|
PICKING_CHARACTER,
|
||||||
ACTIVE
|
ACTIVE,
|
||||||
|
ACCOUNT_BANNED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,8 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call creation event.
|
// Call creation event.
|
||||||
PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call();
|
PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class);
|
||||||
|
event.call();
|
||||||
|
|
||||||
// Get player.
|
// Get player.
|
||||||
Player player = DatabaseHelper.getPlayerByAccount(account, event.getPlayerClass());
|
Player player = DatabaseHelper.getPlayerByAccount(account, event.getPlayerClass());
|
||||||
@ -87,8 +88,8 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
|
|||||||
|
|
||||||
// Checks if the player is banned
|
// Checks if the player is banned
|
||||||
if (session.getAccount().isBanned()) {
|
if (session.getAccount().isBanned()) {
|
||||||
|
session.setState(SessionState.ACCOUNT_BANNED);
|
||||||
session.send(new PacketGetPlayerTokenRsp(session, 21, "FORBID_CHEATING_PLUGINS", session.getAccount().getBanEndTime()));
|
session.send(new PacketGetPlayerTokenRsp(session, 21, "FORBID_CHEATING_PLUGINS", session.getAccount().getBanEndTime()));
|
||||||
session.close();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,8 +133,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
|
|||||||
|
|
||||||
session.send(new PacketGetPlayerTokenRsp(session, base64str, "bm90aGluZyBoZXJl"));
|
session.send(new PacketGetPlayerTokenRsp(session, base64str, "bm90aGluZyBoZXJl"));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Send packet
|
// Send packet
|
||||||
session.send(new PacketGetPlayerTokenRsp(session));
|
session.send(new PacketGetPlayerTokenRsp(session));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user