Browse Source

It's not working yet. Just end-of-day commit.

master
Stanislav Usenkov 10 years ago
parent
commit
bd89f3f5f1
  1. 169
      src/main/java/ru/simsonic/rscPermissions/InternalCache/InternalCache.java

169
src/main/java/ru/simsonic/rscPermissions/InternalCache/InternalCache.java

@ -12,18 +12,18 @@ import ru.simsonic.rscPermissions.Backends.DatabaseContents;
public class InternalCache public class InternalCache
{ {
private final HashMap<String, RowEntity> entities_g = new HashMap<>();
private final HashMap<String, RowEntity> entities_u = new HashMap<>();
private final ArrayList<RowPermission> permissions_p2g = new ArrayList<>();
private final ArrayList<RowPermission> permissions_p2u = new ArrayList<>();
private final ArrayList<RowInheritance> inheritance_g2g = new ArrayList<>();
private final ArrayList<RowInheritance> inheritance_g2u = new ArrayList<>();
private final RowInheritance defaultInheritance = new RowInheritance(); private final RowInheritance defaultInheritance = new RowInheritance();
public void setDefaultGroup(String defaultGroup) public void setDefaultGroup(String defaultGroup)
{ {
defaultInheritance.parent = defaultGroup; defaultInheritance.parent = defaultGroup;
defaultInheritance.deriveInstance(); defaultInheritance.deriveInstance();
} }
private final HashMap<String, RowEntity> entities_g = new HashMap<>();
private final HashMap<String, RowEntity> entities_u = new HashMap<>();
private final ArrayList<RowPermission> permissions_p2g = new ArrayList<>();
private final ArrayList<RowPermission> permissions_p2u = new ArrayList<>();
private final ArrayList<RowInheritance> inheritance_g2g = new ArrayList<>();
private final ArrayList<RowInheritance> inheritance_g2u = new ArrayList<>();
public static class InheritanceLeaf implements Comparable<InheritanceLeaf> public static class InheritanceLeaf implements Comparable<InheritanceLeaf>
{ {
public RowInheritance node; public RowInheritance node;
@ -37,13 +37,84 @@ public class InternalCache
return (other.node != null && node != null) ? other.node.compareTo(node) : 0; return (other.node != null && node != null) ? other.node.compareTo(node) : 0;
} }
} }
private final HashMap<String, InheritanceLeaf> entityTrees = new HashMap<>(); private final HashMap<String, InheritanceLeaf> entityTrees = new HashMap<>();
private final HashMap<String, RowPermission[]> groupPermissions = new HashMap<>(); private final HashMap<String, RowPermission[]> permissionsTreesG = new HashMap<>();
private final HashMap<String, RowPermission[]> playerPermissions = new HashMap<>(); private final HashMap<String, RowPermission[]> permissionsTreesU = new HashMap<>();
private void buildPermissions() private final HashMap<String, RowInheritance[]> inheritanceTreesG = new HashMap<>();
private final HashMap<String, RowInheritance[]> inheritanceTreesU = new HashMap<>();
public synchronized void fill(DatabaseContents contents)
{
clear();
if(contents.entities != null)
importEntities(contents.entities);
if(contents.permissions != null)
importPermissions(contents.permissions);
if(contents.inheritance != null)
importInheritance(contents.inheritance);
buildInheritanceForest();
}
public synchronized ResolutionResult resolvePlayer(String player, String serverId)
{
return resolvePlayer(new String[] { player }, serverId);
}
public synchronized ResolutionResult resolvePlayer(String[] player, String serverId)
{
final ResolutionParams params = new ResolutionParams();
params.applicableIdentifiers = player;
params.destRegions = new String[] {};
// params.destWorld = "";
params.destServerId = serverId;
// params.expirience = 0;
return resolvePlayer(params);
}
public synchronized ResolutionResult resolvePlayer(ResolutionParams params)
{
final ArrayList<InheritanceLeaf> applicableBranches = new ArrayList<>();
// Grab all inheritance rows applicable to this player
for(String identifier : params.applicableIdentifiers)
for(String tree : entityTrees.keySet())
if(tree.equals(identifier))
applicableBranches.add(entityTrees.get(tree));
Collections.sort(applicableBranches);
// Begin resolution
final ArrayList<ResolutionResult> intermediateResults = new ArrayList<>();
for(InheritanceLeaf branch : applicableBranches)
if(isInheritanceApplicable(params, branch.node, ""))
intermediateResults.add(resolveBranch(params, branch, ""));
final ResolutionResult result = processResultColumn(params, intermediateResults, "");
intermediateResults.clear();
return result;
}
private void importEntities(RowEntity[] rows)
{
for(RowEntity row : rows)
{
if(row.entityType == EntityType.group)
entities_g.put(row.entity.toLowerCase(), row);
else
entities_u.put(row.entity.toLowerCase(), row);
}
}
private void importPermissions(RowPermission[] rows)
{
for(RowPermission row : rows)
{
if(row.entityType == EntityType.group)
permissions_p2g.add(row);
else
permissions_p2u.add(row);
}
}
private void importInheritance(RowInheritance[] rows)
{ {
for(RowInheritance row : rows)
if(row.childType == EntityType.group)
inheritance_g2g.add(row);
else
inheritance_g2u.add(row);
} }
private void buildEntityTree() // FROM HERE I SHOULD MAKE IT WORKING
private void buildInheritanceForest()
{ {
final HashSet<String> entitiesWhichInherits = new HashSet<>(); final HashSet<String> entitiesWhichInherits = new HashSet<>();
for(RowInheritance row : inheritance_g2u) for(RowInheritance row : inheritance_g2u)
@ -81,38 +152,6 @@ public class InternalCache
result.subleafs = subleafs.toArray(new InheritanceLeaf[subleafs.size()]); result.subleafs = subleafs.toArray(new InheritanceLeaf[subleafs.size()]);
return result; return result;
} }
public synchronized ResolutionResult resolvePlayer(String player, String serverId)
{
return resolvePlayer(new String[] { player }, serverId);
}
public synchronized ResolutionResult resolvePlayer(String[] player, String serverId)
{
final ResolutionParams params = new ResolutionParams();
params.applicableIdentifiers = player;
params.destRegions = new String[] {};
// params.destWorld = "";
params.destServerId = serverId;
// params.expirience = 0;
return resolvePlayer(params);
}
public synchronized ResolutionResult resolvePlayer(ResolutionParams params)
{
final ArrayList<InheritanceLeaf> applicableBranches = new ArrayList<>();
// Grab all inheritance rows applicable to this player
for(String identifier : params.applicableIdentifiers)
for(String tree : entityTrees.keySet())
if(tree.equals(identifier))
applicableBranches.add(entityTrees.get(tree));
Collections.sort(applicableBranches);
// Begin resolution
final ArrayList<ResolutionResult> intermediateResults = new ArrayList<>();
for(InheritanceLeaf branch : applicableBranches)
if(isInheritanceApplicable(params, branch.node, ""))
intermediateResults.add(resolveBranch(params, branch, ""));
final ResolutionResult result = processResultColumn(params, intermediateResults, "");
intermediateResults.clear();
return result;
}
private ResolutionResult resolveBranch(ResolutionParams params, InheritanceLeaf branch, String instantiator) private ResolutionResult resolveBranch(ResolutionParams params, InheritanceLeaf branch, String instantiator)
{ {
final ArrayList<ResolutionResult> intermediateResults = new ArrayList<>(); final ArrayList<ResolutionResult> intermediateResults = new ArrayList<>();
@ -174,50 +213,6 @@ public class InternalCache
? row.destination.isRegionApplicable(params.destRegions, instantiator) ? row.destination.isRegionApplicable(params.destRegions, instantiator)
: false; : false;
} }
public synchronized void fill(DatabaseContents contents)
{
importEntities(contents.entities);
importPermissions(contents.permissions);
importInheritance(contents.inheritance);
buildEntityTree();
}
private void importEntities(RowEntity[] rows)
{
entities_g.clear();
entities_u.clear();
if(rows != null)
for(RowEntity row : rows)
{
if(row.entityType == EntityType.group)
entities_g.put(row.entity.toLowerCase(), row);
else
entities_u.put(row.entity.toLowerCase(), row);
}
}
private void importPermissions(RowPermission[] rows)
{
permissions_p2g.clear();
permissions_p2u.clear();
if(rows != null)
for(RowPermission row : rows)
{
if(row.entityType == EntityType.group)
permissions_p2g.add(row);
else
permissions_p2u.add(row);
}
}
private void importInheritance(RowInheritance[] rows)
{
inheritance_g2g.clear();
inheritance_g2u.clear();
if(rows != null)
for(RowInheritance row : rows)
if(row.childType == EntityType.group)
inheritance_g2g.add(row);
else
inheritance_g2u.add(row);
}
public synchronized void clear() public synchronized void clear()
{ {
entities_g.clear(); entities_g.clear();

Loading…
Cancel
Save