mirror of
https://github.com/xoo0524tw/OpenFlameCord.git
synced 2026-12-05 22:16:01 +02:00
Initial import of FlameCord 2.7.1
This commit is contained in:
commit
5f9eb0ebc1
958 files changed
+112127
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
* text=auto
|
||||||
|
src/main/resources/** -text
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
/target/
|
||||||
|
/analysis/
|
||||||
|
/tests/
|
||||||
|
/.idea/*
|
||||||
|
!/.idea/misc.xml
|
||||||
|
!/.idea/encodings.xml
|
||||||
|
/.run/*
|
||||||
|
!/.run/FlameCord Package.run.xml
|
||||||
|
/*.jar
|
||||||
|
*.iml
|
||||||
|
/logs/
|
||||||
|
/plugins/
|
||||||
|
/modules/
|
||||||
|
/whitelist/
|
||||||
|
/out/
|
||||||
|
/*.yml
|
||||||
|
/*.log
|
||||||
|
/.env
|
||||||
|
/.env.*
|
||||||
|
/.agents/
|
||||||
|
/.codex/
|
||||||
|
/.opencode/
|
||||||
|
/.serena/
|
||||||
|
/AGENTS.md
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" />
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="FlameCord Package" type="MavenRunConfiguration" factoryName="Maven">
|
||||||
|
<MavenSettings>
|
||||||
|
<option name="myRunnerParameters">
|
||||||
|
<MavenRunnerParameters>
|
||||||
|
<option name="goals">
|
||||||
|
<list>
|
||||||
|
<option value="clean" />
|
||||||
|
<option value="package" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="workingDirPath" value="$PROJECT_DIR$" />
|
||||||
|
</MavenRunnerParameters>
|
||||||
|
</option>
|
||||||
|
</MavenSettings>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# FlameCord 2.7.1
|
||||||
|
|
||||||
|
FlameCord 是以 Waterfall/BungeeCord 為基礎的 Minecraft Java 版代理伺服器。玩家先連到代理,再由代理分流至後端伺服器。FlameCord 在這層加入機器人流量過濾、登入檢查與連線管理。本專案從 2.7.1 發行版 JAR 重建 Java 原始碼、執行資源與 Maven 建置。
|
||||||
|
|
||||||
|
## 原始混淆與重建
|
||||||
|
|
||||||
|
原始 JAR 的主要套件、類別與方法仍保留可辨識的名稱,例如 `FlameCord`、`CheckManager` 與 `PacketsCheck`。就可辨識的符號而言,名稱混淆程度有限。發布者採用的混淆工具與完整設定無法從現有證據確認。
|
||||||
|
|
||||||
|
重建時先反編譯 JVM 類別,再用原始位元組碼核對反編譯結果,修正型別與控制流程以恢復可編譯的 Java 原始碼,並用 Maven 還原相依套件及封裝流程。重建結果曾比對類別介面與部分離線行為。實際代理連線與外部服務互動仍待端對端驗證。
|
||||||
|
|
||||||
|
## 重建的主要功能
|
||||||
|
|
||||||
|
- **代理與協定**涵蓋連線、登入、後端切換、封包編解碼,以及 Waterfall 的管理指令與外掛模組。
|
||||||
|
- **機器人與流量防護**包含連線速率、重新連線、暱稱、帳號、延遲、聊天頻率與封包異常檢查。
|
||||||
|
- **登入前驗證**包含 Limbo 暫存連線、驗證碼、白名單與封鎖統計。
|
||||||
|
- **來源過濾**支援 IP、代理來源與國家或地區檢查,並可整合 Linux 防火牆。
|
||||||
|
- **伺服器營運**支援負載平衡、後端備援、維護模式、自訂伺服器清單訊息與玩家數顯示。
|
||||||
|
|
||||||
|
## 開發與建置
|
||||||
|
|
||||||
|
在 IntelliJ IDEA 開啟專案根目錄,或將根目錄的 `pom.xml` 開啟為專案。Maven 匯入會設定原始碼、資源與相依套件。若 IDEA 要求選擇 Project SDK,選用 JDK 21。匯入完成後可執行共用的 **FlameCord Package** 設定,或從終端機以 JDK 21 和 Maven 3.9 以上建置。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mvn clean package
|
||||||
|
```
|
||||||
|
|
||||||
|
首次建置需連線至 Maven Central 與 Mojang 的公開 Maven 倉庫。主要程式以 Java 17 為編譯目標,啟動入口以 Java 11 編譯,以便在舊版 Java 上顯示版本提示。封裝結果可直接啟動。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
java -jar target/flamecord-2.7.1.jar
|
||||||
|
```
|
||||||
@@ -0,0 +1,495 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>dev._2lstudios</groupId>
|
||||||
|
<artifactId>flamecord</artifactId>
|
||||||
|
<version>2.7.1</version>
|
||||||
|
<name>FlameCord 2.7.1</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.release>17</maven.compiler.release>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<netty.version>4.2.18.Final</netty.version>
|
||||||
|
<jline.version>4.4.0</jline.version>
|
||||||
|
<log4j.version>2.25.3</log4j.version>
|
||||||
|
<slf4j.version>1.7.36</slf4j.version>
|
||||||
|
<gson.version>2.13.2</gson.version>
|
||||||
|
<protobuf.version>4.31.1</protobuf.version>
|
||||||
|
<maven-resolver.version>1.9.27</maven-resolver.version>
|
||||||
|
<netty.native.resources>META-INF/native/libnetty_*</netty.native.resources>
|
||||||
|
<jline.native.resources>org/jline/nativ/**/*jlinenative.*</jline.native.resources>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<url>https://repo.maven.apache.org/maven2/</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>minecraft-libraries</id>
|
||||||
|
<url>https://libraries.minecraft.net/</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-bom</artifactId>
|
||||||
|
<version>${netty.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
<version>${protobuf.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-codec-haproxy</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-codec-http</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-resolver-dns</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-handler</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-codec-protobuf</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.google.protobuf.nano</groupId>
|
||||||
|
<artifactId>protobuf-javanano</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-codec-marshalling</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.jboss.marshalling</groupId>
|
||||||
|
<artifactId>*</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-transport-classes-epoll</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-transport-classes-io_uring</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-resolver-dns-native-macos</artifactId>
|
||||||
|
<classifier>osx-x86_64</classifier>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-transport-native-epoll</artifactId>
|
||||||
|
<classifier>linux-x86_64</classifier>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-transport-native-epoll</artifactId>
|
||||||
|
<classifier>linux-aarch_64</classifier>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-transport-native-io_uring</artifactId>
|
||||||
|
<classifier>linux-x86_64</classifier>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-transport-native-io_uring</artifactId>
|
||||||
|
<classifier>linux-aarch_64</classifier>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>33.5.0-jre</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>${gson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mojang</groupId>
|
||||||
|
<artifactId>brigadier</artifactId>
|
||||||
|
<version>1.2.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>it.unimi.dsi</groupId>
|
||||||
|
<artifactId>fastutil-core</artifactId>
|
||||||
|
<version>8.5.19</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.maxmind.db</groupId>
|
||||||
|
<artifactId>maxmind-db</artifactId>
|
||||||
|
<version>2.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>26.7.0</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm-commons</artifactId>
|
||||||
|
<version>9.10.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>2.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sf.jopt-simple</groupId>
|
||||||
|
<artifactId>jopt-simple</artifactId>
|
||||||
|
<version>5.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.minecrell</groupId>
|
||||||
|
<artifactId>terminalconsoleappender</artifactId>
|
||||||
|
<version>1.3.0</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline-terminal</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline-reader</artifactId>
|
||||||
|
<version>3.20.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline-terminal</artifactId>
|
||||||
|
<version>${jline.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline-terminal-ffm</artifactId>
|
||||||
|
<version>${jline.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline-terminal-jni</artifactId>
|
||||||
|
<version>${jline.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>${log4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-iostreams</artifactId>
|
||||||
|
<version>${log4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-jul</artifactId>
|
||||||
|
<version>${log4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
|
<version>${log4j.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-jdk14</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.lmax</groupId>
|
||||||
|
<artifactId>disruptor</artifactId>
|
||||||
|
<version>3.4.4</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-resolver-provider</artifactId>
|
||||||
|
<version>3.9.16</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.resolver</groupId>
|
||||||
|
<artifactId>maven-resolver-connector-basic</artifactId>
|
||||||
|
<version>${maven-resolver.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.resolver</groupId>
|
||||||
|
<artifactId>maven-resolver-transport-http</artifactId>
|
||||||
|
<version>${maven-resolver.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>1.21.0</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.inject</groupId>
|
||||||
|
<artifactId>javax.inject</artifactId>
|
||||||
|
<version>1</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.24</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>24.0.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>${netty.native.resources}</exclude>
|
||||||
|
<exclude>${jline.native.resources}</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
<configuration>
|
||||||
|
<addDefaultExcludes>false</addDefaultExcludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<proc>none</proc>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-Xpkginfo:always</arg>
|
||||||
|
<arg>-implicit:none</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>default-compile</id>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>net/md_5/bungee/Bootstrap.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>compile-bootstrap</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<release>11</release>
|
||||||
|
<includes>
|
||||||
|
<include>net/md_5/bungee/Bootstrap.java</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
<configuration>
|
||||||
|
<forceCreation>true</forceCreation>
|
||||||
|
<archive>
|
||||||
|
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||||
|
<addMavenDescriptor>false</addMavenDescriptor>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>extract-multi-release-descriptors</id>
|
||||||
|
<phase>prepare-package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>unpack</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/module-descriptors</outputDirectory>
|
||||||
|
<artifactItems>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>${gson.version}</version>
|
||||||
|
<includes>META-INF/versions/9/module-info.class</includes>
|
||||||
|
</artifactItem>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-codec-haproxy</artifactId>
|
||||||
|
<version>${netty.version}</version>
|
||||||
|
<includes>META-INF/versions/11/module-info.class</includes>
|
||||||
|
</artifactItem>
|
||||||
|
</artifactItems>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.6.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>shade-runtime</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputFile>${project.build.directory}/distribution-runtime.jar</outputFile>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<includes>
|
||||||
|
<include>**/*.class</include>
|
||||||
|
<include>${netty.native.resources}</include>
|
||||||
|
<include>${jline.native.resources}</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/module-info.class</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
<filter>
|
||||||
|
<artifact>org.slf4j:slf4j-jdk14</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>org/slf4j/impl/Static*Binder.class</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>assemble-distribution</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<zip destfile="${project.build.directory}/${project.build.finalName}-exact.jar"
|
||||||
|
filesonly="true" duplicate="fail" encoding="UTF-8">
|
||||||
|
<fileset dir="${project.build.outputDirectory}" includes="META-INF/MANIFEST.MF"/>
|
||||||
|
<fileset dir="${project.build.outputDirectory}" excludes="META-INF/MANIFEST.MF,**/*.class" defaultexcludes="false"/>
|
||||||
|
<fileset dir="${project.build.directory}/module-descriptors" includes="**/module-info.class"/>
|
||||||
|
<zipfileset src="${project.build.directory}/distribution-runtime.jar"/>
|
||||||
|
</zip>
|
||||||
|
<move file="${project.build.directory}/${project.build.finalName}-exact.jar"
|
||||||
|
tofile="${project.build.directory}/${project.build.finalName}.jar" overwrite="true"/>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.arkflame.flamecord.natives;
|
||||||
|
|
||||||
|
import com.arkflame.flamecord.natives.compress.Compressor;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
|
|
||||||
|
public class MoreByteBufUtils {
|
||||||
|
public static ByteBuf ensureCompatible(ByteBufAllocator alloc, Compressor nativeStuff, ByteBuf buf) {
|
||||||
|
if (isCompatible(nativeStuff, buf)) {
|
||||||
|
return buf.retain();
|
||||||
|
} else {
|
||||||
|
ByteBuf newBuf = alloc.directBuffer(buf.readableBytes());
|
||||||
|
newBuf.writeBytes(buf);
|
||||||
|
return newBuf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isCompatible(Compressor nativeStuff, ByteBuf buf) {
|
||||||
|
if (nativeStuff.isNeedDirectBuffer()) {
|
||||||
|
return buf.hasMemoryAddress();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.arkflame.flamecord.natives;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
public final class NativeEnvironmentDetector {
|
||||||
|
private static final boolean IS_AMD64;
|
||||||
|
private static final boolean IS_AARCH64;
|
||||||
|
private static final boolean CAN_GET_MEMORYADDRESS;
|
||||||
|
|
||||||
|
public static boolean isLinux_X86_64() {
|
||||||
|
return CAN_GET_MEMORYADDRESS && System.getProperty("os.name", "").equalsIgnoreCase("Linux") && IS_AMD64;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isLinux_AARCH64() {
|
||||||
|
return CAN_GET_MEMORYADDRESS && System.getProperty("os.name", "").equalsIgnoreCase("Linux") && IS_AARCH64;
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
ByteBuf test = Unpooled.directBuffer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
CAN_GET_MEMORYADDRESS = test.hasMemoryAddress();
|
||||||
|
} finally {
|
||||||
|
test.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
String osArch = System.getProperty("os.arch", "");
|
||||||
|
IS_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64");
|
||||||
|
IS_AARCH64 = osArch.equals("aarch64") || osArch.equals("arm64");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package com.arkflame.flamecord.natives;
|
||||||
|
|
||||||
|
import com.arkflame.flamecord.natives.compress.Compressor;
|
||||||
|
import com.arkflame.flamecord.natives.compress.CompressorFactory;
|
||||||
|
import com.arkflame.flamecord.natives.compress.JavaCompressor;
|
||||||
|
import com.arkflame.flamecord.natives.compress.LibdeflateCompressor;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.CopyOption;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Natives {
|
||||||
|
private static final CompressorFactory COMPRESSOR_FACTORY = loadAvailableCompressFactory();
|
||||||
|
|
||||||
|
public static CompressorFactory getCompressorFactory() {
|
||||||
|
return COMPRESSOR_FACTORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<CompressorFactory> getAvailableCompressorFactories() {
|
||||||
|
return Arrays.asList(new CompressorFactory() {
|
||||||
|
public String getName() {
|
||||||
|
return "Libdeflate (linux_x86_64)";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCorrectEnvironment() {
|
||||||
|
return NativeEnvironmentDetector.isLinux_X86_64();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNativePath() {
|
||||||
|
return "/libdeflate_x86_64.so";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Compressor create(int level) {
|
||||||
|
return new LibdeflateCompressor(level);
|
||||||
|
}
|
||||||
|
}, new CompressorFactory() {
|
||||||
|
public String getName() {
|
||||||
|
return "Libdeflate (linux_aarch64)";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCorrectEnvironment() {
|
||||||
|
return NativeEnvironmentDetector.isLinux_AARCH64();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNativePath() {
|
||||||
|
return "/libdeflate_aarch64.so";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Compressor create(int level) {
|
||||||
|
return new LibdeflateCompressor(level);
|
||||||
|
}
|
||||||
|
}, new CompressorFactory() {
|
||||||
|
public String getName() {
|
||||||
|
return "Java";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCorrectEnvironment() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNativePath() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Compressor create(int level) {
|
||||||
|
return new JavaCompressor(level);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompressorFactory loadAvailableCompressFactory() {
|
||||||
|
for (CompressorFactory factory : getAvailableCompressorFactories()) {
|
||||||
|
if (factory.isCorrectEnvironment()) {
|
||||||
|
String nativePath = factory.getNativePath();
|
||||||
|
if (nativePath != null) {
|
||||||
|
try {
|
||||||
|
copyAndLoadNative(nativePath);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("None of the compress factories recognized the environment!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyAndLoadNative(String path) {
|
||||||
|
try {
|
||||||
|
InputStream nativeLib = Natives.class.getResourceAsStream(path);
|
||||||
|
if (nativeLib == null) {
|
||||||
|
throw new IllegalStateException("Native library " + path + " not found.");
|
||||||
|
} else {
|
||||||
|
Path tempFile = Files.createTempFile("native-", path.substring(path.lastIndexOf(46)));
|
||||||
|
Files.copy(nativeLib, tempFile, new CopyOption[]{StandardCopyOption.REPLACE_EXISTING});
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(tempFile);
|
||||||
|
} catch (IOException var2) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.load(tempFile.toAbsolutePath().toString());
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
throw new RuntimeException("Unable to load native " + String.valueOf(tempFile.toAbsolutePath()), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Unable to copy natives", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.arkflame.flamecord.natives.compress;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
|
public interface Compressor extends Closeable {
|
||||||
|
int OUTPUT_BUFFER_SIZE = 8192;
|
||||||
|
|
||||||
|
void inflate(ByteBuf var1, ByteBuf var2, int var3) throws DataFormatException;
|
||||||
|
|
||||||
|
void deflate(ByteBuf var1, ByteBuf var2) throws DataFormatException;
|
||||||
|
|
||||||
|
boolean isNeedDirectBuffer();
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.arkflame.flamecord.natives.compress;
|
||||||
|
|
||||||
|
public interface CompressorFactory {
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
boolean isCorrectEnvironment();
|
||||||
|
|
||||||
|
String getNativePath();
|
||||||
|
|
||||||
|
Compressor create(int var1);
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.arkflame.flamecord.natives.compress;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.zip.DataFormatException;
|
||||||
|
import java.util.zip.Deflater;
|
||||||
|
import java.util.zip.Inflater;
|
||||||
|
|
||||||
|
public class JavaCompressor implements Compressor {
|
||||||
|
private final byte[] buffer = new byte[8192];
|
||||||
|
private final Deflater deflater;
|
||||||
|
private final Inflater inflater;
|
||||||
|
private boolean disposed = false;
|
||||||
|
|
||||||
|
public JavaCompressor(int level) {
|
||||||
|
this.deflater = new Deflater(level);
|
||||||
|
this.inflater = new Inflater();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void inflate(ByteBuf source, ByteBuf destination, int uncompressedSize) throws DataFormatException {
|
||||||
|
this.ensureNotDisposed();
|
||||||
|
Preconditions.checkArgument(source.nioBufferCount() == 1, "source has multiple backing buffers");
|
||||||
|
Preconditions.checkArgument(destination.nioBufferCount() == 1, "destination has multiple backing buffers");
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] inData = new byte[source.readableBytes()];
|
||||||
|
source.readBytes(inData);
|
||||||
|
this.inflater.setInput(inData);
|
||||||
|
|
||||||
|
while(!this.inflater.finished() && this.inflater.getTotalIn() < inData.length) {
|
||||||
|
int count = this.inflater.inflate(this.buffer);
|
||||||
|
destination.writeBytes(this.buffer, 0, count);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.inflater.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deflate(ByteBuf source, ByteBuf destination) throws DataFormatException {
|
||||||
|
this.ensureNotDisposed();
|
||||||
|
Preconditions.checkArgument(source.nioBufferCount() == 1, "source has multiple backing buffers");
|
||||||
|
Preconditions.checkArgument(destination.nioBufferCount() == 1, "destination has multiple backing buffers");
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] inData = new byte[source.readableBytes()];
|
||||||
|
source.readBytes(inData);
|
||||||
|
this.deflater.setInput(inData);
|
||||||
|
this.deflater.finish();
|
||||||
|
|
||||||
|
while(!this.deflater.finished()) {
|
||||||
|
int count = this.deflater.deflate(this.buffer);
|
||||||
|
destination.writeBytes(this.buffer, 0, count);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.deflater.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
this.disposed = true;
|
||||||
|
this.deflater.end();
|
||||||
|
this.inflater.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureNotDisposed() {
|
||||||
|
Preconditions.checkState(!this.disposed, "Object already disposed");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNeedDirectBuffer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package com.arkflame.flamecord.natives.compress;
|
||||||
|
|
||||||
|
import com.arkflame.natives.compression.NativeZlibDeflate;
|
||||||
|
import com.arkflame.natives.compression.NativeZlibInflate;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
|
public class LibdeflateCompressor implements Compressor {
|
||||||
|
private final long inflateCtx;
|
||||||
|
private final long deflateCtx;
|
||||||
|
private boolean disposed = false;
|
||||||
|
|
||||||
|
public LibdeflateCompressor(int level) {
|
||||||
|
int correctedLevel = level == -1 ? 6 : level;
|
||||||
|
if (correctedLevel > 12 || correctedLevel < 1) {
|
||||||
|
throw new IllegalArgumentException("Invalid compression level " + level);
|
||||||
|
}
|
||||||
|
this.inflateCtx = NativeZlibInflate.init();
|
||||||
|
this.deflateCtx = NativeZlibDeflate.init(correctedLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void inflate(ByteBuf source, ByteBuf destination, int uncompressedSize) throws DataFormatException {
|
||||||
|
this.ensureNotDisposed();
|
||||||
|
destination.ensureWritable(uncompressedSize);
|
||||||
|
if (source.hasMemoryAddress() && destination.hasMemoryAddress()) {
|
||||||
|
long sourceAddress = source.memoryAddress() + (long)source.readerIndex();
|
||||||
|
long destinationAddress = destination.memoryAddress() + (long)destination.writerIndex();
|
||||||
|
boolean success = NativeZlibInflate.process(this.inflateCtx, sourceAddress, source.readableBytes(), destinationAddress, uncompressedSize);
|
||||||
|
if (!success) {
|
||||||
|
throw new DataFormatException("Failed to inflate data");
|
||||||
|
}
|
||||||
|
destination.writerIndex(destination.writerIndex() + uncompressedSize);
|
||||||
|
source.readerIndex(source.writerIndex());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] srcArray;
|
||||||
|
int srcOffset;
|
||||||
|
int srcLength = source.readableBytes();
|
||||||
|
if (source.hasArray()) {
|
||||||
|
srcArray = source.array();
|
||||||
|
srcOffset = source.arrayOffset() + source.readerIndex();
|
||||||
|
} else {
|
||||||
|
srcArray = new byte[srcLength];
|
||||||
|
source.readBytes(srcArray);
|
||||||
|
srcOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] dstArray;
|
||||||
|
int dstOffset;
|
||||||
|
if (destination.hasArray()) {
|
||||||
|
dstArray = destination.array();
|
||||||
|
dstOffset = destination.arrayOffset() + destination.writerIndex();
|
||||||
|
} else {
|
||||||
|
dstArray = new byte[uncompressedSize];
|
||||||
|
dstOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean success = NativeZlibInflate.processHeap(this.inflateCtx, srcArray, srcOffset, srcLength, dstArray, dstOffset, uncompressedSize);
|
||||||
|
if (!success) {
|
||||||
|
throw new DataFormatException("Failed to inflate data on heap");
|
||||||
|
}
|
||||||
|
if (destination.hasArray()) {
|
||||||
|
destination.writerIndex(destination.writerIndex() + uncompressedSize);
|
||||||
|
} else {
|
||||||
|
destination.writeBytes(dstArray, 0, uncompressedSize);
|
||||||
|
}
|
||||||
|
source.readerIndex(source.writerIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deflate(ByteBuf source, ByteBuf destination) throws DataFormatException {
|
||||||
|
this.ensureNotDisposed();
|
||||||
|
if (source.hasMemoryAddress() && destination.hasMemoryAddress()) {
|
||||||
|
long sourceAddress = source.memoryAddress() + (long)source.readerIndex();
|
||||||
|
int sourceLength = source.readableBytes();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
long destinationAddress = destination.memoryAddress() + (long)destination.writerIndex();
|
||||||
|
int destinationLength = destination.writableBytes();
|
||||||
|
int produced = NativeZlibDeflate.process(this.deflateCtx, sourceAddress, sourceLength, destinationAddress, destinationLength);
|
||||||
|
if (produced > 0) {
|
||||||
|
destination.writerIndex(destination.writerIndex() + produced);
|
||||||
|
source.readerIndex(source.writerIndex());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (produced == 0) {
|
||||||
|
destination.ensureWritable(destination.capacity() * 2);
|
||||||
|
} else {
|
||||||
|
throw new DataFormatException("libdeflate returned error code " + produced);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] srcArray;
|
||||||
|
int srcOffset;
|
||||||
|
int srcLength = source.readableBytes();
|
||||||
|
if (source.hasArray()) {
|
||||||
|
srcArray = source.array();
|
||||||
|
srcOffset = source.arrayOffset() + source.readerIndex();
|
||||||
|
} else {
|
||||||
|
srcArray = new byte[srcLength];
|
||||||
|
source.readBytes(srcArray);
|
||||||
|
srcOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
byte[] dstArray;
|
||||||
|
int dstOffset;
|
||||||
|
int dstLength = destination.writableBytes();
|
||||||
|
if (destination.hasArray()) {
|
||||||
|
dstArray = destination.array();
|
||||||
|
dstOffset = destination.arrayOffset() + destination.writerIndex();
|
||||||
|
} else {
|
||||||
|
dstArray = new byte[dstLength];
|
||||||
|
dstOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int produced = NativeZlibDeflate.processHeap(this.deflateCtx, srcArray, srcOffset, srcLength, dstArray, dstOffset, dstLength);
|
||||||
|
if (produced > 0) {
|
||||||
|
if (destination.hasArray()) {
|
||||||
|
destination.writerIndex(destination.writerIndex() + produced);
|
||||||
|
} else {
|
||||||
|
destination.writeBytes(dstArray, 0, produced);
|
||||||
|
}
|
||||||
|
source.readerIndex(source.writerIndex());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (produced == 0) {
|
||||||
|
destination.ensureWritable(destination.capacity() * 2);
|
||||||
|
} else {
|
||||||
|
throw new DataFormatException("libdeflate returned error code " + produced + " on heap");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureNotDisposed() {
|
||||||
|
Preconditions.checkState(!this.disposed, "Object already disposed");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
if (!this.disposed) {
|
||||||
|
NativeZlibInflate.free(this.inflateCtx);
|
||||||
|
NativeZlibDeflate.free(this.deflateCtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.disposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNeedDirectBuffer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.arkflame.natives.compression;
|
||||||
|
|
||||||
|
public class NativeZlibDeflate {
|
||||||
|
public static native long init(int var0);
|
||||||
|
|
||||||
|
public static native long free(long var0);
|
||||||
|
|
||||||
|
public static native int process(long var0, long var2, int var4, long var5, int var7);
|
||||||
|
|
||||||
|
public static native int processHeap(long var0, byte[] var2, int var3, int var4, byte[] var5, int var6, int var7);
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.arkflame.natives.compression;
|
||||||
|
|
||||||
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
|
public class NativeZlibInflate {
|
||||||
|
public static native long init();
|
||||||
|
|
||||||
|
public static native long free(long var0);
|
||||||
|
|
||||||
|
public static native boolean process(long var0, long var2, int var4, long var5, int var7) throws DataFormatException;
|
||||||
|
|
||||||
|
public static native boolean processHeap(long var0, byte[] var2, int var3, int var4, byte[] var5, int var6, int var7) throws DataFormatException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
package dev._2lstudios.flamecord;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.antibot.BlockedPlayersNotifier;
|
||||||
|
import dev._2lstudios.flamecord.antibot.CheckManager;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.StatsData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import dev._2lstudios.flamecord.configuration.ModulesConfiguration;
|
||||||
|
import dev._2lstudios.flamecord.managers.UserWhitelistManager;
|
||||||
|
import dev._2lstudios.flamecord.util.FirewallCommandQueue;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
|
||||||
|
public class FlameCord {
|
||||||
|
private static FlameCord instance;
|
||||||
|
private FlameCordConfiguration flameCordConfiguration;
|
||||||
|
private ModulesConfiguration modulesConfiguration;
|
||||||
|
private MessagesConfiguration messagesConfiguration;
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
private CheckManager checkManager;
|
||||||
|
private StatsData statsData;
|
||||||
|
private LoggerWrapper loggerWrapper;
|
||||||
|
private UserWhitelistManager userWhitelistManager;
|
||||||
|
private BlockedPlayersNotifier blockedPlayersNotifier;
|
||||||
|
private volatile FirewallCommandQueue firewallCommands;
|
||||||
|
private volatile Thread firewallTickThread;
|
||||||
|
private volatile boolean firewallRunning;
|
||||||
|
private boolean shutdown = false;
|
||||||
|
|
||||||
|
public static void initialize(Logger logger, Collection<String> whitelistedAddresses) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new FlameCord();
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.reload(logger, whitelistedAddresses);
|
||||||
|
instance.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload(Logger logger, Collection<String> whitelistedAddresses) {
|
||||||
|
ConfigurationProvider configurationProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||||
|
this.flameCordConfiguration = new FlameCordConfiguration(configurationProvider, whitelistedAddresses);
|
||||||
|
this.modulesConfiguration = new ModulesConfiguration(configurationProvider);
|
||||||
|
this.messagesConfiguration = new MessagesConfiguration(logger, configurationProvider);
|
||||||
|
if (this.checkManager != null) {
|
||||||
|
this.checkManager.unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loggerWrapper = new LoggerWrapper(Logger.getLogger("BungeeCord"));
|
||||||
|
this.addressDataManager = new AddressDataManager();
|
||||||
|
this.checkManager = new CheckManager(this.addressDataManager, this.flameCordConfiguration);
|
||||||
|
this.statsData = new StatsData();
|
||||||
|
this.blockedPlayersNotifier = new BlockedPlayersNotifier();
|
||||||
|
this.userWhitelistManager = new UserWhitelistManager(new File("whitelist/"), logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printReviewBanner(Logger logger, String version) {
|
||||||
|
try {
|
||||||
|
if (!this.flameCordConfiguration.isReviewReminderEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("============================================");
|
||||||
|
logger.info(" FlameCord v" + version + " - by ArkFlame Studios");
|
||||||
|
logger.info(" Enjoying it? Please leave a review:");
|
||||||
|
logger.info(" https://builtbybit.com/resources/flamecord-ultimate-anti-bot-solution.13492/reviews");
|
||||||
|
logger.info(" Hide this: review-reminder.enabled: false");
|
||||||
|
logger.info("============================================");
|
||||||
|
} catch (Throwable var4) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
this.stopFirewall();
|
||||||
|
if (!this.flameCordConfiguration.isAntibotFirewallIpset()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FirewallCommandQueue queue = new FirewallCommandQueue(this.loggerWrapper.getLogger());
|
||||||
|
this.firewallCommands = queue;
|
||||||
|
queue.start();
|
||||||
|
String ttl = Integer.toString(this.flameCordConfiguration.getAntibotFirewallExpire());
|
||||||
|
queue.enqueue("ipset", "destroy", "flamecord");
|
||||||
|
queue.enqueue("ipset", "create", "flamecord", "hash:ip", "timeout", ttl);
|
||||||
|
queue.enqueue("ipset", "destroy", "flamecord6");
|
||||||
|
queue.enqueue("ipset", "create", "flamecord6", "hash:ip", "family", "inet6", "timeout", ttl);
|
||||||
|
queue.enqueue("iptables", "-t", "raw", "-I", "PREROUTING", "-m", "set", "--match-set", "flamecord", "src", "-j", "DROP");
|
||||||
|
queue.enqueue("ip6tables", "-t", "raw", "-I", "PREROUTING", "-m", "set", "--match-set", "flamecord6", "src", "-j", "DROP");
|
||||||
|
this.firewallRunning = true;
|
||||||
|
Thread tick = new Thread(() -> {
|
||||||
|
while (this.firewallRunning && !Thread.currentThread().isInterrupted()) {
|
||||||
|
try {
|
||||||
|
this.checkManager.getReconnectCheck().tick();
|
||||||
|
} catch (Throwable failure) {
|
||||||
|
this.loggerWrapper.warning("Reconnect check tick failed: " + String.valueOf(failure));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000L);
|
||||||
|
} catch (InterruptedException interrupted) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, "FlameCord-Firewall-Tick");
|
||||||
|
tick.setDaemon(true);
|
||||||
|
this.firewallTickThread = tick;
|
||||||
|
tick.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<List<String>> firewallCleanupCommands() {
|
||||||
|
return Arrays.asList(Arrays.asList("iptables", "-t", "raw", "-D", "PREROUTING", "-m", "set", "--match-set", "flamecord", "src", "-j", "DROP"), Arrays.asList("ip6tables", "-t", "raw", "-D", "PREROUTING", "-m", "set", "--match-set", "flamecord6", "src", "-j", "DROP"), Arrays.asList("ipset", "destroy", "flamecord"), Arrays.asList("ipset", "destroy", "flamecord6"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopFirewall() {
|
||||||
|
this.firewallRunning = false;
|
||||||
|
Thread tick = this.firewallTickThread;
|
||||||
|
this.firewallTickThread = null;
|
||||||
|
if (tick != null) {
|
||||||
|
tick.interrupt();
|
||||||
|
|
||||||
|
try {
|
||||||
|
tick.join(2000L);
|
||||||
|
} catch (InterruptedException var3) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FirewallCommandQueue queue = this.firewallCommands;
|
||||||
|
this.firewallCommands = null;
|
||||||
|
if (queue != null && !queue.shutdown(firewallCleanupCommands())) {
|
||||||
|
this.loggerWrapper.warning("Firewall cleanup did not finish; rules may remain installed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShuttingDown() {
|
||||||
|
return this.shutdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
this.shutdown = true;
|
||||||
|
this.stopFirewall();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enqueueLinuxCommand(String... command) {
|
||||||
|
FirewallCommandQueue queue = this.firewallCommands;
|
||||||
|
if (queue != null) {
|
||||||
|
queue.enqueue(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public static FlameCord getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public FlameCordConfiguration getFlameCordConfiguration() {
|
||||||
|
return this.flameCordConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public ModulesConfiguration getModulesConfiguration() {
|
||||||
|
return this.modulesConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public MessagesConfiguration getMessagesConfiguration() {
|
||||||
|
return this.messagesConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public AddressDataManager getAddressDataManager() {
|
||||||
|
return this.addressDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public CheckManager getCheckManager() {
|
||||||
|
return this.checkManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public StatsData getStatsData() {
|
||||||
|
return this.statsData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public LoggerWrapper getLoggerWrapper() {
|
||||||
|
return this.loggerWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public UserWhitelistManager getUserWhitelistManager() {
|
||||||
|
return this.userWhitelistManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public BlockedPlayersNotifier getBlockedPlayersNotifier() {
|
||||||
|
return this.blockedPlayersNotifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package dev._2lstudios.flamecord;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.packets.DefaultSpawnPosition;
|
||||||
|
import dev._2lstudios.flamecord.packets.EmptyChunkPacket;
|
||||||
|
import dev._2lstudios.flamecord.packets.JoinGame;
|
||||||
|
import dev._2lstudios.flamecord.packets.Player;
|
||||||
|
import dev._2lstudios.flamecord.packets.PlayerAbilities;
|
||||||
|
import dev._2lstudios.flamecord.packets.PlayerPosition;
|
||||||
|
import dev._2lstudios.flamecord.packets.PlayerPositionAndLook;
|
||||||
|
import dev._2lstudios.flamecord.packets.RegistryData;
|
||||||
|
import dev._2lstudios.flamecord.packets.SetExp;
|
||||||
|
import dev._2lstudios.flamecord.packets.SetSlot;
|
||||||
|
import dev._2lstudios.flamecord.packets.TeleportConfirm;
|
||||||
|
import dev._2lstudios.flamecord.packets.TimeUpdate;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
import net.md_5.bungee.protocol.packet.Chat;
|
||||||
|
import net.md_5.bungee.protocol.packet.ClientChat;
|
||||||
|
import net.md_5.bungee.protocol.packet.ClientSettings;
|
||||||
|
import net.md_5.bungee.protocol.packet.KeepAlive;
|
||||||
|
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||||
|
|
||||||
|
public class LimboProtocol {
|
||||||
|
private static Protocol.ProtocolMapping map(int protocol, int id) {
|
||||||
|
return Protocol.map(protocol, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerConfigurationPackets(Protocol.DirectionData TO_CLIENT) {
|
||||||
|
TO_CLIENT.registerPacket(RegistryData.class, RegistryData::new, map(764, 5), map(766, 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerPackets(Protocol.DirectionData TO_CLIENT, Protocol.DirectionData TO_SERVER) {
|
||||||
|
TO_CLIENT.registerPacket(JoinGame.class, JoinGame::new, map(47, 1), map(107, 35), map(393, 37), map(573, 38), map(735, 37), map(751, 36), map(755, 38), map(759, 35), map(760, 37), map(761, 36), map(762, 40), map(764, 41), map(766, 43), map(768, 44), map(770, 43), map(773, 48));
|
||||||
|
TO_CLIENT.registerPacket(TimeUpdate.class, TimeUpdate::new, map(47, 3), map(107, 68), map(335, 70), map(338, 71), map(393, 74), map(477, 78), map(573, 79), map(735, 78), map(755, 88), map(757, 89), map(760, 92), map(761, 90), map(762, 94), map(764, 96), map(765, 98), map(766, 100), map(768, 107), map(770, 106), map(773, 111));
|
||||||
|
TO_CLIENT.registerPacket(PlayerPositionAndLook.class, PlayerPositionAndLook::new, map(47, 8), map(107, 46), map(338, 47), map(393, 50), map(477, 53), map(573, 54), map(735, 53), map(751, 52), map(755, 56), map(759, 54), map(760, 57), map(761, 56), map(762, 60), map(764, 62), map(766, 64), map(768, 66), map(770, 65), map(773, 70));
|
||||||
|
TO_CLIENT.registerPacket(EmptyChunkPacket.class, EmptyChunkPacket::new, map(47, 33), map(107, 32), map(393, 34), map(477, 33), map(573, 34), map(735, 33), map(751, 32), map(755, 34), map(759, 31), map(760, 33), map(761, 32), map(762, 36), map(764, 37), map(766, 39), map(768, 40), map(770, 39), map(773, 44));
|
||||||
|
TO_CLIENT.registerPacket(SetSlot.class, SetSlot::new, map(47, 47), map(107, 22), map(393, 23), map(477, 22), map(573, 23), map(735, 22), map(751, 21), map(755, 22), map(759, 19), map(761, 18), map(762, 20), map(764, 21), map(765, 22), map(766, 24), map(767, 23), map(768, 26), map(770, 25), map(771, 26), map(773, 31));
|
||||||
|
TO_CLIENT.registerPacket(PlayerAbilities.class, PlayerAbilities::new, map(47, 57), map(107, 43), map(338, 44), map(393, 46), map(477, 49), map(573, 50), map(735, 49), map(751, 48), map(755, 50), map(759, 47), map(760, 49), map(761, 48), map(762, 52), map(764, 54), map(766, 56), map(768, 58), map(770, 57), map(773, 62));
|
||||||
|
TO_CLIENT.registerPacket(SetExp.class, SetExp::new, map(47, 31), map(107, 61), map(335, 63), map(338, 64), map(393, 67), map(477, 71), map(573, 72), map(755, 81), map(760, 84), map(761, 82), map(762, 86), map(764, 88), map(765, 90), map(766, 92), map(768, 97), map(770, 96), map(773, 101));
|
||||||
|
TO_CLIENT.registerPacket(DefaultSpawnPosition.class, DefaultSpawnPosition::new, map(47, 5), map(107, 67), map(335, 69), map(338, 70), map(393, 73), map(477, 77), map(573, 78), map(735, 66), map(755, 75), map(759, 74), map(760, 77), map(761, 76), map(762, 80), map(764, 82), map(765, 84), map(766, 86), map(768, 91), map(770, 90), map(773, 95));
|
||||||
|
TO_SERVER.registerPacket(ClientSettings.class, ClientSettings::new, map(47, 21), map(107, 4), map(335, 5), map(338, 4), map(477, 5), map(759, 7), map(760, 8), map(761, 7), map(762, 8), map(764, 9), map(766, 10), map(768, 12), map(771, 13));
|
||||||
|
TO_SERVER.registerPacket(TeleportConfirm.class, TeleportConfirm::new, map(107, 0));
|
||||||
|
TO_SERVER.registerPacket(PlayerPositionAndLook.class, PlayerPositionAndLook::new, map(47, 6), map(107, 13), map(335, 15), map(338, 14), map(393, 17), map(477, 18), map(735, 19), map(755, 18), map(759, 20), map(760, 21), map(761, 20), map(762, 21), map(764, 23), map(765, 24), map(766, 27), map(768, 29), map(771, 30));
|
||||||
|
TO_SERVER.registerPacket(PlayerPosition.class, PlayerPosition::new, map(47, 4), map(107, 12), map(335, 14), map(338, 13), map(393, 16), map(477, 17), map(735, 18), map(755, 17), map(759, 19), map(760, 20), map(761, 19), map(762, 20), map(764, 22), map(765, 23), map(766, 26), map(768, 28), map(771, 29));
|
||||||
|
TO_SERVER.registerPacket(Player.class, Player::new, map(47, 3), map(107, 15), map(335, 13), map(338, 12), map(393, 15), map(477, 20), map(735, 21), map(755, 20), map(759, 22), map(760, 23), map(761, 22), map(762, 23), map(764, 25), map(765, 26), map(766, 29), map(768, 31), map(771, 32));
|
||||||
|
TO_SERVER.registerPacket(KeepAlive.class, KeepAlive::new, map(47, 0), map(107, 11), map(335, 12), map(338, 11), map(393, 14), map(477, 15), map(735, 16), map(755, 15), map(759, 17), map(760, 18), map(761, 17), map(762, 18), map(764, 20), map(765, 21), map(766, 24), map(768, 26), map(771, 27));
|
||||||
|
TO_SERVER.registerPacket(Chat.class, Chat::new, map(47, 1), map(107, 2), map(335, 3), map(338, 2), map(477, 3), map(759, -1));
|
||||||
|
TO_SERVER.registerPacket(ClientChat.class, ClientChat::new, map(759, 4), map(760, 5), map(766, 6), map(768, 7), map(771, 8));
|
||||||
|
TO_SERVER.registerPacket(PluginMessage.class, PluginMessage::new, map(47, 23), map(107, 9), map(335, 10), map(338, 9), map(393, 10), map(477, 11), map(755, 10), map(759, 12), map(760, 13), map(761, 12), map(762, 13), map(764, 15), map(765, 16), map(766, 18), map(768, 20), map(771, 21));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package dev._2lstudios.flamecord;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.antibot.LimboFilter;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedPacketType;
|
||||||
|
import dev._2lstudios.flamecord.antibot.handlers.LimboHandler;
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
|
||||||
|
public class LimboThread {
|
||||||
|
private static Thread thread;
|
||||||
|
private static final Set<Map.Entry<String, LimboHandler>> TO_REMOVE_SET = new HashSet();
|
||||||
|
private static final BungeeCord bungee = BungeeCord.getInstance();
|
||||||
|
private static final long SLEEP_TIME = 1000L;
|
||||||
|
private static final long MESSAGE_INTERVAL = 3000L;
|
||||||
|
|
||||||
|
public static void start() {
|
||||||
|
thread = new Thread(() -> {
|
||||||
|
while(sleep(1000L)) {
|
||||||
|
processConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
}, "LimboHandler thread");
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stop() {
|
||||||
|
if (thread != null) {
|
||||||
|
thread.interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void processConnections() {
|
||||||
|
try {
|
||||||
|
long currTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
for(Map.Entry<String, LimboHandler> entry : LimboFilter.getConnectedUsersSet().entrySet()) {
|
||||||
|
LimboHandler limboHandler = (LimboHandler)entry.getValue();
|
||||||
|
String userKey = (String)entry.getKey();
|
||||||
|
if (limboHandler.isConnected() && !shouldRemoveHandler(limboHandler, currTime)) {
|
||||||
|
if (!limboHandler.isCheckStarted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage(currTime, limboHandler);
|
||||||
|
limboHandler.sendPing();
|
||||||
|
} else {
|
||||||
|
TO_REMOVE_SET.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
bungee.getLogger().log(Level.WARNING, "[LimboHandler] Unexpected error. Please report to the developer!", e);
|
||||||
|
} finally {
|
||||||
|
cleanUpConnections();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendMessage(long currTime, LimboHandler limboHandler) {
|
||||||
|
if (currTime - limboHandler.getLastMessageSent() >= 3000L) {
|
||||||
|
LimboFilter.CheckState state = limboHandler.getState();
|
||||||
|
limboHandler.sendMessage(state != LimboFilter.CheckState.CAPTCHA_ON_POSITION_FAILED && state != LimboFilter.CheckState.ONLY_POSITION ? CachedPacketType.CHECKING_CAPTCHA_MSG : CachedPacketType.CHECKING_MSG);
|
||||||
|
limboHandler.setLastMessageSent(currTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean shouldRemoveHandler(LimboHandler limboHandler, long currTime) {
|
||||||
|
LimboFilter.CheckState state = limboHandler.getState();
|
||||||
|
if (state != LimboFilter.CheckState.SUCCESSFULLY && state != LimboFilter.CheckState.FAILED) {
|
||||||
|
if (currTime - limboHandler.getJoinTime() >= (long)(FlameCord.getInstance().getFlameCordConfiguration().getAntibotLimboTimeout() * 1000)) {
|
||||||
|
limboHandler.failed(PacketUtils.KickType.TIMED_OUT, state == LimboFilter.CheckState.CAPTCHA_ON_POSITION_FAILED ? "Too long fall check" : "Captcha not entered");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void cleanUpConnections() {
|
||||||
|
if (!TO_REMOVE_SET.isEmpty()) {
|
||||||
|
TO_REMOVE_SET.forEach((entry) -> LimboFilter.removeConnection((String)entry.getKey(), (LimboHandler)entry.getValue()));
|
||||||
|
TO_REMOVE_SET.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean sleep(long time) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(time);
|
||||||
|
return true;
|
||||||
|
} catch (InterruptedException var3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package dev._2lstudios.flamecord;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.StringReader;
|
||||||
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import lombok.Generated;
|
||||||
|
|
||||||
|
public class WrappedArgumentType implements ArgumentType<Object> {
|
||||||
|
public final String actualKey;
|
||||||
|
public final int actualIntKey;
|
||||||
|
public final byte[] actualPayload;
|
||||||
|
|
||||||
|
public Object parse(StringReader stringReader) throws CommandSyntaxException {
|
||||||
|
throw new UnsupportedOperationException("Not supported.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public WrappedArgumentType(String actualKey, int actualIntKey, byte[] actualPayload) {
|
||||||
|
this.actualKey = actualKey;
|
||||||
|
this.actualIntKey = actualIntKey;
|
||||||
|
this.actualPayload = actualPayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getActualKey() {
|
||||||
|
return this.actualKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getActualIntKey() {
|
||||||
|
return this.actualIntKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public byte[] getActualPayload() {
|
||||||
|
return this.actualPayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof WrappedArgumentType)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
WrappedArgumentType other = (WrappedArgumentType)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getActualIntKey() != other.getActualIntKey()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Object this$actualKey = this.getActualKey();
|
||||||
|
Object other$actualKey = other.getActualKey();
|
||||||
|
if (this$actualKey == null) {
|
||||||
|
if (other$actualKey != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$actualKey.equals(other$actualKey)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Arrays.equals(this.getActualPayload(), other.getActualPayload())) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof WrappedArgumentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + this.getActualIntKey();
|
||||||
|
Object $actualKey = this.getActualKey();
|
||||||
|
result = result * 59 + ($actualKey == null ? 43 : $actualKey.hashCode());
|
||||||
|
result = result * 59 + Arrays.hashCode(this.getActualPayload());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
String var10000 = this.getActualKey();
|
||||||
|
return "WrappedArgumentType(actualKey=" + var10000 + ", actualIntKey=" + this.getActualIntKey() + ", actualPayload=" + Arrays.toString(this.getActualPayload()) + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot;
|
||||||
|
|
||||||
|
public class BlockedPlayersNotifier {
|
||||||
|
private long currentWindowSecond;
|
||||||
|
private int currentCount;
|
||||||
|
private String firstSubject;
|
||||||
|
private String readySingleSubject;
|
||||||
|
private int readyCount;
|
||||||
|
|
||||||
|
public synchronized void recordBlocked(String subject) {
|
||||||
|
if (subject == null || subject.isEmpty()) {
|
||||||
|
subject = "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
long nowSecond = System.currentTimeMillis() / 1000L;
|
||||||
|
if (nowSecond != this.currentWindowSecond) {
|
||||||
|
this.flushCurrentWindowIfExpired(nowSecond);
|
||||||
|
this.currentWindowSecond = nowSecond;
|
||||||
|
this.currentCount = 0;
|
||||||
|
this.firstSubject = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
++this.currentCount;
|
||||||
|
if (this.firstSubject == null) {
|
||||||
|
this.firstSubject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized Summary drainReadySummary() {
|
||||||
|
if (this.readyCount == 0) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
Summary summary = new Summary(this.readySingleSubject, this.readyCount);
|
||||||
|
this.readySingleSubject = null;
|
||||||
|
this.readyCount = 0;
|
||||||
|
return summary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flushCurrentWindowIfExpired(long nowSecond) {
|
||||||
|
if (this.currentWindowSecond != nowSecond && this.currentCount > 0) {
|
||||||
|
this.readySingleSubject = this.firstSubject;
|
||||||
|
this.readyCount = this.currentCount;
|
||||||
|
this.currentCount = 0;
|
||||||
|
this.firstSubject = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Summary {
|
||||||
|
private final String singleSubject;
|
||||||
|
private final int count;
|
||||||
|
|
||||||
|
public Summary(String singleSubject, int count) {
|
||||||
|
this.singleSubject = singleSubject;
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSingleSubject() {
|
||||||
|
return this.singleSubject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return this.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSingle() {
|
||||||
|
return this.count == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.AccountsCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.CountryCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.FastChatCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.LatencyCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.LimboCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.LockdownCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.NicknameCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.PacketsCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.PasswordCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.RatelimitCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.ReconnectCheck;
|
||||||
|
import dev._2lstudios.flamecord.antibot.proxy.ProxyCheck;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import lombok.Generated;
|
||||||
|
|
||||||
|
public class CheckManager {
|
||||||
|
private final AccountsCheck accountsCheck;
|
||||||
|
private final CountryCheck countryCheck;
|
||||||
|
private final FastChatCheck fastChatCheck;
|
||||||
|
private final NicknameCheck nicknameCheck;
|
||||||
|
private final PasswordCheck passwordCheck;
|
||||||
|
private final RatelimitCheck ratelimitCheck;
|
||||||
|
private final ReconnectCheck reconnectCheck;
|
||||||
|
private final PacketsCheck packetsCheck;
|
||||||
|
private final ProxyCheck proxyCheck;
|
||||||
|
private final LockdownCheck lockdownCheck;
|
||||||
|
private final LatencyCheck latencyCheck;
|
||||||
|
private final LimboCheck limboCheck;
|
||||||
|
|
||||||
|
public CheckManager(AddressDataManager addressDataManager, FlameCordConfiguration config) {
|
||||||
|
this.accountsCheck = new AccountsCheck(addressDataManager);
|
||||||
|
this.countryCheck = new CountryCheck(addressDataManager);
|
||||||
|
this.fastChatCheck = new FastChatCheck(addressDataManager);
|
||||||
|
this.nicknameCheck = new NicknameCheck(addressDataManager);
|
||||||
|
this.passwordCheck = new PasswordCheck(addressDataManager);
|
||||||
|
this.ratelimitCheck = new RatelimitCheck(addressDataManager);
|
||||||
|
this.reconnectCheck = new ReconnectCheck(addressDataManager);
|
||||||
|
this.packetsCheck = new PacketsCheck();
|
||||||
|
this.proxyCheck = new ProxyCheck(addressDataManager);
|
||||||
|
this.lockdownCheck = new LockdownCheck(addressDataManager);
|
||||||
|
this.latencyCheck = new LatencyCheck(addressDataManager);
|
||||||
|
this.limboCheck = new LimboCheck(addressDataManager);
|
||||||
|
this.countryCheck.load();
|
||||||
|
if (config.isAntibotProxyEnabled()) {
|
||||||
|
(new Thread(() -> this.proxyCheck.updateProxies())).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unload() {
|
||||||
|
this.countryCheck.unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public AccountsCheck getAccountsCheck() {
|
||||||
|
return this.accountsCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public CountryCheck getCountryCheck() {
|
||||||
|
return this.countryCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public FastChatCheck getFastChatCheck() {
|
||||||
|
return this.fastChatCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public NicknameCheck getNicknameCheck() {
|
||||||
|
return this.nicknameCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public PasswordCheck getPasswordCheck() {
|
||||||
|
return this.passwordCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public RatelimitCheck getRatelimitCheck() {
|
||||||
|
return this.ratelimitCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public ReconnectCheck getReconnectCheck() {
|
||||||
|
return this.reconnectCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public PacketsCheck getPacketsCheck() {
|
||||||
|
return this.packetsCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public ProxyCheck getProxyCheck() {
|
||||||
|
return this.proxyCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public LockdownCheck getLockdownCheck() {
|
||||||
|
return this.lockdownCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public LatencyCheck getLatencyCheck() {
|
||||||
|
return this.latencyCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public LimboCheck getLimboCheck() {
|
||||||
|
return this.limboCheck;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.LimboThread;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedCaptcha;
|
||||||
|
import dev._2lstudios.flamecord.antibot.handlers.LimboHandler;
|
||||||
|
import dev._2lstudios.flamecord.captcha.CaptchaGeneration;
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import net.md_5.bungee.UserConnection;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.compress.PacketDecompressor;
|
||||||
|
import net.md_5.bungee.connection.InitialHandler;
|
||||||
|
import net.md_5.bungee.netty.HandlerBoss;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
|
||||||
|
public class LimboFilter {
|
||||||
|
public static final int MAX_PLUGIN_MESSAGES_BYTES = 160000;
|
||||||
|
public static int TOTAL_TICKS = 100;
|
||||||
|
public static long TOTAL_TIME;
|
||||||
|
private static final Map<String, LimboHandler> connectedUsersSet;
|
||||||
|
private static ExecutorService executor;
|
||||||
|
|
||||||
|
public static void connectToBotFilter(UserConnection userConnection) {
|
||||||
|
LimboHandler connector = new LimboHandler(userConnection);
|
||||||
|
if (!addConnection(connector)) {
|
||||||
|
userConnection.disconnect(BungeeCord.getInstance().getTranslation("already_connected_proxy"));
|
||||||
|
} else {
|
||||||
|
PacketDecompressor packetDecompressor = (PacketDecompressor)userConnection.getCh().getHandle().pipeline().get(PacketDecompressor.class);
|
||||||
|
if (packetDecompressor != null) {
|
||||||
|
}
|
||||||
|
|
||||||
|
((HandlerBoss)userConnection.getCh().getHandle().pipeline().get(HandlerBoss.class)).setHandler(connector);
|
||||||
|
userConnection.getPendingConnection().sendLoginSuccess(userConnection.getSessionId());
|
||||||
|
userConnection.getCh().setEncodeProtocol(Protocol.GAME);
|
||||||
|
userConnection.getCh().setDecodeProtocol(userConnection.getPendingConnection().getVersion() >= 764 ? Protocol.LOGIN : Protocol.BOTFILTER);
|
||||||
|
if (userConnection.getPendingConnection().getVersion() < 764) {
|
||||||
|
connector.spawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isOnChecking(String name) {
|
||||||
|
return connectedUsersSet.containsKey(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean addConnection(LimboHandler limboHandler) {
|
||||||
|
return connectedUsersSet.putIfAbsent(limboHandler.getName(), limboHandler) == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeConnection(String name, LimboHandler limboHandler) {
|
||||||
|
name = name == null ? (limboHandler == null ? null : limboHandler.getName()) : name;
|
||||||
|
if (name != null) {
|
||||||
|
connectedUsersSet.remove(name);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Name and connector is null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enable() {
|
||||||
|
PacketUtils.init();
|
||||||
|
CheckManager checkManager = FlameCord.getInstance().getCheckManager();
|
||||||
|
executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2, (new ThreadFactoryBuilder()).setNameFormat("FlameCord-%d").build());
|
||||||
|
if (!CachedCaptcha.isGenerated() && FlameCord.getInstance().getFlameCordConfiguration().isAntibotLimboEnabled()) {
|
||||||
|
executor.execute(() -> CaptchaGeneration.generateImages());
|
||||||
|
}
|
||||||
|
|
||||||
|
LimboThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disable() {
|
||||||
|
LimboThread.stop();
|
||||||
|
|
||||||
|
for(LimboHandler connector : connectedUsersSet.values()) {
|
||||||
|
if (connector.getUserConnection() != null) {
|
||||||
|
connector.getUserConnection().disconnect("\u00a7c[FlameCord] \u00a7aFilter reloading");
|
||||||
|
}
|
||||||
|
|
||||||
|
connector.setState(LimboFilter.CheckState.FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
connectedUsersSet.clear();
|
||||||
|
if (executor != null) {
|
||||||
|
executor.shutdownNow();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkAsyncIfNeeded(InitialHandler handler) {
|
||||||
|
CheckManager checkManager = FlameCord.getInstance().getCheckManager();
|
||||||
|
if (checkManager.getCountryCheck().isEnabled()) {
|
||||||
|
executor.execute(() -> {
|
||||||
|
SocketAddress remoteAddress = handler.getCh().getRemoteAddress();
|
||||||
|
AddressData addressData = FlameCord.getInstance().getAddressDataManager().getAddressData(remoteAddress);
|
||||||
|
if (checkManager.getCountryCheck().check(remoteAddress)) {
|
||||||
|
String subject = handler.getName();
|
||||||
|
if (subject == null || subject.isEmpty()) {
|
||||||
|
subject = remoteAddress.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
FlameCord.getInstance().getBlockedPlayersNotifier().recordBlocked(subject);
|
||||||
|
handler.disconnect(ProxyServer.getInstance().getTranslation("antibot_country", addressData.getCountry()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handler.getCh().getHandle().eventLoop().execute(() -> handler.delayedHandleOfLoginRequset());
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
handler.delayedHandleOfLoginRequset();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public static Map<String, LimboHandler> getConnectedUsersSet() {
|
||||||
|
return connectedUsersSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
TOTAL_TIME = (long)(TOTAL_TICKS * 50 - 100);
|
||||||
|
connectedUsersSet = new ConcurrentHashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum CheckState {
|
||||||
|
ONLY_POSITION,
|
||||||
|
ONLY_CAPTCHA,
|
||||||
|
CAPTCHA_POSITION,
|
||||||
|
CAPTCHA_ON_POSITION_FAILED,
|
||||||
|
SUCCESSFULLY,
|
||||||
|
FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
|
public class LoggerWrapper {
|
||||||
|
private Logger logger;
|
||||||
|
private long lastLog = System.currentTimeMillis();
|
||||||
|
private int logCount = 0;
|
||||||
|
private static final int MAX_LOGS_BEFORE_THROTTLE = 2;
|
||||||
|
private static final long THROTTLE_PERIOD_MS = 100L;
|
||||||
|
|
||||||
|
public LoggerWrapper(Logger logger) {
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Logger getLogger() {
|
||||||
|
return this.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(Level level, String msg, Object... params) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
long timeSinceLastLog = currentTime - this.lastLog;
|
||||||
|
if (timeSinceLastLog > 100L) {
|
||||||
|
this.logCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.logCount < 2 || timeSinceLastLog > 100L) {
|
||||||
|
this.lastLog = currentTime;
|
||||||
|
++this.logCount;
|
||||||
|
String var10000 = String.valueOf(ChatColor.GRAY);
|
||||||
|
msg = var10000 + "[" + String.valueOf(ChatColor.RED) + "FlameCord" + String.valueOf(ChatColor.GRAY) + "] " + String.valueOf(ChatColor.WHITE) + msg;
|
||||||
|
this.logger.log(level, msg, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info(String msg) {
|
||||||
|
this.log(Level.INFO, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning(String msg) {
|
||||||
|
this.log(Level.WARNING, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.enums.PacketsViolationReason;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PacketsData {
|
||||||
|
private SocketAddress address;
|
||||||
|
private double packetsVls = (double)0.0F;
|
||||||
|
private double packetsVlsSize = (double)0.0F;
|
||||||
|
private double packetsVlsRate = (double)0.0F;
|
||||||
|
private long lastVlsCalculated = System.currentTimeMillis();
|
||||||
|
private Map<Integer, Double> vlsByPacketId = new HashMap();
|
||||||
|
private boolean cancelPrinted = false;
|
||||||
|
|
||||||
|
public PacketsData(SocketAddress address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double simplify(double number) {
|
||||||
|
return (double)((int)(number * (double)1000.0F)) / (double)1000.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printKick() {
|
||||||
|
if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsLog()) {
|
||||||
|
LoggerWrapper var10000 = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
String var10001 = String.valueOf(this.address);
|
||||||
|
var10000.info("[" + var10001 + "] was kicked because of too many packets (Total: " + this.simplify(this.packetsVls) + "vls Size: " + this.simplify(this.packetsVlsSize) + "vls Rate: " + this.simplify(this.packetsVlsRate) + "vls)");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printCancel() {
|
||||||
|
if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsLog() && !this.cancelPrinted) {
|
||||||
|
LoggerWrapper var10000 = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
String var10001 = String.valueOf(this.address);
|
||||||
|
var10000.info("[" + var10001 + "] was cancelled because of too many packets (Total: " + this.simplify(this.packetsVls) + "vls Size: " + this.simplify(this.packetsVlsSize) + "vls Rate: " + this.simplify(this.packetsVlsRate) + "vls)");
|
||||||
|
this.cancelPrinted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printPackets() {
|
||||||
|
if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotPacketsDebug() && this.simplify(this.packetsVls) > (double)0.0F) {
|
||||||
|
LoggerWrapper var10000 = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
String var10001 = String.valueOf(this.address);
|
||||||
|
var10000.info("[" + var10001 + "] debug is enabled, showing stats (Total: " + this.simplify(this.packetsVls) + "vls Size: " + this.simplify(this.packetsVlsSize) + "vls Rate: " + this.simplify(this.packetsVlsRate) + "vls)");
|
||||||
|
|
||||||
|
for(Map.Entry<Integer, Double> entry : this.vlsByPacketId.entrySet()) {
|
||||||
|
PrintStream var3 = System.out;
|
||||||
|
var10001 = String.valueOf(entry.getKey());
|
||||||
|
var3.print(var10001 + "-" + this.simplify((Double)entry.getValue()) + "vls, ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPacketsVls() {
|
||||||
|
if (System.currentTimeMillis() - this.lastVlsCalculated >= 1000L) {
|
||||||
|
this.printPackets();
|
||||||
|
this.cancelPrinted = false;
|
||||||
|
this.packetsVls = (double)0.0F;
|
||||||
|
this.packetsVlsSize = (double)0.0F;
|
||||||
|
this.packetsVlsRate = (double)0.0F;
|
||||||
|
this.vlsByPacketId.clear();
|
||||||
|
this.lastVlsCalculated = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.packetsVls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVls(double packetsVls, PacketsViolationReason reason, int packetId) {
|
||||||
|
this.packetsVls += packetsVls;
|
||||||
|
this.vlsByPacketId.put(packetId, (Double)this.vlsByPacketId.getOrDefault(packetId, (double)0.0F) + packetsVls);
|
||||||
|
switch (reason) {
|
||||||
|
case SIZE -> this.packetsVlsSize += packetsVls;
|
||||||
|
case RATE -> this.packetsVlsRate += packetsVls;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPacketsVlsSize() {
|
||||||
|
return this.packetsVlsSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPacketsVlsRate() {
|
||||||
|
return this.packetsVlsRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot;
|
||||||
|
|
||||||
|
public class StatsData {
|
||||||
|
private long lastSecond = System.currentTimeMillis();
|
||||||
|
private int totalPings = 0;
|
||||||
|
private int totalConnections = 0;
|
||||||
|
private int currentPings = 0;
|
||||||
|
private int currentConnections = 0;
|
||||||
|
private int lastPings = 0;
|
||||||
|
private int lastConnections = 0;
|
||||||
|
private int totalFirewalled = 0;
|
||||||
|
private int currentFirewalled = 0;
|
||||||
|
private int lastFirewalled = 0;
|
||||||
|
|
||||||
|
public void resetData() {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
if (currentTime - this.lastSecond > 1000L) {
|
||||||
|
this.lastSecond = currentTime;
|
||||||
|
this.lastPings = this.currentPings;
|
||||||
|
this.lastConnections = this.currentConnections;
|
||||||
|
this.lastFirewalled = this.currentFirewalled;
|
||||||
|
this.currentPings = 0;
|
||||||
|
this.currentConnections = 0;
|
||||||
|
this.currentFirewalled = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPing() {
|
||||||
|
this.resetData();
|
||||||
|
++this.currentPings;
|
||||||
|
++this.totalPings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConnection() {
|
||||||
|
this.resetData();
|
||||||
|
++this.currentConnections;
|
||||||
|
++this.totalConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFirewalled() {
|
||||||
|
this.resetData();
|
||||||
|
++this.currentFirewalled;
|
||||||
|
++this.totalFirewalled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentPings() {
|
||||||
|
this.resetData();
|
||||||
|
return this.currentPings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentConnections() {
|
||||||
|
this.resetData();
|
||||||
|
return this.currentConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastPings() {
|
||||||
|
this.resetData();
|
||||||
|
return this.lastPings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastConnections() {
|
||||||
|
this.resetData();
|
||||||
|
return this.lastConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalPings() {
|
||||||
|
return this.totalPings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalConnections() {
|
||||||
|
return this.totalConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalFirewalled() {
|
||||||
|
return this.totalFirewalled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentFirewalled() {
|
||||||
|
return this.currentFirewalled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastFirewalled() {
|
||||||
|
return this.lastFirewalled;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.addressdata;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.StatsData;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import dev._2lstudios.flamecord.managers.UserWhitelistManager;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class AddressData {
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private StatsData statsData = FlameCord.getInstance().getStatsData();
|
||||||
|
private Collection<String> nicknames = null;
|
||||||
|
private final String hostString;
|
||||||
|
private String lastNickname = "";
|
||||||
|
private String country = null;
|
||||||
|
private String firewallReason = null;
|
||||||
|
private long lastPing = 0L;
|
||||||
|
private long penultimateConnection = 0L;
|
||||||
|
private long lastConnection = 0L;
|
||||||
|
private long lastFirewall = 0L;
|
||||||
|
private int pingsSecond = 0;
|
||||||
|
private int totalPings = 0;
|
||||||
|
private int connectionsSecond = 0;
|
||||||
|
private int totalConnections = 0;
|
||||||
|
private int latency = -1;
|
||||||
|
private long firstHandshakeTime = -1L;
|
||||||
|
|
||||||
|
public AddressData(String hostString) {
|
||||||
|
this.hostString = hostString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<String> getNicknames() {
|
||||||
|
if (this.nicknames == null) {
|
||||||
|
this.nicknames = new HashSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.nicknames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastNickname() {
|
||||||
|
return this.lastNickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNickname(String nickname) {
|
||||||
|
if (this.nicknames == null) {
|
||||||
|
this.nicknames = new HashSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.lastNickname.equals(nickname)) {
|
||||||
|
this.lastNickname = nickname;
|
||||||
|
this.totalConnections = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.nicknames.add(nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeNickname(String nickname) {
|
||||||
|
if (this.nicknames != null) {
|
||||||
|
this.nicknames.remove(nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearNicknames() {
|
||||||
|
if (this.nicknames != null) {
|
||||||
|
this.nicknames.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getPenultimateConnection() {
|
||||||
|
return this.penultimateConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimeSincePenultimateConnection() {
|
||||||
|
return System.currentTimeMillis() - this.penultimateConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastConnection() {
|
||||||
|
return this.lastConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimeSinceLastConnection() {
|
||||||
|
return System.currentTimeMillis() - this.lastConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePingsSecond() {
|
||||||
|
if (System.currentTimeMillis() - this.lastPing >= 1000L) {
|
||||||
|
this.pingsSecond = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPingsSecond() {
|
||||||
|
this.updatePingsSecond();
|
||||||
|
return this.pingsSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPing() {
|
||||||
|
this.statsData.addPing();
|
||||||
|
this.updatePingsSecond();
|
||||||
|
this.lastPing = System.currentTimeMillis();
|
||||||
|
++this.pingsSecond;
|
||||||
|
++this.totalPings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalPings() {
|
||||||
|
return this.totalPings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateConnectionsSecond() {
|
||||||
|
if (System.currentTimeMillis() - this.lastConnection >= 1000L) {
|
||||||
|
this.connectionsSecond = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getConnectionsSecond() {
|
||||||
|
this.updateConnectionsSecond();
|
||||||
|
return this.connectionsSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConnection() {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
this.statsData.addConnection();
|
||||||
|
this.updateConnectionsSecond();
|
||||||
|
this.penultimateConnection = this.lastConnection == 0L ? currentTime : this.lastConnection;
|
||||||
|
this.lastConnection = currentTime;
|
||||||
|
++this.connectionsSecond;
|
||||||
|
++this.totalConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalConnections() {
|
||||||
|
return this.totalConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHostString() {
|
||||||
|
return this.hostString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFirewalled() {
|
||||||
|
return System.currentTimeMillis() - this.lastFirewall < (long)(this.config.getAntibotFirewallExpire() * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void firewall(String reason) {
|
||||||
|
if (!FlameCord.getInstance().getFlameCordConfiguration().getAntibotFirewallWhitelist().contains(this.hostString) || !this.isWhitelisted()) {
|
||||||
|
this.lastFirewall = System.currentTimeMillis();
|
||||||
|
this.firewallReason = reason;
|
||||||
|
this.statsData.addFirewalled();
|
||||||
|
if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotFirewallLog()) {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().log(Level.INFO, "[{0}] was firewalled because of " + reason, this.hostString);
|
||||||
|
}
|
||||||
|
|
||||||
|
String ip = FirewallAddress.canonical(this.hostString);
|
||||||
|
if (ip != null) {
|
||||||
|
FlameCord.getInstance().enqueueLinuxCommand("ipset", "add", FirewallAddress.ipset(ip), ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unfirewall() {
|
||||||
|
this.lastFirewall = 0L;
|
||||||
|
this.firewallReason = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirewallReason() {
|
||||||
|
return this.isFirewalled() ? this.firewallReason : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalConnections(int totalConnections) {
|
||||||
|
this.totalConnections = totalConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setCountry(String country) {
|
||||||
|
return this.country = country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCountry() {
|
||||||
|
return this.country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNickname(String nickname) {
|
||||||
|
return this.nicknames.contains(nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startLatency() {
|
||||||
|
this.firstHandshakeTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopLatency() {
|
||||||
|
if (this.firstHandshakeTime != -1L) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
this.latency = (int)(currentTime - this.firstHandshakeTime);
|
||||||
|
this.firstHandshakeTime = -1L;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLatency() {
|
||||||
|
return this.latency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWhitelisted() {
|
||||||
|
UserWhitelistManager userWhitelist = FlameCord.getInstance().getUserWhitelistManager();
|
||||||
|
return userWhitelist.isWhitelisted(this.hostString) || userWhitelist.isWhitelisted(this.lastNickname);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.addressdata;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class AddressDataManager {
|
||||||
|
private Map<String, AddressData> addressData = new HashMap();
|
||||||
|
|
||||||
|
public String sanitizeAddress(String text) {
|
||||||
|
return FirewallAddress.sanitize(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddressData getAddressData(String addressString) {
|
||||||
|
addressString = this.sanitizeAddress(addressString);
|
||||||
|
if (this.addressData.containsKey(addressString)) {
|
||||||
|
return (AddressData)this.addressData.get(addressString);
|
||||||
|
} else {
|
||||||
|
AddressData data = new AddressData(addressString);
|
||||||
|
this.addressData.put(addressString, data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddressData getAddressData(SocketAddress address) {
|
||||||
|
if (!(address instanceof InetSocketAddress inetAddress)) {
|
||||||
|
return this.getAddressData(address.toString());
|
||||||
|
} else {
|
||||||
|
String addressString = inetAddress.isUnresolved() ? inetAddress.getHostString() : inetAddress.getAddress().getHostAddress();
|
||||||
|
return this.getAddressData(addressString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAddresCount() {
|
||||||
|
return this.addressData.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.addressdata;
|
||||||
|
|
||||||
|
import com.google.common.net.InetAddresses;
|
||||||
|
|
||||||
|
public final class FirewallAddress {
|
||||||
|
public static final String IPV4_SET = "flamecord";
|
||||||
|
public static final String IPV6_SET = "flamecord6";
|
||||||
|
|
||||||
|
private FirewallAddress() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String canonical(String address) {
|
||||||
|
if (address == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
String text = address.trim();
|
||||||
|
if (text.startsWith("[") && text.endsWith("]")) {
|
||||||
|
text = text.substring(1, text.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int scope = text.indexOf(37);
|
||||||
|
if (scope != -1) {
|
||||||
|
if (scope == text.length() - 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
text = text.substring(0, scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InetAddresses.isInetAddress(text)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return InetAddresses.toAddrString(InetAddresses.forString(text));
|
||||||
|
} catch (IllegalArgumentException var4) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String ipset(String canonicalAddress) {
|
||||||
|
if (canonicalAddress == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return canonicalAddress.indexOf(58) == -1 ? "flamecord" : "flamecord6";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sanitize(String text) {
|
||||||
|
if (text == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
text = text.trim();
|
||||||
|
if (text.startsWith("/")) {
|
||||||
|
text = text.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text.startsWith("[")) {
|
||||||
|
int end = text.indexOf(93);
|
||||||
|
if (end != -1) {
|
||||||
|
String inner = text.substring(1, end);
|
||||||
|
String ip = canonical(inner);
|
||||||
|
return ip != null ? ip : inner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String ip = canonical(text);
|
||||||
|
if (ip != null) {
|
||||||
|
return ip;
|
||||||
|
} else {
|
||||||
|
int colon = text.indexOf(58);
|
||||||
|
return colon != -1 && colon == text.lastIndexOf(58) ? text.substring(0, colon) : text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.cached;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.packets.MapDataPacket;
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import lombok.Generated;
|
||||||
|
|
||||||
|
public class CachedCaptcha {
|
||||||
|
private static final Random random = new Random();
|
||||||
|
private static final List<CaptchaHolder> captchas = new ArrayList();
|
||||||
|
private static final AtomicInteger counter = new AtomicInteger();
|
||||||
|
public static boolean generated = false;
|
||||||
|
private static final Map<Integer, Integer> packetIds = new HashMap();
|
||||||
|
|
||||||
|
public void createCaptchaPacket(MapDataPacket map, String answer) {
|
||||||
|
Map<Integer, ByteBuf> versionedPackets = new HashMap();
|
||||||
|
|
||||||
|
for(Map.Entry<Integer, Integer> entry : packetIds.entrySet()) {
|
||||||
|
int version = (Integer)entry.getKey();
|
||||||
|
int packetId = (Integer)entry.getValue();
|
||||||
|
versionedPackets.put(version, PacketUtils.createPacket(map, packetId, version));
|
||||||
|
}
|
||||||
|
|
||||||
|
captchas.add(new CaptchaHolder(answer, versionedPackets));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CaptchaHolder randomCaptcha() {
|
||||||
|
return captchas.isEmpty() ? null : (CaptchaHolder)captchas.get(random.nextInt(captchas.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void releaseAndClear() {
|
||||||
|
for(CaptchaHolder holder : captchas) {
|
||||||
|
for(ByteBuf buf : holder.versionedPackets.values()) {
|
||||||
|
PacketUtils.releaseByteBuf(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
captchas.clear();
|
||||||
|
counter.set(0);
|
||||||
|
generated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public static boolean isGenerated() {
|
||||||
|
return generated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public static void setGenerated(boolean generated) {
|
||||||
|
CachedCaptcha.generated = generated;
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
packetIds.put(47, 52);
|
||||||
|
packetIds.put(107, 36);
|
||||||
|
packetIds.put(393, 38);
|
||||||
|
packetIds.put(477, 38);
|
||||||
|
packetIds.put(573, 39);
|
||||||
|
packetIds.put(751, 37);
|
||||||
|
packetIds.put(755, 39);
|
||||||
|
packetIds.put(759, 36);
|
||||||
|
packetIds.put(760, 38);
|
||||||
|
packetIds.put(761, 37);
|
||||||
|
packetIds.put(762, 41);
|
||||||
|
packetIds.put(764, 42);
|
||||||
|
packetIds.put(766, 44);
|
||||||
|
packetIds.put(768, 45);
|
||||||
|
packetIds.put(770, 44);
|
||||||
|
packetIds.put(771, 45);
|
||||||
|
packetIds.put(773, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CaptchaHolder {
|
||||||
|
private final String answer;
|
||||||
|
private final Map<Integer, ByteBuf> versionedPackets;
|
||||||
|
|
||||||
|
public void write(Channel channel, int version, boolean flush) {
|
||||||
|
ByteBuf buf = this.findPacket(version);
|
||||||
|
if (buf != null) {
|
||||||
|
channel.write(buf.retainedDuplicate(), channel.voidPromise());
|
||||||
|
if (flush) {
|
||||||
|
channel.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Version found but returned null for CachedCaptcha: " + version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ByteBuf findPacket(int version) {
|
||||||
|
if (version <= 47) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(47);
|
||||||
|
} else if (version <= 340) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(107);
|
||||||
|
} else if (version <= 404) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(393);
|
||||||
|
} else if (version <= 498) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(477);
|
||||||
|
} else if (version <= 578) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(573);
|
||||||
|
} else if (version <= 754) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(751);
|
||||||
|
} else if (version <= 758) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(755);
|
||||||
|
} else if (version <= 759) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(759);
|
||||||
|
} else if (version <= 760) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(760);
|
||||||
|
} else if (version <= 761) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(761);
|
||||||
|
} else if (version <= 763) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(762);
|
||||||
|
} else if (version <= 765) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(764);
|
||||||
|
} else if (version <= 769) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(768);
|
||||||
|
} else if (version <= 770) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(770);
|
||||||
|
} else if (version <= 772) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(771);
|
||||||
|
} else if (version <= 774) {
|
||||||
|
return (ByteBuf)this.versionedPackets.get(773);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Version not found for CachedCaptcha: " + version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public CaptchaHolder(String answer, Map<Integer, ByteBuf> versionedPackets) {
|
||||||
|
this.answer = answer;
|
||||||
|
this.versionedPackets = versionedPackets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getAnswer() {
|
||||||
|
return this.answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Map<Integer, ByteBuf> getVersionedPackets() {
|
||||||
|
return this.versionedPackets;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.cached;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.antibot.LimboFilter;
|
||||||
|
import dev._2lstudios.flamecord.packets.SetExp;
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
|
||||||
|
public class CachedExpPackets {
|
||||||
|
private ByteBuf[][] byteBuf;
|
||||||
|
|
||||||
|
public CachedExpPackets() {
|
||||||
|
this.byteBuf = new ByteBuf[LimboFilter.TOTAL_TICKS][PacketUtils.PROTOCOLS_COUNT];
|
||||||
|
this.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void create() {
|
||||||
|
int ticks = LimboFilter.TOTAL_TICKS;
|
||||||
|
int interval = 2;
|
||||||
|
float expInterval = 1.0F / ((float)ticks / (float)interval);
|
||||||
|
SetExp setExp = new SetExp(0.0F, 0, 0);
|
||||||
|
|
||||||
|
for(int i = 0; i < ticks; i += interval) {
|
||||||
|
setExp.setExpBar(setExp.getExpBar() + expInterval);
|
||||||
|
setExp.setLevel(setExp.getLevel() + 1);
|
||||||
|
PacketUtils.fillArray(this.byteBuf[i], setExp, Protocol.BOTFILTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteBuf get(int tick, int version) {
|
||||||
|
if (tick >= this.byteBuf.length) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
ByteBuf buf = this.byteBuf[tick][PacketUtils.rewriteVersion(version)];
|
||||||
|
return buf != null ? buf.retainedDuplicate() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
for(ByteBuf[] buffers : this.byteBuf) {
|
||||||
|
if (buffers != null) {
|
||||||
|
for(ByteBuf buf : buffers) {
|
||||||
|
if (buf != null) {
|
||||||
|
PacketUtils.releaseByteBuf(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.byteBuf = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.cached;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import net.md_5.bungee.protocol.packet.Chat;
|
||||||
|
import net.md_5.bungee.protocol.packet.SystemChat;
|
||||||
|
|
||||||
|
public class CachedMessage {
|
||||||
|
private ByteBuf[] bufs;
|
||||||
|
|
||||||
|
public CachedMessage(String message) {
|
||||||
|
this.bufs = new ByteBuf[PacketUtils.PROTOCOLS_COUNT];
|
||||||
|
if (message != null && !message.isEmpty()) {
|
||||||
|
PacketUtils.fillArray(this.bufs, createMessagePacket(message, false), 4, 758, Protocol.GAME);
|
||||||
|
PacketUtils.fillArray(this.bufs, createMessagePacket(message, true), 759, ProtocolConstants.getLastSupportedProtocol(), Protocol.GAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DefinedPacket createMessagePacket(String message, boolean is119) {
|
||||||
|
BaseComponent baseComponent = TextComponent.fromLegacy(ChatColor.translateAlternateColorCodes('&', message.replace("%nl%", "\n")));
|
||||||
|
message = ComponentSerializer.toString(baseComponent);
|
||||||
|
return (DefinedPacket)(is119 ? new SystemChat(baseComponent, ChatMessageType.SYSTEM.ordinal()) : new Chat(message, (byte)ChatMessageType.CHAT.ordinal()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(Channel channel, int version) {
|
||||||
|
ByteBuf buf = this.bufs[PacketUtils.rewriteVersion(version)];
|
||||||
|
if (buf != null) {
|
||||||
|
channel.write(buf.retainedDuplicate());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
for(ByteBuf buf : this.bufs) {
|
||||||
|
PacketUtils.releaseByteBuf(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.cached;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
|
||||||
|
public class CachedPacket {
|
||||||
|
private final Map<Integer, ByteBuf> bufs = new HashMap();
|
||||||
|
|
||||||
|
public CachedPacket(DefinedPacket packet, Protocol... protocols) {
|
||||||
|
if (packet != null) {
|
||||||
|
PacketUtils.fillPackets(this.bufs, packet, protocols);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteBuf get(int version) {
|
||||||
|
ByteBuf buf = this.bufs.getOrDefault(version, null);
|
||||||
|
return buf == null ? null : buf.retainedDuplicate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
if (this.bufs != null) {
|
||||||
|
for(ByteBuf buf : this.bufs.values()) {
|
||||||
|
PacketUtils.releaseByteBuf(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.cached;
|
||||||
|
|
||||||
|
public enum CachedPacketType {
|
||||||
|
LOGIN,
|
||||||
|
TIME,
|
||||||
|
PLAYERABILITIES,
|
||||||
|
PLAYERPOSANDLOOK_CAPTCHA,
|
||||||
|
SETSLOT_MAP,
|
||||||
|
SETSLOT_RESET,
|
||||||
|
KEEPALIVE,
|
||||||
|
PLAYERPOSANDLOOK,
|
||||||
|
SETEXP_RESET,
|
||||||
|
BRAND,
|
||||||
|
BRAND_MODERN,
|
||||||
|
DEFAULT_SPAWN_POSITION,
|
||||||
|
FINISH_CONFIGURATION,
|
||||||
|
GAME_STATE,
|
||||||
|
CAPTCHA_FAILED_2_MSG,
|
||||||
|
CAPTCHA_FAILED_1_MSG,
|
||||||
|
CHECKING_MSG,
|
||||||
|
CHECKING_CAPTCHA_MSG,
|
||||||
|
CHECK_SUS_MSG,
|
||||||
|
CHECK_IN_PROGRESS_TITLE,
|
||||||
|
ENTER_CAPTCHA_TITLE,
|
||||||
|
CHECK_COMPLETED_TYPE;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.cached;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.packets.RegistryData;
|
||||||
|
import dev._2lstudios.flamecord.utils.Dimension;
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
|
||||||
|
public class CachedRegistryData {
|
||||||
|
private List<ByteBuf> bufs = new ArrayList();
|
||||||
|
|
||||||
|
public CachedRegistryData(Dimension dimension, int version) {
|
||||||
|
this.create(dimension, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void create(Dimension dimension, int version) {
|
||||||
|
for(RegistryData registryData : RegistryData.transform(dimension, version)) {
|
||||||
|
this.bufs.add(PacketUtils.createPacket(registryData, Protocol.BOTFILTER_CONFIGURATION, PacketUtils.getPacketId(registryData, version, Protocol.BOTFILTER_CONFIGURATION), version));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(Channel channel) {
|
||||||
|
for(ByteBuf buf : this.bufs) {
|
||||||
|
channel.write(buf.retainedDuplicate(), channel.voidPromise());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
for(ByteBuf buf : this.bufs) {
|
||||||
|
buf.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.cached;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import net.md_5.bungee.protocol.packet.Subtitle;
|
||||||
|
import net.md_5.bungee.protocol.packet.Title;
|
||||||
|
import net.md_5.bungee.protocol.packet.TitleTimes;
|
||||||
|
|
||||||
|
public class CachedTitle {
|
||||||
|
private ByteBuf[] times;
|
||||||
|
private ByteBuf[] title;
|
||||||
|
private ByteBuf[] subtitle;
|
||||||
|
|
||||||
|
public CachedTitle(String raw, int in, int stay, int out) {
|
||||||
|
if (!raw.isEmpty()) {
|
||||||
|
String[] titles = raw.split("%nl%");
|
||||||
|
String titleText = titles[0];
|
||||||
|
String subtitleText = titles.length == 2 ? titles[1] : null;
|
||||||
|
if (!titleText.isEmpty()) {
|
||||||
|
this.initializeTitle(titleText);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subtitleText != null && !subtitleText.isEmpty()) {
|
||||||
|
this.initializeSubtitle(subtitleText);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.title != null || this.subtitle != null) {
|
||||||
|
this.initializeTimes(in, stay, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeTitle(String titleText) {
|
||||||
|
this.title = new ByteBuf[PacketUtils.PROTOCOLS_COUNT];
|
||||||
|
Title titlePacket = new Title();
|
||||||
|
titlePacket.setAction(Title.Action.TITLE);
|
||||||
|
titlePacket.setText(TextComponent.fromLegacy(ChatColor.translateAlternateColorCodes('&', titleText)));
|
||||||
|
PacketUtils.fillArray(this.title, titlePacket, Protocol.GAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeSubtitle(String subtitleText) {
|
||||||
|
this.subtitle = new ByteBuf[PacketUtils.PROTOCOLS_COUNT];
|
||||||
|
Title subTitlePacket = new Title();
|
||||||
|
subTitlePacket.setAction(Title.Action.SUBTITLE);
|
||||||
|
subTitlePacket.setText(TextComponent.fromLegacy(ChatColor.translateAlternateColorCodes('&', subtitleText)));
|
||||||
|
PacketUtils.fillArray(this.subtitle, subTitlePacket, 4, 754, Protocol.GAME);
|
||||||
|
Subtitle subtitlePacket = new Subtitle();
|
||||||
|
subtitlePacket.setText(subTitlePacket.getText());
|
||||||
|
PacketUtils.fillArray(this.subtitle, subtitlePacket, 755, ProtocolConstants.getLastSupportedProtocol(), Protocol.GAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeTimes(int in, int stay, int out) {
|
||||||
|
this.times = new ByteBuf[PacketUtils.PROTOCOLS_COUNT];
|
||||||
|
Title timesPacket = new Title();
|
||||||
|
timesPacket.setFadeIn(in);
|
||||||
|
timesPacket.setStay(stay);
|
||||||
|
timesPacket.setFadeOut(out);
|
||||||
|
timesPacket.setAction(Title.Action.TIMES);
|
||||||
|
PacketUtils.fillArray(this.times, timesPacket, 4, 754, Protocol.GAME);
|
||||||
|
TitleTimes times1 = new TitleTimes();
|
||||||
|
times1.setFadeIn(in);
|
||||||
|
times1.setStay(stay);
|
||||||
|
times1.setFadeOut(out);
|
||||||
|
PacketUtils.fillArray(this.times, times1, 755, ProtocolConstants.getLastSupportedProtocol(), Protocol.GAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeTitle(Channel channel, int version) {
|
||||||
|
version = PacketUtils.rewriteVersion(version);
|
||||||
|
if (this.title != null) {
|
||||||
|
channel.write(this.title[version].retainedDuplicate());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.subtitle != null) {
|
||||||
|
channel.write(this.subtitle[version].retainedDuplicate());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.times != null) {
|
||||||
|
channel.write(this.times[version].retainedDuplicate());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
this.releaseResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
this.releaseResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseResources() {
|
||||||
|
this.releaseByteBufArray(this.title);
|
||||||
|
this.releaseByteBufArray(this.subtitle);
|
||||||
|
this.releaseByteBufArray(this.times);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseByteBufArray(ByteBuf[] bufferArray) {
|
||||||
|
if (bufferArray != null) {
|
||||||
|
for(ByteBuf buf : bufferArray) {
|
||||||
|
PacketUtils.releaseByteBuf(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class AccountsCheck {
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private LoggerWrapper logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
|
||||||
|
public AccountsCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress remoteAddress, String nickname) {
|
||||||
|
if (this.config.getAntibotAccountsWhitelist().contains(nickname)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (this.config.isAntibotAccountsEnabled()) {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<String> nicknames = addressData.getNicknames();
|
||||||
|
if (nicknames.size() > this.config.getAntibotAccountsLimit()) {
|
||||||
|
nicknames.remove(nickname);
|
||||||
|
if (this.config.isAntibotAccountsLog()) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] has too many accounts", remoteAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotAccountsFirewall()) {
|
||||||
|
addressData.firewall("Too many accounts");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import com.maxmind.db.CHMCache;
|
||||||
|
import com.maxmind.db.MaxMindDbConstructor;
|
||||||
|
import com.maxmind.db.MaxMindDbParameter;
|
||||||
|
import com.maxmind.db.Reader;
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.CopyOption;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class CountryCheck {
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private LoggerWrapper logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
private Reader maxMindReader;
|
||||||
|
|
||||||
|
public CountryCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return this.config.isAntibotCountryEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void download(URL url, File file) throws Exception {
|
||||||
|
InputStream in = url.openStream();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.copy(in, file.toPath(), new CopyOption[0]);
|
||||||
|
} catch (Throwable var7) {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (Throwable var6) {
|
||||||
|
var7.addSuppressed(var6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw var7;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
if (this.isEnabled()) {
|
||||||
|
File file = new File("GeoLite2-Country.mmdb");
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!file.exists()) {
|
||||||
|
System.out.println("Starting download of MaxMindDB (This will take some seconds...)");
|
||||||
|
this.download(new URL("https://git.io/GeoLite2-Country.mmdb"), file);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.maxMindReader = new Reader(file, new CHMCache());
|
||||||
|
} catch (Exception var3) {
|
||||||
|
System.out.println("MaxMindDB was not able to download!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unload() {
|
||||||
|
try {
|
||||||
|
if (this.maxMindReader != null) {
|
||||||
|
this.maxMindReader.close();
|
||||||
|
}
|
||||||
|
} catch (IOException var2) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlacklisted(FlameCordConfiguration config, String isoCode) {
|
||||||
|
Collection<String> countryBlacklist = config.getAntibotCountryBlacklist();
|
||||||
|
if (countryBlacklist != null && !countryBlacklist.isEmpty()) {
|
||||||
|
for(String blacklisted : config.getAntibotCountryBlacklist()) {
|
||||||
|
if (isoCode.contains(blacklisted)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<String> countryWhitelist = config.getAntibotCountryWhitelist();
|
||||||
|
if (countryWhitelist != null && !countryWhitelist.isEmpty()) {
|
||||||
|
return !countryWhitelist.contains(isoCode);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIsoCode(InetAddress address) {
|
||||||
|
try {
|
||||||
|
LookupResult lookupResult = (LookupResult)this.maxMindReader.get(address, LookupResult.class);
|
||||||
|
if (lookupResult == null) {
|
||||||
|
return "LOCAL";
|
||||||
|
} else {
|
||||||
|
Country country = lookupResult.getCountry();
|
||||||
|
String isoCode = country.getIsoCode();
|
||||||
|
return isoCode;
|
||||||
|
}
|
||||||
|
} catch (Exception var5) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress remoteAddress) {
|
||||||
|
if (this.config.isAntibotCountryEnabled()) {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String addressCountry = addressData.getCountry();
|
||||||
|
String country;
|
||||||
|
if (addressCountry != null) {
|
||||||
|
country = addressCountry;
|
||||||
|
} else {
|
||||||
|
country = this.getIsoCode(((InetSocketAddress)remoteAddress).getAddress());
|
||||||
|
addressData.setCountry(country);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (country != null && this.isBlacklisted(this.config, country)) {
|
||||||
|
if (this.config.isAntibotCountryLog()) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] has his country blocked from the server", remoteAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotCountryFirewall()) {
|
||||||
|
addressData.firewall("Blacklisted country");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LookupResult {
|
||||||
|
private final Country country;
|
||||||
|
|
||||||
|
@MaxMindDbConstructor
|
||||||
|
public LookupResult(@MaxMindDbParameter(name = "country") Country country) {
|
||||||
|
this.country = country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Country getCountry() {
|
||||||
|
return this.country;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Country {
|
||||||
|
private final String isoCode;
|
||||||
|
|
||||||
|
@MaxMindDbConstructor
|
||||||
|
public Country(@MaxMindDbParameter(name = "iso_code") String isoCode) {
|
||||||
|
this.isoCode = isoCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIsoCode() {
|
||||||
|
return this.isoCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class FastChatCheck {
|
||||||
|
private FlameCordConfiguration config;
|
||||||
|
private LoggerWrapper logger;
|
||||||
|
private final AddressDataManager addressDataManager;
|
||||||
|
private final Map<String, Integer> chatUsageMap = new HashMap();
|
||||||
|
private long lastClearTime = System.currentTimeMillis();
|
||||||
|
private long lastLogTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
public FastChatCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
this.config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
this.logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isChattingTooFast(SocketAddress remoteAddress) {
|
||||||
|
if (!this.config.isAntibotFastChatEnabled()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.getTimeSinceLastConnection() <= (long)this.config.getAntibotFastChatTime()) {
|
||||||
|
if (this.config.isAntibotFastChatLog()) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] is chatting too fast", remoteAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotFastChatFirewall()) {
|
||||||
|
addressData.firewall("Too fast chatting");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCommandRepetitive(SocketAddress remoteAddress, String chat, boolean isCommand) {
|
||||||
|
if (this.config.isAntibotFastChatEnabled() && this.config.isAntibotFastChatRepetitionEnabled()) {
|
||||||
|
if (isCommand && !chat.contains(" ")) {
|
||||||
|
return false;
|
||||||
|
} else if (!isCommand && chat.length() <= this.config.getAntibotFastChatRepetitionLength()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (!isCommand && this.config.isAntibotFastChatRepetitionChat() || this.config.getAntibotFastChatRepetitionCommands().contains(chat.split(" ")[0])) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
if (currentTime - this.lastClearTime > (long)this.config.getAntibotFastChatRepetitionPeriod()) {
|
||||||
|
this.lastClearTime = currentTime;
|
||||||
|
this.chatUsageMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
int usageCount = (Integer)this.chatUsageMap.getOrDefault(chat, 0) + 1;
|
||||||
|
this.chatUsageMap.put(chat, usageCount);
|
||||||
|
if (usageCount > this.config.getAntibotFastChatRepetitionThreshold()) {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (this.config.isAntibotFastChatLog() && currentTime - this.lastLogTime > (long)this.config.getAntibotFastChatLogCooldown()) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] is repeating similar chats {1} (x{2})", remoteAddress, chat.split(" ")[0], String.valueOf(usageCount));
|
||||||
|
this.lastLogTime = currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotFastChatRepetitionFirewall()) {
|
||||||
|
addressData.firewall("Too fast chatting");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class LatencyCheck {
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private LoggerWrapper logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
|
||||||
|
public LatencyCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress remoteAddress) {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (this.config.isAntibotLatencyEnabled()) {
|
||||||
|
int limit = FlameCord.getInstance().getFlameCordConfiguration().getAntibotLatencyLimit();
|
||||||
|
addressData.stopLatency();
|
||||||
|
if (addressData.getLatency() > limit) {
|
||||||
|
if (this.config.isAntibotLatencyLog()) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] has a very high latency ({1}ms)", remoteAddress, addressData.getLatency());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotLatencyFirewall()) {
|
||||||
|
addressData.firewall("Too high latency");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.antibot.utils.Whitelist;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.util.AttributeKey;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
|
public class LimboCheck {
|
||||||
|
private static final String IP_WHITELIST_FILE = "./flamecord/limbo-ips.txt";
|
||||||
|
private static final String NAME_WHITELIST_FILE = "./flamecord/limbo-names.txt";
|
||||||
|
private static final AttributeKey<?> FLOODGATE_PLAYER_ATTRIBUTE = AttributeKey.valueOf("floodgate-player");
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
private Whitelist ipWhitelist = new Whitelist("./flamecord/limbo-ips.txt");
|
||||||
|
private Whitelist nameWhitelist = new Whitelist("./flamecord/limbo-names.txt");
|
||||||
|
private int connections = 0;
|
||||||
|
private long triggerTime = 0L;
|
||||||
|
private long lastConnectionPeriodTime = 0L;
|
||||||
|
|
||||||
|
public LimboCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
this.ipWhitelist.load();
|
||||||
|
this.nameWhitelist.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress remoteAddress, Channel ch, String name) {
|
||||||
|
if (!this.config.isAntibotLimboEnabled()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.config.isAntibotReconnectGeyserBypass() && ch.attr(FLOODGATE_PLAYER_ATTRIBUTE).get() != null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.config.isAntibotLimboWhitelist() && this.ipWhitelist.contains(addressData.getHostString()) && this.nameWhitelist.contains(name)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
int trigger = this.config.getAntibotLimboTriggerConnections();
|
||||||
|
if (trigger > 0) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
int period = this.config.getAntibotLimboTriggerPeriod() * 1000;
|
||||||
|
if (currentTime - this.lastConnectionPeriodTime > (long)period) {
|
||||||
|
this.lastConnectionPeriodTime = currentTime;
|
||||||
|
this.connections = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int secondsActive = this.config.getAntibotLimboTriggerSecondsActive() * 1000;
|
||||||
|
if (currentTime - this.triggerTime > (long)secondsActive) {
|
||||||
|
if (++this.connections <= trigger) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.triggerTime = currentTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToWhitelist(String name, String ip) {
|
||||||
|
if (this.config.isAntibotLimboEnabled()) {
|
||||||
|
this.ipWhitelist.add(ip);
|
||||||
|
this.nameWhitelist.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveWhitelist() {
|
||||||
|
this.ipWhitelist.save();
|
||||||
|
this.nameWhitelist.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.antibot.utils.Whitelist;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
|
public class LockdownCheck {
|
||||||
|
private static final String IP_WHITELIST_FILE = "./flamecord/lockdown-ips.txt";
|
||||||
|
private static final String NAME_WHITELIST_FILE = "./flamecord/lockdown-names.txt";
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
private Whitelist ipWhitelist = new Whitelist("./flamecord/lockdown-ips.txt");
|
||||||
|
private Whitelist nameWhitelist = new Whitelist("./flamecord/lockdown-names.txt");
|
||||||
|
private int counter = 0;
|
||||||
|
private boolean isBlocking = false;
|
||||||
|
private long lastPeriodLimitExceeded = System.currentTimeMillis();
|
||||||
|
private long lastPeriod = System.currentTimeMillis();
|
||||||
|
|
||||||
|
public LockdownCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Loading lockdown whitelist from file.");
|
||||||
|
this.ipWhitelist.load();
|
||||||
|
this.nameWhitelist.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().isAntibotLockdownEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLog() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().isAntibotLockdownLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPeriod() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().getAntibotLockdownPeriod();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPeriodLimit() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().getAntibotLockdownPeriodLimit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDuration() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().getAntibotLockdownDuration();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCounter() {
|
||||||
|
return this.counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(String ip, String nickname) {
|
||||||
|
if (!this.isEnabled()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.isWhitelisted(ip, nickname)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
this.incrementCounter();
|
||||||
|
boolean flagged = this.isBlocking();
|
||||||
|
if (flagged) {
|
||||||
|
if (this.isLog()) {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().log(Level.INFO, "[{0}, {1}] was blocked because the server is under lockdown.", ip, nickname);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.ipWhitelist.add(ip);
|
||||||
|
this.nameWhitelist.add(nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
return flagged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress address, String nickname) {
|
||||||
|
if (!this.isEnabled()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(address);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
String ip = addressData.getHostString();
|
||||||
|
return this.check(ip, nickname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrementCounter() {
|
||||||
|
if (this.isEnabled()) {
|
||||||
|
this.checkPeriod();
|
||||||
|
++this.counter;
|
||||||
|
this.checkPeriodLimit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasPeriodPassed() {
|
||||||
|
return System.currentTimeMillis() - this.lastPeriod > (long)this.getPeriod();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetCounter() {
|
||||||
|
this.counter = 0;
|
||||||
|
this.lastPeriod = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPeriod() {
|
||||||
|
if (this.hasPeriodPassed()) {
|
||||||
|
this.resetCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPeriodLimit() {
|
||||||
|
if (this.isLimitExceeded()) {
|
||||||
|
this.isBlocking = true;
|
||||||
|
this.lastPeriodLimitExceeded = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isLimitExceeded() {
|
||||||
|
return this.counter >= this.getPeriodLimit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkBlocking() {
|
||||||
|
if (System.currentTimeMillis() - this.lastPeriodLimitExceeded < (long)this.getDuration()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.isBlocking = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlocking() {
|
||||||
|
return this.isBlocking && this.checkBlocking();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isWhitelisted(String ip, String nickname) {
|
||||||
|
return this.ipWhitelist.contains(ip) && this.nameWhitelist.contains(nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearWhitelist() {
|
||||||
|
if (this.isEnabled()) {
|
||||||
|
this.ipWhitelist.clear();
|
||||||
|
this.nameWhitelist.clear();
|
||||||
|
this.ipWhitelist.save();
|
||||||
|
this.nameWhitelist.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unlock() {
|
||||||
|
if (this.isEnabled() && this.isBlocking()) {
|
||||||
|
this.isBlocking = false;
|
||||||
|
this.lastPeriodLimitExceeded = 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lock() {
|
||||||
|
if (this.isEnabled() && !this.isBlocking()) {
|
||||||
|
this.isBlocking = true;
|
||||||
|
this.lastPeriodLimitExceeded = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimeAsString() {
|
||||||
|
if (this.isEnabled() && this.isBlocking()) {
|
||||||
|
long remainingTime = (long)this.getDuration() - (System.currentTimeMillis() - this.lastPeriodLimitExceeded);
|
||||||
|
return this.formatDuration(remainingTime);
|
||||||
|
} else {
|
||||||
|
return "Inactive";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
if (!this.isEnabled()) {
|
||||||
|
return "Inactive";
|
||||||
|
} else {
|
||||||
|
return this.isBlocking() ? String.valueOf(ChatColor.RED) + "Locked" : String.valueOf(ChatColor.GREEN) + "Unlocked";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatDuration(long duration) {
|
||||||
|
long seconds = duration / 1000L;
|
||||||
|
long minutes = seconds / 60L;
|
||||||
|
long hours = minutes / 60L;
|
||||||
|
return String.format("%02d:%02d:%02d", hours, minutes % 60L, seconds % 60L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveWhitelist() {
|
||||||
|
this.ipWhitelist.save();
|
||||||
|
this.nameWhitelist.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class NicknameCheck {
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private LoggerWrapper logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
|
||||||
|
public NicknameCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlacklisted(FlameCordConfiguration config, String nickname) {
|
||||||
|
String lowerNickname = nickname.toLowerCase();
|
||||||
|
|
||||||
|
for(String blacklisted : config.getAntibotNicknameBlacklist()) {
|
||||||
|
if (lowerNickname.contains(blacklisted)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress remoteAddress) {
|
||||||
|
if (this.config.isAntibotNicknameEnabled()) {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String nickname = addressData.getLastNickname();
|
||||||
|
if (this.isBlacklisted(this.config, nickname)) {
|
||||||
|
if (this.config.isAntibotNicknameLog()) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] has a blacklisted nickname (" + nickname + ")", remoteAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotNicknameFirewall()) {
|
||||||
|
addressData.firewall("Blacklisted nickname [" + nickname + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.PacketsData;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import dev._2lstudios.flamecord.enums.PacketsCheckResult;
|
||||||
|
import dev._2lstudios.flamecord.enums.PacketsViolationReason;
|
||||||
|
import dev._2lstudios.flamecord.utils.ProtocolUtil;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PacketsCheck {
|
||||||
|
private Map<String, PacketsData> packetsData = new HashMap();
|
||||||
|
private long lastClear = System.currentTimeMillis();
|
||||||
|
|
||||||
|
public PacketsData getData(SocketAddress address) {
|
||||||
|
String ip = address.toString();
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
if (currentTime - this.lastClear > 60000L) {
|
||||||
|
this.lastClear = currentTime;
|
||||||
|
this.packetsData.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.packetsData.containsKey(ip)) {
|
||||||
|
return (PacketsData)this.packetsData.get(ip);
|
||||||
|
} else {
|
||||||
|
PacketsData data = new PacketsData(address);
|
||||||
|
this.packetsData.put(ip, data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketsCheckResult check(SocketAddress socketAddress, ByteBuf byteBuf) {
|
||||||
|
FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
if (!config.isAntibotPacketsEnabled()) {
|
||||||
|
return PacketsCheckResult.NONE;
|
||||||
|
} else {
|
||||||
|
PacketsData packetsData = this.getData(socketAddress);
|
||||||
|
int length = byteBuf.readableBytes();
|
||||||
|
int index = byteBuf.readerIndex();
|
||||||
|
int packetId = ProtocolUtil.readVarInt(byteBuf);
|
||||||
|
byteBuf.readerIndex(index);
|
||||||
|
if (packetId == -1) {
|
||||||
|
return PacketsCheckResult.CANCEL;
|
||||||
|
} else if (packetsData == null) {
|
||||||
|
return PacketsCheckResult.NONE;
|
||||||
|
} else {
|
||||||
|
packetsData.addVls((double)length * config.getAntibotPacketsVlsPerByte(), PacketsViolationReason.SIZE, packetId);
|
||||||
|
packetsData.addVls(config.getAntibotPacketsVlsPerPacket(), PacketsViolationReason.RATE, packetId);
|
||||||
|
double vls = packetsData.getPacketsVls();
|
||||||
|
if (vls >= config.getAntibotPacketsVlsToKick()) {
|
||||||
|
if (config.isAntibotAccountsFirewall()) {
|
||||||
|
FlameCord.getInstance().getAddressDataManager().getAddressData(socketAddress).firewall("Too many packets");
|
||||||
|
}
|
||||||
|
|
||||||
|
return PacketsCheckResult.KICK;
|
||||||
|
} else {
|
||||||
|
return vls >= config.getAntibotPacketsVlsToCancel() ? PacketsCheckResult.CANCEL : PacketsCheckResult.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class PasswordCheck {
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
private LoggerWrapper logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
private Map<String, Collection<String>> passwords = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
public int getPasswordCount(String password) {
|
||||||
|
return this.passwords.containsKey(password) ? ((Collection)this.passwords.get(password)).size() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasUsedPassword(String password, String nickname) {
|
||||||
|
return this.passwords.containsKey(password) ? ((Collection)this.passwords.get(password)).contains(nickname) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPassword(String password, String nickname) {
|
||||||
|
if (this.passwords.containsKey(password)) {
|
||||||
|
((Collection)this.passwords.get(password)).add(nickname);
|
||||||
|
} else {
|
||||||
|
Collection<String> nicknames = new HashSet();
|
||||||
|
nicknames.add(nickname);
|
||||||
|
this.passwords.put(password, nicknames);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public PasswordCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress remoteAddress, String passwordMessage) {
|
||||||
|
if (this.config.isAntibotPasswordEnabled()) {
|
||||||
|
if (!passwordMessage.contains(" ")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String cmd : this.config.getAntibotPasswordLoginCommands()) {
|
||||||
|
if (passwordMessage.startsWith(cmd)) {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String nickname = addressData.getLastNickname();
|
||||||
|
String password = passwordMessage.split(" ")[1];
|
||||||
|
boolean usedPassword = this.hasUsedPassword(nickname, password);
|
||||||
|
if (!usedPassword && this.getPasswordCount(password) >= this.config.getAntibotPasswordLimit()) {
|
||||||
|
if (this.config.isAntibotPasswordLog()) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] has entered a repeated password", remoteAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotPasswordFirewall()) {
|
||||||
|
addressData.firewall("Repeated password");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addPassword(nickname, password);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class RatelimitCheck {
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private LoggerWrapper logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
|
||||||
|
public RatelimitCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress remoteAddress, int protocol) {
|
||||||
|
if (this.config.isAntibotRatelimitEnabled()) {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.getAntibotRatelimitWhitelist().contains(addressData.getHostString())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addressData.getConnectionsSecond() >= this.config.getAntibotRatelimitConnectionsPerSecond() || addressData.getPingsSecond() >= this.config.getAntibotRatelimitPingsPerSecond()) {
|
||||||
|
if (this.config.isAntibotRatelimitLog()) {
|
||||||
|
if (protocol == 1) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] is pinging too fast", remoteAddress);
|
||||||
|
} else {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] is connecting too fast", remoteAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotRatelimitFirewall()) {
|
||||||
|
if (protocol == 1) {
|
||||||
|
addressData.firewall("Too many pings");
|
||||||
|
} else {
|
||||||
|
addressData.firewall("Too many connections");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.check;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.antibot.utils.Whitelist;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.util.AttributeKey;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class ReconnectCheck {
|
||||||
|
private static final AttributeKey<?> FLOODGATE_PLAYER_ATTRIBUTE = AttributeKey.valueOf("floodgate-player");
|
||||||
|
private static final String IP_WHITELIST_FILE = "./flamecord/reconnect-ips.txt";
|
||||||
|
private static final String NAME_WHITELIST_FILE = "./flamecord/reconnect-names.txt";
|
||||||
|
private FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
private LoggerWrapper logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
private int currentConnections = 0;
|
||||||
|
private int periodRemainingSeconds = 0;
|
||||||
|
private Whitelist ipWhitelist = new Whitelist("./flamecord/reconnect-ips.txt");
|
||||||
|
private Whitelist nameWhitelist = new Whitelist("./flamecord/reconnect-names.txt");
|
||||||
|
|
||||||
|
public ReconnectCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
this.logger.info("Loading whitelisted items from file.");
|
||||||
|
this.ipWhitelist.save();
|
||||||
|
this.nameWhitelist.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
this.currentConnections = 0;
|
||||||
|
--this.periodRemainingSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress remoteAddress, Channel ch, String name) {
|
||||||
|
if (!this.config.isAntibotReconnectEnabled()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.config.isAntibotReconnectGeyserBypass() && ch.attr(FLOODGATE_PLAYER_ATTRIBUTE).get() != null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
int lastRemainingSeconds = this.periodRemainingSeconds;
|
||||||
|
++this.currentConnections;
|
||||||
|
if (this.currentConnections >= this.config.getAntibotReconnectConnectionsTrigger()) {
|
||||||
|
this.periodRemainingSeconds = this.config.getAntibotReconnectSecondsActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastRemainingSeconds <= 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(remoteAddress);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.config.isAntibotReconnectWhitelist() && this.ipWhitelist.contains(addressData.getHostString()) && this.nameWhitelist.contains(name)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
long lastConnection = addressData.getTimeSincePenultimateConnection();
|
||||||
|
boolean tooSlow = lastConnection > (long)this.config.getAntibotReconnectMaxTime();
|
||||||
|
boolean tooFast = lastConnection < (long)this.config.getAntibotReconnectMinTime();
|
||||||
|
if (!tooSlow && !tooFast) {
|
||||||
|
int remainingReconnect = this.config.getAntibotReconnectAttempts() - addressData.getTotalConnections();
|
||||||
|
int remainingPing = this.config.getAntibotReconnectPings() - addressData.getTotalPings();
|
||||||
|
if (remainingReconnect <= 0 && remainingPing <= 0) {
|
||||||
|
if (this.config.isAntibotReconnectWhitelist()) {
|
||||||
|
this.ipWhitelist.add(addressData.getHostString());
|
||||||
|
this.nameWhitelist.add(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (this.config.isAntibotReconnectLog()) {
|
||||||
|
String msg = "[{0}] has to";
|
||||||
|
if (remainingReconnect > 0) {
|
||||||
|
msg = msg + " reconnect " + remainingReconnect + " times";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remainingPing > 0) {
|
||||||
|
msg = msg + " ping " + remainingPing + " times";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.log(Level.INFO, msg, remoteAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.config.isAntibotReconnectLog()) {
|
||||||
|
String msg = "[{0}] has to reconnect again";
|
||||||
|
if (tooSlow) {
|
||||||
|
msg = msg + " (Too slow)";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tooFast) {
|
||||||
|
msg = msg + " (Too fast)";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.log(Level.INFO, msg, remoteAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
addressData.setTotalConnections(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveWhitelist() {
|
||||||
|
this.ipWhitelist.save();
|
||||||
|
this.nameWhitelist.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,427 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.handlers;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LimboFilter;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedCaptcha;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedMessage;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedPacketType;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedTitle;
|
||||||
|
import dev._2lstudios.flamecord.utils.IPUtils;
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import dev._2lstudios.flamecord.utils.Util;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.UserConnection;
|
||||||
|
import net.md_5.bungee.compress.PacketDecompressor;
|
||||||
|
import net.md_5.bungee.netty.ChannelWrapper;
|
||||||
|
import net.md_5.bungee.protocol.PacketWrapper;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
import net.md_5.bungee.protocol.packet.Chat;
|
||||||
|
import net.md_5.bungee.protocol.packet.ClientChat;
|
||||||
|
import net.md_5.bungee.protocol.packet.ClientSettings;
|
||||||
|
import net.md_5.bungee.protocol.packet.FinishConfiguration;
|
||||||
|
import net.md_5.bungee.protocol.packet.KeepAlive;
|
||||||
|
import net.md_5.bungee.protocol.packet.LoginAcknowledged;
|
||||||
|
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||||
|
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||||
|
|
||||||
|
public class LimboHandler extends MoveHandler {
|
||||||
|
private static final double MAX_MOVEMENT_DIFFERENCE = 0.1;
|
||||||
|
private final String name;
|
||||||
|
private final String ip;
|
||||||
|
private final int version;
|
||||||
|
private UserConnection userConnection;
|
||||||
|
private LimboFilter.CheckState state;
|
||||||
|
private Channel channel;
|
||||||
|
private ChannelWrapper ch;
|
||||||
|
private String captchaAnswer;
|
||||||
|
private int aticks;
|
||||||
|
private int sentPings;
|
||||||
|
private int attemps;
|
||||||
|
private long joinTime;
|
||||||
|
private long lastSend;
|
||||||
|
private long totalping;
|
||||||
|
private boolean markDisconnected;
|
||||||
|
private int pluginMessagesBytes;
|
||||||
|
private boolean checkStarted;
|
||||||
|
private boolean repeat;
|
||||||
|
private long lastMessageSent;
|
||||||
|
|
||||||
|
public LimboHandler(UserConnection userConnection) {
|
||||||
|
super(userConnection);
|
||||||
|
this.state = LimboFilter.CheckState.CAPTCHA_POSITION;
|
||||||
|
this.aticks = 0;
|
||||||
|
this.sentPings = 0;
|
||||||
|
this.attemps = 3;
|
||||||
|
this.joinTime = System.currentTimeMillis();
|
||||||
|
this.lastSend = 0L;
|
||||||
|
this.totalping = 9999L;
|
||||||
|
this.markDisconnected = false;
|
||||||
|
this.pluginMessagesBytes = 0;
|
||||||
|
this.repeat = true;
|
||||||
|
this.lastMessageSent = 0L;
|
||||||
|
this.name = userConnection.getName();
|
||||||
|
this.channel = userConnection.getCh().getHandle();
|
||||||
|
this.ch = userConnection.getCh();
|
||||||
|
this.userConnection = userConnection;
|
||||||
|
this.version = userConnection.getPendingConnection().getVersion();
|
||||||
|
this.userConnection.setClientEntityId(PacketUtils.CLIENTID);
|
||||||
|
this.userConnection.setDimension(0);
|
||||||
|
this.ip = IPUtils.getAddress(this.userConnection).getHostAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawn() {
|
||||||
|
this.checkStarted = true;
|
||||||
|
if (this.state == LimboFilter.CheckState.CAPTCHA_ON_POSITION_FAILED) {
|
||||||
|
PacketUtils.spawnPlayer(this.channel, this.userConnection.getPendingConnection().getVersion(), false, false);
|
||||||
|
((CachedTitle)PacketUtils.titles.get(CachedPacketType.CHECK_IN_PROGRESS_TITLE)).writeTitle(this.channel, this.version);
|
||||||
|
} else {
|
||||||
|
PacketUtils.spawnPlayer(this.channel, this.userConnection.getPendingConnection().getVersion(), this.state == LimboFilter.CheckState.ONLY_CAPTCHA, true);
|
||||||
|
this.sendCaptcha();
|
||||||
|
((CachedTitle)PacketUtils.titles.get(CachedPacketType.ENTER_CAPTCHA_TITLE)).writeTitle(this.channel, this.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendPing();
|
||||||
|
if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotLimboLog()) {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Player (" + this.name + "|" + this.ip + ") connected to limbo");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exception(Throwable t) throws Exception {
|
||||||
|
this.markDisconnected = true;
|
||||||
|
if (this.state == LimboFilter.CheckState.FAILED) {
|
||||||
|
if (this.channel != null) {
|
||||||
|
this.channel.close();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.userConnection.disconnect(Util.exception(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.disconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(PacketWrapper packet) throws Exception {
|
||||||
|
if (packet.packet == null && packet.buf.readableBytes() > 2048) {
|
||||||
|
this.failed(PacketUtils.KickType.BIG_PACKET, "Sent packet larger than 2048 bytes (" + packet.buf.readableBytes() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnected(ChannelWrapper channel) throws Exception {
|
||||||
|
switch (this.state) {
|
||||||
|
case ONLY_CAPTCHA:
|
||||||
|
case ONLY_POSITION:
|
||||||
|
case CAPTCHA_POSITION:
|
||||||
|
if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotLimboLog()) {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Player (" + this.name + "|" + this.ip + ") left the limbo");
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
LimboFilter.removeConnection((String)null, this);
|
||||||
|
this.disconnected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handlerChanged() {
|
||||||
|
this.disconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disconnected() {
|
||||||
|
this.channel = null;
|
||||||
|
this.userConnection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void completeCheck() {
|
||||||
|
if (System.currentTimeMillis() - this.joinTime < LimboFilter.TOTAL_TIME && this.state != LimboFilter.CheckState.ONLY_CAPTCHA) {
|
||||||
|
if (this.state == LimboFilter.CheckState.CAPTCHA_POSITION && this.aticks < LimboFilter.TOTAL_TICKS) {
|
||||||
|
this.channel.writeAndFlush(PacketUtils.getCachedPacket(CachedPacketType.SETSLOT_RESET).get(this.version), this.channel.voidPromise());
|
||||||
|
this.state = LimboFilter.CheckState.ONLY_POSITION;
|
||||||
|
} else if (this.state == LimboFilter.CheckState.CAPTCHA_ON_POSITION_FAILED) {
|
||||||
|
this.changeStateToCaptcha();
|
||||||
|
} else {
|
||||||
|
this.failed(PacketUtils.KickType.FAILED_FALLING, "Too fast check passed");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (this.lastSend == 0L) {
|
||||||
|
int var10000 = this.sentPings;
|
||||||
|
} else {
|
||||||
|
int var3 = this.sentPings - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = LimboFilter.CheckState.SUCCESSFULLY;
|
||||||
|
((CachedTitle)PacketUtils.titles.get(CachedPacketType.CHECK_COMPLETED_TYPE)).writeTitle(this.channel, this.version);
|
||||||
|
this.channel.flush();
|
||||||
|
LimboFilter.removeConnection((String)null, this);
|
||||||
|
this.sendMessage(CachedPacketType.CHECK_SUS_MSG);
|
||||||
|
PacketDecompressor packetDecompressor = (PacketDecompressor)this.channel.pipeline().get(PacketDecompressor.class);
|
||||||
|
if (packetDecompressor != null) {
|
||||||
|
}
|
||||||
|
|
||||||
|
this.userConnection.setNeedLogin(false);
|
||||||
|
this.userConnection.getPendingConnection().finishLoginWithLoginEvent(true);
|
||||||
|
this.markDisconnected = true;
|
||||||
|
FlameCord.getInstance().getCheckManager().getLimboCheck().addToWhitelist(this.name, this.ip);
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Player (" + this.name + "|" + this.ip + ") passed limbo check");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onMove() {
|
||||||
|
if (this.lastY != (double)-1.0F && this.state != LimboFilter.CheckState.FAILED && this.state != LimboFilter.CheckState.SUCCESSFULLY && !this.onGround) {
|
||||||
|
if (this.state == LimboFilter.CheckState.ONLY_CAPTCHA) {
|
||||||
|
if (this.lastY != this.y && this.waitingTeleportId == -1) {
|
||||||
|
this.resetPosition(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
double diff = formatDouble(this.lastY - this.y);
|
||||||
|
if (diff == (double)0.0F && this.y != (double)120.0F && !this.repeat) {
|
||||||
|
this.repeat = true;
|
||||||
|
} else {
|
||||||
|
this.repeat = false;
|
||||||
|
if (Math.abs(diff - getSpeed(this.ticks)) > 0.1) {
|
||||||
|
if (this.state == LimboFilter.CheckState.CAPTCHA_ON_POSITION_FAILED) {
|
||||||
|
this.changeStateToCaptcha();
|
||||||
|
} else {
|
||||||
|
this.failed(PacketUtils.KickType.FAILED_FALLING, "Failed position check");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (this.y <= (double)60.0F && this.state == LimboFilter.CheckState.CAPTCHA_POSITION && this.waitingTeleportId == -1) {
|
||||||
|
this.resetPosition(false);
|
||||||
|
} else if (this.aticks >= LimboFilter.TOTAL_TICKS && this.state != LimboFilter.CheckState.CAPTCHA_POSITION) {
|
||||||
|
this.completeCheck();
|
||||||
|
} else {
|
||||||
|
if (this.state == LimboFilter.CheckState.CAPTCHA_POSITION || this.state == LimboFilter.CheckState.CAPTCHA_ON_POSITION_FAILED || this.state == LimboFilter.CheckState.ONLY_POSITION) {
|
||||||
|
ByteBuf expBuf = PacketUtils.expPackets.get(this.aticks, this.version);
|
||||||
|
if (expBuf != null) {
|
||||||
|
this.channel.writeAndFlush(expBuf, this.channel.voidPromise());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
++this.ticks;
|
||||||
|
++this.aticks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPosition(boolean disableFall) {
|
||||||
|
if (disableFall) {
|
||||||
|
this.channel.write(PacketUtils.getCachedPacket(CachedPacketType.PLAYERABILITIES).get(this.version), this.channel.voidPromise());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.waitingTeleportId = 9876;
|
||||||
|
this.channel.writeAndFlush(PacketUtils.getCachedPacket(CachedPacketType.PLAYERPOSANDLOOK_CAPTCHA).get(this.version), this.channel.voidPromise());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Chat chat) throws Exception {
|
||||||
|
this.handleChat(chat.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(LoginAcknowledged loginAcknowledged) throws Exception {
|
||||||
|
this.userConnection.getCh().setDecodeProtocol(Protocol.CONFIGURATION);
|
||||||
|
PacketUtils.configure(this.channel, this.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(FinishConfiguration finishConfiguration) throws Exception {
|
||||||
|
this.userConnection.getCh().setDecodeProtocol(Protocol.BOTFILTER);
|
||||||
|
this.spawn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(ClientChat chat) throws Exception {
|
||||||
|
this.handleChat(chat.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleChat(String message) {
|
||||||
|
if (this.state != LimboFilter.CheckState.CAPTCHA_ON_POSITION_FAILED) {
|
||||||
|
if (message.length() > 256) {
|
||||||
|
this.failed(PacketUtils.KickType.FAILED_CAPTCHA, "Too long message");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.replace("/", "").equals(this.captchaAnswer)) {
|
||||||
|
this.setState(LimboFilter.CheckState.ONLY_POSITION);
|
||||||
|
} else if (--this.attemps != 0) {
|
||||||
|
this.sendMessage(this.attemps == 2 ? CachedPacketType.CAPTCHA_FAILED_2_MSG : CachedPacketType.CAPTCHA_FAILED_1_MSG);
|
||||||
|
this.sendCaptcha();
|
||||||
|
} else {
|
||||||
|
this.failed(PacketUtils.KickType.FAILED_CAPTCHA, "Failed captcha check");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(ClientSettings settings) throws Exception {
|
||||||
|
this.userConnection.setSettings(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(KeepAlive keepAlive) throws Exception {
|
||||||
|
if (keepAlive.getRandomId() == (long)PacketUtils.KEEPALIVE_ID) {
|
||||||
|
if (this.lastSend == 0L) {
|
||||||
|
this.failed(PacketUtils.KickType.PING, "Tried send fake ping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long ping = System.currentTimeMillis() - this.lastSend;
|
||||||
|
this.totalping = this.totalping == 9999L ? ping : this.totalping + ping;
|
||||||
|
this.lastSend = 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(PluginMessage pluginMessage) throws Exception {
|
||||||
|
this.pluginMessagesBytes += pluginMessage.getTag().length() * 4;
|
||||||
|
this.pluginMessagesBytes += pluginMessage.getData().length;
|
||||||
|
if (this.pluginMessagesBytes > 160000) {
|
||||||
|
this.failed(PacketUtils.KickType.BIG_PACKET, "Bad PluginMessage's");
|
||||||
|
} else {
|
||||||
|
this.userConnection.getPendingConnection().relayMessage0(pluginMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(SetCompression setCompression) throws Exception {
|
||||||
|
this.ch.setCompressionThreshold(setCompression.getThreshold());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPing() {
|
||||||
|
if (this.lastSend == 0L && this.state != LimboFilter.CheckState.FAILED && this.state != LimboFilter.CheckState.SUCCESSFULLY) {
|
||||||
|
this.lastSend = System.currentTimeMillis();
|
||||||
|
++this.sentPings;
|
||||||
|
this.channel.writeAndFlush(PacketUtils.getCachedPacket(CachedPacketType.KEEPALIVE).get(this.version));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendCaptcha() {
|
||||||
|
CachedCaptcha.CaptchaHolder captchaHolder = PacketUtils.captchas.randomCaptcha();
|
||||||
|
if (captchaHolder != null) {
|
||||||
|
this.captchaAnswer = captchaHolder.getAnswer();
|
||||||
|
this.channel.write(PacketUtils.getCachedPacket(CachedPacketType.SETSLOT_MAP).get(this.version), this.channel.voidPromise());
|
||||||
|
captchaHolder.write(this.channel, this.version, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeStateToCaptcha() {
|
||||||
|
this.state = LimboFilter.CheckState.ONLY_CAPTCHA;
|
||||||
|
this.joinTime = System.currentTimeMillis() + 3500L;
|
||||||
|
this.channel.write(PacketUtils.getCachedPacket(CachedPacketType.SETEXP_RESET).get(this.version), this.channel.voidPromise());
|
||||||
|
((CachedTitle)PacketUtils.titles.get(CachedPacketType.ENTER_CAPTCHA_TITLE)).writeTitle(this.channel, this.version);
|
||||||
|
this.resetPosition(true);
|
||||||
|
this.sendCaptcha();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConnected() {
|
||||||
|
return this.userConnection != null && this.channel != null && !this.markDisconnected && this.userConnection.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void failed(PacketUtils.KickType type, String kickMessage) {
|
||||||
|
this.state = LimboFilter.CheckState.FAILED;
|
||||||
|
FlameCord.getInstance().getBlockedPlayersNotifier().recordBlocked(this.name != null ? this.name : this.ip);
|
||||||
|
PacketUtils.kickPlayer(type, Protocol.GAME, this.userConnection.getCh(), this.version);
|
||||||
|
this.markDisconnected = true;
|
||||||
|
if (FlameCord.getInstance().getFlameCordConfiguration().isAntibotLimboLog()) {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Player (" + this.name + "|" + this.ip + ") check failed: " + kickMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(CachedPacketType type) {
|
||||||
|
((CachedMessage)PacketUtils.messages.get(type)).write(this.getChannel(), this.getVersion());
|
||||||
|
this.getChannel().flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "[" + this.name + "|" + this.ip + "] <-> Limbo";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof LimboHandler)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
LimboHandler other = (LimboHandler)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Object this$name = this.getName();
|
||||||
|
Object other$name = other.getName();
|
||||||
|
if (this$name == null) {
|
||||||
|
if (other$name != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$name.equals(other$name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof LimboHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
Object $name = this.getName();
|
||||||
|
result = result * 59 + ($name == null ? 43 : $name.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getVersion() {
|
||||||
|
return this.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public UserConnection getUserConnection() {
|
||||||
|
return this.userConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public LimboFilter.CheckState getState() {
|
||||||
|
return this.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setState(LimboFilter.CheckState state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Channel getChannel() {
|
||||||
|
return this.channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public long getJoinTime() {
|
||||||
|
return this.joinTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isCheckStarted() {
|
||||||
|
return this.checkStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public long getLastMessageSent() {
|
||||||
|
return this.lastMessageSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setLastMessageSent(long lastMessageSent) {
|
||||||
|
this.lastMessageSent = lastMessageSent;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.handlers;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.packets.Player;
|
||||||
|
import dev._2lstudios.flamecord.packets.PlayerPosition;
|
||||||
|
import dev._2lstudios.flamecord.packets.PlayerPositionAndLook;
|
||||||
|
import dev._2lstudios.flamecord.packets.TeleportConfirm;
|
||||||
|
import net.md_5.bungee.UserConnection;
|
||||||
|
import net.md_5.bungee.netty.PacketHandler;
|
||||||
|
|
||||||
|
public class MoveHandler extends PacketHandler {
|
||||||
|
private static final int DEFAULT_TELEPORT_ID = 9876;
|
||||||
|
private static final double INVALID_Y_POSITION = (double)-1.0F;
|
||||||
|
public static final int TELEPORT_TRIGGER_Y = 120;
|
||||||
|
private static final double TELEPORT_TRIGGER_XZ = (double)7.0F;
|
||||||
|
public double x = (double)0.0F;
|
||||||
|
public double y = (double)0.0F;
|
||||||
|
public double z = (double)0.0F;
|
||||||
|
public boolean onGround = false;
|
||||||
|
public int teleportId = -1;
|
||||||
|
public int waitingTeleportId = 9876;
|
||||||
|
public double lastY = (double)0.0F;
|
||||||
|
public int ticks = 0;
|
||||||
|
private final UserConnection userConnection;
|
||||||
|
|
||||||
|
public MoveHandler(UserConnection userConnection) {
|
||||||
|
this.userConnection = userConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Player player) throws Exception {
|
||||||
|
this.onGround = player.isOnGround();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(PlayerPosition pos) throws Exception {
|
||||||
|
this.x = pos.getX();
|
||||||
|
this.lastY = this.y;
|
||||||
|
this.y = pos.getY();
|
||||||
|
this.z = pos.getZ();
|
||||||
|
this.onGround = pos.isOnGround();
|
||||||
|
this.onMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(PlayerPositionAndLook posRot) throws Exception {
|
||||||
|
if (this.isTeleportTriggered(posRot)) {
|
||||||
|
this.resetTeleportData();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.updatePosition(posRot)) {
|
||||||
|
this.onMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(TeleportConfirm confirm) throws Exception {
|
||||||
|
if (confirm.getTeleportId() == this.waitingTeleportId) {
|
||||||
|
this.resetTeleportData();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean updatePosition(PlayerPositionAndLook posRot) {
|
||||||
|
boolean changed = false;
|
||||||
|
if (this.x != posRot.getX()) {
|
||||||
|
this.x = posRot.getX();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.lastY != this.y || this.y != posRot.getY()) {
|
||||||
|
this.lastY = this.y;
|
||||||
|
this.y = posRot.getY();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.z != posRot.getZ()) {
|
||||||
|
this.z = posRot.getZ();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.onGround != posRot.isOnGround()) {
|
||||||
|
this.onGround = posRot.isOnGround();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTeleportTriggered(PlayerPositionAndLook posRot) {
|
||||||
|
return this.userConnection.getPendingConnection().getVersion() <= 47 && posRot.getX() == (double)7.0F && posRot.getY() == (double)120.0F && posRot.getZ() == (double)7.0F && this.waitingTeleportId == 9876;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTeleportData() {
|
||||||
|
this.ticks = 0;
|
||||||
|
this.y = (double)-1.0F;
|
||||||
|
this.lastY = (double)-1.0F;
|
||||||
|
this.waitingTeleportId = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onMove() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getSpeed(int ticks) {
|
||||||
|
double powResult = Math.pow(0.98, (double)ticks) - (double)1.0F;
|
||||||
|
double speed = -(powResult * 3.92);
|
||||||
|
return formatDouble(speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double formatDouble(double value) {
|
||||||
|
return Math.floor(value * (double)100.0F) / (double)100.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "MoveHandler{x=" + this.x + ", y=" + this.y + ", z=" + this.z + ", onGround=" + this.onGround + ", teleportId=" + this.teleportId + ", waitingTeleportId=" + this.waitingTeleportId + ", lastY=" + this.lastY + ", ticks=" + this.ticks + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.proxy;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class IPCollection {
|
||||||
|
private final Map<String, IPCollection> children = new ConcurrentHashMap();
|
||||||
|
private boolean isEndOfIP = false;
|
||||||
|
private int ipCount = 0;
|
||||||
|
|
||||||
|
public void add(String ip) {
|
||||||
|
String[] octets = ip.split("\\.");
|
||||||
|
if (this.addRecursive(octets, 0)) {
|
||||||
|
++this.ipCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean addRecursive(String[] octets, int index) {
|
||||||
|
if (index >= octets.length) {
|
||||||
|
if (!this.isEndOfIP) {
|
||||||
|
this.isEndOfIP = true;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String octet = octets[index];
|
||||||
|
IPCollection child = (IPCollection)this.children.computeIfAbsent(octet, (k) -> new IPCollection());
|
||||||
|
return child.addRecursive(octets, index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(String ip) {
|
||||||
|
String[] octets = ip.split("\\.");
|
||||||
|
return this.containsRecursive(octets, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containsRecursive(String[] octets, int index) {
|
||||||
|
if (index >= octets.length) {
|
||||||
|
return this.isEndOfIP;
|
||||||
|
} else {
|
||||||
|
IPCollection child = (IPCollection)this.children.get(octets[index]);
|
||||||
|
return child == null ? false : child.containsRecursive(octets, index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSubnet(String baseIp, int subnetMask) {
|
||||||
|
String[] octets = baseIp.split("\\.");
|
||||||
|
this.addSubnetRecursive(octets, subnetMask, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addSubnetRecursive(String[] octets, int subnetMask, int index) {
|
||||||
|
if (subnetMask > 0 && index < octets.length) {
|
||||||
|
String octet = octets[index];
|
||||||
|
IPCollection child = (IPCollection)this.children.computeIfAbsent(octet, (k) -> new IPCollection());
|
||||||
|
child.addSubnetRecursive(octets, subnetMask - 8, index + 1);
|
||||||
|
} else {
|
||||||
|
this.isEndOfIP = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.ipCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.proxy;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.addressdata.AddressDataManager;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class ProxyCheck {
|
||||||
|
private FlameCordConfiguration config;
|
||||||
|
private LoggerWrapper logger;
|
||||||
|
private AddressDataManager addressDataManager;
|
||||||
|
private IPCollection ipCollection = new IPCollection();
|
||||||
|
|
||||||
|
public ProxyCheck(AddressDataManager addressDataManager) {
|
||||||
|
this.addressDataManager = addressDataManager;
|
||||||
|
this.config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
this.logger = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateProxies() {
|
||||||
|
List<String> lists = this.config.getAntibotProxyLists();
|
||||||
|
if (!lists.isEmpty()) {
|
||||||
|
Collection<ProxyLoadTask> proxyLoadTasks = new HashSet();
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Updating proxy database from " + lists.size() + " websites... (It can take a while!)");
|
||||||
|
|
||||||
|
for(String website : lists) {
|
||||||
|
ProxyLoadTask loadingTask = new ProxyLoadTask(this, website);
|
||||||
|
proxyLoadTasks.add(loadingTask);
|
||||||
|
loadingTask.start(proxyLoadTasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProxyRecurringCheck.start(proxyLoadTasks, this.ipCollection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(String ip) {
|
||||||
|
return this.ipCollection.contains(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(SocketAddress address) {
|
||||||
|
if (!this.config.isAntibotProxyEnabled()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
AddressData addressData = this.addressDataManager.getAddressData(address);
|
||||||
|
if (addressData.isWhitelisted()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
String ip = addressData.getHostString();
|
||||||
|
Collection<String> whitelist = this.config.getAntibotProxyWhitelist();
|
||||||
|
if (whitelist.contains(ip)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.check(ip)) {
|
||||||
|
if (this.config.isAntibotProxyLog()) {
|
||||||
|
this.logger.log(Level.INFO, "[{0}] was blocked for using a VPN/Proxy service", address);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isAntibotProxyFirewall()) {
|
||||||
|
addressData.firewall("Using VPN/Proxy services");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addProxy(String address) {
|
||||||
|
if (address.contains("/")) {
|
||||||
|
String[] parts = address.split("/");
|
||||||
|
String baseIp = parts[0];
|
||||||
|
int subnetMask = 32;
|
||||||
|
if (parts.length > 1) {
|
||||||
|
try {
|
||||||
|
subnetMask = Integer.parseInt(parts[1]);
|
||||||
|
} catch (NumberFormatException var6) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ipCollection.addSubnet(baseIp, subnetMask);
|
||||||
|
} else {
|
||||||
|
this.ipCollection.add(address.split(":")[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.proxy;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class ProxyLoadTask {
|
||||||
|
private ProxyCheck proxyCheck;
|
||||||
|
private String website;
|
||||||
|
private long finishTime = 0L;
|
||||||
|
private boolean finished = false;
|
||||||
|
|
||||||
|
public ProxyLoadTask(ProxyCheck proxyCheck, String website) {
|
||||||
|
this.proxyCheck = proxyCheck;
|
||||||
|
this.website = website;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finish() {
|
||||||
|
this.finishTime = System.currentTimeMillis();
|
||||||
|
this.finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean finished() {
|
||||||
|
return this.finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(Collection<ProxyLoadTask> proxyLoadTasks) {
|
||||||
|
(new Thread() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
URL url = new URL(ProxyLoadTask.this.website);
|
||||||
|
HttpURLConnection con = (HttpURLConnection)url.openConnection();
|
||||||
|
con.setConnectTimeout(5000);
|
||||||
|
con.setReadTimeout(5000);
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
int responseCode = con.getResponseCode();
|
||||||
|
if (responseCode == 200) {
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
|
||||||
|
String inputLine;
|
||||||
|
while((inputLine = in.readLine()) != null) {
|
||||||
|
if (!inputLine.startsWith("#")) {
|
||||||
|
ProxyLoadTask.this.proxyCheck.addProxy(inputLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
in.close();
|
||||||
|
} else {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().log(Level.INFO, "Failed to load proxies from " + ProxyLoadTask.this.website);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().log(Level.INFO, "Error while loading proxies from " + ProxyLoadTask.this.website);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ProxyLoadTask.this.finish();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFinishTime() {
|
||||||
|
return this.finishTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.proxy;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class ProxyRecurringCheck {
|
||||||
|
public static void start(final Collection<ProxyLoadTask> proxyLoadTasks, final IPCollection proxies) {
|
||||||
|
final long startTime = System.currentTimeMillis();
|
||||||
|
(new Thread() {
|
||||||
|
public void run() {
|
||||||
|
int taskCount = proxyLoadTasks.size();
|
||||||
|
int finishedCount = 0;
|
||||||
|
|
||||||
|
for(ProxyLoadTask loadingTask : proxyLoadTasks) {
|
||||||
|
if (loadingTask.finished()) {
|
||||||
|
++finishedCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (finishedCount < taskCount) {
|
||||||
|
String finishedPercentage = String.format("%.2f", (double)finishedCount / (double)taskCount * (double)100.0F);
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Loading proxies (" + finishedPercentage + "%)");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000L);
|
||||||
|
} catch (InterruptedException var9) {
|
||||||
|
}
|
||||||
|
|
||||||
|
this.run();
|
||||||
|
} else {
|
||||||
|
long finishTime = 0L;
|
||||||
|
|
||||||
|
for(ProxyLoadTask loadingTask : proxyLoadTasks) {
|
||||||
|
long loadingFinishTime = loadingTask.getFinishTime();
|
||||||
|
if (loadingFinishTime > finishTime) {
|
||||||
|
finishTime = loadingFinishTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String timeTook = String.format("%.2f", (double)(finishTime - startTime) / (double)1000.0F);
|
||||||
|
LoggerWrapper var10000 = FlameCord.getInstance().getLoggerWrapper();
|
||||||
|
int var10001 = proxies.size();
|
||||||
|
var10000.info("Loaded a total of " + var10001 + " proxies to the database (" + timeTook + "s)!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package dev._2lstudios.flamecord.antibot.utils;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Whitelist {
|
||||||
|
private String fileName;
|
||||||
|
private Set<String> loadedEntries = new HashSet();
|
||||||
|
private Set<String> newEntries = new HashSet();
|
||||||
|
|
||||||
|
public Whitelist(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String entry) {
|
||||||
|
if (entry != null) {
|
||||||
|
if (!this.loadedEntries.contains(entry)) {
|
||||||
|
this.newEntries.add(entry);
|
||||||
|
this.loadedEntries.add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
try {
|
||||||
|
BufferedReader reader = new BufferedReader(new FileReader(this.fileName));
|
||||||
|
|
||||||
|
String line;
|
||||||
|
try {
|
||||||
|
while((line = reader.readLine()) != null) {
|
||||||
|
this.loadedEntries.add(line);
|
||||||
|
}
|
||||||
|
} catch (Throwable var5) {
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (Throwable var4) {
|
||||||
|
var5.addSuppressed(var4);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw var5;
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.close();
|
||||||
|
} catch (FileNotFoundException var6) {
|
||||||
|
} catch (Exception var7) {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Error while loading whitelisted items from file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
File file = new File(this.fileName);
|
||||||
|
if (!file.exists()) {
|
||||||
|
File parentDir = file.getParentFile();
|
||||||
|
if (parentDir != null && !parentDir.exists()) {
|
||||||
|
parentDir.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
PrintWriter writer = new PrintWriter(new FileWriter(this.fileName, true));
|
||||||
|
|
||||||
|
try {
|
||||||
|
for(String item : this.newEntries) {
|
||||||
|
writer.println(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.newEntries.clear();
|
||||||
|
} catch (Throwable var6) {
|
||||||
|
try {
|
||||||
|
writer.close();
|
||||||
|
} catch (Throwable var5) {
|
||||||
|
var6.addSuppressed(var5);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw var6;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
} catch (Exception var7) {
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Error while saving whitelisted items to file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
this.loadedEntries.clear();
|
||||||
|
this.newEntries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(String entry) {
|
||||||
|
return this.loadedEntries.contains(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package dev._2lstudios.flamecord.balancer;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import net.md_5.bungee.ServerConnection;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
|
||||||
|
public class Balancer {
|
||||||
|
public static ServerInfo getBestServer() {
|
||||||
|
ServerInfo serverWithLeastPlayers = null;
|
||||||
|
int minPlayerCount = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
for(String serverName : FlameCord.getInstance().getFlameCordConfiguration().getBalancerServers()) {
|
||||||
|
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(serverName);
|
||||||
|
if (serverInfo != null) {
|
||||||
|
int playerCount = serverInfo.getPlayers().size();
|
||||||
|
if (playerCount < minPlayerCount) {
|
||||||
|
minPlayerCount = playerCount;
|
||||||
|
serverWithLeastPlayers = serverInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverWithLeastPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEnabled() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().isBalancerEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isOnJoin() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().isBalancerOnJoin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isServer(ServerConnection server) {
|
||||||
|
return server == null ? false : isServer((ServerInfo)server.getInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isServer(ServerInfo server) {
|
||||||
|
return server == null ? false : FlameCord.getInstance().getFlameCordConfiguration().getBalancerServers().contains(server.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFallback() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().isBalancerFallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isUseLobbyCommand() {
|
||||||
|
return FlameCord.getInstance().getFlameCordConfiguration().isBalancerLobbyCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isServerCommandBlacklisted(ServerInfo server) {
|
||||||
|
return server == null ? true : FlameCord.getInstance().getFlameCordConfiguration().getBalancerCommandBlacklist().contains(server.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package dev._2lstudios.flamecord.captcha;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedCaptcha;
|
||||||
|
import dev._2lstudios.flamecord.captcha.generator.CaptchaPainter;
|
||||||
|
import dev._2lstudios.flamecord.captcha.generator.map.CraftMapCanvas;
|
||||||
|
import dev._2lstudios.flamecord.captcha.generator.map.MapPalette;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import dev._2lstudios.flamecord.packets.MapDataPacket;
|
||||||
|
import dev._2lstudios.flamecord.utils.PacketUtils;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import lombok.Generated;
|
||||||
|
|
||||||
|
public final class CaptchaGeneration {
|
||||||
|
private static final Random rnd = new Random();
|
||||||
|
|
||||||
|
private static Font resolveFont(String familyName) {
|
||||||
|
int style = 0;
|
||||||
|
if (familyName.equalsIgnoreCase("MONOSPACED")) {
|
||||||
|
style = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Font font = new Font(familyName, style, 12);
|
||||||
|
return font;
|
||||||
|
} catch (Exception var3) {
|
||||||
|
return new Font("SansSerif", style, 12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Font pickRandomFont(FlameCordConfiguration config) {
|
||||||
|
List<String> families = config.getAntibotLimboCaptchaFonts();
|
||||||
|
String family = (String)families.get(rnd.nextInt(families.size()));
|
||||||
|
Font font = resolveFont(family);
|
||||||
|
int minSize = Math.max(10, config.getAntibotLimboCaptchaFontSizeMin());
|
||||||
|
int maxSize = Math.max(minSize, config.getAntibotLimboCaptchaFontSizeMax());
|
||||||
|
int size = minSize + rnd.nextInt(Math.max(1, maxSize - minSize + 1));
|
||||||
|
return font.deriveFont((float)size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void generateImages() {
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||||
|
CaptchaPainter painter = new CaptchaPainter();
|
||||||
|
FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
int numCaptchas = config.getAntibotLimboCaptchaCount();
|
||||||
|
MapPalette.prepareColors();
|
||||||
|
Color bgColor = parseColor(config.getAntibotLimboCaptchaBackground());
|
||||||
|
painter.setBackground(bgColor);
|
||||||
|
|
||||||
|
for(int i = 0; i < numCaptchas; ++i) {
|
||||||
|
executor.execute(() -> {
|
||||||
|
String answer = randomAnswer(config);
|
||||||
|
Font font = pickRandomFont(config);
|
||||||
|
Color fgColor = randomForeground(config);
|
||||||
|
BufferedImage image = painter.draw(font, fgColor, answer);
|
||||||
|
drawRandomLines(image, config);
|
||||||
|
CraftMapCanvas map = new CraftMapCanvas();
|
||||||
|
map.drawImage(0, 0, image);
|
||||||
|
MapDataPacket packet = new MapDataPacket(0, (byte)0, map.getMapData());
|
||||||
|
PacketUtils.captchas.createCaptchaPacket(packet, answer);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
monitorAndShutdownExecutor(executor, numCaptchas);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color parseColor(String name) {
|
||||||
|
try {
|
||||||
|
return (Color)Color.class.getField(name.toUpperCase()).get((Object)null);
|
||||||
|
} catch (Exception var2) {
|
||||||
|
return Color.WHITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void monitorAndShutdownExecutor(ExecutorService executor, int numCaptchas) {
|
||||||
|
ScheduledExecutorService monitor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
ThreadPoolExecutor threadPool = (ThreadPoolExecutor)executor;
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
monitor.scheduleAtFixedRate(() -> {
|
||||||
|
int remaining = numCaptchas - threadPool.getQueue().size() - threadPool.getActiveCount();
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Generating captcha [" + remaining + "/" + numCaptchas + "]");
|
||||||
|
if (threadPool.getActiveCount() == 0 && threadPool.getQueue().isEmpty()) {
|
||||||
|
monitor.shutdown();
|
||||||
|
CachedCaptcha.setGenerated(true);
|
||||||
|
executor.shutdown();
|
||||||
|
FlameCord.getInstance().getLoggerWrapper().info("Captcha generated in " + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 0L, 1L, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawRandomLines(BufferedImage image, FlameCordConfiguration config) {
|
||||||
|
Graphics2D g2d = (Graphics2D)image.getGraphics();
|
||||||
|
int count = Math.max(0, config.getAntibotLimboCaptchaLineCount());
|
||||||
|
|
||||||
|
for(int i = 0; i < count; ++i) {
|
||||||
|
if (config.isAntibotLimboCaptchaLineRandomColor()) {
|
||||||
|
g2d.setColor(randomLineColor());
|
||||||
|
} else {
|
||||||
|
g2d.setColor(randomForeground(config));
|
||||||
|
}
|
||||||
|
|
||||||
|
int x1 = rnd.nextInt(image.getWidth());
|
||||||
|
int y1 = rnd.nextInt(image.getHeight());
|
||||||
|
int x2 = rnd.nextInt(image.getWidth());
|
||||||
|
int y2 = rnd.nextInt(image.getHeight());
|
||||||
|
g2d.drawLine(x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
g2d.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color randomLineColor() {
|
||||||
|
return new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color randomForeground(FlameCordConfiguration config) {
|
||||||
|
int min = config.getAntibotLimboCaptchaForegroundMin();
|
||||||
|
int max = config.getAntibotLimboCaptchaForegroundMax();
|
||||||
|
if (min < 0) {
|
||||||
|
min = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max > 255) {
|
||||||
|
max = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max < min) {
|
||||||
|
max = min;
|
||||||
|
}
|
||||||
|
|
||||||
|
int range = max - min + 1;
|
||||||
|
int threshold = 220;
|
||||||
|
int attempts = 0;
|
||||||
|
|
||||||
|
Color color;
|
||||||
|
do {
|
||||||
|
color = new Color(min + rnd.nextInt(range), min + rnd.nextInt(range), min + rnd.nextInt(range));
|
||||||
|
++attempts;
|
||||||
|
} while(isNearWhite(color, threshold) && attempts < 20);
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isNearWhite(Color color, int threshold) {
|
||||||
|
return color.getRed() > threshold && color.getGreen() > threshold && color.getBlue() > threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String randomAnswer(FlameCordConfiguration config) {
|
||||||
|
int minLen = Math.max(1, config.getAntibotLimboCaptchaLengthMin());
|
||||||
|
int maxLen = Math.max(minLen, config.getAntibotLimboCaptchaLengthMax());
|
||||||
|
int length = minLen + rnd.nextInt(Math.max(1, maxLen - minLen + 1));
|
||||||
|
return Integer.toString((int)Math.pow((double)10.0F, (double)(length - 1)) + rnd.nextInt((int)Math.pow((double)10.0F, (double)length) - (int)Math.pow((double)10.0F, (double)(length - 1))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
private CaptchaGeneration() {
|
||||||
|
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package dev._2lstudios.flamecord.captcha.generator;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.font.FontRenderContext;
|
||||||
|
import java.awt.font.GlyphVector;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.ConvolveOp;
|
||||||
|
import java.awt.image.Kernel;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class CaptchaPainter {
|
||||||
|
private final int width = 128;
|
||||||
|
private final int height = 128;
|
||||||
|
private Color background;
|
||||||
|
private final Random rnd;
|
||||||
|
|
||||||
|
public CaptchaPainter() {
|
||||||
|
this.background = Color.WHITE;
|
||||||
|
this.rnd = new Random();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackground(Color background) {
|
||||||
|
if (background != null) {
|
||||||
|
this.background = background;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage draw(Font font, Color fGround, String text) {
|
||||||
|
if (font == null) {
|
||||||
|
throw new IllegalArgumentException("Font can not be null.");
|
||||||
|
} else if (fGround == null) {
|
||||||
|
throw new IllegalArgumentException("Foreground color can not be null.");
|
||||||
|
} else if (text != null && text.length() >= 1) {
|
||||||
|
BufferedImage img = this.createImage();
|
||||||
|
Graphics g = img.getGraphics();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Graphics2D g2 = this.configureGraphics(g, font, fGround);
|
||||||
|
this.draw(g2, text);
|
||||||
|
} finally {
|
||||||
|
g.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
img = this.postProcess(img);
|
||||||
|
return img;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("No text given.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BufferedImage createImage() {
|
||||||
|
return new BufferedImage(128, 128, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Graphics2D configureGraphics(Graphics g, Font font, Color fGround) {
|
||||||
|
if (!(g instanceof Graphics2D g2)) {
|
||||||
|
throw new IllegalStateException("Graphics (" + String.valueOf(g) + ") that is not an instance of Graphics2D.");
|
||||||
|
} else {
|
||||||
|
this.configureGraphicsQuality(g2);
|
||||||
|
g2.setColor(fGround);
|
||||||
|
g2.setBackground(this.background);
|
||||||
|
g2.setFont(font);
|
||||||
|
g2.clearRect(0, 0, 128, 128);
|
||||||
|
return g2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void configureGraphicsQuality(Graphics2D g2) {
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void draw(Graphics2D g, String text) {
|
||||||
|
GlyphVector vector = g.getFont().createGlyphVector(g.getFontRenderContext(), text);
|
||||||
|
this.transform(g, text, vector);
|
||||||
|
Rectangle bounds = vector.getPixelBounds((FontRenderContext)null, 0.0F, 128.0F);
|
||||||
|
float bw = (float)bounds.getWidth();
|
||||||
|
float bh = (float)bounds.getHeight();
|
||||||
|
boolean outlineEnabled = true;
|
||||||
|
float wr = 128.0F / bw * (this.rnd.nextFloat() / 20.0F + 0.89F) * 1.0F;
|
||||||
|
float hr = 128.0F / bh * (this.rnd.nextFloat() / 20.0F + 0.68F) * 1.0F;
|
||||||
|
g.translate((double)((128.0F - bw * wr) / 2.0F), (double)((128.0F - bh * hr) / 2.0F));
|
||||||
|
g.scale((double)wr, (double)hr);
|
||||||
|
float bx = (float)bounds.getX();
|
||||||
|
float by = (float)bounds.getY();
|
||||||
|
g.draw(vector.getOutline(Math.signum(this.rnd.nextFloat() - 0.5F) * 1.0F * 128.0F / 200.0F - bx, Math.signum(this.rnd.nextFloat() - 0.5F) * 1.0F * 128.0F / 70.0F + 128.0F - by));
|
||||||
|
g.drawGlyphVector(vector, -bx, 128.0F - by);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void transform(Graphics2D g, String text, GlyphVector v) {
|
||||||
|
int glyphNum = v.getNumGlyphs();
|
||||||
|
Point2D prePos = null;
|
||||||
|
Rectangle2D preBounds = null;
|
||||||
|
double rotateCur = (this.rnd.nextDouble() - (double)0.5F) * Math.PI / (double)8.0F;
|
||||||
|
double rotateStep = Math.signum(rotateCur) * (this.rnd.nextDouble() * (double)3.0F * Math.PI / (double)8.0F / (double)glyphNum);
|
||||||
|
boolean rotateEnabled = true;
|
||||||
|
|
||||||
|
for(int fi = 0; fi < glyphNum; ++fi) {
|
||||||
|
AffineTransform tr = AffineTransform.getRotateInstance(rotateCur);
|
||||||
|
if (this.rnd.nextDouble() < (double)0.25F) {
|
||||||
|
rotateStep *= (double)-1.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
rotateCur += rotateStep;
|
||||||
|
v.setGlyphTransform(fi, tr);
|
||||||
|
Point2D pos = v.getGlyphPosition(fi);
|
||||||
|
Rectangle2D bounds = v.getGlyphVisualBounds(fi).getBounds2D();
|
||||||
|
Point2D newPos;
|
||||||
|
if (prePos == null) {
|
||||||
|
newPos = new Point2D.Double(pos.getX() - bounds.getX(), pos.getY());
|
||||||
|
} else {
|
||||||
|
newPos = new Point2D.Double(preBounds.getMaxX() + pos.getX() - bounds.getX() - Math.min(preBounds.getWidth(), bounds.getWidth()) * (this.rnd.nextDouble() / (double)20.0F + 0.27), pos.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
v.setGlyphPosition(fi, newPos);
|
||||||
|
prePos = newPos;
|
||||||
|
preBounds = v.getGlyphVisualBounds(fi).getBounds2D();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BufferedImage postProcess(BufferedImage img) {
|
||||||
|
Rippler.AxisConfig vertical = new Rippler.AxisConfig(this.rnd.nextDouble() * (double)2.0F * Math.PI, ((double)1.0F + this.rnd.nextDouble() * (double)2.0F) * Math.PI, (double)img.getHeight() / (double)10.0F);
|
||||||
|
Rippler.AxisConfig horizontal = new Rippler.AxisConfig(this.rnd.nextDouble() * (double)2.0F * Math.PI, ((double)2.0F + this.rnd.nextDouble() * (double)2.0F) * Math.PI, (double)img.getWidth() / (double)100.0F);
|
||||||
|
Rippler op = new Rippler(vertical, horizontal);
|
||||||
|
img = op.filter(img, this.createImage());
|
||||||
|
float[] blurArray = new float[9];
|
||||||
|
this.fillBlurArray(blurArray);
|
||||||
|
ConvolveOp blur = new ConvolveOp(new Kernel(3, 3, blurArray), 1, (RenderingHints)null);
|
||||||
|
img = blur.filter(img, this.createImage());
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillBlurArray(float[] array) {
|
||||||
|
float sum = 0.0F;
|
||||||
|
|
||||||
|
for(int fi = 0; fi < array.length; ++fi) {
|
||||||
|
array[fi] = this.rnd.nextFloat();
|
||||||
|
sum += array[fi];
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int fi = 0; fi < array.length; ++fi) {
|
||||||
|
array[fi] /= sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package dev._2lstudios.flamecord.captcha.generator;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class Rippler {
|
||||||
|
private final AxisConfig vertical;
|
||||||
|
private final AxisConfig horizontal;
|
||||||
|
|
||||||
|
public Rippler(AxisConfig vertical, AxisConfig horizontal) {
|
||||||
|
this.vertical = vertical;
|
||||||
|
this.horizontal = horizontal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage filter(BufferedImage src, BufferedImage dest) {
|
||||||
|
int width = src.getWidth();
|
||||||
|
int height = src.getHeight();
|
||||||
|
int[] verticalDelta = this.calcDeltaArray(this.vertical, width);
|
||||||
|
int[] horizontalDelta = this.calcDeltaArray(this.horizontal, height);
|
||||||
|
|
||||||
|
for(int x = 0; x < width; ++x) {
|
||||||
|
for(int y = 0; y < height; ++y) {
|
||||||
|
int ny = (y + verticalDelta[x] + height) % height;
|
||||||
|
int nx = (x + horizontalDelta[ny] + width) % width;
|
||||||
|
dest.setRGB(nx, ny, src.getRGB(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int[] calcDeltaArray(AxisConfig axisConfig, int num) {
|
||||||
|
int[] delta = new int[num];
|
||||||
|
double start = axisConfig.getStart();
|
||||||
|
double period = axisConfig.getLength() / (double)num;
|
||||||
|
double amplitude = axisConfig.getAmplitude();
|
||||||
|
|
||||||
|
for(int fi = 0; fi < num; ++fi) {
|
||||||
|
delta[fi] = (int)Math.round(amplitude * Math.sin(start + (double)fi * period));
|
||||||
|
}
|
||||||
|
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AxisConfig getVertical() {
|
||||||
|
return this.vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AxisConfig getHorizontal() {
|
||||||
|
return this.horizontal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AxisConfig {
|
||||||
|
private final double start;
|
||||||
|
private final double length;
|
||||||
|
private final double amplitude;
|
||||||
|
|
||||||
|
public AxisConfig(double start, double length, double amplitude) {
|
||||||
|
this.start = this.normalize(start, 2);
|
||||||
|
this.length = this.normalize(length, 4);
|
||||||
|
this.amplitude = amplitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected double normalize(double a, int multi) {
|
||||||
|
double piMulti = (double)multi * Math.PI;
|
||||||
|
a = Math.abs(a);
|
||||||
|
double d = Math.floor(a / piMulti);
|
||||||
|
return a - d * piMulti;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getStart() {
|
||||||
|
return this.start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLength() {
|
||||||
|
return this.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getAmplitude() {
|
||||||
|
return this.amplitude;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package dev._2lstudios.flamecord.captcha.generator.map;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.packets.MapDataPacket;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.ImageObserver;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class CraftMapCanvas {
|
||||||
|
private static final ThreadLocal<byte[]> mcPixelsBuffer = ThreadLocal.withInitial(() -> new byte[16384]);
|
||||||
|
private final byte[] buffer;
|
||||||
|
|
||||||
|
public CraftMapCanvas() {
|
||||||
|
this.buffer = (byte[])mcPixelsBuffer.get();
|
||||||
|
Arrays.fill(this.buffer, (byte)-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPixel(int x, int y, byte color) {
|
||||||
|
if (x >= 0 && y >= 0 && x < 128 && y < 128 && this.buffer[y * 128 + x] != color) {
|
||||||
|
this.buffer[y * 128 + x] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawImage(int x, int y, BufferedImage image) {
|
||||||
|
int[] bytes = MapPalette.imageToBytes(image);
|
||||||
|
int width = image.getWidth((ImageObserver)null);
|
||||||
|
int height = image.getHeight((ImageObserver)null);
|
||||||
|
|
||||||
|
for(int x2 = 0; x2 < width; ++x2) {
|
||||||
|
for(int y2 = 0; y2 < height; ++y2) {
|
||||||
|
this.setPixel(x + x2, y + y2, (byte)bytes[y2 * width + x2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapDataPacket.MapData getMapData() {
|
||||||
|
return new MapDataPacket.MapData(128, 128, 0, 0, this.buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package dev._2lstudios.flamecord.captcha.generator.map;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class MapPalette {
|
||||||
|
private static final ThreadLocal<int[]> rgbBuffer = ThreadLocal.withInitial(() -> new int[16384]);
|
||||||
|
public static final Color[] colors = new Color[]{c(0, 0, 0), c(0, 0, 0), c(0, 0, 0), c(0, 0, 0), c(89, 125, 39), c(109, 153, 48), c(127, 178, 56), c(67, 94, 29), c(174, 164, 115), c(213, 201, 140), c(247, 233, 163), c(130, 123, 86), c(140, 140, 140), c(171, 171, 171), c(199, 199, 199), c(105, 105, 105), c(180, 0, 0), c(220, 0, 0), c(255, 0, 0), c(135, 0, 0), c(112, 112, 180), c(138, 138, 220), c(160, 160, 255), c(84, 84, 135), c(117, 117, 117), c(144, 144, 144), c(167, 167, 167), c(88, 88, 88), c(0, 87, 0), c(0, 106, 0), c(0, 124, 0), c(0, 65, 0), c(180, 180, 180), c(220, 220, 220), c(255, 255, 255), c(135, 135, 135), c(115, 118, 129), c(141, 144, 158), c(164, 168, 184), c(86, 88, 97), c(106, 76, 54), c(130, 94, 66), c(151, 109, 77), c(79, 57, 40), c(79, 79, 79), c(96, 96, 96), c(112, 112, 112), c(59, 59, 59), c(45, 45, 180), c(55, 55, 220), c(64, 64, 255), c(33, 33, 135), c(100, 84, 50), c(123, 102, 62), c(143, 119, 72), c(75, 63, 38), c(180, 177, 172), c(220, 217, 211), c(255, 252, 245), c(135, 133, 129), c(152, 89, 36), c(186, 109, 44), c(216, 127, 51), c(114, 67, 27), c(125, 53, 152), c(153, 65, 186), c(178, 76, 216), c(94, 40, 114), c(72, 108, 152), c(88, 132, 186), c(102, 153, 216), c(54, 81, 114), c(161, 161, 36), c(197, 197, 44), c(229, 229, 51), c(121, 121, 27), c(89, 144, 17), c(109, 176, 21), c(127, 204, 25), c(67, 108, 13), c(170, 89, 116), c(208, 109, 142), c(242, 127, 165), c(128, 67, 87), c(53, 53, 53), c(65, 65, 65), c(76, 76, 76), c(40, 40, 40), c(108, 108, 108), c(132, 132, 132), c(153, 153, 153), c(81, 81, 81), c(53, 89, 108), c(65, 109, 132), c(76, 127, 153), c(40, 67, 81), c(89, 44, 125), c(109, 54, 153), c(127, 63, 178), c(67, 33, 94), c(36, 53, 125), c(44, 65, 153), c(51, 76, 178), c(27, 40, 94), c(72, 53, 36), c(88, 65, 44), c(102, 76, 51), c(54, 40, 27), c(72, 89, 36), c(88, 109, 44), c(102, 127, 51), c(54, 67, 27), c(108, 36, 36), c(132, 44, 44), c(153, 51, 51), c(81, 27, 27), c(17, 17, 17), c(21, 21, 21), c(25, 25, 25), c(13, 13, 13), c(176, 168, 54), c(215, 205, 66), c(250, 238, 77), c(132, 126, 40), c(64, 154, 150), c(79, 188, 183), c(92, 219, 213), c(48, 115, 112), c(52, 90, 180), c(63, 110, 220), c(74, 128, 255), c(39, 67, 135), c(0, 153, 40), c(0, 187, 50), c(0, 217, 58), c(0, 114, 30), c(91, 60, 34), c(111, 74, 42), c(129, 86, 49), c(68, 45, 25), c(79, 1, 0), c(96, 1, 0), c(112, 2, 0), c(59, 1, 0)};
|
||||||
|
private static final Map<Integer, Byte> colorToIndexMap = new HashMap();
|
||||||
|
|
||||||
|
public static void prepareColors() {
|
||||||
|
for(int i = 4; i < colors.length; ++i) {
|
||||||
|
Color color = colors[i];
|
||||||
|
byte index = (byte)(i < 128 ? i : -129 + (i - 127));
|
||||||
|
colorToIndexMap.put(color.getRGB(), index);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color c(int r, int g, int b) {
|
||||||
|
return new Color(r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double getDistance(Color c1, Color c2) {
|
||||||
|
double rmean = (double)(c1.getRed() + c2.getRed()) / (double)2.0F;
|
||||||
|
double r = (double)(c1.getRed() - c2.getRed());
|
||||||
|
double g = (double)(c1.getGreen() - c2.getGreen());
|
||||||
|
int b = c1.getBlue() - c2.getBlue();
|
||||||
|
double weightR = (double)2.0F + rmean / (double)256.0F;
|
||||||
|
double weightG = (double)4.0F;
|
||||||
|
double weightB = (double)2.0F + ((double)255.0F - rmean) / (double)256.0F;
|
||||||
|
return weightR * r * r + weightG * g * g + weightB * (double)b * (double)b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
|
@Deprecated
|
||||||
|
public static int[] imageToBytes(BufferedImage image) {
|
||||||
|
int[] result = (int[])rgbBuffer.get();
|
||||||
|
image.getRGB(0, 0, image.getWidth(), image.getHeight(), result, 0, image.getWidth());
|
||||||
|
|
||||||
|
for(int i = 0; i < result.length; ++i) {
|
||||||
|
result[i] = tryFastMatchColor(result[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte tryFastMatchColor(int rgb) {
|
||||||
|
Byte color = (Byte)colorToIndexMap.get(rgb);
|
||||||
|
return color != null ? color : matchColor(new Color(rgb, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
|
@Deprecated
|
||||||
|
public static byte matchColor(Color color) {
|
||||||
|
if (color.getAlpha() < 128) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
int index = 0;
|
||||||
|
double best = (double)-1.0F;
|
||||||
|
|
||||||
|
for(int i = 4; i < colors.length; ++i) {
|
||||||
|
double distance = getDistance(color, colors[i]);
|
||||||
|
if (distance < best || best == (double)-1.0F) {
|
||||||
|
best = distance;
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (byte)(index < 128 ? index : -129 + (index - 127));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package dev._2lstudios.flamecord.commands;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
|
||||||
|
public class BungeeIPCommand extends Command {
|
||||||
|
public BungeeIPCommand() {
|
||||||
|
super("bip");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
FlameCord flameCord = FlameCord.getInstance();
|
||||||
|
MessagesConfiguration messagesConfiguration = flameCord.getMessagesConfiguration();
|
||||||
|
if (sender.hasPermission("flamecord.bip")) {
|
||||||
|
if (args.length > 0) {
|
||||||
|
ProxiedPlayer player = BungeeCord.getInstance().getPlayer(args[0]);
|
||||||
|
if (player != null) {
|
||||||
|
String message = messagesConfiguration.getTranslation("flamecord_bip", player.getDisplayName(), player.getUniqueId(), player.getSocketAddress(), player.getPing(), player.getLocale(), player.getViewDistance(), player.getServer().getInfo().getName());
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(message));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_bip_offline")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_bip_usage")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_bip_nopermission")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package dev._2lstudios.flamecord.commands;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
|
||||||
|
public class BungeeKickCommand extends Command {
|
||||||
|
public BungeeKickCommand() {
|
||||||
|
super("bkick");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
FlameCord flameCord = FlameCord.getInstance();
|
||||||
|
MessagesConfiguration messagesConfiguration = flameCord.getMessagesConfiguration();
|
||||||
|
if (!sender.hasPermission("flamecord.bkick")) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_bkick_nopermission")));
|
||||||
|
} else if (args.length <= 0) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_bkick_usage")));
|
||||||
|
} else {
|
||||||
|
String name = args[0];
|
||||||
|
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(name);
|
||||||
|
if (player != null && player.isConnected()) {
|
||||||
|
String reason = null;
|
||||||
|
if (args.length > 1) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
|
for(int i = 1; i < args.length; ++i) {
|
||||||
|
result.append(args[i]).append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
reason = result.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
player.disconnect(reason == null ? ChatColor.translateAlternateColorCodes('&', FlameCord.getInstance().getMessagesConfiguration().getTranslation("flamecord_bkick_default")) : String.valueOf(ChatColor.RED) + ChatColor.translateAlternateColorCodes('&', reason));
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', FlameCord.getInstance().getMessagesConfiguration().getTranslation("flamecord_bkick", name)));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', FlameCord.getInstance().getMessagesConfiguration().getTranslation("flamecord_bkick_notfound")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package dev._2lstudios.flamecord.commands;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import java.util.Collection;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
public class BungeePluginsCommand extends Command {
|
||||||
|
public BungeePluginsCommand() {
|
||||||
|
super("bplugins");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
FlameCord flameCord = FlameCord.getInstance();
|
||||||
|
MessagesConfiguration messagesConfiguration = flameCord.getMessagesConfiguration();
|
||||||
|
if (sender.hasPermission("flamecord.bplugins")) {
|
||||||
|
Collection<Plugin> plugins = BungeeCord.getInstance().getPluginManager().getPlugins();
|
||||||
|
int amount = plugins.size();
|
||||||
|
String header = FlameCord.getInstance().getMessagesConfiguration().getTranslation("flamecord_bplugins_header", amount);
|
||||||
|
String separator = FlameCord.getInstance().getMessagesConfiguration().getTranslation("flamecord_bplugins_separator");
|
||||||
|
StringBuilder stringBuilder = new StringBuilder(header);
|
||||||
|
boolean first = true;
|
||||||
|
|
||||||
|
for(Plugin plugin : plugins) {
|
||||||
|
stringBuilder.append((first ? "" : separator) + plugin.getDescription().getName());
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(stringBuilder.toString()));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_bplugins_nopermission")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
package dev._2lstudios.flamecord.commands;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.check.LockdownCheck;
|
||||||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
|
||||||
|
public class FlameCordCommand extends Command {
|
||||||
|
private final BungeeCord bungeeCord;
|
||||||
|
private FlameCordStatsCommand flameCordStatsCommand = new FlameCordStatsCommand();
|
||||||
|
private FlameCordWhitelistCommand flameCordWhitelistCommand = new FlameCordWhitelistCommand();
|
||||||
|
|
||||||
|
public FlameCordCommand(BungeeCord bungeeCord) {
|
||||||
|
super("flamecord");
|
||||||
|
this.bungeeCord = bungeeCord;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlameCordStatsCommand getStatsCommand() {
|
||||||
|
return this.flameCordStatsCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
FlameCord flameCord = FlameCord.getInstance();
|
||||||
|
MessagesConfiguration messagesConfiguration = flameCord.getMessagesConfiguration();
|
||||||
|
if (args.length > 0) {
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "whitelist":
|
||||||
|
if (!sender.hasPermission("flamecord.whitelist")) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_nopermission")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.flameCordWhitelistCommand.execute(sender, args);
|
||||||
|
break;
|
||||||
|
case "reload":
|
||||||
|
if (!sender.hasPermission("flamecord.reload")) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_nopermission")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<String> whitelistedAddresses = new HashSet();
|
||||||
|
|
||||||
|
for(ServerInfo serverInfo : this.bungeeCord.getServers().values()) {
|
||||||
|
whitelistedAddresses.add(serverInfo.getSocketAddress().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
FlameCord.initialize(this.bungeeCord.getLogger(), whitelistedAddresses);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_reload")));
|
||||||
|
break;
|
||||||
|
case "stats":
|
||||||
|
if (!sender.hasPermission("flamecord.stats")) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_nopermission")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.flameCordStatsCommand.execute(sender);
|
||||||
|
break;
|
||||||
|
case "firewall":
|
||||||
|
if (!sender.hasPermission("flamecord.firewall")) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_nopermission")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length > 2) {
|
||||||
|
String ip = args[2];
|
||||||
|
switch (args[1]) {
|
||||||
|
case "add":
|
||||||
|
FlameCord.getInstance().getAddressDataManager().getAddressData(ip).firewall("Blacklisted by command");
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_firewall_add", ip)));
|
||||||
|
return;
|
||||||
|
case "remove":
|
||||||
|
FlameCord.getInstance().getAddressDataManager().getAddressData(ip).unfirewall();
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_firewall_remove", ip)));
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_firewall_help")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_firewall_help")));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "accounts":
|
||||||
|
if (!sender.hasPermission("flamecord.accounts")) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_nopermission")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length <= 1) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_accounts_help")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String subCommand = args[1];
|
||||||
|
switch (subCommand) {
|
||||||
|
case "add":
|
||||||
|
case "remove":
|
||||||
|
if (args.length <= 3) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_accounts_help")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ip = args[2];
|
||||||
|
String name = args[3];
|
||||||
|
if (subCommand.equals("add")) {
|
||||||
|
FlameCord.getInstance().getAddressDataManager().getAddressData(ip).addNickname(name);
|
||||||
|
} else {
|
||||||
|
FlameCord.getInstance().getAddressDataManager().getAddressData(ip).removeNickname(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_accounts_" + subCommand, name, ip)));
|
||||||
|
return;
|
||||||
|
case "clear":
|
||||||
|
if (args.length <= 2) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_accounts_help")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String clearIp = args[2];
|
||||||
|
FlameCord.getInstance().getAddressDataManager().getAddressData(clearIp).clearNicknames();
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_accounts_clear", clearIp)));
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_accounts_help")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case "lockdown":
|
||||||
|
if (!sender.hasPermission("flamecord.lockdown")) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_nopermission")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length > 1) {
|
||||||
|
switch (args[1]) {
|
||||||
|
case "start":
|
||||||
|
FlameCord.getInstance().getCheckManager().getLockdownCheck().lock();
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(String.valueOf(ChatColor.GREEN) + "Lockdown started!"));
|
||||||
|
return;
|
||||||
|
case "stop":
|
||||||
|
FlameCord.getInstance().getCheckManager().getLockdownCheck().unlock();
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(String.valueOf(ChatColor.RED) + "Lockdown stopped!"));
|
||||||
|
return;
|
||||||
|
case "clear":
|
||||||
|
FlameCord.getInstance().getCheckManager().getLockdownCheck().clearWhitelist();
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(String.valueOf(ChatColor.YELLOW) + "Whitelist cleared!"));
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
String var10001 = String.valueOf(ChatColor.GOLD);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var10001 + "Remaining time: " + FlameCord.getInstance().getCheckManager().getLockdownCheck().getTimeAsString()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||||
|
LockdownCheck lockdownCheck = FlameCord.getInstance().getCheckManager().getLockdownCheck();
|
||||||
|
if (config.isAntibotLockdownEnabled()) {
|
||||||
|
String var23 = String.valueOf(ChatColor.GOLD);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var23 + "Remaining time: " + String.valueOf(ChatColor.YELLOW) + lockdownCheck.getTimeAsString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
String var24 = String.valueOf(ChatColor.GOLD);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "Lockdown Enabled: " + String.valueOf(config.isAntibotLockdownEnabled() ? ChatColor.GREEN : ChatColor.RED) + config.isAntibotLockdownEnabled()));
|
||||||
|
if (config.isAntibotLockdownEnabled()) {
|
||||||
|
var24 = String.valueOf(ChatColor.GOLD);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "Lockdown Log: " + String.valueOf(config.isAntibotLockdownLog() ? ChatColor.GREEN : ChatColor.RED) + config.isAntibotLockdownLog()));
|
||||||
|
var24 = String.valueOf(ChatColor.GOLD);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "Lockdown Period: " + String.valueOf(ChatColor.AQUA) + config.getAntibotLockdownPeriod()));
|
||||||
|
var24 = String.valueOf(ChatColor.GOLD);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "Lockdown Period Limit: " + String.valueOf(ChatColor.AQUA) + config.getAntibotLockdownPeriodLimit()));
|
||||||
|
var24 = String.valueOf(ChatColor.GOLD);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "Lockdown Duration: " + String.valueOf(ChatColor.AQUA) + config.getAntibotLockdownDuration()));
|
||||||
|
var24 = String.valueOf(ChatColor.GOLD);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "Count in Current Period: " + String.valueOf(ChatColor.YELLOW) + lockdownCheck.getCounter()));
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(String.valueOf(ChatColor.GOLD) + "Available subcommands:"));
|
||||||
|
var24 = String.valueOf(ChatColor.YELLOW);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "/flamecord lockdown start - " + String.valueOf(ChatColor.GREEN) + "Start lockdown"));
|
||||||
|
var24 = String.valueOf(ChatColor.YELLOW);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "/flamecord lockdown stop - " + String.valueOf(ChatColor.RED) + "Stop lockdown"));
|
||||||
|
var24 = String.valueOf(ChatColor.YELLOW);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var24 + "/flamecord lockdown clear - " + String.valueOf(ChatColor.AQUA) + "Clear whitelist"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_help", BungeeCord.getInstance().getVersion())));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("flamecord_help", BungeeCord.getInstance().getVersion())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package dev._2lstudios.flamecord.commands;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.StatsData;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
public class FlameCordStatsCommand {
|
||||||
|
private Collection<ProxiedPlayer> showStats = new HashSet();
|
||||||
|
|
||||||
|
public boolean isShowStats(ProxiedPlayer proxiedPlayer) {
|
||||||
|
return this.showStats.contains(proxiedPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideStats(ProxiedPlayer proxiedPlayer) {
|
||||||
|
this.showStats.remove(proxiedPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showStats(ProxiedPlayer proxiedPlayer) {
|
||||||
|
this.showStats.add(proxiedPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<ProxiedPlayer> getShowStats() {
|
||||||
|
return this.showStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender) {
|
||||||
|
MessagesConfiguration messagesConfiguration = FlameCord.getInstance().getMessagesConfiguration();
|
||||||
|
StatsData statsData = FlameCord.getInstance().getStatsData();
|
||||||
|
int totalPings = statsData.getTotalPings();
|
||||||
|
int totalConnections = statsData.getTotalConnections();
|
||||||
|
int firewalled = statsData.getTotalFirewalled();
|
||||||
|
int lastPings = statsData.getLastPings();
|
||||||
|
int lastConnections = statsData.getLastConnections();
|
||||||
|
int lastFirewalled = statsData.getLastFirewalled();
|
||||||
|
if (sender instanceof ProxiedPlayer proxiedPlayer) {
|
||||||
|
if (this.isShowStats(proxiedPlayer)) {
|
||||||
|
this.hideStats(proxiedPlayer);
|
||||||
|
} else {
|
||||||
|
this.showStats(proxiedPlayer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("antibot_stats", totalPings, totalConnections, lastPings, lastConnections, firewalled, lastFirewalled)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package dev._2lstudios.flamecord.commands;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
|
public class FlameCordWhitelistCommand {
|
||||||
|
private final Pattern IP_PATTERN = Pattern.compile("^([0-9]{1,3}\\.){3}[0-9]{1,3}$");
|
||||||
|
private final Pattern NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_]{3,16}$");
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
FlameCord flameCord = FlameCord.getInstance();
|
||||||
|
MessagesConfiguration messages = flameCord.getMessagesConfiguration();
|
||||||
|
if (args.length < 3) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(String.valueOf(ChatColor.RED) + "Usage: /flamecord whitelist <add|remove> <ip|name>"));
|
||||||
|
} else {
|
||||||
|
String action = args[1].toLowerCase();
|
||||||
|
String target = args[2];
|
||||||
|
boolean isIP = this.IP_PATTERN.matcher(target).matches();
|
||||||
|
boolean isName = this.NAME_PATTERN.matcher(target).matches();
|
||||||
|
if (!isIP && !isName) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(String.valueOf(ChatColor.RED) + "Invalid format! Use a valid IP address or Minecraft nickname."));
|
||||||
|
} else {
|
||||||
|
if (action.equals("add")) {
|
||||||
|
flameCord.getUserWhitelistManager().add(target);
|
||||||
|
String var10001 = String.valueOf(ChatColor.GREEN);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var10001 + "Successfully added " + String.valueOf(ChatColor.WHITE) + target + String.valueOf(ChatColor.GREEN) + " to the persistent user whitelist."));
|
||||||
|
} else if (action.equals("remove")) {
|
||||||
|
flameCord.getUserWhitelistManager().remove(target);
|
||||||
|
String var9 = String.valueOf(ChatColor.YELLOW);
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(var9 + "Successfully removed " + String.valueOf(ChatColor.WHITE) + target + String.valueOf(ChatColor.YELLOW) + " from the persistent user whitelist."));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(String.valueOf(ChatColor.RED) + "Usage: /flamecord whitelist <add|remove> <ip|name>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package dev._2lstudios.flamecord.commands;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.balancer.Balancer;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
|
||||||
|
public class LobbyCommand extends Command {
|
||||||
|
public LobbyCommand() {
|
||||||
|
super("lobby", (String)null, "hub");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
FlameCord flameCord = FlameCord.getInstance();
|
||||||
|
MessagesConfiguration messagesConfiguration = flameCord.getMessagesConfiguration();
|
||||||
|
if (!(sender instanceof ProxiedPlayer)) {
|
||||||
|
sender.sendMessage((BaseComponent)(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_not_from_console"))));
|
||||||
|
} else if (!Balancer.isUseLobbyCommand()) {
|
||||||
|
sender.sendMessage((BaseComponent)(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_command_disabled"))));
|
||||||
|
} else if (!Balancer.isEnabled()) {
|
||||||
|
sender.sendMessage((BaseComponent)(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_balancer_disabled"))));
|
||||||
|
} else if (!Balancer.isFallback()) {
|
||||||
|
sender.sendMessage((BaseComponent)(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_no_fallback_configured"))));
|
||||||
|
} else {
|
||||||
|
ProxiedPlayer player = (ProxiedPlayer)sender;
|
||||||
|
ServerInfo server = player.getServer().getInfo();
|
||||||
|
if (Balancer.isServer(server)) {
|
||||||
|
sender.sendMessage((BaseComponent)(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_already_connected"))));
|
||||||
|
} else if (Balancer.isServerCommandBlacklisted(server)) {
|
||||||
|
sender.sendMessage((BaseComponent)(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_command_blacklisted"))));
|
||||||
|
} else {
|
||||||
|
ServerInfo bestServer = Balancer.getBestServer();
|
||||||
|
if (bestServer == null) {
|
||||||
|
sender.sendMessage((BaseComponent)(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_no_servers_available"))));
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
player.connect(bestServer);
|
||||||
|
player.sendMessage(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_connecting")));
|
||||||
|
} catch (Exception var9) {
|
||||||
|
player.sendMessage(new TextComponent(messagesConfiguration.getTranslation("flamecord_lobby_connection_failed")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package dev._2lstudios.flamecord.configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
|
||||||
|
public class FlameConfig {
|
||||||
|
Configuration load(File file) {
|
||||||
|
ConfigurationProvider configurationProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||||
|
if (file.exists() && file.isFile()) {
|
||||||
|
try {
|
||||||
|
return configurationProvider.load(file);
|
||||||
|
} catch (IOException var4) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Configuration();
|
||||||
|
}
|
||||||
|
|
||||||
|
void save(Configuration config, File file) {
|
||||||
|
ConfigurationProvider configurationProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
configurationProvider.save(config, file);
|
||||||
|
} catch (IOException var5) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double setIfUnexistant(String arg1, double arg2, Configuration configuration) {
|
||||||
|
return (Double)this.setIfUnexistant(arg1, (Object)arg2, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
int setIfUnexistant(String arg1, int arg2, Configuration configuration) {
|
||||||
|
return (Integer)this.setIfUnexistant(arg1, (Object)arg2, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
String setIfUnexistant(String arg1, String arg2, Configuration configuration) {
|
||||||
|
return (String)this.setIfUnexistant(arg1, (Object)arg2, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean setIfUnexistant(String arg1, boolean arg2, Configuration configuration) {
|
||||||
|
return (Boolean)this.setIfUnexistant(arg1, (Object)arg2, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object setIfUnexistant(String arg1, Object arg2, Configuration configuration) {
|
||||||
|
if (!configuration.contains(arg1)) {
|
||||||
|
configuration.set(arg1, arg2);
|
||||||
|
return arg2;
|
||||||
|
} else {
|
||||||
|
return configuration.get(arg1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<String> setIfUnexistant(String arg1, Collection<String> arg2, Configuration configuration) {
|
||||||
|
if (!configuration.contains(arg1)) {
|
||||||
|
configuration.set(arg1, new ArrayList(arg2));
|
||||||
|
return arg2;
|
||||||
|
} else {
|
||||||
|
return new HashSet(configuration.getStringList(arg1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> setIfUnexistant(String arg1, List<String> arg2, Configuration configuration) {
|
||||||
|
if (!configuration.contains(arg1)) {
|
||||||
|
configuration.set(arg1, new ArrayList(arg2));
|
||||||
|
return arg2;
|
||||||
|
} else {
|
||||||
|
return configuration.getStringList(arg1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,142 @@
|
|||||||
|
package dev._2lstudios.flamecord.configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
|
||||||
|
public class MessagesConfiguration extends FlameConfig {
|
||||||
|
private final Logger logger;
|
||||||
|
private final Map<String, String> messages = new HashMap();
|
||||||
|
|
||||||
|
public MessagesConfiguration(Logger logger, ConfigurationProvider configurationProvider) {
|
||||||
|
this.logger = logger;
|
||||||
|
File configurationFile = new File("./messages.yml");
|
||||||
|
Configuration configuration = this.load(configurationFile);
|
||||||
|
this.setIfUnexistant("flamecord_reload", "&aAll files had been successfully reloaded!", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_help", "&8&m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n&c&lFLAMECORD {0} COMMANDS\n&8&m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n&7 /flamecord help: &fShows this message\n&7 /flamecord reload: &fReloads FlameCord files\n&7 /flamecord firewall <add/remove> <ip>: &fFirewall certain IPs\n&7 /flamecord accounts <add/remove/clear> <ip> [name]: &fManage player accounts\n&7 /flamecord lockdown: &fCheck lockdown status\n&7 /bplugins: &fShow the plugin list\n&7 /bip <player>: &fShow the IP and info of a player\n&7 /bkick <player>: &fKick a player from the proxy\n&8&m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n&8 \u00bb &b&nhttps://flamecord.com", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_nopermission", "&cYou don't have permission to do this!", configuration);
|
||||||
|
this.setIfUnexistant("alert", "&8[&4Alert&8]&r ", configuration);
|
||||||
|
this.setIfUnexistant("already_connected", "&cYou are already connected to this server!", configuration);
|
||||||
|
this.setIfUnexistant("already_connected_proxy", "&cYou are already connected to this proxy!", configuration);
|
||||||
|
this.setIfUnexistant("already_connecting", "&cAlready connecting to this server!", configuration);
|
||||||
|
this.setIfUnexistant("command_list", "&a[{0}] &e({1}): &r{2}", configuration);
|
||||||
|
this.setIfUnexistant("connect_kick", "&cKicked whilst connecting to {0}: {1}", configuration);
|
||||||
|
this.setIfUnexistant("current_server", "&6You are currently connected to {0}.", configuration);
|
||||||
|
this.setIfUnexistant("fallback_kick", "&cCould not connect to a default or fallback server, please try again later: {0}", configuration);
|
||||||
|
this.setIfUnexistant("fallback_lobby", "&cCould not connect to target server, you have been moved to a fallback server.", configuration);
|
||||||
|
this.setIfUnexistant("lost_connection", "[Proxy] Lost connection to server.", configuration);
|
||||||
|
this.setIfUnexistant("mojang_fail", "Error occurred while contacting login servers, are they down?", configuration);
|
||||||
|
this.setIfUnexistant("no_permission", "&cYou do not have permission to execute this command!", configuration);
|
||||||
|
this.setIfUnexistant("no_server", "&cThe specified server does not exist.", configuration);
|
||||||
|
this.setIfUnexistant("no_server_permission", "&cYou don't have permission to access this server.", configuration);
|
||||||
|
this.setIfUnexistant("outdated_client", "Outdated client! Please use {0}", configuration);
|
||||||
|
this.setIfUnexistant("outdated_server", "Outdated server! I'm still on {0}", configuration);
|
||||||
|
this.setIfUnexistant("proxy_full", "Server is full!", configuration);
|
||||||
|
this.setIfUnexistant("restart", "[Proxy] Proxy restarting.", configuration);
|
||||||
|
this.setIfUnexistant("server_list", "&6You may connect to the following servers at this time: ", configuration);
|
||||||
|
this.setIfUnexistant("server_went_down", "&cThe server you were previously on went down, you have been connected to a fallback server", configuration);
|
||||||
|
this.setIfUnexistant("total_players", "Total players online: {0}", configuration);
|
||||||
|
this.setIfUnexistant("name_invalid", "Username contains invalid characters.", configuration);
|
||||||
|
this.setIfUnexistant("ping_cannot_connect", "&c[Bungee] Can't connect to server.", configuration);
|
||||||
|
this.setIfUnexistant("offline_mode_player", "Not authenticated with Minecraft.net", configuration);
|
||||||
|
this.setIfUnexistant("secure_profile_required", "A secure profile is required to join this server.", configuration);
|
||||||
|
this.setIfUnexistant("secure_profile_expired", "Secure profile expired.", configuration);
|
||||||
|
this.setIfUnexistant("secure_profile_invalid", "Secure profile invalid.", configuration);
|
||||||
|
this.setIfUnexistant("message_needed", "&cYou must supply a message.", configuration);
|
||||||
|
this.setIfUnexistant("error_occurred_player", "&cAn error occurred while parsing your message. (Hover for details)", configuration);
|
||||||
|
this.setIfUnexistant("error_occurred_console", "&cAn error occurred while parsing your message: {0}", configuration);
|
||||||
|
this.setIfUnexistant("server_command_hover_players", "{0} players", configuration);
|
||||||
|
this.setIfUnexistant("click_to_connect", "Click to connect to the server", configuration);
|
||||||
|
this.setIfUnexistant("username_needed", "&cPlease follow this command by a user name.", configuration);
|
||||||
|
this.setIfUnexistant("user_not_online", "&cThat user is not online.", configuration);
|
||||||
|
this.setIfUnexistant("user_online_at", "&a{0} &ris online at {1}", configuration);
|
||||||
|
this.setIfUnexistant("send_cmd_usage", "&cNot enough arguments, usage: /send <server|player|all|current> <target>", configuration);
|
||||||
|
this.setIfUnexistant("player_only", "&cOnly in game players can use this command", configuration);
|
||||||
|
this.setIfUnexistant("you_got_summoned", "&6Summoned to {0} by {1}", configuration);
|
||||||
|
this.setIfUnexistant("command_perms_groups", "&6You have the following groups: {0}", configuration);
|
||||||
|
this.setIfUnexistant("command_perms_permission", "&9- {0}", configuration);
|
||||||
|
this.setIfUnexistant("command_ip", "&9IP of {0} is {1}", configuration);
|
||||||
|
this.setIfUnexistant("illegal_chat_characters", "&cIllegal characters in chat ({0})", configuration);
|
||||||
|
this.setIfUnexistant("antibot_latency", "&c&lFlameCord\n\n&c\u00a1Your ping is too high! ({0}ms)\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_accounts", "&c&lFlameCord\n\n&c\u00a1You have too many accounts! ({0})\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_fastchat", "&c&lFlameCord\n\n&c\u00a1You are chatting too fast!\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_fastchat_cancel", "&c\u00a1You are repeating chats too fast! Please &lSTOP!!!&r", configuration);
|
||||||
|
this.setIfUnexistant("antibot_firewall", "&c&lFlameCord\n\n&c\u00a1You are blacklisted from this server!\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_nickname", "&c&lFlameCord\n\n&c\u00a1Your nickname was detected as bot! ({0})\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_password", "&c&lFlameCord\n\n&c\u00a1Use another password! ({0})\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_ratelimit", "&c&lFlameCord\n\n&c\u00a1You are connecting too fast! ({0})\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_reconnect_reconnect", "&cReconnect &b{0}&c more times", configuration);
|
||||||
|
this.setIfUnexistant("antibot_reconnect_ping", "&cRefresh server list &b{0}&c more times", configuration);
|
||||||
|
this.setIfUnexistant("antibot_reconnect_message", "&c&lFlameCord\n\n{0}\n{1}\n\n&c(Do it slowly)\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_country", "&c&lFlameCord\n\n&c\u00a1Your country {0} is blacklisted!\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_proxy", "&c&lFlameCord\n\n&c\u00a1You are using a Proxy/VPN!\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_lockdown", "&c&lFlameCord\n\n&cServer locked. \u00a1Wait a minute to join!\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_stats", "&c&lFlameCord Antibot Stats\n &7\u25a0 Total Pings: &a{0}\n &7\u25a0 Total Connections: &b{1}\n\n &7\u25a0 Current Pings: &a{2}/s\n &7\u25a0 Current Connections: &b{3}/s\n\n &7\u25a0 Total Firewalled: &b{4}\n &7\u25a0 Current Firewalled: &b{5}/s", configuration);
|
||||||
|
this.setIfUnexistant("antibot_stats_actionbar", "&ePings: &f{0}/s &7- &eConnections: &f{1}/s&7 - &eFirewalled:&f {2}", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_check_in_progress", "&eChecking...", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_check_completed", "&aPassed!", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_enter_captcha", "&cNeed Captcha", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_wrong_captcha", "&cWrong captcha", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_wait_verification", "&eVerification in progress...", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_enter_number", "&cPlease write the captcha number", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_verification_passed", "&aVerified!", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_kick", "&c&lFlameCord\n\n&c\u00a1You failed the limbo check!\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_high_latency", "&c&lFlameCord\n\n&c\u00a1You failed the limbo check! (Latency)\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_too_big_packet", "&c&lFlameCord\n\n&c\u00a1You failed the limbo check! (Big Packet)\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_requires_ping", "&eRefresh the server list", configuration);
|
||||||
|
this.setIfUnexistant("antibot_limbo_too_many_checks", "&cToo many checks. Wait 1 minute.", configuration);
|
||||||
|
this.setIfUnexistant("antibot_notify_blocked_single", "&e[FlameCord] &cBlocked: &f{0}", configuration);
|
||||||
|
this.setIfUnexistant("antibot_notify_blocked_multiple", "&e[FlameCord] &cBlocked: &f{0} players", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_firewall_help", "&c/flamecord firewall <add/remove> <ip>", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_firewall_add", "&cThe ip {0} was added to the firewall!", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_firewall_remove", "&cThe ip {0} was removed from the firewall!", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_accounts_help", "&9Usage: /accounts &e<add/remove> <ip> <name>", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_accounts_add", "&aNickname &e{0} &ahas been added to the account with IP &e{1}.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_accounts_remove", "&aNickname &e{0} &ahas been removed from the account with IP &e{1}.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_accounts_clear", "&aAll nicknames have been cleared from the account with IP &e{0}.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bplugins_nopermission", "&cYou don't have permission to do this!", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bplugins_separator", ", ", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bplugins_header", "&aPlugins ({0}): ", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bip_nopermission", "&cYou don't have permission to do this!", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bip_offline", "&cThe player is not online!", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bip_usage", "&c/bip <player>", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bip", "&aInformation about {0}&a:\n&aUUID: &b{1}\n&aIP: &b{2}\n&aPing: &b{3}ms\n&aLocale: &b{4}\n&aView Distance: &b{5}\n&aCurrent Server: &b{6}", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bkick_nopermission", "&cYou don't have permission to use this command!", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bkick_default", "&cYou have been kicked from the server.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bkick_notfound", "&cPlayer not found or is not currently connected.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bkick_usage", "&cUsage: /bkick <player> [reason]", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_bkick", "&c{0} has been kicked from the server.", configuration);
|
||||||
|
this.setIfUnexistant("command_list_format", "&aServers:&r", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_not_from_console", "&cThis command cannot be used from the console.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_command_disabled", "&cThe lobby command is disabled.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_balancer_disabled", "&cBalancer is currently disabled.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_no_fallback_configured", "&cThere is no fallback server configured.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_already_connected", "&eYou are already connected to the fallback server.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_command_blacklisted", "&cYou cannot use the lobby command from this server.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_no_servers_available", "&cNo available servers to connect to.", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_connecting", "&aConnecting you to the best available lobby...", configuration);
|
||||||
|
this.setIfUnexistant("flamecord_lobby_connection_failed", "&cFailed to connect to the server. Please try again later.", configuration);
|
||||||
|
|
||||||
|
for(String key : configuration.getKeys()) {
|
||||||
|
Object value = configuration.get(key);
|
||||||
|
if (value instanceof String) {
|
||||||
|
this.messages.put(key, ChatColor.translateAlternateColorCodes('&', (String)value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.save(configuration, configurationFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTranslation(String name, Object... args) {
|
||||||
|
if (!this.messages.containsKey(name)) {
|
||||||
|
this.logger.warning("[FlameCord] Tried to get translation '" + name + "' from messages.yml file but wasn't found. Please try resetting this file or report to a developer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return MessageFormat.format((String)this.messages.getOrDefault(name, "<translation '" + name + "' missing>"), args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package dev._2lstudios.flamecord.configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
|
||||||
|
public class ModulesConfiguration extends FlameConfig {
|
||||||
|
public boolean reconnectEnabled = false;
|
||||||
|
public boolean alertEnabled = true;
|
||||||
|
public boolean findEnabled = true;
|
||||||
|
public boolean ipEnabled = true;
|
||||||
|
public boolean listEnabled = true;
|
||||||
|
public boolean permsEnabled = true;
|
||||||
|
public boolean reloadEnabled = true;
|
||||||
|
public boolean sendEnabled = true;
|
||||||
|
public boolean serverEnabled = true;
|
||||||
|
|
||||||
|
public ModulesConfiguration(ConfigurationProvider configurationProvider) {
|
||||||
|
File configurationFile = new File("./modules.yml");
|
||||||
|
Configuration configuration = this.load(configurationFile);
|
||||||
|
this.alertEnabled = this.setIfUnexistant("alert.enabled", this.alertEnabled, configuration);
|
||||||
|
this.findEnabled = this.setIfUnexistant("find.enabled", this.findEnabled, configuration);
|
||||||
|
this.ipEnabled = this.setIfUnexistant("ip.enabled", this.ipEnabled, configuration);
|
||||||
|
this.listEnabled = this.setIfUnexistant("list.enabled", this.listEnabled, configuration);
|
||||||
|
this.permsEnabled = this.setIfUnexistant("perms.enabled", this.permsEnabled, configuration);
|
||||||
|
this.reloadEnabled = this.setIfUnexistant("reload.enabled", this.reloadEnabled, configuration);
|
||||||
|
this.sendEnabled = this.setIfUnexistant("send.enabled", this.sendEnabled, configuration);
|
||||||
|
this.serverEnabled = this.setIfUnexistant("server.enabled", this.serverEnabled, configuration);
|
||||||
|
this.reconnectEnabled = this.setIfUnexistant("reconnect.enabled", this.reconnectEnabled, configuration);
|
||||||
|
this.save(configuration, configurationFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package dev._2lstudios.flamecord.enums;
|
||||||
|
|
||||||
|
public enum PacketsCheckResult {
|
||||||
|
KICK,
|
||||||
|
CANCEL,
|
||||||
|
NONE;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package dev._2lstudios.flamecord.enums;
|
||||||
|
|
||||||
|
public enum PacketsViolationReason {
|
||||||
|
SIZE,
|
||||||
|
RATE;
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package dev._2lstudios.flamecord.event;
|
||||||
|
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.api.Callback;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.event.AsyncEvent;
|
||||||
|
import net.md_5.bungee.protocol.packet.Handshake;
|
||||||
|
|
||||||
|
public class DownstreamHandshakeEvent extends AsyncEvent<DownstreamHandshakeEvent> {
|
||||||
|
private Handshake originalHandshake;
|
||||||
|
private Handshake modifiedHandshake;
|
||||||
|
private ProxiedPlayer player;
|
||||||
|
private ServerInfo server;
|
||||||
|
|
||||||
|
public DownstreamHandshakeEvent(ProxiedPlayer player, Handshake originalHandshake, Handshake modifiedHandshake, ServerInfo server, Callback<DownstreamHandshakeEvent> done) {
|
||||||
|
super(done);
|
||||||
|
this.player = player;
|
||||||
|
this.originalHandshake = originalHandshake;
|
||||||
|
this.modifiedHandshake = modifiedHandshake;
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Handshake getOriginalHandshake() {
|
||||||
|
return this.originalHandshake;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Handshake getModifiedHandshake() {
|
||||||
|
return this.modifiedHandshake;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public ProxiedPlayer getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public ServerInfo getServer() {
|
||||||
|
return this.server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setOriginalHandshake(Handshake originalHandshake) {
|
||||||
|
this.originalHandshake = originalHandshake;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setModifiedHandshake(Handshake modifiedHandshake) {
|
||||||
|
this.modifiedHandshake = modifiedHandshake;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setPlayer(ProxiedPlayer player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setServer(ServerInfo server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
String var10000 = String.valueOf(this.getOriginalHandshake());
|
||||||
|
return "DownstreamHandshakeEvent(originalHandshake=" + var10000 + ", modifiedHandshake=" + String.valueOf(this.getModifiedHandshake()) + ", player=" + String.valueOf(this.getPlayer()) + ", server=" + String.valueOf(this.getServer()) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof DownstreamHandshakeEvent)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
DownstreamHandshakeEvent other = (DownstreamHandshakeEvent)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Object this$originalHandshake = this.getOriginalHandshake();
|
||||||
|
Object other$originalHandshake = other.getOriginalHandshake();
|
||||||
|
if (this$originalHandshake == null) {
|
||||||
|
if (other$originalHandshake != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$originalHandshake.equals(other$originalHandshake)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$modifiedHandshake = this.getModifiedHandshake();
|
||||||
|
Object other$modifiedHandshake = other.getModifiedHandshake();
|
||||||
|
if (this$modifiedHandshake == null) {
|
||||||
|
if (other$modifiedHandshake != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$modifiedHandshake.equals(other$modifiedHandshake)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$player = this.getPlayer();
|
||||||
|
Object other$player = other.getPlayer();
|
||||||
|
if (this$player == null) {
|
||||||
|
if (other$player != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$player.equals(other$player)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$server = this.getServer();
|
||||||
|
Object other$server = other.getServer();
|
||||||
|
if (this$server == null) {
|
||||||
|
if (other$server != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$server.equals(other$server)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof DownstreamHandshakeEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
Object $originalHandshake = this.getOriginalHandshake();
|
||||||
|
result = result * 59 + ($originalHandshake == null ? 43 : $originalHandshake.hashCode());
|
||||||
|
Object $modifiedHandshake = this.getModifiedHandshake();
|
||||||
|
result = result * 59 + ($modifiedHandshake == null ? 43 : $modifiedHandshake.hashCode());
|
||||||
|
Object $player = this.getPlayer();
|
||||||
|
result = result * 59 + ($player == null ? 43 : $player.hashCode());
|
||||||
|
Object $server = this.getServer();
|
||||||
|
result = result * 59 + ($server == null ? 43 : $server.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package dev._2lstudios.flamecord.forge;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Cancellable;
|
||||||
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
|
import net.md_5.bungee.protocol.packet.LoginPayloadRequest;
|
||||||
|
import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
|
||||||
|
|
||||||
|
public abstract class ModernFMLHandshakeEvent extends Event implements Cancellable {
|
||||||
|
private final ProxiedPlayer player;
|
||||||
|
private final ServerInfo serverInfo;
|
||||||
|
private boolean cancelled = false;
|
||||||
|
|
||||||
|
protected ModernFMLHandshakeEvent(ProxiedPlayer player, ServerInfo serverInfo) {
|
||||||
|
this.player = player;
|
||||||
|
this.serverInfo = serverInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProxiedPlayer getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerInfo getTarget() {
|
||||||
|
return this.serverInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Request extends ModernFMLHandshakeEvent {
|
||||||
|
private final LoginPayloadRequest request;
|
||||||
|
private LoginPayloadResponse response;
|
||||||
|
|
||||||
|
public Request(ProxiedPlayer player, ServerInfo serverInfo, LoginPayloadRequest request) {
|
||||||
|
super(player, serverInfo);
|
||||||
|
this.request = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoginPayloadRequest getRequest() {
|
||||||
|
return this.request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReply(LoginPayloadResponse response) {
|
||||||
|
this.setCancelled(true);
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoginPayloadResponse getResponse() {
|
||||||
|
return this.response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Response extends ModernFMLHandshakeEvent {
|
||||||
|
private final LoginPayloadResponse response;
|
||||||
|
|
||||||
|
public Response(ProxiedPlayer player, ServerInfo serverInfo, LoginPayloadResponse response) {
|
||||||
|
super(player, serverInfo);
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoginPayloadResponse getResponse() {
|
||||||
|
return this.response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package dev._2lstudios.flamecord.forge;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import net.md_5.bungee.UserConnection;
|
||||||
|
import net.md_5.bungee.forge.ForgeClientHandler;
|
||||||
|
|
||||||
|
public class ModernForgeClientHandler extends ForgeClientHandler {
|
||||||
|
public ModernForgeClientHandler(@NonNull UserConnection con) {
|
||||||
|
super(con);
|
||||||
|
if (con == null) {
|
||||||
|
throw new NullPointerException("con is marked non-null but is null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetHandshake() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package dev._2lstudios.flamecord.forge;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.BungeeServerInfo;
|
||||||
|
import net.md_5.bungee.ServerConnector;
|
||||||
|
import net.md_5.bungee.UserConnection;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.connection.UpstreamBridge;
|
||||||
|
import net.md_5.bungee.forge.ForgeConstants;
|
||||||
|
import net.md_5.bungee.netty.ChannelWrapper;
|
||||||
|
import net.md_5.bungee.netty.HandlerBoss;
|
||||||
|
import net.md_5.bungee.protocol.PacketWrapper;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
import net.md_5.bungee.protocol.packet.EncryptionResponse;
|
||||||
|
import net.md_5.bungee.protocol.packet.Kick;
|
||||||
|
import net.md_5.bungee.protocol.packet.Login;
|
||||||
|
import net.md_5.bungee.protocol.packet.LoginPayloadRequest;
|
||||||
|
import net.md_5.bungee.protocol.packet.LoginSuccess;
|
||||||
|
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||||
|
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||||
|
|
||||||
|
public class ModernForgeServerConnector extends ServerConnector {
|
||||||
|
private final Queue<LoginPayloadRequest> pendingHandshakes = new ConcurrentLinkedQueue();
|
||||||
|
private volatile State thisState;
|
||||||
|
|
||||||
|
public ModernForgeServerConnector(ProxyServer bungee, UserConnection user, BungeeServerInfo target) {
|
||||||
|
super(bungee, user, target);
|
||||||
|
this.thisState = ModernForgeServerConnector.State.PLAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldHandle(PacketWrapper packet) throws Exception {
|
||||||
|
boolean var10000;
|
||||||
|
label41: {
|
||||||
|
if (this.user.isConnected()) {
|
||||||
|
if (this.thisState != ModernForgeServerConnector.State.PLAIN) {
|
||||||
|
if (packet.packet instanceof LoginPayloadRequest || packet.packet instanceof SetCompression || packet.packet instanceof LoginSuccess || packet.packet instanceof EncryptionResponse || packet.packet instanceof PluginMessage || packet.packet instanceof Kick) {
|
||||||
|
break label41;
|
||||||
|
}
|
||||||
|
} else if (super.shouldHandle(packet)) {
|
||||||
|
break label41;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var10000 = false;
|
||||||
|
return var10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
var10000 = true;
|
||||||
|
return var10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connected(ChannelWrapper channel) throws Exception {
|
||||||
|
super.connected(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(LoginSuccess loginSuccess) throws Exception {
|
||||||
|
Preconditions.checkState(this.thisState != ModernForgeServerConnector.State.PENDING, "Not expecting PENDING");
|
||||||
|
if (this.thisState == ModernForgeServerConnector.State.ACK) {
|
||||||
|
this.user.unsafe().sendPacket(loginSuccess);
|
||||||
|
this.user.getCh().setProtocol(Protocol.GAME);
|
||||||
|
this.user.getCh().endHandshake();
|
||||||
|
((HandlerBoss)this.user.getCh().getHandle().pipeline().get(HandlerBoss.class)).setHandler(new UpstreamBridge(this.bungee, this.user));
|
||||||
|
this.thisState = ModernForgeServerConnector.State.PLAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.handle(loginSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Login login) throws Exception {
|
||||||
|
super.handle(login);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(LoginPayloadRequest request) {
|
||||||
|
switch (this.thisState.ordinal()) {
|
||||||
|
case 0:
|
||||||
|
this.user.setForgeServerHandler(this.getHandshakeHandler());
|
||||||
|
this.user.getCh().getHandle().flush();
|
||||||
|
this.user.getCh().write((Object)ForgeConstants.MODERN_FML_RESET);
|
||||||
|
this.user.getCh().setProtocol(Protocol.LOGIN);
|
||||||
|
this.user.getCh().beginHandshake();
|
||||||
|
((HandlerBoss)this.user.getCh().getHandle().pipeline().get(HandlerBoss.class)).setHandler(new ModernForgeUpstreamBridge(this.bungee, this.user, this));
|
||||||
|
if (this.user.getServer() != null) {
|
||||||
|
this.user.getServer().setObsolete(true);
|
||||||
|
this.user.getServer().disconnect("Quiting");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.thisState = ModernForgeServerConnector.State.PENDING;
|
||||||
|
case 1:
|
||||||
|
this.pendingHandshakes.add(request);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
this.writePacket(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onResetAck() {
|
||||||
|
Preconditions.checkState(this.thisState == ModernForgeServerConnector.State.PENDING, "Not expecting PENDING");
|
||||||
|
|
||||||
|
while(!this.pendingHandshakes.isEmpty()) {
|
||||||
|
this.writePacket((LoginPayloadRequest)this.pendingHandshakes.poll());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.thisState = ModernForgeServerConnector.State.ACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writePacket(LoginPayloadRequest packet) {
|
||||||
|
ModernFMLHandshakeEvent.Request event = new ModernFMLHandshakeEvent.Request(this.user, this.target, packet);
|
||||||
|
if (event.callEvent()) {
|
||||||
|
this.user.unsafe().sendPacket(packet);
|
||||||
|
} else if (event.getResponse() != null) {
|
||||||
|
this.user.getForgeServerHandler().getCh().write((Object)event.getResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChannelWrapper getChannel() {
|
||||||
|
return this.ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
if (this.thisState != ModernForgeServerConnector.State.PLAIN) {
|
||||||
|
String var10000 = this.user.getName();
|
||||||
|
return "[" + var10000 + "|" + String.valueOf(this.user.getAddress()) + "] <-> Modern FML " + String.valueOf(this.thisState) + " [" + this.target.getName() + "]";
|
||||||
|
} else {
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BungeeServerInfo getTarget() {
|
||||||
|
return this.target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public State getThisState() {
|
||||||
|
return this.thisState;
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum State {
|
||||||
|
PLAIN,
|
||||||
|
PENDING,
|
||||||
|
ACK;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package dev._2lstudios.flamecord.forge;
|
||||||
|
|
||||||
|
import io.netty.handler.timeout.ReadTimeoutException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import net.md_5.bungee.UserConnection;
|
||||||
|
import net.md_5.bungee.Util;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
|
import net.md_5.bungee.netty.ChannelWrapper;
|
||||||
|
import net.md_5.bungee.netty.PacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.PacketWrapper;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
|
||||||
|
|
||||||
|
public class ModernForgeUpstreamBridge extends PacketHandler {
|
||||||
|
private final ProxyServer bungee;
|
||||||
|
private final UserConnection con;
|
||||||
|
private final ModernForgeServerConnector server;
|
||||||
|
private static final byte[] RESET_ACK;
|
||||||
|
|
||||||
|
public boolean shouldHandle(PacketWrapper packet) throws Exception {
|
||||||
|
return packet.packet instanceof LoginPayloadResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(LoginPayloadResponse response) throws Exception {
|
||||||
|
if (isAckPacket(response)) {
|
||||||
|
this.server.onResetAck();
|
||||||
|
} else if ((new ModernFMLHandshakeEvent.Response(this.con, this.server.getTarget(), response)).callEvent()) {
|
||||||
|
this.con.getForgeServerHandler().getCh().write((Object)response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exception(Throwable t) throws Exception {
|
||||||
|
if (this.server.getThisState() == ModernForgeServerConnector.State.PENDING) {
|
||||||
|
this.con.getCh().setProtocol(Protocol.GAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t instanceof ReadTimeoutException) {
|
||||||
|
this.con.disconnect("You need to install lightfall client mod to join this server!");
|
||||||
|
} else {
|
||||||
|
this.con.disconnect(Util.exception(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnected(ChannelWrapper channel) throws Exception {
|
||||||
|
PlayerDisconnectEvent event = new PlayerDisconnectEvent(this.con);
|
||||||
|
this.bungee.getPluginManager().callEvent(event);
|
||||||
|
this.con.getTabListHandler().onDisconnect();
|
||||||
|
this.server.getChannel().close();
|
||||||
|
BungeeCord.getInstance().removeConnection(this.con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
String var10000 = String.valueOf(this.con.getAddress());
|
||||||
|
return "[" + var10000 + "|" + this.con.getName() + "] -> HS Upstream";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAckPacket(LoginPayloadResponse response) {
|
||||||
|
return Arrays.equals(response.getData(), RESET_ACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public ModernForgeUpstreamBridge(ProxyServer bungee, UserConnection con, ModernForgeServerConnector server) {
|
||||||
|
this.bungee = bungee;
|
||||||
|
this.con = con;
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
RESET_ACK = "lightfall:ack".getBytes(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package dev._2lstudios.flamecord.managers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class UserWhitelistManager {
|
||||||
|
private final Set<String> whitelisted = new HashSet();
|
||||||
|
private final File folder;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
public UserWhitelistManager(File dataFolder, Logger logger) {
|
||||||
|
this.folder = new File(dataFolder, "whitelists");
|
||||||
|
this.logger = logger;
|
||||||
|
if (!this.folder.exists()) {
|
||||||
|
this.folder.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
this.whitelisted.clear();
|
||||||
|
File[] files = this.folder.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for(File file : files) {
|
||||||
|
if (file.isFile() && file.getName().endsWith(".yml")) {
|
||||||
|
String entry = file.getName().substring(0, file.getName().length() - 4);
|
||||||
|
this.whitelisted.add(entry.toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info("[FlameCord] Loaded " + this.whitelisted.size() + " entries into User Whitelist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String target) {
|
||||||
|
String entry = target.toLowerCase();
|
||||||
|
if (this.whitelisted.add(entry)) {
|
||||||
|
File file = new File(this.folder, entry + ".yml");
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
} catch (IOException var5) {
|
||||||
|
this.logger.warning("[FlameCord] Could not create whitelist file for: " + entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(String target) {
|
||||||
|
String entry = target.toLowerCase();
|
||||||
|
if (this.whitelisted.remove(entry)) {
|
||||||
|
File file = new File(this.folder, entry + ".yml");
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWhitelisted(String target) {
|
||||||
|
if (target == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return target.isEmpty() ? false : this.whitelisted.contains(target.toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class DefaultSpawnPosition extends DefinedPacket {
|
||||||
|
private int posX;
|
||||||
|
private int posY;
|
||||||
|
private int posZ;
|
||||||
|
private float angle;
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
long location;
|
||||||
|
if (protocolVersion < 477) {
|
||||||
|
location = ((long)this.posX & 67108863L) << 38 | ((long)this.posY & 4095L) << 26 | (long)this.posZ & 67108863L;
|
||||||
|
} else {
|
||||||
|
location = ((long)this.posX & 67108863L) << 38 | ((long)this.posZ & 67108863L) << 12 | (long)this.posY & 4095L;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.writeLong(location);
|
||||||
|
if (protocolVersion >= 755) {
|
||||||
|
buf.writeFloat(this.angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public DefaultSpawnPosition(int posX, int posY, int posZ, float angle) {
|
||||||
|
this.posX = posX;
|
||||||
|
this.posY = posY;
|
||||||
|
this.posZ = posZ;
|
||||||
|
this.angle = angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public DefaultSpawnPosition() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getPosX() {
|
||||||
|
return this.posX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getPosY() {
|
||||||
|
return this.posY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getPosZ() {
|
||||||
|
return this.posZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getAngle() {
|
||||||
|
return this.angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setPosX(int posX) {
|
||||||
|
this.posX = posX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setPosY(int posY) {
|
||||||
|
this.posY = posY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setPosZ(int posZ) {
|
||||||
|
this.posZ = posZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setAngle(float angle) {
|
||||||
|
this.angle = angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof DefaultSpawnPosition)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
DefaultSpawnPosition other = (DefaultSpawnPosition)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getPosX() != other.getPosX()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getPosY() != other.getPosY()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getPosZ() != other.getPosZ()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return Float.compare(this.getAngle(), other.getAngle()) == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof DefaultSpawnPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + this.getPosX();
|
||||||
|
result = result * 59 + this.getPosY();
|
||||||
|
result = result * 59 + this.getPosZ();
|
||||||
|
result = result * 59 + Float.floatToIntBits(this.getAngle());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
int var10000 = this.getPosX();
|
||||||
|
return "DefaultSpawnPosition(posX=" + var10000 + ", posY=" + this.getPosY() + ", posZ=" + this.getPosZ() + ", angle=" + this.getAngle() + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.BitSet;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import se.llbit.nbt.CompoundTag;
|
||||||
|
import se.llbit.nbt.LongArrayTag;
|
||||||
|
import se.llbit.nbt.NamedTag;
|
||||||
|
import se.llbit.nbt.Tag;
|
||||||
|
|
||||||
|
public class EmptyChunkPacket extends DefinedPacket {
|
||||||
|
int x;
|
||||||
|
int z;
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int version) {
|
||||||
|
buf.writeInt(this.x);
|
||||||
|
buf.writeInt(this.z);
|
||||||
|
if (version < 755) {
|
||||||
|
buf.writeBoolean(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version >= 735 && version < 751) {
|
||||||
|
buf.writeBoolean(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version < 755) {
|
||||||
|
if (version == 47) {
|
||||||
|
buf.writeShort(1);
|
||||||
|
} else {
|
||||||
|
writeVarInt(0, buf);
|
||||||
|
}
|
||||||
|
} else if (version < 757) {
|
||||||
|
BitSet bitSet = new BitSet();
|
||||||
|
|
||||||
|
for(int i = 0; i < 16; ++i) {
|
||||||
|
bitSet.set(i, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
long[] mask = bitSet.toLongArray();
|
||||||
|
DefinedPacket.writeVarInt(mask.length, buf);
|
||||||
|
|
||||||
|
for(long l : mask) {
|
||||||
|
buf.writeLong(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version >= 477) {
|
||||||
|
this.write1_14Heightmaps(buf, version);
|
||||||
|
if (version >= 573 && version < 757) {
|
||||||
|
if (version >= 751) {
|
||||||
|
writeVarInt(1024, buf);
|
||||||
|
|
||||||
|
for(int i = 0; i < 1024; ++i) {
|
||||||
|
writeVarInt(1, buf);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < 1024; ++i) {
|
||||||
|
buf.writeInt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version < 393) {
|
||||||
|
writeArray(new byte[256], buf);
|
||||||
|
} else if (version < 573) {
|
||||||
|
writeArray(new byte[1024], buf);
|
||||||
|
} else if (version < 757) {
|
||||||
|
writeVarInt(0, buf);
|
||||||
|
} else {
|
||||||
|
byte[] sectionData = new byte[]{0, 0, 0, 0, 0, 0, 1, 0};
|
||||||
|
writeVarInt(sectionData.length * 16, buf);
|
||||||
|
|
||||||
|
for(int i = 0; i < 16; ++i) {
|
||||||
|
buf.writeBytes(sectionData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version >= 110) {
|
||||||
|
DefinedPacket.writeVarInt(0, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version >= 757) {
|
||||||
|
byte[] lightData = new byte[]{1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 3, -1, -1, 0, 0};
|
||||||
|
buf.ensureWritable(lightData.length);
|
||||||
|
if (version >= 763) {
|
||||||
|
buf.writeBytes(lightData, 1, lightData.length - 1);
|
||||||
|
} else {
|
||||||
|
buf.writeBytes(lightData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void write1_14Heightmaps(ByteBuf buf, int version) {
|
||||||
|
long[] longArrayTag = new long[version < 757 ? 36 : 37];
|
||||||
|
CompoundTag compoundTag = new CompoundTag();
|
||||||
|
compoundTag.add("MOTION_BLOCKING", new LongArrayTag(longArrayTag));
|
||||||
|
Tag write = (Tag)(version >= 764 ? compoundTag : new NamedTag("", compoundTag));
|
||||||
|
writeTag(write, buf, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getX() {
|
||||||
|
return this.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getZ() {
|
||||||
|
return this.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setZ(int z) {
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
int var10000 = this.getX();
|
||||||
|
return "EmptyChunkPacket(x=" + var10000 + ", z=" + this.getZ() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public EmptyChunkPacket() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public EmptyChunkPacket(int x, int z) {
|
||||||
|
this.x = x;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof EmptyChunkPacket)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
EmptyChunkPacket other = (EmptyChunkPacket)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getX() != other.getX()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.getZ() == other.getZ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof EmptyChunkPacket;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + this.getX();
|
||||||
|
result = result * 59 + this.getZ();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,486 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.utils.Dimension;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class JoinGame extends DefinedPacket {
|
||||||
|
private final int entityId;
|
||||||
|
private boolean hardcore;
|
||||||
|
private short gameMode;
|
||||||
|
private short previousGameMode;
|
||||||
|
private Set<String> worldNames;
|
||||||
|
private String worldName;
|
||||||
|
private int dimensionId;
|
||||||
|
private long seed;
|
||||||
|
private short difficulty;
|
||||||
|
private short maxPlayers;
|
||||||
|
private String levelType;
|
||||||
|
private int viewDistance;
|
||||||
|
private boolean reducedDebugInfo;
|
||||||
|
private boolean normalRespawn;
|
||||||
|
private boolean debug;
|
||||||
|
private boolean flat;
|
||||||
|
private Dimension dimension;
|
||||||
|
|
||||||
|
public JoinGame() {
|
||||||
|
this(0, Dimension.OVERWORLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JoinGame(int entityId, Dimension dimension) {
|
||||||
|
this.hardcore = false;
|
||||||
|
this.gameMode = 0;
|
||||||
|
this.previousGameMode = 0;
|
||||||
|
this.worldNames = new HashSet(Arrays.asList("minecraft:overworld"));
|
||||||
|
this.worldName = "minecraft:overworld";
|
||||||
|
this.dimensionId = 0;
|
||||||
|
this.seed = 1L;
|
||||||
|
this.difficulty = 0;
|
||||||
|
this.maxPlayers = 1;
|
||||||
|
this.levelType = "flat";
|
||||||
|
this.viewDistance = 0;
|
||||||
|
this.reducedDebugInfo = false;
|
||||||
|
this.normalRespawn = true;
|
||||||
|
this.debug = false;
|
||||||
|
this.flat = true;
|
||||||
|
this.entityId = entityId;
|
||||||
|
this.dimensionId = dimension.getDimensionId();
|
||||||
|
this.worldName = dimension.getKey();
|
||||||
|
this.worldNames = new HashSet(Arrays.asList(dimension.getKey()));
|
||||||
|
this.dimension = dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
buf.writeInt(this.entityId);
|
||||||
|
if (protocolVersion >= 751) {
|
||||||
|
buf.writeBoolean(this.hardcore);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion < 764) {
|
||||||
|
buf.writeByte(this.gameMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 735) {
|
||||||
|
if (protocolVersion < 764) {
|
||||||
|
buf.writeByte(this.previousGameMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeVarInt(this.worldNames.size(), buf);
|
||||||
|
|
||||||
|
for(String world : this.worldNames) {
|
||||||
|
writeString(world, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion < 764) {
|
||||||
|
writeTag(this.dimension.getFullCodec(protocolVersion), buf, protocolVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 735) {
|
||||||
|
if (protocolVersion >= 751 && protocolVersion < 759) {
|
||||||
|
writeTag(this.dimension.getAttributes(protocolVersion), buf, protocolVersion);
|
||||||
|
} else if (protocolVersion < 764) {
|
||||||
|
writeString(this.worldName, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion < 764) {
|
||||||
|
writeString(this.worldName, buf);
|
||||||
|
}
|
||||||
|
} else if (protocolVersion > 107) {
|
||||||
|
buf.writeInt(this.dimensionId);
|
||||||
|
} else {
|
||||||
|
buf.writeByte(this.dimensionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 573 && protocolVersion < 764) {
|
||||||
|
buf.writeLong(this.seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion < 477) {
|
||||||
|
buf.writeByte(this.difficulty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 751) {
|
||||||
|
writeVarInt(this.maxPlayers, buf);
|
||||||
|
} else {
|
||||||
|
buf.writeByte(this.maxPlayers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion < 735) {
|
||||||
|
writeString(this.levelType, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 477) {
|
||||||
|
writeVarInt(this.viewDistance, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 757) {
|
||||||
|
writeVarInt(this.viewDistance, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 29) {
|
||||||
|
buf.writeBoolean(this.reducedDebugInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 573) {
|
||||||
|
buf.writeBoolean(this.normalRespawn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 764) {
|
||||||
|
buf.writeBoolean(true);
|
||||||
|
if (protocolVersion >= 766) {
|
||||||
|
writeVarInt(0, buf);
|
||||||
|
} else {
|
||||||
|
writeString(this.worldName, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeString(this.worldName, buf);
|
||||||
|
buf.writeLong(this.seed);
|
||||||
|
buf.writeByte(this.gameMode);
|
||||||
|
buf.writeByte(this.previousGameMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 735) {
|
||||||
|
buf.writeBoolean(this.debug);
|
||||||
|
buf.writeBoolean(this.flat);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 759) {
|
||||||
|
buf.writeBoolean(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 763) {
|
||||||
|
writeVarInt(0, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 768) {
|
||||||
|
writeVarInt(60, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 766) {
|
||||||
|
buf.writeBoolean(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getEntityId() {
|
||||||
|
return this.entityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isHardcore() {
|
||||||
|
return this.hardcore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public short getGameMode() {
|
||||||
|
return this.gameMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public short getPreviousGameMode() {
|
||||||
|
return this.previousGameMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Set<String> getWorldNames() {
|
||||||
|
return this.worldNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getWorldName() {
|
||||||
|
return this.worldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getDimensionId() {
|
||||||
|
return this.dimensionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public long getSeed() {
|
||||||
|
return this.seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public short getDifficulty() {
|
||||||
|
return this.difficulty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public short getMaxPlayers() {
|
||||||
|
return this.maxPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getLevelType() {
|
||||||
|
return this.levelType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getViewDistance() {
|
||||||
|
return this.viewDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isReducedDebugInfo() {
|
||||||
|
return this.reducedDebugInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isNormalRespawn() {
|
||||||
|
return this.normalRespawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isDebug() {
|
||||||
|
return this.debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isFlat() {
|
||||||
|
return this.flat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Dimension getDimension() {
|
||||||
|
return this.dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setHardcore(boolean hardcore) {
|
||||||
|
this.hardcore = hardcore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setGameMode(short gameMode) {
|
||||||
|
this.gameMode = gameMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setPreviousGameMode(short previousGameMode) {
|
||||||
|
this.previousGameMode = previousGameMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setWorldNames(Set<String> worldNames) {
|
||||||
|
this.worldNames = worldNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setWorldName(String worldName) {
|
||||||
|
this.worldName = worldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setDimensionId(int dimensionId) {
|
||||||
|
this.dimensionId = dimensionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setSeed(long seed) {
|
||||||
|
this.seed = seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setDifficulty(short difficulty) {
|
||||||
|
this.difficulty = difficulty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setMaxPlayers(short maxPlayers) {
|
||||||
|
this.maxPlayers = maxPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setLevelType(String levelType) {
|
||||||
|
this.levelType = levelType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setViewDistance(int viewDistance) {
|
||||||
|
this.viewDistance = viewDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setReducedDebugInfo(boolean reducedDebugInfo) {
|
||||||
|
this.reducedDebugInfo = reducedDebugInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setNormalRespawn(boolean normalRespawn) {
|
||||||
|
this.normalRespawn = normalRespawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setDebug(boolean debug) {
|
||||||
|
this.debug = debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setFlat(boolean flat) {
|
||||||
|
this.flat = flat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setDimension(Dimension dimension) {
|
||||||
|
this.dimension = dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
int var10000 = this.getEntityId();
|
||||||
|
return "JoinGame(entityId=" + var10000 + ", hardcore=" + this.isHardcore() + ", gameMode=" + this.getGameMode() + ", previousGameMode=" + this.getPreviousGameMode() + ", worldNames=" + String.valueOf(this.getWorldNames()) + ", worldName=" + this.getWorldName() + ", dimensionId=" + this.getDimensionId() + ", seed=" + this.getSeed() + ", difficulty=" + this.getDifficulty() + ", maxPlayers=" + this.getMaxPlayers() + ", levelType=" + this.getLevelType() + ", viewDistance=" + this.getViewDistance() + ", reducedDebugInfo=" + this.isReducedDebugInfo() + ", normalRespawn=" + this.isNormalRespawn() + ", debug=" + this.isDebug() + ", flat=" + this.isFlat() + ", dimension=" + String.valueOf(this.getDimension()) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public JoinGame(int entityId) {
|
||||||
|
this.hardcore = false;
|
||||||
|
this.gameMode = 0;
|
||||||
|
this.previousGameMode = 0;
|
||||||
|
this.worldNames = new HashSet(Arrays.asList("minecraft:overworld"));
|
||||||
|
this.worldName = "minecraft:overworld";
|
||||||
|
this.dimensionId = 0;
|
||||||
|
this.seed = 1L;
|
||||||
|
this.difficulty = 0;
|
||||||
|
this.maxPlayers = 1;
|
||||||
|
this.levelType = "flat";
|
||||||
|
this.viewDistance = 0;
|
||||||
|
this.reducedDebugInfo = false;
|
||||||
|
this.normalRespawn = true;
|
||||||
|
this.debug = false;
|
||||||
|
this.flat = true;
|
||||||
|
this.entityId = entityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof JoinGame)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
JoinGame other = (JoinGame)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getEntityId() != other.getEntityId()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.isHardcore() != other.isHardcore()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getGameMode() != other.getGameMode()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getPreviousGameMode() != other.getPreviousGameMode()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getDimensionId() != other.getDimensionId()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getSeed() != other.getSeed()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getDifficulty() != other.getDifficulty()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getMaxPlayers() != other.getMaxPlayers()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getViewDistance() != other.getViewDistance()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.isReducedDebugInfo() != other.isReducedDebugInfo()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.isNormalRespawn() != other.isNormalRespawn()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.isDebug() != other.isDebug()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.isFlat() != other.isFlat()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Object this$worldNames = this.getWorldNames();
|
||||||
|
Object other$worldNames = other.getWorldNames();
|
||||||
|
if (this$worldNames == null) {
|
||||||
|
if (other$worldNames != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$worldNames.equals(other$worldNames)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$worldName = this.getWorldName();
|
||||||
|
Object other$worldName = other.getWorldName();
|
||||||
|
if (this$worldName == null) {
|
||||||
|
if (other$worldName != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$worldName.equals(other$worldName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$levelType = this.getLevelType();
|
||||||
|
Object other$levelType = other.getLevelType();
|
||||||
|
if (this$levelType == null) {
|
||||||
|
if (other$levelType != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$levelType.equals(other$levelType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$dimension = this.getDimension();
|
||||||
|
Object other$dimension = other.getDimension();
|
||||||
|
if (this$dimension == null) {
|
||||||
|
if (other$dimension != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$dimension.equals(other$dimension)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof JoinGame;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + this.getEntityId();
|
||||||
|
result = result * 59 + (this.isHardcore() ? 79 : 97);
|
||||||
|
result = result * 59 + this.getGameMode();
|
||||||
|
result = result * 59 + this.getPreviousGameMode();
|
||||||
|
result = result * 59 + this.getDimensionId();
|
||||||
|
long $seed = this.getSeed();
|
||||||
|
result = result * 59 + (int)($seed >>> 32 ^ $seed);
|
||||||
|
result = result * 59 + this.getDifficulty();
|
||||||
|
result = result * 59 + this.getMaxPlayers();
|
||||||
|
result = result * 59 + this.getViewDistance();
|
||||||
|
result = result * 59 + (this.isReducedDebugInfo() ? 79 : 97);
|
||||||
|
result = result * 59 + (this.isNormalRespawn() ? 79 : 97);
|
||||||
|
result = result * 59 + (this.isDebug() ? 79 : 97);
|
||||||
|
result = result * 59 + (this.isFlat() ? 79 : 97);
|
||||||
|
Object $worldNames = this.getWorldNames();
|
||||||
|
result = result * 59 + ($worldNames == null ? 43 : $worldNames.hashCode());
|
||||||
|
Object $worldName = this.getWorldName();
|
||||||
|
result = result * 59 + ($worldName == null ? 43 : $worldName.hashCode());
|
||||||
|
Object $levelType = this.getLevelType();
|
||||||
|
result = result * 59 + ($levelType == null ? 43 : $levelType.hashCode());
|
||||||
|
Object $dimension = this.getDimension();
|
||||||
|
result = result * 59 + ($dimension == null ? 43 : $dimension.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class MapDataPacket extends DefinedPacket {
|
||||||
|
private int mapId;
|
||||||
|
private byte scale;
|
||||||
|
private MapData data;
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
writeVarInt(this.mapId, buf);
|
||||||
|
buf.writeByte(this.scale);
|
||||||
|
if (protocolVersion >= 107 && protocolVersion < 755) {
|
||||||
|
buf.writeBoolean(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 477) {
|
||||||
|
buf.writeBoolean(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 755) {
|
||||||
|
buf.writeBoolean(false);
|
||||||
|
} else {
|
||||||
|
writeVarInt(0, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.writeByte(this.data.getColumns());
|
||||||
|
buf.writeByte(this.data.getRows());
|
||||||
|
buf.writeByte(this.data.getX());
|
||||||
|
buf.writeByte(this.data.getY());
|
||||||
|
buf.ensureWritable(3 + this.data.getData().length);
|
||||||
|
writeArray(this.data.getData(), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getMapId() {
|
||||||
|
return this.mapId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public byte getScale() {
|
||||||
|
return this.scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public MapData getData() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setMapId(int mapId) {
|
||||||
|
this.mapId = mapId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setScale(byte scale) {
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setData(MapData data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
int var10000 = this.getMapId();
|
||||||
|
return "MapDataPacket(mapId=" + var10000 + ", scale=" + this.getScale() + ", data=" + String.valueOf(this.getData()) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public MapDataPacket() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public MapDataPacket(int mapId, byte scale, MapData data) {
|
||||||
|
this.mapId = mapId;
|
||||||
|
this.scale = scale;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof MapDataPacket)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
MapDataPacket other = (MapDataPacket)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getMapId() != other.getMapId()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getScale() != other.getScale()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Object this$data = this.getData();
|
||||||
|
Object other$data = other.getData();
|
||||||
|
if (this$data == null) {
|
||||||
|
if (other$data != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$data.equals(other$data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof MapDataPacket;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + this.getMapId();
|
||||||
|
result = result * 59 + this.getScale();
|
||||||
|
Object $data = this.getData();
|
||||||
|
result = result * 59 + ($data == null ? 43 : $data.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MapData {
|
||||||
|
private int columns;
|
||||||
|
private int rows;
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private byte[] data;
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public MapData(int columns, int rows, int x, int y, byte[] data) {
|
||||||
|
this.columns = columns;
|
||||||
|
this.rows = rows;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getColumns() {
|
||||||
|
return this.columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getRows() {
|
||||||
|
return this.rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getX() {
|
||||||
|
return this.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getY() {
|
||||||
|
return this.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public byte[] getData() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class Player extends DefinedPacket {
|
||||||
|
private boolean onGround;
|
||||||
|
|
||||||
|
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
if (protocolVersion < 768) {
|
||||||
|
this.onGround = buf.readBoolean();
|
||||||
|
} else {
|
||||||
|
short flags = buf.readUnsignedByte();
|
||||||
|
this.onGround = (flags & 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
handler.handle(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isOnGround() {
|
||||||
|
return this.onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setOnGround(boolean onGround) {
|
||||||
|
this.onGround = onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
return "Player(onGround=" + this.isOnGround() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Player() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Player(boolean onGround) {
|
||||||
|
this.onGround = onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof Player)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Player other = (Player)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.isOnGround() == other.isOnGround();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof Player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + (this.isOnGround() ? 79 : 97);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class PlayerAbilities extends DefinedPacket {
|
||||||
|
byte flags;
|
||||||
|
float speed;
|
||||||
|
float field;
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
buf.writeByte(this.flags);
|
||||||
|
buf.writeFloat(this.speed);
|
||||||
|
buf.writeFloat(this.field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public byte getFlags() {
|
||||||
|
return this.flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getSpeed() {
|
||||||
|
return this.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getField() {
|
||||||
|
return this.field;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setFlags(byte flags) {
|
||||||
|
this.flags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setSpeed(float speed) {
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setField(float field) {
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
byte var10000 = this.getFlags();
|
||||||
|
return "PlayerAbilities(flags=" + var10000 + ", speed=" + this.getSpeed() + ", field=" + this.getField() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public PlayerAbilities() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public PlayerAbilities(byte flags, float speed, float field) {
|
||||||
|
this.flags = flags;
|
||||||
|
this.speed = speed;
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof PlayerAbilities)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
PlayerAbilities other = (PlayerAbilities)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getFlags() != other.getFlags()) {
|
||||||
|
return false;
|
||||||
|
} else if (Float.compare(this.getSpeed(), other.getSpeed()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return Float.compare(this.getField(), other.getField()) == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof PlayerAbilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + this.getFlags();
|
||||||
|
result = result * 59 + Float.floatToIntBits(this.getSpeed());
|
||||||
|
result = result * 59 + Float.floatToIntBits(this.getField());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class PlayerPosition extends DefinedPacket {
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
private double z;
|
||||||
|
private boolean onGround;
|
||||||
|
|
||||||
|
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
this.x = buf.readDouble();
|
||||||
|
this.y = buf.readDouble();
|
||||||
|
this.z = buf.readDouble();
|
||||||
|
if (protocolVersion < 768) {
|
||||||
|
this.onGround = buf.readBoolean();
|
||||||
|
} else {
|
||||||
|
short flags = buf.readUnsignedByte();
|
||||||
|
this.onGround = (flags & 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
handler.handle(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public double getX() {
|
||||||
|
return this.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public double getY() {
|
||||||
|
return this.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public double getZ() {
|
||||||
|
return this.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isOnGround() {
|
||||||
|
return this.onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setX(double x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setY(double y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setZ(double z) {
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setOnGround(boolean onGround) {
|
||||||
|
this.onGround = onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
double var10000 = this.getX();
|
||||||
|
return "PlayerPosition(x=" + var10000 + ", y=" + this.getY() + ", z=" + this.getZ() + ", onGround=" + this.isOnGround() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public PlayerPosition() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public PlayerPosition(double x, double y, double z, boolean onGround) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.onGround = onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof PlayerPosition)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
PlayerPosition other = (PlayerPosition)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (Double.compare(this.getX(), other.getX()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else if (Double.compare(this.getY(), other.getY()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else if (Double.compare(this.getZ(), other.getZ()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.isOnGround() == other.isOnGround();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof PlayerPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
long $x = Double.doubleToLongBits(this.getX());
|
||||||
|
result = result * 59 + (int)($x >>> 32 ^ $x);
|
||||||
|
long $y = Double.doubleToLongBits(this.getY());
|
||||||
|
result = result * 59 + (int)($y >>> 32 ^ $y);
|
||||||
|
long $z = Double.doubleToLongBits(this.getZ());
|
||||||
|
result = result * 59 + (int)($z >>> 32 ^ $z);
|
||||||
|
result = result * 59 + (this.isOnGround() ? 79 : 97);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class PlayerPositionAndLook extends DefinedPacket {
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
private double z;
|
||||||
|
private float yaw;
|
||||||
|
private float pitch;
|
||||||
|
private int teleportId;
|
||||||
|
private boolean onGround;
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
if (protocolVersion >= 768) {
|
||||||
|
DefinedPacket.writeVarInt(this.teleportId, buf);
|
||||||
|
buf.writeDouble(this.x);
|
||||||
|
buf.writeDouble(this.y);
|
||||||
|
buf.writeDouble(this.z);
|
||||||
|
buf.writeDouble((double)0.0F);
|
||||||
|
buf.writeDouble((double)0.0F);
|
||||||
|
buf.writeDouble((double)0.0F);
|
||||||
|
buf.writeFloat(this.yaw);
|
||||||
|
buf.writeFloat(this.pitch);
|
||||||
|
buf.writeInt(0);
|
||||||
|
} else {
|
||||||
|
buf.writeDouble(this.x);
|
||||||
|
buf.writeDouble(this.y);
|
||||||
|
buf.writeDouble(this.z);
|
||||||
|
buf.writeFloat(this.yaw);
|
||||||
|
buf.writeFloat(this.pitch);
|
||||||
|
buf.writeByte(0);
|
||||||
|
if (protocolVersion >= 107) {
|
||||||
|
writeVarInt(this.teleportId, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 755 && protocolVersion <= 761) {
|
||||||
|
buf.writeBoolean(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
this.x = buf.readDouble();
|
||||||
|
this.y = buf.readDouble();
|
||||||
|
this.z = buf.readDouble();
|
||||||
|
this.yaw = buf.readFloat();
|
||||||
|
this.pitch = buf.readFloat();
|
||||||
|
if (protocolVersion < 768) {
|
||||||
|
this.onGround = buf.readBoolean();
|
||||||
|
} else {
|
||||||
|
short flags = buf.readUnsignedByte();
|
||||||
|
this.onGround = (flags & 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
handler.handle(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public double getX() {
|
||||||
|
return this.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public double getY() {
|
||||||
|
return this.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public double getZ() {
|
||||||
|
return this.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getYaw() {
|
||||||
|
return this.yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getPitch() {
|
||||||
|
return this.pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getTeleportId() {
|
||||||
|
return this.teleportId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isOnGround() {
|
||||||
|
return this.onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setX(double x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setY(double y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setZ(double z) {
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setYaw(float yaw) {
|
||||||
|
this.yaw = yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setPitch(float pitch) {
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setTeleportId(int teleportId) {
|
||||||
|
this.teleportId = teleportId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setOnGround(boolean onGround) {
|
||||||
|
this.onGround = onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
double var10000 = this.getX();
|
||||||
|
return "PlayerPositionAndLook(x=" + var10000 + ", y=" + this.getY() + ", z=" + this.getZ() + ", yaw=" + this.getYaw() + ", pitch=" + this.getPitch() + ", teleportId=" + this.getTeleportId() + ", onGround=" + this.isOnGround() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public PlayerPositionAndLook() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public PlayerPositionAndLook(double x, double y, double z, float yaw, float pitch, int teleportId, boolean onGround) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.yaw = yaw;
|
||||||
|
this.pitch = pitch;
|
||||||
|
this.teleportId = teleportId;
|
||||||
|
this.onGround = onGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof PlayerPositionAndLook)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
PlayerPositionAndLook other = (PlayerPositionAndLook)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (Double.compare(this.getX(), other.getX()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else if (Double.compare(this.getY(), other.getY()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else if (Double.compare(this.getZ(), other.getZ()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else if (Float.compare(this.getYaw(), other.getYaw()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return Float.compare(this.getPitch(), other.getPitch()) == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof PlayerPositionAndLook;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
long $x = Double.doubleToLongBits(this.getX());
|
||||||
|
result = result * 59 + (int)($x >>> 32 ^ $x);
|
||||||
|
long $y = Double.doubleToLongBits(this.getY());
|
||||||
|
result = result * 59 + (int)($y >>> 32 ^ $y);
|
||||||
|
long $z = Double.doubleToLongBits(this.getZ());
|
||||||
|
result = result * 59 + (int)($z >>> 32 ^ $z);
|
||||||
|
result = result * 59 + Float.floatToIntBits(this.getYaw());
|
||||||
|
result = result * 59 + Float.floatToIntBits(this.getPitch());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.utils.Dimension;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import se.llbit.nbt.CompoundTag;
|
||||||
|
import se.llbit.nbt.ListTag;
|
||||||
|
import se.llbit.nbt.NamedTag;
|
||||||
|
import se.llbit.nbt.Tag;
|
||||||
|
|
||||||
|
public class RegistryData extends DefinedPacket {
|
||||||
|
private Tag codec;
|
||||||
|
private String name;
|
||||||
|
private List<Entry> entries;
|
||||||
|
|
||||||
|
public RegistryData(Tag codec) {
|
||||||
|
this.codec = codec;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegistryData(String name, List<Entry> entries) {
|
||||||
|
this.name = name;
|
||||||
|
this.entries = entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
if (protocolVersion < 766) {
|
||||||
|
writeTag(this.codec, buf, protocolVersion);
|
||||||
|
} else {
|
||||||
|
writeString(this.name, buf);
|
||||||
|
writeVarInt(this.entries.size(), buf);
|
||||||
|
|
||||||
|
for(Entry entry : this.entries) {
|
||||||
|
writeString(entry.id, buf);
|
||||||
|
if (entry.tag != null) {
|
||||||
|
buf.writeBoolean(true);
|
||||||
|
writeTag(entry.tag, buf, protocolVersion);
|
||||||
|
} else {
|
||||||
|
buf.writeBoolean(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<RegistryData> transform(Dimension dimension, int protocolVersion) {
|
||||||
|
CompoundTag codec = (CompoundTag)dimension.getFullCodec(protocolVersion);
|
||||||
|
if (protocolVersion <= 765) {
|
||||||
|
return Collections.singletonList(new RegistryData(codec));
|
||||||
|
} else {
|
||||||
|
List<RegistryData> result = new ArrayList();
|
||||||
|
|
||||||
|
for(NamedTag tag : codec) {
|
||||||
|
String type = tag.getTag().get("type").stringValue();
|
||||||
|
ListTag values = tag.getTag().get("value").asList();
|
||||||
|
List<Entry> entries = new ArrayList(values.size());
|
||||||
|
|
||||||
|
for(Tag value : values) {
|
||||||
|
Tag element = value.get("element");
|
||||||
|
entries.add(new Entry(value.get("name").stringValue(), element.isError() ? null : element));
|
||||||
|
}
|
||||||
|
|
||||||
|
result.add(new RegistryData(type, entries));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Tag getCodec() {
|
||||||
|
return this.codec;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public List<Entry> getEntries() {
|
||||||
|
return this.entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setCodec(Tag codec) {
|
||||||
|
this.codec = codec;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setEntries(List<Entry> entries) {
|
||||||
|
this.entries = entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
String var10000 = String.valueOf(this.getCodec());
|
||||||
|
return "RegistryData(codec=" + var10000 + ", name=" + this.getName() + ", entries=" + String.valueOf(this.getEntries()) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public RegistryData() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public RegistryData(Tag codec, String name, List<Entry> entries) {
|
||||||
|
this.codec = codec;
|
||||||
|
this.name = name;
|
||||||
|
this.entries = entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof RegistryData)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
RegistryData other = (RegistryData)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Object this$codec = this.getCodec();
|
||||||
|
Object other$codec = other.getCodec();
|
||||||
|
if (this$codec == null) {
|
||||||
|
if (other$codec != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$codec.equals(other$codec)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$name = this.getName();
|
||||||
|
Object other$name = other.getName();
|
||||||
|
if (this$name == null) {
|
||||||
|
if (other$name != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$name.equals(other$name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$entries = this.getEntries();
|
||||||
|
Object other$entries = other.getEntries();
|
||||||
|
if (this$entries == null) {
|
||||||
|
if (other$entries != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$entries.equals(other$entries)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof RegistryData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
Object $codec = this.getCodec();
|
||||||
|
result = result * 59 + ($codec == null ? 43 : $codec.hashCode());
|
||||||
|
Object $name = this.getName();
|
||||||
|
result = result * 59 + ($name == null ? 43 : $name.hashCode());
|
||||||
|
Object $entries = this.getEntries();
|
||||||
|
result = result * 59 + ($entries == null ? 43 : $entries.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Entry {
|
||||||
|
private String id;
|
||||||
|
private Tag tag;
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Entry(String id, Tag tag) {
|
||||||
|
this.id = id;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class SetExp extends DefinedPacket {
|
||||||
|
float expBar;
|
||||||
|
int level;
|
||||||
|
int totalExp;
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
buf.writeFloat(this.expBar);
|
||||||
|
DefinedPacket.writeVarInt(this.level, buf);
|
||||||
|
DefinedPacket.writeVarInt(this.totalExp, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getExpBar() {
|
||||||
|
return this.expBar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getLevel() {
|
||||||
|
return this.level;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getTotalExp() {
|
||||||
|
return this.totalExp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setExpBar(float expBar) {
|
||||||
|
this.expBar = expBar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setLevel(int level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setTotalExp(int totalExp) {
|
||||||
|
this.totalExp = totalExp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
float var10000 = this.getExpBar();
|
||||||
|
return "SetExp(expBar=" + var10000 + ", level=" + this.getLevel() + ", totalExp=" + this.getTotalExp() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public SetExp() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public SetExp(float expBar, int level, int totalExp) {
|
||||||
|
this.expBar = expBar;
|
||||||
|
this.level = level;
|
||||||
|
this.totalExp = totalExp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof SetExp)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
SetExp other = (SetExp)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (Float.compare(this.getExpBar(), other.getExpBar()) != 0) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getLevel() != other.getLevel()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.getTotalExp() == other.getTotalExp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof SetExp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + Float.floatToIntBits(this.getExpBar());
|
||||||
|
result = result * 59 + this.getLevel();
|
||||||
|
result = result * 59 + this.getTotalExp();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,269 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import se.llbit.nbt.CompoundTag;
|
||||||
|
import se.llbit.nbt.IntTag;
|
||||||
|
import se.llbit.nbt.NamedTag;
|
||||||
|
import se.llbit.nbt.Tag;
|
||||||
|
|
||||||
|
public class SetSlot extends DefinedPacket {
|
||||||
|
private int windowId;
|
||||||
|
private int slot;
|
||||||
|
private int item;
|
||||||
|
private int count;
|
||||||
|
private int data;
|
||||||
|
|
||||||
|
public void write18(ByteBuf buf, ProtocolConstants.Direction direction, int version) {
|
||||||
|
buf.writeByte(this.windowId);
|
||||||
|
buf.writeShort(this.slot);
|
||||||
|
boolean isMap = this.item == 358;
|
||||||
|
int id = isMap ? this.getCaptchaId(version) : this.item;
|
||||||
|
boolean present = id > 0;
|
||||||
|
if (version >= 404) {
|
||||||
|
buf.writeBoolean(present);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!present && version < 404) {
|
||||||
|
buf.writeShort(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (present) {
|
||||||
|
if (version < 404) {
|
||||||
|
buf.writeShort(id);
|
||||||
|
buf.writeByte(this.count);
|
||||||
|
buf.writeShort(this.data);
|
||||||
|
buf.writeByte(0);
|
||||||
|
} else {
|
||||||
|
DefinedPacket.writeVarInt(id, buf);
|
||||||
|
buf.writeByte(this.count);
|
||||||
|
buf.writeShort(this.data);
|
||||||
|
buf.writeByte(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write117(ByteBuf buf, ProtocolConstants.Direction direction, int version) {
|
||||||
|
if (version >= 768) {
|
||||||
|
DefinedPacket.writeVarInt(this.windowId, buf);
|
||||||
|
} else {
|
||||||
|
buf.writeByte(this.windowId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version >= 756) {
|
||||||
|
DefinedPacket.writeVarInt(0, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.writeShort(this.slot);
|
||||||
|
boolean isMap = this.item == 358;
|
||||||
|
int id = isMap ? this.getCaptchaId(version) : this.item;
|
||||||
|
boolean present = id > 0;
|
||||||
|
if (version >= 404) {
|
||||||
|
if (version < 766) {
|
||||||
|
buf.writeBoolean(present);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!present && version >= 766) {
|
||||||
|
writeVarInt(0, buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!present && version < 404) {
|
||||||
|
buf.writeShort(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (present) {
|
||||||
|
if (version < 404) {
|
||||||
|
buf.writeShort(id);
|
||||||
|
} else if (version >= 766) {
|
||||||
|
DefinedPacket.writeVarInt(this.count, buf);
|
||||||
|
DefinedPacket.writeVarInt(id, buf);
|
||||||
|
} else {
|
||||||
|
DefinedPacket.writeVarInt(id, buf);
|
||||||
|
buf.writeByte(this.count);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version < 393) {
|
||||||
|
buf.writeShort(this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version < 755) {
|
||||||
|
buf.writeByte(0);
|
||||||
|
} else if (version < 766) {
|
||||||
|
CompoundTag nbt = new CompoundTag();
|
||||||
|
nbt.add("map", new IntTag(0));
|
||||||
|
Tag write = (Tag)(version >= 764 ? nbt : new NamedTag("", nbt));
|
||||||
|
DefinedPacket.writeTag(write, buf, version);
|
||||||
|
} else if (isMap) {
|
||||||
|
DefinedPacket.writeVarInt(1, buf);
|
||||||
|
DefinedPacket.writeVarInt(0, buf);
|
||||||
|
if (version < 768) {
|
||||||
|
DefinedPacket.writeVarInt(26, buf);
|
||||||
|
} else {
|
||||||
|
DefinedPacket.writeVarInt(36, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefinedPacket.writeVarInt(0, buf);
|
||||||
|
} else {
|
||||||
|
DefinedPacket.writeVarInt(0, buf);
|
||||||
|
DefinedPacket.writeVarInt(0, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int version) {
|
||||||
|
if (version >= 393) {
|
||||||
|
this.write117(buf, direction, version);
|
||||||
|
} else {
|
||||||
|
this.write18(buf, direction, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCaptchaId(int version) {
|
||||||
|
if (version <= 340) {
|
||||||
|
return 358;
|
||||||
|
} else if (version == 393) {
|
||||||
|
return 608;
|
||||||
|
} else if (version <= 404) {
|
||||||
|
return 613;
|
||||||
|
} else if (version <= 578) {
|
||||||
|
return 671;
|
||||||
|
} else if (version <= 754) {
|
||||||
|
return 733;
|
||||||
|
} else if (version <= 758) {
|
||||||
|
return 847;
|
||||||
|
} else if (version <= 760) {
|
||||||
|
return 886;
|
||||||
|
} else if (version <= 761) {
|
||||||
|
return 914;
|
||||||
|
} else if (version <= 762) {
|
||||||
|
return 937;
|
||||||
|
} else if (version <= 764) {
|
||||||
|
return 941;
|
||||||
|
} else if (version <= 765) {
|
||||||
|
return 979;
|
||||||
|
} else {
|
||||||
|
return version <= 768 ? 982 : 1031;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getWindowId() {
|
||||||
|
return this.windowId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getSlot() {
|
||||||
|
return this.slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getItem() {
|
||||||
|
return this.item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getCount() {
|
||||||
|
return this.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getData() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setWindowId(int windowId) {
|
||||||
|
this.windowId = windowId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setSlot(int slot) {
|
||||||
|
this.slot = slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setItem(int item) {
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setData(int data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
int var10000 = this.getWindowId();
|
||||||
|
return "SetSlot(windowId=" + var10000 + ", slot=" + this.getSlot() + ", item=" + this.getItem() + ", count=" + this.getCount() + ", data=" + this.getData() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public SetSlot() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public SetSlot(int windowId, int slot, int item, int count, int data) {
|
||||||
|
this.windowId = windowId;
|
||||||
|
this.slot = slot;
|
||||||
|
this.item = item;
|
||||||
|
this.count = count;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof SetSlot)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
SetSlot other = (SetSlot)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getWindowId() != other.getWindowId()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getSlot() != other.getSlot()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getItem() != other.getItem()) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getCount() != other.getCount()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.getData() == other.getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof SetSlot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + this.getWindowId();
|
||||||
|
result = result * 59 + this.getSlot();
|
||||||
|
result = result * 59 + this.getItem();
|
||||||
|
result = result * 59 + this.getCount();
|
||||||
|
result = result * 59 + this.getData();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class TeleportConfirm extends DefinedPacket {
|
||||||
|
int teleportId;
|
||||||
|
|
||||||
|
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
this.teleportId = DefinedPacket.readVarInt(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
handler.handle(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getTeleportId() {
|
||||||
|
return this.teleportId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setTeleportId(int teleportId) {
|
||||||
|
this.teleportId = teleportId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
return "TeleportConfirm(teleportId=" + this.getTeleportId() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public TeleportConfirm() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public TeleportConfirm(int teleportId) {
|
||||||
|
this.teleportId = teleportId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof TeleportConfirm)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
TeleportConfirm other = (TeleportConfirm)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.getTeleportId() == other.getTeleportId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof TeleportConfirm;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
result = result * 59 + this.getTeleportId();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package dev._2lstudios.flamecord.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Generated;
|
||||||
|
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
|
||||||
|
public class TimeUpdate extends DefinedPacket {
|
||||||
|
long age;
|
||||||
|
long time;
|
||||||
|
|
||||||
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
|
buf.writeLong(this.age);
|
||||||
|
buf.writeLong(this.time);
|
||||||
|
if (protocolVersion >= 768) {
|
||||||
|
buf.writeBoolean(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public long getAge() {
|
||||||
|
return this.age;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public long getTime() {
|
||||||
|
return this.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setAge(long age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public void setTime(long time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String toString() {
|
||||||
|
long var10000 = this.getAge();
|
||||||
|
return "TimeUpdate(age=" + var10000 + ", time=" + this.getTime() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public TimeUpdate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public TimeUpdate(long age, long time) {
|
||||||
|
this.age = age;
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof TimeUpdate)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
TimeUpdate other = (TimeUpdate)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else if (this.getAge() != other.getAge()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return this.getTime() == other.getTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof TimeUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int hashCode() {
|
||||||
|
int PRIME = 59;
|
||||||
|
int result = 1;
|
||||||
|
long $age = this.getAge();
|
||||||
|
result = result * 59 + (int)($age >>> 32 ^ $age);
|
||||||
|
long $time = this.getTime();
|
||||||
|
result = result * 59 + (int)($time >>> 32 ^ $time);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package dev._2lstudios.flamecord.tasks;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.BlockedPlayersNotifier;
|
||||||
|
import dev._2lstudios.flamecord.antibot.StatsData;
|
||||||
|
import dev._2lstudios.flamecord.commands.FlameCordStatsCommand;
|
||||||
|
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
public class StatsTask implements Runnable {
|
||||||
|
private FlameCordStatsCommand flameCordStatsCommand;
|
||||||
|
private StatsData statsData;
|
||||||
|
private MessagesConfiguration messagesConfiguration;
|
||||||
|
|
||||||
|
public StatsTask(FlameCordStatsCommand flameCordStatsCommand, StatsData statsData, MessagesConfiguration messagesConfiguration) {
|
||||||
|
this.flameCordStatsCommand = flameCordStatsCommand;
|
||||||
|
this.statsData = statsData;
|
||||||
|
this.messagesConfiguration = messagesConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
while(!Thread.interrupted()) {
|
||||||
|
BlockedPlayersNotifier.Summary summary = FlameCord.getInstance().getBlockedPlayersNotifier().drainReadySummary();
|
||||||
|
boolean blockedActionbarEnabled = FlameCord.getInstance().getFlameCordConfiguration().isAntibotBlockedActionbarEnabled();
|
||||||
|
Collection<ProxiedPlayer> notifyPlayers = new HashSet();
|
||||||
|
if (blockedActionbarEnabled) {
|
||||||
|
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||||
|
if (player.hasPermission("flamecord.notify")) {
|
||||||
|
notifyPlayers.add(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockedActionbarEnabled && summary != null && !notifyPlayers.isEmpty()) {
|
||||||
|
String message;
|
||||||
|
if (summary.isSingle()) {
|
||||||
|
message = this.messagesConfiguration.getTranslation("antibot_notify_blocked_single", summary.getSingleSubject());
|
||||||
|
} else {
|
||||||
|
message = this.messagesConfiguration.getTranslation("antibot_notify_blocked_multiple", summary.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseComponent[] actionMessage = TextComponent.fromLegacyText(message);
|
||||||
|
|
||||||
|
for(ProxiedPlayer player : notifyPlayers) {
|
||||||
|
player.sendMessage(ChatMessageType.ACTION_BAR, actionMessage);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(ProxiedPlayer proxiedPlayer : this.flameCordStatsCommand.getShowStats()) {
|
||||||
|
if (!notifyPlayers.contains(proxiedPlayer)) {
|
||||||
|
int currentPings = this.statsData.getCurrentPings();
|
||||||
|
int currentConnections = this.statsData.getCurrentConnections();
|
||||||
|
int totalFirewalled = this.statsData.getTotalFirewalled();
|
||||||
|
BaseComponent[] actionMessage = TextComponent.fromLegacyText(this.messagesConfiguration.getTranslation("antibot_stats_actionbar", currentPings, currentConnections, totalFirewalled));
|
||||||
|
proxiedPlayer.sendMessage(ChatMessageType.ACTION_BAR, actionMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(200L);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
package dev._2lstudios.flamecord.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public final class FirewallCommandQueue {
|
||||||
|
private static final int CLEANUP_COMMAND_COUNT = 4;
|
||||||
|
private static final long DEFAULT_COMMAND_TIMEOUT_MS = 30000L;
|
||||||
|
private final Logger logger;
|
||||||
|
private final Runner runner;
|
||||||
|
private final long commandTimeoutMs;
|
||||||
|
private final BlockingQueue<List<String>> queue;
|
||||||
|
private final Object lifecycle;
|
||||||
|
private volatile Thread worker;
|
||||||
|
private boolean shutdown;
|
||||||
|
private boolean inFlight;
|
||||||
|
private boolean loggedEnabled;
|
||||||
|
|
||||||
|
private static Runner processRunner(long timeoutMs) {
|
||||||
|
return (command) -> {
|
||||||
|
Process process = (new ProcessBuilder(command)).redirectOutput(Redirect.DISCARD).redirectError(Redirect.DISCARD).start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!process.waitFor(timeoutMs, TimeUnit.MILLISECONDS)) {
|
||||||
|
process.destroyForcibly();
|
||||||
|
throw new IOException("Command timed out: " + (String)command.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.exitValue() != 0) {
|
||||||
|
String var10002 = (String)command.get(0);
|
||||||
|
throw new IOException("Command failed: " + var10002 + " (exit " + process.exitValue() + ")");
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
process.destroyForcibly();
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new IOException("Command interrupted: " + (String)command.get(0), e);
|
||||||
|
} finally {
|
||||||
|
process.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public FirewallCommandQueue(Logger logger) {
|
||||||
|
this(logger, processRunner(30000L), 256, 30000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
FirewallCommandQueue(Logger logger, Runner runner, int capacity, long commandTimeoutMs) {
|
||||||
|
this.lifecycle = new Object();
|
||||||
|
this.logger = logger;
|
||||||
|
this.runner = runner;
|
||||||
|
this.commandTimeoutMs = commandTimeoutMs;
|
||||||
|
this.queue = new LinkedBlockingQueue(Math.max(capacity, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
synchronized (this.lifecycle) {
|
||||||
|
if (this.worker != null || this.shutdown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Thread thread = new Thread(this::work, "FlameCord-Firewall-Commands");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
this.worker = thread;
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enqueue(String... command) {
|
||||||
|
return this.enqueue(Arrays.asList(command));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enqueue(List<String> command) {
|
||||||
|
List<String> copy = Collections.unmodifiableList(new ArrayList(command));
|
||||||
|
synchronized(this.lifecycle) {
|
||||||
|
if (!this.shutdown && this.queue.offer(copy)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (!this.shutdown) {
|
||||||
|
this.logger.warning("Firewall command queue is full; dropping command.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shutdown(List<List<String>> cleanup) {
|
||||||
|
boolean startDrain = false;
|
||||||
|
boolean dropped = false;
|
||||||
|
Thread thread;
|
||||||
|
synchronized(this.lifecycle) {
|
||||||
|
if (!this.shutdown) {
|
||||||
|
this.shutdown = true;
|
||||||
|
this.queue.clear();
|
||||||
|
|
||||||
|
for(List<String> command : cleanup) {
|
||||||
|
List<String> copy = Collections.unmodifiableList(new ArrayList(command));
|
||||||
|
if (!this.queue.offer(copy)) {
|
||||||
|
this.logger.severe("Firewall cleanup command dropped: " + (String)command.get(0));
|
||||||
|
dropped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thread = this.worker;
|
||||||
|
if (thread == null && !this.queue.isEmpty()) {
|
||||||
|
Thread drain = new Thread(this::work, "FlameCord-Firewall-Cleanup");
|
||||||
|
drain.setDaemon(true);
|
||||||
|
this.worker = drain;
|
||||||
|
thread = drain;
|
||||||
|
startDrain = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDrain) {
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean drained = !dropped;
|
||||||
|
if (thread != null) {
|
||||||
|
long budgetMs = Math.max(1000L, (long)cleanup.size() * (this.commandTimeoutMs + 250L) + 500L);
|
||||||
|
|
||||||
|
try {
|
||||||
|
thread.join(budgetMs);
|
||||||
|
} catch (InterruptedException var10) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
drained = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thread.isAlive()) {
|
||||||
|
this.logger.severe("Firewall command worker did not finish within " + budgetMs + " ms; cleanup may be incomplete.");
|
||||||
|
drained = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return drained;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean awaitDrained(long timeoutMs) {
|
||||||
|
long deadline = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeoutMs);
|
||||||
|
|
||||||
|
while(System.nanoTime() < deadline) {
|
||||||
|
synchronized(this.lifecycle) {
|
||||||
|
if (this.queue.isEmpty() && !this.inFlight) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1L);
|
||||||
|
} catch (InterruptedException var7) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void work() {
|
||||||
|
while(true) {
|
||||||
|
List<String> command;
|
||||||
|
synchronized(this.lifecycle) {
|
||||||
|
if (this.shutdown && this.queue.isEmpty() && !this.inFlight) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
command = (List)this.queue.poll();
|
||||||
|
if (command != null) {
|
||||||
|
this.inFlight = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command == null) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1L);
|
||||||
|
} catch (InterruptedException var17) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
this.runner.run(command);
|
||||||
|
if (!this.loggedEnabled) {
|
||||||
|
this.loggedEnabled = true;
|
||||||
|
this.logger.info("IPSet command execution is enabled.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.logger.warning("IPSet command failed: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
synchronized(this.lifecycle) {
|
||||||
|
this.inFlight = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Runner {
|
||||||
|
void run(List<String> var1) throws Exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package dev._2lstudios.flamecord.utils;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.utils.iridiumcolorapi.IridiumColorAPI;
|
||||||
|
import java.util.List;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
|
public class ColorUtil {
|
||||||
|
public static String color(String text) {
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> color(List<String> texts) {
|
||||||
|
for(int i = 0; i < texts.size(); ++i) {
|
||||||
|
texts.set(i, color((String)texts.get(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return texts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String hex(String text, int protocol) {
|
||||||
|
return text == null ? text : IridiumColorAPI.process(text, protocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String hexColor(String text, int protocol) {
|
||||||
|
if (text != null) {
|
||||||
|
text = color(text);
|
||||||
|
if (text != null) {
|
||||||
|
text = hex(text, protocol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> hexColor(List<String> texts, int protocol) {
|
||||||
|
for(int i = 0; i < texts.size(); ++i) {
|
||||||
|
texts.set(i, hexColor((String)texts.get(i), protocol));
|
||||||
|
}
|
||||||
|
|
||||||
|
return texts;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package dev._2lstudios.flamecord.utils;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class ConcurrentHashSet<E> implements Iterable<E> {
|
||||||
|
private final ConcurrentHashMap<E, Boolean> map = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
public boolean add(E element) {
|
||||||
|
return this.map.putIfAbsent(element, Boolean.TRUE) == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(E element) {
|
||||||
|
return this.map.containsKey(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean remove(E element) {
|
||||||
|
return this.map.remove(element) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.map.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator<E> iterator() {
|
||||||
|
return this.map.keySet().iterator();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,580 @@
|
|||||||
|
package dev._2lstudios.flamecord.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
import lombok.Generated;
|
||||||
|
import se.llbit.nbt.ByteTag;
|
||||||
|
import se.llbit.nbt.CompoundTag;
|
||||||
|
import se.llbit.nbt.DoubleTag;
|
||||||
|
import se.llbit.nbt.FloatTag;
|
||||||
|
import se.llbit.nbt.IntTag;
|
||||||
|
import se.llbit.nbt.ListTag;
|
||||||
|
import se.llbit.nbt.LongTag;
|
||||||
|
import se.llbit.nbt.NamedTag;
|
||||||
|
import se.llbit.nbt.SpecificTag;
|
||||||
|
import se.llbit.nbt.StringTag;
|
||||||
|
import se.llbit.nbt.Tag;
|
||||||
|
|
||||||
|
public class Dimension {
|
||||||
|
static CompoundTag damageType;
|
||||||
|
static CompoundTag damageType1_20;
|
||||||
|
static CompoundTag damageType1_21;
|
||||||
|
static CompoundTag damageType1_21_2;
|
||||||
|
public static Dimension OVERWORLD;
|
||||||
|
public static Dimension THE_NETHER;
|
||||||
|
public static Dimension THE_END;
|
||||||
|
private final String key;
|
||||||
|
private final int dimensionId;
|
||||||
|
private final int id;
|
||||||
|
private final boolean piglinSafe;
|
||||||
|
private final boolean natural;
|
||||||
|
private final float ambientLight;
|
||||||
|
private final String infiniburn;
|
||||||
|
private final boolean respawnAnchorWorks;
|
||||||
|
private final boolean hasSkylight;
|
||||||
|
private final boolean bedWorks;
|
||||||
|
private final String effects;
|
||||||
|
private final boolean hasRaids;
|
||||||
|
private final int monster_spawn_light_level;
|
||||||
|
private final int monster_spawn_block_light_limit;
|
||||||
|
private final int logicalHeight;
|
||||||
|
private final float coordinateScale;
|
||||||
|
private final boolean ultrawarm;
|
||||||
|
private final boolean hasCeiling;
|
||||||
|
private final int minY;
|
||||||
|
private final int height;
|
||||||
|
private final List<Biome> biomes;
|
||||||
|
|
||||||
|
private static void appendElementsDamageType(CompoundTag compoundTag, int version) {
|
||||||
|
ListTag list = compoundTag.get("value").asList();
|
||||||
|
CompoundTag campfire = new CompoundTag();
|
||||||
|
campfire.add("name", new StringTag("minecraft:campfire"));
|
||||||
|
campfire.add("id", new IntTag(44));
|
||||||
|
CompoundTag campfireData = new CompoundTag();
|
||||||
|
campfireData.add("scaling", new StringTag("when_caused_by_living_non_player"));
|
||||||
|
campfireData.add("message_id", new StringTag("inFire"));
|
||||||
|
campfireData.add("exhaustion", new FloatTag(0.1F));
|
||||||
|
campfire.add("element", campfireData);
|
||||||
|
list.add(campfire);
|
||||||
|
if (version >= 768) {
|
||||||
|
CompoundTag enderpearl = new CompoundTag();
|
||||||
|
enderpearl.add("name", new StringTag("minecraft:ender_pearl"));
|
||||||
|
enderpearl.add("id", new IntTag(45));
|
||||||
|
CompoundTag maceSmash = new CompoundTag();
|
||||||
|
maceSmash.add("name", new StringTag("minecraft:mace_smash"));
|
||||||
|
maceSmash.add("id", new IntTag(46));
|
||||||
|
CompoundTag enderpearlData = new CompoundTag();
|
||||||
|
enderpearlData.add("scaling", new StringTag("when_caused_by_living_non_player"));
|
||||||
|
enderpearlData.add("message_id", new StringTag("fall"));
|
||||||
|
enderpearlData.add("exhaustion", new FloatTag(0.0F));
|
||||||
|
CompoundTag maceSmashData = new CompoundTag();
|
||||||
|
maceSmashData.add("scaling", new StringTag("when_caused_by_living_non_player"));
|
||||||
|
maceSmashData.add("message_id", new StringTag("mace_smash"));
|
||||||
|
maceSmashData.add("exhaustion", new FloatTag(0.1F));
|
||||||
|
enderpearl.add("element", enderpearlData);
|
||||||
|
maceSmash.add("element", maceSmashData);
|
||||||
|
list.add(enderpearl);
|
||||||
|
list.add(maceSmash);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag getFullCodec(int protocolVersion) {
|
||||||
|
try {
|
||||||
|
CompoundTag attributes = this.encodeAttributes(protocolVersion);
|
||||||
|
if (protocolVersion <= 736) {
|
||||||
|
CompoundTag dimensions = new CompoundTag();
|
||||||
|
dimensions.add("dimension", new ListTag(10, Collections.singletonList(attributes)));
|
||||||
|
return new NamedTag("", dimensions);
|
||||||
|
} else {
|
||||||
|
CompoundTag dimensionData = new CompoundTag();
|
||||||
|
dimensionData.add("name", new StringTag(this.key));
|
||||||
|
dimensionData.add("id", new IntTag(this.id));
|
||||||
|
dimensionData.add("element", attributes);
|
||||||
|
CompoundTag dimensions = new CompoundTag();
|
||||||
|
dimensions.add("type", new StringTag("minecraft:dimension_type"));
|
||||||
|
dimensions.add("value", new ListTag(10, Collections.singletonList(dimensionData)));
|
||||||
|
CompoundTag root = new CompoundTag();
|
||||||
|
root.add("minecraft:dimension_type", dimensions);
|
||||||
|
root.add("minecraft:worldgen/biome", this.createBiomeRegistry());
|
||||||
|
if (protocolVersion >= 762) {
|
||||||
|
CompoundTag damage = protocolVersion >= 763 ? damageType1_20 : damageType;
|
||||||
|
if (protocolVersion == 767) {
|
||||||
|
damage = damageType1_21;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 768) {
|
||||||
|
damage = damageType1_21_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
root.add("minecraft:damage_type", damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 759) {
|
||||||
|
root.add("minecraft:chat_type", this.createChatRegistry(protocolVersion));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 767) {
|
||||||
|
root.add("minecraft:painting_variant", this.createPaintingVariant(protocolVersion));
|
||||||
|
root.add("minecraft:wolf_variant", this.createWoldVariant(protocolVersion));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Tag)(protocolVersion >= 764 ? root : new NamedTag("", root));
|
||||||
|
}
|
||||||
|
} catch (Throwable $ex) {
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag getAttributes(int protocolVersion) {
|
||||||
|
return new NamedTag("", this.encodeAttributes(protocolVersion));
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompoundTag encodeAttributes(int protocolVersion) {
|
||||||
|
Map<String, SpecificTag> attributes = new HashMap();
|
||||||
|
attributes.put("name", new StringTag(this.key));
|
||||||
|
attributes.put("natural", new ByteTag(this.natural ? 1 : 0));
|
||||||
|
attributes.put("has_skylight", new ByteTag(this.hasSkylight ? 1 : 0));
|
||||||
|
attributes.put("has_ceiling", new ByteTag(this.hasCeiling ? 1 : 0));
|
||||||
|
attributes.put("fixed_time", new LongTag(10000L));
|
||||||
|
attributes.put("shrunk", new ByteTag(0));
|
||||||
|
attributes.put("ambient_light", new FloatTag(this.ambientLight));
|
||||||
|
attributes.put("ultrawarm", new ByteTag(this.ultrawarm ? 1 : 0));
|
||||||
|
attributes.put("has_raids", new ByteTag(this.hasRaids ? 1 : 0));
|
||||||
|
attributes.put("respawn_anchor_works", new ByteTag(this.respawnAnchorWorks ? 1 : 0));
|
||||||
|
attributes.put("bed_works", new ByteTag(this.bedWorks ? 1 : 0));
|
||||||
|
attributes.put("piglin_safe", new ByteTag(this.piglinSafe ? 1 : 0));
|
||||||
|
attributes.put("infiniburn", new StringTag(this.infiniburn));
|
||||||
|
attributes.put("logical_height", new ByteTag(this.logicalHeight));
|
||||||
|
if (protocolVersion >= 751) {
|
||||||
|
attributes.remove("name");
|
||||||
|
attributes.remove("fixed_time");
|
||||||
|
attributes.remove("shrunk");
|
||||||
|
attributes.put("effects", new StringTag(this.effects));
|
||||||
|
attributes.put("coordinate_scale", new FloatTag(this.coordinateScale));
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes.put("height", new IntTag(this.height));
|
||||||
|
attributes.put("min_y", new IntTag(this.minY));
|
||||||
|
if (protocolVersion >= 758) {
|
||||||
|
attributes.put("infiniburn", new StringTag("#" + this.infiniburn));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocolVersion >= 759) {
|
||||||
|
attributes.put("monster_spawn_light_level", new IntTag(this.monster_spawn_light_level));
|
||||||
|
attributes.put("monster_spawn_block_light_limit", new IntTag(this.monster_spawn_block_light_limit));
|
||||||
|
}
|
||||||
|
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
|
||||||
|
for(Map.Entry<String, SpecificTag> entry : attributes.entrySet()) {
|
||||||
|
tag.add((String)entry.getKey(), (SpecificTag)entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompoundTag createBiomeRegistry() {
|
||||||
|
CompoundTag root = new CompoundTag();
|
||||||
|
root.add("type", new StringTag("minecraft:worldgen/biome"));
|
||||||
|
List<CompoundTag> biomes = new ArrayList();
|
||||||
|
|
||||||
|
for(Biome biome : this.biomes) {
|
||||||
|
biomes.add(this.encodeBiome(biome));
|
||||||
|
}
|
||||||
|
|
||||||
|
root.add("value", new ListTag(10, biomes));
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompoundTag createChatRegistry(int version) {
|
||||||
|
CompoundTag root = new CompoundTag();
|
||||||
|
root.add("type", new StringTag("minecraft:chat_type"));
|
||||||
|
CompoundTag systemChat = new CompoundTag();
|
||||||
|
systemChat.add("name", new StringTag("minecraft:system"));
|
||||||
|
systemChat.add("id", new IntTag(1));
|
||||||
|
CompoundTag element = new CompoundTag();
|
||||||
|
CompoundTag chat = new CompoundTag();
|
||||||
|
if (version >= 760) {
|
||||||
|
chat.add("style", new CompoundTag());
|
||||||
|
chat.add("translation_key", new StringTag("chat.type.system"));
|
||||||
|
chat.add("parameters", new ListTag(8, Arrays.asList(new StringTag("sender"), new StringTag("content"))));
|
||||||
|
}
|
||||||
|
|
||||||
|
element.add("chat", chat);
|
||||||
|
CompoundTag narration = new CompoundTag();
|
||||||
|
if (version >= 760) {
|
||||||
|
narration.add("style", new CompoundTag());
|
||||||
|
narration.add("translation_key", new StringTag("chat.type.system.narrate"));
|
||||||
|
narration.add("parameters", new ListTag(8, Arrays.asList(new StringTag("sender"), new StringTag("content"))));
|
||||||
|
} else {
|
||||||
|
narration.add("priority", new StringTag("system"));
|
||||||
|
}
|
||||||
|
|
||||||
|
element.add("narration", narration);
|
||||||
|
systemChat.add("element", element);
|
||||||
|
root.add("value", new ListTag(10, Arrays.asList(systemChat)));
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompoundTag createPaintingVariant(int version) {
|
||||||
|
CompoundTag root = new CompoundTag();
|
||||||
|
root.add("type", new StringTag("minecraft:painting_variant"));
|
||||||
|
CompoundTag alban = new CompoundTag();
|
||||||
|
alban.add("name", new StringTag("minecraft:alban"));
|
||||||
|
alban.add("id", new IntTag(0));
|
||||||
|
CompoundTag paintingVariant = new CompoundTag();
|
||||||
|
paintingVariant.add("width", new IntTag(1));
|
||||||
|
paintingVariant.add("height", new IntTag(1));
|
||||||
|
paintingVariant.add("asset_id", new StringTag("minecraft:alban"));
|
||||||
|
alban.add("element", paintingVariant);
|
||||||
|
root.add("value", new ListTag(10, Arrays.asList(alban)));
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompoundTag createWoldVariant(int version) {
|
||||||
|
CompoundTag root = new CompoundTag();
|
||||||
|
root.add("type", new StringTag("minecraft:wolf_variant"));
|
||||||
|
CompoundTag ashen = new CompoundTag();
|
||||||
|
ashen.add("name", new StringTag("minecraft:ashen"));
|
||||||
|
ashen.add("id", new IntTag(0));
|
||||||
|
CompoundTag ashenProperties = new CompoundTag();
|
||||||
|
ashenProperties.add("wild_texture", new StringTag("minecraft:entity/wolf/wolf_ashen"));
|
||||||
|
ashenProperties.add("tame_texture", new StringTag("minecraft:entity/wolf/wolf_ashen_tame"));
|
||||||
|
ashenProperties.add("angry_texture", new StringTag("minecraft:entity/wolf/wolf_ashen_angry"));
|
||||||
|
ashenProperties.add("biomes", new ListTag(8, Arrays.asList(new StringTag("minecraft:plains"))));
|
||||||
|
ashen.add("element", ashenProperties);
|
||||||
|
root.add("value", new ListTag(10, Arrays.asList(ashen)));
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompoundTag encodeBiome(Biome biome) {
|
||||||
|
CompoundTag biomeTag = new CompoundTag();
|
||||||
|
biomeTag.add("name", new StringTag(biome.getName()));
|
||||||
|
biomeTag.add("id", new IntTag(biome.getId()));
|
||||||
|
CompoundTag element = new CompoundTag();
|
||||||
|
element.add("precipitation", new StringTag(biome.getPrecipitation()));
|
||||||
|
element.add("has_precipitation", new ByteTag(biome.getPrecipitation().equals("none") ? 0 : 1));
|
||||||
|
element.add("depth", new FloatTag(biome.getDepth()));
|
||||||
|
element.add("temperature", new FloatTag(biome.getTemperature()));
|
||||||
|
element.add("scale", new FloatTag(biome.getScale()));
|
||||||
|
element.add("downfall", new FloatTag(biome.getDownfall()));
|
||||||
|
element.add("category", new StringTag(biome.getCategory()));
|
||||||
|
CompoundTag effects = new CompoundTag();
|
||||||
|
effects.add("sky_color", new IntTag(biome.getSky_color()));
|
||||||
|
effects.add("water_fog_color", new IntTag(biome.getWater_color()));
|
||||||
|
effects.add("fog_color", new IntTag(biome.getFog_color()));
|
||||||
|
effects.add("water_color", new IntTag(biome.getWater_color()));
|
||||||
|
if (biome.getGrass_color_modiefer() != null) {
|
||||||
|
effects.add("grass_color_modifier", new StringTag(biome.getGrass_color_modiefer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (biome.getFoliage_color() != Integer.MIN_VALUE) {
|
||||||
|
effects.add("foliage_color", new IntTag(biome.getFoliage_color()));
|
||||||
|
}
|
||||||
|
|
||||||
|
CompoundTag moodSound = new CompoundTag();
|
||||||
|
moodSound.add("tick_delay", new IntTag(biome.getTick_delay()));
|
||||||
|
moodSound.add("offset", new DoubleTag(biome.getOffset()));
|
||||||
|
moodSound.add("block_search_extent", new IntTag(biome.getBlock_search_extent()));
|
||||||
|
moodSound.add("sound", new StringTag(biome.getSound()));
|
||||||
|
effects.add("mood_sound", moodSound);
|
||||||
|
element.add("effects", effects);
|
||||||
|
biomeTag.add("element", element);
|
||||||
|
return biomeTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public Dimension(String key, int dimensionId, int id, boolean piglinSafe, boolean natural, float ambientLight, String infiniburn, boolean respawnAnchorWorks, boolean hasSkylight, boolean bedWorks, String effects, boolean hasRaids, int monster_spawn_light_level, int monster_spawn_block_light_limit, int logicalHeight, float coordinateScale, boolean ultrawarm, boolean hasCeiling, int minY, int height, List<Biome> biomes) {
|
||||||
|
this.key = key;
|
||||||
|
this.dimensionId = dimensionId;
|
||||||
|
this.id = id;
|
||||||
|
this.piglinSafe = piglinSafe;
|
||||||
|
this.natural = natural;
|
||||||
|
this.ambientLight = ambientLight;
|
||||||
|
this.infiniburn = infiniburn;
|
||||||
|
this.respawnAnchorWorks = respawnAnchorWorks;
|
||||||
|
this.hasSkylight = hasSkylight;
|
||||||
|
this.bedWorks = bedWorks;
|
||||||
|
this.effects = effects;
|
||||||
|
this.hasRaids = hasRaids;
|
||||||
|
this.monster_spawn_light_level = monster_spawn_light_level;
|
||||||
|
this.monster_spawn_block_light_limit = monster_spawn_block_light_limit;
|
||||||
|
this.logicalHeight = logicalHeight;
|
||||||
|
this.coordinateScale = coordinateScale;
|
||||||
|
this.ultrawarm = ultrawarm;
|
||||||
|
this.hasCeiling = hasCeiling;
|
||||||
|
this.minY = minY;
|
||||||
|
this.height = height;
|
||||||
|
this.biomes = biomes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getKey() {
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getDimensionId() {
|
||||||
|
return this.dimensionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isPiglinSafe() {
|
||||||
|
return this.piglinSafe;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isNatural() {
|
||||||
|
return this.natural;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getAmbientLight() {
|
||||||
|
return this.ambientLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getInfiniburn() {
|
||||||
|
return this.infiniburn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isRespawnAnchorWorks() {
|
||||||
|
return this.respawnAnchorWorks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isHasSkylight() {
|
||||||
|
return this.hasSkylight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isBedWorks() {
|
||||||
|
return this.bedWorks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getEffects() {
|
||||||
|
return this.effects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isHasRaids() {
|
||||||
|
return this.hasRaids;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getMonster_spawn_light_level() {
|
||||||
|
return this.monster_spawn_light_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getMonster_spawn_block_light_limit() {
|
||||||
|
return this.monster_spawn_block_light_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getLogicalHeight() {
|
||||||
|
return this.logicalHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getCoordinateScale() {
|
||||||
|
return this.coordinateScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isUltrawarm() {
|
||||||
|
return this.ultrawarm;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public boolean isHasCeiling() {
|
||||||
|
return this.hasCeiling;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getMinY() {
|
||||||
|
return this.minY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getHeight() {
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public List<Biome> getBiomes() {
|
||||||
|
return this.biomes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
damageType = (CompoundTag)CompoundTag.read(new DataInputStream(new BufferedInputStream(new GZIPInputStream(Dimension.class.getResourceAsStream("/damage-types-1.19.4.nbt"))))).get("");
|
||||||
|
damageType1_20 = (CompoundTag)CompoundTag.read(new DataInputStream(new BufferedInputStream(new GZIPInputStream(Dimension.class.getResourceAsStream("/damage-types-1.20.nbt"))))).get("");
|
||||||
|
damageType1_21 = (CompoundTag)CompoundTag.read(new DataInputStream(new BufferedInputStream(new GZIPInputStream(Dimension.class.getResourceAsStream("/damage-types-1.20.nbt"))))).get("");
|
||||||
|
damageType1_21_2 = (CompoundTag)CompoundTag.read(new DataInputStream(new BufferedInputStream(new GZIPInputStream(Dimension.class.getResourceAsStream("/damage-types-1.20.nbt"))))).get("");
|
||||||
|
appendElementsDamageType(damageType1_21, 767);
|
||||||
|
appendElementsDamageType(damageType1_21_2, 768);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
OVERWORLD = new Dimension("minecraft:overworld", 0, 0, false, true, 0.0F, "minecraft:infiniburn_overworld", false, true, true, "minecraft:overworld", true, 0, 0, 256, 1.0F, false, false, 0, 256, Arrays.asList(Dimension.Biome.PLAINS, Dimension.Biome.SWAMP, Dimension.Biome.SWAMP_HILLS));
|
||||||
|
THE_NETHER = new Dimension("minecraft:the_nether", -1, 1, false, true, 0.0F, "minecraft:infiniburn_nether", false, true, true, "minecraft:the_nether", true, 0, 0, 256, 1.0F, false, false, 0, 256, Arrays.asList(Dimension.Biome.NETHER_WASTES));
|
||||||
|
THE_END = new Dimension("minecraft:the_end", 1, 2, false, true, 0.0F, "minecraft:infiniburn_end", false, true, true, "minecraft:the_end", true, 0, 0, 256, 1.0F, false, false, 0, 256, Arrays.asList(Dimension.Biome.THE_END));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum Biome {
|
||||||
|
PLAINS("minecraft:plains", 0, "rain", 0.125F, 0.8F, 0.05F, 0.4F, "plains", 7907327, 329011, 12638463, 4159204, 6000, (double)2.0F, 8, "minecraft:ambient.cave", (String)null, Integer.MIN_VALUE),
|
||||||
|
SWAMP("minecraft:swamp", 1, "rain", -0.2F, 0.8F, 0.1F, 0.9F, "swamp", 7907327, 2302743, 12638463, 6388580, 6000, (double)2.0F, 8, "minecraft:ambient.cave", "swamp", 6975545),
|
||||||
|
SWAMP_HILLS("minecraft:swamp_hills", 2, "rain", -0.1F, 0.8F, 0.3F, 0.9F, "swamp", 7907327, 2302743, 12638463, 6388580, 6000, (double)2.0F, 8, "minecraft:ambient.cave", "swamp", 6975545),
|
||||||
|
NETHER_WASTES("minecraft:nether_wastes", 3, "none", 0.1F, 2.0F, 0.2F, 0.0F, "nether", 7254527, 329011, 3344392, 4159204, 6000, (double)2.0F, 8, "minecraft:ambient.cave", "swamp", 6975545),
|
||||||
|
THE_END("minecraft:the_end", 4, "none", 0.1F, 0.5F, 0.2F, 0.5F, "the_end", 7907327, 10518688, 12638463, 4159204, 6000, (double)2.0F, 8, "minecraft:ambient.cave", "swamp", 6975545);
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final int id;
|
||||||
|
private final String precipitation;
|
||||||
|
private final float depth;
|
||||||
|
private final float temperature;
|
||||||
|
private final float scale;
|
||||||
|
private final float downfall;
|
||||||
|
private final String category;
|
||||||
|
private final int sky_color;
|
||||||
|
private final int water_fog_color;
|
||||||
|
private final int fog_color;
|
||||||
|
private final int water_color;
|
||||||
|
private final int tick_delay;
|
||||||
|
private final double offset;
|
||||||
|
private final int block_search_extent;
|
||||||
|
private final String sound;
|
||||||
|
private final String grass_color_modiefer;
|
||||||
|
private final int foliage_color;
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
private Biome(final String name, final int id, final String precipitation, final float depth, final float temperature, final float scale, final float downfall, final String category, final int sky_color, final int water_fog_color, final int fog_color, final int water_color, final int tick_delay, final double offset, final int block_search_extent, final String sound, final String grass_color_modiefer, final int foliage_color) {
|
||||||
|
this.name = name;
|
||||||
|
this.id = id;
|
||||||
|
this.precipitation = precipitation;
|
||||||
|
this.depth = depth;
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.scale = scale;
|
||||||
|
this.downfall = downfall;
|
||||||
|
this.category = category;
|
||||||
|
this.sky_color = sky_color;
|
||||||
|
this.water_fog_color = water_fog_color;
|
||||||
|
this.fog_color = fog_color;
|
||||||
|
this.water_color = water_color;
|
||||||
|
this.tick_delay = tick_delay;
|
||||||
|
this.offset = offset;
|
||||||
|
this.block_search_extent = block_search_extent;
|
||||||
|
this.sound = sound;
|
||||||
|
this.grass_color_modiefer = grass_color_modiefer;
|
||||||
|
this.foliage_color = foliage_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getPrecipitation() {
|
||||||
|
return this.precipitation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getDepth() {
|
||||||
|
return this.depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getTemperature() {
|
||||||
|
return this.temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getScale() {
|
||||||
|
return this.scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public float getDownfall() {
|
||||||
|
return this.downfall;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getCategory() {
|
||||||
|
return this.category;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getSky_color() {
|
||||||
|
return this.sky_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getWater_fog_color() {
|
||||||
|
return this.water_fog_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getFog_color() {
|
||||||
|
return this.fog_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getWater_color() {
|
||||||
|
return this.water_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getTick_delay() {
|
||||||
|
return this.tick_delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public double getOffset() {
|
||||||
|
return this.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getBlock_search_extent() {
|
||||||
|
return this.block_search_extent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getSound() {
|
||||||
|
return this.sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public String getGrass_color_modiefer() {
|
||||||
|
return this.grass_color_modiefer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated
|
||||||
|
public int getFoliage_color() {
|
||||||
|
return this.foliage_color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package dev._2lstudios.flamecord.utils;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import net.md_5.bungee.UserConnection;
|
||||||
|
import net.md_5.bungee.netty.ChannelWrapper;
|
||||||
|
|
||||||
|
public class IPUtils {
|
||||||
|
public static InetAddress getAddress(UserConnection userCon) {
|
||||||
|
return userCon.getAddress().getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InetAddress getAddress(ChannelWrapper wrapper) {
|
||||||
|
return ((InetSocketAddress)wrapper.getRemoteAddress()).getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InetAddress getAddress(String ip) {
|
||||||
|
try {
|
||||||
|
return InetAddress.getByName(ip);
|
||||||
|
} catch (UnknownHostException ex) {
|
||||||
|
BungeeCord.getInstance().getLogger().log(Level.WARNING, "[FlameCord] Could not get InetAddress for " + ip, ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,362 @@
|
|||||||
|
package dev._2lstudios.flamecord.utils;
|
||||||
|
|
||||||
|
import dev._2lstudios.flamecord.FlameCord;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedCaptcha;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedExpPackets;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedMessage;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedPacket;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedPacketType;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedRegistryData;
|
||||||
|
import dev._2lstudios.flamecord.antibot.cached.CachedTitle;
|
||||||
|
import dev._2lstudios.flamecord.packets.DefaultSpawnPosition;
|
||||||
|
import dev._2lstudios.flamecord.packets.EmptyChunkPacket;
|
||||||
|
import dev._2lstudios.flamecord.packets.JoinGame;
|
||||||
|
import dev._2lstudios.flamecord.packets.PlayerAbilities;
|
||||||
|
import dev._2lstudios.flamecord.packets.PlayerPositionAndLook;
|
||||||
|
import dev._2lstudios.flamecord.packets.SetExp;
|
||||||
|
import dev._2lstudios.flamecord.packets.SetSlot;
|
||||||
|
import dev._2lstudios.flamecord.packets.TimeUpdate;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.netty.ChannelWrapper;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import net.md_5.bungee.protocol.packet.FinishConfiguration;
|
||||||
|
import net.md_5.bungee.protocol.packet.GameState;
|
||||||
|
import net.md_5.bungee.protocol.packet.KeepAlive;
|
||||||
|
import net.md_5.bungee.protocol.packet.Kick;
|
||||||
|
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||||
|
|
||||||
|
public class PacketUtils {
|
||||||
|
public static final CachedCaptcha captchas = new CachedCaptcha();
|
||||||
|
public static final List<CachedPacket> chunksPackets = new ArrayList();
|
||||||
|
private static final Map<KickType, CachedPacket> kickMessagesGame = new HashMap(3);
|
||||||
|
private static final Map<KickType, CachedPacket> kickMessagesLogin = new HashMap(4);
|
||||||
|
private static final Map<Integer, CachedRegistryData> configurationRegistry = new HashMap();
|
||||||
|
public static int PROTOCOLS_COUNT;
|
||||||
|
public static int CLIENTID;
|
||||||
|
public static int KEEPALIVE_ID;
|
||||||
|
public static CachedExpPackets expPackets;
|
||||||
|
private static final Map<CachedPacketType, CachedPacket> cachedPackets;
|
||||||
|
public static final Map<CachedPacketType, CachedTitle> titles;
|
||||||
|
public static final Map<CachedPacketType, CachedMessage> messages;
|
||||||
|
private static int[] VERSION_REWRITE;
|
||||||
|
|
||||||
|
public static ByteBuf createPacket(DefinedPacket packet, Protocol protocol, int id, int protocolVersion) {
|
||||||
|
ByteBuf tempBuffer = ByteBufAllocator.DEFAULT.buffer();
|
||||||
|
DefinedPacket.writeVarInt(id, tempBuffer);
|
||||||
|
if (protocol == null) {
|
||||||
|
packet.write(tempBuffer, ProtocolConstants.Direction.TO_CLIENT, protocolVersion);
|
||||||
|
} else {
|
||||||
|
packet.write(tempBuffer, protocol, ProtocolConstants.Direction.TO_CLIENT, protocolVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] bytes = new byte[tempBuffer.readableBytes()];
|
||||||
|
tempBuffer.readBytes(bytes);
|
||||||
|
tempBuffer.release();
|
||||||
|
return ByteBufAllocator.DEFAULT.buffer().writeBytes(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ByteBuf createPacket(DefinedPacket packet, int id, int protocolVersion) {
|
||||||
|
return createPacket(packet, (Protocol)null, id, protocolVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void release() {
|
||||||
|
if (expPackets != null) {
|
||||||
|
expPackets.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CachedPacket packet : cachedPackets.values()) {
|
||||||
|
if (packet != null) {
|
||||||
|
packet.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CachedTitle title : titles.values()) {
|
||||||
|
if (title != null) {
|
||||||
|
title.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CachedPacket packet : kickMessagesGame.values()) {
|
||||||
|
packet.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CachedMessage message : messages.values()) {
|
||||||
|
if (message != null) {
|
||||||
|
message.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CachedRegistryData packets : configurationRegistry.values()) {
|
||||||
|
packets.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
captchas.releaseAndClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
Arrays.fill(VERSION_REWRITE, -1);
|
||||||
|
|
||||||
|
for (int i = 0; i < ProtocolConstants.SUPPORTED_VERSION_IDS.size(); i++) {
|
||||||
|
int version = ProtocolConstants.SUPPORTED_VERSION_IDS.get(i);
|
||||||
|
VERSION_REWRITE[version] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
release();
|
||||||
|
kickMessagesGame.clear();
|
||||||
|
expPackets = new CachedExpPackets();
|
||||||
|
titles.put(CachedPacketType.CHECK_IN_PROGRESS_TITLE, new CachedTitle(ProxyServer.getInstance().getTranslation("antibot_limbo_check_in_progress"), 5, 90, 15));
|
||||||
|
titles.put(CachedPacketType.ENTER_CAPTCHA_TITLE, new CachedTitle(ProxyServer.getInstance().getTranslation("antibot_limbo_enter_captcha"), 5, 35, 10));
|
||||||
|
titles.put(CachedPacketType.CHECK_COMPLETED_TYPE, new CachedTitle(ProxyServer.getInstance().getTranslation("antibot_limbo_check_completed"), 5, 20, 10));
|
||||||
|
int dimensionType = FlameCord.getInstance().getFlameCordConfiguration().getAntibotLimboDimension();
|
||||||
|
Dimension dimension = dimensionType == 2 ? Dimension.THE_END : (dimensionType == 1 ? Dimension.THE_NETHER : Dimension.OVERWORLD);
|
||||||
|
EnumMap<CachedPacketType, DefinedPacket> packets = new EnumMap(CachedPacketType.class);
|
||||||
|
packets.put(CachedPacketType.LOGIN, new JoinGame(CLIENTID, dimension));
|
||||||
|
packets.put(CachedPacketType.TIME, new TimeUpdate(1L, 23700L));
|
||||||
|
packets.put(CachedPacketType.PLAYERABILITIES, new PlayerAbilities((byte)6, 0.0F, 0.0F));
|
||||||
|
packets.put(CachedPacketType.PLAYERPOSANDLOOK_CAPTCHA, new PlayerPositionAndLook((double)7.0F, (double)120.0F, (double)7.0F, 90.0F, 38.0F, 9876, false));
|
||||||
|
packets.put(CachedPacketType.SETSLOT_MAP, new SetSlot(0, 36, 358, 1, 0));
|
||||||
|
packets.put(CachedPacketType.SETSLOT_RESET, new SetSlot(0, 36, -1, 0, 0));
|
||||||
|
packets.put(CachedPacketType.KEEPALIVE, new KeepAlive((long)KEEPALIVE_ID));
|
||||||
|
packets.put(CachedPacketType.PLAYERPOSANDLOOK, new PlayerPositionAndLook((double)7.0F, (double)120.0F, (double)7.0F, 90.0F, 10.0F, 9876, false));
|
||||||
|
packets.put(CachedPacketType.SETEXP_RESET, new SetExp(0.0F, 0, 0));
|
||||||
|
packets.put(CachedPacketType.BRAND, createBrand(false));
|
||||||
|
packets.put(CachedPacketType.BRAND_MODERN, createBrand(true));
|
||||||
|
packets.put(CachedPacketType.DEFAULT_SPAWN_POSITION, new DefaultSpawnPosition(7, 120, 7, 123.0F));
|
||||||
|
packets.put(CachedPacketType.FINISH_CONFIGURATION, new FinishConfiguration());
|
||||||
|
packets.put(CachedPacketType.GAME_STATE, new GameState((short)13, 0.0F));
|
||||||
|
|
||||||
|
for(Map.Entry<CachedPacketType, DefinedPacket> entry : packets.entrySet()) {
|
||||||
|
cachedPackets.put((CachedPacketType)entry.getKey(), new CachedPacket((DefinedPacket)entry.getValue(), new Protocol[]{Protocol.BOTFILTER, Protocol.BOTFILTER_CONFIGURATION, Protocol.GAME, Protocol.CONFIGURATION}));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int version : Arrays.asList(764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774)) {
|
||||||
|
configurationRegistry.put(version, new CachedRegistryData(dimension, version));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chunksPackets.isEmpty()) {
|
||||||
|
for(int x = -1; x <= 1; ++x) {
|
||||||
|
for(int z = -1; z <= 1; ++z) {
|
||||||
|
chunksPackets.add(new CachedPacket(new EmptyChunkPacket(x, z), new Protocol[]{Protocol.BOTFILTER}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
messages.put(CachedPacketType.CAPTCHA_FAILED_2_MSG, new CachedMessage(ProxyServer.getInstance().getTranslation("antibot_limbo_wrong_captcha")));
|
||||||
|
messages.put(CachedPacketType.CAPTCHA_FAILED_1_MSG, new CachedMessage(ProxyServer.getInstance().getTranslation("antibot_limbo_wrong_captcha")));
|
||||||
|
messages.put(CachedPacketType.CHECKING_MSG, new CachedMessage(ProxyServer.getInstance().getTranslation("antibot_limbo_wait_verification")));
|
||||||
|
messages.put(CachedPacketType.CHECKING_CAPTCHA_MSG, new CachedMessage(ProxyServer.getInstance().getTranslation("antibot_limbo_enter_number")));
|
||||||
|
messages.put(CachedPacketType.CHECK_SUS_MSG, new CachedMessage(ProxyServer.getInstance().getTranslation("antibot_limbo_verification_passed")));
|
||||||
|
Protocol kickGame = Protocol.GAME;
|
||||||
|
Protocol kickLogin = Protocol.LOGIN;
|
||||||
|
CachedPacket failedMessage = new CachedPacket(createKickPacket(ProxyServer.getInstance().getTranslation("antibot_limbo_kick")), new Protocol[]{kickGame});
|
||||||
|
kickMessagesGame.put(PacketUtils.KickType.PING, new CachedPacket(createKickPacket(ProxyServer.getInstance().getTranslation("antibot_limbo_high_latency")), new Protocol[]{kickGame}));
|
||||||
|
kickMessagesGame.put(PacketUtils.KickType.FAILED_CAPTCHA, failedMessage);
|
||||||
|
kickMessagesGame.put(PacketUtils.KickType.FAILED_FALLING, failedMessage);
|
||||||
|
kickMessagesGame.put(PacketUtils.KickType.TIMED_OUT, failedMessage);
|
||||||
|
kickMessagesGame.put(PacketUtils.KickType.BIG_PACKET, new CachedPacket(createKickPacket(ProxyServer.getInstance().getTranslation("antibot_limbo_too_big_packet")), new Protocol[]{kickGame}));
|
||||||
|
kickMessagesLogin.put(PacketUtils.KickType.PING, new CachedPacket(createKickPacket(String.join("", ProxyServer.getInstance().getTranslation("antibot_limbo_requires_ping"))), new Protocol[]{kickLogin}));
|
||||||
|
kickMessagesLogin.put(PacketUtils.KickType.MANYCHECKS, new CachedPacket(createKickPacket(ProxyServer.getInstance().getTranslation("antibot_limbo_too_many_checks")), new Protocol[]{kickLogin}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DefinedPacket createKickPacket(String message) {
|
||||||
|
return new Kick(TextComponent.fromLegacy(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PluginMessage createBrand(boolean modern) {
|
||||||
|
String var10000 = ProxyServer.getInstance().getName();
|
||||||
|
String text = var10000 + " (" + ProxyServer.getInstance().getVersion() + ")";
|
||||||
|
String channel = modern ? "minecraft:brand" : "MC|Brand";
|
||||||
|
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
|
||||||
|
DefinedPacket.writeString(text, brand);
|
||||||
|
PluginMessage packet = new PluginMessage(channel, DefinedPacket.toArray(brand), false);
|
||||||
|
brand.release();
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPacketId(DefinedPacket packet, int version, Protocol protocol) {
|
||||||
|
try {
|
||||||
|
return protocol.TO_CLIENT.getId(packet.getClass(), version);
|
||||||
|
} catch (Exception var4) {
|
||||||
|
System.out.println("No ID found for packet " + String.valueOf(packet.getClass()) + " for version " + version + " protocol " + String.valueOf(protocol));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Protocol findProtocolContainsPacket(DefinedPacket packet, int version, Protocol... protocols) {
|
||||||
|
for(Protocol protocol : protocols) {
|
||||||
|
try {
|
||||||
|
protocol.TO_CLIENT.getId(packet.getClass(), version);
|
||||||
|
return protocol;
|
||||||
|
} catch (Exception var8) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void releaseByteBuf(ByteBuf buf) {
|
||||||
|
if (buf != null && buf.refCnt() != 0) {
|
||||||
|
while(buf.refCnt() != 0) {
|
||||||
|
buf.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fillPackets(Map<Integer, ByteBuf> bufs, DefinedPacket packet, Protocol... protocols) {
|
||||||
|
if (packet != null) {
|
||||||
|
for(int version : ProtocolConstants.SUPPORTED_VERSION_IDS) {
|
||||||
|
Protocol protocol = findProtocolContainsPacket(packet, version, protocols);
|
||||||
|
if (protocol != null) {
|
||||||
|
int id = getPacketId(packet, version, protocol);
|
||||||
|
if (id != -1) {
|
||||||
|
if (bufs.containsKey(version)) {
|
||||||
|
System.out.println("===> Duplicated Packet Detected <===");
|
||||||
|
System.out.println("Packet Class: " + packet.getClass().getName());
|
||||||
|
System.out.println("Protocol Version: " + version);
|
||||||
|
System.out.println("Packet ID: " + id);
|
||||||
|
System.out.println("Protocol: " + protocol.getClass().getName());
|
||||||
|
} else {
|
||||||
|
bufs.put(version, createPacket(packet, protocol, id, version));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fillArray(ByteBuf[] buffer, DefinedPacket packet, Protocol... protocols) {
|
||||||
|
fillArray(buffer, packet, 0, Integer.MAX_VALUE, protocols);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fillArray(ByteBuf[] buffer, DefinedPacket packet, int from, int to, Protocol... protocols) {
|
||||||
|
if (packet != null) {
|
||||||
|
int oldPacketId = -1;
|
||||||
|
ByteBuf oldBuf = null;
|
||||||
|
|
||||||
|
for(int version : ProtocolConstants.SUPPORTED_VERSION_IDS) {
|
||||||
|
if (version >= from && version <= to) {
|
||||||
|
int versionRewrited = rewriteVersion(version);
|
||||||
|
Protocol protocol = findProtocolContainsPacket(packet, version, protocols);
|
||||||
|
if (protocol != null) {
|
||||||
|
int newPacketId = getPacketId(packet, version, protocol);
|
||||||
|
if (newPacketId != -1) {
|
||||||
|
if (newPacketId != oldPacketId) {
|
||||||
|
oldPacketId = newPacketId;
|
||||||
|
oldBuf = createPacket(packet, protocol, newPacketId, version);
|
||||||
|
buffer[versionRewrited] = oldBuf;
|
||||||
|
} else {
|
||||||
|
ByteBuf newBuf = createPacket(packet, protocol, oldPacketId, version);
|
||||||
|
if (newBuf.equals(oldBuf)) {
|
||||||
|
buffer[versionRewrited] = oldBuf;
|
||||||
|
newBuf.release();
|
||||||
|
} else {
|
||||||
|
oldBuf = newBuf;
|
||||||
|
buffer[versionRewrited] = newBuf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int rewriteVersion(int version) {
|
||||||
|
int rewritten = VERSION_REWRITE[version];
|
||||||
|
if (rewritten == -1) {
|
||||||
|
throw new IllegalArgumentException("Version is not supported");
|
||||||
|
} else {
|
||||||
|
return rewritten;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void configure(Channel channel, int version) {
|
||||||
|
if (version >= 764) {
|
||||||
|
if (!configurationRegistry.containsKey(version)) {
|
||||||
|
throw new IllegalArgumentException("Version " + version + " is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
((CachedRegistryData)configurationRegistry.get(version)).write(channel);
|
||||||
|
channel.write(getCachedPacket(CachedPacketType.FINISH_CONFIGURATION).get(version), channel.voidPromise());
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void spawnPlayer(Channel channel, int version, boolean disableFall, boolean captcha) {
|
||||||
|
channel.write(getCachedPacket(CachedPacketType.LOGIN).get(version), channel.voidPromise());
|
||||||
|
channel.write(getCachedPacket(version >= 393 ? CachedPacketType.BRAND_MODERN : CachedPacketType.BRAND).get(version), channel.voidPromise());
|
||||||
|
if (version >= 765) {
|
||||||
|
channel.write(getCachedPacket(CachedPacketType.GAME_STATE).get(version), channel.voidPromise());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(CachedPacket cachedPacket : chunksPackets) {
|
||||||
|
channel.write(cachedPacket.get(version), channel.voidPromise());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disableFall) {
|
||||||
|
channel.write(getCachedPacket(CachedPacketType.PLAYERABILITIES).get(version), channel.voidPromise());
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.write(getCachedPacket(CachedPacketType.DEFAULT_SPAWN_POSITION).get(version), channel.voidPromise());
|
||||||
|
if (captcha) {
|
||||||
|
channel.write(getCachedPacket(CachedPacketType.PLAYERPOSANDLOOK_CAPTCHA).get(version), channel.voidPromise());
|
||||||
|
} else {
|
||||||
|
channel.write(getCachedPacket(CachedPacketType.PLAYERPOSANDLOOK).get(version), channel.voidPromise());
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.write(getCachedPacket(CachedPacketType.TIME).get(version), channel.voidPromise());
|
||||||
|
channel.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void kickPlayer(KickType kick, Protocol protocol, ChannelWrapper wrapper, int version) {
|
||||||
|
if (wrapper.getHandle().isActive() && !wrapper.isClosed() && !wrapper.isClosing()) {
|
||||||
|
if (protocol == Protocol.GAME) {
|
||||||
|
wrapper.close(((CachedPacket)kickMessagesGame.get(kick)).get(version));
|
||||||
|
} else {
|
||||||
|
wrapper.close(((CachedPacket)kickMessagesLogin.get(kick)).get(version));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CachedPacket getCachedPacket(CachedPacketType type) {
|
||||||
|
return (CachedPacket)cachedPackets.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
PROTOCOLS_COUNT = ProtocolConstants.SUPPORTED_VERSION_IDS.size();
|
||||||
|
CLIENTID = (new Random()).nextInt(2147483547) + 50;
|
||||||
|
KEEPALIVE_ID = 9876;
|
||||||
|
cachedPackets = new EnumMap(CachedPacketType.class);
|
||||||
|
titles = new EnumMap(CachedPacketType.class);
|
||||||
|
messages = new EnumMap(CachedPacketType.class);
|
||||||
|
VERSION_REWRITE = new int[1024];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum KickType {
|
||||||
|
MANYCHECKS,
|
||||||
|
FAILED_CAPTCHA,
|
||||||
|
FAILED_FALLING,
|
||||||
|
TIMED_OUT,
|
||||||
|
LEAVED,
|
||||||
|
BIG_PACKET,
|
||||||
|
PING;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package dev._2lstudios.flamecord.utils;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class ProtocolUtil {
|
||||||
|
private static int SEGMENT_BITS = 127;
|
||||||
|
private static int CONTINUE_BIT = 128;
|
||||||
|
|
||||||
|
public static int readVarInt(ByteBuf byteBuf) {
|
||||||
|
int value = 0;
|
||||||
|
int position = 0;
|
||||||
|
|
||||||
|
while(byteBuf.isReadable()) {
|
||||||
|
byte currentByte = byteBuf.readByte();
|
||||||
|
value |= (currentByte & SEGMENT_BITS) << position;
|
||||||
|
if ((currentByte & CONTINUE_BIT) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
position += 7;
|
||||||
|
if (position >= 32) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loaded 100 of 958 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user