Skip to content

Commit 976d422

Browse files
author
mdxd44
committedDec 23, 2021
Ability to max filter time, some improvements.
1 parent 214cd28 commit 976d422

17 files changed

+163
-144
lines changed
 

‎.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ jobs:
1717
with:
1818
distribution: adopt
1919
java-version: ${{ matrix.java }}
20-
- name: Cache gradle
20+
- name: Cache Gradle
2121
uses: actions/cache@v2.1.6
2222
with:
2323
path: ~/.gradle
2424
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
2525
restore-keys: ${{ runner.os }}-gradle-
26-
- name: Build plugins
26+
- name: Build LimboFilter
2727
run: ./gradlew build
2828
- name: Upload LimboFilter
2929
uses: actions/upload-artifact@v2.2.4

‎.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ jobs:
1717
with:
1818
distribution: adopt
1919
java-version: ${{ matrix.java }}
20-
- name: Cache gradle
20+
- name: Cache Gradle
2121
uses: actions/cache@v2.1.6
2222
with:
2323
path: ~/.gradle
2424
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
2525
restore-keys: ${{ runner.os }}-gradle-
26-
- name: Build plugins
26+
- name: Build LimboFilter
2727
run: ./gradlew build
2828
- name: Upload LimboFilter
2929
uses: actions/upload-artifact@v2.2.4

‎build.gradle

+35-33
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
//file:noinspection GroovyAssignabilityCheck
22

3-
import com.github.spotbugs.snom.SpotBugsTask
4-
53
plugins {
6-
id "java"
7-
id "checkstyle"
8-
id "com.github.spotbugs" version "4.7.9"
9-
id "org.cadixdev.licenser" version "0.6.1"
4+
id("java")
5+
id("checkstyle")
6+
id("com.github.spotbugs").version("5.0.3")
7+
id("org.cadixdev.licenser").version("0.6.1")
108
}
119

12-
group = "net.elytrium"
13-
version = "1.0.3-SNAPSHOT"
10+
setGroup("net.elytrium")
11+
setVersion("1.0.3-SNAPSHOT")
1412

15-
compileJava.options.encoding = "UTF-8"
13+
compileJava {
14+
getOptions().setEncoding("UTF-8")
15+
}
1616

1717
java {
18-
sourceCompatibility = JavaVersion.VERSION_11
19-
targetCompatibility = JavaVersion.VERSION_11
18+
setSourceCompatibility(JavaVersion.VERSION_11)
19+
setTargetCompatibility(JavaVersion.VERSION_11)
2020
}
2121

2222
repositories {
2323
mavenCentral()
2424

2525
maven {
26-
name = "velocitypowered-repo"
27-
url = "https://repo.velocitypowered.com/snapshots/"
26+
setName("velocitypowered-repo")
27+
setUrl("https://nexus.velocitypowered.com/repository/maven-public/")
2828
}
2929
maven {
30-
name = "elytrium-repo"
31-
url = "https://maven.elytrium.net/repo/"
30+
setName("elytrium-repo")
31+
setUrl("https://maven.elytrium.net/repo/")
3232
}
3333
}
3434

@@ -40,41 +40,43 @@ dependencies {
4040
compileOnly("com.velocitypowered:velocity-proxy:3.1.0") // From Elytrium Repo
4141

4242
// Needs for some velocity methods
43-
compileOnly("io.netty:netty-codec:4.1.70.Final")
43+
compileOnly("io.netty:netty-codec:4.1.72.Final")
4444

45-
compileOnly("com.github.spotbugs:spotbugs-annotations:4.5.0")
45+
compileOnly("com.github.spotbugs:spotbugs-annotations:4.5.2")
4646
}
4747

4848
license {
49-
header = project.rootProject.file("HEADER.txt")
49+
setHeader(file("HEADER.txt"))
5050
}
5151

5252
checkstyle {
53-
toolVersion "9.0.1"
54-
configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml")
55-
configProperties = [configDirectory: "${project.rootDir}/config/checkstyle"]
53+
setToolVersion("9.2")
54+
setConfigFile(file("${this.getRootDir()}/config/checkstyle/checkstyle.xml"))
55+
setConfigProperties("configDirectory": "${this.getRootDir()}/config/checkstyle")
5656

5757
// The build should immediately fail if we have errors.
58-
maxErrors = 0
59-
maxWarnings = 0
58+
setMaxErrors(0)
59+
setMaxWarnings(0)
6060
}
6161

62-
tasks.withType(SpotBugsTask) {
62+
spotbugsMain {
63+
setExcludeFilter(file("${this.getRootDir()}/config/spotbugs/suppressions.xml"))
64+
6365
reports {
6466
html {
65-
enabled = true
66-
destination = file("$buildDir/reports/spotbugs/main/spotbugs.html")
67-
stylesheet = "fancy-hist.xsl"
67+
getRequired().set(true)
68+
getOutputLocation().set(file("${this.getBuildDir()}/reports/spotbugs/main/spotbugs.html"))
69+
setStylesheet("fancy-hist.xsl")
6870
}
6971
}
7072
}
7173

72-
sourceSets.main.java.srcDir(tasks.register("generateTemplates", Copy) { task ->
73-
task.inputs.properties "version": project.version
74+
sourceSets.main.getJava().srcDir(getTasks().register("generateTemplates", Copy) { task ->
75+
task.getInputs().properties("version": getVersion())
7476

75-
task.from file("src/main/templates")
76-
task.into layout.buildDirectory.dir("../build/generated/sources/templates")
77-
task.expand "version": project.version
77+
task.from(file("src/main/templates"))
78+
.into(getLayout().getBuildDirectory().dir("generated/sources/templates"))
79+
.expand("version": getVersion())
7880
}.map {
79-
it.outputs
81+
it.getOutputs()
8082
})

‎config/spotbugs/suppressions.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<FindBugsFilter>
4+
<Match>
5+
<Bug pattern="EI_EXPOSE_REP"/>
6+
</Match>
7+
<Match>
8+
<Bug pattern="EI_EXPOSE_REP2"/>
9+
</Match>
10+
</FindBugsFilter>

‎settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name = "limbofilter"
1+
getRootProject().setName("limbofilter")

‎src/main/java/net/elytrium/limbofilter/LimboFilter.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.velocitypowered.api.plugin.annotation.DataDirectory;
2929
import com.velocitypowered.api.proxy.Player;
3030
import com.velocitypowered.api.proxy.ProxyServer;
31-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3231
import java.io.File;
3332
import java.io.IOException;
3433
import java.net.InetAddress;
@@ -46,7 +45,7 @@
4645
import net.elytrium.limbofilter.cache.CachedPackets;
4746
import net.elytrium.limbofilter.cache.captcha.CachedCaptcha;
4847
import net.elytrium.limbofilter.commands.LimboFilterCommand;
49-
import net.elytrium.limbofilter.generator.CaptchaGeneration;
48+
import net.elytrium.limbofilter.captcha.CaptchaGenerator;
5049
import net.elytrium.limbofilter.handler.BotFilterSessionHandler;
5150
import net.elytrium.limbofilter.listener.FilterListener;
5251
import net.elytrium.limbofilter.stats.Statistics;
@@ -61,7 +60,6 @@
6160
authors = {"hevav", "mdxd44"},
6261
dependencies = {@Dependency(id = "limboapi")}
6362
)
64-
@SuppressFBWarnings("EI_EXPOSE_REP")
6563
public class LimboFilter {
6664

6765
private static LimboFilter instance;
@@ -101,12 +99,13 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
10199
public void reload() {
102100
Settings.IMP.reload(new File(this.dataDirectory.toFile().getAbsoluteFile(), "config.yml"));
103101

104-
BotFilterSessionHandler.reload();
102+
BotFilterSessionHandler.FALLING_CHECK_TOTAL_TIME = Settings.IMP.MAIN.FALLING_CHECK_TICKS * 50L;
105103

106104
this.statistics.startUpdating();
107105

108106
this.cachedCaptcha = new CachedCaptcha();
109-
CaptchaGeneration.init();
107+
CaptchaGenerator.init();
108+
110109
this.packets.createPackets(this.getFactory());
111110

112111
this.cachedFilterChecks = new ConcurrentHashMap<>();
@@ -184,7 +183,7 @@ public boolean shouldCheck(String nickname, InetAddress ip) {
184183
}
185184
}
186185

187-
public void filter(Player player) {
186+
public void sendToFilterServer(Player player) {
188187
try {
189188
this.filterServer.spawnPlayer(player, new BotFilterSessionHandler(player, this));
190189
} catch (Throwable t) {
@@ -223,6 +222,10 @@ public static LimboFilter getInstance() {
223222
return instance;
224223
}
225224

225+
public ProxyServer getServer() {
226+
return this.server;
227+
}
228+
226229
public Logger getLogger() {
227230
return this.logger;
228231
}

‎src/main/java/net/elytrium/limbofilter/Settings.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public static class MAIN {
4848
public int CAPTCHA_ATTEMPTS = 2;
4949
@Comment("Duration of Falling Check in Minecraft ticks (1 tick = 0.05 second, 20 ticks = 1 second).")
5050
public int FALLING_CHECK_TICKS = 128;
51+
@Comment("Maximum time to check the player in milliseconds. If the player stays on the filter limbo for longer than this time, then the check will fail.")
52+
public int TIME_OUT = 15000;
5153
@Comment("Change the parameters below only if you know what they mean.")
5254
public int NON_VALID_POSITION_XZ_ATTEMPTS = 10;
5355
public int NON_VALID_POSITION_Y_ATTEMPTS = 10;
@@ -164,12 +166,15 @@ public static class CAPTCHA_GENERATOR {
164166
@Create
165167
public MAIN.STRINGS STRINGS;
166168

167-
@Comment("Leave titles empty to disable.")
169+
@Comment("Leave title fields empty to disable.")
168170
public static class STRINGS {
169171

170172
public String RELOAD = "{PRFX} &aReloaded successfully!";
171173
public String RELOAD_FAILED = "{PRFX} &cReload failed, check console for details.";
172174

175+
public String CLIENT_SETTINGS_KICK = "{PRFX}{NL}&cYour client doesn't send settings packets.";
176+
public String CLIENT_BRAND_KICK = "{PRFX}{NL}&cYour client doesn't send brand packet or it's blocked.";
177+
173178
public String CHECKING_CHAT = "{PRFX} Bot-Filter check was started, please wait and don't move..";
174179
public String CHECKING_TITLE = "{PRFX}";
175180
public String CHECKING_SUBTITLE = "&aPlease wait..";
@@ -180,17 +185,15 @@ public static class STRINGS {
180185
public String CHECKING_CAPTCHA_SUBTITLE = "&aYou have &6{0} &aattempts.";
181186

182187
public String SUCCESSFUL_CRACKED = "{PRFX} &aSuccessfully passed Bot-Filter check.";
183-
public String SUCCESSFUL_PREMIUM = "{PRFX} &aSuccessfully passed Bot-Filter check.{NL}&6Please, rejoin the server!";
188+
public String SUCCESSFUL_PREMIUM_KICK = "{PRFX}{NL}&aSuccessfully passed Bot-Filter check.{NL}&6Please, rejoin the server!";
184189

185-
public String CAPTCHA_FAILED = "{PRFX} &cYou've mistaken in captcha check.{NL}&6Please, rejoin the server.";
186-
public String FALLING_CHECK_FAILED = "{PRFX} &cFalling Check was failed.{NL}&6Please, rejoin the server.";
190+
public String CAPTCHA_FAILED_KICK = "{PRFX}{NL}&cYou've mistaken in captcha check.{NL}&6Please, rejoin the server.";
191+
public String FALLING_CHECK_FAILED_KICK = "{PRFX}{NL}&cFalling Check was failed.{NL}&6Please, rejoin the server.";
192+
public String TIMES_UP = "{PRFX}{NL}&cВы не успели пройти проверку за отведённое время.{NL}&6Please, rejoin the server.";
187193

188194
public String STATS_FORMAT = "&c&lTotal Blocked: &6&l{0} &c&l| Connections: &6&l{1} &c&l| Pings: &6&l{2} &c&l| Total Connections: &6&l{3} &c&l| Ping: &6&l{4}";
189195
public String STATS_ENABLED = "{PRFX} &aNow you see statistics in your action bar.";
190196
public String STATS_DISABLED = "{PRFX} &cYou're no longer see statistics in your action bar.";
191-
192-
public String KICK_CLIENT_CHECK_SETTINGS = "{NL}{NL}&cYour client doesn't send settings packets.";
193-
public String KICK_CLIENT_CHECK_BRAND = "{NL}{NL}&cYour client doesn't send brand packet or it's blocked.";
194197
}
195198

196199
@Create

‎src/main/java/net/elytrium/limbofilter/cache/CachedPackets.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.velocitypowered.proxy.protocol.packet.Chat;
2424
import com.velocitypowered.proxy.protocol.packet.Disconnect;
2525
import com.velocitypowered.proxy.protocol.packet.title.GenericTitlePacket;
26-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2726
import java.util.ArrayList;
2827
import java.util.List;
2928
import net.elytrium.limboapi.api.LimboFactory;
@@ -32,17 +31,16 @@
3231
import net.elytrium.limboapi.api.protocol.PreparedPacket;
3332
import net.elytrium.limboapi.api.protocol.packets.BuiltInPackets;
3433
import net.elytrium.limbofilter.Settings;
35-
import net.elytrium.limbofilter.handler.BotFilterSessionHandler;
3634
import net.kyori.adventure.nbt.CompoundBinaryTag;
3735
import net.kyori.adventure.nbt.IntBinaryTag;
3836
import net.kyori.adventure.text.Component;
3937
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
4038

41-
@SuppressFBWarnings("EI_EXPOSE_REP")
4239
public class CachedPackets {
4340

4441
private PreparedPacket captchaFailed;
4542
private PreparedPacket fallingCheckFailed;
43+
private PreparedPacket timesUp;
4644
private PreparedPacket setSlot;
4745
private PreparedPacket resetSlot;
4846
private PreparedPacket checkingChat;
@@ -57,8 +55,9 @@ public class CachedPackets {
5755
public void createPackets(LimboFactory factory) {
5856
Settings.MAIN.STRINGS strings = Settings.IMP.MAIN.STRINGS;
5957

60-
this.captchaFailed = this.createDisconnectPacket(factory, strings.CAPTCHA_FAILED);
61-
this.fallingCheckFailed = this.createDisconnectPacket(factory, strings.FALLING_CHECK_FAILED);
58+
this.captchaFailed = this.createDisconnectPacket(factory, strings.CAPTCHA_FAILED_KICK);
59+
this.fallingCheckFailed = this.createDisconnectPacket(factory, strings.FALLING_CHECK_FAILED_KICK);
60+
this.timesUp = this.createDisconnectPacket(factory, strings.TIMES_UP);
6261

6362
this.setSlot = factory.createPreparedPacket()
6463
.prepare(
@@ -75,11 +74,11 @@ public void createPackets(LimboFactory factory) {
7574
this.checkingChat = this.createChatPacket(factory, strings.CHECKING_CHAT);
7675
this.checkingTitle = this.createTitlePacket(factory, strings.CHECKING_TITLE, strings.CHECKING_SUBTITLE);
7776

78-
this.kickClientCheckSettings = this.createDisconnectPacket(factory, strings.KICK_CLIENT_CHECK_SETTINGS);
79-
this.kickClientCheckBrand = this.createDisconnectPacket(factory, strings.KICK_CLIENT_CHECK_BRAND);
77+
this.kickClientCheckSettings = this.createDisconnectPacket(factory, strings.CLIENT_SETTINGS_KICK);
78+
this.kickClientCheckBrand = this.createDisconnectPacket(factory, strings.CLIENT_BRAND_KICK);
8079

8180
this.successfulBotFilterChat = this.createChatPacket(factory, strings.SUCCESSFUL_CRACKED);
82-
this.successfulBotFilterDisconnect = this.createDisconnectPacket(factory, strings.SUCCESSFUL_PREMIUM);
81+
this.successfulBotFilterDisconnect = this.createDisconnectPacket(factory, strings.SUCCESSFUL_PREMIUM_KICK);
8382

8483
this.noAbilities = this.createAbilitiesPacket(factory);
8584
this.experience = this.createExpPackets(factory);
@@ -91,7 +90,7 @@ private PreparedPacket createAbilitiesPacket(LimboFactory factory) {
9190

9291
private List<PreparedPacket> createExpPackets(LimboFactory factory) {
9392
List<PreparedPacket> packets = new ArrayList<>();
94-
long ticks = BotFilterSessionHandler.getTotalTicks();
93+
long ticks = Settings.IMP.MAIN.FALLING_CHECK_TICKS;
9594
float expInterval = 0.01F;
9695
for (int i = 0; i < ticks; ++i) {
9796
int percentage = (int) (i * 100 / ticks);
@@ -150,8 +149,8 @@ public PreparedPacket createTitlePacket(LimboFactory factory, String title, Stri
150149
preparedPacket.prepare((version) -> {
151150
GenericTitlePacket packet = GenericTitlePacket.constructTitlePacket(GenericTitlePacket.ActionType.SET_TIMES, version);
152151
packet.setFadeIn(10);
153-
packet.setStay(50);
154-
packet.setFadeOut(10);
152+
packet.setStay(70);
153+
packet.setFadeOut(20);
155154
return packet;
156155
}, ProtocolVersion.MINECRAFT_1_8);
157156
}
@@ -167,6 +166,10 @@ public PreparedPacket getFallingCheckFailed() {
167166
return this.fallingCheckFailed;
168167
}
169168

169+
public PreparedPacket getTimesUp() {
170+
return this.timesUp;
171+
}
172+
170173
public PreparedPacket getSetSlot() {
171174
return this.setSlot;
172175
}

‎src/main/java/net/elytrium/limbofilter/cache/captcha/CaptchaHandler.java

-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
import com.velocitypowered.api.network.ProtocolVersion;
2121
import com.velocitypowered.proxy.protocol.MinecraftPacket;
22-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2322
import net.elytrium.limboapi.api.protocol.PreparedPacket;
2423

25-
@SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
2624
public class CaptchaHandler {
2725

2826
private final MinecraftPacket mapPacket;

‎src/main/java/net/elytrium/limbofilter/generator/CaptchaGeneration.java ‎src/main/java/net/elytrium/limbofilter/captcha/CaptchaGenerator.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package net.elytrium.limbofilter.generator;
18+
package net.elytrium.limbofilter.captcha;
1919

2020
import com.velocitypowered.proxy.protocol.MinecraftPacket;
2121
import java.awt.Color;
@@ -38,11 +38,11 @@
3838
import net.elytrium.limboapi.api.protocol.packets.BuiltInPackets;
3939
import net.elytrium.limbofilter.LimboFilter;
4040
import net.elytrium.limbofilter.Settings;
41-
import net.elytrium.limbofilter.generator.map.CraftMapCanvas;
42-
import net.elytrium.limbofilter.generator.painter.CaptchaPainter;
41+
import net.elytrium.limbofilter.captcha.map.CraftMapCanvas;
42+
import net.elytrium.limbofilter.captcha.painter.CaptchaPainter;
4343
import org.slf4j.Logger;
4444

45-
public class CaptchaGeneration {
45+
public class CaptchaGenerator {
4646

4747
private static final CraftMapCanvas cachedBackgroundMap = new CraftMapCanvas();
4848
private static final LimboFilter plugin = LimboFilter.getInstance();
@@ -98,14 +98,14 @@ public static void init() {
9898
});
9999
}
100100

101-
new Thread(CaptchaGeneration::generateImages).start();
101+
new Thread(CaptchaGenerator::generateImages).start();
102102
}
103103

104104
@SuppressWarnings("StatementWithEmptyBody")
105105
public static void generateImages() {
106106
ThreadPoolExecutor ex = (ThreadPoolExecutor) Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
107107
for (int i = 100; i <= 999; ++i) {
108-
ex.execute(CaptchaGeneration::genNewPacket);
108+
ex.execute(CaptchaGenerator::genNewPacket);
109109
}
110110

111111
long start = System.currentTimeMillis();

‎src/main/java/net/elytrium/limbofilter/generator/map/CraftMapCanvas.java ‎src/main/java/net/elytrium/limbofilter/captcha/map/CraftMapCanvas.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package net.elytrium.limbofilter.generator.map;
18+
package net.elytrium.limbofilter.captcha.map;
1919

20-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2120
import java.awt.image.BufferedImage;
2221
import java.util.Arrays;
2322
import java.util.concurrent.ThreadLocalRandom;
2423
import net.elytrium.limboapi.api.protocol.map.MapPalette;
2524
import net.elytrium.limboapi.api.protocol.packets.data.MapData;
2625

27-
@SuppressFBWarnings("EI_EXPOSE_REP")
2826
public class CraftMapCanvas {
2927

3028
private static final int MAP_SIZE = 16384; // 128 x 128

‎src/main/java/net/elytrium/limbofilter/generator/painter/CaptchaPainter.java ‎src/main/java/net/elytrium/limbofilter/captcha/painter/CaptchaPainter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package net.elytrium.limbofilter.generator.painter;
18+
package net.elytrium.limbofilter.captcha.painter;
1919

2020
import java.awt.Color;
2121
import java.awt.Font;

‎src/main/java/net/elytrium/limbofilter/generator/painter/Rippler.java ‎src/main/java/net/elytrium/limbofilter/captcha/painter/Rippler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package net.elytrium.limbofilter.generator.painter;
18+
package net.elytrium.limbofilter.captcha.painter;
1919

2020

2121
import java.awt.image.BufferedImage;

‎src/main/java/net/elytrium/limbofilter/handler/BotFilterSessionHandler.java

+61-59
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919

2020
import com.velocitypowered.api.network.ProtocolVersion;
2121
import com.velocitypowered.api.proxy.Player;
22+
import com.velocitypowered.api.scheduler.ScheduledTask;
2223
import com.velocitypowered.proxy.protocol.MinecraftPacket;
2324
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
2425
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
2526
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
26-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2727
import java.text.MessageFormat;
2828
import java.util.List;
29+
import java.util.concurrent.TimeUnit;
2930
import net.elytrium.limboapi.api.Limbo;
3031
import net.elytrium.limboapi.api.LimboFactory;
3132
import net.elytrium.limboapi.api.chunk.VirtualChunk;
@@ -39,14 +40,11 @@
3940
import net.elytrium.limbofilter.stats.Statistics;
4041
import org.slf4j.Logger;
4142

42-
@SuppressFBWarnings("EI_EXPOSE_REP2")
4343
public class BotFilterSessionHandler extends FallingCheckHandler {
4444

45-
private static long TOTAL_TICKS;
46-
private static double CAPTCHA_Y;
47-
private static long TOTAL_TIME;
45+
public static long FALLING_CHECK_TOTAL_TIME;
4846

49-
private final Player player;
47+
private final Player proxyPlayer;
5048
private final LimboFilter plugin;
5149
private final Statistics statistics;
5250
private final Logger logger;
@@ -56,22 +54,24 @@ public class BotFilterSessionHandler extends FallingCheckHandler {
5654
private final MinecraftPacket fallingCheckChunk;
5755
private final MinecraftPacket fallingCheckView;
5856

57+
private final long joinTime = System.currentTimeMillis();
58+
private ScheduledTask filterMainTask;
59+
5960
private CheckState state = CheckState.valueOf(Settings.IMP.MAIN.CHECK_STATE);
60-
private LimboPlayer limboPlayer;
61+
private LimboPlayer player;
6162
private Limbo server;
6263
private String captchaAnswer;
6364
private int attempts = Settings.IMP.MAIN.CAPTCHA_ATTEMPTS;
6465
private int ignoredTicks = 0;
6566
private int nonValidPacketsSize = 0;
66-
private long joinTime = System.currentTimeMillis();
6767
private boolean startedListening = false;
6868
private boolean checkedBySettings = false;
6969
private boolean checkedByBrand = false;
7070

71-
public BotFilterSessionHandler(Player player, LimboFilter plugin) {
72-
super(player.getProtocolVersion());
71+
public BotFilterSessionHandler(Player proxyPlayer, LimboFilter plugin) {
72+
super(proxyPlayer.getProtocolVersion());
7373

74-
this.player = player;
74+
this.proxyPlayer = proxyPlayer;
7575
this.plugin = plugin;
7676

7777
this.statistics = this.plugin.getStatistics();
@@ -94,24 +94,31 @@ public BotFilterSessionHandler(Player player, LimboFilter plugin) {
9494
@Override
9595
public void onSpawn(Limbo server, LimboPlayer player) {
9696
this.server = server;
97-
this.limboPlayer = player;
97+
this.player = player;
9898

9999
if (this.state == CheckState.ONLY_CAPTCHA) {
100100
this.sendCaptcha();
101101
} else if (this.state == CheckState.CAPTCHA_POSITION) {
102102
this.sendFallingCheckPackets();
103103
this.sendCaptcha();
104104
} else if (this.state == CheckState.ONLY_POSITION || this.state == CheckState.CAPTCHA_ON_POSITION_FAILED) {
105-
if (this.player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
105+
if (this.proxyPlayer.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
106106
if (!Settings.IMP.MAIN.STRINGS.CHECKING_TITLE.isEmpty() && !Settings.IMP.MAIN.STRINGS.CHECKING_SUBTITLE.isEmpty()) {
107-
this.limboPlayer.writePacket(this.packets.getCheckingTitle());
107+
this.player.writePacket(this.packets.getCheckingTitle());
108108
}
109109
}
110-
this.limboPlayer.writePacket(this.packets.getCheckingChat());
110+
this.player.writePacket(this.packets.getCheckingChat());
111111
this.sendFallingCheckPackets();
112112
}
113113

114-
this.limboPlayer.flushPackets();
114+
this.player.flushPackets();
115+
116+
this.filterMainTask = this.plugin.getServer().getScheduler().buildTask(this.plugin, () -> {
117+
// TODO: Maybe check for max ping?
118+
if (System.currentTimeMillis() - BotFilterSessionHandler.this.joinTime > Settings.IMP.MAIN.TIME_OUT) {
119+
BotFilterSessionHandler.this.disconnect(BotFilterSessionHandler.this.packets.getTimesUp(), true);
120+
}
121+
}).delay(1, TimeUnit.SECONDS).repeat(1, TimeUnit.SECONDS).schedule();
115122
}
116123

117124
@Override
@@ -129,7 +136,7 @@ public void onMove() {
129136
++this.nonValidPacketsSize;
130137
}
131138
if (this.startedListening && this.state != CheckState.SUCCESSFUL) {
132-
if (this.lastY == CAPTCHA_Y || this.onGround) {
139+
if (this.lastY == Settings.IMP.MAIN.COORDS.CAPTCHA_Y || this.onGround) {
133140
return;
134141
}
135142
if (this.state == CheckState.ONLY_CAPTCHA) {
@@ -142,7 +149,7 @@ public void onMove() {
142149
++this.ignoredTicks;
143150
return;
144151
}
145-
if (this.ticks >= TOTAL_TICKS) {
152+
if (this.ticks >= Settings.IMP.MAIN.FALLING_CHECK_TICKS) {
146153
if (this.state == CheckState.CAPTCHA_POSITION) {
147154
this.changeStateToCaptcha();
148155
} else {
@@ -168,7 +175,7 @@ public void onMove() {
168175
}
169176
PreparedPacket expBuf = this.packets.getExperience().get(this.ticks);
170177
if (expBuf != null) {
171-
this.limboPlayer.writePacketAndFlush(expBuf);
178+
this.player.writePacketAndFlush(expBuf);
172179
}
173180

174181
++this.ticks;
@@ -179,7 +186,7 @@ public void onMove() {
179186
public void onChat(String message) {
180187
if ((this.state == CheckState.CAPTCHA_POSITION || this.state == CheckState.ONLY_CAPTCHA)) {
181188
if (message.equals(this.captchaAnswer)) {
182-
this.limboPlayer.writePacketAndFlush(this.packets.getResetSlot());
189+
this.player.writePacketAndFlush(this.packets.getResetSlot());
183190
this.finishCheck();
184191
} else if (--this.attempts != 0) {
185192
this.sendCaptcha();
@@ -195,21 +202,26 @@ public void onGeneric(Object packet) {
195202
PluginMessage pluginMessage = (PluginMessage) packet;
196203
if (PluginMessageUtil.isMcBrand(pluginMessage) && !this.checkedByBrand) {
197204
String brand = PluginMessageUtil.readBrandMessage(pluginMessage.content());
198-
this.logger.info("{} has client brand {}", this.player, brand);
205+
this.logger.info("{} has client brand {}", this.proxyPlayer, brand);
199206
if (!Settings.IMP.MAIN.BLOCKED_CLIENT_BRANDS.contains(brand)) {
200207
this.checkedByBrand = true;
201208
}
202209
}
203210
} else if (packet instanceof ClientSettings) {
204-
if (!this.checkedBySettings && Settings.IMP.MAIN.CHECK_CLIENT_SETTINGS) {
211+
if (Settings.IMP.MAIN.CHECK_CLIENT_SETTINGS && !this.checkedBySettings) {
205212
this.checkedBySettings = true;
206213
}
207214
}
208215
}
209216

217+
@Override
218+
public void onDisconnect() {
219+
this.filterMainTask.cancel();
220+
}
221+
210222
private void finishCheck() {
211-
if (System.currentTimeMillis() - this.joinTime < TOTAL_TIME && this.state != CheckState.ONLY_CAPTCHA) {
212-
if (this.state == CheckState.CAPTCHA_POSITION && this.ticks < TOTAL_TICKS) {
223+
if (System.currentTimeMillis() - this.joinTime < FALLING_CHECK_TOTAL_TIME && this.state != CheckState.ONLY_CAPTCHA) {
224+
if (this.state == CheckState.CAPTCHA_POSITION && this.ticks < Settings.IMP.MAIN.FALLING_CHECK_TICKS) {
213225
this.state = CheckState.ONLY_POSITION;
214226
} else {
215227
if (this.state == CheckState.CAPTCHA_ON_POSITION_FAILED) {
@@ -221,70 +233,72 @@ private void finishCheck() {
221233
return;
222234
}
223235

224-
if (!this.checkedBySettings && Settings.IMP.MAIN.CHECK_CLIENT_SETTINGS) {
236+
if (Settings.IMP.MAIN.CHECK_CLIENT_SETTINGS && !this.checkedBySettings) {
225237
this.disconnect(this.packets.getKickClientCheckSettings(), true);
226238
}
227-
if (!this.checkedByBrand && Settings.IMP.MAIN.CHECK_CLIENT_BRAND) {
239+
if (Settings.IMP.MAIN.CHECK_CLIENT_BRAND && !this.checkedByBrand) {
228240
this.disconnect(this.packets.getKickClientCheckBrand(), true);
229241
}
230242

231243
this.state = CheckState.SUCCESSFUL;
232-
this.plugin.cacheFilterUser(this.player);
244+
this.plugin.cacheFilterUser(this.proxyPlayer);
233245

234246
if (this.plugin.checkCpsLimit(Settings.IMP.MAIN.FILTER_AUTO_TOGGLE.ONLINE_MODE_VERIFY)
235247
|| this.plugin.checkCpsLimit(Settings.IMP.MAIN.FILTER_AUTO_TOGGLE.NEED_TO_RECONNECT)) {
236248
this.disconnect(this.packets.getSuccessfulBotFilterDisconnect(), false);
237249
} else {
238-
this.limboPlayer.writePacketAndFlush(this.packets.getSuccessfulBotFilterChat());
239-
this.limboPlayer.disconnect();
250+
this.player.writePacketAndFlush(this.packets.getSuccessfulBotFilterChat());
251+
this.player.disconnect();
240252
}
241253
}
242254

243255
private void sendFallingCheckPackets() {
244-
this.limboPlayer.writePacket(this.fallingCheckPos);
245-
if (this.player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
246-
this.limboPlayer.writePacket(this.fallingCheckView);
256+
this.player.writePacket(this.fallingCheckPos);
257+
if (this.proxyPlayer.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
258+
this.player.writePacket(this.fallingCheckView);
247259
}
248260

249-
this.limboPlayer.writePacket(this.fallingCheckChunk);
261+
this.player.writePacket(this.fallingCheckChunk);
250262
}
251263

252264
private void sendCaptcha() {
253-
ProtocolVersion version = this.player.getProtocolVersion();
265+
ProtocolVersion version = this.proxyPlayer.getProtocolVersion();
254266
CaptchaHandler captchaHandler = this.plugin.getCachedCaptcha().randomCaptcha();
255267
String captchaAnswer = captchaHandler.getAnswer();
256268
this.setCaptchaAnswer(captchaAnswer);
257269
Settings.MAIN.STRINGS strings = Settings.IMP.MAIN.STRINGS;
258270
if (this.attempts == Settings.IMP.MAIN.CAPTCHA_ATTEMPTS) {
259-
this.limboPlayer.writePacket(
271+
this.player.writePacket(
260272
this.packets.createChatPacket(this.plugin.getFactory(), MessageFormat.format(strings.CHECKING_CAPTCHA_CHAT, this.attempts))
261273
);
262274
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
263275
if (!strings.CHECKING_CAPTCHA_TITLE.isEmpty() && !strings.CHECKING_CAPTCHA_SUBTITLE.isEmpty()) {
264-
this.limboPlayer.writePacket(
276+
this.player.writePacket(
265277
this.packets.createTitlePacket(
266-
this.plugin.getFactory(), strings.CHECKING_CAPTCHA_TITLE, MessageFormat.format(strings.CHECKING_CAPTCHA_SUBTITLE, this.attempts)
278+
this.plugin.getFactory(),
279+
MessageFormat.format(strings.CHECKING_CAPTCHA_TITLE, this.attempts),
280+
MessageFormat.format(strings.CHECKING_CAPTCHA_SUBTITLE, this.attempts)
267281
)
268282
);
269283
}
270284
}
271285
} else {
272-
this.limboPlayer.writePacket(
286+
this.player.writePacket(
273287
this.packets.createChatPacket(this.plugin.getFactory(), MessageFormat.format(strings.CHECKING_WRONG_CAPTCHA_CHAT, this.attempts))
274288
);
275289
}
276-
this.limboPlayer.writePacket(this.packets.getSetSlot());
290+
this.player.writePacket(this.packets.getSetSlot());
277291
for (Object packet : captchaHandler.getMapPacket(version)) {
278-
this.limboPlayer.writePacket(packet);
292+
this.player.writePacket(packet);
279293
}
280294

281-
this.limboPlayer.flushPackets();
295+
this.player.flushPackets();
282296
}
283297

284298
private void fallingCheckFailed() {
285299
if (this.state == CheckState.CAPTCHA_ON_POSITION_FAILED) {
286300
List<PreparedPacket> expList = this.packets.getExperience();
287-
this.limboPlayer.writePacketAndFlush(expList.get(expList.size() - 1));
301+
this.player.writePacketAndFlush(expList.get(expList.size() - 1));
288302
this.changeStateToCaptcha();
289303
return;
290304
}
@@ -293,7 +307,7 @@ private void fallingCheckFailed() {
293307
}
294308

295309
private void disconnect(PreparedPacket reason, boolean blocked) {
296-
this.limboPlayer.closeWith(reason);
310+
this.player.closeWith(reason);
297311
if (blocked) {
298312
this.statistics.addBlockedConnection();
299313
}
@@ -304,8 +318,8 @@ private boolean checkY() {
304318
}
305319

306320
private void setCaptchaPositionAndDisableFalling() {
307-
this.server.respawnPlayer(this.player);
308-
this.limboPlayer.writePacketAndFlush(this.packets.getNoAbilities());
321+
this.server.respawnPlayer(this.proxyPlayer);
322+
this.player.writePacketAndFlush(this.packets.getNoAbilities());
309323

310324
this.waitingTeleportId = this.validTeleportId;
311325
}
@@ -316,7 +330,7 @@ public void setCaptchaAnswer(String captchaAnswer) {
316330

317331
private void changeStateToCaptcha() {
318332
this.state = CheckState.ONLY_CAPTCHA;
319-
this.joinTime = System.currentTimeMillis() + TOTAL_TIME;
333+
//this.joinTime = System.currentTimeMillis() + this.fallingCheckTotalTime;
320334
this.setCaptchaPositionAndDisableFalling();
321335
if (this.captchaAnswer == null) {
322336
this.sendCaptcha();
@@ -336,24 +350,12 @@ private MinecraftPacket createUpdateViewPosition(LimboFactory factory, int x, in
336350
return (MinecraftPacket) factory.instantiatePacket(BuiltInPackets.UpdateViewPosition, x >> 4, z >> 4);
337351
}
338352

339-
public static void reload() {
340-
TOTAL_TICKS = Settings.IMP.MAIN.FALLING_CHECK_TICKS;
341-
TOTAL_TIME = (TOTAL_TICKS * 50) - 100;
342-
CAPTCHA_Y = Settings.IMP.MAIN.COORDS.CAPTCHA_Y;
343-
}
344-
345-
public static long getTotalTicks() {
346-
return TOTAL_TICKS;
347-
}
348-
349-
@SuppressWarnings("unused")
350353
public enum CheckState {
351354

352355
ONLY_POSITION,
353356
ONLY_CAPTCHA,
354357
CAPTCHA_POSITION,
355358
CAPTCHA_ON_POSITION_FAILED,
356-
SUCCESSFUL,
357-
FAILED
359+
SUCCESSFUL
358360
}
359361
}

‎src/main/java/net/elytrium/limbofilter/handler/FallingCheckHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class FallingCheckHandler implements LimboSessionHandler {
3838
public double posY;
3939
public double posZ;
4040
public boolean onGround = false;
41-
public int waitingTeleportId = 9876;
41+
public int waitingTeleportId;
4242
public double lastY;
4343
public int validX;
4444
public int validY;
@@ -54,7 +54,7 @@ public FallingCheckHandler(ProtocolVersion version) {
5454
ThreadLocalRandom rnd = ThreadLocalRandom.current();
5555
this.validX = rnd.nextInt(256, 16384);
5656
// See https://media.discordapp.net/attachments/878241549857738793/915165038464098314/unknown.png
57-
this.validY = rnd.nextInt(256 + (this.version.compareTo(ProtocolVersion.MINECRAFT_1_8) < 0 ? 150 : 0), 512);
57+
this.validY = rnd.nextInt(256 + (this.version.compareTo(ProtocolVersion.MINECRAFT_1_8) < 0 ? 200 : 0), 512);
5858
this.validZ = rnd.nextInt(256, 16384);
5959
this.validTeleportId = rnd.nextInt(65535);
6060

‎src/main/java/net/elytrium/limbofilter/listener/FilterListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void onProxyConnect(PreLoginEvent event) {
4646
@Subscribe(order = PostOrder.FIRST)
4747
public void onLogin(LoginLimboRegisterEvent event) {
4848
if (this.plugin.shouldCheck(event.getPlayer())) {
49-
event.addCallback(() -> this.plugin.filter(event.getPlayer()));
49+
event.addCallback(() -> this.plugin.sendToFilterServer(event.getPlayer()));
5050
}
5151
}
5252

‎src/main/java/net/elytrium/limbofilter/utils/UpdatesChecker.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@ public static void checkForUpdates(Logger logger) {
4343
}
4444
String latestVersion0 = getCleanVersion(latestVersion.trim());
4545
String currentVersion0 = getCleanVersion(Settings.IMP.VERSION);
46-
int latestVersionID = Integer.parseInt(latestVersion0.replace(".", "").replace("$", ""));
47-
int currentVersionID = Integer.parseInt(currentVersion0.replace(".", "").replace("$", ""));
46+
int latestVersionId = Integer.parseInt(latestVersion0.replace(".", "").replace("$", ""));
47+
int currentVersionId = Integer.parseInt(currentVersion0.replace(".", "").replace("$", ""));
4848
if (latestVersion0.endsWith("$")) {
49-
--latestVersionID;
49+
--latestVersionId;
5050
}
5151
if (currentVersion0.endsWith("$")) {
52-
--currentVersionID;
52+
--currentVersionId;
5353
}
5454

55-
if (currentVersionID < latestVersionID) {
55+
if (currentVersionId < latestVersionId) {
5656
logger.error("****************************************");
5757
logger.warn("The new LimboFilter update was found, please update.");
5858
logger.error("https://github.com/Elytrium/LimboFilter/releases/");
5959
logger.error("****************************************");
6060
}
6161
}
62-
} catch (IOException ex) {
63-
logger.warn("Unable to check for updates.", ex);
62+
} catch (IOException e) {
63+
logger.warn("Unable to check for updates.", e);
6464
}
6565
}
6666

0 commit comments

Comments
 (0)
Please sign in to comment.