Merge branch 'master' into latest-snapshot
# Conflicts: # gradle.properties
This commit is contained in:
commit
c0e95cf8d7
|
@ -1,12 +1,20 @@
|
||||||
---
|
---
|
||||||
name: Bug report
|
name: Bug report
|
||||||
about: Create a report to help us improve
|
about: Create a report to help us improve
|
||||||
title: "[BUG]"
|
title: "[BUG] [Fabric/Forge]"
|
||||||
labels: ''
|
labels: bug
|
||||||
assignees: ''
|
assignees: samolego
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
**Mod Loader**
|
||||||
|
- [x] Fabric
|
||||||
|
- [ ] Forge
|
||||||
|
|
||||||
|
**Versions**
|
||||||
|
* SimpleAuth X.Y.Z
|
||||||
|
* Fabric API X.Y.Z / Forge X.Y.Z
|
||||||
|
|
||||||
**Describe the bug**
|
**Describe the bug**
|
||||||
A clear and concise description of what the bug is.
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,11 @@ plugins {
|
||||||
repositories {
|
repositories {
|
||||||
// Carpet mod
|
// Carpet mod
|
||||||
maven {
|
maven {
|
||||||
//url 'https://masa.dy.fi/maven'
|
|
||||||
url 'https://jitpack.io'
|
url 'https://jitpack.io'
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
url 'https://masa.dy.fi/maven'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
@ -47,9 +49,9 @@ dependencies {
|
||||||
// carpetMod
|
// carpetMod
|
||||||
// from masa's maven
|
// from masa's maven
|
||||||
//modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}"
|
//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
|
// 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 {
|
processResources {
|
||||||
|
|
|
@ -10,10 +10,10 @@ loader_version=0.9.0+build.204
|
||||||
fabric_version=0.16.0+build.386-1.16
|
fabric_version=0.16.0+build.386-1.16
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.4.7
|
mod_version = 1.4.8
|
||||||
maven_group = org.samo_lego
|
maven_group = org.samo_lego
|
||||||
archives_base_name = simpleauth
|
archives_base_name = simpleauth
|
||||||
|
|
||||||
# Carpet for debugging
|
# Carpet for debugging
|
||||||
#carpet_core_version = 1.3.23+v200513
|
carpet_core_version = 1.4.0+v200623
|
||||||
carpet_branch = 1.16
|
carpet_branch = 1.16
|
||||||
|
|
|
@ -49,6 +49,8 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
|
|
||||||
public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool();
|
public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
|
private static final Timer TIMER = new Timer();
|
||||||
|
|
||||||
// HashMap of players that are not authenticated
|
// HashMap of players that are not authenticated
|
||||||
// Rather than storing all the authenticated players, we just store ones 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
|
// 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
|
// Authenticates player and sends the message
|
||||||
public static void authenticatePlayer(ServerPlayerEntity player, Text msg) {
|
public static void authenticatePlayer(ServerPlayerEntity player, Text msg) {
|
||||||
|
PlayerCache playerCache = deauthenticatedUsers.get(convertUuid(player));
|
||||||
// Teleporting player back
|
// Teleporting player back
|
||||||
if(config.main.spawnOnJoin)
|
if(config.main.spawnOnJoin)
|
||||||
teleportPlayer(player, false);
|
teleportPlayer(player, false);
|
||||||
|
|
||||||
// Updating blocks if needed (if portal rescue action happened)
|
// Updating blocks if needed (if portal rescue action happened)
|
||||||
if(deauthenticatedUsers.get(convertUuid(player)).wasInPortal) {
|
if(playerCache.wasInPortal) {
|
||||||
World world = player.getEntityWorld();
|
World world = player.getEntityWorld();
|
||||||
BlockPos pos = player.getBlockPos();
|
BlockPos pos = player.getBlockPos();
|
||||||
|
|
||||||
|
@ -181,7 +184,11 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
|
|
||||||
// Setting last air to player
|
// Setting last air to player
|
||||||
if(player.isSubmergedInWater())
|
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));
|
deauthenticatedUsers.remove(convertUuid(player));
|
||||||
|
|
||||||
|
@ -196,9 +203,9 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
if(DB.isClosed())
|
if(DB.isClosed())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Marking player as not authenticated, (re)setting login tries to zero
|
// Marking player as not authenticated
|
||||||
String uuid = convertUuid(player);
|
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
|
// Teleporting player to spawn to hide its position
|
||||||
if(config.main.spawnOnJoin)
|
if(config.main.spawnOnJoin)
|
||||||
|
@ -210,15 +217,17 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
// Setting the player to be invisible to mobs and also invulnerable
|
// Setting the player to be invisible to mobs and also invulnerable
|
||||||
player.setInvulnerable(SimpleAuth.config.experimental.playerInvulnerable);
|
player.setInvulnerable(SimpleAuth.config.experimental.playerInvulnerable);
|
||||||
player.setInvisible(SimpleAuth.config.experimental.playerInvisible);
|
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)
|
||||||
@Override
|
if(player.networkHandler.getConnection().isOpen())
|
||||||
public void run() {
|
TIMER.schedule(new TimerTask() {
|
||||||
// Kicking player if not authenticated
|
@Override
|
||||||
if(!SimpleAuth.isAuthenticated(player) && player.networkHandler.getConnection().isOpen())
|
public void run() {
|
||||||
player.networkHandler.disconnect(new LiteralText(SimpleAuth.config.lang.timeExpired));
|
// Kicking player if not authenticated
|
||||||
}
|
if(!isAuthenticated(player) && player.networkHandler.getConnection().isOpen())
|
||||||
}, SimpleAuth.config.main.delay * 1000);
|
player.networkHandler.disconnect(new LiteralText(SimpleAuth.config.lang.timeExpired));
|
||||||
|
}
|
||||||
|
}, SimpleAuth.config.main.delay * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking is player is a fake (carpetmod) player
|
// Checking is player is a fake (carpetmod) player
|
||||||
|
@ -232,7 +241,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
MinecraftServer server = player.getServer();
|
MinecraftServer server = player.getServer();
|
||||||
if(server == null || config.worldSpawn.dimension == null)
|
if(server == null || config.worldSpawn.dimension == null)
|
||||||
return;
|
return;
|
||||||
// registry for dimensions
|
|
||||||
if (toSpawn) {
|
if (toSpawn) {
|
||||||
// Teleports player to spawn
|
// Teleports player to spawn
|
||||||
player.teleport(
|
player.teleport(
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.TypedActionResult;
|
import net.minecraft.util.TypedActionResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import org.samo_lego.simpleauth.SimpleAuth;
|
||||||
import org.samo_lego.simpleauth.mixin.BlockUpdateS2CPacketAccessor;
|
import org.samo_lego.simpleauth.mixin.BlockUpdateS2CPacketAccessor;
|
||||||
import org.samo_lego.simpleauth.storage.PlayerCache;
|
import org.samo_lego.simpleauth.storage.PlayerCache;
|
||||||
|
|
||||||
|
@ -76,9 +77,13 @@ public class AuthEventHandler {
|
||||||
playerCache.validUntil >= System.currentTimeMillis() &&
|
playerCache.validUntil >= System.currentTimeMillis() &&
|
||||||
player.getIp().equals(playerCache.lastIp)
|
player.getIp().equals(playerCache.lastIp)
|
||||||
) {
|
) {
|
||||||
deauthenticatedUsers.remove(uuid); // Makes player authenticated
|
authenticatePlayer(player, null); // Makes player authenticated
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Ugly fix for #13
|
||||||
|
player.setInvulnerable(SimpleAuth.config.experimental.playerInvulnerable);
|
||||||
|
player.setInvisible(SimpleAuth.config.experimental.playerInvisible);
|
||||||
|
|
||||||
// Invalidating session
|
// Invalidating session
|
||||||
playerCache.wasAuthenticated = false;
|
playerCache.wasAuthenticated = false;
|
||||||
player.sendMessage(notAuthenticated(player), false);
|
player.sendMessage(notAuthenticated(player), false);
|
||||||
|
@ -106,7 +111,6 @@ public class AuthEventHandler {
|
||||||
((BlockUpdateS2CPacketAccessor) headPacket).setState(Blocks.AIR.getDefaultState());
|
((BlockUpdateS2CPacketAccessor) headPacket).setState(Blocks.AIR.getDefaultState());
|
||||||
((BlockUpdateS2CPacketAccessor) headPacket).setBlockPos(pos.up());
|
((BlockUpdateS2CPacketAccessor) headPacket).setBlockPos(pos.up());
|
||||||
player.networkHandler.sendPacket(headPacket);
|
player.networkHandler.sendPacket(headPacket);
|
||||||
System.out.println(headPacket);
|
|
||||||
|
|
||||||
// Teleporting player to the middle of the block
|
// Teleporting player to the middle of the block
|
||||||
player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
|
player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||||
|
|
||||||
public class PlayerCache {
|
public class PlayerCache {
|
||||||
public boolean isRegistered;
|
public boolean isRegistered;
|
||||||
|
// If player from another location (different IP) joins, session is invalidated using this boolean
|
||||||
public boolean wasAuthenticated;
|
public boolean wasAuthenticated;
|
||||||
public String password;
|
public String password;
|
||||||
public int loginTries;
|
public int loginTries;
|
||||||
|
@ -16,6 +17,7 @@ public class PlayerCache {
|
||||||
public long validUntil;
|
public long validUntil;
|
||||||
|
|
||||||
public int lastAir = 300;
|
public int lastAir = 300;
|
||||||
|
public boolean wasOnFire = false;
|
||||||
|
|
||||||
public String lastDim;
|
public String lastDim;
|
||||||
public double lastX;
|
public double lastX;
|
||||||
|
@ -34,6 +36,7 @@ public class PlayerCache {
|
||||||
this.lastIp = player.getIp();
|
this.lastIp = player.getIp();
|
||||||
|
|
||||||
this.lastAir = player.getAir();
|
this.lastAir = player.getAir();
|
||||||
|
this.wasOnFire = player.isOnFire();
|
||||||
|
|
||||||
// Setting position cache
|
// Setting position cache
|
||||||
this.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
|
this.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue());
|
||||||
|
|
Loading…
Reference in New Issue