PageRenderTime 43ms CodeModel.GetById 29ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 28#include "llagentaccess.h"
 29#include "indra_constants.h"
 30#include "llcontrol.h"
 31
 32LLAgentAccess::LLAgentAccess(LLControlGroup& savedSettings) :
 33	mSavedSettings(savedSettings),
 34	mAccess(SIM_ACCESS_PG),
 35	mAdminOverride(false),
 36	mGodLevel(GOD_NOT),
 37	mAOTransition(false)
 38{
 39}
 40
 41bool LLAgentAccess::getAdminOverride() const	
 42{ 
 43	return mAdminOverride; 
 44}
 45
 46void LLAgentAccess::setAdminOverride(bool b)
 47{ 
 48	mAdminOverride = b; 
 49}
 50
 51void LLAgentAccess::setGodLevel(U8 god_level)
 52{ 
 53	mGodLevel = god_level; 
 54}
 55
 56bool LLAgentAccess::isGodlike() const
 57{
 58#ifdef HACKED_GODLIKE_VIEWER
 59	return true;
 60#else
 61	if(mAdminOverride) return true;
 62	return mGodLevel > GOD_NOT;
 63#endif
 64}
 65
 66bool LLAgentAccess::isGodlikeWithoutAdminMenuFakery() const
 67{
 68#ifdef HACKED_GODLIKE_VIEWER
 69	return true;
 70#else
 71	return mGodLevel > GOD_NOT;
 72#endif
 73}
 74
 75U8 LLAgentAccess::getGodLevel() const
 76{
 77#ifdef HACKED_GODLIKE_VIEWER
 78	return GOD_MAINTENANCE;
 79#else
 80	if(mAdminOverride) return GOD_FULL; // :(
 81	return mGodLevel;
 82#endif
 83}
 84
 85bool LLAgentAccess::wantsPGOnly() const
 86{
 87	return (prefersPG() || isTeen()) && !isGodlike();
 88}
 89
 90bool LLAgentAccess::canAccessMature() const
 91{
 92	// if you prefer mature, you're either mature or adult, and
 93	// therefore can access all mature content
 94	return isGodlike() || (prefersMature() && !isTeen());
 95}
 96
 97bool LLAgentAccess::canAccessAdult() const
 98{
 99	// if you prefer adult, you must BE adult.
100	return isGodlike() || (prefersAdult() && isAdult());
101}
102
103bool LLAgentAccess::prefersPG() const
104{
105	U32 access = mSavedSettings.getU32("PreferredMaturity");
106	return access < SIM_ACCESS_MATURE;
107}
108
109bool LLAgentAccess::prefersMature() const
110{
111	U32 access = mSavedSettings.getU32("PreferredMaturity");
112	return access >= SIM_ACCESS_MATURE;
113}
114
115bool LLAgentAccess::prefersAdult() const
116{
117	U32 access = mSavedSettings.getU32("PreferredMaturity");
118	return access >= SIM_ACCESS_ADULT;
119}
120
121bool LLAgentAccess::isTeen() const
122{
123	return mAccess < SIM_ACCESS_MATURE;
124}
125
126bool LLAgentAccess::isMature() const
127{
128	return mAccess >= SIM_ACCESS_MATURE;
129}
130
131bool LLAgentAccess::isAdult() const
132{
133	return mAccess >= SIM_ACCESS_ADULT;
134}
135
136void LLAgentAccess::setTeen(bool teen)
137{
138	if (teen)
139	{
140		mAccess = SIM_ACCESS_PG;
141	}
142	else
143	{
144		mAccess = SIM_ACCESS_MATURE;
145	}
146}
147
148//static 
149int LLAgentAccess::convertTextToMaturity(char text)
150{
151	if ('A' == text)
152	{
153		return SIM_ACCESS_ADULT;
154	}
155	else if ('M'== text)
156	{
157		return SIM_ACCESS_MATURE;
158	}
159	else if ('P'== text)
160	{
161		return SIM_ACCESS_PG;
162	}
163	return SIM_ACCESS_MIN;
164}
165
166void LLAgentAccess::setMaturity(char text)
167{
168	mAccess = LLAgentAccess::convertTextToMaturity(text);
169	U32 preferred_access = mSavedSettings.getU32("PreferredMaturity");
170	while (!canSetMaturity(preferred_access))
171	{
172		if (preferred_access == SIM_ACCESS_ADULT)
173		{
174			preferred_access = SIM_ACCESS_MATURE;
175		}
176		else
177		{
178			// Mature or invalid access gets set to PG
179			preferred_access = SIM_ACCESS_PG;
180		}
181	}
182	mSavedSettings.setU32("PreferredMaturity", preferred_access);
183}
184
185void LLAgentAccess::setTransition()
186{
187	mAOTransition = true;
188}
189
190bool LLAgentAccess::isInTransition() const
191{
192	return mAOTransition;
193}
194
195bool LLAgentAccess::canSetMaturity(S32 maturity)
196{
197	if (isGodlike()) // Gods can always set their Maturity level
198		return true;
199	if (isAdult()) // Adults can always set their Maturity level
200		return true;
201	if (maturity == SIM_ACCESS_PG || (maturity == SIM_ACCESS_MATURE && isMature()))
202		return true;
203	else
204		return false;
205}