Changed Group. This isn't java. Don't use accessor/mutator methods. Use properties.
This commit is contained in:
parent
c3bf304c0c
commit
fff6e1bcbc
3 changed files with 69 additions and 86 deletions
|
|
@ -14,86 +14,69 @@ GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
public class Group
|
public class Group
|
||||||
{
|
{
|
||||||
private string name;
|
private readonly List<string> permissions = new List<string>();
|
||||||
private Group parent;
|
private readonly List<string> negatedpermissions = new List<string>();
|
||||||
private List<string> permissions = new List<string>();
|
|
||||||
private List<string> negatedPermissions = new List<string>();
|
public string Name { get; protected set; }
|
||||||
|
public Group Parent { get; protected set; }
|
||||||
public Group(string groupName, Group parentGroup = null)
|
|
||||||
{
|
public Group(string groupname, Group parentgroup = null)
|
||||||
name = groupName;
|
{
|
||||||
parent = parentGroup;
|
Name = groupname;
|
||||||
}
|
Parent = parentgroup;
|
||||||
|
}
|
||||||
public Group()
|
|
||||||
{
|
public virtual bool HasPermission(string permission)
|
||||||
throw new Exception("Called Group constructor with no parameters");
|
{
|
||||||
}
|
if (permission.Equals(""))
|
||||||
|
{
|
||||||
public string GetName()
|
return true;
|
||||||
{
|
}
|
||||||
return name;
|
if (negatedpermissions.Contains(permission))
|
||||||
}
|
{
|
||||||
|
return false;
|
||||||
public Group GetParent()
|
}
|
||||||
{
|
if (permissions.Contains(permission))
|
||||||
return parent;
|
{
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
public virtual bool HasPermission(string permission)
|
if (Parent != null)
|
||||||
{
|
{
|
||||||
if (permission.Equals(""))
|
//inception
|
||||||
{
|
return Parent.HasPermission(permission);
|
||||||
return true;
|
}
|
||||||
}
|
return false;
|
||||||
if (negatedPermissions.Contains(permission))
|
}
|
||||||
{
|
|
||||||
return false;
|
public void NegatePermission(string permission)
|
||||||
}
|
{
|
||||||
else if (permissions.Contains(permission))
|
negatedpermissions.Add(permission);
|
||||||
{
|
}
|
||||||
return true;
|
|
||||||
}
|
public void AddPermission(string permission)
|
||||||
else if (parent != null)
|
{
|
||||||
{
|
permissions.Add(permission);
|
||||||
//inception
|
}
|
||||||
return parent.HasPermission(permission);
|
}
|
||||||
}
|
|
||||||
return false;
|
public class SuperAdminGroup : Group
|
||||||
}
|
{
|
||||||
|
public SuperAdminGroup(string groupName, Group parentGroup = null)
|
||||||
public void NegatePermission(string permission)
|
: base(groupName, parentGroup)
|
||||||
{
|
{
|
||||||
negatedPermissions.Add(permission);
|
}
|
||||||
}
|
|
||||||
|
public override bool HasPermission(string permission)
|
||||||
public void AddPermission(string permission)
|
{
|
||||||
{
|
return true;
|
||||||
permissions.Add(permission);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public class SuperAdminGroup : Group
|
|
||||||
{
|
|
||||||
public SuperAdminGroup(string groupName, Group parentGroup = null) : base(groupName, parentGroup)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperAdminGroup()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool HasPermission(string permission)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -570,7 +570,7 @@ namespace TShockAPI
|
||||||
if (Main.netMode != 2)
|
if (Main.netMode != 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", Tools.FindPlayer(who), Tools.GetPlayerIP(who), players[who].Group.GetName()));
|
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", Tools.FindPlayer(who), Tools.GetPlayerIP(who), players[who].Group.Name));
|
||||||
|
|
||||||
Tools.ShowMOTD(who);
|
Tools.ShowMOTD(who);
|
||||||
if (HackedHealth(who))
|
if (HackedHealth(who))
|
||||||
|
|
|
||||||
|
|
@ -415,7 +415,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
for (int j = 0; j < groups.Count; j++)
|
for (int j = 0; j < groups.Count; j++)
|
||||||
{
|
{
|
||||||
if (groups[j].GetName().Equals(parent))
|
if (groups[j].Name.Equals(parent))
|
||||||
{
|
{
|
||||||
group = new Group(name, groups[j]);
|
group = new Group(name, groups[j]);
|
||||||
break;
|
break;
|
||||||
|
|
@ -455,7 +455,7 @@ namespace TShockAPI
|
||||||
//first attempt on cached groups
|
//first attempt on cached groups
|
||||||
for (int i = 0; i < groups.Count; i++)
|
for (int i = 0; i < groups.Count; i++)
|
||||||
{
|
{
|
||||||
if (groups[i].GetName().Equals(groupName))
|
if (groups[i].Name.Equals(groupName))
|
||||||
{
|
{
|
||||||
return groups[i];
|
return groups[i];
|
||||||
}
|
}
|
||||||
|
|
@ -465,7 +465,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
for (int i = 0; i < groups.Count; i++)
|
for (int i = 0; i < groups.Count; i++)
|
||||||
{
|
{
|
||||||
if (groups[i].GetName().Equals(groupName))
|
if (groups[i].Name.Equals(groupName))
|
||||||
{
|
{
|
||||||
return groups[i];
|
return groups[i];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue