Close #376 - case insensitive servers and maps
This commit is contained in:
parent
32fdc83841
commit
9fdcded97f
@ -6,6 +6,7 @@ import com.ning.http.client.AsyncHttpClient;
|
|||||||
import com.ning.http.client.AsyncHttpClientConfig;
|
import com.ning.http.client.AsyncHttpClientConfig;
|
||||||
import com.ning.http.client.providers.netty.NettyAsyncHttpProvider;
|
import com.ning.http.client.providers.netty.NettyAsyncHttpProvider;
|
||||||
import com.ning.http.client.providers.netty.NettyAsyncHttpProviderConfig;
|
import com.ning.http.client.providers.netty.NettyAsyncHttpProviderConfig;
|
||||||
|
import gnu.trove.map.TMap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelException;
|
import io.netty.channel.ChannelException;
|
||||||
@ -27,7 +28,6 @@ import java.util.Map;
|
|||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -53,6 +53,7 @@ import net.md_5.bungee.netty.PipelineUtils;
|
|||||||
import net.md_5.bungee.packet.DefinedPacket;
|
import net.md_5.bungee.packet.DefinedPacket;
|
||||||
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
||||||
import net.md_5.bungee.scheduler.BungeeThreadPool;
|
import net.md_5.bungee.scheduler.BungeeThreadPool;
|
||||||
|
import net.md_5.bungee.util.CaseInsensitiveMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main BungeeCord proxy class.
|
* Main BungeeCord proxy class.
|
||||||
@ -96,7 +97,7 @@ public class BungeeCord extends ProxyServer
|
|||||||
/**
|
/**
|
||||||
* Fully qualified connections.
|
* Fully qualified connections.
|
||||||
*/
|
*/
|
||||||
public Map<String, UserConnection> connections = new ConcurrentHashMap<>();
|
public TMap<String, UserConnection> connections = new CaseInsensitiveMap<>();
|
||||||
/**
|
/**
|
||||||
* Tab list handler
|
* Tab list handler
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.md_5.bungee.config;
|
package net.md_5.bungee.config;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import gnu.trove.map.TMap;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -12,6 +13,7 @@ import net.md_5.bungee.api.config.ServerInfo;
|
|||||||
import net.md_5.bungee.tablist.GlobalPing;
|
import net.md_5.bungee.tablist.GlobalPing;
|
||||||
import net.md_5.bungee.tablist.Global;
|
import net.md_5.bungee.tablist.Global;
|
||||||
import net.md_5.bungee.tablist.ServerUnique;
|
import net.md_5.bungee.tablist.ServerUnique;
|
||||||
|
import net.md_5.bungee.util.CaseInsensitiveMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core configuration for the proxy.
|
* Core configuration for the proxy.
|
||||||
@ -43,7 +45,7 @@ public class Configuration
|
|||||||
/**
|
/**
|
||||||
* Set of all servers.
|
* Set of all servers.
|
||||||
*/
|
*/
|
||||||
private Map<String, ServerInfo> servers;
|
private TMap<String, ServerInfo> servers;
|
||||||
/**
|
/**
|
||||||
* Should we check minecraft.net auth.
|
* Should we check minecraft.net auth.
|
||||||
*/
|
*/
|
||||||
@ -86,7 +88,7 @@ public class Configuration
|
|||||||
|
|
||||||
if ( servers == null )
|
if ( servers == null )
|
||||||
{
|
{
|
||||||
servers = newServers;
|
servers = new CaseInsensitiveMap<>( newServers );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
for ( ServerInfo oldServer : servers.values() )
|
for ( ServerInfo oldServer : servers.values() )
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package net.md_5.bungee.util;
|
||||||
|
|
||||||
|
import gnu.trove.map.hash.TCustomHashMap;
|
||||||
|
import gnu.trove.strategy.HashingStrategy;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CaseInsensitiveMap<V> extends TCustomHashMap<String, V>
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final HashingStrategy<String> hashingStrategy = new HashingStrategy<String>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int computeHashCode(String object)
|
||||||
|
{
|
||||||
|
return object.toLowerCase().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(String o1, String o2)
|
||||||
|
{
|
||||||
|
return o1.toLowerCase().equals( o2.toLowerCase() );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public CaseInsensitiveMap()
|
||||||
|
{
|
||||||
|
super( hashingStrategy );
|
||||||
|
}
|
||||||
|
|
||||||
|
public CaseInsensitiveMap(Map<? extends String, ? extends V> map)
|
||||||
|
{
|
||||||
|
super( hashingStrategy, map );
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package net.md_5.bungee.util;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
public class CaseInsensitiveTest
|
||||||
|
{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaps()
|
||||||
|
{
|
||||||
|
Object obj = new Object();
|
||||||
|
CaseInsensitiveMap<Object> map = new CaseInsensitiveMap<>();
|
||||||
|
|
||||||
|
map.put( "FOO", obj );
|
||||||
|
Assert.assertTrue( map.contains( "foo" ) ); // Assert that it is case insensitive
|
||||||
|
Assert.assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Asert that case is preserved
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user