Add better custom security features.
This commit is contained in:
parent
ff12aa1673
commit
14b7fe8a42
4 changed files with 47 additions and 9 deletions
23
helpers/PlayerSecuirtyWrapper.java
Normal file
23
helpers/PlayerSecuirtyWrapper.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package appeng.helpers;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.security.ISecurityRegister;
|
||||
|
||||
public class PlayerSecuirtyWrapper implements ISecurityRegister
|
||||
{
|
||||
|
||||
final HashMap<Integer, EnumSet<SecurityPermissions>> target;
|
||||
|
||||
public PlayerSecuirtyWrapper(HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms) {
|
||||
target = playerPerms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(int PlayerID, EnumSet<SecurityPermissions> permissions)
|
||||
{
|
||||
target.put( PlayerID, permissions );
|
||||
}
|
||||
}
|
|
@ -10,7 +10,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.features.IPlayerRegistry;
|
||||
import appeng.api.implementations.items.IBiometricCard;
|
||||
import appeng.api.networking.security.ISecurityRegister;
|
||||
import appeng.client.render.items.ToolBiometricCardRender;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
|
@ -148,4 +150,9 @@ public class ToolBiometricCard extends AEBaseItem implements IBiometricCard
|
|||
tag.setBoolean( permission.name(), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPermissions(ISecurityRegister register, IPlayerRegistry pr, ItemStack is)
|
||||
{
|
||||
register.addPlayer( pr.getID( getUsername( is ) ), getPermissions( is ) );
|
||||
}
|
||||
}
|
||||
|
|
14
me/cache/SecurityCache.java
vendored
14
me/cache/SecurityCache.java
vendored
|
@ -15,14 +15,14 @@ import appeng.api.networking.IGridStorage;
|
|||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkSecurityChange;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.networking.security.ISecurityProvider;
|
||||
import appeng.core.WorldSettings;
|
||||
import appeng.me.GridNode;
|
||||
import appeng.tile.misc.TileSecurity;
|
||||
|
||||
public class SecurityCache implements IGridCache, ISecurityGrid
|
||||
{
|
||||
|
||||
private List<TileSecurity> securityProvider = new ArrayList();
|
||||
private List<ISecurityProvider> securityProvider = new ArrayList();
|
||||
private HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms = new HashMap<Integer, EnumSet<SecurityPermissions>>();
|
||||
|
||||
public SecurityCache(IGrid g) {
|
||||
|
@ -84,7 +84,7 @@ public class SecurityCache implements IGridCache, ISecurityGrid
|
|||
long lastCode = securityKey;
|
||||
|
||||
if ( securityProvider.size() == 1 )
|
||||
securityKey = securityProvider.get( 0 ).securityKey;
|
||||
securityKey = securityProvider.get( 0 ).getSecurityKey();
|
||||
else
|
||||
securityKey = -1;
|
||||
|
||||
|
@ -99,9 +99,9 @@ public class SecurityCache implements IGridCache, ISecurityGrid
|
|||
@Override
|
||||
public void removeNode(IGridNode gridNode, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof TileSecurity )
|
||||
if ( machine instanceof ISecurityProvider )
|
||||
{
|
||||
securityProvider.remove( (TileSecurity) machine );
|
||||
securityProvider.remove( (ISecurityProvider) machine );
|
||||
updateSecurityKey();
|
||||
}
|
||||
}
|
||||
|
@ -109,9 +109,9 @@ public class SecurityCache implements IGridCache, ISecurityGrid
|
|||
@Override
|
||||
public void addNode(IGridNode gridNode, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof TileSecurity )
|
||||
if ( machine instanceof ISecurityProvider )
|
||||
{
|
||||
securityProvider.add( (TileSecurity) machine );
|
||||
securityProvider.add( (ISecurityProvider) machine );
|
||||
updateSecurityKey();
|
||||
}
|
||||
else
|
||||
|
|
|
@ -31,6 +31,7 @@ import appeng.api.networking.events.MENetworkChannelsChanged;
|
|||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.events.MENetworkSecurityChange;
|
||||
import appeng.api.networking.security.ISecurityProvider;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
|
@ -40,6 +41,7 @@ import appeng.api.storage.data.IAEItemStack;
|
|||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.helpers.PlayerSecuirtyWrapper;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.SecurityInventory;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
|
@ -53,7 +55,7 @@ import appeng.util.IConfigManagerHost;
|
|||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost
|
||||
public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost, ISecurityProvider
|
||||
{
|
||||
|
||||
private static int diffrence = 0;
|
||||
|
@ -205,7 +207,7 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
|||
if ( i instanceof IBiometricCard )
|
||||
{
|
||||
IBiometricCard bc = (IBiometricCard) i;
|
||||
playerPerms.put( pr.getID( bc.getUsername( is ) ), bc.getPermissions( is ) );
|
||||
bc.registerPermissions( new PlayerSecuirtyWrapper( playerPerms ), pr, is );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,4 +308,10 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSecurityKey()
|
||||
{
|
||||
return securityKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue