summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvilSeph <evilseph@gmail.com>2011-09-16 20:57:43 -0400
committerEvilSeph <evilseph@gmail.com>2011-09-16 22:26:49 -0400
commit392e2a4272b033ba0ffd8121adab3698267bddec (patch)
tree3e1d7f79e8e0a6eaf72ae5cb74dbe3cd18962d28
parent096672b3c1e82795f8cbb53bc0a6eb4ed8060088 (diff)
downloadcraftbukkit-392e2a4272b033ba0ffd8121adab3698267bddec.tar
craftbukkit-392e2a4272b033ba0ffd8121adab3698267bddec.tar.gz
craftbukkit-392e2a4272b033ba0ffd8121adab3698267bddec.tar.lz
craftbukkit-392e2a4272b033ba0ffd8121adab3698267bddec.tar.xz
craftbukkit-392e2a4272b033ba0ffd8121adab3698267bddec.zip
Implemented configurable ping packet limit.
-rw-r--r--src/main/java/net/minecraft/server/ServerConfigurationManager.java32
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftServer.java6
2 files changed, 25 insertions, 13 deletions
diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java
index e9bf8e05..eb8edb6e 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;
+
+ int lastIndex = (this.server.ticks * packetsToSend) % totalPacketCount;
- this.sendAll(new Packet201PlayerInfo(entityplayer.name, true, entityplayer.i));
+ 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 2c8420d0..7d1ce471 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<String> icanhasbukkit = new ArrayList<String>();
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;
}