diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/AllToLua.pkg | 1 | ||||
-rw-r--r-- | source/Bindings.cpp | 549 | ||||
-rw-r--r-- | source/Bindings.h | 2 | ||||
-rw-r--r-- | source/ManualBindings.cpp | 47 | ||||
-rw-r--r-- | source/cPlugin_NewLua.cpp | 34 | ||||
-rw-r--r-- | source/cPlugin_NewLua.h | 8 | ||||
-rw-r--r-- | source/cWebAdmin.cpp | 50 | ||||
-rw-r--r-- | source/cWebPlugin_Lua.cpp | 149 | ||||
-rw-r--r-- | source/cWebPlugin_Lua.h | 31 |
9 files changed, 773 insertions, 98 deletions
diff --git a/source/AllToLua.pkg b/source/AllToLua.pkg index 0a10104d0..32293c370 100644 --- a/source/AllToLua.pkg +++ b/source/AllToLua.pkg @@ -26,6 +26,7 @@ $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"
diff --git a/source/Bindings.cpp b/source/Bindings.cpp index b8396c33b..2a97c8af6 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/26/12 18:52:03.
+** Generated automatically by tolua++-1.0.92 on 01/27/12 00:53:11.
*/
#ifndef __cplusplus
@@ -38,6 +38,7 @@ 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"
@@ -167,24 +168,25 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cRoot");
tolua_usertype(tolua_S,"Lua__cPickup");
tolua_usertype(tolua_S,"Lua__cPacket_BlockDig");
+ tolua_usertype(tolua_S,"cWorld");
tolua_usertype(tolua_S,"cPlugin::CommandStruct");
tolua_usertype(tolua_S,"cPickup");
- tolua_usertype(tolua_S,"cWorld");
+ tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cPacket_Login");
tolua_usertype(tolua_S,"cClientHandle");
- tolua_usertype(tolua_S,"Vector3i");
- tolua_usertype(tolua_S,"cFurnaceRecipe");
tolua_usertype(tolua_S,"cGroup");
- tolua_usertype(tolua_S,"cChatColor");
+ tolua_usertype(tolua_S,"cFurnaceRecipe");
tolua_usertype(tolua_S,"cTracer");
+ tolua_usertype(tolua_S,"cChatColor");
+ 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,"cMCLogger");
+ 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,"cCuboid");
+ tolua_usertype(tolua_S,"cWebPlugin_Lua");
tolua_usertype(tolua_S,"Lua__cPlayer");
tolua_usertype(tolua_S,"cPacket");
tolua_usertype(tolua_S,"cPacket_BlockDig");
@@ -197,8 +199,8 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cGroupManager");
tolua_usertype(tolua_S,"cPacket_BlockPlace");
tolua_usertype(tolua_S,"cLadder");
- tolua_usertype(tolua_S,"cPluginManager");
tolua_usertype(tolua_S,"Lua__cPlugin_NewLua");
+ tolua_usertype(tolua_S,"cPluginManager");
tolua_usertype(tolua_S,"cIniFile");
tolua_usertype(tolua_S,"Lua__cEntity");
tolua_usertype(tolua_S,"HTTPRequest");
@@ -8043,6 +8045,212 @@ static int tolua_AllToLua_cPlugin_NewLua_Initialize00(lua_State* tolua_S) }
#endif //#ifndef TOLUA_DISABLE
+/* method: Tick of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_Tick00
+static int tolua_AllToLua_cPlugin_NewLua_Tick00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ float a_Dt = ((float) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Tick'", NULL);
+#endif
+ {
+ self->Tick(a_Dt);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Tick'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnPlayerJoin of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_OnPlayerJoin00
+static int tolua_AllToLua_cPlugin_NewLua_OnPlayerJoin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnPlayerJoin'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnPlayerJoin(a_Player);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnPlayerJoin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnLogin of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_OnLogin00
+static int tolua_AllToLua_cPlugin_NewLua_OnLogin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPacket_Login",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPacket_Login* a_PacketData = ((cPacket_Login*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnLogin'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnLogin(a_PacketData);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnLogin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnBlockPlace of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_OnBlockPlace00
+static int tolua_AllToLua_cPlugin_NewLua_OnBlockPlace00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPacket_BlockPlace",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPacket_BlockPlace* a_PacketData = ((cPacket_BlockPlace*) tolua_tousertype(tolua_S,2,0));
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnBlockPlace'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnBlockPlace(a_PacketData,a_Player);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnBlockPlace'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnKilled of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_OnKilled00
+static int tolua_AllToLua_cPlugin_NewLua_OnKilled00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPawn",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cEntity",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPawn* a_Killed = ((cPawn*) tolua_tousertype(tolua_S,2,0));
+ cEntity* a_Killer = ((cEntity*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnKilled'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnKilled(a_Killed,a_Killer);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnKilled'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: CreateWebPlugin of class cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00
+static int tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin_NewLua* self = (cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ lua_State* a_LuaState = tolua_S;
+#ifndef TOLUA_RELEASE
+ 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");
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'CreateWebPlugin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
class Lua__cPlugin_NewLua : public cPlugin_NewLua, public ToluaBase {
public:
bool Initialize( void ) {
@@ -8055,47 +8263,38 @@ public: return ( bool ) cPlugin_NewLua:: Initialize();
};
};
- void OnDisable( void ) {
- if (push_method("OnDisable", tolua_AllToLua_cPlugin_OnDisable00)) {
- ToluaBase::dbcall(lua_state, 1, 0);
- } else {
- return ( void ) cPlugin_NewLua:: OnDisable();
- };
- };
void Tick( float a_Dt) {
- if (push_method("Tick", tolua_AllToLua_cPlugin_Tick00)) {
+ if (push_method("Tick", tolua_AllToLua_cPlugin_NewLua_Tick00)) {
tolua_pushnumber(lua_state, (lua_Number)a_Dt);
ToluaBase::dbcall(lua_state, 2, 0);
} else {
return ( void ) cPlugin_NewLua:: Tick(a_Dt);
};
};
- bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
- if (push_method("OnCollectItem", tolua_AllToLua_cPlugin_OnCollectItem00)) {
- tolua_pushusertype(lua_state, (void*)a_Pickup, "cPickup");
+ bool OnPlayerJoin( cPlayer* a_Player) {
+ if (push_method("OnPlayerJoin", tolua_AllToLua_cPlugin_NewLua_OnPlayerJoin00)) {
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
- ToluaBase::dbcall(lua_state, 3, 1);
+ ToluaBase::dbcall(lua_state, 2, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
- return ( bool ) cPlugin_NewLua:: OnCollectItem(a_Pickup,a_Player);
+ return ( bool ) cPlugin_NewLua:: OnPlayerJoin(a_Player);
};
};
- bool OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
- if (push_method("OnDisconnect", tolua_AllToLua_cPlugin_OnDisconnect00)) {
- tolua_pushcppstring(lua_state, (const char*)a_Reason);
- tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
- ToluaBase::dbcall(lua_state, 3, 1);
+ bool OnLogin( cPacket_Login* a_PacketData) {
+ if (push_method("OnLogin", tolua_AllToLua_cPlugin_NewLua_OnLogin00)) {
+ tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_Login");
+ ToluaBase::dbcall(lua_state, 2, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
- return ( bool ) cPlugin_NewLua:: OnDisconnect(a_Reason,a_Player);
+ return ( bool ) cPlugin_NewLua:: OnLogin(a_PacketData);
};
};
bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) {
- if (push_method("OnBlockPlace", tolua_AllToLua_cPlugin_OnBlockPlace00)) {
+ if (push_method("OnBlockPlace", tolua_AllToLua_cPlugin_NewLua_OnBlockPlace00)) {
tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_BlockPlace");
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
ToluaBase::dbcall(lua_state, 3, 1);
@@ -8106,6 +8305,49 @@ public: return ( bool ) cPlugin_NewLua:: OnBlockPlace(a_PacketData,a_Player);
};
};
+ bool OnKilled( cPawn* a_Killed, cEntity* a_Killer) {
+ if (push_method("OnKilled", tolua_AllToLua_cPlugin_NewLua_OnKilled00)) {
+ tolua_pushusertype(lua_state, (void*)a_Killed, "cPawn");
+ tolua_pushusertype(lua_state, (void*)a_Killer, "cEntity");
+ ToluaBase::dbcall(lua_state, 3, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnKilled(a_Killed,a_Killer);
+ };
+ };
+ void OnDisable( void ) {
+ if (push_method("OnDisable", tolua_AllToLua_cPlugin_OnDisable00)) {
+ ToluaBase::dbcall(lua_state, 1, 0);
+ } else {
+ return ( void ) cPlugin_NewLua:: OnDisable();
+ };
+ };
+ bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
+ if (push_method("OnCollectItem", tolua_AllToLua_cPlugin_OnCollectItem00)) {
+ tolua_pushusertype(lua_state, (void*)a_Pickup, "cPickup");
+ tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
+ ToluaBase::dbcall(lua_state, 3, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnCollectItem(a_Pickup,a_Player);
+ };
+ };
+ bool OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
+ if (push_method("OnDisconnect", tolua_AllToLua_cPlugin_OnDisconnect00)) {
+ tolua_pushcppstring(lua_state, (const char*)a_Reason);
+ tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
+ ToluaBase::dbcall(lua_state, 3, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnDisconnect(a_Reason,a_Player);
+ };
+ };
bool OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem) {
if (push_method("OnBlockDig", tolua_AllToLua_cPlugin_OnBlockDig00)) {
tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_BlockDig");
@@ -8131,17 +8373,6 @@ public: return ( bool ) cPlugin_NewLua:: OnChat(a_Chat,a_Player);
};
};
- bool OnLogin( cPacket_Login* a_PacketData) {
- if (push_method("OnLogin", tolua_AllToLua_cPlugin_OnLogin00)) {
- tolua_pushusertype(lua_state, (void*)a_PacketData, "cPacket_Login");
- ToluaBase::dbcall(lua_state, 2, 1);
- bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
- lua_pop(lua_state, 1);
- return tolua_ret;
- } else {
- return ( bool ) cPlugin_NewLua:: OnLogin(a_PacketData);
- };
- };
void OnPlayerSpawn( cPlayer* a_Player) {
if (push_method("OnPlayerSpawn", tolua_AllToLua_cPlugin_OnPlayerSpawn00)) {
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
@@ -8150,17 +8381,6 @@ public: return ( void ) cPlugin_NewLua:: OnPlayerSpawn(a_Player);
};
};
- bool OnPlayerJoin( cPlayer* a_Player) {
- if (push_method("OnPlayerJoin", tolua_AllToLua_cPlugin_OnPlayerJoin00)) {
- tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
- ToluaBase::dbcall(lua_state, 2, 1);
- bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
- lua_pop(lua_state, 1);
- return tolua_ret;
- } else {
- return ( bool ) cPlugin_NewLua:: OnPlayerJoin(a_Player);
- };
- };
void OnPlayerMove( cPlayer* a_Player) {
if (push_method("OnPlayerMove", tolua_AllToLua_cPlugin_OnPlayerMove00)) {
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
@@ -8178,61 +8398,49 @@ public: return ( void ) cPlugin_NewLua:: OnTakeDamage(a_Pawn,a_TakeDamageInfo);
};
};
- bool OnKilled( cPawn* a_Killed, cEntity* a_Killer) {
- if (push_method("OnKilled", tolua_AllToLua_cPlugin_OnKilled00)) {
- tolua_pushusertype(lua_state, (void*)a_Killed, "cPawn");
- tolua_pushusertype(lua_state, (void*)a_Killer, "cEntity");
- ToluaBase::dbcall(lua_state, 3, 1);
- bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
- lua_pop(lua_state, 1);
- return tolua_ret;
- } else {
- return ( bool ) cPlugin_NewLua:: OnKilled(a_Killed,a_Killer);
- };
- };
bool cPlugin_NewLua__Initialize( void ) {
return ( bool )cPlugin_NewLua::Initialize();
};
- void cPlugin_NewLua__OnDisable( void ) {
- return ( void )cPlugin_NewLua::OnDisable();
- };
void cPlugin_NewLua__Tick( float a_Dt) {
return ( void )cPlugin_NewLua::Tick(a_Dt);
};
+ bool cPlugin_NewLua__OnPlayerJoin( cPlayer* a_Player) {
+ return ( bool )cPlugin_NewLua::OnPlayerJoin(a_Player);
+ };
+ bool cPlugin_NewLua__OnLogin( cPacket_Login* a_PacketData) {
+ return ( bool )cPlugin_NewLua::OnLogin(a_PacketData);
+ };
+ bool cPlugin_NewLua__OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) {
+ return ( bool )cPlugin_NewLua::OnBlockPlace(a_PacketData,a_Player);
+ };
+ bool cPlugin_NewLua__OnKilled( cPawn* a_Killed, cEntity* a_Killer) {
+ return ( bool )cPlugin_NewLua::OnKilled(a_Killed,a_Killer);
+ };
+ void cPlugin_NewLua__OnDisable( void ) {
+ return ( void )cPlugin_NewLua::OnDisable();
+ };
bool cPlugin_NewLua__OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnCollectItem(a_Pickup,a_Player);
};
bool cPlugin_NewLua__OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnDisconnect(a_Reason,a_Player);
};
- bool cPlugin_NewLua__OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) {
- return ( bool )cPlugin_NewLua::OnBlockPlace(a_PacketData,a_Player);
- };
bool cPlugin_NewLua__OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem) {
return ( bool )cPlugin_NewLua::OnBlockDig(a_PacketData,a_Player,a_PickupItem);
};
bool cPlugin_NewLua__OnChat( const char* a_Chat, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnChat(a_Chat,a_Player);
};
- bool cPlugin_NewLua__OnLogin( cPacket_Login* a_PacketData) {
- return ( bool )cPlugin_NewLua::OnLogin(a_PacketData);
- };
void cPlugin_NewLua__OnPlayerSpawn( cPlayer* a_Player) {
return ( void )cPlugin_NewLua::OnPlayerSpawn(a_Player);
};
- bool cPlugin_NewLua__OnPlayerJoin( cPlayer* a_Player) {
- return ( bool )cPlugin_NewLua::OnPlayerJoin(a_Player);
- };
void cPlugin_NewLua__OnPlayerMove( cPlayer* a_Player) {
return ( void )cPlugin_NewLua::OnPlayerMove(a_Player);
};
void cPlugin_NewLua__OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo) {
return ( void )cPlugin_NewLua::OnTakeDamage(a_Pawn,a_TakeDamageInfo);
};
- bool cPlugin_NewLua__OnKilled( cPawn* a_Killed, cEntity* a_Killer) {
- return ( bool )cPlugin_NewLua::OnKilled(a_Killed,a_Killer);
- };
};
/* method: tolua__set_instance of class Lua__cPlugin_NewLua */
@@ -8300,6 +8508,179 @@ static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Initialize00(lua_S }
#endif //#ifndef TOLUA_DISABLE
+/* method: cPlugin_NewLua__Tick of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Tick00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Tick00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ float a_Dt = ((float) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__Tick'", NULL);
+#endif
+ {
+ self->cPlugin_NewLua__Tick(a_Dt);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__Tick'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin_NewLua__OnPlayerJoin of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnPlayerJoin00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnPlayerJoin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__OnPlayerJoin'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin_NewLua__OnPlayerJoin(a_Player);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__OnPlayerJoin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin_NewLua__OnLogin of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnLogin00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnLogin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPacket_Login",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPacket_Login* a_PacketData = ((cPacket_Login*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__OnLogin'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin_NewLua__OnLogin(a_PacketData);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__OnLogin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin_NewLua__OnBlockPlace of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnBlockPlace00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnBlockPlace00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPacket_BlockPlace",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cPlayer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPacket_BlockPlace* a_PacketData = ((cPacket_BlockPlace*) tolua_tousertype(tolua_S,2,0));
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__OnBlockPlace'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin_NewLua__OnBlockPlace(a_PacketData,a_Player);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__OnBlockPlace'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin_NewLua__OnKilled of class Lua__cPlugin_NewLua */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnKilled00
+static int tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnKilled00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin_NewLua",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPawn",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cEntity",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin_NewLua* self = (Lua__cPlugin_NewLua*) tolua_tousertype(tolua_S,1,0);
+ cPawn* a_Killed = ((cPawn*) tolua_tousertype(tolua_S,2,0));
+ cEntity* a_Killer = ((cEntity*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin_NewLua__OnKilled'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin_NewLua__OnKilled(a_Killed,a_Killer);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin_NewLua__OnKilled'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: GetFileName of class cPlugin_Lua */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_Lua_GetFileName00
static int tolua_AllToLua_cPlugin_Lua_GetFileName00(lua_State* tolua_S)
@@ -16496,11 +16877,22 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_cclass(tolua_S,"cPlugin_NewLua","cPlugin_NewLua","cPlugin",NULL);
tolua_beginmodule(tolua_S,"cPlugin_NewLua");
tolua_function(tolua_S,"Initialize",tolua_AllToLua_cPlugin_NewLua_Initialize00);
+ tolua_function(tolua_S,"Tick",tolua_AllToLua_cPlugin_NewLua_Tick00);
+ tolua_function(tolua_S,"OnPlayerJoin",tolua_AllToLua_cPlugin_NewLua_OnPlayerJoin00);
+ tolua_function(tolua_S,"OnLogin",tolua_AllToLua_cPlugin_NewLua_OnLogin00);
+ tolua_function(tolua_S,"OnBlockPlace",tolua_AllToLua_cPlugin_NewLua_OnBlockPlace00);
+ tolua_function(tolua_S,"OnKilled",tolua_AllToLua_cPlugin_NewLua_OnKilled00);
+ tolua_function(tolua_S,"CreateWebPlugin",tolua_AllToLua_cPlugin_NewLua_CreateWebPlugin00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"Lua__cPlugin_NewLua","Lua__cPlugin_NewLua","cPlugin_NewLua",NULL);
tolua_beginmodule(tolua_S,"Lua__cPlugin_NewLua");
tolua_function(tolua_S,"tolua__set_instance",tolua_AllToLua_Lua__cPlugin_NewLua_tolua__set_instance00);
tolua_function(tolua_S,"cPlugin_NewLua__Initialize",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Initialize00);
+ tolua_function(tolua_S,"cPlugin_NewLua__Tick",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__Tick00);
+ tolua_function(tolua_S,"cPlugin_NewLua__OnPlayerJoin",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnPlayerJoin00);
+ tolua_function(tolua_S,"cPlugin_NewLua__OnLogin",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnLogin00);
+ tolua_function(tolua_S,"cPlugin_NewLua__OnBlockPlace",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnBlockPlace00);
+ tolua_function(tolua_S,"cPlugin_NewLua__OnKilled",tolua_AllToLua_Lua__cPlugin_NewLua_cPlugin_NewLua__OnKilled00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cPlugin_Lua","cPlugin_Lua","",NULL);
tolua_beginmodule(tolua_S,"cPlugin_Lua");
@@ -16602,6 +16994,9 @@ 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
diff --git a/source/Bindings.h b/source/Bindings.h index 6e7719b93..fc3d0cb62 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/26/12 18:52:03.
+** Generated automatically by tolua++-1.0.92 on 01/27/12 00:53:12.
*/
/* Exported function */
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp index 728320f11..a40bcb9d6 100644 --- a/source/ManualBindings.cpp +++ b/source/ManualBindings.cpp @@ -6,6 +6,7 @@ #include "cWorld.h"
#include "cPlugin.h"
#include "cPluginManager.h"
+#include "cWebPlugin_Lua.h"
#include "cLuaCommandBinder.h"
#include "cPlayer.h"
#include "md5/md5.h"
@@ -191,6 +192,49 @@ static int tolua_cPlugin_BindCommand(lua_State* tolua_S) return 0;
}
+static int tolua_cWebPlugin_Lua_AddTab(lua_State* tolua_S)
+{
+ cWebPlugin_Lua* self = (cWebPlugin_Lua*) tolua_tousertype(tolua_S,1,0);
+
+ tolua_Error tolua_err;
+ tolua_err.array = 0;
+ tolua_err.index = 0;
+ tolua_err.type = 0;
+
+ std::string Title = "";
+ int Reference = LUA_REFNIL;
+
+ if( tolua_isstring( tolua_S, 2, 0, &tolua_err ) &&
+ lua_isfunction( tolua_S, 3 ) )
+ {
+ Reference = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
+ Title = ((std::string) tolua_tocppstring(tolua_S,2,0));
+ }
+ else
+ {
+ if( tolua_err.type == 0 )
+ {
+ tolua_err.type = "function";
+ }
+ tolua_error(tolua_S,"#ferror in function 'AddTab'.",&tolua_err);
+ return 0;
+ }
+
+ if( Reference != LUA_REFNIL )
+ {
+ if( !self->AddTab( 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() );
+ }
+
+ return 0;
+}
+
static int tolua_md5(lua_State* tolua_S)
{
std::string SourceString = tolua_tostring(tolua_S, 1, 0);
@@ -222,6 +266,9 @@ void ManualBindings::Bind( lua_State* tolua_S ) tolua_beginmodule(tolua_S,"cPlayer");
tolua_function(tolua_S,"GetGroups",tolua_cPlayer_GetGroups);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S,"cWebPlugin_Lua");
+ tolua_function(tolua_S,"AddTab",tolua_cWebPlugin_Lua_AddTab);
+ tolua_endmodule(tolua_S);
tolua_function(tolua_S,"md5",tolua_md5);
diff --git a/source/cPlugin_NewLua.cpp b/source/cPlugin_NewLua.cpp index 81e629ce4..fd5a23772 100644 --- a/source/cPlugin_NewLua.cpp +++ b/source/cPlugin_NewLua.cpp @@ -1,6 +1,7 @@ #define LUA_USE_POSIX
#include "cPlugin_NewLua.h"
#include "cMCLogger.h"
+#include "cWebPlugin_Lua.h"
extern "C"
{
@@ -11,10 +12,10 @@ extern "C" #include "Bindings.h"
#include "ManualBindings.h"
-#ifdef _WIN32 -#include "wdirent.h" -#else -#include <dirent.h> +#ifdef _WIN32
+#include "wdirent.h"
+#else
+#include <dirent.h>
#endif
extern bool report_errors(lua_State* lua, int status);
@@ -27,6 +28,12 @@ cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName ) cPlugin_NewLua::~cPlugin_NewLua()
{
+ for( WebPluginList::iterator itr = m_WebPlugins.begin(); itr != m_WebPlugins.end(); ++itr )
+ {
+ delete *itr;
+ }
+ m_WebPlugins.clear();
+
if( m_LuaState )
{
lua_close( m_LuaState );
@@ -49,9 +56,9 @@ bool cPlugin_NewLua::Initialize() // Load all files for this plugin, and execute them
DIR* dp;
struct dirent *entry;
- if(dp = opendir( PluginPath.c_str() )) - { - while(entry = readdir(dp)) + if(dp = opendir( PluginPath.c_str() ))
+ {
+ while(entry = readdir(dp))
{
std::string FileName = entry->d_name;
if( FileName.find(".lua") != std::string::npos )
@@ -76,6 +83,7 @@ bool cPlugin_NewLua::Initialize() }
}
}
+ closedir( dp );
}
@@ -177,7 +185,19 @@ bool cPlugin_NewLua::OnKilled( cPawn* a_Killed, cEntity* a_Killer ) return bRetVal;
}
+cWebPlugin_Lua* cPlugin_NewLua::CreateWebPlugin(lua_State* a_LuaState)
+{
+ if( a_LuaState != m_LuaState )
+ {
+ LOGERROR("Not allowed to create a WebPlugin from another plugin but your own!");
+ return 0;
+ }
+ cWebPlugin_Lua* WebPlugin = new cWebPlugin_Lua( this );
+ m_WebPlugins.push_back( WebPlugin );
+
+ return WebPlugin;
+}
// Helper functions
diff --git a/source/cPlugin_NewLua.h b/source/cPlugin_NewLua.h index bdd7f1f7e..1aa4242ea 100644 --- a/source/cPlugin_NewLua.h +++ b/source/cPlugin_NewLua.h @@ -2,8 +2,10 @@ #include "cPlugin.h"
#include <string>
+#include <list>
typedef struct lua_State lua_State;
+class cWebPlugin_Lua;
class cPlugin_NewLua : public cPlugin //tolua_export
{ //tolua_export
@@ -18,10 +20,16 @@ public: //tolua_export virtual bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player ); // tolua_export
virtual bool OnKilled( cPawn* a_Killed, cEntity* a_Killer ); //tolua_export
+ lua_State* GetLuaState() { return m_LuaState; }
+
+ cWebPlugin_Lua* CreateWebPlugin(lua_State* a_LuaState); //tolua_export
private:
bool PushFunction( const char* a_FunctionName );
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;
+
std::string m_Directory;
lua_State* m_LuaState;
};//tolua_export
\ No newline at end of file diff --git a/source/cWebAdmin.cpp b/source/cWebAdmin.cpp index 86dbf5990..ec4894aef 100644 --- a/source/cWebAdmin.cpp +++ b/source/cWebAdmin.cpp @@ -3,6 +3,7 @@ #include "cStringMap.h"
#include "cWebPlugin.h"
+#include "cWebPlugin_Lua.h"
#include "cPluginManager.h"
#include "cPlugin.h"
@@ -96,6 +97,16 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) std::string UserPassword = WebAdmin->m_IniFile->GetValue( "User:"+r->username_, "Password", "");
if (UserPassword != "" && r->password_ == UserPassword)
{
+ std::string BaseURL = "./";
+ if( Split.size() > 1 )
+ {
+ for( unsigned int i = 0; i < Split.size(); i++)
+ {
+ BaseURL += "../";
+ }
+ BaseURL += "webadmin/";
+ }
+
std::string Menu;
std::string Content;
std::string Template = WebAdmin->GetTemplate();
@@ -103,7 +114,20 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) for( PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr )
{
- Menu += "<li><a href='" + (*itr)->GetName() + "'>" + (*itr)->GetName() + "</a></li>";
+ cWebPlugin* WebPlugin = *itr;
+ 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 )
+ {
+ Menu += "<li><a href='" + BaseURL + WebPlugin->GetName() + "/" + (*Name) + "'>" + (*Name) + "</a></li>";
+ }
+ }
+ else
+ {
+ Menu += "<li><a href='" + BaseURL + WebPlugin->GetName() + "'>" + WebPlugin->GetName() + "</a></li>";
+ }
}
HTTPRequest Request;
@@ -112,17 +136,20 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) Request.Params = new cStringMap(r->params_);
Request.Path = r->path_;
-
-
if( Split.size() > 1 )
{
-
for( PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr )
{
if( (*itr)->GetName() == Split[1] )
{
Content = (*itr)->HandleRequest( &Request );
- FoundPlugin = (*itr)->GetName();
+ cWebPlugin* WebPlugin = *itr;
+ FoundPlugin = WebPlugin->GetName();
+ cWebPlugin_Lua* LuaPlugin = dynamic_cast< cWebPlugin_Lua* >( WebPlugin );
+ if( LuaPlugin )
+ {
+ FoundPlugin += " - " + LuaPlugin->GetTabNameForRequest( &Request );
+ }
break;
}
}
@@ -144,7 +171,10 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) const cPluginManager::PluginList & List = PM->GetAllPlugins();
for( cPluginManager::PluginList::const_iterator itr = List.begin(); itr != List.end(); ++itr )
{
- Content += std::string("<li>") + std::string( (*itr)->GetName() ) + "</li>";
+ char c_VersionNum[32]; // 32 digits should be enough? XD
+ sprintf_s( c_VersionNum, 32, "%i", (*itr)->GetVersion() );
+ Content += std::string("<li>") + std::string( (*itr)->GetName() ) + " V. " + std::string( c_VersionNum ) + "</li>";
+
}
}
Content += "</ul>";
@@ -163,13 +193,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) if( Split.size() > 1 )
{
- Content += "\n<p><a href='";
- for( unsigned int i = 0; i < Split.size(); i++)
- {
- Content += "../";
- }
- Content += "webadmin/";
- Content += "'>Go back</a></p>";
+ Content += "\n<p><a href='" + BaseURL + "'>Go back</a></p>";
}
// mem usage
diff --git a/source/cWebPlugin_Lua.cpp b/source/cWebPlugin_Lua.cpp new file mode 100644 index 000000000..c9aaef5a7 --- /dev/null +++ b/source/cWebPlugin_Lua.cpp @@ -0,0 +1,149 @@ +#include "cMCLogger.h"
+#include "cWebPlugin_Lua.h"
+#include "cPlugin_NewLua.h"
+
+#include <string>
+#include "tolua++.h"
+#include "cWebAdmin.h"
+
+extern bool report_errors(lua_State* lua, int status);
+extern std::vector<std::string> StringSplit(std::string str, std::string delim);
+
+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 = a_Title; // TODO - Convert all non alphabet/digit letters to underscores
+
+ Tab->Reference = a_FunctionReference;
+
+ m_Tabs.push_back( Tab );
+ return true;
+}
+
+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() )
+ 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
+ {
+ 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( report_errors( LuaState, s ) )
+ {
+ LOGINFO("error. Stack size: %i", lua_gettop(LuaState) );
+ return false;
+ }
+
+
+ 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 "";
+ }
+
+ 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::string cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request )
+{
+ std::vector<std::string> 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 )
+ {
+ return Tab->Title;
+ }
+ }
+
+ return "";
+}
+
+std::list< std::string > cWebPlugin_Lua::GetTabNames()
+{
+ std::list< std::string > NameList;
+ for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
+ {
+ NameList.push_back( (*itr)->Title );
+ }
+ return NameList;
+}
\ No newline at end of file diff --git a/source/cWebPlugin_Lua.h b/source/cWebPlugin_Lua.h new file mode 100644 index 000000000..deec9333e --- /dev/null +++ b/source/cWebPlugin_Lua.h @@ -0,0 +1,31 @@ +#pragma once
+
+#include "cWebPlugin.h"
+
+#include <list>
+#include <string>
+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::string GetTabNameForRequest( HTTPRequest* a_Request );
+
+ std::list< std::string > GetTabNames();
+private:
+ cPlugin_NewLua* m_Plugin;
+
+ struct sWebPluginTab;
+ typedef std::list< sWebPluginTab* > TabList;
+ TabList m_Tabs;
+}; //tolua_export
\ No newline at end of file |