From d17c457040a60ded085feb8acb666798ca291ccd Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 12 Feb 2013 11:48:38 +1100 Subject: [PATCH] Add experimental offline mode support - closes issue #121 --- .../net/md_5/bungee/api/config/ConfigurationAdapter.java | 9 +++++++++ proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java | 2 +- proxy/src/main/java/net/md_5/bungee/InitialHandler.java | 2 +- .../main/java/net/md_5/bungee/config/Configuration.java | 5 +++++ .../src/main/java/net/md_5/bungee/config/YamlConfig.java | 6 ++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/config/ConfigurationAdapter.java b/api/src/main/java/net/md_5/bungee/api/config/ConfigurationAdapter.java index d2d43b79..c82e0c8d 100644 --- a/api/src/main/java/net/md_5/bungee/api/config/ConfigurationAdapter.java +++ b/api/src/main/java/net/md_5/bungee/api/config/ConfigurationAdapter.java @@ -34,6 +34,15 @@ public interface ConfigurationAdapter */ public String getString(String path, String def); + /** + * Gets a boolean from the specified path. + * + * @param path the path to retrieve the boolean form. + * @param def the default value + * @return the retrieved boolean + */ + public boolean getBoolean(String path, boolean def); + /** * Get the configuration all servers which may be accessible via the proxy. * diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index 6954ad03..9ecf4988 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -51,7 +51,7 @@ public class EncryptionUtil keys = KeyPairGenerator.getInstance( "RSA" ).generateKeyPair(); } - String hash = Long.toString( random.nextLong(), 16 ); + String hash = ( BungeeCord.getInstance().config.isOnlineMode() ) ? Long.toString( random.nextLong(), 16 ) : "-"; byte[] pubKey = keys.getPublic().getEncoded(); byte[] verify = new byte[ 4 ]; random.nextBytes( verify ); diff --git a/proxy/src/main/java/net/md_5/bungee/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/InitialHandler.java index e7aa45f3..2407fb74 100644 --- a/proxy/src/main/java/net/md_5/bungee/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/InitialHandler.java @@ -109,7 +109,7 @@ public class InitialHandler extends PacketHandler implements Runnable, PendingCo Preconditions.checkState( thisState == State.ENCRYPT, "Not expecting ENCRYPT" ); SecretKey shared = EncryptionUtil.getSecret( encryptResponse, request ); - if ( !EncryptionUtil.isAuthenticated( handshake.username, request.serverId, shared ) ) + if ( BungeeCord.getInstance().config.isOnlineMode() && !EncryptionUtil.isAuthenticated( handshake.username, request.serverId, shared ) ) { throw new KickException( "Not authenticated with minecraft.net" ); } diff --git a/proxy/src/main/java/net/md_5/bungee/config/Configuration.java b/proxy/src/main/java/net/md_5/bungee/config/Configuration.java index 72df6f62..9677aacf 100644 --- a/proxy/src/main/java/net/md_5/bungee/config/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/config/Configuration.java @@ -44,6 +44,10 @@ public class Configuration * Set of all servers. */ private Map servers; + /** + * Should we check minecraft.net auth. + */ + private boolean onlineMode = true; public void load() { @@ -52,6 +56,7 @@ public class Configuration timeout = adapter.getInt( "timeout", timeout ); uuid = adapter.getString( "stats", uuid ); + onlineMode = adapter.getBoolean( "online_mode", onlineMode ); DefaultTabList tab = DefaultTabList.valueOf( adapter.getString( "tab_list", "GLOBAL_PING" ) ); if ( tab == null ) diff --git a/proxy/src/main/java/net/md_5/bungee/config/YamlConfig.java b/proxy/src/main/java/net/md_5/bungee/config/YamlConfig.java index 313b0011..44e715e1 100644 --- a/proxy/src/main/java/net/md_5/bungee/config/YamlConfig.java +++ b/proxy/src/main/java/net/md_5/bungee/config/YamlConfig.java @@ -127,6 +127,12 @@ public class YamlConfig implements ConfigurationAdapter return get( path, def ); } + @Override + public boolean getBoolean(String path, boolean def) + { + return get( path, def ); + } + @Override @SuppressWarnings("unchecked") public Map getServers()