Merge branch 'fabric' into mongodb

# Conflicts:
#	src/main/java/org/samo_lego/simpleauth/SimpleAuth.java
#	src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java
This commit is contained in:
samo_lego 2020-10-13 20:43:07 +02:00
commit 394256abbd
10 changed files with 157 additions and 76 deletions

View File

@ -28,9 +28,9 @@ jobs:
- name: Build with Gradle
run: ./gradlew build
- name: Execute permission for renaming script
run: chmod +x ./.github/workflows/renaming.sh
- name: Running renaming script
run: ./.github/workflows/renaming.sh
run: chmod +x ./.github/workflows/main.sh
- name: Running main script
run: ./.github/workflows/main.sh
# Artifact upload
- name: Uploading artifacts
@ -39,3 +39,29 @@ jobs:
#name: ${{ env.BUILDNAME }}.jar
name: UNZIP_ME_${{ env.BUILDNAME }}
path: build/libs/${{ env.BUILDNAME }}.jar
- name: Create a Release
if: ${{ env.SHOULD_PUBLISH }}
id: create_release
uses: actions/create-release@v1.1.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# The name of the tag. This should come from the webhook payload, `github.GITHUB_REF` when a user pushes a new tag
tag_name: ${{ env.VERSION }}
# The name of the release. For example, `Release v1.0.1`
release_name: SimpleAuth ${{ env.VERSION }}
# Text describing the contents of the tag.
body: This release was created automatically, since version was bumped. Should be stable unless I messed up something.
- name: Upload a Release Asset
if: ${{ env.SHOULD_PUBLISH }}
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# The URL for uploading assets to the release
upload_url: ${{ steps.create_release.outputs.upload_url }}
# The path to the asset you want to upload
asset_path: build/libs/${{ env.BUILDNAME }}.jar
# The name of the asset you want to upload
asset_name: ${{ env.BUILDNAME }}
asset_content_type: application/zip

33
.github/workflows/main.sh vendored Normal file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# Setting the variables
projectId="$(grep 'archives_base_name' gradle.properties | sed 's/archives_base_name = //g;s/ //g;s/,//g;s/"//g')"
version="$(grep 'mod_version' gradle.properties | grep -o '[0-9]*\.[0-9]*\.[0-9]*')"
mcVersion="$(grep 'minecraft_version' gradle.properties | sed 's/minecraft_version=//g;s/ //g;s/,//g;s/"//g')"
cd ./build/libs || exit
buildName="$projectId-$version-devbuild_$GITHUB_RUN_NUMBER-MC_$mcVersion"
echo "Build is going to be renamed: $buildName.jar"
# Renaming the dev build
mv "$projectId-$version-$mcVersion.jar" "$buildName.jar"
# Setting the buildname for GH actions
echo "BUILDNAME=$buildName" >> $GITHUB_ENV
echo "PROJECT_ID=$projectId" >> $GITHUB_ENV
echo "VERSION=$version" >> $GITHUB_ENV
echo "MC_VERSION=$mcVersion" >> $GITHUB_ENV
# Checks if build is stable (I always bump version when I release stable, uploadable version)
latestRelease=$(curl -s "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/latest" | grep -oP '"tag_name": "\K(.*)(?=")')
echo "Latest release is: $latestRelease"
if [ "$latestRelease" == "$version" ]; then
echo "No need to publish release. Not necesarry stable yet."
else
echo "Hooray! New release!"
echo "SHOULD_PUBLISH=true" >> $GITHUB_ENV
fi

View File

@ -1,17 +0,0 @@
#!/bin/bash
# Setting the variables
projectId="$(grep 'archives_base_name' gradle.properties | sed 's/archives_base_name = //g;s/ //g;s/,//g;s/"//g')"
version="$(grep 'mod_version' gradle.properties | grep -o '[0-9]*\.[0-9]*\.[0-9]*')"
mcVersion="$(grep 'minecraft_version' gradle.properties | sed 's/minecraft_version=//g;s/ //g;s/,//g;s/"//g')"
cd ./build/libs || exit
buildName="$projectId-$version-devbuild_$GITHUB_RUN_NUMBER-MC_$mcVersion"
echo "Build is going to be renamed: $buildName.jar"
# Renaming the dev build
mv "$projectId-$version-$mcVersion.jar" "$buildName.jar"
#Setting the buildname for GH actions
echo "::set-env name=BUILDNAME::$buildName"

View File

@ -10,7 +10,7 @@ loader_version=0.9.3+build.207
fabric_version=0.20.2+build.402-1.16
# Mod Properties
mod_version = 1.5.2
mod_version = 1.5.3
maven_group = org.samo_lego
archives_base_name = simpleauth

View File

@ -36,6 +36,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static org.iq80.leveldb.impl.Iq80DBFactory.bytes;
import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake;
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo;
@ -284,22 +285,22 @@ public class SimpleAuth implements DedicatedServerModInitializer {
// Puts player to last cached position
try {
player.teleport(
server.getWorld(RegistryKey.of(Registry.DIMENSION, new Identifier(cache.lastDim))),
cache.lastX,
cache.lastY,
cache.lastZ,
0,
0
server.getWorld(RegistryKey.of(Registry.DIMENSION, new Identifier(cache.lastLocation.lastDim))),
cache.lastLocation.lastX,
cache.lastLocation.lastY,
cache.lastLocation.lastZ,
cache.lastLocation.lastYaw,
cache.lastLocation.lastPitch
);
} catch (Error e) {
player.sendMessage(new LiteralText(config.lang.corruptedPlayerData), false);
logError("Couldn't teleport player " + player.getName().asString());
logError(
String.format("Last recorded position is X: %s, Y: %s, Z: %s in dimension %s",
cache.lastX,
cache.lastY,
cache.lastZ,
cache.lastDim
cache.lastLocation.lastX,
cache.lastLocation.lastY,
cache.lastLocation.lastZ,
cache.lastLocation.lastDim
));
}
}

View File

@ -3,6 +3,7 @@ package org.samo_lego.simpleauth.commands;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.DimensionArgumentType;
import net.minecraft.command.argument.RotationArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;
@ -48,17 +49,23 @@ public class AuthCommand {
ctx.getSource().getEntityOrThrow().getEntityWorld().getRegistryKey().getValue(),
ctx.getSource().getEntityOrThrow().getX(),
ctx.getSource().getEntityOrThrow().getY(),
ctx.getSource().getEntityOrThrow().getZ()
ctx.getSource().getEntityOrThrow().getZ(),
ctx.getSource().getEntityOrThrow().yaw,
ctx.getSource().getEntityOrThrow().pitch
))
.then(argument("dimension", DimensionArgumentType.dimension())
.then(argument("position", BlockPosArgumentType.blockPos())
.executes(ctx -> setSpawn(
ctx.getSource(),
DimensionArgumentType.getDimensionArgument(ctx, "dimension").getRegistryKey().getValue(),
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getX(),
// +1 to not spawn player in ground
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getY() + 1,
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getZ()
.then(argument("angle", RotationArgumentType.rotation())
.executes(ctx -> setSpawn(
ctx.getSource(),
DimensionArgumentType.getDimensionArgument(ctx, "dimension").getRegistryKey().getValue(),
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getX(),
// +1 to not spawn player in ground
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getY() + 1,
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getZ(),
RotationArgumentType.getRotation(ctx, "angle").toAbsoluteRotation(ctx.getSource()).y,
RotationArgumentType.getRotation(ctx, "angle").toAbsoluteRotation(ctx.getSource()).x
)
)
)
)
@ -146,14 +153,18 @@ public class AuthCommand {
* @param x x coordinate of the global spawn
* @param y y coordinate of the global spawn
* @param z z coordinate of the global spawn
* @param yaw player yaw (y rotation)
* @param pitch player pitch (x rotation)
* @return 0
*/
private static int setSpawn(ServerCommandSource source, Identifier world, double x, double y, double z) {
private static int setSpawn(ServerCommandSource source, Identifier world, double x, double y, double z, float yaw, float pitch) {
// Setting config values and saving
config.worldSpawn.dimension = String.valueOf(world);
config.worldSpawn.x = x;
config.worldSpawn.y = y;
config.worldSpawn.z = z;
config.worldSpawn.yaw = yaw;
config.worldSpawn.pitch = pitch;
config.main.spawnOnJoin = true;
config.save(new File("./mods/SimpleAuth/config.json"));

View File

@ -5,10 +5,11 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import org.samo_lego.simpleauth.storage.PlayerCache;
import static net.minecraft.server.command.CommandManager.literal;
import static org.samo_lego.simpleauth.SimpleAuth.config;
import static org.samo_lego.simpleauth.SimpleAuth.deauthenticatePlayer;
import static org.samo_lego.simpleauth.SimpleAuth.*;
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
public class LogoutCommand {
@ -21,6 +22,14 @@ public class LogoutCommand {
private static int logout(ServerCommandSource serverCommandSource) throws CommandSyntaxException {
ServerPlayerEntity player = serverCommandSource.getPlayer();
PlayerCache playerCache = playerCacheMap.get(convertUuid(player));
playerCache.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
playerCache.lastLocation.lastX = player.getX();
playerCache.lastLocation.lastY = player.getY();
playerCache.lastLocation.lastZ = player.getZ();
playerCache.lastLocation.lastYaw = player.yaw;
playerCache.lastLocation.lastPitch = player.pitch;
deauthenticatePlayer(player);
player.sendMessage(new LiteralText(config.lang.successfulLogout), false);
return 1;

View File

@ -121,14 +121,18 @@ public class AuthEventHandler {
playerCache.lastAir = player.getAir();
playerCache.wasOnFire = player.isOnFire();
playerCache.wasInPortal = player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL);
playerCache.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
playerCache.lastX = player.getX();
playerCache.lastY = player.getY();
playerCache.lastZ = player.getZ();
if(isAuthenticated(player)) {
playerCache.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
playerCache.lastLocation.lastX = player.getX();
playerCache.lastLocation.lastY = player.getY();
playerCache.lastLocation.lastZ = player.getZ();
playerCache.lastLocation.lastYaw = player.yaw;
playerCache.lastLocation.lastPitch = player.pitch;
// Setting the session expire time
if(isAuthenticated(player) && config.main.sessionTimeoutTime != -1)
playerCache.validUntil = System.currentTimeMillis() + config.main.sessionTimeoutTime * 1000;
// Setting the session expire time
if(config.main.sessionTimeoutTime != -1)
playerCache.validUntil = System.currentTimeMillis() + config.main.sessionTimeoutTime * 1000;
}
}
// Player chatting
@ -174,13 +178,13 @@ public class AuthEventHandler {
return ActionResult.PASS;
}
// Punching a block
public static ActionResult onAttackBlock(PlayerEntity player) {
// Breaking a block
public static boolean onBreakBlock(PlayerEntity player) {
if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowBlockPunch) {
player.sendMessage(notAuthenticated(player), false);
return ActionResult.FAIL;
return false;
}
return ActionResult.PASS;
return true;
}
// Using an item

View File

@ -95,13 +95,15 @@ public class AuthConfig {
* @see <a href="https://github.com/samolego/SimpleAuth/wiki/Coordinate-Hiding" target="_blank">wiki</a>
*/
public static class WorldSpawn {
/**
* Dimension id, e.g. "minecraft:overworld"
*/
public String dimension;
public double x;
public double y;
public double z;
/**
* Dimension id, e.g. "minecraft:overworld"
*/
public String dimension;
public double x;
public double y;
public double z;
public float yaw;
public float pitch;
}
/**

View File

@ -51,10 +51,17 @@ public class PlayerCache {
/**
* Last recorded position before de-authentication.
*/
public String lastDim;
public double lastX;
public double lastY;
public double lastZ;
public static class LastLocation {
public String lastDim;
public double lastX;
public double lastY;
public double lastZ;
public float lastYaw;
public float lastPitch;
}
public PlayerCache.LastLocation lastLocation = new PlayerCache.LastLocation();
private static final Gson gson = new Gson();
@ -72,10 +79,13 @@ public class PlayerCache {
this.lastAir = player.getAir();
// Setting position cache
this.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
this.lastX = player.getX();
this.lastY = player.getY();
this.lastZ = player.getZ();
this.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
this.wasInPortal = player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL);
this.lastLocation.lastX = player.getX();
this.lastLocation.lastY = player.getY();
this.lastLocation.lastZ = player.getZ();
this.lastLocation.lastYaw = player.yaw;
this.lastLocation.lastPitch = player.pitch;
}
else {
this.wasOnFire = false;
@ -118,10 +128,12 @@ public class PlayerCache {
playerCache.wasOnFire = player.isOnFire();
// Setting position cache
playerCache.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
playerCache.lastX = player.getX();
playerCache.lastY = player.getY();
playerCache.lastZ = player.getZ();
playerCache.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
playerCache.lastLocation.lastX = player.getX();
playerCache.lastLocation.lastY = player.getY();
playerCache.lastLocation.lastZ = player.getZ();
playerCache.lastLocation.lastYaw = player.yaw;
playerCache.lastLocation.lastPitch = player.pitch;
}
else {
playerCache.wasInPortal = false;
@ -137,10 +149,10 @@ public class PlayerCache {
cacheJson.addProperty("password", this.password);
JsonObject lastLocation = new JsonObject();
lastLocation.addProperty("dim", this.lastDim);
lastLocation.addProperty("x", this.lastX);
lastLocation.addProperty("y", this.lastY);
lastLocation.addProperty("z", this.lastZ);
lastLocation.addProperty("dim", this.lastLocation.lastDim);
lastLocation.addProperty("x", this.lastLocation.lastX);
lastLocation.addProperty("y", this.lastLocation.lastY);
lastLocation.addProperty("z", this.lastLocation.lastZ);
cacheJson.addProperty("lastLocation", lastLocation.toString());