From: <z-...@us...> - 2008-01-26 01:36:45
|
Revision: 7626 http://armagetronad.svn.sourceforge.net/armagetronad/?rev=7626&view=rev Author: z-man Date: 2008-01-25 17:36:50 -0800 (Fri, 25 Jan 2008) Log Message: ----------- Added SUDO command. Modified Paths: -------------- armagetronad/branches/0.2.8-auth/armagetronad/NEWS armagetronad/branches/0.2.8-auth/armagetronad/src/tools/tConfiguration.cpp armagetronad/branches/0.2.8-auth/armagetronad/src/tools/tConfiguration.h Modified: armagetronad/branches/0.2.8-auth/armagetronad/NEWS =================================================================== --- armagetronad/branches/0.2.8-auth/armagetronad/NEWS 2008-01-25 23:10:10 UTC (rev 7625) +++ armagetronad/branches/0.2.8-auth/armagetronad/NEWS 2008-01-26 01:36:50 UTC (rev 7626) @@ -1,6 +1,7 @@ Changes since 0.2.8.2: New settings and commands: +- SUDO to temporarily raise the access level - ACCESS_LEVEL to modify the required access level to change settings - KICK_TO and MOVE_TO: redirect a client to a different server - DEFAULT_KICK(_TO)_MESSAGE: default reason given to players for a kick Modified: armagetronad/branches/0.2.8-auth/armagetronad/src/tools/tConfiguration.cpp =================================================================== --- armagetronad/branches/0.2.8-auth/armagetronad/src/tools/tConfiguration.cpp 2008-01-25 23:10:10 UTC (rev 7625) +++ armagetronad/branches/0.2.8-auth/armagetronad/src/tools/tConfiguration.cpp 2008-01-26 01:36:50 UTC (rev 7626) @@ -151,6 +151,12 @@ currentLevel_ = newLevel; } + +tCurrentAccessLevel::tCurrentAccessLevel() +{ + lastLevel_ = currentLevel_; +} + tCurrentAccessLevel::~tCurrentAccessLevel() { currentLevel_ = lastLevel_; @@ -238,7 +244,7 @@ { tASSERT(0); } - + virtual bool Writable(){ return false; } @@ -246,11 +252,63 @@ virtual bool Save(){ return false; } - }; static tConfItemLevel st_confLevel; +//! sudo command: elevates the access level for the context of the current configuration file +class tSudo: tConfItemBase +{ +public: + tSudo() + : tConfItemBase( "SUDO" ) + { + requiredLevel = tAccessLevel_Program; + } + + virtual void ReadVal( std::istream & s ) + { + int required_int = 0, elevated_int = 20; + + // read required and elevated access levels + s >> required_int; + s >> elevated_int; + + tAccessLevel elevated = static_cast< tAccessLevel >( elevated_int ); + tAccessLevel required = static_cast< tAccessLevel >( required_int ); + + if ( s.eof() || !s.good() || s.fail() ) + { + con << tOutput( "$sudo_usage" ); + } + else if ( tCurrentAccessLevel::GetAccessLevel() < required ) + { + con << tOutput( "$access_level_error", + "SUDO", + required, + tCurrentAccessLevel::GetName( tCurrentAccessLevel::GetAccessLevel() ) + ); + } + else + { + tCurrentAccessLevel::currentLevel_ = elevated; + } + } + + virtual void WriteVal(std::ostream &s) + { + tASSERT(0); + } + + virtual bool Writable(){ + return false; + } + + virtual bool Save(){ + return false; + } +}; + bool st_FirstUse=true; static tConfItem<bool> fu("FIRST_USE",st_FirstUse); //static tConfItem<bool> fu("FIRST_USE","help_first_use",st_FirstUse); @@ -565,6 +623,8 @@ } void tConfItemBase::LoadAll(std::istream &s){ + tCurrentAccessLevel levelResetter; + while(!s.eof() && s.good()) { tString line; Modified: armagetronad/branches/0.2.8-auth/armagetronad/src/tools/tConfiguration.h =================================================================== --- armagetronad/branches/0.2.8-auth/armagetronad/src/tools/tConfiguration.h 2008-01-25 23:10:10 UTC (rev 7625) +++ armagetronad/branches/0.2.8-auth/armagetronad/src/tools/tConfiguration.h 2008-01-26 01:36:50 UTC (rev 7626) @@ -168,9 +168,13 @@ //! class managing the current access level class tCurrentAccessLevel { + friend class tSudo; public: //! for the lifetime of this object, change the user's admit level to the passed one. tCurrentAccessLevel( tAccessLevel newLevel ); + + //! does not change the access level on construction, but resets it on destruction + tCurrentAccessLevel(); ~tCurrentAccessLevel(); //! returns the current access level @@ -179,7 +183,6 @@ //! returns the name of an access level static tString GetName( tAccessLevel level ); private: - tCurrentAccessLevel(); tCurrentAccessLevel( tCurrentAccessLevel const & ); tCurrentAccessLevel & operator = ( tCurrentAccessLevel const & ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |