mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
Don't wait for main thread when processing commands.
In order to correctly handle disconnects for invalid chat we setup a Waitable and pass it to the main thread then wait for it to be processed. However, commands are also chat packets and they are already on the main thread. In this case, waiting will deadlock the server so we should just do a normal disconnect.
This commit is contained in:
parent
9add7d3000
commit
558411692a
1 changed files with 57 additions and 45 deletions
|
@ -794,6 +794,7 @@ public class NetServerHandler extends NetHandler {
|
||||||
|
|
||||||
if (s.length() > 100) {
|
if (s.length() > 100) {
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
if (packet3chat.a_()) {
|
||||||
Waitable waitable = new Waitable() {
|
Waitable waitable = new Waitable() {
|
||||||
@Override
|
@Override
|
||||||
protected Object evaluate() {
|
protected Object evaluate() {
|
||||||
|
@ -811,6 +812,9 @@ public class NetServerHandler extends NetHandler {
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.disconnect("Chat message too long");
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
} else {
|
} else {
|
||||||
s = s.trim();
|
s = s.trim();
|
||||||
|
@ -818,6 +822,7 @@ public class NetServerHandler extends NetHandler {
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
|
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
if (packet3chat.a_()) {
|
||||||
Waitable waitable = new Waitable() {
|
Waitable waitable = new Waitable() {
|
||||||
@Override
|
@Override
|
||||||
protected Object evaluate() {
|
protected Object evaluate() {
|
||||||
|
@ -835,6 +840,9 @@ public class NetServerHandler extends NetHandler {
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.disconnect("Illegal characters in chat");
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -851,6 +859,7 @@ public class NetServerHandler extends NetHandler {
|
||||||
// This section stays because it is only applicable to packets
|
// This section stays because it is only applicable to packets
|
||||||
if (chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getServerConfigurationManager().isOp(this.player.name)) { // CraftBukkit use thread-safe spam
|
if (chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getServerConfigurationManager().isOp(this.player.name)) { // CraftBukkit use thread-safe spam
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
if (packet3chat.a_()) {
|
||||||
Waitable waitable = new Waitable() {
|
Waitable waitable = new Waitable() {
|
||||||
@Override
|
@Override
|
||||||
protected Object evaluate() {
|
protected Object evaluate() {
|
||||||
|
@ -868,6 +877,9 @@ public class NetServerHandler extends NetHandler {
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.disconnect("disconnect.spam");
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue