Line ending normalization to CRLF (Windows)
This commit is contained in:
parent
f82bff1b17
commit
9470e20423
16 changed files with 1859 additions and 1854 deletions
|
|
@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
|
@ -166,7 +166,7 @@ namespace TShockAPI.DB
|
|||
/// <param name="permissions">permissions</param>
|
||||
/// <param name="chatcolor">chatcolor</param>
|
||||
public void UpdateGroup(string name, string parentname, string permissions, string chatcolor)
|
||||
{
|
||||
{
|
||||
Group group = GetGroupByName(name);
|
||||
if (group == null)
|
||||
throw new GroupNotExistException(name);
|
||||
|
|
@ -176,22 +176,22 @@ namespace TShockAPI.DB
|
|||
{
|
||||
parent = GetGroupByName(parentname);
|
||||
if (parent == null || parent == group)
|
||||
throw new GroupManagerException("Invalid parent \"{0}\" for group \"{1}\".".SFormat(parentname, name));
|
||||
|
||||
// Check if the new parent would cause loops.
|
||||
List<Group> groupChain = new List<Group> { group, parent };
|
||||
Group checkingGroup = parent.Parent;
|
||||
while (checkingGroup != null)
|
||||
{
|
||||
if (groupChain.Contains(checkingGroup))
|
||||
throw new GroupManagerException(
|
||||
string.Format("Invalid parent \"{0}\" for group \"{1}\" would cause loops in the parent chain.", parentname, name));
|
||||
|
||||
groupChain.Add(checkingGroup);
|
||||
checkingGroup = checkingGroup.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
throw new GroupManagerException("Invalid parent \"{0}\" for group \"{1}\".".SFormat(parentname, name));
|
||||
|
||||
// Check if the new parent would cause loops.
|
||||
List<Group> groupChain = new List<Group> { group, parent };
|
||||
Group checkingGroup = parent.Parent;
|
||||
while (checkingGroup != null)
|
||||
{
|
||||
if (groupChain.Contains(checkingGroup))
|
||||
throw new GroupManagerException(
|
||||
string.Format("Invalid parent \"{0}\" for group \"{1}\" would cause loops in the parent chain.", parentname, name));
|
||||
|
||||
groupChain.Add(checkingGroup);
|
||||
checkingGroup = checkingGroup.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure any group validation is also persisted to the DB.
|
||||
var newGroup = new Group(name, parent, chatcolor, permissions);
|
||||
string query = "UPDATE GroupList SET Parent=@0, Commands=@1, ChatColor=@2 WHERE GroupName=@3";
|
||||
|
|
@ -265,107 +265,107 @@ namespace TShockAPI.DB
|
|||
}
|
||||
|
||||
public void LoadPermisions()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Group> newGroups = new List<Group>(groups.Count);
|
||||
Dictionary<string,string> newGroupParents = new Dictionary<string, string>(groups.Count);
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Group> newGroups = new List<Group>(groups.Count);
|
||||
Dictionary<string,string> newGroupParents = new Dictionary<string, string>(groups.Count);
|
||||
using (var reader = database.QueryReader("SELECT * FROM GroupList"))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
string groupName = reader.Get<string>("GroupName");
|
||||
if (groupName == "superadmin")
|
||||
{
|
||||
Log.ConsoleInfo("WARNING: Group \"superadmin\" is defined in the database even though it's a reserved group name.");
|
||||
continue;
|
||||
}
|
||||
{
|
||||
string groupName = reader.Get<string>("GroupName");
|
||||
if (groupName == "superadmin")
|
||||
{
|
||||
Log.ConsoleInfo("WARNING: Group \"superadmin\" is defined in the database even though it's a reserved group name.");
|
||||
continue;
|
||||
}
|
||||
|
||||
newGroups.Add(new Group(groupName, null, reader.Get<string>("ChatColor"), reader.Get<string>("Commands")) {
|
||||
Prefix = reader.Get<string>("Prefix"),
|
||||
Suffix = reader.Get<string>("Suffix"),
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
newGroupParents.Add(groupName, reader.Get<string>("Parent"));
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Just in case somebody messed with the unique primary key.
|
||||
Log.ConsoleError("ERROR: Group name \"{0}\" occurs more than once. Keeping current group settings.");
|
||||
return;
|
||||
Suffix = reader.Get<string>("Suffix"),
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
newGroupParents.Add(groupName, reader.Get<string>("Parent"));
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Just in case somebody messed with the unique primary key.
|
||||
Log.ConsoleError("ERROR: Group name \"{0}\" occurs more than once. Keeping current group settings.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Get rid of deleted groups.
|
||||
for (int i = 0; i < groups.Count; i++)
|
||||
if (newGroups.All(g => g.Name != groups[i].Name))
|
||||
groups.RemoveAt(i--);
|
||||
|
||||
// Apply changed group settings while keeping the current instances and add new groups.
|
||||
foreach (Group newGroup in newGroups)
|
||||
{
|
||||
Group currentGroup = groups.FirstOrDefault(g => g.Name == newGroup.Name);
|
||||
if (currentGroup != null)
|
||||
newGroup.AssignTo(currentGroup);
|
||||
else
|
||||
groups.Add(newGroup);
|
||||
}
|
||||
|
||||
// Resolve parent groups.
|
||||
Debug.Assert(newGroups.Count == newGroupParents.Count);
|
||||
for (int i = 0; i < groups.Count; i++)
|
||||
{
|
||||
Group group = groups[i];
|
||||
string parentGroupName;
|
||||
if (!newGroupParents.TryGetValue(group.Name, out parentGroupName) || string.IsNullOrEmpty(parentGroupName))
|
||||
continue;
|
||||
|
||||
group.Parent = groups.FirstOrDefault(g => g.Name == parentGroupName);
|
||||
if (group.Parent == null)
|
||||
{
|
||||
Log.ConsoleError(
|
||||
"ERROR: Group \"{0}\" is referencing non existent parent group \"{1}\", parent reference was removed.",
|
||||
group.Name, parentGroupName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (group.Parent == group)
|
||||
Log.ConsoleInfo(
|
||||
"WARNING: Group \"{0}\" is referencing itself as parent group, parent reference was removed.", group.Name);
|
||||
|
||||
List<Group> groupChain = new List<Group> { group };
|
||||
Group checkingGroup = group;
|
||||
while (checkingGroup.Parent != null)
|
||||
{
|
||||
if (groupChain.Contains(checkingGroup.Parent))
|
||||
{
|
||||
Log.ConsoleError(
|
||||
"ERROR: Group \"{0}\" is referencing parent group \"{1}\" which is already part of the parent chain. Parent reference removed.",
|
||||
checkingGroup.Name, checkingGroup.Parent.Name);
|
||||
|
||||
checkingGroup.Parent = null;
|
||||
break;
|
||||
}
|
||||
groupChain.Add(checkingGroup);
|
||||
checkingGroup = checkingGroup.Parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!groups.Any(g => g is SuperAdminGroup))
|
||||
groups.Add(new SuperAdminGroup());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.ConsoleError("Error on reloading groups: " + ex);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Get rid of deleted groups.
|
||||
for (int i = 0; i < groups.Count; i++)
|
||||
if (newGroups.All(g => g.Name != groups[i].Name))
|
||||
groups.RemoveAt(i--);
|
||||
|
||||
// Apply changed group settings while keeping the current instances and add new groups.
|
||||
foreach (Group newGroup in newGroups)
|
||||
{
|
||||
Group currentGroup = groups.FirstOrDefault(g => g.Name == newGroup.Name);
|
||||
if (currentGroup != null)
|
||||
newGroup.AssignTo(currentGroup);
|
||||
else
|
||||
groups.Add(newGroup);
|
||||
}
|
||||
|
||||
// Resolve parent groups.
|
||||
Debug.Assert(newGroups.Count == newGroupParents.Count);
|
||||
for (int i = 0; i < groups.Count; i++)
|
||||
{
|
||||
Group group = groups[i];
|
||||
string parentGroupName;
|
||||
if (!newGroupParents.TryGetValue(group.Name, out parentGroupName) || string.IsNullOrEmpty(parentGroupName))
|
||||
continue;
|
||||
|
||||
group.Parent = groups.FirstOrDefault(g => g.Name == parentGroupName);
|
||||
if (group.Parent == null)
|
||||
{
|
||||
Log.ConsoleError(
|
||||
"ERROR: Group \"{0}\" is referencing non existent parent group \"{1}\", parent reference was removed.",
|
||||
group.Name, parentGroupName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (group.Parent == group)
|
||||
Log.ConsoleInfo(
|
||||
"WARNING: Group \"{0}\" is referencing itself as parent group, parent reference was removed.", group.Name);
|
||||
|
||||
List<Group> groupChain = new List<Group> { group };
|
||||
Group checkingGroup = group;
|
||||
while (checkingGroup.Parent != null)
|
||||
{
|
||||
if (groupChain.Contains(checkingGroup.Parent))
|
||||
{
|
||||
Log.ConsoleError(
|
||||
"ERROR: Group \"{0}\" is referencing parent group \"{1}\" which is already part of the parent chain. Parent reference removed.",
|
||||
checkingGroup.Name, checkingGroup.Parent.Name);
|
||||
|
||||
checkingGroup.Parent = null;
|
||||
break;
|
||||
}
|
||||
groupChain.Add(checkingGroup);
|
||||
checkingGroup = checkingGroup.Parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!groups.Any(g => g is SuperAdminGroup))
|
||||
groups.Add(new SuperAdminGroup());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.ConsoleError("Error on reloading groups: " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -394,10 +394,10 @@ namespace TShockAPI.DB
|
|||
mergedIDs = reader.Get<string>("UserIds");
|
||||
}
|
||||
|
||||
string userIdToAdd = Convert.ToString(TShock.Users.GetUserID(userName));
|
||||
string[] ids = mergedIDs.Split(',');
|
||||
// Is the user already allowed to the region?
|
||||
if (ids.Contains(userIdToAdd))
|
||||
string userIdToAdd = Convert.ToString(TShock.Users.GetUserID(userName));
|
||||
string[] ids = mergedIDs.Split(',');
|
||||
// Is the user already allowed to the region?
|
||||
if (ids.Contains(userIdToAdd))
|
||||
return true;
|
||||
|
||||
if (string.IsNullOrEmpty(mergedIDs))
|
||||
|
|
@ -484,9 +484,9 @@ namespace TShockAPI.DB
|
|||
mergedGroups = reader.Get<string>("Groups");
|
||||
}
|
||||
|
||||
string[] groups = mergedGroups.Split(',');
|
||||
// Is the group already allowed to the region?
|
||||
if (groups.Contains(groupName))
|
||||
string[] groups = mergedGroups.Split(',');
|
||||
// Is the group already allowed to the region?
|
||||
if (groups.Contains(groupName))
|
||||
return true;
|
||||
|
||||
if (mergedGroups != "")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue