"Updating position protection."
This commit is contained in:
parent
f5d7de0b41
commit
1b0b72afa1
|
@ -112,7 +112,8 @@ 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) {
|
||||||
// Teleporting player back
|
// Teleporting player back
|
||||||
teleportPlayer(player, false);
|
if(config.main.spawnOnJoin)
|
||||||
|
teleportPlayer(player, false);
|
||||||
|
|
||||||
deauthenticatedUsers.remove(convertUuid(player));
|
deauthenticatedUsers.remove(convertUuid(player));
|
||||||
|
|
||||||
|
@ -131,7 +132,8 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
String uuid = convertUuid(player);
|
String uuid = convertUuid(player);
|
||||||
SimpleAuth.deauthenticatedUsers.put(uuid, new PlayerCache(uuid, player));
|
SimpleAuth.deauthenticatedUsers.put(uuid, new PlayerCache(uuid, player));
|
||||||
// Teleporting player to spawn to hide its position
|
// Teleporting player to spawn to hide its position
|
||||||
teleportPlayer(player, true);
|
if(config.main.spawnOnJoin)
|
||||||
|
teleportPlayer(player, true);
|
||||||
|
|
||||||
// Player is now not authenticated
|
// Player is now not authenticated
|
||||||
player.sendMessage(notAuthenticated(), false);
|
player.sendMessage(notAuthenticated(), false);
|
||||||
|
@ -156,30 +158,30 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
|
|
||||||
// Teleports player to spawn or last location when authenticating
|
// Teleports player to spawn or last location when authenticating
|
||||||
public static void teleportPlayer(ServerPlayerEntity player, boolean toSpawn) {
|
public static void teleportPlayer(ServerPlayerEntity player, boolean toSpawn) {
|
||||||
if(config.main.spawnOnJoin) {
|
MinecraftServer server = player.getServer();
|
||||||
MinecraftServer server = player.getServer();
|
if(server == null)
|
||||||
assert server != null;
|
return;
|
||||||
if (toSpawn) {
|
if (toSpawn) {
|
||||||
// Teleports player to spawn
|
// Teleports player to spawn
|
||||||
player.teleport(
|
player.teleport(
|
||||||
server.getWorld(DimensionType.byRawId(config.worldSpawn.dimensionId)),
|
server.getWorld(DimensionType.byRawId(config.worldSpawn.dimensionId)),
|
||||||
config.worldSpawn.x,
|
config.worldSpawn.x,
|
||||||
config.worldSpawn.y,
|
config.worldSpawn.y,
|
||||||
config.worldSpawn.z,
|
config.worldSpawn.z,
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PlayerCache cache = deauthenticatedUsers.get(convertUuid(player));
|
|
||||||
// Puts player to last cached position
|
|
||||||
player.setWorld(server.getWorld(DimensionType.byRawId(cache.lastDimId)));
|
|
||||||
player.setPos(
|
|
||||||
cache.lastX,
|
|
||||||
cache.lastY,
|
|
||||||
cache.lastZ
|
|
||||||
);
|
);
|
||||||
player.updateNeeded = true;
|
return;
|
||||||
}
|
}
|
||||||
|
PlayerCache cache = deauthenticatedUsers.get(convertUuid(player));
|
||||||
|
// Puts player to last cached position
|
||||||
|
player.teleport(
|
||||||
|
server.getWorld(DimensionType.byRawId(cache.lastDimId)),
|
||||||
|
cache.lastX,
|
||||||
|
cache.lastY,
|
||||||
|
cache.lastZ,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -163,13 +163,7 @@ public class AuthEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onPlayerLeave(ServerPlayerEntity player) {
|
public static void onPlayerLeave(ServerPlayerEntity player) {
|
||||||
if(isPlayerFake(player))
|
if(isPlayerFake(player) || !isAuthenticated(player) || config.main.sessionTimeoutTime == -1)
|
||||||
return;
|
|
||||||
|
|
||||||
// Teleporting player back
|
|
||||||
teleportPlayer(player, false);
|
|
||||||
|
|
||||||
if(!isAuthenticated(player) || config.main.sessionTimeoutTime == -1)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Starting session
|
// Starting session
|
||||||
|
|
|
@ -3,12 +3,17 @@ package org.samo_lego.simpleauth.mixin;
|
||||||
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
|
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
|
||||||
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
||||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
import org.samo_lego.simpleauth.event.entity.player.ChatCallback;
|
import org.samo_lego.simpleauth.event.entity.player.ChatCallback;
|
||||||
import org.samo_lego.simpleauth.event.entity.player.PlayerMoveCallback;
|
import org.samo_lego.simpleauth.event.entity.player.PlayerMoveCallback;
|
||||||
import org.samo_lego.simpleauth.event.item.TakeItemCallback;
|
import org.samo_lego.simpleauth.event.item.TakeItemCallback;
|
||||||
|
import org.samo_lego.simpleauth.storage.PlayerCache;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -16,12 +21,19 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import static net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS;
|
import static net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS;
|
||||||
|
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||||
|
import static org.samo_lego.simpleauth.SimpleAuth.deauthenticatedUsers;
|
||||||
|
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
||||||
|
|
||||||
@Mixin(ServerPlayNetworkHandler.class)
|
@Mixin(ServerPlayNetworkHandler.class)
|
||||||
public abstract class MixinServerPlayNetworkHandler {
|
public abstract class MixinServerPlayNetworkHandler {
|
||||||
@Shadow
|
@Shadow
|
||||||
public ServerPlayerEntity player;
|
public ServerPlayerEntity player;
|
||||||
|
|
||||||
|
@Final
|
||||||
|
@Shadow
|
||||||
|
private MinecraftServer server;
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "onGameMessage(Lnet/minecraft/network/packet/c2s/play/ChatMessageC2SPacket;)V",
|
method = "onGameMessage(Lnet/minecraft/network/packet/c2s/play/ChatMessageC2SPacket;)V",
|
||||||
at = @At(
|
at = @At(
|
||||||
|
@ -74,4 +86,48 @@ public abstract class MixinServerPlayNetworkHandler {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method="disconnect(Lnet/minecraft/text/Text;)V",
|
||||||
|
at = @At(value = "HEAD"),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
// If player is disconnected because of sth (e.g. wrong password)
|
||||||
|
// its position is set back to previous (e.g. not spawn)
|
||||||
|
private void disconnect(Text reason, CallbackInfo ci) {
|
||||||
|
if(config.main.spawnOnJoin) {
|
||||||
|
PlayerCache cache = deauthenticatedUsers.get(convertUuid(player));
|
||||||
|
// Puts player to last cached position
|
||||||
|
this.player.teleport(
|
||||||
|
this.server.getWorld(DimensionType.byRawId(cache.lastDimId)),
|
||||||
|
cache.lastX,
|
||||||
|
cache.lastY,
|
||||||
|
cache.lastZ,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method="onDisconnected(Lnet/minecraft/text/Text;)V",
|
||||||
|
at = @At(value = "HEAD"),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
// If player is disconnected because of sth (e.g. wrong password)
|
||||||
|
// its position is set back to previous (e.g. not spawn)
|
||||||
|
private void onDisconnected(Text reason, CallbackInfo ci) {
|
||||||
|
if(config.main.spawnOnJoin) {
|
||||||
|
PlayerCache cache = deauthenticatedUsers.get(convertUuid(player));
|
||||||
|
// Puts player to last cached position
|
||||||
|
this.player.teleport(
|
||||||
|
this.server.getWorld(DimensionType.byRawId(cache.lastDimId)),
|
||||||
|
cache.lastX,
|
||||||
|
cache.lastY,
|
||||||
|
cache.lastZ,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,9 +79,9 @@ public class SimpleAuthDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates the password of the user
|
// Updates the password of the user
|
||||||
public void updateUserData(String uuid, String password) {
|
public void updateUserData(String uuid, String data) {
|
||||||
try {
|
try {
|
||||||
levelDBStore.put(bytes("UUID:" + uuid),bytes("data:" + password));
|
levelDBStore.put(bytes("UUID:" + uuid),bytes("data:" + data));
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
LOGGER.error("[SimpleAuth] " + e.getMessage());
|
LOGGER.error("[SimpleAuth] " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"samo_lego"
|
"samo_lego"
|
||||||
],
|
],
|
||||||
"contact": {
|
"contact": {
|
||||||
|
"homepage": "samolego.github.io",
|
||||||
"sources": "https://github.com/samolego/SimpleAuth"
|
"sources": "https://github.com/samolego/SimpleAuth"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue