// Execution ValheimPermission.ValheimDB.ShowUserPermissions(SteamID) // Important Note: You need to send the SteamID in STRING format instead of the default LONG format. use SteamID.ToString() before sending. // Results: Will return a string[] of all the permission nodes the user has access to. // Or: will return one array result (false) if there is no permissions. // NOTE: Results will be returned to you in an string[] format! Code accordingly! public static string[] ShowUserPermissions(string SteamID) { string[] nullresult = { "No.Permissions.Found" }; using (var db = new LiteDatabase(DatabaseLocation)) { var Permissions = db.GetCollection <User_Permission>("User_Permission"); var count = Permissions.Count(Query.EQ("SteamID", SteamID)); string[] returnme = new string[0]; int i = 0; if (Util.IsAdmin(long.Parse(SteamID))) { returnme = new string[count + 1]; returnme[0] = "*"; } else { returnme = new string[count]; i = 0; } foreach (var item in Permissions.Find(Query.EQ("SteamID", SteamID)).OrderBy(x => x.permission)) { returnme[i++] = item.permission; } if ((count > 0) || (returnme.Length > 0)) { return(returnme); } return(nullresult); } }
// Execution ValheimPermissions.ValheimDB.ScanUserPermission(SteamID, PERMISSION_NODE) // Important Note: You need to send the SteamID in STRING format instead of the default LONG format. use SteamID.ToString() before sending. // Results: Will return true if the user has permission to that node or higher. // Or: will return false if the user does not have permission to that node // NOTE: Results will be returned to you in BOOL format (true/false) public static bool ScanUserPermission(string SteamID, string permission) { permission = permission.ToLower(); string[] permissionsplit = permission.Split('.'); using (var db = new LiteDatabase(DatabaseLocation)) { var Permissions = db.GetCollection <User_Permission>("User_Permission"); int i = 0; string lookuppermission = ""; if (Util.IsAdmin(long.Parse(SteamID))) { return(true); } var pexists = Permissions.FindOne(Query.And(Query.EQ("SteamID", SteamID.ToString()), Query.EQ("permission", lookuppermission + "*"))); if (pexists != null) { return(true); } while (i < permissionsplit.Length) { if (i == 0) { lookuppermission = permissionsplit[i].ToLower(); } else { lookuppermission = lookuppermission + "." + permissionsplit[i].ToLower(); } if (i + 1 != permissionsplit.Length) { pexists = Permissions.FindOne(Query.And(Query.EQ("SteamID", SteamID.ToString()), Query.EQ("permission", lookuppermission + ".*"))); } else { pexists = Permissions.FindOne(Query.And(Query.EQ("SteamID", SteamID.ToString()), Query.EQ("permission", lookuppermission))); } if (pexists != null) { return(true); } if (i + 1 == permissionsplit.Length) { return(false); } i++; } } return(false); }