Allow security hand shakes for monitorables.

This commit is contained in:
AlgorithmX2 2014-04-17 22:33:48 -05:00
parent cb81f34db3
commit a4eb01b191
11 changed files with 75 additions and 15 deletions

View file

@ -3,6 +3,7 @@ package appeng.core.features.registries.entries;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IExternalStorageHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
@ -18,7 +19,7 @@ public class ExternalIInv implements IExternalStorageHandler
}
@Override
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel)
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src)
{
if ( channel == StorageChannel.ITEMS && te instanceof IInventory )
return new MEMonitorIInventory( (IInventory) te, d );

View file

@ -158,10 +158,10 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
IAEItemStack req = config.getAEStackInSlot( slot );
if ( req != null && req.getStackSize() <= 0 )
{
config.setInventorySlotContents(slot, null);
config.setInventorySlotContents( slot, null );
req = null;
}
ItemStack Stored = storage.getStackInSlot( slot );
if ( req == null && Stored != null )
@ -478,6 +478,29 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
{
// TODO Auto-generated method stub
}
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src, IStorageMonitorable myInterface)
{
if ( Platform.canAccess( gridProxy, src ) )
return myInterface;
final DualityInterface di = this;
return new IStorageMonitorable() {
@Override
public IMEMonitor<IAEItemStack> getItemInventory()
{
return new InterfaceInventory( di );
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
return null;
}
};
};
}

View file

@ -2,6 +2,7 @@ package appeng.integration.modules.helpers;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IExternalStorageHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
@ -17,7 +18,7 @@ public class BCPipeHandler implements IExternalStorageHandler
}
@Override
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan)
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource src)
{
if ( chan == StorageChannel.ITEMS )
return new BCPipeInventory( te, d );

View file

@ -2,6 +2,7 @@ package appeng.integration.modules.helpers;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IExternalStorageHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
@ -17,7 +18,7 @@ public class FactorizationHandler implements IExternalStorageHandler
}
@Override
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan)
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource src)
{
if ( chan == StorageChannel.ITEMS )
return FZ.instance.getFactorizationBarrel( te );

View file

@ -2,6 +2,7 @@ package appeng.integration.modules.helpers;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IExternalStorageHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
@ -17,7 +18,7 @@ public class MFRDSUHandler implements IExternalStorageHandler
}
@Override
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan)
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource src)
{
if ( chan == StorageChannel.ITEMS )
return DSU.instance.getDSU( te );

View file

@ -3,6 +3,7 @@ package appeng.me.storage;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.tiles.ITileStorageMonitorable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IExternalStorageHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IStorageMonitorable;
@ -24,7 +25,7 @@ public class AEExternalHandler implements IExternalStorageHandler
}
@Override
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel)
public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src)
{
if ( te instanceof TileCondenser )
{
@ -37,7 +38,7 @@ public class AEExternalHandler implements IExternalStorageHandler
if ( te instanceof ITileStorageMonitorable )
{
ITileStorageMonitorable iface = (ITileStorageMonitorable) te;
IStorageMonitorable sm = iface.getMonitorable( d );
IStorageMonitorable sm = iface.getMonitorable( d, src );
if ( channel == StorageChannel.ITEMS && sm != null )
{

View file

@ -12,6 +12,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.tiles.ISegmentedInventory;
import appeng.api.implementations.tiles.ITileStorageMonitorable;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
@ -277,8 +278,8 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISeg
}
@Override
public IStorageMonitorable getMonitorable(ForgeDirection side)
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
{
return this;
return duality.getMonitorable( side, src, this );
}
}

View file

@ -219,7 +219,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
IExternalStorageHandler esh = AEApi.instance().registries().externalStorage().getHandler( target, side.getOpposite(), StorageChannel.ITEMS );
if ( esh != null )
{
IMEInventory inv = esh.getInventory( target, side.getOpposite(), StorageChannel.ITEMS );
IMEInventory inv = esh.getInventory( target, side.getOpposite(), StorageChannel.ITEMS, mySrc );
if ( inv instanceof MEMonitorIInventory )
((MEMonitorIInventory) inv).mySource = new MachineSource( this );

View file

@ -10,6 +10,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.tiles.ISegmentedInventory;
import appeng.api.implementations.tiles.ITileStorageMonitorable;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
@ -191,9 +192,9 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, IS
}
@Override
public IStorageMonitorable getMonitorable(ForgeDirection side)
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
{
return this;
return duality.getMonitorable( side, src, this );
}
@Override

View file

@ -706,9 +706,11 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
}
@Override
public IStorageMonitorable getMonitorable(ForgeDirection side)
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
{
return this;
if ( Platform.canAccess( gridProxy, src ) )
return this;
return null;
}
public ItemStack getStorageType()

View file

@ -62,7 +62,10 @@ import appeng.api.networking.IGrid;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.security.PlayerSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitorHandlerReceiver;
@ -76,7 +79,9 @@ import appeng.api.util.AEItemDefinition;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.me.GridAccessException;
import appeng.me.GridNode;
import appeng.me.helpers.AENetworkProxy;
import appeng.server.AccessType;
import appeng.util.item.AEItemStack;
import appeng.util.item.AESharedNBT;
@ -1516,4 +1521,27 @@ public class Platform
player.rotationYaw = player.prevCameraYaw = player.cameraYaw = yaw;
}
public static boolean canAccess(AENetworkProxy gridProxy, BaseActionSource src)
{
try
{
if ( src.isPlayer() )
{
return gridProxy.getSecurity().hasPermission( ((PlayerSource) src).player, SecurityPermissions.BUILD );
}
else if ( src.isMachine() )
{
IActionHost te = ((MachineSource) src).via;
int playerID = te.getActionableNode().getPlayerID();
return gridProxy.getSecurity().hasPermission( playerID, SecurityPermissions.BUILD );
}
else
return false;
}
catch (GridAccessException gae)
{
return false;
}
}
}