Fixing #13
This commit is contained in:
parent
c0bd923855
commit
cd704bfbf3
|
@ -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.384-1.16.1
|
fabric_version=0.16.0+build.384-1.16.1
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -184,6 +186,10 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
if(player.isSubmergedInWater())
|
if(player.isSubmergedInWater())
|
||||||
player.setAir(playerCache.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));
|
||||||
|
|
||||||
// Player no longer needs to be invisible and invulnerable
|
// Player no longer needs to be invisible and invulnerable
|
||||||
|
@ -197,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)
|
||||||
|
@ -211,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
|
||||||
|
@ -233,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;
|
||||||
|
|
||||||
|
@ -79,6 +80,10 @@ public class AuthEventHandler {
|
||||||
authenticatePlayer(player, null); // 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