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-09 22:21:57 +08:00
committed by Melledy
parent 6483e8a5a7
commit 3a6387c2bd
11 changed files with 750 additions and 9 deletions

View File

@@ -4,13 +4,17 @@ import java.io.File;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.time.Instant;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Base64;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import emu.nebula.GameConstants;
import it.unimi.dsi.fastutil.ints.IntList;
public class Utils {
@@ -321,4 +325,16 @@ public class Utils {
var month = YearMonth.of(date.getYear(), date.getMonthValue());
return month.lengthOfMonth();
}
public static String formatTimestamp(long timestamp) {
return Instant.ofEpochMilli(timestamp)
.atZone(GameConstants.UTC_ZONE)
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
public static String formatTimestamp(long timestamp, String pattern) {
return Instant.ofEpochMilli(timestamp)
.atZone(GameConstants.UTC_ZONE)
.format(DateTimeFormatter.ofPattern(pattern));
}
}