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
This commit is contained in:
parent
968f41ba51
commit
28bc14e267
@ -131,8 +131,8 @@ function Initialize( Plugin )
|
|||||||
WebPlugin:SetName( Plugin:GetName() )
|
WebPlugin:SetName( Plugin:GetName() )
|
||||||
WebPlugin:AddTab( "Playerlist", HandleRequest_PlayerList )
|
WebPlugin:AddTab( "Playerlist", HandleRequest_PlayerList )
|
||||||
WebPlugin:AddTab( "Whitelist", HandleRequest_WhiteList )
|
WebPlugin:AddTab( "Whitelist", HandleRequest_WhiteList )
|
||||||
WebPlugin:AddTab( "Reload", HandleRequest_Reload )
|
|
||||||
WebPlugin:AddTab( "Permissions", HandleRequest_Permissions )
|
WebPlugin:AddTab( "Permissions", HandleRequest_Permissions )
|
||||||
|
WebPlugin:AddTab( "Manage Plugins", HandleRequest_ManagePlugins )
|
||||||
|
|
||||||
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
||||||
return true
|
return true
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
function HandleRequest_Reload( Request )
|
|
||||||
local Content = ""
|
|
||||||
|
|
||||||
if( Request.PostParams["reload"] ~= nil ) then
|
|
||||||
Content = Content .. "<head><meta http-equiv=\"refresh\" content=\"2;././\"></head>"
|
|
||||||
Content = Content .. "<p>Reloading plugins... This can take a while depending on the plugins you're using.</p>"
|
|
||||||
cRoot:Get():GetPluginManager():ReloadPlugins()
|
|
||||||
else
|
|
||||||
Content = Content .. "<form method=POST>"
|
|
||||||
Content = Content .. "<p>Click the reload button to reload all plugins!<br>"
|
|
||||||
Content = Content .. "<input type=\"submit\" name=\"reload\" value=\"Reload!\"></p>"
|
|
||||||
Content = Content .. "</form>"
|
|
||||||
end
|
|
||||||
return Content
|
|
||||||
end
|
|
@ -342,6 +342,20 @@ unsigned cIniFile::GetValueV( const string & keyname, const string & valuename,
|
|||||||
return nVals;
|
return nVals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cIniFile::DeleteValueByID( const unsigned keyID, const unsigned valueID )
|
||||||
|
{
|
||||||
|
if ( keyID < keys.size() && valueID < keys[keyID].names.size())
|
||||||
|
{
|
||||||
|
// This looks strange, but is neccessary.
|
||||||
|
vector<string>::iterator npos = keys[keyID].names.begin() + valueID;
|
||||||
|
vector<string>::iterator vpos = keys[keyID].values.begin() + valueID;
|
||||||
|
keys[keyID].names.erase( npos, npos + 1);
|
||||||
|
keys[keyID].values.erase( vpos, vpos + 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool cIniFile::DeleteValue( const string & keyname, const string & valuename)
|
bool cIniFile::DeleteValue( const string & keyname, const string & valuename)
|
||||||
{
|
{
|
||||||
long keyID = FindKey( keyname);
|
long keyID = FindKey( keyname);
|
||||||
@ -352,13 +366,7 @@ bool cIniFile::DeleteValue( const string & keyname, const string & valuename)
|
|||||||
if ( valueID == noID)
|
if ( valueID == noID)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// This looks strange, but is neccessary.
|
return DeleteValueByID( keyID, valueID );
|
||||||
vector<string>::iterator npos = keys[keyID].names.begin() + valueID;
|
|
||||||
vector<string>::iterator vpos = keys[keyID].values.begin() + valueID;
|
|
||||||
keys[keyID].names.erase( npos, npos + 1);
|
|
||||||
keys[keyID].values.erase( vpos, vpos + 1);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cIniFile::DeleteKey( const string & keyname)
|
bool cIniFile::DeleteKey( const string & keyname)
|
||||||
|
@ -138,6 +138,7 @@ public:
|
|||||||
|
|
||||||
// Deletes specified value.
|
// Deletes specified value.
|
||||||
// Returns true if value existed and deleted, false otherwise.
|
// Returns true if value existed and deleted, false otherwise.
|
||||||
|
bool DeleteValueByID( const unsigned keyID, const unsigned valueID ); //tolua_export
|
||||||
bool DeleteValue( const std::string & keyname, const std::string & valuename); //tolua_export
|
bool DeleteValue( const std::string & keyname, const std::string & valuename); //tolua_export
|
||||||
|
|
||||||
// Deletes specified key and all values contained within.
|
// Deletes specified key and all values contained within.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** Lua binding: AllToLua
|
** Lua binding: AllToLua
|
||||||
** Generated automatically by tolua++-1.0.92 on 01/31/12 19:40:39.
|
** Generated automatically by tolua++-1.0.92 on 02/01/12 00:50:40.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
@ -1707,6 +1707,42 @@ static int tolua_AllToLua_cIniFile_SetValueF00(lua_State* tolua_S)
|
|||||||
}
|
}
|
||||||
#endif //#ifndef TOLUA_DISABLE
|
#endif //#ifndef TOLUA_DISABLE
|
||||||
|
|
||||||
|
/* method: DeleteValueByID of class cIniFile */
|
||||||
|
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_DeleteValueByID00
|
||||||
|
static int tolua_AllToLua_cIniFile_DeleteValueByID00(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
#ifndef TOLUA_RELEASE
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
if (
|
||||||
|
!tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) ||
|
||||||
|
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
|
||||||
|
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
|
||||||
|
!tolua_isnoobj(tolua_S,4,&tolua_err)
|
||||||
|
)
|
||||||
|
goto tolua_lerror;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0);
|
||||||
|
const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0));
|
||||||
|
const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0));
|
||||||
|
#ifndef TOLUA_RELEASE
|
||||||
|
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteValueByID'", NULL);
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
bool tolua_ret = (bool) self->DeleteValueByID(keyID,valueID);
|
||||||
|
tolua_pushboolean(tolua_S,(bool)tolua_ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
#ifndef TOLUA_RELEASE
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'DeleteValueByID'.",&tolua_err);
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif //#ifndef TOLUA_DISABLE
|
||||||
|
|
||||||
/* method: DeleteValue of class cIniFile */
|
/* method: DeleteValue of class cIniFile */
|
||||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_DeleteValue00
|
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_DeleteValue00
|
||||||
static int tolua_AllToLua_cIniFile_DeleteValue00(lua_State* tolua_S)
|
static int tolua_AllToLua_cIniFile_DeleteValue00(lua_State* tolua_S)
|
||||||
@ -16278,6 +16314,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
|||||||
tolua_function(tolua_S,"SetValueI",tolua_AllToLua_cIniFile_SetValueI00);
|
tolua_function(tolua_S,"SetValueI",tolua_AllToLua_cIniFile_SetValueI00);
|
||||||
tolua_function(tolua_S,"SetValueB",tolua_AllToLua_cIniFile_SetValueB00);
|
tolua_function(tolua_S,"SetValueB",tolua_AllToLua_cIniFile_SetValueB00);
|
||||||
tolua_function(tolua_S,"SetValueF",tolua_AllToLua_cIniFile_SetValueF00);
|
tolua_function(tolua_S,"SetValueF",tolua_AllToLua_cIniFile_SetValueF00);
|
||||||
|
tolua_function(tolua_S,"DeleteValueByID",tolua_AllToLua_cIniFile_DeleteValueByID00);
|
||||||
tolua_function(tolua_S,"DeleteValue",tolua_AllToLua_cIniFile_DeleteValue00);
|
tolua_function(tolua_S,"DeleteValue",tolua_AllToLua_cIniFile_DeleteValue00);
|
||||||
tolua_function(tolua_S,"DeleteKey",tolua_AllToLua_cIniFile_DeleteKey00);
|
tolua_function(tolua_S,"DeleteKey",tolua_AllToLua_cIniFile_DeleteKey00);
|
||||||
tolua_function(tolua_S,"NumHeaderComments",tolua_AllToLua_cIniFile_NumHeaderComments00);
|
tolua_function(tolua_S,"NumHeaderComments",tolua_AllToLua_cIniFile_NumHeaderComments00);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** Lua binding: AllToLua
|
** Lua binding: AllToLua
|
||||||
** Generated automatically by tolua++-1.0.92 on 01/31/12 19:40:39.
|
** Generated automatically by tolua++-1.0.92 on 02/01/12 00:50:40.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Exported function */
|
/* Exported function */
|
||||||
|
@ -121,10 +121,10 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
|
|||||||
cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
|
cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
|
||||||
if( LuaPlugin )
|
if( LuaPlugin )
|
||||||
{
|
{
|
||||||
std::list< std::string > NameList = LuaPlugin->GetTabNames();
|
std::list< std::pair<std::string, std::string> > NameList = LuaPlugin->GetTabNames();
|
||||||
for( std::list< std::string >::iterator Name = NameList.begin(); Name != NameList.end(); ++Name )
|
for( std::list< std::pair<std::string, std::string> >::iterator Names = NameList.begin(); Names != NameList.end(); ++Names )
|
||||||
{
|
{
|
||||||
Menu += "<li><a href='" + BaseURL + WebPlugin->GetName() + "/" + (*Name) + "'>" + (*Name) + "</a></li>";
|
Menu += "<li><a href='" + BaseURL + WebPlugin->GetName() + "/" + (*Names).second + "'>" + (*Names).first + "</a></li>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -164,7 +164,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
|
|||||||
cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
|
cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
|
||||||
if( LuaPlugin )
|
if( LuaPlugin )
|
||||||
{
|
{
|
||||||
FoundPlugin += " - " + LuaPlugin->GetTabNameForRequest( &Request );
|
FoundPlugin += " - " + LuaPlugin->GetTabNameForRequest( &Request ).first;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,20 @@
|
|||||||
#include "cWebAdmin.h"
|
#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);
|
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();
|
sWebPluginTab* Tab = new sWebPluginTab();
|
||||||
Tab->Title = a_Title;
|
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;
|
Tab->Reference = a_FunctionReference;
|
||||||
|
|
||||||
@ -60,14 +73,15 @@ std::string cWebPlugin_Lua::HandleRequest( HTTPRequest* a_Request )
|
|||||||
lua_State* LuaState = m_Plugin->GetLuaState();
|
lua_State* LuaState = m_Plugin->GetLuaState();
|
||||||
std::string RetVal = "";
|
std::string RetVal = "";
|
||||||
|
|
||||||
std::string TabName = GetTabNameForRequest(a_Request);
|
std::pair< std::string, std::string > TabName = GetTabNameForRequest(a_Request);
|
||||||
if( TabName.empty() )
|
std::string SafeTabName = TabName.second;
|
||||||
|
if( SafeTabName.empty() )
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
sWebPluginTab* Tab = 0;
|
sWebPluginTab* Tab = 0;
|
||||||
for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
|
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;
|
Tab = *itr;
|
||||||
break;
|
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<std::string> Split = StringSplit( a_Request->Path, "/" );
|
std::vector<std::string> Split = StringSplit( a_Request->Path, "/" );
|
||||||
|
|
||||||
if( Split.size() > 1 )
|
if( Split.size() > 1 )
|
||||||
@ -139,19 +154,23 @@ std::string cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request )
|
|||||||
|
|
||||||
if( Tab )
|
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<std::string, std::string> > 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 )
|
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;
|
return NameList;
|
||||||
}
|
}
|
@ -17,9 +17,9 @@ public: //tolua_export
|
|||||||
virtual std::string HandleRequest( HTTPRequest* a_Request );
|
virtual std::string HandleRequest( HTTPRequest* a_Request );
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
|
|
||||||
std::string GetTabNameForRequest( HTTPRequest* a_Request );
|
std::pair< std::string, std::string > GetTabNameForRequest( HTTPRequest* a_Request );
|
||||||
|
|
||||||
std::list< std::string > GetTabNames();
|
std::list< std::pair<std::string, std::string> > GetTabNames();
|
||||||
private:
|
private:
|
||||||
cPlugin_NewLua* m_Plugin;
|
cPlugin_NewLua* m_Plugin;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user