Update to 1.15pre2

Added chat protection and movement protection. Mod should now enter polishing state.
This commit is contained in:
samo_lego 2019-11-26 22:11:56 +01:00
parent beeb1183fc
commit 653230e534
5 changed files with 37 additions and 27 deletions

View File

@ -1,14 +1,13 @@
# Done to increase the memory available to gradle. # Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric properties
minecraft_version=1.15-pre1 minecraft_version=1.15-pre2
yarn_mappings=1.15-pre1+build.3 yarn_mappings=1.15-pre2+build.3
loader_version=0.7.1+build.173 loader_version=0.7.1+build.173
# Dependencies #Fabric api
# Fabric API fabric_version=0.4.16+build.268-1.15
fabric_version=0.4.13+build.264-1.15
# Mod Properties # Mod Properties
mod_version = 1.0.0 mod_version = 1.0.0

View File

@ -35,20 +35,16 @@ public class AuthEventHandler {
// todo // todo
public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) { public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) {
String msg = chatMessageC2SPacket.getChatMessage(); String msg = chatMessageC2SPacket.getChatMessage();
System.out.println(msg); if(!SimpleAuth.authenticatedUsers.contains(player) && !(msg.startsWith("/login") || msg.startsWith("/register"))) {
if(!SimpleAuth.authenticatedUsers.contains(player) || !msg.startsWith("/login") || !msg.startsWith("/register")) {
System.out.println("Ok.");
player.sendMessage(notAuthenticated); player.sendMessage(notAuthenticated);
return ActionResult.FAIL; return ActionResult.FAIL;
} }
System.out.println("Pass "+ msg.startsWith("/login")+msg.startsWith("/register"));
return ActionResult.PASS; return ActionResult.PASS;
} }
//todo //todo
public static ActionResult onPlayerMove(PlayerEntity player) { public static ActionResult onPlayerMove(PlayerEntity player) {
if(!SimpleAuth.authenticatedUsers.contains(player)) { if(!SimpleAuth.authenticatedUsers.contains(player)) {
System.out.println("Ok. Moved & should fail. AuthEventHandler"); // TP player back?
player.sendMessage(notAuthenticated);
return ActionResult.FAIL; return ActionResult.FAIL;
} }
return ActionResult.PASS; return ActionResult.PASS;

View File

@ -26,10 +26,12 @@ public abstract class MixinPlayerEntity {
ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player); ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player);
if (result == ActionResult.FAIL) { if (result == ActionResult.FAIL) {
// Canceling the item drop, as well as giving the items back to player // Canceling the item drop, as well as giving the items back to player (and updating inv with packet)
cir.cancel();
player.giveItemStack(stack); player.giveItemStack(stack);
player.inventory.updateItems();
playerContainer.sendContentUpdates(); playerContainer.sendContentUpdates();
cir.cancel();
} }
} }
} }

View File

@ -12,7 +12,6 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerPlayNetworkHandler.class) @Mixin(ServerPlayNetworkHandler.class)
public class MixinServerPlayNetworkHandler { public class MixinServerPlayNetworkHandler {
@ -20,24 +19,38 @@ public class MixinServerPlayNetworkHandler {
public ServerPlayerEntity player; public ServerPlayerEntity player;
// TODO // TODO
@Inject(method = "onChatMessage", at = @At(value = "HEAD"), cancellable = true) @Inject(
private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket_1, CallbackInfoReturnable cir) { method = "onChatMessage(Lnet/minecraft/server/network/packet/ChatMessageC2SPacket;)V",
at = @At(
value = "INVOKE",
// Thanks to Liach for helping me out!
target = "net/minecraft/network/NetworkThreadUtils.forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V",
shift = At.Shift.AFTER
),
cancellable = true
)
private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket_1, CallbackInfo ci) {
ActionResult result = OnChatCallback.EVENT.invoker().onPlayerChat(player, chatMessageC2SPacket_1); ActionResult result = OnChatCallback.EVENT.invoker().onPlayerChat(player, chatMessageC2SPacket_1);
System.out.println("Mixined");
if (result == ActionResult.FAIL) { if (result == ActionResult.FAIL) {
cir.cancel(); ci.cancel();
} }
} }
// TODO // TODO
@Inject(method="onPlayerMove", at = @At(value = "HEAD"), cancellable = true) @Inject(
private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo cir) { method="onPlayerMove(Lnet/minecraft/server/network/packet/PlayerMoveC2SPacket;)V",
at = @At(
value = "INVOKE",
// Thanks to Liach for helping me out!
target = "net/minecraft/network/NetworkThreadUtils.forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V",
shift = At.Shift.AFTER
),
cancellable = true
)
private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci) {
ActionResult result = OnPlayerMoveCallback.EVENT.invoker().onPlayerMove(player); ActionResult result = OnPlayerMoveCallback.EVENT.invoker().onPlayerMove(player);
System.out.println("Player move");
if (result == ActionResult.FAIL) { if (result == ActionResult.FAIL) {
cir.cancel(); ci.cancel();
} }
} }
} }

View File

@ -5,7 +5,7 @@
"mixins": [ "mixins": [
], ],
"server": [ "server": [
"MixinServerPlayNetworkHandler",
"MixinPlayerManager", "MixinPlayerManager",
"MixinPlayerEntity" "MixinPlayerEntity"
], ],