Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Relax registration checks for same servers somewhat.
If a server with the same ServerInfo is attempting to be re-registered, we will return the existing registered server, which is less surprising behavior than before.
Dieser Commit ist enthalten in:
Ursprung
3bd48dec99
Commit
f6cac0f50a
@ -34,8 +34,15 @@ public class ServerMap {
|
||||
Preconditions.checkNotNull(serverInfo, "serverInfo");
|
||||
String lowerName = serverInfo.getName().toLowerCase(Locale.US);
|
||||
VelocityRegisteredServer rs = new VelocityRegisteredServer(server, serverInfo);
|
||||
Preconditions.checkArgument(servers.putIfAbsent(lowerName, rs) == null, "Server with name %s already registered", serverInfo.getName());
|
||||
return rs;
|
||||
|
||||
RegisteredServer existing = servers.putIfAbsent(lowerName, rs);
|
||||
if (existing != null && !existing.getServerInfo().equals(serverInfo)) {
|
||||
throw new IllegalArgumentException("Server with name " + serverInfo.getName() + " already registered");
|
||||
} else if (existing == null) {
|
||||
return rs;
|
||||
} else {
|
||||
return existing;
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister(ServerInfo serverInfo) {
|
||||
|
@ -35,4 +35,12 @@ class ServerMapTest {
|
||||
ServerInfo willReject = new ServerInfo("TESTSERVER", TEST_ADDRESS);
|
||||
assertThrows(IllegalArgumentException.class, () -> map.register(willReject));
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowsSameServerLaxRegistrationCheck() {
|
||||
ServerMap map = new ServerMap(null);
|
||||
ServerInfo info = new ServerInfo("TestServer", TEST_ADDRESS);
|
||||
RegisteredServer connection = map.register(info);
|
||||
assertEquals(connection, map.register(info));
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren