[Bleeding] Fixed bugs with TFM_PlayerList and TFM_BanManager

This commit is contained in:
unknown 2014-04-15 15:43:07 +02:00
parent c98909df12
commit 7f2e72ee51
13 changed files with 103 additions and 74 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Mon Apr 14 21:11:06 CEST 2014 #Tue Apr 15 15:42:20 CEST 2014
build.number=732 build.number=755

View File

@ -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: 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: uuids:
- '245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:UUID ban example' - '245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:UUID ban example'

View File

@ -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); TFM_Util.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
// Undo WorldEdits: // Undo WorldEdits:
try
{
TFM_WorldEditBridge.getInstance().undo(player, 15); TFM_WorldEditBridge.getInstance().undo(player, 15);
}
catch (NoClassDefFoundError ex)
{
}
// rollback // rollback
TFM_RollbackManager.rollback(player.getName()); 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)); TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));
// ban username: // 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: // kick Player:
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : "")); player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));

View File

@ -44,20 +44,7 @@ public class Command_tfbanlist extends TFM_Command
} }
} }
StringBuilder banned_players = new StringBuilder(); playerMsg(TFM_BanManager.getInstance().getUuidBanList().size() + " UUID bans total");
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());
return true; return true;
} }

View File

@ -44,26 +44,7 @@ public class Command_tfipbanlist extends TFM_Command
} }
} }
List<String> ip_bans = Arrays.asList(server.getIPBans().toArray(new String[0])); playerMsg(TFM_BanManager.getInstance().getIpBanList().size() + " IPbans total");
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());
return true; return true;
} }

View File

@ -671,7 +671,8 @@ public class TFM_PlayerListener implements Listener
{ {
TotalFreedomMod.fuckoffEnabledFor.remove(player); TotalFreedomMod.fuckoffEnabledFor.remove(player);
} }
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.disarmMP44(); playerdata.disarmMP44();
if (playerdata.isCaged()) if (playerdata.isCaged())
{ {
@ -689,11 +690,8 @@ public class TFM_PlayerListener implements Listener
final String ip = TFM_Util.getIp(player); final String ip = TFM_Util.getIp(player);
TFM_Log.info("[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip, true); 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); final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
entry.setLastJoinUnix(TFM_Util.getUnixTime()); entry.setLastJoinUnix(TFM_Util.getUnixTime());
entry.setLastJoinName(player.getName()); entry.setLastJoinName(player.getName());
@ -701,10 +699,7 @@ public class TFM_PlayerListener implements Listener
} }
else else
{ {
// Preload the entry; the login unix is defaulted to the current time TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
entry.addIp(ip);
entry.save();
} }
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
@ -713,6 +708,16 @@ public class TFM_PlayerListener implements Listener
// Verify strict IP match // Verify strict IP match
if (TFM_AdminList.isSuperAdmin(player)) 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); player.setOp(true);
if (!TFM_AdminList.isIdentityMatched(player)) if (!TFM_AdminList.isIdentityMatched(player))

View File

@ -14,11 +14,20 @@ public class TFM_Ban
static static
{ {
// 192.168.1.254:LocalHost:DarthSalamon:0:none // 192.168.1.254:LocalHost:DarthSalamon:0:none
// 127.0.*.*:TestUserName:BannedByNotch:123567:Test reason
IP_BAN_REGEX = Pattern.compile( 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 // 245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:Example reason
UUID_BAN_REGEX = Pattern.compile( 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 boolean complete;
private String subject; // uuid or IP private String subject; // uuid or IP
@ -47,8 +56,9 @@ public class TFM_Ban
this.subject = subject; this.subject = subject;
this.lastLoginName = (lastLoginName == null ? "none" : lastLoginName); this.lastLoginName = (lastLoginName == null ? "none" : lastLoginName);
this.by = (sender == null ? "none" : sender); 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); this.reason = (reason == null ? "none" : reason);
complete = true;
} }
public TFM_Ban(String banString, boolean ip) public TFM_Ban(String banString, boolean ip)
@ -75,7 +85,7 @@ public class TFM_Ban
lastLoginName = matcher.group(2); lastLoginName = matcher.group(2);
by = matcher.group(3); by = matcher.group(3);
expireUnix = Long.valueOf(matcher.group(4)); expireUnix = Long.valueOf(matcher.group(4));
reason = matcher.group(5); reason = TFM_Util.colorize(matcher.group(5));
complete = true; complete = true;
} }
@ -107,7 +117,7 @@ public class TFM_Ban
public boolean isExpired() public boolean isExpired()
{ {
return expireUnix < TFM_Util.getUnixTime(); return expireUnix != 0 && expireUnix < TFM_Util.getUnixTime();
} }
public boolean isComplete() public boolean isComplete()
@ -119,6 +129,6 @@ public class TFM_Ban
@Override @Override
public String toString() public String toString()
{ {
return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + reason; return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + TFM_Util.decolorize(reason);
} }
} }

View File

@ -58,6 +58,8 @@ public class TFM_BanManager
// Save the config // Save the config
save(); save();
TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans.");
} }
public void save() public void save()
@ -69,14 +71,20 @@ public class TFM_BanManager
final List<String> newUuidBans = new ArrayList<String>(); final List<String> newUuidBans = new ArrayList<String>();
for (TFM_Ban savedBan : ipBans) for (TFM_Ban savedBan : ipBans)
{
if (!savedBan.isExpired())
{ {
newIpBans.add(savedBan.toString()); newIpBans.add(savedBan.toString());
} }
}
for (TFM_Ban savedBan : uuidBans) for (TFM_Ban savedBan : uuidBans)
{
if (!savedBan.isExpired())
{ {
newUuidBans.add(savedBan.toString()); newUuidBans.add(savedBan.toString());
} }
}
config.set("ips", newIpBans); config.set("ips", newIpBans);
config.set("uuids", newUuidBans); config.set("uuids", newUuidBans);
@ -99,6 +107,28 @@ public class TFM_BanManager
{ {
for (TFM_Ban ban : ipBans) 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)) if (ban.getSubject().equals(ip))
{ {
return ban; return ban;
@ -113,6 +143,11 @@ public class TFM_BanManager
{ {
if (ban.getSubject().equalsIgnoreCase(uuid.toString())) if (ban.getSubject().equalsIgnoreCase(uuid.toString()))
{ {
if (ban.isExpired())
{
continue;
}
return ban; return ban;
} }
} }
@ -125,11 +160,11 @@ public class TFM_BanManager
if (ban == null) if (ban == null)
{ {
TFM_Log.warning("Could not unban IP: " + ip + ", IP is not banned!");
return; return;
} }
removeBan(ban); removeBan(ban);
save();
} }
public void unbanUuid(UUID uuid) public void unbanUuid(UUID uuid)
@ -138,7 +173,6 @@ public class TFM_BanManager
if (ban == null) if (ban == null)
{ {
TFM_Log.warning("Could not unban UUID: " + uuid + ", UUID is not banned!");
return; return;
} }
@ -159,7 +193,7 @@ public class TFM_BanManager
{ {
if (!ban.isComplete()) 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()) if (ban.isExpired())
@ -168,13 +202,14 @@ public class TFM_BanManager
} }
uuidBans.add(ban); uuidBans.add(ban);
save();
} }
public void addIpBan(TFM_Ban ban) public void addIpBan(TFM_Ban ban)
{ {
if (!ban.isComplete()) 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()) if (ban.isExpired())
@ -183,6 +218,7 @@ public class TFM_BanManager
} }
ipBans.add(ban); ipBans.add(ban);
save();
} }
public void removeBan(TFM_Ban ban) public void removeBan(TFM_Ban ban)
@ -204,6 +240,8 @@ public class TFM_BanManager
uuids.remove(); uuids.remove();
} }
} }
save();
} }
public void purgeIpBans() public void purgeIpBans()

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class TFM_PlayerEntry public class TFM_PlayerEntry
@ -24,7 +25,7 @@ public class TFM_PlayerEntry
this.lastJoinName = section.getString("lastjoinname"); this.lastJoinName = section.getString("lastjoinname");
this.firstJoinUnix = section.getLong("firstjoinunix"); this.firstJoinUnix = section.getLong("firstjoinunix");
this.firstJoinUnix = section.getLong("lastjoinunix"); this.lastJoinUnix = section.getLong("lastjoinunix");
this.ips.addAll(section.getStringList("ips")); this.ips.addAll(section.getStringList("ips"));
} }

View File

@ -199,16 +199,6 @@ public class TFM_ServerInterface
// force-allow superadmins to log in // force-allow superadmins to log in
event.allow(); event.allow();
if (banManager.isIpBanned(ip))
{
banManager.unbanIp(ip);
}
if (banManager.isUuidBanned(uuid))
{
banManager.unbanUuid(uuid);
}
for (Player onlinePlayer : server.getOnlinePlayers()) for (Player onlinePlayer : server.getOnlinePlayers())
{ {
if (onlinePlayer.getName().equalsIgnoreCase(username)) if (onlinePlayer.getName().equalsIgnoreCase(username))

View File

@ -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) public static void buildHistory(Location location, int length, TFM_PlayerData playerdata)
{ {
Block center = location.getBlock(); Block center = location.getBlock();

View File

@ -193,6 +193,7 @@ public class TotalFreedomMod extends JavaPlugin
server.getScheduler().cancelTasks(plugin); server.getScheduler().cancelTasks(plugin);
TFM_HTTPD_Manager.getInstance().stop(); TFM_HTTPD_Manager.getInstance().stop();
TFM_BanManager.getInstance().save();
TFM_Log.info("Plugin disabled"); TFM_Log.info("Plugin disabled");
} }

View File

@ -2,7 +2,7 @@ name: TotalFreedomMod
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
version: 3.6 version: 3.6
description: Plugin for the Total Freedom server. description: Plugin for the Total Freedom server.
softdepend: [BukkitTelnet] softdepend: [BukkitTelnet, WorldEdit, Essentials]
authors: [Madgeek1450, DarthSalamon] authors: [Madgeek1450, DarthSalamon]
# plugin.yml is no longer used to define commands. # plugin.yml is no longer used to define commands.