forked from Crasher508/Barrel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# Eclipse | ||
.classpath | ||
.project | ||
.settings/ | ||
|
||
# Intellij | ||
.idea/ | ||
*.iml | ||
*.iws | ||
|
||
# Mac | ||
.DS_Store | ||
|
||
# Maven | ||
log/ | ||
target/ | ||
|
||
# Inclusions | ||
!lib/** | ||
|
||
# Compiled Files | ||
*.class | ||
bin/ | ||
build/ | ||
/bin1/ | ||
java/build/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Barrel Proxy | ||
|
||
(WIP) A proxy to connect to Minecraft: Bedrock Edition servers with Minecraft: Java edition written in Java | ||
|
||
## Need implemented | ||
|
||
- Chunks | ||
- Inventory | ||
- Xbox Auth | ||
- And More... | ||
|
||
## Credits | ||
|
||
- [EZ4H](https://github.com/Project-EZ4H/EZ4H) (Archived) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.barrelmc.barrel</groupId> | ||
<artifactId>Barrel</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<repositories> | ||
<repository> | ||
<id>nukkitx-repo-release</id> | ||
<url>https://repo.nukkitx.com/maven-releases/</url> | ||
</repository> | ||
<repository> | ||
<id>nukkitx-repo-snapshot</id> | ||
<url>https://repo.nukkitx.com/maven-snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.nukkitx.protocol</groupId> | ||
<artifactId>bedrock-v440</artifactId> | ||
<version>2.8.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.Steveice10</groupId> | ||
<artifactId>MCProtocolLib</artifactId> | ||
<version>1.16.5-2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
<version>1.28</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>fastjson</artifactId> | ||
<version>1.2.47</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>RELEASE</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.auth0</groupId> | ||
<artifactId>java-jwt</artifactId> | ||
<version>3.16.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.barrelmc.barrel.Barrel</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<release>11</release> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* ____ _ | ||
* | __ ) __ _ _ __ _ __ ___ | | | ||
* | _ \ / _` | | '__| | '__| / _ \ | | | ||
* | |_) | | (_| | | | | | | __/ | | | ||
* |____/ \__,_| |_| |_| \___| |_| | ||
* | ||
* Copyright (c) 2021 BarrelMC | ||
* BarrelMC/Barrel is licensed under the MIT License | ||
*/ | ||
|
||
package org.barrelmc.barrel; | ||
|
||
import org.barrelmc.barrel.server.ProxyServer; | ||
|
||
public class Barrel { | ||
|
||
public static String DATA_PATH = System.getProperty("user.dir") + "/"; | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Starting Barrel Proxy software"); | ||
new ProxyServer(DATA_PATH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.barrelmc.barrel.auth; | ||
|
||
import java.security.SignatureException; | ||
|
||
// https://github.com/Project-EZ4H/EZ4H/blob/main/src/main/java/me/liuli/ez4h/minecraft/auth/JoseStuff.java | ||
public class JoseStuff { | ||
|
||
public static byte[] DERToJOSE(byte[] derSignature, AlgorithmType algorithmType) throws SignatureException { | ||
// DER Structure: http://crypto.stackexchange.com/a/1797 | ||
boolean derEncoded = derSignature[0] == 0x30 && derSignature.length != algorithmType.ecNumberSize * 2; | ||
if (!derEncoded) { | ||
throw new SignatureException("Invalid DER signature format."); | ||
} | ||
|
||
final byte[] joseSignature = new byte[algorithmType.ecNumberSize * 2]; | ||
|
||
//Skip 0x30 | ||
int offset = 1; | ||
if (derSignature[1] == (byte) 0x81) { | ||
//Skip sign | ||
offset++; | ||
} | ||
|
||
//Convert to unsigned. Should match DER length - offset | ||
int encodedLength = derSignature[offset++] & 0xff; | ||
if (encodedLength != derSignature.length - offset) { | ||
throw new SignatureException("Invalid DER signature format."); | ||
} | ||
|
||
//Skip 0x02 | ||
offset++; | ||
|
||
//Obtain R number length (Includes padding) and skip it | ||
int rLength = derSignature[offset++]; | ||
if (rLength > algorithmType.ecNumberSize + 1) { | ||
throw new SignatureException("Invalid DER signature format."); | ||
} | ||
int rPadding = algorithmType.ecNumberSize - rLength; | ||
//Retrieve R number | ||
System.arraycopy(derSignature, offset + Math.max(-rPadding, 0), joseSignature, Math.max(rPadding, 0), rLength + Math.min(rPadding, 0)); | ||
|
||
//Skip R number and 0x02 | ||
offset += rLength + 1; | ||
|
||
//Obtain S number length. (Includes padding) | ||
int sLength = derSignature[offset++]; | ||
if (sLength > algorithmType.ecNumberSize + 1) { | ||
throw new SignatureException("Invalid DER signature format."); | ||
} | ||
int sPadding = algorithmType.ecNumberSize - sLength; | ||
//Retrieve R number | ||
System.arraycopy(derSignature, offset + Math.max(-sPadding, 0), joseSignature, algorithmType.ecNumberSize + Math.max(sPadding, 0), sLength + Math.min(sPadding, 0)); | ||
|
||
return joseSignature; | ||
} | ||
|
||
public enum AlgorithmType { | ||
ECDSA256(32), ECDSA384(48); | ||
|
||
public int ecNumberSize; | ||
|
||
AlgorithmType(int ecNumberSize) { | ||
this.ecNumberSize = ecNumberSize; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2021 BarrelMC | ||
* BarrelMC/Barrel is licensed under the MIT License | ||
*/ | ||
|
||
package org.barrelmc.barrel.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
public class Config { | ||
|
||
@Setter | ||
@Getter | ||
public String bindAddress; | ||
|
||
@Setter | ||
@Getter | ||
public Integer port; | ||
|
||
@Setter | ||
@Getter | ||
public String motd; | ||
|
||
@Setter | ||
@Getter | ||
public String bedrockAddress; | ||
|
||
@Setter | ||
@Getter | ||
public Integer bedrockPort; | ||
|
||
@Setter | ||
@Getter | ||
public String auth; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.barrelmc.barrel.math; | ||
|
||
import com.nukkitx.math.GenericMath; | ||
import com.nukkitx.math.vector.Vector3f; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
public class Vector3 { | ||
|
||
@Setter | ||
@Getter | ||
public double x; | ||
@Setter | ||
@Getter | ||
public double y; | ||
@Setter | ||
@Getter | ||
public double z; | ||
@Setter | ||
@Getter | ||
public float yaw; | ||
@Setter | ||
@Getter | ||
public float pitch; | ||
|
||
public int getFloorX() { | ||
return GenericMath.floor(this.x); | ||
} | ||
|
||
public int getFloorY() { | ||
return GenericMath.floor(this.y); | ||
} | ||
|
||
public int getFloorZ() { | ||
return GenericMath.floor(this.z); | ||
} | ||
|
||
public void setPosition(double x, double y, double z) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
} | ||
|
||
public void setLocation(double x, double y, double z, float yaw, float pitch) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
this.yaw = yaw; | ||
this.pitch = pitch; | ||
} | ||
|
||
public void setRotation(float yaw, float pitch) { | ||
this.yaw = yaw; | ||
this.pitch = pitch; | ||
} | ||
|
||
public Vector3f getVector3f() { | ||
return Vector3f.from(this.x, this.y + 1.62, this.z); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/barrelmc/barrel/network/BedrockBatchHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2021 BarrelMC | ||
* BarrelMC/Barrel is licensed under the MIT License | ||
*/ | ||
|
||
package org.barrelmc.barrel.network; | ||
|
||
import com.nukkitx.protocol.bedrock.BedrockPacket; | ||
import com.nukkitx.protocol.bedrock.BedrockSession; | ||
import com.nukkitx.protocol.bedrock.handler.BatchHandler; | ||
import io.netty.buffer.ByteBuf; | ||
import org.barrelmc.barrel.network.translator.PacketTranslator; | ||
import org.barrelmc.barrel.player.Player; | ||
|
||
import java.util.Collection; | ||
|
||
public class BedrockBatchHandler implements BatchHandler { | ||
|
||
private final Player player; | ||
|
||
public BedrockBatchHandler(Player player) { | ||
this.player = player; | ||
} | ||
|
||
@Override | ||
public void handle(BedrockSession bedrockSession, ByteBuf byteBuf, Collection<BedrockPacket> collection) { | ||
for (BedrockPacket packet : collection) { | ||
PacketTranslator.translateToJava(packet, this.player); | ||
} | ||
} | ||
} |
Oops, something went wrong.