Merge branch 'master' into latest-snapshot

# Conflicts:
#	gradle.properties
This commit is contained in:
samo_lego 2020-07-28 12:02:13 +02:00
commit c0e95cf8d7
6 changed files with 50 additions and 24 deletions

View File

@ -1,12 +1,20 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: ''
assignees: ''
title: "[BUG] [Fabric/Forge]"
labels: bug
assignees: samolego
---
**Mod Loader**
- [x] Fabric
- [ ] Forge
**Versions**
* SimpleAuth X.Y.Z
* Fabric API X.Y.Z / Forge X.Y.Z
**Describe the bug**
A clear and concise description of what the bug is.

View File

@ -6,9 +6,11 @@ plugins {
repositories {
// Carpet mod
maven {
//url 'https://masa.dy.fi/maven'
url 'https://jitpack.io'
}
maven {
url 'https://masa.dy.fi/maven'
}
}
sourceCompatibility = JavaVersion.VERSION_1_8
@ -47,9 +49,9 @@ dependencies {
// carpetMod
// from masa's maven
//modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}"
modImplementation "carpet:fabric-carpet:1.16-${project.carpet_core_version}"
// jitpack for quicker updating
modImplementation "com.github.gnembon:fabric-carpet:${project.carpet_branch}-SNAPSHOT"
//modImplementation "com.github.gnembon:fabric-carpet:${project.carpet_branch}-SNAPSHOT"
}
processResources {

View File

@ -10,10 +10,10 @@ loader_version=0.9.0+build.204
fabric_version=0.16.0+build.386-1.16
# Mod Properties
mod_version = 1.4.7
mod_version = 1.4.8
maven_group = org.samo_lego
archives_base_name = simpleauth
# Carpet for debugging
#carpet_core_version = 1.3.23+v200513
carpet_core_version = 1.4.0+v200623
carpet_branch = 1.16

View File

@ -49,6 +49,8 @@ public class SimpleAuth implements DedicatedServerModInitializer {
public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool();
private static final Timer TIMER = new Timer();
// HashMap of players that are not authenticated
// Rather than storing all the authenticated players, we just store ones that are not authenticated
// It stores some data as well, e.g. login tries and user password
@ -164,12 +166,13 @@ public class SimpleAuth implements DedicatedServerModInitializer {
// Authenticates player and sends the message
public static void authenticatePlayer(ServerPlayerEntity player, Text msg) {
PlayerCache playerCache = deauthenticatedUsers.get(convertUuid(player));
// Teleporting player back
if(config.main.spawnOnJoin)
teleportPlayer(player, false);
// Updating blocks if needed (if portal rescue action happened)
if(deauthenticatedUsers.get(convertUuid(player)).wasInPortal) {
if(playerCache.wasInPortal) {
World world = player.getEntityWorld();
BlockPos pos = player.getBlockPos();
@ -181,7 +184,11 @@ public class SimpleAuth implements DedicatedServerModInitializer {
// Setting last air to player
if(player.isSubmergedInWater())
player.setAir(deauthenticatedUsers.get(convertUuid(player)).lastAir);
player.setAir(playerCache.lastAir);
// In case player is in lava during authentication proccess
if(!playerCache.wasOnFire)
player.setFireTicks(0);
deauthenticatedUsers.remove(convertUuid(player));
@ -196,9 +203,9 @@ public class SimpleAuth implements DedicatedServerModInitializer {
if(DB.isClosed())
return;
// Marking player as not authenticated, (re)setting login tries to zero
// Marking player as not authenticated
String uuid = convertUuid(player);
SimpleAuth.deauthenticatedUsers.put(uuid, new PlayerCache(uuid, player));
deauthenticatedUsers.put(uuid, new PlayerCache(uuid, player));
// Teleporting player to spawn to hide its position
if(config.main.spawnOnJoin)
@ -210,12 +217,14 @@ public class SimpleAuth implements DedicatedServerModInitializer {
// Setting the player to be invisible to mobs and also invulnerable
player.setInvulnerable(SimpleAuth.config.experimental.playerInvulnerable);
player.setInvisible(SimpleAuth.config.experimental.playerInvisible);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
// Timer should start only if player has joined, not left the server (in case os session)
if(player.networkHandler.getConnection().isOpen())
TIMER.schedule(new TimerTask() {
@Override
public void run() {
// Kicking player if not authenticated
if(!SimpleAuth.isAuthenticated(player) && player.networkHandler.getConnection().isOpen())
if(!isAuthenticated(player) && player.networkHandler.getConnection().isOpen())
player.networkHandler.disconnect(new LiteralText(SimpleAuth.config.lang.timeExpired));
}
}, SimpleAuth.config.main.delay * 1000);
@ -232,7 +241,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
MinecraftServer server = player.getServer();
if(server == null || config.worldSpawn.dimension == null)
return;
// registry for dimensions
if (toSpawn) {
// Teleports player to spawn
player.teleport(

View File

@ -12,6 +12,7 @@ import net.minecraft.text.LiteralText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import org.samo_lego.simpleauth.SimpleAuth;
import org.samo_lego.simpleauth.mixin.BlockUpdateS2CPacketAccessor;
import org.samo_lego.simpleauth.storage.PlayerCache;
@ -76,9 +77,13 @@ public class AuthEventHandler {
playerCache.validUntil >= System.currentTimeMillis() &&
player.getIp().equals(playerCache.lastIp)
) {
deauthenticatedUsers.remove(uuid); // Makes player authenticated
authenticatePlayer(player, null); // Makes player authenticated
return;
}
// Ugly fix for #13
player.setInvulnerable(SimpleAuth.config.experimental.playerInvulnerable);
player.setInvisible(SimpleAuth.config.experimental.playerInvisible);
// Invalidating session
playerCache.wasAuthenticated = false;
player.sendMessage(notAuthenticated(player), false);
@ -106,7 +111,6 @@ public class AuthEventHandler {
((BlockUpdateS2CPacketAccessor) headPacket).setState(Blocks.AIR.getDefaultState());
((BlockUpdateS2CPacketAccessor) headPacket).setBlockPos(pos.up());
player.networkHandler.sendPacket(headPacket);
System.out.println(headPacket);
// Teleporting player to the middle of the block
player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);

View File

@ -9,6 +9,7 @@ import static org.samo_lego.simpleauth.SimpleAuth.config;
public class PlayerCache {
public boolean isRegistered;
// If player from another location (different IP) joins, session is invalidated using this boolean
public boolean wasAuthenticated;
public String password;
public int loginTries;
@ -16,6 +17,7 @@ public class PlayerCache {
public long validUntil;
public int lastAir = 300;
public boolean wasOnFire = false;
public String lastDim;
public double lastX;
@ -34,6 +36,7 @@ public class PlayerCache {
this.lastIp = player.getIp();
this.lastAir = player.getAir();
this.wasOnFire = player.isOnFire();
// Setting position cache
this.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());