diff options
author | madmaxoft <github@xoft.cz> | 2013-08-07 22:39:40 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-08-07 22:39:40 +0200 |
commit | 09ebda4d10ef004d196315b829e9c6740dd3d1ee (patch) | |
tree | 402223064c637abc1a036c82177f63ac8f534843 /source | |
parent | Merge pull request #48 from mc-server/BlockTracing (diff) | |
download | cuberite-09ebda4d10ef004d196315b829e9c6740dd3d1ee.tar cuberite-09ebda4d10ef004d196315b829e9c6740dd3d1ee.tar.gz cuberite-09ebda4d10ef004d196315b829e9c6740dd3d1ee.tar.bz2 cuberite-09ebda4d10ef004d196315b829e9c6740dd3d1ee.tar.lz cuberite-09ebda4d10ef004d196315b829e9c6740dd3d1ee.tar.xz cuberite-09ebda4d10ef004d196315b829e9c6740dd3d1ee.tar.zst cuberite-09ebda4d10ef004d196315b829e9c6740dd3d1ee.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Globals.h | 6 | ||||
-rw-r--r-- | source/Plugin.h | 2 | ||||
-rw-r--r-- | source/PluginManager.cpp | 1 | ||||
-rw-r--r-- | source/Plugin_Squirrel.cpp | 409 | ||||
-rw-r--r-- | source/Plugin_Squirrel.h | 69 | ||||
-rw-r--r-- | source/Root.cpp | 8 | ||||
-rw-r--r-- | source/SquirrelCommandBinder.cpp | 118 | ||||
-rw-r--r-- | source/SquirrelCommandBinder.h | 51 | ||||
-rw-r--r-- | source/main.cpp | 4 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelArray.h | 56 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelBaseClass.h | 66 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelBindings.cpp | 195 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelBindings.h | 32 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelFunctions.cpp | 94 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelFunctions.h | 28 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelObject.h | 55 |
16 files changed, 1 insertions, 1193 deletions
diff --git a/source/Globals.h b/source/Globals.h index c9589bfc5..150051de0 100644 --- a/source/Globals.h +++ b/source/Globals.h @@ -131,12 +131,6 @@ typedef unsigned short UInt16; #endif #endif -#if !defined(ANDROID_NDK) - // 2012_11_08 _X: Disabled SquirrelVM, because it would crash the server from time to time. - // For details see: http://forum.mc-server.org/showthread.php?tid=610 - // #define USE_SQUIRREL -#endif - #if defined(ANDROID_NDK) #define FILE_IO_PREFIX "/sdcard/mcserver/" #else diff --git a/source/Plugin.h b/source/Plugin.h index 3b3feb99c..0f68273ee 100644 --- a/source/Plugin.h +++ b/source/Plugin.h @@ -127,7 +127,7 @@ public: { E_CPP, E_LUA, - E_SQUIRREL, + E_SQUIRREL, // OBSOLETE, but kept in place to remind us of the horrors lurking in the history }; PluginLanguage GetLanguage() { return m_Language; } void SetLanguage( PluginLanguage a_Language ) { m_Language = a_Language; } diff --git a/source/PluginManager.cpp b/source/PluginManager.cpp index 412200256..16b4056f4 100644 --- a/source/PluginManager.cpp +++ b/source/PluginManager.cpp @@ -1073,7 +1073,6 @@ void cPluginManager::UnloadPluginsNow() m_Commands.clear(); m_ConsoleCommands.clear(); - //SquirrelVM::Shutdown(); // This breaks shit } diff --git a/source/Plugin_Squirrel.cpp b/source/Plugin_Squirrel.cpp deleted file mode 100644 index adca4b519..000000000 --- a/source/Plugin_Squirrel.cpp +++ /dev/null @@ -1,409 +0,0 @@ - -#include "Globals.h" - - - - -#ifdef USE_SUIRREL - - - - - -#include "Plugin_Squirrel.h" -#include "squirrelbindings/SquirrelFunctions.h" -#include "squirrelbindings/SquirrelBindings.h" -#include "squirrelbindings/SquirrelBaseClass.h" - - -cPlugin_Squirrel::cPlugin_Squirrel( const char* a_PluginName ) - : cPlugin( a_PluginName ) -{ - SetLanguage( cPlugin::E_SQUIRREL ); - m_PluginName = a_PluginName; -} - -cPlugin_Squirrel::~cPlugin_Squirrel() -{ - delete m_Plugin; -} - -bool cPlugin_Squirrel::Initialize() -{ - cCSLock Lock(m_CriticalSection); - - std::string PluginPath = std::string("Plugins/") + m_PluginName + ".nut"; - - Sqrat::Script script; - script.CompileFile(PluginPath); - if(script.IsNull()) - { - LOGERROR("Unable to run script \"%s\"", m_PluginName); - } - - try { - script.Run(); - - Sqrat::Function construct(Sqrat::RootTable(), m_PluginName); - - if(construct.IsNull()) - { - LOGERROR("Constructor for Plugin \"%s\" not found.", m_PluginName); - return false; - } - - Sqrat::Object obj = construct.Evaluate<Sqrat::Object>(); - - ((cSquirrelBaseClass *) obj.GetInstanceUP())->setInstance(this); - - m_Plugin = new SquirrelObject(obj); - - - Sqrat::Object PluginName = obj.GetSlot("name"); - if(!PluginName.IsNull()) - { - this->SetName(PluginName.Cast<const char*>()); - } - - Sqrat::Function init = m_Plugin->GetFunction("Initialize"); - if(init.IsNull()) - { - LOGERROR("Can not initialize plugin \"%s\"", m_PluginName); - return false; - } - - return init.Evaluate<bool>(); - - } catch(Sqrat::Exception &e) - { - LOGERROR("Initialisation of \"%s\" failed: %s", m_PluginName, e.Message().c_str()); - return false; - } -} - - - - - -void cPlugin_Squirrel::OnDisable() -{ - cCSLock Lock(m_CriticalSection); - - if(!m_Plugin->HasFunction("OnDisable")) return; - - m_Plugin->GetFunction("OnDisable").Execute(); -} - - - - - -void cPlugin_Squirrel::Tick(float a_Dt) -{ - cCSLock Lock( m_CriticalSection ); - - if(!m_Plugin->HasFunction("OnTick")) return; - - m_Plugin->GetFunction("OnTick").Execute(a_Dt); -} - - - - - -bool cPlugin_Squirrel::OnCollectPickup(cPlayer * a_Player, cPickup * a_Pickup) -{ - cCSLock Lock(m_CriticalSection); - - if (!m_Plugin->HasFunction("OnCollectPickup")) - { - return false; - } - - return m_Plugin->GetFunction("OnCollectPickup").Evaluate<bool>(a_Player, a_Pickup); -} - - - - - -bool cPlugin_Squirrel::OnDisconnect(cPlayer* a_Player, const AString & a_Reason) -{ - cCSLock Lock( m_CriticalSection ); - - if (!m_Plugin->HasFunction("OnDisconnect")) return false; - - return m_Plugin->GetFunction("OnDisconnect").Evaluate<bool>(a_Player, a_Reason); -} - - - - - -bool cPlugin_Squirrel::OnBlockPlace(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem) -{ - cCSLock Lock(m_CriticalSection); - - if (!m_Plugin->HasFunction("OnBlockPlace")) return false; - - return m_Plugin->GetFunction("OnBlockPlace").Evaluate<bool>(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_HeldItem); -} - - - - - -bool cPlugin_Squirrel::OnBlockDig(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) -{ - cCSLock Lock(m_CriticalSection); - - if (!m_Plugin->HasFunction("OnBlockDig")) return false; - - return m_Plugin->GetFunction("OnBlockDig").Evaluate<bool>(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status, a_OldBlock, a_OldMeta); -} - - - - - -bool cPlugin_Squirrel::OnChat(cPlayer * a_Player, const AString & a_Message) -{ - cCSLock Lock(m_CriticalSection); - - if (!m_Plugin->HasFunction("OnChat")) return false; - - return m_Plugin->GetFunction("OnChat").Evaluate<bool>(a_Player, a_Message); - -} - - - - - -bool cPlugin_Squirrel::OnLogin(cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) -{ - cCSLock Lock( m_CriticalSection ); - - if (!m_Plugin->HasFunction("OnLogin")) - { - return false; - } - - return m_Plugin->GetFunction("OnLogin").Evaluate<bool>(a_Client, a_ProtocolVersion, a_Username); -} - - - - - -void cPlugin_Squirrel::OnPlayerSpawn( cPlayer* a_Player ) -{ - cCSLock Lock( m_CriticalSection ); - - if(!m_Plugin->HasFunction("OnPlayerSpawn")) return; - - return m_Plugin->GetFunction("OnPlayerSpawn").Execute(a_Player); - -} - - - - - -bool cPlugin_Squirrel::OnPlayerJoin( cPlayer* a_Player ) -{ - cCSLock Lock( m_CriticalSection ); - - if(!m_Plugin->HasFunction("OnPlayerJoin")) return false; - - return m_Plugin->GetFunction("OnPlayerJoin").Evaluate<bool>(a_Player); -} - - - - - -void cPlugin_Squirrel::OnPlayerMove( cPlayer* a_Player ) -{ - cCSLock Lock( m_CriticalSection ); - - if(!m_Plugin->HasFunction("OnPlayerMove")) return; - - return m_Plugin->GetFunction("OnPlayerMove").Execute(a_Player); - -} - - - - - -void cPlugin_Squirrel::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) -{ - cCSLock Lock( m_CriticalSection ); - - if(!m_Plugin->HasFunction("OnTakeDamage")) return; - - return m_Plugin->GetFunction("OnTakeDamage")(a_Pawn, a_TakeDamageInfo); -} - - - - - -bool cPlugin_Squirrel::OnKilled( cPawn* a_Killed, cEntity* a_Killer ) -{ - cCSLock Lock( m_CriticalSection ); - if(!m_Plugin->HasFunction("OnKilled")) return false; - return m_Plugin->GetFunction("OnKilled").Evaluate<bool>(a_Killed, a_Killer); -} - - - - - -void cPlugin_Squirrel::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ) -{ - cCSLock Lock(m_CriticalSection); - if(!m_Plugin->HasFunction("OnChunkGenerated")) return; - return m_Plugin->GetFunction("OnChunkGenerated")(a_World, a_ChunkX, a_ChunkZ); -} - - - - - -bool cPlugin_Squirrel::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_pLuaChunk) -{ - cCSLock Lock(m_CriticalSection); - if(!m_Plugin->HasFunction("OnChunkGenerating")) return false; - return m_Plugin->GetFunction("OnChunkGenerating").Evaluate<bool>(a_World, a_ChunkX, a_ChunkZ, a_pLuaChunk); -} - - - - - -bool cPlugin_Squirrel::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) -{ - cCSLock Lock(m_CriticalSection); - if(!m_Plugin->HasFunction("OnPreCrafting")) return false; - return m_Plugin->GetFunction("OnPreCrafting").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe); - -} - - - - - -bool cPlugin_Squirrel::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) -{ - cCSLock Lock(m_CriticalSection); - if(!m_Plugin->HasFunction("OnCraftingNoRecipe")) return false; - return m_Plugin->GetFunction("OnCraftingNoRecipe").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe); -} - - - - - -bool cPlugin_Squirrel::OnPostCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) -{ - cCSLock Lock(m_CriticalSection); - - if(!m_Plugin->HasFunction("OnPostCrafting")) return false; - return m_Plugin->GetFunction("OnPostCrafting").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe); -} - - - - - -bool cPlugin_Squirrel::OnBlockToPickup( - BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, - const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups -) -{ - cCSLock Lock(m_CriticalSection); - - if(!m_Plugin->HasFunction("OnBlockToPickup")) return false; - return m_Plugin->GetFunction("OnBlockToPickup").Evaluate<bool>(a_BlockType, a_BlockMeta, (cPlayer *) a_Player, a_EquippedItem, a_Pickups); - -} - - - - - -bool cPlugin_Squirrel::OnWeatherChanged(cWorld * a_World) -{ - cCSLock Lock(m_CriticalSection); - - if(!m_Plugin->HasFunction("OnWeatherChanged")) return false; - return m_Plugin->GetFunction("OnWeatherChanged").Evaluate<bool>(a_World); -} - - - - - -bool cPlugin_Squirrel::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, - cPlayer * a_Player -) -{ - cCSLock Lock(m_CriticalSection); - - if(!m_Plugin->HasFunction("OnUpdatingSign")) return false; - return m_Plugin->GetFunction("OnUpdatingSign") - .Evaluate<bool>( - a_World, - a_BlockX, - a_BlockY, - a_BlockZ, - a_Line1, - a_Line2, - a_Line3, - a_Line4, - a_Player - ); -} - - - - - -bool cPlugin_Squirrel::OnUpdatedSign( - cWorld * a_World, - int a_BlockX, int a_BlockY, int a_BlockZ, - const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, - cPlayer * a_Player -) -{ - cCSLock Lock(m_CriticalSection); - - if(!m_Plugin->HasFunction("OnUpdatedSign")) return false; - return m_Plugin->GetFunction("OnUpdatedSign") - .Evaluate<bool>( - a_World, - a_BlockX, - a_BlockY, - a_BlockZ, - a_Line1, - a_Line2, - a_Line3, - a_Line4, - a_Player - ); -} - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/Plugin_Squirrel.h b/source/Plugin_Squirrel.h deleted file mode 100644 index 1a56172e9..000000000 --- a/source/Plugin_Squirrel.h +++ /dev/null @@ -1,69 +0,0 @@ - -#pragma once - - - - - -#ifdef USE_SQUIRREL - - - - - -#include "Plugin.h" -#include <sqrat.h> -#include "squirrelbindings/SquirrelObject.h" - - - - - -class cPlugin_Squirrel : - public cPlugin -{ -public: - cPlugin_Squirrel(const char* a_PluginName); - ~cPlugin_Squirrel(); - - void OnDisable(); - bool Initialize(); - - void Tick(float a_Dt); - - virtual bool OnBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) override; - virtual bool OnBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem) override; - virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups); - virtual bool OnChat (cPlayer * a_Player, const AString & a_Message) override; - virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override; - virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_pLuaChunk ) override; - virtual bool OnCollectPickup (cPlayer * a_Player, cPickup * a_Pickup) override; - virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; - virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason) override; - virtual bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override; - virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override; - virtual bool OnPlayerJoin (cPlayer* a_Player ) override; - virtual void OnPlayerMove (cPlayer* a_Player ) override; - virtual void OnPlayerSpawn (cPlayer* a_Player ) override; - virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; - virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; - virtual void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override; - virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player) override; - 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, cPlayer * a_Player) override; - virtual bool OnWeatherChanged (cWorld * a_World) override; - -protected: - const char * m_PluginName; - cCriticalSection m_CriticalSection; - SquirrelObject *m_Plugin; -}; - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/Root.cpp b/source/Root.cpp index f12ccc832..5ec27aa0d 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -17,11 +17,6 @@ #include "Protocol/ProtocolRecognizer.h" // for protocol version constants #include "CommandOutput.h" -#ifdef USE_SQUIRREL - #include "squirrelbindings/SquirrelFunctions.h" - #include "squirrelbindings/SquirrelBindings.h" -#endif - #include "../iniFile/iniFile.h" #include <iostream> @@ -195,9 +190,6 @@ void cRoot::Start(void) m_Authenticator.Stop(); - #ifdef USE_SQUIRREL - CloseSquirrelVM(); - #endif LOG("Freeing MonsterConfig..."); delete m_MonsterConfig; m_MonsterConfig = 0; LOG("Stopping WebAdmin..."); diff --git a/source/SquirrelCommandBinder.cpp b/source/SquirrelCommandBinder.cpp deleted file mode 100644 index 66b456ace..000000000 --- a/source/SquirrelCommandBinder.cpp +++ /dev/null @@ -1,118 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - - - - - -#ifdef USE_SQUIRREL - - - - - -#include "SquirrelCommandBinder.h" -#include "Player.h" -#include "Plugin.h" -#include "Plugin_Squirrel.h" -#include "squirrelbindings/SquirrelArray.h" - - -cSquirrelCommandBinder::cSquirrelCommandBinder() -{ -} - -cSquirrelCommandBinder::~cSquirrelCommandBinder() -{ -} - -void cSquirrelCommandBinder::ClearBindings() -{ - m_BoundCommands.clear(); -} - -void cSquirrelCommandBinder::RemoveBindingsForPlugin( cPlugin* a_Plugin ) -{ - for( CommandMap::iterator itr = m_BoundCommands.begin(); itr != m_BoundCommands.end(); ) - { - if( itr->second.Plugin == a_Plugin ) - { - LOGINFO("Unbinding %s ", itr->first.c_str( ) ); - CommandMap::iterator eraseme = itr; - ++itr; - m_BoundCommands.erase( eraseme ); - continue; - } - ++itr; - } -} - -bool cSquirrelCommandBinder::BindCommand( const std::string & a_Command, const std::string & a_Permission, cPlugin* a_Plugin, Sqrat::Function a_Callback ) -{ - if( !a_Plugin->CanBindCommands() ) - { - LOGERROR("ERROR: Trying to bind command \"%s\" to a plugin that is not initialized.", a_Command.c_str() ); - return false; - } - if( m_BoundCommands.find( a_Command ) != m_BoundCommands.end() ) - { - LOGERROR("ERROR: Trying to bind command \"%s\" that has already been bound.", a_Command.c_str() ); - return false; - } - LOGINFO("Binding %s (%s)", a_Command.c_str(), a_Permission.c_str() ); - - BoundFunction Callback; - Callback.Callback = a_Callback; - Callback.Plugin = a_Plugin; - Callback.Permission = a_Permission; - - m_BoundCommands[ a_Command ] = Callback; - return true; -} - -bool cSquirrelCommandBinder::HandleCommand( const std::string & a_Command, cPlayer* a_Player ) -{ - AStringVector Split = StringSplit(a_Command, " "); - if (Split.size() == 0) - { - return false; - } - - CommandMap::iterator FoundCommand = m_BoundCommands.find( Split[0] ); - if( FoundCommand != m_BoundCommands.end() ) - { - const BoundFunction & func = FoundCommand->second; - if( func.Permission.size() > 0 ) - { - if( !a_Player->HasPermission( func.Permission.c_str() ) ) - { - return false; - } - } - - - // Push the split - SquirrelStringArray SplitData; - - std::vector<std::string>::const_iterator iter = Split.begin(); - while(iter != Split.end()) { - SplitData.Add(*iter); - ++iter; - } - - // Push player - Sqrat::Function callback = func.Callback; - return callback.Evaluate<bool>(&SplitData, a_Player); - } - return false; -} - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/SquirrelCommandBinder.h b/source/SquirrelCommandBinder.h deleted file mode 100644 index 49e6fd003..000000000 --- a/source/SquirrelCommandBinder.h +++ /dev/null @@ -1,51 +0,0 @@ - -#pragma once - - - - - -#ifdef USE_SQUIRREL - - - - - -#include <sqrat.h> - -class cPlugin; -class cPlayer; - -class cSquirrelCommandBinder -{ -public: - cSquirrelCommandBinder(); - ~cSquirrelCommandBinder(); - - bool HandleCommand( const std::string & a_Command, cPlayer* a_Player ); - - bool BindCommand( const std::string & a_Command, const std::string & a_Permission, cPlugin* a_Plugin, Sqrat::Function a_Callback); - - void ClearBindings(); - void RemoveBindingsForPlugin( cPlugin* a_Plugin ); -private: - struct BoundFunction - { - Sqrat::Function Callback; - cPlugin *Plugin; - std::string Permission; - }; - - typedef std::map< std::string, BoundFunction > CommandMap; - CommandMap m_BoundCommands; -}; - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/main.cpp b/source/main.cpp index baf41a845..1f6aad24f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -6,10 +6,6 @@ #include <exception> //std::exception #include <csignal> //std::signal #include <stdlib.h> //exit() -#ifdef USE_SQUIRREL -#include "squirrelbindings/SquirrelFunctions.h" -#include "squirrelbindings/SquirrelBindings.h" -#endif #ifdef _MSC_VER #include <dbghelp.h> diff --git a/source/squirrelbindings/SquirrelArray.h b/source/squirrelbindings/SquirrelArray.h deleted file mode 100644 index de5027f86..000000000 --- a/source/squirrelbindings/SquirrelArray.h +++ /dev/null @@ -1,56 +0,0 @@ - -#pragma once - - - - - -#ifdef USE_SQUIRREL - - - - - -template <typename T> -class SquirrelArray -{ -public: - SquirrelArray() - { - } - - unsigned int Size() - { - return m_Values.size(); - } - - T Get(unsigned int a_Index) - { - if(m_Values.size() < a_Index) - { - return T(); - } - return m_Values.at(a_Index); - } - - void Add(T a_Value) - { - m_Values.push_back(a_Value); - } - -protected: - std::vector<T> m_Values; - -}; - -class SquirrelStringArray : public SquirrelArray<std::string> { }; - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelBaseClass.h b/source/squirrelbindings/SquirrelBaseClass.h deleted file mode 100644 index fb5e95c05..000000000 --- a/source/squirrelbindings/SquirrelBaseClass.h +++ /dev/null @@ -1,66 +0,0 @@ - -#pragma once - - - - -#ifdef USE_SQUIRREL - - - - - -#include "SquirrelBindings.h" -#include "../Plugin_Squirrel.h" -#include "../PluginManager.h" -#include "../Root.h" -#include "../SquirrelCommandBinder.h" - - - - - -// The baseclass for squirrel plugins -class cSquirrelBaseClass -{ -public: - cSquirrelBaseClass() - : m_Instance(0) - { - } - - void setInstance(cPlugin_Squirrel *a_Instance) - { - m_Instance = a_Instance; - } - - void AddHook(short a_Hook) - { - if(m_Instance) - cRoot::Get()->GetPluginManager()->AddHook(m_Instance, (cPluginManager::PluginHook) a_Hook); - } - - void AddCommand( std::string a_Command, std::string a_Description, std::string a_Permission ) - { - if(m_Instance) m_Instance->AddCommand(a_Command, a_Description, a_Permission); - } - - bool BindCommand( const std::string a_Command, const std::string a_Permission, Sqrat::Function a_Callback) - { - if(!m_Instance) return false; - return cRoot::Get()->GetPluginManager()->GetSquirrelCommandBinder()->BindCommand(a_Command, a_Permission, m_Instance, a_Callback); - } - -protected: - cPlugin_Squirrel *m_Instance; -}; - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelBindings.cpp b/source/squirrelbindings/SquirrelBindings.cpp deleted file mode 100644 index 51acc184f..000000000 --- a/source/squirrelbindings/SquirrelBindings.cpp +++ /dev/null @@ -1,195 +0,0 @@ - -#include "Globals.h" - - - - - -#ifdef USE_SQUIRREL - - - - -#include "SquirrelBindings.h" -#include "SquirrelFunctions.h" - -#include "SquirrelBaseClass.h" -#include "SquirrelArray.h" - -#include "../Player.h" - - - - - -using namespace Sqrat; - - - - - -void BindSquirrel(HSQUIRRELVM vm) -{ - RootTable() - .Bind("Plugin", Class<cSquirrelBaseClass>() - .Func("AddHook", &cSquirrelBaseClass::AddHook) - .Func("AddCommand", &cSquirrelBaseClass::AddCommand) - .Func("BindCommand", &cSquirrelBaseClass::BindCommand) - ); - - RootTable().Bind("Vector3f", Class<Vector3f, NoConstructor>() - .Func("Set", &Vector3f::Set) - .Func("Normalize", &Vector3f::Normalize) - .Func("Length", &Vector3f::Length) - .Func("SqrLength", &Vector3f::SqrLength) - .Var("x", &Vector3f::x) - .Var("y", &Vector3f::y) - .Var("z", &Vector3f::z) - ); - - RootTable().Bind("Vector3d", Class<Vector3d, NoConstructor>() - .Func("Set", &Vector3d::Set) - .Func("Normalize", &Vector3d::Normalize) - .Func("Length", &Vector3d::Length) - .Func("SqrLength", &Vector3d::SqrLength) - .Var("x", &Vector3d::x) - .Var("y", &Vector3d::y) - .Var("z", &Vector3d::z) - ); - - RootTable().Bind("cEntity", Class<cEntity, NoConstructor>() - .Func("GetEntityType", &cEntity::GetEntityType) - .Func("IsA", &cEntity::IsA) - .Func("GetWorld", &cEntity::GetWorld) - .Func("GetPosition", &cEntity::GetPosition) - .Func("GetPosX", &cEntity::GetPosX) - .Func("GetPosY", &cEntity::GetPosY) - .Func("GetPosZ", &cEntity::GetPosZ) - .Func("GetRot", &cEntity::GetRot) - .Func("GetRotation", &cEntity::GetRotation) - .Func("GetPitch", &cEntity::GetPitch) - .Func("GetRoll", &cEntity::GetRoll) - .Func("SetRotation", &cEntity::SetRotation) - .Func("SetPitch", &cEntity::SetPitch) - .Func("SetRoll", &cEntity::SetRoll) - .Func("GetLookVector", &cEntity::GetLookVector) - .Func("GetChunkX", &cEntity::GetChunkX) - .Func("GetChunkY", &cEntity::GetChunkY) - .Func("GetChunkZ", &cEntity::GetChunkZ) - .Func("SetPosX", &cEntity::SetPosX) - .Func("SetPosY", &cEntity::SetPosY) - .Func("SetPosZ", &cEntity::SetPosZ) - .Func<void (cEntity::*) (double, double, double)>("SetPosition", &cEntity::SetPosition) - .Func("GetUniqueID", &cEntity::GetUniqueID) - .Func("IsDestroyed", &cEntity::IsDestroyed) - .Func("Destroy", &cEntity::Destroy) - ); - - ConstTable().Enum("MetaData", Enumeration() - .Const("Normal", cPawn::NORMAL) - .Const("Burning", cPawn::BURNING) - .Const("Crouched", cPawn::CROUCHED) - .Const("Riding", cPawn::RIDING) - .Const("Sprinting", cPawn::SPRINTING) - .Const("Eating", cPawn::EATING) - .Const("Blocking", cPawn::BLOCKING) - ); - - RootTable().Bind("cPawn", DerivedClass<cPawn, cEntity, NoConstructor>() - .Func("TeleportToEntity", &cPawn::TeleportToEntity) - .Func("TeleportTo", &cPawn::TeleportTo) - .Func("Heal", &cPawn::Heal) - .Func("TakeDamage", &cPawn::TakeDamage) - .Func("KilledBy", &cPawn::KilledBy) - .Func("GetHealth", &cPawn::GetHealth) - .Func("SetMetaData", &cPawn::SetMetaData) - .Func("GetMetaData", &cPawn::GetMetaData) - .Func("SetMaxHealth", &cPawn::SetMaxHealth) - .Func("GetMaxHealth", &cPawn::GetMaxHealth) - ); - - RootTable().Bind("cPlayer", DerivedClass<cPlayer, cPawn, NoConstructor>() - .Func("GetName", &cPlayer::GetName) - .Func("SetTouchGround", &cPlayer::SetTouchGround) - .Func("SetStance", &cPlayer::SetStance) - .Func("GetEyeHeight", &cPlayer::GetEyeHeight) - .Func("GetEyePosition", &cPlayer::GetEyePosition) - .Func("GetFlying", &cPlayer::GetFlying) - .Func("GetStance", &cPlayer::GetStance) - //TODO .Func("GetInventory", &cPlayer::GetInventory) - .Func("TeleportTo", &cPlayer::TeleportTo) - .Func("GetGameMode", &cPlayer::GetGameMode) - .Func("GetIP", &cPlayer::GetIP) - .Func("GetLastBlockActionTime", &cPlayer::GetLastBlockActionTime) - .Func("GetLastBlockActionCnt", &cPlayer::GetLastBlockActionCnt) - .Func("SetLastBlockActionCnt", &cPlayer::SetLastBlockActionCnt) - .Func("SetLastBlockActionTime", &cPlayer::SetLastBlockActionTime) - .Func("SetGameMode", &cPlayer::SetGameMode) - .Func("LoginSetGameMode", &cPlayer::LoginSetGameMode) - .Func("SetIP", &cPlayer::SetIP) - .Func("MoveTo", &cPlayer::MoveTo) - .Func("GetClientHandle", &cPlayer::GetClientHandle) - .Func("SendMessage", &cPlayer::SendMessage) - .Func("AddToGroup", &cPlayer::AddToGroup) - .Func("CanUseCommand", &cPlayer::CanUseCommand) - .Func("HasPermission", &cPlayer::HasPermission) - .Func("IsInGroup", &cPlayer::IsInGroup) - .Func("GetColor", &cPlayer::GetColor) - .Func("TossItem", &cPlayer::TossItem) - .Func("Heal", &cPlayer::Heal) - .Func("Feed", &cPlayer::Feed) - .Func("TakeDamage", &cPlayer::TakeDamage) - .Func("KilledBy", &cPlayer::KilledBy) - .Func("Respawn", &cPlayer::Respawn) - .Func("SetVisible", &cPlayer::SetVisible) - .Func("IsVisible", &cPlayer::IsVisible) - .Func("MoveToWorld", &cPlayer::MoveToWorld) - .Func("GetLoadedWorldName", &cPlayer::GetLoadedWorldName) - .Func("UseEquippedItem", &cPlayer::UseEquippedItem) - ); - - RootTable().Bind("StringArray", Class<SquirrelStringArray>() - .Func("Get", &SquirrelStringArray::Get) - .Func("Add", &SquirrelStringArray::Add) - .Func("Size", &SquirrelStringArray::Size) - ); - - - RootTable().Func("print", &sqPrint); - - - ConstTable().Enum("Hook", Enumeration() - .Const("Tick", cPluginManager::HOOK_TICK) - .Const("Chat", cPluginManager::HOOK_CHAT) - .Const("CollectPickup", cPluginManager::HOOK_COLLECT_PICKUP) - .Const("BlockDig", cPluginManager::HOOK_BLOCK_DIG) - .Const("BlockPlace", cPluginManager::HOOK_BLOCK_PLACE) - .Const("Disconnect", cPluginManager::HOOK_DISCONNECT) - .Const("Handshake", cPluginManager::HOOK_HANDSHAKE) - .Const("Login", cPluginManager::HOOK_LOGIN) - .Const("PlayerSpawn", cPluginManager::HOOK_PLAYER_SPAWN) - .Const("PlayerJoin", cPluginManager::HOOK_PLAYER_JOIN) - .Const("PlayerMove", cPluginManager::HOOK_PLAYER_MOVE) - .Const("TakeDamage", cPluginManager::HOOK_TAKE_DAMAGE) - .Const("Killed", cPluginManager::HOOK_KILLED) - .Const("ChunkGenerated", cPluginManager::HOOK_CHUNK_GENERATED) - .Const("ChunkGenerating", cPluginManager::HOOK_CHUNK_GENERATING) - .Const("BlockToDrops", cPluginManager::HOOK_BLOCK_TO_DROPS) - .Const("PreCrafting", cPluginManager::HOOK_PRE_CRAFTING) - .Const("CraftingNoRecipe", cPluginManager::HOOK_CRAFTING_NO_RECIPE) - .Const("PostCrafting", cPluginManager::HOOK_POST_CRAFTING) - .Const("BlockToPickup", cPluginManager::HOOK_BLOCK_TO_PICKUP) - .Const("WeatherChanged", cPluginManager::HOOK_WEATHER_CHANGED) - .Const("UpdatingSign", cPluginManager::HOOK_UPDATING_SIGN) - .Const("UpdatedSign", cPluginManager::HOOK_UPDATED_SIGN)); -} - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelBindings.h b/source/squirrelbindings/SquirrelBindings.h deleted file mode 100644 index dd2affda0..000000000 --- a/source/squirrelbindings/SquirrelBindings.h +++ /dev/null @@ -1,32 +0,0 @@ - -#pragma once - - - - - -#ifdef USE_SQUIRREL - - - - - -#include <squirrel.h> -#include <sqrat.h> - - - - - -void BindSquirrel(HSQUIRRELVM vm); - - - - - -#endif // USE_SQUIRREL - - - - - diff --git a/source/squirrelbindings/SquirrelFunctions.cpp b/source/squirrelbindings/SquirrelFunctions.cpp deleted file mode 100644 index 9407670d4..000000000 --- a/source/squirrelbindings/SquirrelFunctions.cpp +++ /dev/null @@ -1,94 +0,0 @@ - -#include "Globals.h" - - - - - -#ifdef USE_SQUIRREL - - - - - -#include "SquirrelFunctions.h" -#include "SquirrelBindings.h" - - - - - -static HSQUIRRELVM squirrelvm = NULL; - - - - - -SQInteger runtimeErrorHandler(HSQUIRRELVM a_VM) -{ - const SQChar *sErr = 0; - if(sq_gettop(a_VM) >= 1) - { - if(SQ_SUCCEEDED(sq_getstring(a_VM, 2, &sErr))) - { - LOGERROR("Squirrel Error: %s", sErr); - } - else - { - LOGERROR("Squirrel Error: Unknown Error"); - } - } - return 0; -} - -void compilerErrorHandler(HSQUIRRELVM v, - const SQChar* a_Desc, - const SQChar* a_Source, - SQInteger a_Line, - SQInteger a_Column) -{ - - LOGERROR("Squirrel Error: %s (%d:%d) %s", a_Source, a_Line, a_Column, a_Desc); -} - -HSQUIRRELVM OpenSquirrelVM() -{ - if(!squirrelvm) - { - squirrelvm = sq_open(1024); - Sqrat::DefaultVM::Set(squirrelvm); - - sq_newclosure(squirrelvm, runtimeErrorHandler, 0); - sq_seterrorhandler(squirrelvm); - - sq_setcompilererrorhandler(squirrelvm, compilerErrorHandler); - - BindSquirrel(squirrelvm); - } - return squirrelvm; -} - -void CloseSquirrelVM() -{ - if(squirrelvm) - { - sq_close(squirrelvm); - squirrelvm = NULL; - } -} - - -void sqPrint(SQChar * text) -{ - LOGINFO("%s", text); -} - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelFunctions.h b/source/squirrelbindings/SquirrelFunctions.h deleted file mode 100644 index 272b79c3e..000000000 --- a/source/squirrelbindings/SquirrelFunctions.h +++ /dev/null @@ -1,28 +0,0 @@ - -#pragma once - -#ifdef USE_SQUIRREL - - - - -#include <sqrat.h> - - - - - -HSQUIRRELVM OpenSquirrelVM(); -void CloseSquirrelVM(); - -void sqPrint(SQChar * text); - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelObject.h b/source/squirrelbindings/SquirrelObject.h deleted file mode 100644 index 248a5e02c..000000000 --- a/source/squirrelbindings/SquirrelObject.h +++ /dev/null @@ -1,55 +0,0 @@ - -#pragma once - - - - - -#ifdef USE_SQUIRREL - - - - - -#include <sqrat.h> - - - - - -class SquirrelObject -{ -public: - SquirrelObject(Sqrat::Object a_Obj) - { - m_SquirrelObject = a_Obj; - } - - Sqrat::Function GetFunction(const char *a_MethodName) - { - if(m_SquirrelObject.IsNull()) - return Sqrat::Function(); - - Sqrat::Function method(m_SquirrelObject, a_MethodName); - return method; - } - - bool HasFunction(const char *a_MethodName) - { - return !this->GetFunction(a_MethodName).IsNull(); - } - -protected: - Sqrat::Object m_SquirrelObject; - -}; - - - - - -#endif // USE_SQUIRREL - - - - |