From 14b7fe8a42cc3d2065bde633a9639ea17fce0e49 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 12 May 2014 23:15:46 -0500 Subject: [PATCH] Add better custom security features. --- helpers/PlayerSecuirtyWrapper.java | 23 +++++++++++++++++++++++ items/tools/ToolBiometricCard.java | 7 +++++++ me/cache/SecurityCache.java | 14 +++++++------- tile/misc/TileSecurity.java | 12 ++++++++++-- 4 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 helpers/PlayerSecuirtyWrapper.java diff --git a/helpers/PlayerSecuirtyWrapper.java b/helpers/PlayerSecuirtyWrapper.java new file mode 100644 index 00000000..da31fd79 --- /dev/null +++ b/helpers/PlayerSecuirtyWrapper.java @@ -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> target; + + public PlayerSecuirtyWrapper(HashMap> playerPerms) { + target = playerPerms; + } + + @Override + public void addPlayer(int PlayerID, EnumSet permissions) + { + target.put( PlayerID, permissions ); + } +} diff --git a/items/tools/ToolBiometricCard.java b/items/tools/ToolBiometricCard.java index d34a7489..3690e71a 100644 --- a/items/tools/ToolBiometricCard.java +++ b/items/tools/ToolBiometricCard.java @@ -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 ) ); + } } diff --git a/me/cache/SecurityCache.java b/me/cache/SecurityCache.java index 6b61023a..ffa3e079 100644 --- a/me/cache/SecurityCache.java +++ b/me/cache/SecurityCache.java @@ -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 securityProvider = new ArrayList(); + private List securityProvider = new ArrayList(); private HashMap> playerPerms = new HashMap>(); 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 diff --git a/tile/misc/TileSecurity.java b/tile/misc/TileSecurity.java index 8bb2c6f6..311504d9 100644 --- a/tile/misc/TileSecurity.java +++ b/tile/misc/TileSecurity.java @@ -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; + } + }