Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Better case-insensitivity.
Dieser Commit ist enthalten in:
Ursprung
a778825152
Commit
48822fe55c
@ -29,10 +29,7 @@ import java.nio.file.NoSuchFileException;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class VelocityServer implements ProxyServer {
|
public class VelocityServer implements ProxyServer {
|
||||||
@ -119,11 +116,12 @@ public class VelocityServer implements ProxyServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean registerConnection(ConnectedPlayer connection) {
|
public boolean registerConnection(ConnectedPlayer connection) {
|
||||||
if (connectionsByName.putIfAbsent(connection.getUsername(), connection) != null) {
|
String lowerName = connection.getUsername().toLowerCase(Locale.US);
|
||||||
|
if (connectionsByName.putIfAbsent(lowerName, connection) != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (connectionsByUuid.putIfAbsent(connection.getUniqueId(), connection) != null) {
|
if (connectionsByUuid.putIfAbsent(connection.getUniqueId(), connection) != null) {
|
||||||
connectionsByName.remove(connection.getUsername(), connection);
|
connectionsByName.remove(lowerName, connection);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -137,7 +135,7 @@ public class VelocityServer implements ProxyServer {
|
|||||||
@Override
|
@Override
|
||||||
public Optional<Player> getPlayer(@Nonnull String username) {
|
public Optional<Player> getPlayer(@Nonnull String username) {
|
||||||
Preconditions.checkNotNull(username, "username");
|
Preconditions.checkNotNull(username, "username");
|
||||||
return Optional.ofNullable(connectionsByName.get(username));
|
return Optional.ofNullable(connectionsByName.get(username.toLowerCase(Locale.US)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,10 +4,7 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.velocitypowered.api.server.ServerInfo;
|
import com.velocitypowered.api.server.ServerInfo;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.locks.ReadWriteLock;
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
@ -17,9 +14,10 @@ public class ServerMap {
|
|||||||
|
|
||||||
public Optional<ServerInfo> getServer(String server) {
|
public Optional<ServerInfo> getServer(String server) {
|
||||||
Preconditions.checkNotNull(server, "server");
|
Preconditions.checkNotNull(server, "server");
|
||||||
|
String lowerName = server.toLowerCase(Locale.US);
|
||||||
lock.readLock().lock();
|
lock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
return Optional.ofNullable(servers.get(server.toLowerCase()));
|
return Optional.ofNullable(servers.get(lowerName));
|
||||||
} finally {
|
} finally {
|
||||||
lock.readLock().unlock();
|
lock.readLock().unlock();
|
||||||
}
|
}
|
||||||
@ -36,9 +34,10 @@ public class ServerMap {
|
|||||||
|
|
||||||
public void register(ServerInfo server) {
|
public void register(ServerInfo server) {
|
||||||
Preconditions.checkNotNull(server, "server");
|
Preconditions.checkNotNull(server, "server");
|
||||||
|
String lowerName = server.getName().toLowerCase(Locale.US);
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
Preconditions.checkArgument(servers.putIfAbsent(server.getName(), server) == null, "Server with name %s already registered", server.getName());
|
Preconditions.checkArgument(servers.putIfAbsent(lowerName, server) == null, "Server with name %s already registered", server.getName());
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
@ -46,9 +45,10 @@ public class ServerMap {
|
|||||||
|
|
||||||
public void unregister(ServerInfo server) {
|
public void unregister(ServerInfo server) {
|
||||||
Preconditions.checkNotNull(server, "server");
|
Preconditions.checkNotNull(server, "server");
|
||||||
|
String lowerName = server.getName().toLowerCase(Locale.US);
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
Preconditions.checkArgument(servers.remove(server.getName(), server), "Server with this name is not registered!");
|
Preconditions.checkArgument(servers.remove(lowerName, server), "Server with this name is not registered!");
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren