Implemented "Use Blank Security Cards to Set Default Security Permissions". Fixed #2036
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
- Fixed Crafting Manager displaying wrong name for chained crafters connected to some blocks (raoulvdberge)
|
||||
- Removed handling of reusable items in autocrafting, to avoid problems (raoulvdberge)
|
||||
- You can no longer start a crafting task if it has missing items or fluids (raoulvdberge)
|
||||
- The Security Manager now supports Security Cards that have no player assigned to them. It is the default security card for players that aren't configured (raoulvdberge)
|
||||
- If no default Security Card is configured in the Security Manager, an unconfigured player is allowed to do everything in the network. Create a default Security Card (craft a Security Craft and don't assign it to a player, it acts as a fallback) to handle unconfigured players (raoulvdberge)
|
||||
|
||||
### 1.6.5
|
||||
- Fixed Refined Storage silicon's oredict entry being registered too late (raoulvdberge)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.api.network.security;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -7,8 +8,9 @@ import java.util.UUID;
|
||||
*/
|
||||
public interface ISecurityCard {
|
||||
/**
|
||||
* @return the owner of this card
|
||||
* @return the owner of this card, or null if this is a global card
|
||||
*/
|
||||
@Nullable
|
||||
UUID getOwner();
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.api.network.security;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -7,7 +8,13 @@ import java.util.List;
|
||||
*/
|
||||
public interface ISecurityCardContainer {
|
||||
/**
|
||||
* @return the security cards in this container
|
||||
* @return the security cards in this container, {@link ISecurityCard#getOwner()} CANNOT be null for any card in this list!
|
||||
*/
|
||||
List<ISecurityCard> getCards();
|
||||
|
||||
/**
|
||||
* @return the global security card in this container, or null if there is none, {@link ISecurityCard#getOwner()}) can be null!
|
||||
*/
|
||||
@Nullable
|
||||
ISecurityCard getGlobalCard();
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ public interface ISecurityManager {
|
||||
boolean hasPermission(Permission permission, EntityPlayer player);
|
||||
|
||||
/**
|
||||
* Rebuilds the security list.
|
||||
* Invalidates the security list.
|
||||
*/
|
||||
void rebuild();
|
||||
void invalidate();
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -26,19 +27,20 @@ import java.util.UUID;
|
||||
public class NetworkNodeSecurityManager extends NetworkNode implements ISecurityCardContainer {
|
||||
public static final String ID = "security_manager";
|
||||
|
||||
private List<ISecurityCard> actualCards = new ArrayList<>();
|
||||
private List<ISecurityCard> cards = new ArrayList<>();
|
||||
private ISecurityCard globalCard;
|
||||
|
||||
private ItemHandlerBase cards = new ItemHandlerBase(9 * 2, new ListenerNetworkNode(this), new ItemValidatorBasic(RSItems.SECURITY_CARD)) {
|
||||
private ItemHandlerBase cardsInv = new ItemHandlerBase(9 * 2, new ListenerNetworkNode(this), new ItemValidatorBasic(RSItems.SECURITY_CARD)) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
if (!world.isRemote) {
|
||||
rebuildCards();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
if (network != null) {
|
||||
network.getSecurityManager().rebuild();
|
||||
network.getSecurityManager().invalidate();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -52,8 +54,8 @@ public class NetworkNodeSecurityManager extends NetworkNode implements ISecurity
|
||||
public int getEnergyUsage() {
|
||||
int usage = RS.INSTANCE.config.securityManagerUsage;
|
||||
|
||||
for (int i = 0; i < cards.getSlots(); ++i) {
|
||||
if (!cards.getStackInSlot(i).isEmpty()) {
|
||||
for (int i = 0; i < cardsInv.getSlots(); ++i) {
|
||||
if (!cardsInv.getStackInSlot(i).isEmpty()) {
|
||||
usage += RS.INSTANCE.config.securityManagerPerSecurityCardUsage;
|
||||
}
|
||||
}
|
||||
@@ -66,39 +68,46 @@ public class NetworkNodeSecurityManager extends NetworkNode implements ISecurity
|
||||
super.update();
|
||||
|
||||
if (ticks == 1) {
|
||||
rebuildCards();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildCards() {
|
||||
actualCards.clear();
|
||||
private void invalidate() {
|
||||
this.cards.clear();
|
||||
this.globalCard = null;
|
||||
|
||||
for (int i = 0; i < cards.getSlots(); ++i) {
|
||||
ItemStack stack = cards.getStackInSlot(i);
|
||||
for (int i = 0; i < cardsInv.getSlots(); ++i) {
|
||||
ItemStack stack = cardsInv.getStackInSlot(i);
|
||||
|
||||
if (!stack.isEmpty()) {
|
||||
UUID uuid = ItemSecurityCard.getOwner(stack);
|
||||
|
||||
if (uuid == null) {
|
||||
this.globalCard = createCard(stack, null);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
this.cards.add(createCard(stack, uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ISecurityCard createCard(ItemStack stack, @Nullable UUID uuid) {
|
||||
SecurityCard card = new SecurityCard(uuid);
|
||||
|
||||
for (Permission permission : Permission.values()) {
|
||||
card.getPermissions().put(permission, ItemSecurityCard.hasPermission(stack, permission));
|
||||
}
|
||||
|
||||
actualCards.add(card);
|
||||
}
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NBTTagCompound tag) {
|
||||
super.read(tag);
|
||||
|
||||
StackUtils.readItems(cards, 0, tag);
|
||||
StackUtils.readItems(cardsInv, 0, tag);
|
||||
StackUtils.readItems(editCard, 1, tag);
|
||||
}
|
||||
|
||||
@@ -111,7 +120,7 @@ public class NetworkNodeSecurityManager extends NetworkNode implements ISecurity
|
||||
public NBTTagCompound write(NBTTagCompound tag) {
|
||||
super.write(tag);
|
||||
|
||||
StackUtils.writeItems(cards, 0, tag);
|
||||
StackUtils.writeItems(cardsInv, 0, tag);
|
||||
StackUtils.writeItems(editCard, 1, tag);
|
||||
|
||||
return tag;
|
||||
@@ -121,11 +130,11 @@ public class NetworkNodeSecurityManager extends NetworkNode implements ISecurity
|
||||
public void onConnectedStateChange(INetwork network, boolean state) {
|
||||
super.onConnectedStateChange(network, state);
|
||||
|
||||
network.getSecurityManager().rebuild();
|
||||
network.getSecurityManager().invalidate();
|
||||
}
|
||||
|
||||
public ItemHandlerBase getCardsItems() {
|
||||
return cards;
|
||||
return cardsInv;
|
||||
}
|
||||
|
||||
public ItemHandlerBase getEditCard() {
|
||||
@@ -142,12 +151,18 @@ public class NetworkNodeSecurityManager extends NetworkNode implements ISecurity
|
||||
|
||||
@Override
|
||||
public List<ISecurityCard> getCards() {
|
||||
return actualCards;
|
||||
return cards;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ISecurityCard getGlobalCard() {
|
||||
return globalCard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getDrops() {
|
||||
return new CombinedInvWrapper(cards, editCard);
|
||||
return new CombinedInvWrapper(cardsInv, editCard);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.security;
|
||||
import com.raoulvdberge.refinedstorage.api.network.security.ISecurityCard;
|
||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -11,7 +12,7 @@ public class SecurityCard implements ISecurityCard {
|
||||
private UUID owner;
|
||||
private Map<Permission, Boolean> permissions = new HashMap<>();
|
||||
|
||||
public SecurityCard(UUID owner) {
|
||||
public SecurityCard(@Nullable UUID owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@@ -20,6 +21,7 @@ public class SecurityCard implements ISecurityCard {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public UUID getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ import java.util.UUID;
|
||||
public class SecurityManager implements ISecurityManager {
|
||||
private INetwork network;
|
||||
private Map<UUID, ISecurityCard> cards = new HashMap<>();
|
||||
private ISecurityCard globalCard;
|
||||
|
||||
public SecurityManager(INetwork network) {
|
||||
this.network = network;
|
||||
@@ -26,27 +27,42 @@ public class SecurityManager implements ISecurityManager {
|
||||
public boolean hasPermission(Permission permission, EntityPlayer player) {
|
||||
UserListOps ops = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getOppedPlayers();
|
||||
|
||||
if (cards.isEmpty() || ops.getEntry(player.getGameProfile()) != null) {
|
||||
if (ops.getEntry(player.getGameProfile()) != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
UUID uuid = player.getGameProfile().getId();
|
||||
|
||||
if (!cards.containsKey(uuid)) {
|
||||
return false;
|
||||
if (globalCard != null) {
|
||||
return globalCard.hasPermission(permission);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return cards.get(uuid).hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebuild() {
|
||||
cards.clear();
|
||||
public void invalidate() {
|
||||
this.cards.clear();
|
||||
this.globalCard = null;
|
||||
|
||||
for (INetworkNode node : network.getNodeGraph().all()) {
|
||||
if (node instanceof ISecurityCardContainer && node.canUpdate()) {
|
||||
for (ISecurityCard card : ((ISecurityCardContainer) node).getCards()) {
|
||||
cards.put(card.getOwner(), card);
|
||||
ISecurityCardContainer container = (ISecurityCardContainer) node;
|
||||
|
||||
for (ISecurityCard card : container.getCards()) {
|
||||
if (card.getOwner() == null) {
|
||||
throw new IllegalStateException("Owner in #getCards() cannot be null!");
|
||||
}
|
||||
|
||||
this.cards.put(card.getOwner(), card);
|
||||
}
|
||||
|
||||
if (container.getGlobalCard() != null) {
|
||||
this.globalCard = container.getGlobalCard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ public abstract class BlockNodeProxy extends BlockBase {
|
||||
if (!node.getNetwork().getSecurityManager().hasPermission(permission, player)) {
|
||||
WorldUtils.sendNoPermissionMessage(player);
|
||||
|
||||
return false;
|
||||
return true; // Avoid placing blocks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -93,5 +93,11 @@ public class ItemSecurityCard extends ItemBase {
|
||||
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_OWNER_NAME)) {
|
||||
tooltip.add(I18n.format("item.refinedstorage:security_card.owner", stack.getTagCompound().getString(NBT_OWNER_NAME)));
|
||||
}
|
||||
|
||||
for (Permission permission : Permission.values()) {
|
||||
if (hasPermission(stack, permission)) {
|
||||
tooltip.add("- " + I18n.format("gui.refinedstorage:security_manager.permission." + permission.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -232,7 +232,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
|
||||
throttlingDisabled = false;
|
||||
|
||||
nodeGraph.rebuild();
|
||||
securityManager.rebuild();
|
||||
securityManager.invalidate();
|
||||
}
|
||||
} else {
|
||||
ticksSinceUpdateChanged = 0;
|
||||
|
Reference in New Issue
Block a user