From 0b10f83916d48f1662ebfd86897e830d03ce5549 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 16 Feb 2013 12:41:26 +1100 Subject: [PATCH] Cut CPU load to sane amounts in the same way that Minecraft does. --- .../main/java/net/md_5/bungee/UserConnection.java | 14 ++++++++++++++ .../java/net/md_5/bungee/config/Configuration.java | 2 ++ 2 files changed, 16 insertions(+) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 4caee0de..ab02e924 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -331,6 +331,13 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer { server.stream.write( packet ); } + + try + { + Thread.sleep( BungeeCord.getInstance().config.getSleepTime() ); + } catch ( InterruptedException ex ) + { + } } catch ( IOException ex ) { destroySelf( "Reached end of stream" ); @@ -526,6 +533,13 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer connect( nextServer, true ); break outer; } + + try + { + Thread.sleep( BungeeCord.getInstance().config.getSleepTime() ); + } catch ( InterruptedException ex ) + { + } } } catch ( Exception ex ) { 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 9677aacf..2abf1744 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 @@ -48,6 +48,7 @@ public class Configuration * Should we check minecraft.net auth. */ private boolean onlineMode = true; + private int sleepTime = 2; public void load() { @@ -57,6 +58,7 @@ public class Configuration timeout = adapter.getInt( "timeout", timeout ); uuid = adapter.getString( "stats", uuid ); onlineMode = adapter.getBoolean( "online_mode", onlineMode ); + sleepTime = adapter.getInt( "sleep_time", sleepTime ); DefaultTabList tab = DefaultTabList.valueOf( adapter.getString( "tab_list", "GLOBAL_PING" ) ); if ( tab == null )