/indra/newview/llagentaccess.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 205 lines · 152 code · 23 blank · 30 comment · 25 complexity · 01e125d037864f35d0e5d396ddf1e615 MD5 · raw file

  1. /**
  2. * @file llagentaccess.cpp
  3. * @brief LLAgentAccess class implementation - manages maturity and godmode info
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llagentaccess.h"
  28. #include "indra_constants.h"
  29. #include "llcontrol.h"
  30. LLAgentAccess::LLAgentAccess(LLControlGroup& savedSettings) :
  31. mSavedSettings(savedSettings),
  32. mAccess(SIM_ACCESS_PG),
  33. mAdminOverride(false),
  34. mGodLevel(GOD_NOT),
  35. mAOTransition(false)
  36. {
  37. }
  38. bool LLAgentAccess::getAdminOverride() const
  39. {
  40. return mAdminOverride;
  41. }
  42. void LLAgentAccess::setAdminOverride(bool b)
  43. {
  44. mAdminOverride = b;
  45. }
  46. void LLAgentAccess::setGodLevel(U8 god_level)
  47. {
  48. mGodLevel = god_level;
  49. }
  50. bool LLAgentAccess::isGodlike() const
  51. {
  52. #ifdef HACKED_GODLIKE_VIEWER
  53. return true;
  54. #else
  55. if(mAdminOverride) return true;
  56. return mGodLevel > GOD_NOT;
  57. #endif
  58. }
  59. bool LLAgentAccess::isGodlikeWithoutAdminMenuFakery() const
  60. {
  61. #ifdef HACKED_GODLIKE_VIEWER
  62. return true;
  63. #else
  64. return mGodLevel > GOD_NOT;
  65. #endif
  66. }
  67. U8 LLAgentAccess::getGodLevel() const
  68. {
  69. #ifdef HACKED_GODLIKE_VIEWER
  70. return GOD_MAINTENANCE;
  71. #else
  72. if(mAdminOverride) return GOD_FULL; // :(
  73. return mGodLevel;
  74. #endif
  75. }
  76. bool LLAgentAccess::wantsPGOnly() const
  77. {
  78. return (prefersPG() || isTeen()) && !isGodlike();
  79. }
  80. bool LLAgentAccess::canAccessMature() const
  81. {
  82. // if you prefer mature, you're either mature or adult, and
  83. // therefore can access all mature content
  84. return isGodlike() || (prefersMature() && !isTeen());
  85. }
  86. bool LLAgentAccess::canAccessAdult() const
  87. {
  88. // if you prefer adult, you must BE adult.
  89. return isGodlike() || (prefersAdult() && isAdult());
  90. }
  91. bool LLAgentAccess::prefersPG() const
  92. {
  93. U32 access = mSavedSettings.getU32("PreferredMaturity");
  94. return access < SIM_ACCESS_MATURE;
  95. }
  96. bool LLAgentAccess::prefersMature() const
  97. {
  98. U32 access = mSavedSettings.getU32("PreferredMaturity");
  99. return access >= SIM_ACCESS_MATURE;
  100. }
  101. bool LLAgentAccess::prefersAdult() const
  102. {
  103. U32 access = mSavedSettings.getU32("PreferredMaturity");
  104. return access >= SIM_ACCESS_ADULT;
  105. }
  106. bool LLAgentAccess::isTeen() const
  107. {
  108. return mAccess < SIM_ACCESS_MATURE;
  109. }
  110. bool LLAgentAccess::isMature() const
  111. {
  112. return mAccess >= SIM_ACCESS_MATURE;
  113. }
  114. bool LLAgentAccess::isAdult() const
  115. {
  116. return mAccess >= SIM_ACCESS_ADULT;
  117. }
  118. void LLAgentAccess::setTeen(bool teen)
  119. {
  120. if (teen)
  121. {
  122. mAccess = SIM_ACCESS_PG;
  123. }
  124. else
  125. {
  126. mAccess = SIM_ACCESS_MATURE;
  127. }
  128. }
  129. //static
  130. int LLAgentAccess::convertTextToMaturity(char text)
  131. {
  132. if ('A' == text)
  133. {
  134. return SIM_ACCESS_ADULT;
  135. }
  136. else if ('M'== text)
  137. {
  138. return SIM_ACCESS_MATURE;
  139. }
  140. else if ('P'== text)
  141. {
  142. return SIM_ACCESS_PG;
  143. }
  144. return SIM_ACCESS_MIN;
  145. }
  146. void LLAgentAccess::setMaturity(char text)
  147. {
  148. mAccess = LLAgentAccess::convertTextToMaturity(text);
  149. U32 preferred_access = mSavedSettings.getU32("PreferredMaturity");
  150. while (!canSetMaturity(preferred_access))
  151. {
  152. if (preferred_access == SIM_ACCESS_ADULT)
  153. {
  154. preferred_access = SIM_ACCESS_MATURE;
  155. }
  156. else
  157. {
  158. // Mature or invalid access gets set to PG
  159. preferred_access = SIM_ACCESS_PG;
  160. }
  161. }
  162. mSavedSettings.setU32("PreferredMaturity", preferred_access);
  163. }
  164. void LLAgentAccess::setTransition()
  165. {
  166. mAOTransition = true;
  167. }
  168. bool LLAgentAccess::isInTransition() const
  169. {
  170. return mAOTransition;
  171. }
  172. bool LLAgentAccess::canSetMaturity(S32 maturity)
  173. {
  174. if (isGodlike()) // Gods can always set their Maturity level
  175. return true;
  176. if (isAdult()) // Adults can always set their Maturity level
  177. return true;
  178. if (maturity == SIM_ACCESS_PG || (maturity == SIM_ACCESS_MATURE && isMature()))
  179. return true;
  180. else
  181. return false;
  182. }