mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-30 20:16:41 +00:00
Revamped TFM_BanManager, TFM_Ban and TFM_ServerInterface
Better ban type checking Moved ban reason compilation to TFM_Ban TFM_ServerInterface: Less expensive operations first Command_rollback now polls TFM_RollbackManager for available players
This commit is contained in:
@ -18,7 +18,6 @@ public class TFM_ServerInterface
|
||||
{
|
||||
public static final String COMPILE_NMS_VERSION = "v1_7_R3";
|
||||
public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$");
|
||||
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
|
||||
|
||||
public static void setOnlineMode(boolean mode)
|
||||
{
|
||||
@ -66,13 +65,12 @@ public class TFM_ServerInterface
|
||||
public static void handlePlayerLogin(PlayerLoginEvent event)
|
||||
{
|
||||
final Server server = TotalFreedomMod.server;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
final String username = player.getName();
|
||||
final UUID uuid = TFM_Util.getUniqueId(username);
|
||||
final String ip = event.getAddress().getHostAddress().trim();
|
||||
|
||||
// Perform username checks
|
||||
if (username.length() < 3 || username.length() > 20)
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER, "Your username is an invalid length (must be between 3 and 20 characters long).");
|
||||
@ -81,11 +79,12 @@ public class TFM_ServerInterface
|
||||
|
||||
if (!USERNAME_REGEX.matcher(username).find())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters.");
|
||||
event.disallow(Result.KICK_OTHER, "Your username contains invalid characters.");
|
||||
return;
|
||||
}
|
||||
|
||||
// not safe to use TFM_Util.isSuperAdmin for player logging in because player.getAddress() will return a null until after player login.
|
||||
// Check if player is admin
|
||||
// Not safe to use TFM_Util.isSuperAdmin for player logging in because player.getAddress() will return a null until after player login.
|
||||
final boolean isAdmin;
|
||||
if (server.getOnlineMode())
|
||||
{
|
||||
@ -98,119 +97,9 @@ public class TFM_ServerInterface
|
||||
}
|
||||
|
||||
// Validation below this point
|
||||
if (!isAdmin) // If the player is not an admin
|
||||
if (isAdmin) // Player is superadmin
|
||||
{
|
||||
// UUID bans
|
||||
if (TFM_BanManager.isUuidBanned(uuid))
|
||||
{
|
||||
final TFM_Ban ban = TFM_BanManager.getByUuid(uuid);
|
||||
|
||||
String kickMessage = ChatColor.RED + "You are temporarily banned from this server."
|
||||
+ "\nAppeal at " + ChatColor.GOLD + TFM_ConfigEntry.SERVER_BAN_URL.getString();
|
||||
|
||||
if (!ban.getReason().equals("none"))
|
||||
{
|
||||
kickMessage = kickMessage + "\nReason: " + ban.getReason();
|
||||
}
|
||||
|
||||
if (ban.getExpireUnix() != 0)
|
||||
{
|
||||
kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(TFM_Util.getUnixDate(ban.getExpireUnix()));
|
||||
}
|
||||
|
||||
event.disallow(Result.KICK_OTHER, kickMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TFM_BanManager.isIpBanned(ip))
|
||||
{
|
||||
final TFM_Ban ban = TFM_BanManager.getByIp(ip);
|
||||
|
||||
String kickMessage = ChatColor.RED + "Your IP address is temporarily banned from this server."
|
||||
+ "\nAppeal at " + ChatColor.GOLD + TFM_ConfigEntry.SERVER_BAN_URL.getString();
|
||||
|
||||
if (!ban.getReason().equals("none"))
|
||||
{
|
||||
kickMessage = kickMessage + "\nReason: " + ban.getReason();
|
||||
}
|
||||
|
||||
if (ban.getExpireUnix() != 0)
|
||||
{
|
||||
kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(TFM_Util.getUnixDate(ban.getExpireUnix()));
|
||||
}
|
||||
|
||||
event.disallow(Result.KICK_OTHER, kickMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// Permbanned Ips
|
||||
for (String testIp : TFM_PermbanList.getPermbannedIps())
|
||||
{
|
||||
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER,
|
||||
ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at\n"
|
||||
+ ChatColor.GOLD + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Permbanned names
|
||||
for (String testPlayer : TFM_PermbanList.getPermbannedPlayers())
|
||||
{
|
||||
if (testPlayer.equalsIgnoreCase(username))
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER,
|
||||
ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at\n"
|
||||
+ ChatColor.GOLD + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Server full check
|
||||
if (server.getOnlinePlayers().length >= server.getMaxPlayers())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Admin-only mode
|
||||
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is temporarily open to admins only.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Lockdown mode
|
||||
if (TotalFreedomMod.lockdownEnabled)
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is currently in lockdown mode.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Whitelist check
|
||||
if (isWhitelisted())
|
||||
{
|
||||
if (!getWhitelisted().contains(username.toLowerCase()))
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Username already logged in check
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (onlinePlayer.getName().equalsIgnoreCase(username))
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Player is superadmin
|
||||
{
|
||||
// force-allow superadmins to log in
|
||||
// force-allow log in
|
||||
event.allow();
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
@ -241,10 +130,95 @@ public class TFM_ServerInterface
|
||||
|
||||
if (count >= server.getMaxPlayers())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "The server is full and a player could not be kicked, sorry!");
|
||||
event.disallow(Result.KICK_OTHER, "The server is full and a player could not be kicked, sorry!");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Player is not an admin
|
||||
|
||||
// Server full check
|
||||
if (server.getOnlinePlayers().length >= server.getMaxPlayers())
|
||||
{
|
||||
event.disallow(Result.KICK_FULL, "Sorry, but this server is full.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Admin-only mode
|
||||
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER, "Server is temporarily open to admins only.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Lockdown mode
|
||||
if (TotalFreedomMod.lockdownEnabled)
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER, "Server is currently in lockdown mode.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Username already logged in
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (onlinePlayer.getName().equalsIgnoreCase(username))
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER, "Your username is already logged into this server.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Whitelist
|
||||
if (isWhitelisted())
|
||||
{
|
||||
if (!getWhitelisted().contains(username.toLowerCase()))
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER, "You are not whitelisted on this server.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// UUID ban
|
||||
if (TFM_BanManager.isUuidBanned(uuid))
|
||||
{
|
||||
final TFM_Ban ban = TFM_BanManager.getByUuid(uuid);
|
||||
event.disallow(Result.KICK_OTHER, ban.getKickMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// IP ban
|
||||
if (TFM_BanManager.isIpBanned(ip))
|
||||
{
|
||||
final TFM_Ban ban = TFM_BanManager.getByIp(ip);
|
||||
event.disallow(Result.KICK_OTHER, ban.getKickMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// Permbanned IPs
|
||||
for (String testIp : TFM_PermbanList.getPermbannedIps())
|
||||
{
|
||||
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER,
|
||||
ChatColor.RED + "Your IP address is permanently banned from this server.\n"
|
||||
+ "Release procedures are available at\n"
|
||||
+ ChatColor.GOLD + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Permbanned usernames
|
||||
for (String testPlayer : TFM_PermbanList.getPermbannedPlayers())
|
||||
{
|
||||
if (testPlayer.equalsIgnoreCase(username))
|
||||
{
|
||||
event.disallow(Result.KICK_OTHER,
|
||||
ChatColor.RED + "Your username is permanently banned from this server.\n"
|
||||
+ "Release procedures are available at\n"
|
||||
+ ChatColor.GOLD + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user