summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-01 01:02:48 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-01 01:02:48 +0100
commit28bc14e267daff85d66efc9467f40ce87bfcb858 (patch)
treea2ab38d5f8805c64294905a4b65b694d6dfeacf7
parentChanged how Lua handles the (Post)Params in the HTTPRequest of a WebPlugin (diff)
downloadcuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.gz
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.bz2
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.lz
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.xz
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.zst
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.zip
-rw-r--r--Plugins/Core/main.lua2
-rw-r--r--Plugins/Core/web_reload.lua15
-rw-r--r--iniFile/iniFile.cpp22
-rw-r--r--iniFile/iniFile.h1
-rw-r--r--source/Bindings.cpp39
-rw-r--r--source/Bindings.h2
-rw-r--r--source/cWebAdmin.cpp8
-rw-r--r--source/cWebPlugin_Lua.cpp41
-rw-r--r--source/cWebPlugin_Lua.h4
9 files changed, 92 insertions, 42 deletions
diff --git a/Plugins/Core/main.lua b/Plugins/Core/main.lua
index d8fadaad9..e057fb4ce 100644
--- a/Plugins/Core/main.lua
+++ b/Plugins/Core/main.lua
@@ -131,8 +131,8 @@ function Initialize( Plugin )
WebPlugin:SetName( Plugin:GetName() )
WebPlugin:AddTab( "Playerlist", HandleRequest_PlayerList )
WebPlugin:AddTab( "Whitelist", HandleRequest_WhiteList )
- WebPlugin:AddTab( "Reload", HandleRequest_Reload )
WebPlugin:AddTab( "Permissions", HandleRequest_Permissions )
+ WebPlugin:AddTab( "Manage Plugins", HandleRequest_ManagePlugins )
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
return true
diff --git a/Plugins/Core/web_reload.lua b/Plugins/Core/web_reload.lua
deleted file mode 100644
index 3a59ad6b6..000000000
--- a/Plugins/Core/web_reload.lua
+++ /dev/null
@@ -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 \ No newline at end of file
diff --git a/iniFile/iniFile.cpp b/iniFile/iniFile.cpp
index f4381c64f..d1c15df16 100644
--- a/iniFile/iniFile.cpp
+++ b/iniFile/iniFile.cpp
@@ -342,6 +342,20 @@ unsigned cIniFile::GetValueV( const string & keyname, const string & valuename,
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)
{
long keyID = FindKey( keyname);
@@ -352,13 +366,7 @@ bool cIniFile::DeleteValue( const string & keyname, const string & valuename)
if ( valueID == noID)
return false;
- // 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 DeleteValueByID( keyID, valueID );
}
bool cIniFile::DeleteKey( const string & keyname)
diff --git a/iniFile/iniFile.h b/iniFile/iniFile.h
index d0d34e145..6b766ecf7 100644
--- a/iniFile/iniFile.h
+++ b/iniFile/iniFile.h
@@ -138,6 +138,7 @@ public:
// Deletes specified value.
// 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
// Deletes specified key and all values contained within.
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 45008bb32..c8bcc8123 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** 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
@@ -1707,6 +1707,42 @@ static int tolua_AllToLua_cIniFile_SetValueF00(lua_State* tolua_S)
}
#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 */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_DeleteValue00
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,"SetValueB",tolua_AllToLua_cIniFile_SetValueB00);
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,"DeleteKey",tolua_AllToLua_cIniFile_DeleteKey00);
tolua_function(tolua_S,"NumHeaderComments",tolua_AllToLua_cIniFile_NumHeaderComments00);
diff --git a/source/Bindings.h b/source/Bindings.h
index 061f9231e..427b7595b 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** 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 */
diff --git a/source/cWebAdmin.cpp b/source/cWebAdmin.cpp
index b99b8e779..901e24cd7 100644
--- a/source/cWebAdmin.cpp
+++ b/source/cWebAdmin.cpp
@@ -121,10 +121,10 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
if( LuaPlugin )
{
- std::list< std::string > NameList = LuaPlugin->GetTabNames();
- for( std::list< std::string >::iterator Name = NameList.begin(); Name != NameList.end(); ++Name )
+ std::list< std::pair<std::string, std::string> > NameList = LuaPlugin->GetTabNames();
+ 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
@@ -164,7 +164,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
if( LuaPlugin )
{
- FoundPlugin += " - " + LuaPlugin->GetTabNameForRequest( &Request );
+ FoundPlugin += " - " + LuaPlugin->GetTabNameForRequest( &Request ).first;
}
break;
}
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<std::string> 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<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 )
{
- 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
diff --git a/source/cWebPlugin_Lua.h b/source/cWebPlugin_Lua.h
index 98080e855..0444fb44f 100644
--- a/source/cWebPlugin_Lua.h
+++ b/source/cWebPlugin_Lua.h
@@ -17,9 +17,9 @@ public: //tolua_export
virtual std::string HandleRequest( HTTPRequest* a_Request );
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:
cPlugin_NewLua* m_Plugin;