forked from sorceress/EasyAuth
Fixing #13
This commit is contained in:
parent
c0bd923855
commit
cd704bfbf3
|
@ -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 {
|
||||
|
|
|
@ -10,10 +10,10 @@ loader_version=0.9.0+build.204
|
|||
fabric_version=0.16.0+build.384-1.16.1
|
||||
|
||||
# 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
|
||||
|
|
|
@ -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
|
||||
|
@ -184,6 +186,10 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
if(player.isSubmergedInWater())
|
||||
player.setAir(playerCache.lastAir);
|
||||
|
||||
// In case player is in lava during authentication proccess
|
||||
if(!playerCache.wasOnFire)
|
||||
player.setFireTicks(0);
|
||||
|
||||
deauthenticatedUsers.remove(convertUuid(player));
|
||||
|
||||
// Player no longer needs to be invisible and invulnerable
|
||||
|
@ -197,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)
|
||||
|
@ -211,15 +217,17 @@ 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() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Kicking player if not authenticated
|
||||
if(!SimpleAuth.isAuthenticated(player) && player.networkHandler.getConnection().isOpen())
|
||||
player.networkHandler.disconnect(new LiteralText(SimpleAuth.config.lang.timeExpired));
|
||||
}
|
||||
}, SimpleAuth.config.main.delay * 1000);
|
||||
|
||||
// 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(!isAuthenticated(player) && player.networkHandler.getConnection().isOpen())
|
||||
player.networkHandler.disconnect(new LiteralText(SimpleAuth.config.lang.timeExpired));
|
||||
}
|
||||
}, SimpleAuth.config.main.delay * 1000);
|
||||
}
|
||||
|
||||
// Checking is player is a fake (carpetmod) player
|
||||
|
@ -233,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(
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -79,6 +80,10 @@ public class AuthEventHandler {
|
|||
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);
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue