1
0
Fork 0

Bot::Data: Add blacklists to checkModPermissions

master
Marrub 2016-11-25 03:19:56 -05:00
parent d09924cb27
commit 9eb7c02590
2 changed files with 36 additions and 20 deletions

View File

@ -99,33 +99,48 @@ namespace ProjectGolan.Vrobot3
client.disconnect(); client.disconnect();
} }
public bool checkModPermissions(Channel channel, Type mod) private String[] getEnables(Dictionary<String, String[]> enables,
Channel channel)
{ {
String[] enables; var name = channel.name;
if(enables.ContainsKey(name)) return enables[name];
if(info.enables.ContainsKey(channel.name)) else if(enables.ContainsKey("*")) return enables["*"];
enables = info.enables[channel.name]; else return null;
else if(info.enables.ContainsKey("*"))
enables = info.enables["*"];
else
return true;
foreach(var modname in enables)
{
Type type;
if(modname == "*")
return true;
else if(modname[0] == '@')
type = Type.GetType("ProjectGolan.Vrobot3.Modules." + modname.Substring(1));
else
type = Type.GetType(modname);
if(type == mod)
return true;
} }
return false; private bool checkMod(Type mod, String modName)
{
const String modBase = "ProjectGolan.Vrobot3.Modules.";
var modFull = modBase + modName.Substring(1);
Type type;
if(modName == "*") return true;
else if(modName[0] == '@') type = Type.GetType(modFull);
else type = Type.GetType(modName);
return type == mod;
}
public bool checkModPermissions(Channel channel, Type mod)
{
String[] enables = getEnables(info.enables, channel);
String[] disables = getEnables(info.disables, channel);
if(enables == null && disables == null) return true;
bool ret = false;
if(enables != null)
foreach(var modName in enables)
if(checkMod(mod, modName))
{ret = true; break;}
if(disables != null)
foreach(var modName in disables)
if(checkMod(mod, modName))
{ret = false; break;}
return ret;
} }
} }
} }

View File

@ -30,6 +30,7 @@ namespace ProjectGolan.Vrobot3
public struct BotInfo public struct BotInfo
{ {
public Dictionary<String, String[]> enables; public Dictionary<String, String[]> enables;
public Dictionary<String, String[]> disables;
public String serverType; public String serverType;
public String serverName; public String serverName;
public String serverPass; public String serverPass;