Skip to content

Commit 8b0eddc

Browse files
authored
Dont load chunk for Pathfinding & Networking opts (#14)
* Don't load chunk for pathfinding * Virtual thread for User Authenticator * Cache player profile result * Updated Upstream (CatServer)
1 parent 8ab3b59 commit 8b0eddc

File tree

5 files changed

+85
-44
lines changed

5 files changed

+85
-44
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def jvm_arguments = [
8181
def compiler_jvm_arguments = [
8282
'--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED',
8383
'--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED',
84+
'-Xlint:-removal', // Suppress Timings deprecation warnings
8485
'--add-modules=jdk.incubator.vector' // CatRoom - SIMD support
8586
]
8687
// Projects
@@ -507,6 +508,7 @@ project(':cleanroom') {
507508
installer 'net.openhft:affinity:3.23.3'
508509
installer 'org.slf4j:slf4j-api:2.1.0-alpha1' // Affinity
509510
installer 'org.slf4j:slf4j-simple:2.1.0-alpha1' // Affinity
511+
installer 'com.github.ben-manes.caffeine:caffeine:3.1.8'
510512

511513
/*
512514
forgeGradleMcDeps

patches/minecraft/net/minecraft/network/NetworkSystem.java.patch

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- before/net/minecraft/network/NetworkSystem.java
22
+++ after/net/minecraft/network/NetworkSystem.java
3-
@@ -49,27 +49,27 @@
3+
@@ -49,27 +49,36 @@
44
{
55
protected NioEventLoopGroup func_179280_b()
66
{
@@ -30,18 +30,27 @@
3030
- private final List<NetworkManager> field_151272_f = Collections.synchronizedList(Lists.newArrayList());
3131
+ private final List<ChannelFuture> field_151274_e = Collections.<ChannelFuture>synchronizedList(Lists.newArrayList());
3232
+ private final List<NetworkManager> field_151272_f = Collections.<NetworkManager>synchronizedList(Lists.newArrayList());
33+
+ // Paper start - prevent blocking on adding a new network manager while the server is ticking
34+
+ private final List<NetworkManager> pending = Collections.<NetworkManager>synchronizedList(Lists.newArrayList());
35+
+ private void addPending() {
36+
+ synchronized (pending) {
37+
+ this.field_151272_f.addAll(pending);
38+
+ pending.clear();
39+
+ }
40+
+ }
41+
+ // Paper end
3342

3443
public NetworkSystem(MinecraftServer p_i45292_1_)
3544
{
36-
@@ -79,6 +79,7 @@
45+
@@ -79,6 +88,7 @@
3746

3847
public void func_151265_a(InetAddress p_151265_1_, int p_151265_2_) throws IOException
3948
{
4049
+ if (p_151265_1_ instanceof java.net.Inet6Address) System.setProperty("java.net.preferIPv4Stack", "false");
4150
synchronized (this.field_151274_e)
4251
{
4352
Class <? extends ServerSocketChannel > oclass;
44-
@@ -97,43 +98,26 @@
53+
@@ -97,43 +107,26 @@
4554
field_151275_b.info("Using default channel type");
4655
}
4756

@@ -76,7 +85,8 @@
7685
- .addLast("encoder", new NettyPacketEncoder(EnumPacketDirection.CLIENTBOUND));
7786
+ p_initChannel_1_.pipeline().addLast("timeout", new ReadTimeoutHandler(net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.READ_TIMEOUT)).addLast("legacy_query", new LegacyPingHandler(NetworkSystem.this)).addLast("splitter", new NettyVarint21FrameDecoder()).addLast("decoder", new NettyPacketDecoder(EnumPacketDirection.SERVERBOUND)).addLast("prepender", new NettyVarint21FrameEncoder()).addLast("encoder", new NettyPacketEncoder(EnumPacketDirection.CLIENTBOUND));
7887
NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
79-
NetworkSystem.this.field_151272_f.add(networkmanager);
88+
- NetworkSystem.this.field_151272_f.add(networkmanager);
89+
+ pending.add(networkmanager);
8090
p_initChannel_1_.pipeline().addLast("packet_handler", networkmanager);
8191
networkmanager.func_150719_a(new NetHandlerHandshakeTCP(NetworkSystem.this.field_151273_d, networkmanager));
8292
}
@@ -91,7 +101,7 @@
91101
}
92102
}
93103

94-
@@ -144,9 +128,8 @@
104+
@@ -144,9 +137,8 @@
95105

96106
synchronized (this.field_151274_e)
97107
{
@@ -102,7 +112,7 @@
102112
protected void initChannel(Channel p_initChannel_1_) throws Exception
103113
{
104114
NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
105-
@@ -154,7 +137,7 @@
115+
@@ -154,7 +146,7 @@
106116
NetworkSystem.this.field_151272_f.add(networkmanager);
107117
p_initChannel_1_.pipeline().addLast("packet_handler", networkmanager);
108118
}
@@ -111,7 +121,7 @@
111121
this.field_151274_e.add(channelfuture);
112122
}
113123

114-
@@ -171,7 +154,7 @@
124+
@@ -171,7 +163,7 @@
115125
{
116126
channelfuture.channel().close().sync();
117127
}
@@ -120,11 +130,12 @@
120130
{
121131
field_151275_b.error("Interrupted whilst closing channel");
122132
}
123-
@@ -182,6 +165,13 @@
133+
@@ -182,6 +174,14 @@
124134
{
125135
synchronized (this.field_151272_f)
126136
{
127137
+ // Spigot Start
138+
+ addPending(); // Paper
128139
+ // This prevents players from 'gaming' the server, and strategically relogging to increase their position in the tick order
129140
+ if (org.spigotmc.SpigotConfig.playerShuffle > 0 && MinecraftServer.currentTick % org.spigotmc.SpigotConfig.playerShuffle == 0)
130141
+ {
@@ -134,15 +145,15 @@
134145
Iterator<NetworkManager> iterator = this.field_151272_f.iterator();
135146

136147
while (iterator.hasNext())
137-
@@ -216,7 +206,6 @@
148+
@@ -216,7 +216,6 @@
138149
final TextComponentString textcomponentstring = new TextComponentString("Internal server error");
139150
networkmanager.func_179288_a(new SPacketDisconnect(textcomponentstring), new GenericFutureListener < Future <? super Void >> ()
140151
{
141152
- @Override
142153
public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
143154
{
144155
networkmanager.func_150718_a(textcomponentstring);
145-
@@ -227,6 +216,9 @@
156+
@@ -227,6 +226,9 @@
146157
}
147158
else
148159
{

patches/minecraft/net/minecraft/server/network/NetHandlerLoginServer.java.patch

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,27 @@
1919

2020
public class NetHandlerLoginServer implements INetHandlerLoginServer, ITickable
2121
{
22-
@@ -49,6 +54,8 @@
22+
@@ -48,6 +53,11 @@
23+
private final String field_147334_j = "";
2324
private SecretKey field_147335_k;
2425
private EntityPlayerMP field_181025_l;
25-
26-
+ public String hostname = "";
26+
+ private static final com.github.benmanes.caffeine.cache.Cache<String, GameProfile> playerProfileResultCache = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
27+
+ .expireAfterWrite(catserver.server.CatServer.getConfig().playerProfileResultCacheMinutes, java.util.concurrent.TimeUnit.MINUTES)
28+
+ .build(); // CatRoom - Cache player profile result
2729
+
30+
+ public String hostname = "";
31+
2832
public NetHandlerLoginServer(MinecraftServer p_i45298_1_, NetworkManager p_i45298_2_)
2933
{
30-
this.field_147327_f = p_i45298_1_;
31-
@@ -56,7 +63,6 @@
34+
@@ -56,7 +66,6 @@
3235
field_147329_d.nextBytes(this.field_147330_e);
3336
}
3437

3538
- @Override
3639
public void func_73660_a()
3740
{
3841
if (this.field_147328_g == NetHandlerLoginServer.LoginState.READY_TO_ACCEPT)
39-
@@ -70,16 +76,29 @@
42+
@@ -70,16 +79,29 @@
4043
if (entityplayermp == null)
4144
{
4245
this.field_147328_g = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
@@ -70,7 +73,7 @@
7073

7174
public void func_194026_b(ITextComponent p_194026_1_)
7275
{
73-
@@ -95,18 +114,48 @@
76+
@@ -95,18 +117,48 @@
7477
}
7578
}
7679

@@ -126,7 +129,7 @@
126129
}
127130
else
128131
{
129-
@@ -133,12 +182,11 @@
132+
@@ -133,12 +185,11 @@
130133
}
131134
else
132135
{
@@ -140,7 +143,7 @@
140143
public void func_147231_a(ITextComponent p_147231_1_)
141144
{
142145
field_147332_c.info("{} lost connection: {}", this.func_147317_d(), p_147231_1_.func_150260_c());
143-
@@ -146,12 +194,9 @@
146+
@@ -146,12 +197,9 @@
144147

145148
public String func_147317_d()
146149
{
@@ -154,24 +157,25 @@
154157
public void func_147316_a(CPacketLoginStart p_147316_1_)
155158
{
156159
Validate.validState(this.field_147328_g == NetHandlerLoginServer.LoginState.HELLO, "Unexpected hello packet");
157-
@@ -164,11 +209,23 @@
160+
@@ -164,11 +212,24 @@
158161
}
159162
else
160163
{
161164
- this.field_147328_g = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
162165
+ // Spigot start
163-
+ new Thread(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER, "User Authenticator #" + NetHandlerLoginServer.field_147331_b.incrementAndGet()) {
164-
+ @Override
165-
+ public void run() {
166-
+ try {
167-
+ initUUID();
168-
+ new LoginHandler().fireEvents();
169-
+ } catch (Exception ex) {
170-
+ disconnect("Failed to verify username!");
171-
+ field_147327_f.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + field_147337_i.getName(), ex);
172-
+ }
173-
+ }
174-
+ }.start();
166+
+ // CatRoom start - Virtual thread for User Authenticator
167+
+ Thread.ofVirtual()
168+
+ .name("User Authenticator #" + NetHandlerLoginServer.field_147331_b.incrementAndGet())
169+
+ .start(() -> {
170+
+ try {
171+
+ initUUID();
172+
+ new LoginHandler().fireEvents();
173+
+ } catch (Exception ex) {
174+
+ disconnect("Failed to verify username!");
175+
+ field_147327_f.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + field_147337_i.getName(), ex);
176+
+ }
177+
+ });
178+
+ // CatRoom end - Virtual thread for User Authenticator
175179
+ // Spigot end
176180
}
177181
}
@@ -180,12 +184,15 @@
180184
public void func_147315_a(CPacketEncryptionResponse p_147315_1_)
181185
{
182186
Validate.validState(this.field_147328_g == NetHandlerLoginServer.LoginState.KEY, "Unexpected key packet");
183-
@@ -183,32 +240,25 @@
187+
@@ -183,32 +244,39 @@
184188
this.field_147335_k = p_147315_1_.func_149300_a(privatekey);
185189
this.field_147328_g = NetHandlerLoginServer.LoginState.AUTHENTICATING;
186190
this.field_147333_a.func_150727_a(this.field_147335_k);
187191
- (new Thread("User Authenticator #" + field_147331_b.incrementAndGet())
188-
+ (new Thread(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER, "User Authenticator #" + field_147331_b.incrementAndGet())
192+
+ // CatRoom start - Virtual thread for User Authenticator
193+
+ Thread.ofVirtual()
194+
+ .name("User Authenticator #" + field_147331_b.incrementAndGet())
195+
+ .start(new Runnable() // CatRoom end - Virtual thread for User Authenticator
189196
{
190197
- @Override
191198
public void run()
@@ -204,7 +211,18 @@
204211
- .func_147130_as()
205212
- .hasJoinedServer(new GameProfile(null, gameprofile.getName()), s, this.func_191235_a());
206213
+ String s = (new BigInteger(CryptManager.func_75895_a("", NetHandlerLoginServer.this.field_147327_f.func_71250_E().getPublic(), NetHandlerLoginServer.this.field_147335_k))).toString(16);
207-
+ NetHandlerLoginServer.this.field_147337_i = NetHandlerLoginServer.this.field_147327_f.func_147130_as().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s, this.getAddress());
214+
+ // CatRoom start - Cache player profile result
215+
+ if (catserver.server.CatServer.getConfig().cachePlayerProfileResult) {
216+
+ GameProfile gp = playerProfileResultCache.getIfPresent(gameprofile.getName());
217+
+ if (gp == null) {
218+
+ gp = NetHandlerLoginServer.this.field_147327_f.func_147130_as().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s, this.func_191235_a());
219+
+ playerProfileResultCache.put(gameprofile.getName(), gp);
220+
+ }
221+
+ NetHandlerLoginServer.this.field_147337_i = gp;
222+
+ } else {
223+
+ NetHandlerLoginServer.this.field_147337_i = NetHandlerLoginServer.this.field_147327_f.func_147130_as().hasJoinedServer(new GameProfile((UUID) null, gameprofile.getName()), s, this.func_191235_a());
224+
+ }
225+
+ // CatRoom end - Cache player profile result
208226

209227
if (NetHandlerLoginServer.this.field_147337_i != null)
210228
{
@@ -222,7 +240,7 @@
222240
}
223241
else if (NetHandlerLoginServer.this.field_147327_f.func_71264_H())
224242
{
225-
@@ -218,11 +268,11 @@
243+
@@ -218,11 +286,11 @@
226244
}
227245
else
228246
{
@@ -237,7 +255,7 @@
237255
{
238256
if (NetHandlerLoginServer.this.field_147327_f.func_71264_H())
239257
{
240-
@@ -232,23 +282,67 @@
258+
@@ -232,23 +300,67 @@
241259
}
242260
else
243261
{
@@ -254,8 +272,7 @@
254272
}
255273
}
256274
@Nullable
257-
- private InetAddress func_191235_a()
258-
+ private InetAddress getAddress()
275+
private InetAddress func_191235_a()
259276
{
260277
SocketAddress socketaddress = NetHandlerLoginServer.this.field_147333_a.func_74430_c();
261278
- return NetHandlerLoginServer.this.field_147327_f.func_190518_ac() && socketaddress instanceof InetSocketAddress
@@ -268,7 +285,7 @@
268285
- }
269286
+ return NetHandlerLoginServer.this.field_147327_f.func_190518_ac() && socketaddress instanceof InetSocketAddress ? ((InetSocketAddress)socketaddress).getAddress() : null;
270287
+ }
271-
+ }).start();
288+
+ }); // CatRoom
272289
+ }
273290
+ }
274291
+

patches/minecraft/net/minecraft/world/ChunkCache.java.patch

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
--- before/net/minecraft/world/ChunkCache.java
22
+++ after/net/minecraft/world/ChunkCache.java
3+
@@ -34,7 +34,7 @@
4+
{
5+
for (int l = this.field_72816_b; l <= j; ++l)
6+
{
7+
- this.field_72817_c[k - this.field_72818_a][l - this.field_72816_b] = p_i45746_1_.func_72964_e(k, l);
8+
+ this.field_72817_c[k - this.field_72818_a][l - this.field_72816_b] = p_i45746_1_.getChunkIfLoaded(k, l); // Paper
9+
}
10+
}
11+
312
@@ -59,10 +59,9 @@
413
}
514

src/main/java/catserver/server/CatServerConfig.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public class CatServerConfig {
4848

4949
public boolean waitForgeServerChatEvent = false;
5050

51-
public boolean bridgeForgeExplosionEventToBukkit = true; // CatRoom
52-
5351
public int craftRequestThrottle = 20;
5452
public int itemNBTThrottle = 200;
5553
public boolean limitFastClickGUI = false;
@@ -61,8 +59,11 @@ public class CatServerConfig {
6159
public boolean disableFMLStatusModInfo = false;
6260
public boolean disableAsyncCatchWarn = false;
6361
public boolean versionCheck = true;
62+
public boolean cachePlayerProfileResult = false;
63+
public int playerProfileResultCacheMinutes = 1440;
6464

6565
public boolean callConstructCapabilityEventOnRespawn = false;
66+
public boolean bridgeForgeExplosionEventToBukkit = false;
6667

6768
public boolean enableAffinity = false;
6869
public BitSet affinity = Affinity.getAffinity();
@@ -113,10 +114,11 @@ public void loadConfig() {
113114
releaseUseItemThrottle = getOrWriteIntConfig("network.packetLimit.releaseUseItemThrottle", releaseUseItemThrottle);
114115
disableFMLHandshake = getOrWriteBooleanConfig("network.fml.disableHandshake", config.getBoolean("disableFMLHandshake", disableFMLHandshake));
115116
disableFMLStatusModInfo = getOrWriteBooleanConfig("network.fml.disableStatusModInfo", config.getBoolean("disableFMLStatusModInfo", disableFMLStatusModInfo));
116-
// event bridge
117-
bridgeForgeExplosionEventToBukkit = getOrWriteBooleanConfig("event-bridge.bridgeForgeExplosionEventToBukkit", bridgeForgeExplosionEventToBukkit);
117+
cachePlayerProfileResult = getOrWriteBooleanConfig("network.profile.cachePlayerProfileResult", cachePlayerProfileResult);
118+
playerProfileResultCacheMinutes = getOrWriteIntConfig("network.profile.playerProfileResultCacheMinutes", playerProfileResultCacheMinutes);
118119
// compatibility
119120
callConstructCapabilityEventOnRespawn = getOrWriteBooleanConfig("compatibility.callConstructCapabilityEventOnRespawn", callConstructCapabilityEventOnRespawn);
121+
bridgeForgeExplosionEventToBukkit = getOrWriteBooleanConfig("compatibility.bridgeForgeExplosionEventToBukkit", bridgeForgeExplosionEventToBukkit);
120122
// general
121123
disableUpdateGameProfile = getOrWriteBooleanConfig("disableUpdateGameProfile", disableUpdateGameProfile);
122124
disableAsyncCatchWarn = getOrWriteBooleanConfig("disableAsyncCatchWarn", disableAsyncCatchWarn);

0 commit comments

Comments
 (0)