예제 #1
0
        /// <summary>
        /// Updates a group including permissions
        /// </summary>
        /// <param name="name">name of the group to update</param>
        /// <param name="parentname">parent of group</param>
        /// <param name="permissions">permissions</param>
        /// <param name="chatcolor">chatcolor</param>
        public void UpdateGroup(string name, string parentname, string permissions, string chatcolor)
        {
            if (!GroupExists(name))
            {
                throw new GroupNotExistException(name);
            }

            Group parent = null;

            if (!string.IsNullOrWhiteSpace(parentname))
            {
                parent = groups.FirstOrDefault(gp => gp.Name == parentname);
                if (null == parent)
                {
                    throw new GroupManagerException("Invalid parent {0} for group {1}".SFormat(parentname, name));
                }
            }

            // NOTE: we use newgroup.XYZ to ensure any 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";

            if (database.Query(query, parentname, newgroup.Permissions, string.Format("{0},{1},{2}", newgroup.R, newgroup.G, newgroup.B), name) != 1)
            {
                throw new GroupManagerException("Failed to update group '" + name + "'");
            }

            Group group = tPulse.GetGroup(name);

            group.ChatColor   = chatcolor;
            group.Permissions = permissions;
            group.Parent      = tPulse.GetGroup(parentname);
        }
예제 #2
0
 /// <summary>
 /// Returns a Group for a ip from the database
 /// </summary>
 /// <param name="ply">string ip</param>
 public Group GetGroupForIP(string ip)
 {
     try
     {
         using (var reader = database.QueryReader("SELECT * FROM Users WHERE IP=@0", ip))
         {
             if (reader.Read())
             {
                 string group = reader.Get <string>("UserGroup");
                 return(tPulse.GetGroup(group));
             }
         }
     }
     catch (Exception ex)
     {
         Log.ConsoleError("GetGroupForIP SQL returned an error: " + ex);
     }
     return(tPulse.GetGroup(tPulse.Config.DefaultGuestGroupName));
 }