diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java index e9bf8e05a0..eb8edb6e07 100644 --- a/src/main/java/net/minecraft/server/ServerConfigurationManager.java +++ b/src/main/java/net/minecraft/server/ServerConfigurationManager.java @@ -47,11 +47,13 @@ public class ServerConfigurationManager { // CraftBukkit start private CraftServer cserver; + private final int MAX_PACKETS_PER_TICK; public ServerConfigurationManager(MinecraftServer minecraftserver) { minecraftserver.server = new CraftServer(minecraftserver, this); minecraftserver.console = new ColouredConsoleSender(minecraftserver.server); this.cserver = minecraftserver.server; + this.MAX_PACKETS_PER_TICK = minecraftserver.server.getPingPacketLimit(); // CraftBukkit end this.server = minecraftserver; @@ -315,25 +317,29 @@ public class ServerConfigurationManager { // CraftBukkit end } + // CraftBukkit start - Limit/throttle latency packets public void b() { - int i; + int playerCount = this.players.size(); + if ((MAX_PACKETS_PER_TICK > 0) && (playerCount > 0)) { + int fromIndex, toIndex; - if (this.p-- <= 0) { - for (i = 0; i < this.players.size(); ++i) { - // CraftBukkit start -- Client cannot render anymore than 126 Players so there's no point sending anymore packets. - if (i > 126) { - break; - } - // CraftBukkit end - EntityPlayer entityplayer = (EntityPlayer) this.players.get(i); + int playerListSize = playerCount > 126 ? 126 : playerCount; + int totalPacketCount = playerCount * playerListSize; + int packetsToSend = totalPacketCount < MAX_PACKETS_PER_TICK ? totalPacketCount : MAX_PACKETS_PER_TICK; - this.sendAll(new Packet201PlayerInfo(entityplayer.name, true, entityplayer.i)); + int lastIndex = (this.server.ticks * packetsToSend) % totalPacketCount; + + for (int i = lastIndex; i < lastIndex + packetsToSend; i++) { + i %= totalPacketCount; + toIndex = i % playerCount; + fromIndex = i / playerCount; + + ((EntityPlayer) this.players.get(toIndex)).netServerHandler.sendPacket(new Packet201PlayerInfo(((EntityPlayer) this.players.get(fromIndex)).name, true, ((EntityPlayer) this.players.get(fromIndex)).i)); } } - // CraftBukkit start - for (i = 0; i < this.server.worlds.size(); ++i) { - this.server.worlds.get(i).manager.flush(); + for (int j = 0; j < this.server.worlds.size(); ++j) { + this.server.worlds.get(j).manager.flush(); } // CraftBukkit end } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 2c8420d0bc..7d1ce47110 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -119,6 +119,8 @@ public final class CraftServer implements Server { configuration.getString("settings.permissions-file", "permissions.yml"); + configuration.getInt("settings.ping-packet-limit", 100); + if (configuration.getNode("aliases") == null) { List icanhasbukkit = new ArrayList(); icanhasbukkit.add("version"); @@ -317,6 +319,10 @@ public final class CraftServer implements Server { return this.configuration.getString("settings.update-folder", "update"); } + public int getPingPacketLimit() { + return this.configuration.getInt("settings.ping-packet-limit", 100); + } + public PluginManager getPluginManager() { return pluginManager; }