Implement ban functionality

- Added ban module
- Added Ban and Unban commands, supporting banning and unbanning players through various command parameters.
- Added timestamp formatting method in Utils utility class for displaying ban expiration times
- Introduced PlayerErrorCode enum defining various error codes including ErrBan
- Added dual ban checking for both IP and user during player login
- Optimized login failure responses to provide specific error reasons and parameters
This commit is contained in:
HongchengQ
2025-12-10 16:33:41 -08:00
committed by Melledy
parent 6483e8a5a7
commit 3a6387c2bd
11 changed files with 750 additions and 9 deletions
@@ -1,12 +1,15 @@
package emu.nebula.server.handlers;
import emu.nebula.Nebula;
import emu.nebula.game.player.Player;
import emu.nebula.game.player.PlayerErrorCode;
import emu.nebula.net.GameSession;
import emu.nebula.net.HandlerId;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.PlayerLogin.LoginReq;
import emu.nebula.proto.PlayerLogin.LoginResp;
import emu.nebula.net.HandlerId;
import emu.nebula.Nebula;
import emu.nebula.net.GameSession;
import emu.nebula.proto.Public.Error;
@HandlerId(NetMsgId.player_login_req)
public class HandlerPlayerLoginReq extends NetHandler {
@@ -20,20 +23,35 @@ public class HandlerPlayerLoginReq extends NetHandler {
// Parse request
var req = LoginReq.parseFrom(message);
// os
// OS
String loginToken = req.getOfficialOverseas().getToken();
if (loginToken == null || loginToken.isEmpty()) {
// cn
if (loginToken.isEmpty()) {
// CN
loginToken = req.getOfficial().getToken();
}
var banModule = Nebula.getGameContext().getBanModule();
// Check IP ban
if (banModule.isIpBanned(session.getIpAddress())) {
var banInfo = banModule.getIpBanInfo(session.getIpAddress());
return session.encodeMsg(NetMsgId.player_login_failed_ack, banInfo.toProto());
}
// Login
boolean result = session.login(loginToken);
if (!result) {
return session.encodeMsg(NetMsgId.player_login_failed_ack);
Error errorCause = Error.newInstance().setCode(PlayerErrorCode.ErrLogin.getValue());
return session.encodeMsg(NetMsgId.player_login_failed_ack, errorCause);
}
// Check player ban
int playerUid = session.getPlayer().getUid();
if (banModule.isPlayerBanned(playerUid)) {
var banInfo = banModule.getPlayerBanInfo(playerUid);
return session.encodeMsg(NetMsgId.player_login_failed_ack, banInfo.toProto());
}
// Regenerate session token because we are switching encrpytion method
@@ -1,5 +1,6 @@
package emu.nebula.server.handlers;
import emu.nebula.game.player.PlayerErrorCode;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.PlayerSignatureEdit.PlayerSignatureEditReq;
@@ -27,7 +28,9 @@ public class HandlerPlayerSignatureEdit extends NetHandler {
return session.encodeMsg(
NetMsgId.player_signature_edit_failed_ack,
Error.newInstance().setCode(119902).addArguments("\nCommand Result: " + result.getMessage())
Error.newInstance()
.setCode(PlayerErrorCode.ErrConfig.getValue())
.addArguments("\nCommand Result: " + result.getMessage())
);
}