From 28bc14e267daff85d66efc9467f40ce87bfcb858 Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 1 Feb 2012 00:02:48 +0000 Subject: Plugins can now be enabled and disabled through WebAdmin WebPlugins can now have spaces in their tab names git-svn-id: http://mc-server.googlecode.com/svn/trunk@204 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cWebPlugin_Lua.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'source/cWebPlugin_Lua.cpp') diff --git a/source/cWebPlugin_Lua.cpp b/source/cWebPlugin_Lua.cpp index d1446ba24..bb3f79226 100644 --- a/source/cWebPlugin_Lua.cpp +++ b/source/cWebPlugin_Lua.cpp @@ -8,7 +8,20 @@ #include "cWebAdmin.h" - +static std::string SafeString( const std::string& a_String ) +{ + std::string RetVal; + for( unsigned int i = 0; i < a_String.size(); ++i ) + { + char c = a_String[i]; + if( c == ' ' ) + { + c = '_'; + } + RetVal.push_back( c ); + } + return RetVal; +} extern bool report_errors(lua_State* lua, int status); @@ -47,7 +60,7 @@ bool cWebPlugin_Lua::AddTab( const char* a_Title, lua_State * a_LuaState, int a_ } sWebPluginTab* Tab = new sWebPluginTab(); Tab->Title = a_Title; - Tab->SafeTitle = a_Title; // TODO - Convert all non alphabet/digit letters to underscores + Tab->SafeTitle = SafeString( a_Title ); Tab->Reference = a_FunctionReference; @@ -60,14 +73,15 @@ std::string cWebPlugin_Lua::HandleRequest( HTTPRequest* a_Request ) lua_State* LuaState = m_Plugin->GetLuaState(); std::string RetVal = ""; - std::string TabName = GetTabNameForRequest(a_Request); - if( TabName.empty() ) + std::pair< std::string, std::string > TabName = GetTabNameForRequest(a_Request); + std::string SafeTabName = TabName.second; + if( SafeTabName.empty() ) return ""; sWebPluginTab* Tab = 0; for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr ) { - if( (*itr)->Title.compare( TabName ) == 0 ) // This is the one! Rawr + if( (*itr)->SafeTitle.compare( SafeTabName ) == 0 ) // This is the one! Rawr { Tab = *itr; break; @@ -113,8 +127,9 @@ void cWebPlugin_Lua::Initialize() { } -std::string cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request ) +std::pair< std::string, std::string > cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request ) { + std::pair< std::string, std::string > Names; std::vector Split = StringSplit( a_Request->Path, "/" ); if( Split.size() > 1 ) @@ -139,19 +154,23 @@ std::string cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request ) if( Tab ) { - return Tab->Title; + Names.first = Tab->Title; + Names.second = Tab->SafeTitle; } } - return ""; + return Names; } -std::list< std::string > cWebPlugin_Lua::GetTabNames() +std::list< std::pair > cWebPlugin_Lua::GetTabNames() { - std::list< std::string > NameList; + std::list< std::pair< std::string, std::string > > NameList; for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr ) { - NameList.push_back( (*itr)->Title ); + std::pair< std::string, std::string > StringPair; + StringPair.first = (*itr)->Title; + StringPair.second = (*itr)->SafeTitle; + NameList.push_back( StringPair ); } return NameList; } \ No newline at end of file -- cgit v1.2.3