1
0

ISharedAdminManager.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Robust.Shared.Player;
  2. namespace Content.Shared.Administration.Managers;
  3. /// <summary>
  4. /// Manages server administrators and their permission flags.
  5. /// </summary>
  6. public interface ISharedAdminManager
  7. {
  8. /// <summary>
  9. /// Gets the admin data for a player, if they are an admin.
  10. /// </summary>
  11. /// <remarks>
  12. /// When used by the client, this only returns accurate results for the player's own entity.
  13. /// </remarks>
  14. /// <param name="includeDeAdmin">
  15. /// Whether to return admin data for admins that are current de-adminned.
  16. /// </param>
  17. /// <returns><see langword="null" /> if the player is not an admin.</returns>
  18. AdminData? GetAdminData(EntityUid uid, bool includeDeAdmin = false);
  19. /// <summary>
  20. /// Gets the admin data for a player, if they are an admin.
  21. /// </summary>
  22. /// <remarks>
  23. /// When used by the client, this only returns accurate results for the player's own session.
  24. /// </remarks>
  25. /// <param name="includeDeAdmin">
  26. /// Whether to return admin data for admins that are current de-adminned.
  27. /// </param>
  28. /// <returns><see langword="null" /> if the player is not an admin.</returns>
  29. AdminData? GetAdminData(ICommonSession session, bool includeDeAdmin = false);
  30. /// <summary>
  31. /// See if a player has an admin flag.
  32. /// </summary>
  33. /// <remarks>
  34. /// When used by the client, this only returns accurate results for the player's own entity.
  35. /// </remarks>
  36. /// <param name="includeDeAdmin">
  37. /// Whether to check flags even for admins that are current de-adminned.
  38. /// </param>
  39. /// <returns>True if the player is and admin and has the specified flags.</returns>
  40. bool HasAdminFlag(EntityUid player, AdminFlags flag, bool includeDeAdmin = false)
  41. {
  42. var data = GetAdminData(player, includeDeAdmin);
  43. return data != null && data.HasFlag(flag, includeDeAdmin);
  44. }
  45. /// <summary>
  46. /// See if a player has an admin flag.
  47. /// </summary>
  48. /// <remarks>
  49. /// When used by the client, this only returns accurate results for the player's own session.
  50. /// </remarks>
  51. /// <param name="includeDeAdmin">
  52. /// Whether to check flags even for admins that are current de-adminned.
  53. /// </param>
  54. /// <returns>True if the player is and admin and has the specified flags.</returns>
  55. bool HasAdminFlag(ICommonSession player, AdminFlags flag, bool includeDeAdmin = false)
  56. {
  57. var data = GetAdminData(player, includeDeAdmin);
  58. return data != null && data.HasFlag(flag, includeDeAdmin);
  59. }
  60. /// <summary>
  61. /// Checks if a player is an admin.
  62. /// </summary>
  63. /// <remarks>
  64. /// When used by the client, this only returns accurate results for the player's own entity.
  65. /// </remarks>
  66. /// <param name="includeDeAdmin">
  67. /// Whether to return admin data for admins that are current de-adminned.
  68. /// </param>
  69. /// <returns>true if the player is an admin, false otherwise.</returns>
  70. bool IsAdmin(EntityUid uid, bool includeDeAdmin = false)
  71. {
  72. return GetAdminData(uid, includeDeAdmin) != null;
  73. }
  74. /// <summary>
  75. /// Checks if a player is an admin.
  76. /// </summary>
  77. /// <remarks>
  78. /// When used by the client, this only returns accurate results for the player's own session.
  79. /// </remarks>
  80. /// <param name="includeDeAdmin">
  81. /// Whether to return admin data for admins that are current de-adminned.
  82. /// </param>
  83. /// <returns>true if the player is an admin, false otherwise.</returns>
  84. bool IsAdmin(ICommonSession session, bool includeDeAdmin = false)
  85. {
  86. return GetAdminData(session, includeDeAdmin) != null;
  87. }
  88. }