#1227: Refinements to new ban API for improved compatibility and correctness
This commit is contained in:
parent
0d0b1e5dce
commit
0a0fc3beec
@ -23,6 +23,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -1721,14 +1722,14 @@ public final class CraftServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void banIP(InetSocketAddress address) {
|
public void banIP(InetAddress address) {
|
||||||
Preconditions.checkArgument(address != null, "Address cannot be null.");
|
Preconditions.checkArgument(address != null, "Address cannot be null.");
|
||||||
|
|
||||||
((CraftIpBanList) this.getBanList(BanList.Type.IP)).addBan(address, null, null, null);
|
((CraftIpBanList) this.getBanList(BanList.Type.IP)).addBan(address, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unbanIP(InetSocketAddress address) {
|
public void unbanIP(InetAddress address) {
|
||||||
Preconditions.checkArgument(address != null, "Address cannot be null.");
|
Preconditions.checkArgument(address != null, "Address cannot be null.");
|
||||||
|
|
||||||
((CraftIpBanList) this.getBanList(BanList.Type.IP)).pardon(address);
|
((CraftIpBanList) this.getBanList(BanList.Type.IP)).pardon(address);
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package org.bukkit.craftbukkit.ban;
|
package org.bukkit.craftbukkit.ban;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import com.google.common.net.InetAddresses;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import net.minecraft.server.players.IpBanEntry;
|
import net.minecraft.server.players.IpBanEntry;
|
||||||
import net.minecraft.server.players.IpBanList;
|
import net.minecraft.server.players.IpBanList;
|
||||||
import org.bukkit.BanEntry;
|
import org.bukkit.BanEntry;
|
||||||
|
|
||||||
public final class CraftIpBanEntry implements BanEntry<InetSocketAddress> {
|
public final class CraftIpBanEntry implements BanEntry<InetAddress> {
|
||||||
private static final Date minorDate = Date.from(Instant.parse("1899-12-31T04:00:00Z"));
|
private static final Date minorDate = Date.from(Instant.parse("1899-12-31T04:00:00Z"));
|
||||||
private final IpBanList list;
|
private final IpBanList list;
|
||||||
private final String target;
|
private final String target;
|
||||||
@ -31,8 +32,8 @@ public final class CraftIpBanEntry implements BanEntry<InetSocketAddress> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InetSocketAddress getBanTarget() {
|
public InetAddress getBanTarget() {
|
||||||
return new InetSocketAddress(this.target, 0);
|
return InetAddresses.forString(this.target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.ban;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.net.InetAddresses;
|
import com.google.common.net.InetAddresses;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import net.minecraft.server.players.IpBanEntry;
|
import net.minecraft.server.players.IpBanEntry;
|
||||||
@ -18,7 +18,7 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BanEntry<InetSocketAddress> getBanEntry(String target) {
|
public BanEntry<InetAddress> getBanEntry(String target) {
|
||||||
Preconditions.checkArgument(target != null, "Target cannot be null");
|
Preconditions.checkArgument(target != null, "Target cannot be null");
|
||||||
|
|
||||||
IpBanEntry entry = this.list.get(target);
|
IpBanEntry entry = this.list.get(target);
|
||||||
@ -30,12 +30,12 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BanEntry<InetSocketAddress> getBanEntry(InetSocketAddress target) {
|
public BanEntry<InetAddress> getBanEntry(InetAddress target) {
|
||||||
return this.getBanEntry(this.getIpFromAddress(target));
|
return this.getBanEntry(this.getIpFromAddress(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BanEntry<InetSocketAddress> addBan(String target, String reason, Date expires, String source) {
|
public BanEntry<InetAddress> addBan(String target, String reason, Date expires, String source) {
|
||||||
Preconditions.checkArgument(target != null, "Ban target cannot be null");
|
Preconditions.checkArgument(target != null, "Ban target cannot be null");
|
||||||
|
|
||||||
IpBanEntry entry = new IpBanEntry(target, new Date(),
|
IpBanEntry entry = new IpBanEntry(target, new Date(),
|
||||||
@ -48,13 +48,25 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BanEntry<InetSocketAddress> addBan(InetSocketAddress target, String reason, Date expires, String source) {
|
public BanEntry<InetAddress> addBan(InetAddress target, String reason, Date expires, String source) {
|
||||||
return this.addBan(this.getIpFromAddress(target), reason, expires, source);
|
return this.addBan(this.getIpFromAddress(target), reason, expires, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<BanEntry<InetSocketAddress>> getBanEntries() {
|
public Set<BanEntry> getBanEntries() {
|
||||||
ImmutableSet.Builder<BanEntry<InetSocketAddress>> builder = ImmutableSet.builder();
|
ImmutableSet.Builder<BanEntry> builder = ImmutableSet.builder();
|
||||||
|
for (String target : list.getUserList()) {
|
||||||
|
IpBanEntry ipBanEntry = list.get(target);
|
||||||
|
if (ipBanEntry != null) {
|
||||||
|
builder.add(new CraftIpBanEntry(target, ipBanEntry, list));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<BanEntry<InetAddress>> getEntries() {
|
||||||
|
ImmutableSet.Builder<BanEntry<InetAddress>> builder = ImmutableSet.builder();
|
||||||
for (String target : list.getUserList()) {
|
for (String target : list.getUserList()) {
|
||||||
IpBanEntry ipBanEntry = list.get(target);
|
IpBanEntry ipBanEntry = list.get(target);
|
||||||
if (ipBanEntry != null) {
|
if (ipBanEntry != null) {
|
||||||
@ -71,7 +83,7 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBanned(InetSocketAddress target) {
|
public boolean isBanned(InetAddress target) {
|
||||||
return this.isBanned(getIpFromAddress(target));
|
return this.isBanned(getIpFromAddress(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,15 +94,14 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pardon(InetSocketAddress target) {
|
public void pardon(InetAddress target) {
|
||||||
this.pardon(getIpFromAddress(target));
|
this.pardon(getIpFromAddress(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIpFromAddress(InetSocketAddress address) {
|
private String getIpFromAddress(InetAddress address) {
|
||||||
if (address == null) {
|
if (address == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Preconditions.checkArgument(!address.isUnresolved(), "%s its not a valid address", address);
|
return InetAddresses.toAddrString(address);
|
||||||
return InetAddresses.toAddrString(address.getAddress());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,18 @@ public class CraftProfileBanList implements ProfileBanList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<BanEntry<PlayerProfile>> getBanEntries() {
|
public Set<BanEntry> getBanEntries() {
|
||||||
|
ImmutableSet.Builder<BanEntry> builder = ImmutableSet.builder();
|
||||||
|
for (GameProfileBanEntry entry : list.getEntries()) {
|
||||||
|
GameProfile profile = entry.getUser();
|
||||||
|
builder.add(new CraftProfileBanEntry(profile, entry, list));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<BanEntry<PlayerProfile>> getEntries() {
|
||||||
ImmutableSet.Builder<BanEntry<PlayerProfile>> builder = ImmutableSet.builder();
|
ImmutableSet.Builder<BanEntry<PlayerProfile>> builder = ImmutableSet.builder();
|
||||||
for (GameProfileBanEntry entry : list.getEntries()) {
|
for (GameProfileBanEntry entry : list.getEntries()) {
|
||||||
GameProfile profile = entry.getUser();
|
GameProfile profile = entry.getUser();
|
||||||
|
@ -11,6 +11,7 @@ import it.unimi.dsi.fastutil.shorts.ShortSet;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -1208,9 +1209,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BanEntry<InetSocketAddress> banIp(String reason, Date expires, String source, boolean kickPlayer) {
|
public BanEntry<InetAddress> banIp(String reason, Date expires, String source, boolean kickPlayer) {
|
||||||
Preconditions.checkArgument(getAddress() != null, "The Address of this Player is null");
|
Preconditions.checkArgument(getAddress() != null, "The Address of this Player is null");
|
||||||
BanEntry<InetSocketAddress> banEntry = ((IpBanList) server.getBanList(BanList.Type.IP)).addBan(getAddress(), reason, expires, source);
|
BanEntry<InetAddress> banEntry = ((IpBanList) server.getBanList(BanList.Type.IP)).addBan(getAddress().getAddress(), reason, expires, source);
|
||||||
if (kickPlayer) {
|
if (kickPlayer) {
|
||||||
this.kickPlayer(reason);
|
this.kickPlayer(reason);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user