validate player has the prereq self infusion before doing what player has requested (#54)

This commit is contained in:
Glease authored and GitHub committed 2023-08-02 17:43:30 +08:00
1 parent 1e1aab9c7d
commit 68f767e728
4 files changed
+47 -8

No files matched your search

@@ -38,6 +38,9 @@ public class PacketFingersToServer implements IMessage, IMessageHandler<PacketFi
}
public IMessage onMessage(final PacketFingersToServer message, final MessageContext ctx) {
if (!PacketHandler.selfInfusionSecurityCheck(ctx, "open workbench", message.playerid, 2)) {
return null;
}
final World world = DimensionManager.getWorld(message.dim);
final EntityPlayer player = (EntityPlayer) world.getEntityByID(message.playerid);
player.openGui(
@@ -4,13 +4,23 @@
package com.kentington.thaumichorizons.common.lib.networking;
import net.minecraft.entity.player.EntityPlayerMP;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import com.kentington.thaumichorizons.common.ThaumicHorizons;
import com.kentington.thaumichorizons.common.lib.EntityInfusionProperties;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
public class PacketHandler {
public static final SimpleNetworkWrapper INSTANCE;
private static final Marker SECURITY_MARKER = MarkerManager.getMarker("SuspiciousPackets");
public static void init() {
int idx = 0;
@@ -49,4 +59,26 @@ public class PacketHandler {
static {
INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("ThaumicHorizons".toLowerCase());
}
private static void securityWarn(String message, Object... args) {
ThaumicHorizons.log.warn(SECURITY_MARKER, message, args);
}
static boolean selfInfusionSecurityCheck(final MessageContext ctx, String action, int sentPlayerID,
int requiredInfusion) {
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
if (player.getEntityId() != sentPlayerID) {
PacketHandler.securityWarn("Player {} tried to {} for other people!", player.getGameProfile(), action);
return false;
}
EntityInfusionProperties ieep = (EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion");
if (!ieep.hasInfusion(requiredInfusion)) {
PacketHandler.securityWarn(
"Player {} tried to {} getting the ability legitimately",
player.getGameProfile(),
action);
return false;
}
return true;
}
}
@@ -38,6 +38,9 @@ public class PacketToggleClimbToServer implements IMessage, IMessageHandler<Pack
}
public IMessage onMessage(final PacketToggleClimbToServer message, final MessageContext ctx) {
if (!PacketHandler.selfInfusionSecurityCheck(ctx, "toggle spider climb", message.playerid, 9)) {
return null;
}
final World world = DimensionManager.getWorld(message.dim);
final EntityPlayer player = (EntityPlayer) world.getEntityByID(message.playerid);
((EntityInfusionProperties) player
@@ -7,10 +7,9 @@ package com.kentington.thaumichorizons.common.lib.networking;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import com.kentington.thaumichorizons.common.lib.EntityInfusionProperties;
@@ -43,12 +42,14 @@ public class PacketToggleInvisibleToServer
}
public IMessage onMessage(final PacketToggleInvisibleToServer message, final MessageContext ctx) {
final World world = DimensionManager.getWorld(message.dim);
final EntityPlayer player = (EntityPlayer) world.getEntityByID(message.playerid);
((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleInvisible = !((EntityInfusionProperties) player
.getExtendedProperties("CreatureInfusion")).toggleInvisible;
if (((EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion")).toggleInvisible) {
if (!PacketHandler
.selfInfusionSecurityCheck(ctx, "toggle chamelon skin (i.e. invisible)", message.playerid, 10)) {
return null;
}
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
EntityInfusionProperties ieep = (EntityInfusionProperties) player.getExtendedProperties("CreatureInfusion");
ieep.toggleInvisible = !ieep.toggleInvisible;
if (ieep.toggleInvisible) {
player.removePotionEffect(Potion.invisibility.id);
player.setInvisible(false);
} else {