mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-10-02 17:12:57 -04:00
Re-did container permissions
This commit is contained in:
@@ -26,182 +26,38 @@
|
||||
******************************************************************************/
|
||||
package resources.containers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import resources.network.NetBufferStream;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.persistable.Persistable;
|
||||
|
||||
/**
|
||||
* Structure for creating permission sets that will allow the object to be viewed/modified/added/removed by a requested
|
||||
* object depending on the implemented abstract methods.
|
||||
* @author Waverunner
|
||||
*/
|
||||
public abstract class ContainerPermissions implements Persistable {
|
||||
|
||||
public static final WorldPermissions WORLD = new WorldPermissions();
|
||||
public static final InventoryPermissions INVENTORY = new InventoryPermissions();
|
||||
|
||||
private Map<String, Integer> permissionGroups;
|
||||
private List<String> joinedGroups;
|
||||
|
||||
public abstract class ContainerPermissions {
|
||||
|
||||
public ContainerPermissions() {
|
||||
this.permissionGroups = new HashMap<>();
|
||||
this.joinedGroups = new ArrayList<>();
|
||||
}
|
||||
|
||||
protected boolean hasPermissions(String group, Permission... permissions) {
|
||||
if (!hasPermissionGroup(group))
|
||||
return false;
|
||||
|
||||
EnumSet<Permission> groupPermissions = Permission.getFlags(permissionGroups.get(group));
|
||||
|
||||
for (Permission permission : permissions) {
|
||||
if (!groupPermissions.contains(permission))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasPermissions(List<String> requesterGroups, Permission ... permission) {
|
||||
for (String group : requesterGroups) {
|
||||
if (hasPermissions(group, permission))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addPermissions(String group, Permission... permissions) {
|
||||
if (!hasPermissionGroup(group)) {
|
||||
permissionGroups.put(group, Permission.valueOf(permissions));
|
||||
return;
|
||||
}
|
||||
|
||||
EnumSet<Permission> groupPermissions = Permission.getFlags(permissionGroups.get(group));
|
||||
|
||||
for (Permission permission : permissions) {
|
||||
groupPermissions.add(permission);
|
||||
}
|
||||
|
||||
synchronized (permissionGroups) {
|
||||
permissionGroups.put(group, Permission.valueOf(groupPermissions));
|
||||
}
|
||||
}
|
||||
|
||||
public void removePermissions(String group, Permission... permissions) {
|
||||
|
||||
if (!hasPermissionGroup(group))
|
||||
return;
|
||||
|
||||
EnumSet<Permission> groupPermissions = Permission.getFlags(permissionGroups.get(group));
|
||||
|
||||
for (Permission permission : permissions) {
|
||||
groupPermissions.add(permission);
|
||||
}
|
||||
|
||||
synchronized (permissionGroups) {
|
||||
permissionGroups.put(group, Permission.valueOf(groupPermissions));
|
||||
}
|
||||
}
|
||||
|
||||
public void clearPermissions(String group) {
|
||||
synchronized (permissionGroups) {
|
||||
if (permissionGroups.containsKey(group))
|
||||
permissionGroups.put(group, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPermissionGroup(String group) {
|
||||
return permissionGroups.containsKey(group);
|
||||
}
|
||||
|
||||
public Set<String> getPermissionGroups() {
|
||||
synchronized(permissionGroups) {
|
||||
return permissionGroups.keySet();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getJoinedGroups() {
|
||||
return joinedGroups;
|
||||
}
|
||||
|
||||
public void addDefaultWorldPermissions() {
|
||||
addPermissions("world", Permission.VIEW, Permission.ENTER);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NetBufferStream stream) {
|
||||
stream.addByte(0);
|
||||
synchronized (permissionGroups) {
|
||||
stream.addMap(permissionGroups, (e) -> {
|
||||
stream.addAscii(e.getKey());
|
||||
stream.addInt(e.getValue());
|
||||
});
|
||||
}
|
||||
synchronized (joinedGroups) {
|
||||
stream.addList(joinedGroups, (g) -> stream.addAscii(g));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NetBufferStream stream) {
|
||||
stream.getByte();
|
||||
stream.getList((i) -> permissionGroups.put(stream.getAscii(), stream.getInt()));
|
||||
stream.getList((i) -> joinedGroups.add(stream.getAscii()));
|
||||
}
|
||||
|
||||
public abstract boolean canView(SWGObject viewer, SWGObject container);
|
||||
public abstract boolean canEnter(SWGObject requester, SWGObject container);
|
||||
public abstract boolean canRemove(SWGObject requester, SWGObject container);
|
||||
public abstract boolean canMove(SWGObject requester, SWGObject container);
|
||||
public abstract boolean canAdd(SWGObject requester, SWGObject container);
|
||||
|
||||
public enum Permission {
|
||||
VIEW(1),
|
||||
REMOVE(1<<1),
|
||||
ADD(1<<2),
|
||||
MOVE(1<<3),
|
||||
ENTER(1<<4);
|
||||
|
||||
int bitmask;
|
||||
|
||||
Permission(int bitmask) {
|
||||
this.bitmask = bitmask;
|
||||
}
|
||||
|
||||
public static EnumSet<Permission> getFlags(int bits) {
|
||||
EnumSet <Permission> states = EnumSet.noneOf(Permission.class);
|
||||
for (Permission state : values()) {
|
||||
if ((state.bitmask & bits) != 0)
|
||||
states.add(state);
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
public static int valueOf(EnumSet<Permission> bitmaskSet) {
|
||||
int value = 0;
|
||||
|
||||
for (Permission permission : bitmaskSet) {
|
||||
value += permission.bitmask;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int valueOf(Permission... permissions) {
|
||||
int value = 0;
|
||||
|
||||
for (Permission permission : permissions) {
|
||||
value += permission.bitmask;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean canView(SWGObject container) {
|
||||
return canView(null, container);
|
||||
}
|
||||
|
||||
public boolean canEnter(SWGObject container) {
|
||||
return canEnter(null, container);
|
||||
}
|
||||
|
||||
public boolean canRemove(SWGObject container) {
|
||||
return canRemove(null, container);
|
||||
}
|
||||
|
||||
public boolean canMove(SWGObject container) {
|
||||
return canMove(null, container);
|
||||
}
|
||||
|
||||
public boolean canAdd(SWGObject container) {
|
||||
return canAdd(null, container);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+29
-29
@@ -27,40 +27,40 @@
|
||||
***********************************************************************************/
|
||||
package resources.containers;
|
||||
|
||||
import resources.network.NetBufferStream;
|
||||
import resources.objects.SWGObject;
|
||||
|
||||
public class ContainerPermissionsFactory {
|
||||
public enum ContainerPermissionsType {
|
||||
DEFAULT (new DefaultPermissions()),
|
||||
INVENTORY (new InventoryPermissions());
|
||||
|
||||
public static ContainerPermissions create(NetBufferStream stream) {
|
||||
ContainerPermissions permissions;
|
||||
byte type = stream.getByte();
|
||||
switch (type) {
|
||||
case 1:
|
||||
permissions = new DefaultPermissions();
|
||||
break;
|
||||
case 2:
|
||||
permissions = new InventoryPermissions();
|
||||
break;
|
||||
case 3:
|
||||
permissions = new WorldPermissions();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown type byte! Type: " + type);
|
||||
}
|
||||
permissions.read(stream);
|
||||
private final ContainerPermissions permissions;
|
||||
|
||||
ContainerPermissionsType(ContainerPermissions permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public ContainerPermissions getContainerPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public static void save(ContainerPermissions permissions, NetBufferStream stream) {
|
||||
if (permissions instanceof DefaultPermissions)
|
||||
stream.addByte(1);
|
||||
else if (permissions instanceof InventoryPermissions)
|
||||
stream.addByte(2);
|
||||
else if (permissions instanceof WorldPermissions)
|
||||
stream.addByte(3);
|
||||
else
|
||||
throw new IllegalArgumentException("Unknown permissions type! Permissions: " + permissions);
|
||||
permissions.save(stream);
|
||||
public boolean canView(SWGObject viewer, SWGObject container) {
|
||||
return permissions.canView(viewer, container);
|
||||
}
|
||||
|
||||
public boolean canEnter(SWGObject viewer, SWGObject container) {
|
||||
return permissions.canEnter(viewer, container);
|
||||
}
|
||||
|
||||
public boolean canRemove(SWGObject viewer, SWGObject container) {
|
||||
return permissions.canRemove(viewer, container);
|
||||
}
|
||||
|
||||
public boolean canMove(SWGObject viewer, SWGObject container) {
|
||||
return permissions.canMove(viewer, container);
|
||||
}
|
||||
|
||||
public boolean canAdd(SWGObject viewer, SWGObject container) {
|
||||
return permissions.canAdd(viewer, container);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,39 +34,39 @@ import resources.objects.SWGObject;
|
||||
* for every new object.
|
||||
* @author Waverunner
|
||||
*/
|
||||
public class DefaultPermissions extends ContainerPermissions {
|
||||
class DefaultPermissions extends ContainerPermissions {
|
||||
|
||||
@Override
|
||||
public boolean canView(SWGObject requester, SWGObject container) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canEnter(SWGObject requester, SWGObject container) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canRemove(SWGObject requester, SWGObject container) {
|
||||
if (requester.getOwner() == null)
|
||||
if (requester == null || requester.getOwner() == null)
|
||||
return true;
|
||||
if (container.getOwner() == null)
|
||||
return false;
|
||||
return requester.getOwner().equals(container.getOwner());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canMove(SWGObject requester, SWGObject container) {
|
||||
if (requester.getOwner() == null)
|
||||
if (requester == null || requester.getOwner() == null)
|
||||
return true;
|
||||
if (container.getOwner() == null)
|
||||
return false;
|
||||
return requester.getOwner().equals(container.getOwner());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canAdd(SWGObject requester, SWGObject container) {
|
||||
if (requester.getOwner() == null)
|
||||
if (requester == null || requester.getOwner() == null)
|
||||
return true;
|
||||
if (container.getOwner() == null)
|
||||
return false;
|
||||
|
||||
@@ -29,16 +29,11 @@ package resources.containers;
|
||||
|
||||
import resources.objects.SWGObject;
|
||||
|
||||
/**
|
||||
* This set of permissions will allow only the owner to view the container.
|
||||
*
|
||||
* @author Waverunner
|
||||
*/
|
||||
public class InventoryPermissions extends DefaultPermissions {
|
||||
class InventoryPermissions extends DefaultPermissions {
|
||||
|
||||
@Override
|
||||
public boolean canView(SWGObject requester, SWGObject container) {
|
||||
if (requester.getOwner() == null)
|
||||
if (requester == null || requester.getOwner() == null)
|
||||
return true;
|
||||
if (container.getOwner() == null)
|
||||
return false;
|
||||
@@ -47,7 +42,7 @@ public class InventoryPermissions extends DefaultPermissions {
|
||||
|
||||
@Override
|
||||
public boolean canEnter(SWGObject requester, SWGObject container) {
|
||||
if (requester.getOwner() == null)
|
||||
if (requester == null || requester.getOwner() == null)
|
||||
return true;
|
||||
if (container.getOwner() == null)
|
||||
return false;
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 /// Project SWG /// www.projectswg.com
|
||||
*
|
||||
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on
|
||||
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies.
|
||||
* Our goal is to create an emulator which will provide a server for players to
|
||||
* continue playing a game similar to the one they used to play. We are basing
|
||||
* it on the final publish of the game prior to end-game events.
|
||||
*
|
||||
* This file is part of Holocore.
|
||||
*
|
||||
* --------------------------------------------------------------------------------
|
||||
*
|
||||
* Holocore is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Holocore is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Holocore. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
|
||||
package resources.containers;
|
||||
|
||||
import resources.objects.SWGObject;
|
||||
|
||||
/**
|
||||
* This is essentially a universal "all-in-one" permission set for managing permission groups for world objects. This
|
||||
* class makes use of permission groups. Every player joins the world permission group upon creation. When a specific
|
||||
* group is needed, the object will have to remove the world permission set and replace it with their own group of
|
||||
* permissions.
|
||||
* <br><br>Example: In order to allow only certain players into an area of Jabba's palace, you would first
|
||||
* create a permission group for the CellObject with a unique name. Then you need to add the named group to the
|
||||
* players ContainerPermissions joinedGroups list in order for them to properly pass the checks.
|
||||
* <br><br>
|
||||
* This set of permissions will allow:
|
||||
* <OL>
|
||||
* <LI>View - If the viewer has joined a group that is recognized by the container with viewing permissions</LI>
|
||||
* <LI>Enter - If the viewer has joined a group that is recognized by the container with enter permissions</LI>
|
||||
* <LI>Remove, Move, Add - If the container has the same owner as the requester</LI>
|
||||
* </OL>
|
||||
* @author Waverunner
|
||||
*/
|
||||
public class WorldPermissions extends DefaultPermissions {
|
||||
|
||||
@Override
|
||||
public boolean canView(SWGObject viewer, SWGObject container) {
|
||||
if (super.canView(viewer, container))
|
||||
return true;
|
||||
|
||||
return hasPermissions(viewer.getContainerPermissions().getJoinedGroups(), Permission.VIEW);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEnter(SWGObject requester, SWGObject container) {
|
||||
if (super.canView(requester, container))
|
||||
return true;
|
||||
|
||||
return hasPermissions(requester.getContainerPermissions().getJoinedGroups(), Permission.ENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemove(SWGObject requester, SWGObject container) {
|
||||
return super.canRemove(requester, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMove(SWGObject requester, SWGObject container) {
|
||||
return super.canMove(requester, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAdd(SWGObject requester, SWGObject container) {
|
||||
return super.canAdd(requester, container);
|
||||
}
|
||||
}
|
||||
@@ -42,11 +42,8 @@ import resources.Terrain;
|
||||
import resources.buildout.BuildoutArea;
|
||||
import resources.client_info.visitors.ObjectData.ObjectDataAttribute;
|
||||
import resources.common.CRC;
|
||||
import resources.containers.ContainerPermissions;
|
||||
import resources.containers.ContainerPermissionsFactory;
|
||||
import resources.containers.ContainerPermissionsType;
|
||||
import resources.containers.ContainerResult;
|
||||
import resources.containers.DefaultPermissions;
|
||||
import resources.containers.ContainerPermissions.Permission;
|
||||
import resources.encodables.StringId;
|
||||
import resources.network.BaselineBuilder;
|
||||
import resources.network.BaselineObject;
|
||||
@@ -66,42 +63,40 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class SWGObject extends BaselineObject implements Comparable<SWGObject>, Persistable {
|
||||
|
||||
private final Location location;
|
||||
private final long objectId;
|
||||
private final HashMap <String, SWGObject> slots; // HashMap used for null value support
|
||||
private final Set<SWGObject> containedObjects;
|
||||
private final Map <String, String> attributes;
|
||||
private final Map <ObjectDataAttribute, Object> dataAttributes;
|
||||
private transient Set <SWGObject> objectsAware;
|
||||
private transient Set <SWGObject> customAware;
|
||||
private transient BuildoutArea buildoutArea;
|
||||
private transient Player owner;
|
||||
private List <List <String>> arrangement;
|
||||
|
||||
private ObjectClassification classification = ObjectClassification.GENERATED;
|
||||
private GameObjectType gameObjectType = GameObjectType.GOT_NONE;
|
||||
private ContainerPermissions containerPermissions;
|
||||
private SWGObject parent = null;
|
||||
private StringId stringId = new StringId("", "");
|
||||
private StringId detailStringId = new StringId("", "");
|
||||
private String template = "";
|
||||
private int crc = 0;
|
||||
private String objectName = "";
|
||||
private int volume = 0;
|
||||
private float complexity = 1;
|
||||
private int containerType = 0;
|
||||
private double loadRange = 0;
|
||||
private int areaId = -1;
|
||||
|
||||
private int slotArrangement = -1;
|
||||
private final long objectId;
|
||||
private final Location location = new Location();
|
||||
private final Set<SWGObject> containedObjects= new HashSet<>();
|
||||
private final Map <String, String> attributes = new HashMap<>();
|
||||
private final Set <SWGObject> objectsAware = new HashSet<>();
|
||||
private final Set <SWGObject> customAware = new HashSet<>();
|
||||
private final HashMap <String, SWGObject> slots = new HashMap<>(); // HashMap used for null value support
|
||||
private final Map <ObjectDataAttribute, Object> dataAttributes = new HashMap<>();
|
||||
|
||||
private ObjectClassification classification = ObjectClassification.GENERATED;
|
||||
private GameObjectType gameObjectType = GameObjectType.GOT_NONE;
|
||||
private ContainerPermissionsType permissions = ContainerPermissionsType.DEFAULT;
|
||||
private List <List <String>> arrangement = new ArrayList<>();
|
||||
private BuildoutArea buildoutArea = null;
|
||||
private Player owner = null;
|
||||
|
||||
private SWGObject parent = null;
|
||||
private StringId stringId = new StringId("", "");
|
||||
private StringId detailStringId = new StringId("", "");
|
||||
private String template = "";
|
||||
private int crc = 0;
|
||||
private String objectName = "";
|
||||
private int volume = 0;
|
||||
private float complexity = 1;
|
||||
private int containerType = 0;
|
||||
private double loadRange = 0;
|
||||
private int areaId = -1;
|
||||
private int slotArrangement = -1;
|
||||
|
||||
public SWGObject() {
|
||||
this(0, null);
|
||||
@@ -110,16 +105,8 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
public SWGObject(long objectId, BaselineType objectType) {
|
||||
super(objectType);
|
||||
this.objectId = objectId;
|
||||
this.location = new Location();
|
||||
this.objectsAware = new HashSet<>();
|
||||
this.customAware = new HashSet<>();
|
||||
this.slots = new HashMap<>();
|
||||
this.containedObjects = new HashSet<>();
|
||||
this.attributes = new LinkedHashMap<>();
|
||||
this.dataAttributes = new Hashtable<>();
|
||||
this.containerPermissions = new DefaultPermissions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the specified object to this object and places it in the appropriate slot if needed
|
||||
* @param object Object to add to this container, which will either be put into the appropriate slot(s) or become a contained object
|
||||
@@ -229,7 +216,7 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
}
|
||||
|
||||
private ContainerResult moveToContainerChecks(SWGObject requester, SWGObject container) {
|
||||
if(!hasPermission(requester, ContainerPermissions.Permission.MOVE)) {
|
||||
if (!permissions.canMove(requester, this)) {
|
||||
Log.w("SWGObject", "No permission 'MOVE' for requestor %s with object %s", requester, this);
|
||||
return ContainerResult.NO_PERMISSION;
|
||||
}
|
||||
@@ -237,8 +224,8 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
return ContainerResult.SUCCESS;
|
||||
|
||||
// Check if the requester has MOVE permissions to the destination container
|
||||
if (!container.hasPermission(requester, ContainerPermissions.Permission.MOVE)) {
|
||||
Log.w("SWGObject", "No permission 'MOVE' for requestor %s with object %s", requester, this);
|
||||
if (!permissions.canMove(requester, container)) {
|
||||
Log.w("SWGObject", "No permission 'MOVE' for requestor %s with container %s", requester, this);
|
||||
return ContainerResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
@@ -260,106 +247,17 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
slotObj.moveToContainer(oldParent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the passed object has all of the passed permissions
|
||||
* @param object Requester to view this container
|
||||
* @param permissions Permissions to check for
|
||||
* @return
|
||||
*/
|
||||
public boolean hasPermission(SWGObject object, ContainerPermissions.Permission... permissions) {
|
||||
if (object == null)
|
||||
return true;
|
||||
for (ContainerPermissions.Permission permission : permissions) {
|
||||
switch(permission) {
|
||||
case VIEW:
|
||||
if (!containerPermissions.canView(object, this))
|
||||
return false;
|
||||
break;
|
||||
case MOVE:
|
||||
if (!containerPermissions.canMove(object, this))
|
||||
return false;
|
||||
break;
|
||||
case REMOVE:
|
||||
if (!containerPermissions.canRemove(object, this))
|
||||
return false;
|
||||
break;
|
||||
case ADD:
|
||||
if (!containerPermissions.canAdd(object, this))
|
||||
return false;
|
||||
break;
|
||||
case ENTER:
|
||||
if (!containerPermissions.canEnter(object, this))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isVisible(SWGObject target) {
|
||||
if (target == null)
|
||||
return true;
|
||||
if (!hasPermission(target, Permission.VIEW))
|
||||
if (!permissions.canView(target, this))
|
||||
return false;
|
||||
if (getParent() != null)
|
||||
return getParent().isVisible(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new permission group for this object with the given permissions for that group
|
||||
* @param group Name of the permission group
|
||||
* @param permissions Permissions for the group
|
||||
*/
|
||||
public void addPermissions(String group, ContainerPermissions.Permission... permissions) {
|
||||
containerPermissions.addPermissions(group, permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the stated permissions from the group.
|
||||
* @param group Name of the permission group
|
||||
* @param permissions Permissions to remove
|
||||
*/
|
||||
public void removePermissions(String group, ContainerPermissions.Permission... permissions) {
|
||||
containerPermissions.removePermissions(group, permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new permission group specific to the permission requester that has the defined permissions. The name of the
|
||||
* new group for this object will be the objectId of this object plus the objectId of the requester.
|
||||
* <br>This is the same as calling addPermissions(String.valueOf(permissionRequester.getObjectId() + getObjectId()), permissions)
|
||||
* with the added benefit of adding the group to the permissionRequester's joined container groups
|
||||
* @param permissionRequester The object that should be given unique permissions to this object
|
||||
* @param permissions Permissions that the permissionRequester will have for this object
|
||||
*/
|
||||
public void addPermissions(SWGObject permissionRequester, ContainerPermissions.Permission... permissions) {
|
||||
addPermissions(String.valueOf(permissionRequester.getObjectId() + getObjectId()), permissions);
|
||||
permissionRequester.joinPermissionGroup(String.valueOf(getObjectId() + permissionRequester.getObjectId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the unique permissions for the permissionRequester from this object.
|
||||
* @param permissionRequester The object that should no longer have unique permissions to this object
|
||||
*/
|
||||
public void removePermissions(SWGObject permissionRequester) {
|
||||
String group = String.valueOf(permissionRequester.getObjectId() + getObjectId());
|
||||
removePermissions(group);
|
||||
permissionRequester.containerPermissions.getJoinedGroups().remove(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns this object to a permission group
|
||||
* @param group
|
||||
*/
|
||||
public void joinPermissionGroup(String group) {
|
||||
containerPermissions.getJoinedGroups().add(group);
|
||||
}
|
||||
|
||||
public void setContainerPermissions(ContainerPermissions permissions) {
|
||||
this.containerPermissions = permissions;
|
||||
}
|
||||
|
||||
|
||||
public void addAttribute(String attribute, String value) {
|
||||
attributes.put(attribute, value);
|
||||
}
|
||||
@@ -624,6 +522,14 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
this.gameObjectType = gameObjectType;
|
||||
}
|
||||
|
||||
public ContainerPermissionsType getContainerPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setContainerPermissions(ContainerPermissionsType permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public boolean isBuildout() {
|
||||
return classification == ObjectClassification.BUILDOUT;
|
||||
}
|
||||
@@ -643,9 +549,7 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
public void setLoadRange(double range) {
|
||||
this.loadRange = range;
|
||||
}
|
||||
|
||||
public ContainerPermissions getContainerPermissions() { return containerPermissions; }
|
||||
|
||||
|
||||
/**
|
||||
* Gets the arrangementId for the {@link SWGObject} for the current instance
|
||||
* @param object
|
||||
@@ -706,7 +610,7 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
}
|
||||
|
||||
public void createObject(Player target, boolean ignoreSnapshotChecks) {
|
||||
if (!hasPermission(target.getCreatureObject(), ContainerPermissions.Permission.VIEW)) {
|
||||
if (!isVisible(target.getCreatureObject())) {
|
||||
// Log.i("SWGObject", target.getCreatureObject() + " doesn't have permission to view " + this + " -- skipping packet sending");
|
||||
return;
|
||||
}
|
||||
@@ -1092,23 +996,23 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
|
||||
@Override
|
||||
public void save(NetBufferStream stream) {
|
||||
stream.addByte(2);
|
||||
stream.addByte(0);
|
||||
location.save(stream);
|
||||
ContainerPermissionsFactory.save(containerPermissions, stream);
|
||||
stream.addBoolean(parent != null && parent.getClassification() != ObjectClassification.GENERATED);
|
||||
if (parent != null && parent.getClassification() != ObjectClassification.GENERATED)
|
||||
SWGObjectFactory.save(ObjectCreator.createObjectFromTemplate(parent.getObjectId(), parent.getTemplate()), stream);
|
||||
stream.addAscii(permissions.name());
|
||||
stream.addAscii(classification.name());
|
||||
stream.addUnicode(objectName);
|
||||
stream.addInt(volume);
|
||||
stream.addFloat(complexity);
|
||||
stream.addFloat((float) loadRange);
|
||||
synchronized (attributes) {
|
||||
stream.addMap(attributes, (e) -> {
|
||||
stream.addAscii(e.getKey());
|
||||
stream.addAscii(e.getValue());
|
||||
});
|
||||
}
|
||||
stream.addAscii(classification.name());
|
||||
stream.addUnicode(objectName);
|
||||
stream.addInt(volume);
|
||||
stream.addFloat(complexity);
|
||||
stream.addFloat((float) loadRange);
|
||||
Set<SWGObject> contained;
|
||||
synchronized (containedObjects) {
|
||||
contained = new HashSet<>(containedObjects);
|
||||
@@ -1121,24 +1025,18 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
}
|
||||
|
||||
public void read(NetBufferStream stream) {
|
||||
byte ver = stream.getByte();
|
||||
stream.getByte();
|
||||
location.read(stream);
|
||||
if (ver <= 1)
|
||||
containerPermissions.read(stream);
|
||||
else
|
||||
containerPermissions = ContainerPermissionsFactory.create(stream);
|
||||
if (ver >= 1 && stream.getBoolean())
|
||||
if (stream.getBoolean())
|
||||
parent = SWGObjectFactory.create(stream);
|
||||
stream.getList((i) -> attributes.put(stream.getAscii(), stream.getAscii()));
|
||||
permissions = ContainerPermissionsType.valueOf(stream.getAscii());
|
||||
classification = ObjectClassification.valueOf(stream.getAscii());
|
||||
objectName = stream.getUnicode();
|
||||
volume = stream.getInt();
|
||||
complexity = stream.getFloat();
|
||||
loadRange = stream.getFloat();
|
||||
Set<SWGObject> contained = new HashSet<>();
|
||||
stream.getList((i) -> contained.add(SWGObjectFactory.create(stream)));
|
||||
for (SWGObject obj : contained)
|
||||
obj.moveToContainer(this);
|
||||
stream.getList((i) -> attributes.put(stream.getAscii(), stream.getAscii()));
|
||||
stream.getList((i) -> SWGObjectFactory.create(stream).moveToContainer(this));
|
||||
}
|
||||
|
||||
public enum ObjectClassification {
|
||||
|
||||
@@ -37,7 +37,6 @@ import resources.Terrain;
|
||||
import resources.client_info.ClientFactory;
|
||||
import resources.client_info.visitors.CrcStringTableData;
|
||||
import resources.client_info.visitors.DatatableData;
|
||||
import resources.containers.ContainerPermissions;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.SWGObject.ObjectClassification;
|
||||
import resources.objects.cell.CellObject;
|
||||
@@ -96,7 +95,6 @@ class TerrainBuildoutLoader {
|
||||
object.setBuildoutAreaId(area.getIndex());
|
||||
setCellInformation(object, buildoutRow.getCellIndex());
|
||||
addObject(area.getName(), object, buildoutRow.getContainerId());
|
||||
updatePermissions(object);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +130,4 @@ class TerrainBuildoutLoader {
|
||||
cell.setNumber(cellIndex);
|
||||
}
|
||||
|
||||
private void updatePermissions(SWGObject object) {
|
||||
object.setContainerPermissions(ContainerPermissions.WORLD);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import resources.Terrain;
|
||||
import resources.client_info.ClientFactory;
|
||||
import resources.client_info.visitors.WorldSnapshotData;
|
||||
import resources.client_info.visitors.WorldSnapshotData.Node;
|
||||
import resources.containers.ContainerPermissions;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.SWGObject.ObjectClassification;
|
||||
import resources.objects.cell.CellObject;
|
||||
@@ -83,8 +82,7 @@ public class TerrainSnapshotLoader {
|
||||
object.setLoadRange(node.getRadius());
|
||||
setCellInformation(object, node.getCellIndex());
|
||||
addObject(object, node.getContainerId());
|
||||
updatePermissions(object);
|
||||
|
||||
|
||||
for (Node child : node.getChildren()) {
|
||||
createFromNode(templates, child);
|
||||
}
|
||||
@@ -117,8 +115,4 @@ public class TerrainSnapshotLoader {
|
||||
cell.setNumber(cellIndex);
|
||||
}
|
||||
|
||||
private void updatePermissions(SWGObject object) {
|
||||
object.setContainerPermissions(ContainerPermissions.WORLD);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,10 +66,10 @@ class CreatureObjectSharedNP implements Persistable {
|
||||
private boolean shownOnRadar = true;
|
||||
private boolean beast = false;
|
||||
|
||||
private SWGList<Integer> attributes = new SWGList<Integer>(6, 21);
|
||||
private SWGList<Integer> maxAttributes = new SWGList<Integer>(6, 22);
|
||||
private SWGList<Equipment> equipmentList = new SWGList<Equipment>(6, 23);
|
||||
private SWGList<Equipment> appearanceList = new SWGList<Equipment>(6, 33);
|
||||
private SWGList<Integer> attributes = new SWGList<>(6, 21);
|
||||
private SWGList<Integer> maxAttributes = new SWGList<>(6, 22);
|
||||
private SWGList<Equipment> equipmentList = new SWGList<>(6, 23);
|
||||
private SWGList<Equipment> appearanceList = new SWGList<>(6, 33);
|
||||
|
||||
private SWGMap<CRC, Buff> buffs = new SWGMap<>(6, 26);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ import resources.Race;
|
||||
import resources.client_info.ClientFactory;
|
||||
import resources.client_info.visitors.ProfTemplateData;
|
||||
import resources.config.ConfigFile;
|
||||
import resources.containers.ContainerPermissions;
|
||||
import resources.containers.ContainerPermissionsType;
|
||||
import resources.control.Service;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.building.BuildingObject;
|
||||
@@ -378,7 +378,7 @@ public class CharacterCreationService extends Service {
|
||||
private SWGObject createInventoryObject(ObjectManager objManager, CreatureObject creatureObj, String template) {
|
||||
SWGObject obj = ObjectCreator.createObjectFromTemplate(template);
|
||||
obj.moveToContainer(creatureObj);
|
||||
obj.setContainerPermissions(ContainerPermissions.INVENTORY);
|
||||
obj.setContainerPermissions(ContainerPermissionsType.INVENTORY);
|
||||
new ObjectCreatedIntent(obj).broadcast();
|
||||
return obj;
|
||||
}
|
||||
@@ -413,8 +413,6 @@ public class CharacterCreationService extends Service {
|
||||
|
||||
// Any character can perform the basic dance.
|
||||
creatureObj.addAbility("startDance+basic");
|
||||
|
||||
creatureObj.joinPermissionGroup("world");
|
||||
}
|
||||
|
||||
private void setPlayerObjectValues(PlayerObject playerObj, ClientCreateCharacter create) {
|
||||
|
||||
Reference in New Issue
Block a user