Skip to content

Commit 8a5400a

Browse files
committed
Rights structure protptype
1 parent ce80c16 commit 8a5400a

9 files changed

+651
-13
lines changed

TS3AudioBot/MainBot.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace TS3AudioBot
3131
using Sessions;
3232
using Web.Api;
3333
using Web;
34+
using Rights;
3435

3536
using TS3Client;
3637
using TS3Client.Messages;
@@ -75,6 +76,7 @@ internal static void Main(string[] args)
7576
public PlayManager PlayManager { get; private set; }
7677
public ITargetManager TargetManager { get; private set; }
7778
public ConfigFile ConfigManager { get; private set; }
79+
public RightsManager RightsManager { get; private set; }
7880

7981
public bool QuizMode { get; set; }
8082

@@ -116,6 +118,7 @@ private bool InitializeBot()
116118
var pld = ConfigManager.GetDataStruct<PlaylistManagerData>("PlaylistManager", true);
117119
var yfd = ConfigManager.GetDataStruct<YoutubeFactoryData>("YoutubeFactory", true);
118120
var webd = ConfigManager.GetDataStruct<WebData>("WebData", true);
121+
var rmd = ConfigManager.GetDataStruct<RightsManagerData>("RightsManager", true);
119122
mainBotData = ConfigManager.GetDataStruct<MainBotData>("MainBot", true);
120123
ConfigManager.Close();
121124

@@ -161,6 +164,7 @@ private bool InitializeBot()
161164
PluginManager = new PluginManager(this, pmd);
162165
PlayManager = new PlayManager(this);
163166
WebManager = new WebManager(this, webd);
167+
RightsManager = new RightsManager(rmd);
164168
TargetManager = teamspeakClient;
165169

166170
Log.Write(Log.Level.Info, "[=========== Initializing Factories ===========]");
@@ -194,7 +198,6 @@ private bool InitializeBot()
194198
// Register callback to remove open private sessions, when user disconnects
195199
//QueryConnection.OnClientDisconnect += (s, e) => SessionManager.RemoveSession(e.InvokerUid);
196200

197-
198201
Log.Write(Log.Level.Info, "[================= Finalizing =================]");
199202
WebManager.StartServerAsync();
200203

TS3AudioBot/Properties/AssemblyInfo.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.InteropServices;
33

44
// General Information about an assembly is controlled through the following
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("")]
1111
[assembly: AssemblyProduct("TS3AudioBot")]
12-
[assembly: AssemblyCopyright("Copyright © Splamy 2016")]
12+
[assembly: AssemblyCopyright("Copyright © Splamy 2017")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -31,5 +31,6 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("1.0.0.0")]
34+
[assembly: AssemblyVersion("0.2.*")]
35+
[assembly: AssemblyFileVersion("0.2.*")]
36+
[assembly: AssemblyInformationalVersion("0.2.0")]

TS3AudioBot/Rights/RightsDecl.cs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// TS3AudioBot - An advanced Musicbot for Teamspeak 3
2+
// Copyright (C) 2016 TS3AudioBot contributors
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace TS3AudioBot.Rights
18+
{
19+
using Nett;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
23+
internal abstract class RightsDecl
24+
{
25+
public int Id { get; private set; }
26+
public int Level { get; set; }
27+
28+
public RightsRule Parent { get; set; }
29+
private string[] includeNames;
30+
public RightsGroup[] Includes { get; set; }
31+
32+
public string[] DeclAdd { get; set; }
33+
public string[] DeclDeny { get; set; }
34+
35+
public RightsDecl() { }
36+
37+
public virtual void FillNull()
38+
{
39+
if (includeNames == null) includeNames = new string[0];
40+
if (DeclAdd == null) DeclAdd = new string[0];
41+
if (DeclDeny == null) DeclDeny = new string[0];
42+
}
43+
44+
public virtual bool ParseKey(string key, TomlObject tomlObj, List<RightsDecl> rules)
45+
{
46+
switch (key)
47+
{
48+
case "+":
49+
DeclAdd = TomlTools.GetValues<string>(tomlObj);
50+
if (DeclAdd == null)
51+
Log.Write(Log.Level.Error, "<+> Field has invalid data.");
52+
break;
53+
case "-":
54+
DeclDeny = TomlTools.GetValues<string>(tomlObj);
55+
if (DeclDeny == null)
56+
Log.Write(Log.Level.Error, "<-> Field has invalid data.");
57+
break;
58+
case "include":
59+
includeNames = TomlTools.GetValues<string>(tomlObj);
60+
if (includeNames == null)
61+
Log.Write(Log.Level.Error, "<include> Field has invalid data.");
62+
break;
63+
default: return false;
64+
}
65+
return true;
66+
}
67+
68+
public void ParseChilden(TomlTable tomlObj, List<RightsDecl> rules)
69+
{
70+
Id = rules.Count;
71+
rules.Add(this);
72+
73+
foreach (var item in tomlObj)
74+
{
75+
if (!ParseKey(item.Key, item.Value, rules))
76+
{
77+
Log.Write(Log.Level.Error, "Unrecognized key <{0}>.", item.Key);
78+
}
79+
}
80+
FillNull();
81+
}
82+
83+
public abstract RightsGroup ResolveGroup(string groupName);
84+
85+
public bool ResolveIncludes()
86+
{
87+
bool hasErrors = false;
88+
if (includeNames != null)
89+
{
90+
Includes = includeNames.Select(ResolveGroup).ToArray();
91+
for (int i = 0; i < includeNames.Length; i++)
92+
if (Includes[i] == null)
93+
{
94+
Log.Write(Log.Level.Error, "Could not find group \"{0}\" to include.", includeNames[i]);
95+
hasErrors = true;
96+
}
97+
includeNames = null;
98+
}
99+
return !hasErrors;
100+
}
101+
}
102+
}

TS3AudioBot/Rights/RightsGroup.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// TS3AudioBot - An advanced Musicbot for Teamspeak 3
2+
// Copyright (C) 2016 TS3AudioBot contributors
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace TS3AudioBot.Rights
18+
{
19+
internal class RightsGroup : RightsDecl
20+
{
21+
public string Name { get; }
22+
23+
public RightsGroup(string name)
24+
{
25+
Name = name;
26+
}
27+
28+
public override RightsGroup ResolveGroup(string groupName)
29+
{
30+
if (Name == groupName)
31+
return this;
32+
if (Parent == null)
33+
return null;
34+
return Parent.ResolveGroup(groupName);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)