1
0

merged changes from upstream

This commit is contained in:
Tycho Bickerstaff 2013-12-31 16:24:53 +00:00
commit c52a46a5e3
12 changed files with 181 additions and 29 deletions

View File

@ -35,24 +35,29 @@ MARK_AS_ADVANCED(
CMAKE_EXE_LINKER_FLAGS_PROFILE CMAKE_EXE_LINKER_FLAGS_PROFILE
CMAKE_SHARED_LINKER_FLAGS_PROFILE ) CMAKE_SHARED_LINKER_FLAGS_PROFILE )
if(UNIX) # Add the preprocessor macros used for distinguishing between debug and release builds (CMake does this automatically for MSVC):
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DNDEBUG") if (NOT MSVC)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DNDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_DEBUG") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_DEBUG") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
endif() endif()
if(WIN32) if(MSVC)
# Make build use multiple threads under MSVC:
add_flags("/MP") add_flags("/MP")
elseif(APPLE) elseif(APPLE)
#on os x clang adds pthread for us but we need to add it for gcc
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_flags("-pthread") add_flags("-pthread")
endif() endif()
else() else()
# Let gcc / clang know that we're compiling a multi-threaded app:
add_flags("-pthread") add_flags("-pthread")
endif() endif()
if(FORCE_32) # Allow for a forced 32-bit build under 32-bit OS:
if (FORCE_32)
add_flags(-m32) add_flags(-m32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -m32") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -m32")
@ -68,21 +73,21 @@ if(FORCE_32)
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE "${CMAKE_MODULE_LINKER_FLAGS_PROFILE} -m32") set(CMAKE_MODULE_LINKER_FLAGS_PROFILE "${CMAKE_MODULE_LINKER_FLAGS_PROFILE} -m32")
endif() endif()
set(CMAKE_CXX_FLAGS_RELEASE_BAK "${CMAKE_CXX_FLAGS_RELEASE}") # Set lower warnings-level for the libraries:
set(CMAKE_C_FLAGS_RELEASE_BAK "${CMAKE_C_FLAGS_RELEASE}") if (MSVC)
if (UNIX) # Remove /W3 from command line -- cannot just cancel it later with /w like in unix, MSVC produces a D9025 warning (option1 overriden by option2)
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/W3" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/W3" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -w") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -w")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -w") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -w")
else() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -w")
#remove /W3 from command line -- cannot just cancel it later with /w like in unix because of D9025 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -w")
#only remove frome relase as we force release
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/W3" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
endif() endif()
set(CMAKE_BUILD_TYPE_BAK ${CMAKE_BUILD_TYPE}) # Under clang, we need to disable ASM support in CryptoPP:
set(CMAKE_BUILD_TYPE "Release")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_definitions(-DCRYPTOPP_DISABLE_ASM) add_definitions(-DCRYPTOPP_DISABLE_ASM)
endif() endif()
@ -95,6 +100,7 @@ endif()
# The Expat library is linked in statically, make the source files aware of that: # The Expat library is linked in statically, make the source files aware of that:
add_definitions(-DXML_STATIC) add_definitions(-DXML_STATIC)
# Include all the libraries:
add_subdirectory(lib/inifile/) add_subdirectory(lib/inifile/)
add_subdirectory(lib/jsoncpp/) add_subdirectory(lib/jsoncpp/)
add_subdirectory(lib/cryptopp/) add_subdirectory(lib/cryptopp/)
@ -106,16 +112,12 @@ add_subdirectory(lib/expat/)
add_subdirectory(lib/luaexpat/) add_subdirectory(lib/luaexpat/)
add_subdirectory(lib/md5/) add_subdirectory(lib/md5/)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_BAK}") # Re-add the maximum warning level:
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_BAK}") # We do not do that for MSVC since MSVC produces an awful lot of warnings for its own STL headers;
# the important warnings will be turned on using #pragma in Globals.h
#TODo: set -Wall -Werror -Wextra if (NOT MSVC)
if(UNIX)
add_flags("-Wall -Wextra") add_flags("-Wall -Wextra")
else()
add_flags("/Wall")
endif() endif()
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE_BAK}")
add_subdirectory (src) add_subdirectory (src)

View File

@ -0,0 +1,20 @@
return
{
HOOK_PLAYER_FISHED =
{
CalledWhen = "A player gets a reward from fishing.",
DefaultFnName = "OnPlayerFished", -- also used as pagename
Desc = [[
This hook gets called after a player reels in the fishing rod. This is a notification-only hook, the reward has already been decided. If a plugin needs to modify the reward, use the {{OnPlayerFishing|HOOK_PLAYER_FISHING}} hook.
]],
Params =
{
{ Name = "Player", Type = "{{cPlayer}}", Notes = "The player who pulled the fish in." },
{ Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, treasure and junk." },
},
Returns = [[
If the function returns false or no value, the next plugin's callback is called. If the function returns true, no other
callback is called for this event.
]],
}, -- HOOK_PLAYER_FISHED
};

View File

@ -0,0 +1,21 @@
return
{
HOOK_PLAYER_FISHING =
{
CalledWhen = "A player is about to get a reward from fishing.",
DefaultFnName = "OnPlayerFishing", -- also used as pagename
Desc = [[
This hook gets called when a player right clicks with a fishing rod while the floater is under water. The reward is already descided, but the plugin may change it.
]],
Params =
{
{ Name = "Player", Type = "{{cPlayer}}", Notes = "The player who pulled the fish in." },
{ Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, treasure and junk." },
},
Returns = [[
If the function returns false or no value, the next plugin's callback is called. Afterwards, the
server gives the player his reward. If the function returns true, no other
callback is called for this event and the player doesn't get his reward.
]],
}, -- HOOK_PLAYER_FISHING
};

View File

@ -468,6 +468,18 @@ void cLuaState::Push(cItems * a_Items)
void cLuaState::Push(const cItems & a_Items)
{
ASSERT(IsValid());
tolua_pushusertype(m_LuaState, (void *)&a_Items, "cItems");
m_NumCurrentFunctionArgs += 1;
}
void cLuaState::Push(cClientHandle * a_Client) void cLuaState::Push(cClientHandle * a_Client)
{ {
ASSERT(IsValid()); ASSERT(IsValid());

View File

@ -165,6 +165,7 @@ public:
void Push(cMonster * a_Monster); void Push(cMonster * a_Monster);
void Push(cItem * a_Item); void Push(cItem * a_Item);
void Push(cItems * a_Items); void Push(cItems * a_Items);
void Push(const cItems & a_Items);
void Push(cClientHandle * a_ClientHandle); void Push(cClientHandle * a_ClientHandle);
void Push(cPickup * a_Pickup); void Push(cPickup * a_Pickup);
void Push(cChunkDesc * a_ChunkDesc); void Push(cChunkDesc * a_ChunkDesc);

View File

@ -68,6 +68,8 @@ public:
virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual bool OnPlayerEating (cPlayer & a_Player) = 0; virtual bool OnPlayerEating (cPlayer & a_Player) = 0;
virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) = 0;
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 0;
virtual bool OnPlayerJoined (cPlayer & a_Player) = 0; virtual bool OnPlayerJoined (cPlayer & a_Player) = 0;
virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0;
virtual bool OnPlayerMoved (cPlayer & a_Player) = 0; virtual bool OnPlayerMoved (cPlayer & a_Player) = 0;

View File

@ -630,6 +630,46 @@ bool cPluginLua::OnPlayerEating(cPlayer & a_Player)
bool cPluginLua::OnPlayerFished(cPlayer & a_Player, const cItems & a_Reward)
{
cCSLock Lock(m_CriticalSection);
bool res = false;
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHED];
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
{
m_LuaState.Call((int)(**itr), &a_Player, a_Reward, cLuaState::Return, res);
if (res)
{
return true;
}
}
return false;
}
bool cPluginLua::OnPlayerFishing(cPlayer & a_Player, cItems & a_Reward)
{
cCSLock Lock(m_CriticalSection);
bool res = false;
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHING];
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
{
m_LuaState.Call((int)(**itr), &a_Player, a_Reward, cLuaState::Return, res);
if (res)
{
return true;
}
}
return false;
}
bool cPluginLua::OnPlayerJoined(cPlayer & a_Player) bool cPluginLua::OnPlayerJoined(cPlayer & a_Player)
{ {
cCSLock Lock(m_CriticalSection); cCSLock Lock(m_CriticalSection);

View File

@ -65,6 +65,8 @@ public:
virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual bool OnPlayerEating (cPlayer & a_Player) override; virtual bool OnPlayerEating (cPlayer & a_Player) override;
virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) override;
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override;
virtual bool OnPlayerJoined (cPlayer & a_Player) override; virtual bool OnPlayerJoined (cPlayer & a_Player) override;
virtual bool OnPlayerMoved (cPlayer & a_Player) override; virtual bool OnPlayerMoved (cPlayer & a_Player) override;
virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override;

View File

@ -694,6 +694,48 @@ bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player)
bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, const cItems a_Reward)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHED);
if (Plugins == m_Hooks.end())
{
return false;
}
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnPlayerFished(a_Player, a_Reward))
{
return true;
}
}
return false;
}
bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, cItems a_Reward)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHING);
if (Plugins == m_Hooks.end())
{
return false;
}
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnPlayerFishing(a_Player, a_Reward))
{
return true;
}
}
return false;
}
bool cPluginManager::CallHookPlayerJoined(cPlayer & a_Player) bool cPluginManager::CallHookPlayerJoined(cPlayer & a_Player)
{ {
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_JOINED); HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_JOINED);

View File

@ -80,6 +80,8 @@ public: // tolua_export
HOOK_PLAYER_BREAKING_BLOCK, HOOK_PLAYER_BREAKING_BLOCK,
HOOK_PLAYER_BROKEN_BLOCK, HOOK_PLAYER_BROKEN_BLOCK,
HOOK_PLAYER_EATING, HOOK_PLAYER_EATING,
HOOK_PLAYER_FISHED,
HOOK_PLAYER_FISHING,
HOOK_PLAYER_JOINED, HOOK_PLAYER_JOINED,
HOOK_PLAYER_LEFT_CLICK, HOOK_PLAYER_LEFT_CLICK,
HOOK_PLAYER_MOVING, HOOK_PLAYER_MOVING,
@ -168,6 +170,8 @@ public: // tolua_export
bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
bool CallHookPlayerEating (cPlayer & a_Player); bool CallHookPlayerEating (cPlayer & a_Player);
bool CallHookPlayerFished (cPlayer & a_Player, const cItems a_Reward);
bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward);
bool CallHookPlayerJoined (cPlayer & a_Player); bool CallHookPlayerJoined (cPlayer & a_Player);
bool CallHookPlayerMoving (cPlayer & a_Player); bool CallHookPlayerMoving (cPlayer & a_Player);
bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);

View File

@ -9,9 +9,11 @@
#pragma once #pragma once
#include "../Bindings/PluginManager.h"
#include "../Entities/Floater.h" #include "../Entities/Floater.h"
#include "../Entities/Entity.h" #include "../Entities/Entity.h"
#include "../Item.h" #include "../Item.h"
#include "../Root.h"
@ -210,10 +212,14 @@ public:
} }
} }
if (cRoot::Get()->GetPluginManager()->CallHookPlayerFishing(*a_Player, Drops))
{
return true;
}
Vector3d FloaterPos = FloaterInfo.GetPos(); Vector3d FloaterPos = FloaterInfo.GetPos();
Vector3d FlyDirection = a_Player->GetEyePosition() - FloaterPos; Vector3d FlyDirection = a_Player->GetEyePosition() - FloaterPos;
a_World->SpawnItemPickups(Drops, FloaterPos.x, FloaterPos.y, FloaterPos.z, FlyDirection.x, FlyDirection.y + 1, FlyDirection.z); a_World->SpawnItemPickups(Drops, FloaterPos.x, FloaterPos.y, FloaterPos.z, FlyDirection.x, FlyDirection.y + 1, FlyDirection.z);
cRoot::Get()->GetPluginManager()->CallHookPlayerFished(*a_Player, Drops);
} }
} }
else else

View File

@ -701,9 +701,9 @@ int cRoot::GetPhysicalRAMUsage(void)
{ {
AString Line; AString Line;
std::getline(StatFile, Line); std::getline(StatFile, Line);
if (strncmp(Line.c_str(), "VmRSS:", 7) == 0) if (strncmp(Line.c_str(), "VmRSS:", 6) == 0)
{ {
int res = atoi(Line.c_str() + 8); int res = atoi(Line.c_str() + 7);
return (res == 0) ? -1 : res; // If parsing failed, return -1 return (res == 0) ? -1 : res; // If parsing failed, return -1
} }
} }