WebAdmin should not cause crashes anymore
Got rid of cWebPlugin_Lua cPlugin_Lua is also a cWebPlugin now, so plugins don't need a separate cWebPlugin object Changed some stuff to use AString instead of char* git-svn-id: http://mc-server.googlecode.com/svn/trunk@777 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
0da4f7eaa2
commit
7c84349990
@ -135,14 +135,12 @@ function Initialize( Plugin )
|
||||
end
|
||||
end
|
||||
|
||||
local WebPlugin = Plugin:CreateWebPlugin()
|
||||
WebPlugin:SetName( Plugin:GetName() )
|
||||
WebPlugin:AddTab( "Server Settings", HandleRequest_ServerSettings )
|
||||
WebPlugin:AddTab( "Chat", HandleRequest_Chat )
|
||||
WebPlugin:AddTab( "Playerlist", HandleRequest_PlayerList )
|
||||
WebPlugin:AddTab( "Whitelist", HandleRequest_WhiteList )
|
||||
WebPlugin:AddTab( "Permissions", HandleRequest_Permissions )
|
||||
WebPlugin:AddTab( "Manage Plugins", HandleRequest_ManagePlugins )
|
||||
Plugin:AddWebTab( "Server Settings", HandleRequest_ServerSettings )
|
||||
Plugin:AddWebTab( "Chat", HandleRequest_Chat )
|
||||
Plugin:AddWebTab( "Playerlist", HandleRequest_PlayerList )
|
||||
Plugin:AddWebTab( "Whitelist", HandleRequest_WhiteList )
|
||||
Plugin:AddWebTab( "Permissions", HandleRequest_Permissions )
|
||||
Plugin:AddWebTab( "Manage Plugins", HandleRequest_ManagePlugins )
|
||||
|
||||
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
||||
return true
|
||||
|
@ -1912,14 +1912,6 @@
|
||||
RelativePath="..\source\cStringMap.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\cWebPlugin_Lua.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\cWebPlugin_Lua.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\LuaFunctions.h"
|
||||
>
|
||||
|
@ -32,7 +32,6 @@ $cfile "cInventory.h"
|
||||
$cfile "cItem.h"
|
||||
$cfile "cWebAdmin.h"
|
||||
$cfile "cWebPlugin.h"
|
||||
$cfile "cWebPlugin_Lua.h"
|
||||
$cfile "cPickup.h"
|
||||
$cfile "cRoot.h"
|
||||
$cfile "cTCPLink.h"
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 08/19/12 21:46:45.
|
||||
** Generated automatically by tolua++-1.0.92 on 08/22/12 16:11:06.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
@ -41,7 +41,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
|
||||
#include "cItem.h"
|
||||
#include "cWebAdmin.h"
|
||||
#include "cWebPlugin.h"
|
||||
#include "cWebPlugin_Lua.h"
|
||||
#include "cPickup.h"
|
||||
#include "cRoot.h"
|
||||
#include "cTCPLink.h"
|
||||
@ -180,36 +179,35 @@ static void tolua_reg_types (lua_State* tolua_S)
|
||||
tolua_usertype(tolua_S,"cRoot");
|
||||
tolua_usertype(tolua_S,"cLuaItems");
|
||||
tolua_usertype(tolua_S,"cCraftingGrid");
|
||||
tolua_usertype(tolua_S,"cLuaChunk");
|
||||
tolua_usertype(tolua_S,"cPlugin::CommandStruct");
|
||||
tolua_usertype(tolua_S,"cPickup");
|
||||
tolua_usertype(tolua_S,"cItems");
|
||||
tolua_usertype(tolua_S,"cGroup");
|
||||
tolua_usertype(tolua_S,"cLuaChunk");
|
||||
tolua_usertype(tolua_S,"cClientHandle");
|
||||
tolua_usertype(tolua_S,"cTracer");
|
||||
tolua_usertype(tolua_S,"cGroup");
|
||||
tolua_usertype(tolua_S,"cFurnaceRecipe");
|
||||
tolua_usertype(tolua_S,"cMCLogger");
|
||||
tolua_usertype(tolua_S,"cTracer");
|
||||
tolua_usertype(tolua_S,"cChatColor");
|
||||
tolua_usertype(tolua_S,"cCuboid");
|
||||
tolua_usertype(tolua_S,"cMCLogger");
|
||||
tolua_usertype(tolua_S,"cPacket_PickupSpawn");
|
||||
tolua_usertype(tolua_S,"Lua__cWebPlugin");
|
||||
tolua_usertype(tolua_S,"Lua__cPawn");
|
||||
tolua_usertype(tolua_S,"Vector3i");
|
||||
tolua_usertype(tolua_S,"cCuboid");
|
||||
tolua_usertype(tolua_S,"cItem");
|
||||
tolua_usertype(tolua_S,"Vector3f");
|
||||
tolua_usertype(tolua_S,"cPlugin_Lua");
|
||||
tolua_usertype(tolua_S,"cWebPlugin_Lua");
|
||||
tolua_usertype(tolua_S,"Lua__cPlugin_NewLua");
|
||||
tolua_usertype(tolua_S,"cPawn");
|
||||
tolua_usertype(tolua_S,"Lua__cTCPLink");
|
||||
tolua_usertype(tolua_S,"cWebAdmin");
|
||||
tolua_usertype(tolua_S,"cTCPLink");
|
||||
tolua_usertype(tolua_S,"cCraftingRecipes");
|
||||
tolua_usertype(tolua_S,"Lua__cPlugin_NewLua");
|
||||
tolua_usertype(tolua_S,"Vector3i");
|
||||
tolua_usertype(tolua_S,"cPawn");
|
||||
tolua_usertype(tolua_S,"cWebAdmin");
|
||||
tolua_usertype(tolua_S,"Lua__cTCPLink");
|
||||
tolua_usertype(tolua_S,"cTCPLink");
|
||||
tolua_usertype(tolua_S,"cGroupManager");
|
||||
tolua_usertype(tolua_S,"Lua__cPickup");
|
||||
tolua_usertype(tolua_S,"Lua__cPlugin");
|
||||
tolua_usertype(tolua_S,"Lua__cEntity");
|
||||
tolua_usertype(tolua_S,"cPluginManager");
|
||||
tolua_usertype(tolua_S,"Lua__cEntity");
|
||||
tolua_usertype(tolua_S,"cLadder");
|
||||
tolua_usertype(tolua_S,"Lua__cPlayer");
|
||||
tolua_usertype(tolua_S,"cWebPlugin");
|
||||
@ -7189,7 +7187,7 @@ static int tolua_AllToLua_cPluginManager_GetPlugin00(lua_State* tolua_S)
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"const cPluginManager",0,&tolua_err) ||
|
||||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
@ -7197,16 +7195,17 @@ static int tolua_AllToLua_cPluginManager_GetPlugin00(lua_State* tolua_S)
|
||||
#endif
|
||||
{
|
||||
const cPluginManager* self = (const cPluginManager*) tolua_tousertype(tolua_S,1,0);
|
||||
const char* a_Plugin = ((const char*) tolua_tostring(tolua_S,2,0));
|
||||
const AString a_Plugin = ((const AString) tolua_tocppstring(tolua_S,2,0));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetPlugin'", NULL);
|
||||
#endif
|
||||
{
|
||||
cPlugin* tolua_ret = (cPlugin*) self->GetPlugin(a_Plugin);
|
||||
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cPlugin");
|
||||
tolua_pushcppstring(tolua_S,(const char*)a_Plugin);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return 2;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'GetPlugin'.",&tolua_err);
|
||||
@ -8376,8 +8375,8 @@ static int tolua_AllToLua_cPlugin_GetName00(lua_State* tolua_S)
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetName'", NULL);
|
||||
#endif
|
||||
{
|
||||
const char* tolua_ret = (const char*) self->GetName();
|
||||
tolua_pushstring(tolua_S,(const char*)tolua_ret);
|
||||
const AString tolua_ret = (const AString) self->GetName();
|
||||
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@ -8397,7 +8396,7 @@ static int tolua_AllToLua_cPlugin_SetName00(lua_State* tolua_S)
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cPlugin",0,&tolua_err) ||
|
||||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
@ -8405,15 +8404,16 @@ static int tolua_AllToLua_cPlugin_SetName00(lua_State* tolua_S)
|
||||
#endif
|
||||
{
|
||||
cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
|
||||
const char* a_Name = ((const char*) tolua_tostring(tolua_S,2,0));
|
||||
const AString a_Name = ((const AString) tolua_tocppstring(tolua_S,2,0));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetName'", NULL);
|
||||
#endif
|
||||
{
|
||||
self->SetName(a_Name);
|
||||
tolua_pushcppstring(tolua_S,(const char*)a_Name);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'SetName'.",&tolua_err);
|
||||
@ -8906,6 +8906,14 @@ public:
|
||||
return ( bool ) cPlugin:: OnWeatherChanged(a_World);
|
||||
};
|
||||
};
|
||||
void SetName( const AString& a_Name) {
|
||||
if (push_method("SetName", tolua_AllToLua_cPlugin_SetName00)) {
|
||||
tolua_pushcppstring(lua_state, (const char*)a_Name);
|
||||
ToluaBase::dbcall(lua_state, 2, 0);
|
||||
} else {
|
||||
return ( void ) cPlugin:: SetName(a_Name);
|
||||
};
|
||||
};
|
||||
|
||||
void cPlugin__OnDisable( void ) {
|
||||
return ( void )cPlugin::OnDisable();
|
||||
@ -8972,6 +8980,9 @@ public:
|
||||
};
|
||||
bool cPlugin__OnWeatherChanged( cWorld* a_World) {
|
||||
return ( bool )cPlugin::OnWeatherChanged(a_World);
|
||||
};
|
||||
void cPlugin__SetName( const AString& a_Name) {
|
||||
return ( void )cPlugin::SetName(a_Name);
|
||||
};
|
||||
Lua__cPlugin( void ): cPlugin(){};
|
||||
};
|
||||
@ -9856,6 +9867,40 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnWeatherChanged00(lua_State* to
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: cPlugin__SetName of class Lua__cPlugin */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_cPlugin__SetName00
|
||||
static int tolua_AllToLua_Lua__cPlugin_cPlugin__SetName00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"Lua__cPlugin",0,&tolua_err) ||
|
||||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
|
||||
const AString a_Name = ((const AString) tolua_tocppstring(tolua_S,2,0));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__SetName'", NULL);
|
||||
#endif
|
||||
{
|
||||
self->cPlugin__SetName(a_Name);
|
||||
tolua_pushcppstring(tolua_S,(const char*)a_Name);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'cPlugin__SetName'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: new of class Lua__cPlugin */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_new00
|
||||
static int tolua_AllToLua_Lua__cPlugin_new00(lua_State* tolua_S)
|
||||
@ -10070,8 +10115,8 @@ static int tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00(lua_State* tolua_S)
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateWebPlugin'", NULL);
|
||||
#endif
|
||||
{
|
||||
cWebPlugin_Lua* tolua_ret = (cWebPlugin_Lua*) self->CreateWebPlugin(a_LuaState);
|
||||
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cWebPlugin_Lua");
|
||||
OBSOLETE cPlugin_NewLua* tolua_ret = (OBSOLETE cPlugin_NewLua*) self->CreateWebPlugin(a_LuaState);
|
||||
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cPlugin_NewLua");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@ -10081,6 +10126,23 @@ static int tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00(lua_State* tolua_S)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* get function: __cWebPlugin__ of class cPlugin_NewLua */
|
||||
#ifndef TOLUA_DISABLE_tolua_get_cPlugin_NewLua___cWebPlugin__
|
||||
static int tolua_get_cPlugin_NewLua___cWebPlugin__(lua_State* tolua_S)
|
||||
{
|
||||
cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable '__cWebPlugin__'",NULL);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
tolua_pushusertype(tolua_S,(void*)static_cast<cWebPlugin*>(self), "cWebPlugin");
|
||||
#else
|
||||
tolua_pushusertype(tolua_S,(void*)((cWebPlugin*)self), "cWebPlugin");
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
class Lua__cPlugin_NewLua : public cPlugin_NewLua, public ToluaBase {
|
||||
@ -10366,6 +10428,14 @@ public:
|
||||
return ( bool ) cPlugin_NewLua:: OnWeatherChanged(a_World);
|
||||
};
|
||||
};
|
||||
void SetName( const AString& a_Name) {
|
||||
if (push_method("SetName", tolua_AllToLua_cPlugin_SetName00)) {
|
||||
tolua_pushcppstring(lua_state, (const char*)a_Name);
|
||||
ToluaBase::dbcall(lua_state, 2, 0);
|
||||
} else {
|
||||
return ( void ) cPlugin_NewLua:: SetName(a_Name);
|
||||
};
|
||||
};
|
||||
|
||||
void cPlugin_NewLua__OnDisable( void ) {
|
||||
return ( void )cPlugin_NewLua::OnDisable();
|
||||
@ -10436,6 +10506,9 @@ public:
|
||||
bool cPlugin_NewLua__OnWeatherChanged( cWorld* a_World) {
|
||||
return ( bool )cPlugin_NewLua::OnWeatherChanged(a_World);
|
||||
};
|
||||
void cPlugin_NewLua__SetName( const AString& a_Name) {
|
||||
return ( void )cPlugin_NewLua::SetName(a_Name);
|
||||
};
|
||||
};
|
||||
|
||||
/* method: tolua__set_instance of class Lua__cPlugin_NewLua */
|
||||
@ -13460,9 +13533,9 @@ static int tolua_AllToLua_cWebPlugin_GetName00(lua_State* tolua_S)
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: HandleRequest of class cWebPlugin */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWebPlugin_HandleRequest00
|
||||
static int tolua_AllToLua_cWebPlugin_HandleRequest00(lua_State* tolua_S)
|
||||
/* method: HandleWebRequest of class cWebPlugin */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWebPlugin_HandleWebRequest00
|
||||
static int tolua_AllToLua_cWebPlugin_HandleWebRequest00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
@ -13478,48 +13551,48 @@ static int tolua_AllToLua_cWebPlugin_HandleRequest00(lua_State* tolua_S)
|
||||
cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S,1,0);
|
||||
HTTPRequest* a_Request = ((HTTPRequest*) tolua_tousertype(tolua_S,2,0));
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HandleRequest'", NULL);
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HandleWebRequest'", NULL);
|
||||
#endif
|
||||
{
|
||||
std::string tolua_ret = (std::string) self->HandleRequest(a_Request);
|
||||
std::string tolua_ret = (std::string) self->HandleWebRequest(a_Request);
|
||||
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'HandleRequest'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'HandleWebRequest'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: Initialize of class cWebPlugin */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWebPlugin_Initialize00
|
||||
static int tolua_AllToLua_cWebPlugin_Initialize00(lua_State* tolua_S)
|
||||
/* method: SafeString of class cWebPlugin */
|
||||
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWebPlugin_SafeString00
|
||||
static int tolua_AllToLua_cWebPlugin_SafeString00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cWebPlugin",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
||||
!tolua_isusertable(tolua_S,1,"cWebPlugin",0,&tolua_err) ||
|
||||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S,1,0);
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Initialize'", NULL);
|
||||
#endif
|
||||
const AString a_String = ((const AString) tolua_tocppstring(tolua_S,2,0));
|
||||
{
|
||||
self->Initialize();
|
||||
AString tolua_ret = (AString) cWebPlugin::SafeString(a_String);
|
||||
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
|
||||
tolua_pushcppstring(tolua_S,(const char*)a_String);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 2;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'Initialize'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'SafeString'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@ -13527,8 +13600,8 @@ static int tolua_AllToLua_cWebPlugin_Initialize00(lua_State* tolua_S)
|
||||
|
||||
class Lua__cWebPlugin : public cWebPlugin, public ToluaBase {
|
||||
public:
|
||||
std::string HandleRequest( HTTPRequest* a_Request) {
|
||||
if (push_method("HandleRequest", tolua_AllToLua_cWebPlugin_HandleRequest00)) {
|
||||
std::string HandleWebRequest( HTTPRequest* a_Request) {
|
||||
if (push_method("HandleWebRequest", tolua_AllToLua_cWebPlugin_HandleWebRequest00)) {
|
||||
tolua_pushusertype(lua_state, (void*)a_Request, "HTTPRequest");
|
||||
ToluaBase::dbcall(lua_state, 2, 1);
|
||||
std::string tolua_ret = ( std::string )tolua_tocppstring(lua_state, -1, 0);
|
||||
@ -13536,29 +13609,16 @@ public:
|
||||
return tolua_ret;
|
||||
} else {
|
||||
if (lua_state)
|
||||
LOG("pure-virtual method cWebPlugin::HandleRequest not implemented.");
|
||||
LOG("pure-virtual method cWebPlugin::HandleWebRequest not implemented.");
|
||||
else {
|
||||
LOG("pure-virtual method cWebPlugin::HandleRequest called with no lua_state. Aborting");
|
||||
LOG("pure-virtual method cWebPlugin::HandleWebRequest called with no lua_state. Aborting");
|
||||
::abort();
|
||||
};
|
||||
return "";
|
||||
};
|
||||
};
|
||||
void Initialize( void ) {
|
||||
if (push_method("Initialize", tolua_AllToLua_cWebPlugin_Initialize00)) {
|
||||
ToluaBase::dbcall(lua_state, 1, 0);
|
||||
} else {
|
||||
if (lua_state)
|
||||
LOG("pure-virtual method cWebPlugin::Initialize not implemented.");
|
||||
else {
|
||||
LOG("pure-virtual method cWebPlugin::Initialize called with no lua_state. Aborting");
|
||||
::abort();
|
||||
};
|
||||
return ( void )0;
|
||||
};
|
||||
};
|
||||
|
||||
Lua__cWebPlugin( lua_State* L): cWebPlugin(L){};
|
||||
Lua__cWebPlugin( void ): cWebPlugin(){};
|
||||
};
|
||||
|
||||
/* method: tolua__set_instance of class Lua__cWebPlugin */
|
||||
@ -13608,9 +13668,8 @@ static int tolua_AllToLua_Lua__cWebPlugin_new00(lua_State* tolua_S)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
lua_State* L = tolua_S;
|
||||
{
|
||||
Lua__cWebPlugin* tolua_ret = (Lua__cWebPlugin*) Mtolua_new((Lua__cWebPlugin)(L));
|
||||
Lua__cWebPlugin* tolua_ret = (Lua__cWebPlugin*) Mtolua_new((Lua__cWebPlugin)());
|
||||
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cWebPlugin");
|
||||
}
|
||||
}
|
||||
@ -13637,9 +13696,8 @@ static int tolua_AllToLua_Lua__cWebPlugin_new00_local(lua_State* tolua_S)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
lua_State* L = tolua_S;
|
||||
{
|
||||
Lua__cWebPlugin* tolua_ret = (Lua__cWebPlugin*) Mtolua_new((Lua__cWebPlugin)(L));
|
||||
Lua__cWebPlugin* tolua_ret = (Lua__cWebPlugin*) Mtolua_new((Lua__cWebPlugin)());
|
||||
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Lua__cWebPlugin");
|
||||
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
|
||||
}
|
||||
@ -21411,6 +21469,13 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_cclass(tolua_S,"cEntity","cEntity","",NULL);
|
||||
#endif
|
||||
tolua_beginmodule(tolua_S,"cEntity");
|
||||
tolua_constant(tolua_S,"ENTITY_STATUS_HURT",cEntity::ENTITY_STATUS_HURT);
|
||||
tolua_constant(tolua_S,"ENTITY_STATUS_DEAD",cEntity::ENTITY_STATUS_DEAD);
|
||||
tolua_constant(tolua_S,"ENTITY_STATUS_WOLF_TAMING",cEntity::ENTITY_STATUS_WOLF_TAMING);
|
||||
tolua_constant(tolua_S,"ENTITY_STATUS_WOLF_TAMED",cEntity::ENTITY_STATUS_WOLF_TAMED);
|
||||
tolua_constant(tolua_S,"ENTITY_STATUS_WOLF_SHAKING",cEntity::ENTITY_STATUS_WOLF_SHAKING);
|
||||
tolua_constant(tolua_S,"ENTITY_STATUS_EATING_ACCEPTED",cEntity::ENTITY_STATUS_EATING_ACCEPTED);
|
||||
tolua_constant(tolua_S,"ENTITY_STATUS_SHEEP_EATING",cEntity::ENTITY_STATUS_SHEEP_EATING);
|
||||
tolua_function(tolua_S,"delete",tolua_AllToLua_cEntity_delete00);
|
||||
tolua_function(tolua_S,"Initialize",tolua_AllToLua_cEntity_Initialize00);
|
||||
tolua_constant(tolua_S,"eEntityType_Entity",cEntity::eEntityType_Entity);
|
||||
@ -21651,6 +21716,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_function(tolua_S,"cPlugin__OnUpdatedSign",tolua_AllToLua_Lua__cPlugin_cPlugin__OnUpdatedSign00);
|
||||
tolua_function(tolua_S,"cPlugin__OnUpdatingSign",tolua_AllToLua_Lua__cPlugin_cPlugin__OnUpdatingSign00);
|
||||
tolua_function(tolua_S,"cPlugin__OnWeatherChanged",tolua_AllToLua_Lua__cPlugin_cPlugin__OnWeatherChanged00);
|
||||
tolua_function(tolua_S,"cPlugin__SetName",tolua_AllToLua_Lua__cPlugin_cPlugin__SetName00);
|
||||
tolua_function(tolua_S,"new",tolua_AllToLua_Lua__cPlugin_new00);
|
||||
tolua_function(tolua_S,"new_local",tolua_AllToLua_Lua__cPlugin_new00_local);
|
||||
tolua_function(tolua_S,".call",tolua_AllToLua_Lua__cPlugin_new00_local);
|
||||
@ -21662,6 +21728,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_function(tolua_S,"Initialize",tolua_AllToLua_cPlugin_NewLua_Initialize00);
|
||||
tolua_function(tolua_S,"Tick",tolua_AllToLua_cPlugin_NewLua_Tick00);
|
||||
tolua_function(tolua_S,"CreateWebPlugin",tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00);
|
||||
tolua_variable(tolua_S,"__cWebPlugin__",tolua_get_cPlugin_NewLua___cWebPlugin__,NULL);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"Lua__cPlugin_NewLua","Lua__cPlugin_NewLua","cPlugin_NewLua",NULL);
|
||||
tolua_beginmodule(tolua_S,"Lua__cPlugin_NewLua");
|
||||
@ -21788,8 +21855,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_function(tolua_S,"delete",tolua_AllToLua_cWebPlugin_delete00);
|
||||
tolua_function(tolua_S,"SetName",tolua_AllToLua_cWebPlugin_SetName00);
|
||||
tolua_function(tolua_S,"GetName",tolua_AllToLua_cWebPlugin_GetName00);
|
||||
tolua_function(tolua_S,"HandleRequest",tolua_AllToLua_cWebPlugin_HandleRequest00);
|
||||
tolua_function(tolua_S,"Initialize",tolua_AllToLua_cWebPlugin_Initialize00);
|
||||
tolua_function(tolua_S,"HandleWebRequest",tolua_AllToLua_cWebPlugin_HandleWebRequest00);
|
||||
tolua_function(tolua_S,"SafeString",tolua_AllToLua_cWebPlugin_SafeString00);
|
||||
tolua_endmodule(tolua_S);
|
||||
#ifdef __cplusplus
|
||||
tolua_cclass(tolua_S,"Lua__cWebPlugin","Lua__cWebPlugin","cWebPlugin",tolua_collect_Lua__cWebPlugin);
|
||||
@ -21803,9 +21870,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_function(tolua_S,".call",tolua_AllToLua_Lua__cWebPlugin_new00_local);
|
||||
tolua_function(tolua_S,"delete",tolua_AllToLua_Lua__cWebPlugin_delete00);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"cWebPlugin_Lua","cWebPlugin_Lua","cWebPlugin",NULL);
|
||||
tolua_beginmodule(tolua_S,"cWebPlugin_Lua");
|
||||
tolua_endmodule(tolua_S);
|
||||
#ifdef __cplusplus
|
||||
tolua_cclass(tolua_S,"cPickup","cPickup","cEntity",tolua_collect_cPickup);
|
||||
#else
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 08/19/12 21:46:45.
|
||||
** Generated automatically by tolua++-1.0.92 on 08/22/12 16:11:06.
|
||||
*/
|
||||
|
||||
/* Exported function */
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include "cRoot.h"
|
||||
#include "cWorld.h"
|
||||
#include "cPlugin.h"
|
||||
#include "cPlugin_NewLua.h"
|
||||
#include "cPluginManager.h"
|
||||
#include "cWebPlugin_Lua.h"
|
||||
#include "cLuaCommandBinder.h"
|
||||
#include "cPlayer.h"
|
||||
#include "cWebAdmin.h"
|
||||
@ -549,9 +549,9 @@ static int tolua_cPlugin_BindCommand(lua_State* tolua_S)
|
||||
|
||||
|
||||
|
||||
static int tolua_cWebPlugin_Lua_AddTab(lua_State* tolua_S)
|
||||
static int tolua_cPlugin_NewLua_AddWebTab(lua_State* tolua_S)
|
||||
{
|
||||
cWebPlugin_Lua* self = (cWebPlugin_Lua*) tolua_tousertype(tolua_S,1,0);
|
||||
cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
tolua_Error tolua_err;
|
||||
tolua_err.array = 0;
|
||||
@ -573,20 +573,20 @@ static int tolua_cWebPlugin_Lua_AddTab(lua_State* tolua_S)
|
||||
{
|
||||
tolua_err.type = "function";
|
||||
}
|
||||
tolua_error(tolua_S,"#ferror in function 'AddTab'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'AddWebTab'.",&tolua_err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( Reference != LUA_REFNIL )
|
||||
{
|
||||
if( !self->AddTab( Title.c_str(), tolua_S, Reference ) )
|
||||
if( !self->AddWebTab( Title.c_str(), tolua_S, Reference ) )
|
||||
{
|
||||
luaL_unref( tolua_S, LUA_REGISTRYINDEX, Reference );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("ERROR: cWebPlugin_Lua:AddTab invalid function reference in 2nd argument (Title: \"%s\")", Title.c_str() );
|
||||
LOGERROR("ERROR: cPlugin_NewLua:AddWebTab invalid function reference in 2nd argument (Title: \"%s\")", Title.c_str() );
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -596,6 +596,16 @@ static int tolua_cWebPlugin_Lua_AddTab(lua_State* tolua_S)
|
||||
|
||||
|
||||
|
||||
static int tolua_cPlugin_NewLua_AddTab(lua_State* tolua_S)
|
||||
{
|
||||
LOGWARN("WARNING: Using deprecated function AddTab()! Use AddWebTab() instead.");
|
||||
return tolua_cPlugin_NewLua_AddWebTab( tolua_S );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_md5(lua_State* tolua_S)
|
||||
{
|
||||
std::string SourceString = tolua_tostring(tolua_S, 1, 0);
|
||||
@ -709,8 +719,9 @@ void ManualBindings::Bind( lua_State* tolua_S )
|
||||
tolua_function(tolua_S, "GetResolvedPermissions", tolua_cPlayer_GetResolvedPermissions);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_beginmodule(tolua_S, "cWebPlugin_Lua");
|
||||
tolua_function(tolua_S, "AddTab", tolua_cWebPlugin_Lua_AddTab);
|
||||
tolua_beginmodule(tolua_S, "cPlugin_NewLua");
|
||||
tolua_function(tolua_S, "AddWebTab", tolua_cPlugin_NewLua_AddWebTab);
|
||||
tolua_function(tolua_S, "AddTab", tolua_cPlugin_NewLua_AddTab);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_cclass(tolua_S,"HTTPRequest","HTTPRequest","",NULL);
|
||||
|
@ -70,8 +70,8 @@ public:
|
||||
virtual bool OnWeatherChanged (cWorld * a_World);
|
||||
|
||||
// Accessors
|
||||
const char* GetName() const { return m_Name.c_str(); }
|
||||
void SetName( const char* a_Name ) { m_Name = a_Name; }
|
||||
const AString & GetName() const { return m_Name; }
|
||||
virtual void SetName( const AString & a_Name ) { m_Name = a_Name; }
|
||||
|
||||
int GetVersion() const { return m_Version; }
|
||||
void SetVersion( int a_Version ) { m_Version = a_Version; }
|
||||
|
@ -623,11 +623,11 @@ bool cPluginManager::CallHookUpdatedSign(cWorld * a_World, int a_BlockX, int a_B
|
||||
|
||||
|
||||
|
||||
cPlugin* cPluginManager::GetPlugin( const char* a_Plugin ) const
|
||||
cPlugin* cPluginManager::GetPlugin( const AString & a_Plugin ) const
|
||||
{
|
||||
for( PluginList::const_iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr )
|
||||
{
|
||||
if (strcmp((*itr)->GetName(), a_Plugin) == 0 )
|
||||
if ((*itr)->GetName().compare(a_Plugin) == 0)
|
||||
{
|
||||
return *itr;
|
||||
}
|
||||
@ -657,8 +657,6 @@ void cPluginManager::UnloadPluginsNow()
|
||||
cPlugin_Lua* LuaPlugin = *m_LuaPlugins.begin();
|
||||
if( LuaPlugin )
|
||||
{
|
||||
cWebAdmin* WebAdmin = cRoot::Get()->GetWebAdmin();
|
||||
if( WebAdmin ) WebAdmin->RemovePlugin( LuaPlugin->GetLuaState() );
|
||||
delete LuaPlugin;
|
||||
}
|
||||
m_LuaPlugins.remove( LuaPlugin );
|
||||
|
@ -83,7 +83,7 @@ public: //tolua_export
|
||||
static cPluginManager * GetPluginManager(); //tolua_export
|
||||
|
||||
typedef std::list< cPlugin * > PluginList;
|
||||
cPlugin* GetPlugin( const char* a_Plugin ) const; //tolua_export
|
||||
cPlugin * GetPlugin( const AString & a_Plugin ) const; //tolua_export
|
||||
const PluginList & GetAllPlugins() const; // >> EXPORTED IN MANUALBINDINGS <<
|
||||
|
||||
void ReloadPlugins(); //tolua_export
|
||||
|
@ -4,7 +4,6 @@
|
||||
#define LUA_USE_POSIX
|
||||
#include "cPlugin_NewLua.h"
|
||||
#include "cMCLogger.h"
|
||||
#include "cWebPlugin_Lua.h"
|
||||
#include "LuaItems.h"
|
||||
|
||||
extern "C"
|
||||
@ -34,6 +33,7 @@ extern bool report_errors(lua_State* lua, int status);
|
||||
|
||||
cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName )
|
||||
: m_LuaState( 0 )
|
||||
, cWebPlugin()
|
||||
{
|
||||
m_Directory = a_PluginName;
|
||||
}
|
||||
@ -45,11 +45,6 @@ cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName )
|
||||
cPlugin_NewLua::~cPlugin_NewLua()
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
for( WebPluginList::iterator itr = m_WebPlugins.begin(); itr != m_WebPlugins.end(); ++itr )
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
m_WebPlugins.clear();
|
||||
|
||||
if( m_LuaState )
|
||||
{
|
||||
@ -638,22 +633,97 @@ bool cPlugin_NewLua::OnUpdatedSign(
|
||||
|
||||
|
||||
|
||||
cWebPlugin_Lua* cPlugin_NewLua::CreateWebPlugin(lua_State* a_LuaState)
|
||||
cPlugin_NewLua* cPlugin_NewLua::CreateWebPlugin(lua_State* a_LuaState)
|
||||
{
|
||||
LOGWARN("WARNING: Using deprecated function CreateWebPlugin()! A Lua plugin is a WebPlugin by itself now.");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AString cPlugin_NewLua::HandleWebRequest( HTTPRequest * a_Request )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
std::string RetVal = "";
|
||||
|
||||
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 = GetTabs().begin(); itr != GetTabs().end(); ++itr )
|
||||
{
|
||||
if( (*itr)->SafeTitle.compare( SafeTabName ) == 0 ) // This is the one! Rawr
|
||||
{
|
||||
Tab = *itr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( Tab )
|
||||
{
|
||||
//LOGINFO("1. Stack size: %i", lua_gettop(m_LuaState) );
|
||||
lua_rawgeti( m_LuaState, LUA_REGISTRYINDEX, Tab->UserData); // same as lua_getref()
|
||||
|
||||
//LOGINFO("2. Stack size: %i", lua_gettop(m_LuaState) );
|
||||
// Push HTTPRequest
|
||||
tolua_pushusertype( m_LuaState, a_Request, "HTTPRequest" );
|
||||
//LOGINFO("Calling bound function! :D");
|
||||
int s = lua_pcall( m_LuaState, 1, 1, 0);
|
||||
|
||||
if ( s != 0 )
|
||||
{
|
||||
std::string err = lua_tostring(m_LuaState, -1);
|
||||
LOGERROR("-- %s", err.c_str() );
|
||||
lua_pop(m_LuaState, 1);
|
||||
LOGINFO("error. Stack size: %i", lua_gettop(m_LuaState) );
|
||||
return err; // Show the error message in the web page, looks cool
|
||||
}
|
||||
|
||||
if( !lua_isstring( m_LuaState, -1 ) )
|
||||
{
|
||||
LOGWARN("WARNING: WebPlugin tab '%s' did not return a string!", Tab->Title.c_str() );
|
||||
lua_pop(m_LuaState, 1); // Pop return value
|
||||
return std::string("WARNING: WebPlugin tab '") + Tab->Title + std::string("' did not return a string!");
|
||||
}
|
||||
|
||||
RetVal += tolua_tostring(m_LuaState, -1, 0);
|
||||
lua_pop(m_LuaState, 1); // Pop return value
|
||||
//LOGINFO("ok. Stack size: %i", lua_gettop(m_LuaState) );
|
||||
}
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::AddWebTab( const AString & a_Title, lua_State * a_LuaState, int a_FunctionReference )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( a_LuaState != m_LuaState )
|
||||
{
|
||||
LOGERROR("Not allowed to create a WebPlugin from another plugin but your own!");
|
||||
return 0;
|
||||
LOGERROR("Only allowed to add a tab to a WebPlugin of your own Plugin!");
|
||||
return false;
|
||||
}
|
||||
cWebPlugin_Lua* WebPlugin = new cWebPlugin_Lua( this );
|
||||
sWebPluginTab* Tab = new sWebPluginTab();
|
||||
Tab->Title = a_Title;
|
||||
Tab->SafeTitle = SafeString( a_Title );
|
||||
|
||||
m_WebPlugins.push_back( WebPlugin );
|
||||
Tab->UserData = a_FunctionReference;
|
||||
|
||||
return WebPlugin;
|
||||
GetTabs().push_back( Tab );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Helper functions
|
||||
bool cPlugin_NewLua::PushFunction( const char* a_FunctionName, bool a_bLogError /* = true */ )
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "cPlugin.h"
|
||||
#include "cWebPlugin.h"
|
||||
|
||||
|
||||
|
||||
@ -14,7 +15,7 @@ class cWebPlugin_Lua;
|
||||
|
||||
|
||||
|
||||
class cPlugin_NewLua : public cPlugin //tolua_export
|
||||
class cPlugin_NewLua : public cPlugin, public cWebPlugin //tolua_export
|
||||
{ //tolua_export
|
||||
public: //tolua_export
|
||||
cPlugin_NewLua( const char* a_PluginName );
|
||||
@ -46,18 +47,22 @@ public: //tolua_export
|
||||
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) override;
|
||||
virtual bool OnWeatherChanged (cWorld * a_World) override;
|
||||
|
||||
virtual void SetName( const AString & a_Name ) override { cPlugin::SetName(a_Name); cWebPlugin::SetName(a_Name); }
|
||||
|
||||
// cWebPlugin and WebAdmin stuff
|
||||
virtual AString HandleWebRequest( HTTPRequest * a_Request ) override;
|
||||
bool AddWebTab( const AString & a_Title, lua_State * a_LuaState, int a_FunctionReference ); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
OBSOLETE bool AddTab( const AString & a_Title, lua_State * a_LuaState, int a_FunctionReference ); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
|
||||
lua_State* GetLuaState() { return m_LuaState; }
|
||||
|
||||
cWebPlugin_Lua* CreateWebPlugin(lua_State* a_LuaState); //tolua_export
|
||||
OBSOLETE cPlugin_NewLua * CreateWebPlugin(lua_State* a_LuaState); //tolua_export
|
||||
|
||||
cCriticalSection & GetCriticalSection() { return m_CriticalSection; }
|
||||
private:
|
||||
bool PushFunction( const char* a_FunctionName, bool a_bLogError = true );
|
||||
bool CallFunction( int a_NumArgs, int a_NumResults, const char* a_FunctionName ); // a_FunctionName is only used for error messages, nothing else
|
||||
|
||||
typedef std::list< cWebPlugin_Lua* > WebPluginList;
|
||||
WebPluginList m_WebPlugins;
|
||||
|
||||
cCriticalSection m_CriticalSection;
|
||||
|
||||
std::string m_Directory;
|
||||
|
@ -80,13 +80,13 @@ cWebAdmin::~cWebAdmin()
|
||||
delete m_Event;
|
||||
}
|
||||
|
||||
void cWebAdmin::AddPlugin( cWebPlugin* a_Plugin )
|
||||
void cWebAdmin::AddPlugin( cWebPlugin * a_Plugin )
|
||||
{
|
||||
m_Plugins.remove( a_Plugin );
|
||||
m_Plugins.push_back( a_Plugin );
|
||||
}
|
||||
|
||||
void cWebAdmin::RemovePlugin( cWebPlugin* a_Plugin )
|
||||
void cWebAdmin::RemovePlugin( cWebPlugin * a_Plugin )
|
||||
{
|
||||
m_Plugins.remove( a_Plugin );
|
||||
}
|
||||
@ -161,18 +161,10 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
|
||||
for (PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr)
|
||||
{
|
||||
cWebPlugin* WebPlugin = *itr;
|
||||
cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
|
||||
if( LuaPlugin )
|
||||
std::list< std::pair<std::string, std::string> > NameList = WebPlugin->GetTabNames();
|
||||
for( std::list< std::pair<std::string, std::string> >::iterator Names = NameList.begin(); Names != NameList.end(); ++Names )
|
||||
{
|
||||
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() + "/" + (*Names).second + "'>" + (*Names).first + "</a></li>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Menu += "<li><a href='" + BaseURL + WebPlugin->GetName() + "'>" + WebPlugin->GetName() + "</a></li>";
|
||||
Menu += "<li><a href='" + BaseURL + WebPlugin->GetName().c_str() + "/" + (*Names).second + "'>" + (*Names).first + "</a></li>";
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,7 +193,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
|
||||
{
|
||||
if( (*itr)->GetName() == Split[1] )
|
||||
{
|
||||
Content = (*itr)->HandleRequest( &Request );
|
||||
Content = (*itr)->HandleWebRequest( &Request );
|
||||
cWebPlugin* WebPlugin = *itr;
|
||||
FoundPlugin = WebPlugin->GetName();
|
||||
cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
|
||||
@ -229,7 +221,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
|
||||
for( cPluginManager::PluginList::const_iterator itr = List.begin(); itr != List.end(); ++itr )
|
||||
{
|
||||
AString VersionNum;
|
||||
AppendPrintf(Content, "<li>%s V.%i</li>", (*itr)->GetName(), (*itr)->GetVersion());
|
||||
AppendPrintf(Content, "<li>%s V.%i</li>", (*itr)->GetName().c_str(), (*itr)->GetVersion());
|
||||
}
|
||||
}
|
||||
Content += "</ul>";
|
||||
@ -371,22 +363,4 @@ std::string cWebAdmin::GetTemplate()
|
||||
f.ReadRestOfFile(retVal);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cWebAdmin::RemovePlugin( lua_State* L )
|
||||
{
|
||||
for( PluginList::iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); )
|
||||
{
|
||||
if( (*itr)->GetLuaState() == L )
|
||||
{
|
||||
PluginList::iterator prev = itr++;
|
||||
delete *prev; // deleting a dereferenced iterator also takes it out of the list, so no need for erase()
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
@ -43,8 +43,6 @@ public:
|
||||
PluginList GetPlugins() { return m_Plugins; }
|
||||
|
||||
static void Request_Handler(webserver::http_request* r);
|
||||
|
||||
void RemovePlugin( lua_State* L );
|
||||
private:
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -10,17 +10,100 @@
|
||||
|
||||
|
||||
|
||||
cWebPlugin::cWebPlugin( lua_State* L )
|
||||
cWebPlugin::cWebPlugin()
|
||||
{
|
||||
LOG("cWebPlugin::cWebPlugin()");
|
||||
m_LuaState = L;
|
||||
cWebAdmin* WebAdmin = cRoot::Get()->GetWebAdmin();
|
||||
if( WebAdmin ) WebAdmin->AddPlugin( this );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cWebPlugin::~cWebPlugin()
|
||||
{
|
||||
LOG("~cWebPlugin::cWebPlugin()");
|
||||
cWebAdmin* WebAdmin = cRoot::Get()->GetWebAdmin();
|
||||
if( WebAdmin ) WebAdmin->RemovePlugin( this );
|
||||
|
||||
for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
m_Tabs.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::list< std::pair<std::string, std::string> > cWebPlugin::GetTabNames()
|
||||
{
|
||||
std::list< std::pair< std::string, std::string > > NameList;
|
||||
for( TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr )
|
||||
{
|
||||
std::pair< std::string, std::string > StringPair;
|
||||
StringPair.first = (*itr)->Title;
|
||||
StringPair.second = (*itr)->SafeTitle;
|
||||
NameList.push_back( StringPair );
|
||||
}
|
||||
return NameList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::pair< std::string, std::string > cWebPlugin::GetTabNameForRequest( HTTPRequest* a_Request )
|
||||
{
|
||||
std::pair< std::string, std::string > Names;
|
||||
AStringVector Split = StringSplit(a_Request->Path, "/");
|
||||
|
||||
if( Split.size() > 1 )
|
||||
{
|
||||
sWebPluginTab* Tab = 0;
|
||||
if( Split.size() > 2 ) // If we got the tab name, show that page
|
||||
{
|
||||
for( TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr )
|
||||
{
|
||||
if( (*itr)->SafeTitle.compare( Split[2] ) == 0 ) // This is the one! Rawr
|
||||
{
|
||||
Tab = *itr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Otherwise show the first tab
|
||||
{
|
||||
if( GetTabs().size() > 0 )
|
||||
Tab = *GetTabs().begin();
|
||||
}
|
||||
|
||||
if( Tab )
|
||||
{
|
||||
Names.first = Tab->Title;
|
||||
Names.second = Tab->SafeTitle;
|
||||
}
|
||||
}
|
||||
|
||||
return Names;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
AString cWebPlugin::SafeString( const AString & 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;
|
||||
}
|
@ -7,18 +7,32 @@ struct HTTPRequest;
|
||||
class cWebPlugin
|
||||
{
|
||||
public:
|
||||
cWebPlugin( lua_State* L );
|
||||
cWebPlugin();
|
||||
virtual ~cWebPlugin();
|
||||
|
||||
void SetName( std::string a_Name ) { m_Name = a_Name; }
|
||||
std::string GetName() { return m_Name; }
|
||||
|
||||
virtual std::string HandleRequest( HTTPRequest* a_Request ) = 0;
|
||||
virtual void Initialize() = 0;
|
||||
virtual std::string HandleWebRequest( HTTPRequest* a_Request ) = 0;
|
||||
|
||||
static AString SafeString( const AString & a_String );
|
||||
//tolua_end
|
||||
|
||||
lua_State* GetLuaState() { return m_LuaState; }
|
||||
struct sWebPluginTab
|
||||
{
|
||||
std::string Title;
|
||||
std::string SafeTitle;
|
||||
|
||||
int UserData;
|
||||
};
|
||||
|
||||
typedef std::list< sWebPluginTab* > TabList;
|
||||
TabList & GetTabs() { return m_Tabs; }
|
||||
|
||||
std::list< std::pair<std::string, std::string> > GetTabNames();
|
||||
std::pair< std::string, std::string > GetTabNameForRequest( HTTPRequest* a_Request );
|
||||
|
||||
private:
|
||||
lua_State* m_LuaState;
|
||||
TabList m_Tabs;
|
||||
std::string m_Name;
|
||||
}; //tolua_export
|
@ -1,186 +0,0 @@
|
||||
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "cWebPlugin_Lua.h"
|
||||
#include "cPlugin_NewLua.h"
|
||||
|
||||
#include "tolua++.h"
|
||||
#include "cWebAdmin.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern bool report_errors(lua_State* lua, int status);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct cWebPlugin_Lua::sWebPluginTab
|
||||
{
|
||||
std::string Title;
|
||||
std::string SafeTitle;
|
||||
|
||||
int Reference;
|
||||
};
|
||||
|
||||
cWebPlugin_Lua::cWebPlugin_Lua( cPlugin_NewLua* a_Plugin )
|
||||
: cWebPlugin( a_Plugin->GetLuaState() )
|
||||
, m_Plugin( a_Plugin )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cWebPlugin_Lua::~cWebPlugin_Lua()
|
||||
{
|
||||
for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
m_Tabs.clear();
|
||||
}
|
||||
|
||||
bool cWebPlugin_Lua::AddTab( const char* a_Title, lua_State * a_LuaState, int a_FunctionReference )
|
||||
{
|
||||
if( a_LuaState != m_Plugin->GetLuaState() )
|
||||
{
|
||||
LOGERROR("Only allowed to add a tab to a WebPlugin of your own Plugin!");
|
||||
return false;
|
||||
}
|
||||
sWebPluginTab* Tab = new sWebPluginTab();
|
||||
Tab->Title = a_Title;
|
||||
Tab->SafeTitle = SafeString( a_Title );
|
||||
|
||||
Tab->Reference = a_FunctionReference;
|
||||
|
||||
m_Tabs.push_back( Tab );
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string cWebPlugin_Lua::HandleRequest( HTTPRequest* a_Request )
|
||||
{
|
||||
cCSLock( m_Plugin->GetCriticalSection() );
|
||||
lua_State* LuaState = m_Plugin->GetLuaState();
|
||||
std::string RetVal = "";
|
||||
|
||||
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)->SafeTitle.compare( SafeTabName ) == 0 ) // This is the one! Rawr
|
||||
{
|
||||
Tab = *itr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( Tab )
|
||||
{
|
||||
//LOGINFO("1. Stack size: %i", lua_gettop(LuaState) );
|
||||
lua_rawgeti( LuaState, LUA_REGISTRYINDEX, Tab->Reference); // same as lua_getref()
|
||||
|
||||
//LOGINFO("2. Stack size: %i", lua_gettop(LuaState) );
|
||||
// Push HTTPRequest
|
||||
tolua_pushusertype( LuaState, a_Request, "HTTPRequest" );
|
||||
//LOGINFO("Calling bound function! :D");
|
||||
int s = lua_pcall( LuaState, 1, 1, 0);
|
||||
|
||||
if ( s != 0 )
|
||||
{
|
||||
std::string err = lua_tostring(LuaState, -1);
|
||||
LOGERROR("-- %s", err.c_str() );
|
||||
lua_pop(LuaState, 1);
|
||||
LOGINFO("error. Stack size: %i", lua_gettop(LuaState) );
|
||||
return err; // Show the error message in the web page, looks cool
|
||||
}
|
||||
|
||||
if( !lua_isstring( LuaState, -1 ) )
|
||||
{
|
||||
LOGWARN("WARNING: WebPlugin tab '%s' did not return a string!", Tab->Title.c_str() );
|
||||
lua_pop(LuaState, 1); // Pop return value
|
||||
return std::string("WARNING: WebPlugin tab '") + Tab->Title + std::string("' did not return a string!");
|
||||
}
|
||||
|
||||
RetVal += tolua_tostring(LuaState, -1, 0);
|
||||
lua_pop(LuaState, 1); // Pop return value
|
||||
//LOGINFO("ok. Stack size: %i", lua_gettop(LuaState) );
|
||||
}
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
void cWebPlugin_Lua::Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair< std::string, std::string > cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request )
|
||||
{
|
||||
std::pair< std::string, std::string > Names;
|
||||
AStringVector Split = StringSplit(a_Request->Path, "/");
|
||||
|
||||
if( Split.size() > 1 )
|
||||
{
|
||||
sWebPluginTab* Tab = 0;
|
||||
if( Split.size() > 2 ) // If we got the tab name, show that page
|
||||
{
|
||||
for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
|
||||
{
|
||||
if( (*itr)->SafeTitle.compare( Split[2] ) == 0 ) // This is the one! Rawr
|
||||
{
|
||||
Tab = *itr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Otherwise show the first tab
|
||||
{
|
||||
if( m_Tabs.size() > 0 )
|
||||
Tab = *m_Tabs.begin();
|
||||
}
|
||||
|
||||
if( Tab )
|
||||
{
|
||||
Names.first = Tab->Title;
|
||||
Names.second = Tab->SafeTitle;
|
||||
}
|
||||
}
|
||||
|
||||
return Names;
|
||||
}
|
||||
|
||||
std::list< std::pair<std::string, std::string> > cWebPlugin_Lua::GetTabNames()
|
||||
{
|
||||
std::list< std::pair< std::string, std::string > > NameList;
|
||||
for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
|
||||
{
|
||||
std::pair< std::string, std::string > StringPair;
|
||||
StringPair.first = (*itr)->Title;
|
||||
StringPair.second = (*itr)->SafeTitle;
|
||||
NameList.push_back( StringPair );
|
||||
}
|
||||
return NameList;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "cWebPlugin.h"
|
||||
|
||||
class cPlugin_NewLua;
|
||||
typedef struct lua_State lua_State;
|
||||
|
||||
// a WebPlugin class more specialized for Lua
|
||||
class cWebPlugin_Lua : public cWebPlugin //tolua_export
|
||||
{ //tolua_export
|
||||
public: //tolua_export
|
||||
cWebPlugin_Lua( cPlugin_NewLua* a_Plugin );
|
||||
virtual ~cWebPlugin_Lua();
|
||||
|
||||
bool AddTab( const char* a_Title, lua_State * a_LuaState, int a_FunctionReference ); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
|
||||
virtual std::string HandleRequest( HTTPRequest* a_Request );
|
||||
virtual void Initialize();
|
||||
|
||||
std::pair< std::string, std::string > GetTabNameForRequest( HTTPRequest* a_Request );
|
||||
|
||||
std::list< std::pair<std::string, std::string> > GetTabNames();
|
||||
private:
|
||||
cPlugin_NewLua* m_Plugin;
|
||||
|
||||
struct sWebPluginTab;
|
||||
typedef std::list< sWebPluginTab* > TabList;
|
||||
TabList m_Tabs;
|
||||
}; //tolua_export
|
Loading…
Reference in New Issue
Block a user