mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
[Bleeding] Fixed bugs with TFM_PlayerList and TFM_BanManager
This commit is contained in:
parent
c98909df12
commit
7f2e72ee51
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Mon Apr 14 21:11:06 CEST 2014
|
||||
build.number=732
|
||||
#Tue Apr 15 15:42:20 CEST 2014
|
||||
build.number=755
|
||||
|
11
src/bans.yml
11
src/bans.yml
@ -1,8 +1,13 @@
|
||||
#
|
||||
# TotalFreedomMod banning config
|
||||
# Warning: modification of this file is not reccomended
|
||||
#
|
||||
# Format:
|
||||
# Ip: [IP-address / UUID]:[Last login name]:[Expiry unix timestamp (0 = never)][Banned by]:[Reason]
|
||||
#
|
||||
|
||||
# Format: [IP-address]:[Last login name]:[Expiry unix timestamp (0 = never)][Banned by]:[Reason]
|
||||
ips:
|
||||
- '192.168.1.254:LocalHost:DarthSalamon:0:IP ban example'
|
||||
- '192.168.1.254:Notch:DarthSalamon:0:IP ban example'
|
||||
|
||||
# Format: [UUID]:[Last login name]:[Banned by]:[Expiry unix timestamp (0 = never)]:[Reason]
|
||||
uuids:
|
||||
- '245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:UUID ban example'
|
@ -47,7 +47,13 @@ public class Command_gtfo extends TFM_Command
|
||||
TFM_Util.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
|
||||
|
||||
// Undo WorldEdits:
|
||||
TFM_WorldEditBridge.getInstance().undo(player, 15);
|
||||
try
|
||||
{
|
||||
TFM_WorldEditBridge.getInstance().undo(player, 15);
|
||||
}
|
||||
catch (NoClassDefFoundError ex)
|
||||
{
|
||||
}
|
||||
|
||||
// rollback
|
||||
TFM_RollbackManager.rollback(player.getName());
|
||||
@ -84,7 +90,7 @@ public class Command_gtfo extends TFM_Command
|
||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));
|
||||
|
||||
// ban username:
|
||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), null, reason));
|
||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), null, reason));
|
||||
|
||||
// kick Player:
|
||||
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));
|
||||
|
@ -44,20 +44,7 @@ public class Command_tfbanlist extends TFM_Command
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder banned_players = new StringBuilder();
|
||||
banned_players.append("Banned Players: ");
|
||||
boolean first = true;
|
||||
for (OfflinePlayer player : server.getBannedPlayers())
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
banned_players.append(", ");
|
||||
}
|
||||
first = false;
|
||||
banned_players.append(player.getName().trim());
|
||||
}
|
||||
|
||||
playerMsg(banned_players.toString());
|
||||
playerMsg(TFM_BanManager.getInstance().getUuidBanList().size() + " UUID bans total");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -44,26 +44,7 @@ public class Command_tfipbanlist extends TFM_Command
|
||||
}
|
||||
}
|
||||
|
||||
List<String> ip_bans = Arrays.asList(server.getIPBans().toArray(new String[0]));
|
||||
Collections.sort(ip_bans);
|
||||
|
||||
StringBuilder banned_ips = new StringBuilder();
|
||||
banned_ips.append("Banned IPs: ");
|
||||
boolean first = true;
|
||||
for (String ip : ip_bans)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
banned_ips.append(", ");
|
||||
}
|
||||
if (ip.matches("^\\d{1,3}\\.\\d{1,3}\\.(\\d{1,3}|\\*)\\.(\\d{1,3}|\\*)$"))
|
||||
{
|
||||
first = false;
|
||||
banned_ips.append(ip.trim());
|
||||
}
|
||||
}
|
||||
|
||||
playerMsg(banned_ips.toString());
|
||||
playerMsg(TFM_BanManager.getInstance().getIpBanList().size() + " IPbans total");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -671,7 +671,8 @@ public class TFM_PlayerListener implements Listener
|
||||
{
|
||||
TotalFreedomMod.fuckoffEnabledFor.remove(player);
|
||||
}
|
||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||
|
||||
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||
playerdata.disarmMP44();
|
||||
if (playerdata.isCaged())
|
||||
{
|
||||
@ -689,11 +690,8 @@ public class TFM_PlayerListener implements Listener
|
||||
final String ip = TFM_Util.getIp(player);
|
||||
TFM_Log.info("[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip, true);
|
||||
|
||||
// Update player information
|
||||
if (!TFM_PlayerList.getInstance().existsEntry(player))
|
||||
if (TFM_PlayerList.getInstance().existsEntry(player))
|
||||
{
|
||||
TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
|
||||
|
||||
final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
|
||||
entry.setLastJoinUnix(TFM_Util.getUnixTime());
|
||||
entry.setLastJoinName(player.getName());
|
||||
@ -701,10 +699,7 @@ public class TFM_PlayerListener implements Listener
|
||||
}
|
||||
else
|
||||
{
|
||||
// Preload the entry; the login unix is defaulted to the current time
|
||||
final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
|
||||
entry.addIp(ip);
|
||||
entry.save();
|
||||
TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
|
||||
}
|
||||
|
||||
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||
@ -713,6 +708,16 @@ public class TFM_PlayerListener implements Listener
|
||||
// Verify strict IP match
|
||||
if (TFM_AdminList.isSuperAdmin(player))
|
||||
{
|
||||
if (TFM_BanManager.getInstance().isIpBanned(ip))
|
||||
{
|
||||
TFM_BanManager.getInstance().unbanIp(ip);
|
||||
}
|
||||
|
||||
if (TFM_BanManager.getInstance().isUuidBanned(player.getUniqueId()))
|
||||
{
|
||||
TFM_BanManager.getInstance().unbanUuid(player.getUniqueId());
|
||||
}
|
||||
|
||||
player.setOp(true);
|
||||
|
||||
if (!TFM_AdminList.isIdentityMatched(player))
|
||||
|
@ -14,11 +14,20 @@ public class TFM_Ban
|
||||
static
|
||||
{
|
||||
// 192.168.1.254:LocalHost:DarthSalamon:0:none
|
||||
// 127.0.*.*:TestUserName:BannedByNotch:123567:Test reason
|
||||
IP_BAN_REGEX = Pattern.compile(
|
||||
"^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])):([\\w\\s]+):([\\w]+):(\\d+):([\\w\\s]+)$");
|
||||
"^((?:(?:\\*|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\.){3}(?:\\*|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))"
|
||||
+ ":([\\w\\s]+)"
|
||||
+ ":([\\w]+)"
|
||||
+ ":(\\d+)"
|
||||
+ ":([\\s\\S]+)$");
|
||||
// 245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:Example reason
|
||||
UUID_BAN_REGEX = Pattern.compile(
|
||||
"^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}):([\\w\\s]+):([\\w]+):(\\d+):([\\w\\s]+)$");
|
||||
"^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
|
||||
+ ":([\\w\\s]+)"
|
||||
+ ":([\\w]+)"
|
||||
+ ":(\\d+)"
|
||||
+ ":([\\s\\S]+)$");
|
||||
}
|
||||
private boolean complete;
|
||||
private String subject; // uuid or IP
|
||||
@ -47,8 +56,9 @@ public class TFM_Ban
|
||||
this.subject = subject;
|
||||
this.lastLoginName = (lastLoginName == null ? "none" : lastLoginName);
|
||||
this.by = (sender == null ? "none" : sender);
|
||||
this.expireUnix = TFM_Util.getUnixTime(expire);
|
||||
this.expireUnix = (expire == null ? 0 : TFM_Util.getUnixTime(expire));
|
||||
this.reason = (reason == null ? "none" : reason);
|
||||
complete = true;
|
||||
}
|
||||
|
||||
public TFM_Ban(String banString, boolean ip)
|
||||
@ -75,7 +85,7 @@ public class TFM_Ban
|
||||
lastLoginName = matcher.group(2);
|
||||
by = matcher.group(3);
|
||||
expireUnix = Long.valueOf(matcher.group(4));
|
||||
reason = matcher.group(5);
|
||||
reason = TFM_Util.colorize(matcher.group(5));
|
||||
|
||||
complete = true;
|
||||
}
|
||||
@ -107,7 +117,7 @@ public class TFM_Ban
|
||||
|
||||
public boolean isExpired()
|
||||
{
|
||||
return expireUnix < TFM_Util.getUnixTime();
|
||||
return expireUnix != 0 && expireUnix < TFM_Util.getUnixTime();
|
||||
}
|
||||
|
||||
public boolean isComplete()
|
||||
@ -119,6 +129,6 @@ public class TFM_Ban
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + reason;
|
||||
return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + TFM_Util.decolorize(reason);
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ public class TFM_BanManager
|
||||
|
||||
// Save the config
|
||||
save();
|
||||
|
||||
TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans.");
|
||||
}
|
||||
|
||||
public void save()
|
||||
@ -70,12 +72,18 @@ public class TFM_BanManager
|
||||
|
||||
for (TFM_Ban savedBan : ipBans)
|
||||
{
|
||||
newIpBans.add(savedBan.toString());
|
||||
if (!savedBan.isExpired())
|
||||
{
|
||||
newIpBans.add(savedBan.toString());
|
||||
}
|
||||
}
|
||||
|
||||
for (TFM_Ban savedBan : uuidBans)
|
||||
{
|
||||
newUuidBans.add(savedBan.toString());
|
||||
if (!savedBan.isExpired())
|
||||
{
|
||||
newUuidBans.add(savedBan.toString());
|
||||
}
|
||||
}
|
||||
|
||||
config.set("ips", newIpBans);
|
||||
@ -99,6 +107,28 @@ public class TFM_BanManager
|
||||
{
|
||||
for (TFM_Ban ban : ipBans)
|
||||
{
|
||||
if (ban.isExpired())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
wildcardCheck:
|
||||
if (ban.getSubject().contains("*"))
|
||||
{
|
||||
final String[] subjectParts = ban.getSubject().split("\\.");
|
||||
final String[] ipParts = ip.split("\\.");
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (!(subjectParts[i].equals("*") || subjectParts[i].equals(ipParts[i])))
|
||||
{
|
||||
break wildcardCheck;
|
||||
}
|
||||
}
|
||||
|
||||
return ban;
|
||||
}
|
||||
|
||||
if (ban.getSubject().equals(ip))
|
||||
{
|
||||
return ban;
|
||||
@ -113,6 +143,11 @@ public class TFM_BanManager
|
||||
{
|
||||
if (ban.getSubject().equalsIgnoreCase(uuid.toString()))
|
||||
{
|
||||
if (ban.isExpired())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return ban;
|
||||
}
|
||||
}
|
||||
@ -125,11 +160,11 @@ public class TFM_BanManager
|
||||
|
||||
if (ban == null)
|
||||
{
|
||||
TFM_Log.warning("Could not unban IP: " + ip + ", IP is not banned!");
|
||||
return;
|
||||
}
|
||||
|
||||
removeBan(ban);
|
||||
save();
|
||||
}
|
||||
|
||||
public void unbanUuid(UUID uuid)
|
||||
@ -138,7 +173,6 @@ public class TFM_BanManager
|
||||
|
||||
if (ban == null)
|
||||
{
|
||||
TFM_Log.warning("Could not unban UUID: " + uuid + ", UUID is not banned!");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -159,7 +193,7 @@ public class TFM_BanManager
|
||||
{
|
||||
if (!ban.isComplete())
|
||||
{
|
||||
throw new RuntimeException("Could not load IP ban, Invalid format!");
|
||||
throw new RuntimeException("Could not add UUID ban, Invalid format!");
|
||||
}
|
||||
|
||||
if (ban.isExpired())
|
||||
@ -168,13 +202,14 @@ public class TFM_BanManager
|
||||
}
|
||||
|
||||
uuidBans.add(ban);
|
||||
save();
|
||||
}
|
||||
|
||||
public void addIpBan(TFM_Ban ban)
|
||||
{
|
||||
if (!ban.isComplete())
|
||||
{
|
||||
throw new RuntimeException("Could not load UUID ban, Invalid format!");
|
||||
throw new RuntimeException("Could not add IP ban, Invalid format!");
|
||||
}
|
||||
|
||||
if (ban.isExpired())
|
||||
@ -183,6 +218,7 @@ public class TFM_BanManager
|
||||
}
|
||||
|
||||
ipBans.add(ban);
|
||||
save();
|
||||
}
|
||||
|
||||
public void removeBan(TFM_Ban ban)
|
||||
@ -204,6 +240,8 @@ public class TFM_BanManager
|
||||
uuids.remove();
|
||||
}
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
public void purgeIpBans()
|
||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class TFM_PlayerEntry
|
||||
@ -24,7 +25,7 @@ public class TFM_PlayerEntry
|
||||
this.lastJoinName = section.getString("lastjoinname");
|
||||
|
||||
this.firstJoinUnix = section.getLong("firstjoinunix");
|
||||
this.firstJoinUnix = section.getLong("lastjoinunix");
|
||||
this.lastJoinUnix = section.getLong("lastjoinunix");
|
||||
|
||||
this.ips.addAll(section.getStringList("ips"));
|
||||
}
|
||||
|
@ -199,16 +199,6 @@ public class TFM_ServerInterface
|
||||
// force-allow superadmins to log in
|
||||
event.allow();
|
||||
|
||||
if (banManager.isIpBanned(ip))
|
||||
{
|
||||
banManager.unbanIp(ip);
|
||||
}
|
||||
|
||||
if (banManager.isUuidBanned(uuid))
|
||||
{
|
||||
banManager.unbanUuid(uuid);
|
||||
}
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (onlinePlayer.getName().equalsIgnoreCase(username))
|
||||
|
@ -225,6 +225,11 @@ public class TFM_Util
|
||||
}
|
||||
}
|
||||
|
||||
public static String decolorize(String string)
|
||||
{
|
||||
return string.replaceAll("\\u00A7(?=[0-9a-fk-or])", "&");
|
||||
}
|
||||
|
||||
public static void buildHistory(Location location, int length, TFM_PlayerData playerdata)
|
||||
{
|
||||
Block center = location.getBlock();
|
||||
|
@ -193,6 +193,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
server.getScheduler().cancelTasks(plugin);
|
||||
|
||||
TFM_HTTPD_Manager.getInstance().stop();
|
||||
TFM_BanManager.getInstance().save();
|
||||
|
||||
TFM_Log.info("Plugin disabled");
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ name: TotalFreedomMod
|
||||
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
|
||||
version: 3.6
|
||||
description: Plugin for the Total Freedom server.
|
||||
softdepend: [BukkitTelnet]
|
||||
softdepend: [BukkitTelnet, WorldEdit, Essentials]
|
||||
authors: [Madgeek1450, DarthSalamon]
|
||||
|
||||
# plugin.yml is no longer used to define commands.
|
||||
|
Loading…
Reference in New Issue
Block a user