Bot::Data: Add blacklists to checkModPermissions
parent
d09924cb27
commit
9eb7c02590
|
@ -99,33 +99,48 @@ namespace ProjectGolan.Vrobot3
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String[] getEnables(Dictionary<String, String[]> enables,
|
||||||
|
Channel channel)
|
||||||
|
{
|
||||||
|
var name = channel.name;
|
||||||
|
if(enables.ContainsKey(name)) return enables[name];
|
||||||
|
else if(enables.ContainsKey("*")) return enables["*"];
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
public bool checkModPermissions(Channel channel, Type mod)
|
||||||
{
|
{
|
||||||
String[] enables;
|
String[] enables = getEnables(info.enables, channel);
|
||||||
|
String[] disables = getEnables(info.disables, channel);
|
||||||
|
|
||||||
if(info.enables.ContainsKey(channel.name))
|
if(enables == null && disables == null) return true;
|
||||||
enables = info.enables[channel.name];
|
|
||||||
else if(info.enables.ContainsKey("*"))
|
|
||||||
enables = info.enables["*"];
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
|
|
||||||
foreach(var modname in enables)
|
bool ret = false;
|
||||||
{
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
if(modname == "*")
|
if(enables != null)
|
||||||
return true;
|
foreach(var modName in enables)
|
||||||
else if(modname[0] == '@')
|
if(checkMod(mod, modName))
|
||||||
type = Type.GetType("ProjectGolan.Vrobot3.Modules." + modname.Substring(1));
|
{ret = true; break;}
|
||||||
else
|
|
||||||
type = Type.GetType(modname);
|
|
||||||
|
|
||||||
if(type == mod)
|
if(disables != null)
|
||||||
return true;
|
foreach(var modName in disables)
|
||||||
}
|
if(checkMod(mod, modName))
|
||||||
|
{ret = false; break;}
|
||||||
|
|
||||||
return false;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue