diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Bindings/LuaFunctions.h | 2 | ||||
-rw-r--r-- | src/Bindings/LuaState.cpp | 66 | ||||
-rw-r--r-- | src/Bindings/LuaState.h | 4 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_World.cpp | 162 | ||||
-rw-r--r-- | src/Bindings/PluginLua.cpp | 48 | ||||
-rw-r--r-- | src/BlockID.h | 24 | ||||
-rw-r--r-- | src/Blocks/BlockFarmland.h | 8 | ||||
-rwxr-xr-x | src/CheckBasicStyle.lua | 64 | ||||
-rw-r--r-- | src/Generating/IntGen.h | 16 | ||||
-rw-r--r-- | src/Noise/Noise.h | 33 | ||||
-rw-r--r-- | src/OSSupport/IsThread.cpp | 6 | ||||
-rw-r--r-- | src/OSSupport/IsThread.h | 3 | ||||
-rw-r--r-- | src/OSSupport/StackTrace.cpp | 6 | ||||
-rw-r--r-- | src/Protocol/MojangAPI.cpp | 50 | ||||
-rw-r--r-- | src/Root.cpp | 8 | ||||
-rw-r--r-- | src/StringUtils.cpp | 22 | ||||
-rw-r--r-- | src/World.h | 19 | ||||
-rw-r--r-- | src/WorldStorage/FastNBT.cpp | 10 |
18 files changed, 313 insertions, 238 deletions
diff --git a/src/Bindings/LuaFunctions.h b/src/Bindings/LuaFunctions.h index 929794893..98341a131 100644 --- a/src/Bindings/LuaFunctions.h +++ b/src/Bindings/LuaFunctions.h @@ -7,7 +7,7 @@ inline unsigned int GetTime() { - // NB: For caveats, please see http://stackoverflow.com/a/14505248 + // NB: For caveats, please see https://stackoverflow.com/a/14505248 return static_cast<unsigned int>(std::chrono::seconds(time(0)).count()); } diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index f5b2cac4a..953b6f17b 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -807,25 +807,6 @@ void cLuaState::Push(UInt32 a_Value) -void cLuaState::Push(void * a_Ptr) -{ - UNUSED(a_Ptr); - ASSERT(IsValid()); - - // Investigate the cause of this - what is the callstack? - // One code path leading here is the OnHookExploding / OnHookExploded with exotic parameters. Need to decide what to do with them - LOGWARNING("Lua engine: attempting to push a plain pointer, pushing nil instead."); - LOGWARNING("This indicates an unimplemented part of MCS bindings"); - LogStackTrace(); - - lua_pushnil(m_LuaState); - m_NumCurrentFunctionArgs += 1; -} - - - - - void cLuaState::Push(std::chrono::milliseconds a_Value) { ASSERT(IsValid()); @@ -838,20 +819,6 @@ void cLuaState::Push(std::chrono::milliseconds a_Value) -/* -void cLuaState::PushUserType(void * a_Object, const char * a_Type) -{ - ASSERT(IsValid()); - - tolua_pushusertype(m_LuaState, a_Object, a_Type); - m_NumCurrentFunctionArgs += 1; -} -*/ - - - - - bool cLuaState::GetStackValue(int a_StackPos, AString & a_Value) { size_t len = 0; @@ -1197,6 +1164,39 @@ bool cLuaState::CheckParamNumber(int a_StartParam, int a_EndParam) +bool cLuaState::CheckParamBool(int a_StartParam, int a_EndParam) +{ + ASSERT(IsValid()); + + if (a_EndParam < 0) + { + a_EndParam = a_StartParam; + } + + tolua_Error tolua_err; + for (int i = a_StartParam; i <= a_EndParam; i++) + { + if (tolua_isboolean(m_LuaState, i, 0, &tolua_err)) + { + continue; + } + // Not the correct parameter + lua_Debug entry; + VERIFY(lua_getstack(m_LuaState, 0, &entry)); + VERIFY(lua_getinfo (m_LuaState, "n", &entry)); + AString ErrMsg = Printf("#ferror in function '%s'.", (entry.name != nullptr) ? entry.name : "?"); + tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); + return false; + } // for i - Param + + // All params checked ok + return true; +} + + + + + bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam) { ASSERT(IsValid()); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 6b600e150..f66605332 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -259,7 +259,6 @@ public: void Push(int a_Value); void Push(long a_Value); void Push(const UInt32 a_Value); - void Push(void * a_Ptr); void Push(std::chrono::milliseconds a_time); // GetStackValue() retrieves the value at a_StackPos, if it is a valid type. If not, a_Value is unchanged. @@ -375,6 +374,9 @@ public: /** Returns true if the specified parameters on the stack are numbers; also logs warning if not */ bool CheckParamNumber(int a_StartParam, int a_EndParam = -1); + /** Returns true if the specified parameters on the stack are bools; also logs warning if not */ + bool CheckParamBool(int a_StartParam, int a_EndParam = -1); + /** Returns true if the specified parameters on the stack are strings; also logs warning if not */ bool CheckParamString(int a_StartParam, int a_EndParam = -1); diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp index 20fe880c1..225e71af5 100644 --- a/src/Bindings/ManualBindings_World.cpp +++ b/src/Bindings/ManualBindings_World.cpp @@ -110,6 +110,99 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) + +static int tolua_cWorld_DoExplosionAt(lua_State * tolua_S) +{ + /* Function signature: + World:DoExplosionAt(ExplosionSize, BlockX, BlockY, BlockZ, CanCauseFire, SourceType, [SourceData]) + */ + + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType (1, "cWorld") || + !L.CheckParamNumber (2, 5) || + !L.CheckParamBool (6) || + !L.CheckParamNumber (7) || + !L.CheckParamEnd (9) + ) + { + return 0; + } + + // Read the params: + cWorld * World; + double ExplosionSize; + int BlockX, BlockY, BlockZ; + bool CanCauseFire; + int SourceTypeInt; + if (!L.GetStackValues(1, World, ExplosionSize, BlockX, BlockY, BlockZ, CanCauseFire, SourceTypeInt)) + { + LOGWARNING("World:DoExplosionAt(): invalid parameters"); + L.LogStackTrace(); + return 0; + } + if ((SourceTypeInt < 0) || (SourceTypeInt >= esMax)) + { + LOGWARNING("World:DoExplosionAt(): Invalid source type"); + L.LogStackTrace(); + return 0; + } + eExplosionSource SourceType; + void * SourceData; + switch (SourceTypeInt) + { + case esBed: + { + // esBed receives a Vector3i SourceData param: + Vector3i * pos = nullptr; + L.GetStackValue(8, pos); + SourceType = esBed; + SourceData = pos; + break; + } + + case esEnderCrystal: + case esGhastFireball: + case esMonster: + case esPrimedTNT: + case esWitherBirth: + case esWitherSkull: + { + // These all receive a cEntity descendant SourceData param: + cEntity * ent = nullptr; + L.GetStackValue(8, ent); + SourceType = static_cast<eExplosionSource>(SourceTypeInt); + SourceData = ent; + break; + } + + case esOther: + case esPlugin: + { + // esOther and esPlugin ignore their SourceData params + SourceType = static_cast<eExplosionSource>(SourceTypeInt); + SourceData = nullptr; + break; + } + + default: + { + LOGWARNING("cWorld:DoExplosionAt(): invalid SourceType parameter: %d", SourceTypeInt); + L.LogStackTrace(); + return 0; + } + } + + // Create the actual explosion: + World->DoExplosionAt(ExplosionSize, BlockX, BlockY, BlockZ, CanCauseFire, SourceType, SourceData); + + return 0; +} + + + + + static int tolua_cWorld_ForEachLoadedChunk(lua_State * tolua_S) { // Exported manually, because tolua doesn't support converting functions to functor types. @@ -576,41 +669,42 @@ void cManualBindings::BindWorld(lua_State * tolua_S) { tolua_beginmodule(tolua_S, nullptr); tolua_beginmodule(tolua_S, "cWorld"); - tolua_function(tolua_S, "BroadcastParticleEffect", tolua_cWorld_BroadcastParticleEffect); - tolua_function(tolua_S, "ChunkStay", tolua_cWorld_ChunkStay); - tolua_function(tolua_S, "DoWithBlockEntityAt", DoWithXYZ<cWorld, cBlockEntity, &cWorld::DoWithBlockEntityAt>); - tolua_function(tolua_S, "DoWithBeaconAt", DoWithXYZ<cWorld, cBeaconEntity, &cWorld::DoWithBeaconAt>); - tolua_function(tolua_S, "DoWithBrewingstandAt", DoWithXYZ<cWorld, cBrewingstandEntity, &cWorld::DoWithBrewingstandAt>); - tolua_function(tolua_S, "DoWithChestAt", DoWithXYZ<cWorld, cChestEntity, &cWorld::DoWithChestAt>); - tolua_function(tolua_S, "DoWithDispenserAt", DoWithXYZ<cWorld, cDispenserEntity, &cWorld::DoWithDispenserAt>); - tolua_function(tolua_S, "DoWithDropSpenserAt", DoWithXYZ<cWorld, cDropSpenserEntity, &cWorld::DoWithDropSpenserAt>); - tolua_function(tolua_S, "DoWithDropperAt", DoWithXYZ<cWorld, cDropperEntity, &cWorld::DoWithDropperAt>); - tolua_function(tolua_S, "DoWithEntityByID", DoWithID< cWorld, cEntity, &cWorld::DoWithEntityByID>); - tolua_function(tolua_S, "DoWithFurnaceAt", DoWithXYZ<cWorld, cFurnaceEntity, &cWorld::DoWithFurnaceAt>); - tolua_function(tolua_S, "DoWithNoteBlockAt", DoWithXYZ<cWorld, cNoteEntity, &cWorld::DoWithNoteBlockAt>); - tolua_function(tolua_S, "DoWithCommandBlockAt", DoWithXYZ<cWorld, cCommandBlockEntity, &cWorld::DoWithCommandBlockAt>); - tolua_function(tolua_S, "DoWithMobHeadAt", DoWithXYZ<cWorld, cMobHeadEntity, &cWorld::DoWithMobHeadAt>); - tolua_function(tolua_S, "DoWithFlowerPotAt", DoWithXYZ<cWorld, cFlowerPotEntity, &cWorld::DoWithFlowerPotAt>); - tolua_function(tolua_S, "DoWithPlayer", DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); - tolua_function(tolua_S, "FindAndDoWithPlayer", DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); - tolua_function(tolua_S, "DoWithPlayerByUUID", DoWith< cWorld, cPlayer, &cWorld::DoWithPlayerByUUID>); - tolua_function(tolua_S, "ForEachBlockEntityInChunk", ForEachInChunk<cWorld, cBlockEntity, &cWorld::ForEachBlockEntityInChunk>); + tolua_function(tolua_S, "BroadcastParticleEffect", tolua_cWorld_BroadcastParticleEffect); + tolua_function(tolua_S, "ChunkStay", tolua_cWorld_ChunkStay); + tolua_function(tolua_S, "DoExplosionAt", tolua_cWorld_DoExplosionAt); + tolua_function(tolua_S, "DoWithBeaconAt", DoWithXYZ<cWorld, cBeaconEntity, &cWorld::DoWithBeaconAt>); + tolua_function(tolua_S, "DoWithBlockEntityAt", DoWithXYZ<cWorld, cBlockEntity, &cWorld::DoWithBlockEntityAt>); + tolua_function(tolua_S, "DoWithBrewingstandAt", DoWithXYZ<cWorld, cBrewingstandEntity, &cWorld::DoWithBrewingstandAt>); + tolua_function(tolua_S, "DoWithChestAt", DoWithXYZ<cWorld, cChestEntity, &cWorld::DoWithChestAt>); + tolua_function(tolua_S, "DoWithCommandBlockAt", DoWithXYZ<cWorld, cCommandBlockEntity, &cWorld::DoWithCommandBlockAt>); + tolua_function(tolua_S, "DoWithDispenserAt", DoWithXYZ<cWorld, cDispenserEntity, &cWorld::DoWithDispenserAt>); + tolua_function(tolua_S, "DoWithDropSpenserAt", DoWithXYZ<cWorld, cDropSpenserEntity, &cWorld::DoWithDropSpenserAt>); + tolua_function(tolua_S, "DoWithDropperAt", DoWithXYZ<cWorld, cDropperEntity, &cWorld::DoWithDropperAt>); + tolua_function(tolua_S, "DoWithEntityByID", DoWithID< cWorld, cEntity, &cWorld::DoWithEntityByID>); + tolua_function(tolua_S, "DoWithFlowerPotAt", DoWithXYZ<cWorld, cFlowerPotEntity, &cWorld::DoWithFlowerPotAt>); + tolua_function(tolua_S, "DoWithFurnaceAt", DoWithXYZ<cWorld, cFurnaceEntity, &cWorld::DoWithFurnaceAt>); + tolua_function(tolua_S, "DoWithMobHeadAt", DoWithXYZ<cWorld, cMobHeadEntity, &cWorld::DoWithMobHeadAt>); + tolua_function(tolua_S, "DoWithNoteBlockAt", DoWithXYZ<cWorld, cNoteEntity, &cWorld::DoWithNoteBlockAt>); + tolua_function(tolua_S, "DoWithPlayer", DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); + tolua_function(tolua_S, "DoWithPlayerByUUID", DoWith< cWorld, cPlayer, &cWorld::DoWithPlayerByUUID>); + tolua_function(tolua_S, "FindAndDoWithPlayer", DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); + tolua_function(tolua_S, "ForEachBlockEntityInChunk", ForEachInChunk<cWorld, cBlockEntity, &cWorld::ForEachBlockEntityInChunk>); tolua_function(tolua_S, "ForEachBrewingstandInChunk", ForEachInChunk<cWorld, cBrewingstandEntity, &cWorld::ForEachBrewingstandInChunk>); - tolua_function(tolua_S, "ForEachChestInChunk", ForEachInChunk<cWorld, cChestEntity, &cWorld::ForEachChestInChunk>); - tolua_function(tolua_S, "ForEachEntity", ForEach< cWorld, cEntity, &cWorld::ForEachEntity>); - tolua_function(tolua_S, "ForEachEntityInBox", ForEachInBox< cWorld, cEntity, &cWorld::ForEachEntityInBox>); - tolua_function(tolua_S, "ForEachEntityInChunk", ForEachInChunk<cWorld, cEntity, &cWorld::ForEachEntityInChunk>); - tolua_function(tolua_S, "ForEachFurnaceInChunk", ForEachInChunk<cWorld, cFurnaceEntity, &cWorld::ForEachFurnaceInChunk>); - tolua_function(tolua_S, "ForEachPlayer", ForEach< cWorld, cPlayer, &cWorld::ForEachPlayer>); - tolua_function(tolua_S, "ForEachLoadedChunk", tolua_cWorld_ForEachLoadedChunk); - tolua_function(tolua_S, "GetBlockInfo", tolua_cWorld_GetBlockInfo); - tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cWorld_GetBlockTypeMeta); - tolua_function(tolua_S, "GetSignLines", tolua_cWorld_GetSignLines); - tolua_function(tolua_S, "PrepareChunk", tolua_cWorld_PrepareChunk); - tolua_function(tolua_S, "QueueTask", tolua_cWorld_QueueTask); - tolua_function(tolua_S, "ScheduleTask", tolua_cWorld_ScheduleTask); - tolua_function(tolua_S, "SetSignLines", tolua_cWorld_SetSignLines); - tolua_function(tolua_S, "TryGetHeight", tolua_cWorld_TryGetHeight); + tolua_function(tolua_S, "ForEachChestInChunk", ForEachInChunk<cWorld, cChestEntity, &cWorld::ForEachChestInChunk>); + tolua_function(tolua_S, "ForEachEntity", ForEach< cWorld, cEntity, &cWorld::ForEachEntity>); + tolua_function(tolua_S, "ForEachEntityInBox", ForEachInBox< cWorld, cEntity, &cWorld::ForEachEntityInBox>); + tolua_function(tolua_S, "ForEachEntityInChunk", ForEachInChunk<cWorld, cEntity, &cWorld::ForEachEntityInChunk>); + tolua_function(tolua_S, "ForEachFurnaceInChunk", ForEachInChunk<cWorld, cFurnaceEntity, &cWorld::ForEachFurnaceInChunk>); + tolua_function(tolua_S, "ForEachLoadedChunk", tolua_cWorld_ForEachLoadedChunk); + tolua_function(tolua_S, "ForEachPlayer", ForEach< cWorld, cPlayer, &cWorld::ForEachPlayer>); + tolua_function(tolua_S, "GetBlockInfo", tolua_cWorld_GetBlockInfo); + tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cWorld_GetBlockTypeMeta); + tolua_function(tolua_S, "GetSignLines", tolua_cWorld_GetSignLines); + tolua_function(tolua_S, "PrepareChunk", tolua_cWorld_PrepareChunk); + tolua_function(tolua_S, "QueueTask", tolua_cWorld_QueueTask); + tolua_function(tolua_S, "ScheduleTask", tolua_cWorld_ScheduleTask); + tolua_function(tolua_S, "SetSignLines", tolua_cWorld_SetSignLines); + tolua_function(tolua_S, "TryGetHeight", tolua_cWorld_TryGetHeight); tolua_endmodule(tolua_S); tolua_endmodule(tolua_S); } diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 3038264d2..1b7a18ff1 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -667,16 +667,20 @@ bool cPluginLua::OnExploded(cWorld & a_World, double a_ExplosionSize, bool a_Can { switch (a_Source) { - case esOther: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break; - case esPrimedTNT: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cTNTEntity *>(a_SourceData), cLuaState::Return, res); break; - case esMonster: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cMonster *>(a_SourceData), cLuaState::Return, res); break; - case esBed: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<Vector3i *>(a_SourceData), cLuaState::Return, res); break; - case esEnderCrystal: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<Vector3i *>(a_SourceData), cLuaState::Return, res); break; - case esGhastFireball: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break; - case esWitherSkullBlack: - case esWitherSkullBlue: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break; - case esWitherBirth: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break; - case esPlugin: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break; + case esBed: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<Vector3i *> (a_SourceData), cLuaState::Return, res); break; + case esEnderCrystal: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cEntity *> (a_SourceData), cLuaState::Return, res); break; + case esGhastFireball: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cGhastFireballEntity *>(a_SourceData), cLuaState::Return, res); break; + case esMonster: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cMonster *> (a_SourceData), cLuaState::Return, res); break; + case esOther: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, cLuaState::Return, res); break; + case esPlugin: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, cLuaState::Return, res); break; + case esPrimedTNT: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cTNTEntity *> (a_SourceData), cLuaState::Return, res); break; + case esWitherBirth: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cMonster *> (a_SourceData), cLuaState::Return, res); break; + case esWitherSkull: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cWitherSkullEntity *> (a_SourceData), cLuaState::Return, res); break; + case esMax: + { + ASSERT(!"Invalid explosion source"); + return false; + } } if (res) { @@ -703,16 +707,20 @@ bool cPluginLua::OnExploding(cWorld & a_World, double & a_ExplosionSize, bool & { switch (a_Source) { - case esOther: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - case esPrimedTNT: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cTNTEntity *>(a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - case esMonster: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cMonster *>(a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - case esBed: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<Vector3i *>(a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - case esEnderCrystal: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<Vector3i *>(a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - case esGhastFireball: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - case esWitherSkullBlack: - case esWitherSkullBlue: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - case esWitherBirth: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - case esPlugin: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esBed: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<Vector3i *> (a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esEnderCrystal: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cEntity *> (a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esGhastFireball: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cGhastFireballEntity *>(a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esMonster: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cMonster *> (a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esOther: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esPlugin: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esPrimedTNT: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cTNTEntity *> (a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esWitherBirth: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cMonster *> (a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esWitherSkull: m_LuaState.Call(static_cast<int>(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, reinterpret_cast<cWitherSkullEntity *> (a_SourceData), cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; + case esMax: + { + ASSERT(!"Invalid explosion source"); + return false; + } } if (res) { diff --git a/src/BlockID.h b/src/BlockID.h index 98c296249..1a43d4b64 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -1051,18 +1051,30 @@ enum eDamageType +/** The source of an explosion. +Also dictates the type of the additional data passed to the explosion handlers: +| esBed | Vector3i * | Bed exploding in the Nether or in the End +| esEnderCrystal | cEnderCrystal * | +| esGhastFireball | cGhastFireballEntity * | +| esMonster | cMonster * | +| esOther | nullptr | Any other explosion unaccounted for +| esPlugin | nullptr | Explosion primarily attributed to a plugin +| esPrimedTNT | cTNTEntity * | +| esWitherBirth | cMonster * | +| esWitherSkull | cProjectileEntity * | +*/ enum eExplosionSource { - esOther, - esPrimedTNT, - esMonster, esBed, esEnderCrystal, esGhastFireball, - esWitherSkullBlack, - esWitherSkullBlue, - esWitherBirth, + esMonster, + esOther, esPlugin, + esPrimedTNT, + esWitherBirth, + esWitherSkull, + esMax, } ; diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h index e6c7f16f6..412eb1d2c 100644 --- a/src/Blocks/BlockFarmland.h +++ b/src/Blocks/BlockFarmland.h @@ -19,7 +19,7 @@ class cBlockFarmlandHandler : public cBlockHandler { - + public: cBlockFarmlandHandler(BLOCKTYPE a_BlockType) : cBlockHandler(a_BlockType) @@ -104,7 +104,7 @@ public: } // Search for water in a close proximity: - // Ref.: http://www.minecraftwiki.net/wiki/Farmland#Hydrated_Farmland_Tiles + // Ref.: http://minecraft.gamepedia.com/Farmland#Hydrated_Farmland_Tiles // TODO: Rewrite this to use the chunk and its neighbors directly cBlockArea Area; int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width; @@ -139,7 +139,3 @@ public: ); } } ; - - - - diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua index a3d21106a..3f0d2bd45 100755 --- a/src/CheckBasicStyle.lua +++ b/src/CheckBasicStyle.lua @@ -16,10 +16,10 @@ Checks that all source files (*.cpp, *.h) use the basic style requirements of th - (TODO) Hex numbers with even digit length - (TODO) Hex numbers in lowercase - (TODO) Not using "* "-style doxy comment continuation lines - + Violations that cannot be checked easily: - Spaces around "+" (there are things like "a++", "++a", "a += 1", "X+", "stack +1" and ascii-drawn tables) - + Reports all violations on stdout in a form that is readable by Visual Studio's parser, so that dblclicking the line brings the editor directly to the violation. @@ -114,38 +114,38 @@ local g_ViolationPatterns = -- Check against indenting using spaces: {"^\t* +", "Indenting with a space"}, - + -- Check against alignment using tabs: {"[^%s]\t+[^%s]", "Aligning with a tab"}, - + -- Check against trailing whitespace: {"[^%s]%s+\n", "Trailing whitespace"}, - + -- Check that all "//"-style comments have at least two spaces in front (unless alone on line): {"[^%s] //", "Needs at least two spaces in front of a \"//\"-style comment"}, - + -- Check that all "//"-style comments have at least one spaces after: {"%s//[^%s/*<]", "Needs a space after a \"//\"-style comment"}, - + -- Check that doxy-comments are used only in the double-asterisk form: {"/// ", "Use doxycomments in the form /** Comment */"}, - + -- Check that /* */ comments have whitespace around the insides: {"%*%*/", "Wrong comment termination, use */"}, {"/%*[^%s*/\"]", "Needs a space after /*"}, -- Need to take care of the special "//*/" comment ends {"/%*%*[^%s*<]", "Needs a space after /**"}, {"[^%s/*]%*/", "Needs a space before */"}, - + -- Check against MS XML doxycomments: {"/%*%* <", "Remove the MS XML markers from comment"}, -- Check that all commas have spaces after them and not in front of them: {" ,", "Extra space before a \",\""}, {",[^%s\"%%\']", "Needs a space after a \",\""}, -- Report all except >> "," << needed for splitting and >>,%s<< needed for formatting - + -- Check that opening braces are not at the end of a code line: {"[^%s].-{\n?$", "Brace should be on a separate line"}, - + -- Space after keywords: {"[^_]if%(", "Needs a space after \"if\""}, {"%sfor%(", "Needs a space after \"for\""}, @@ -153,16 +153,16 @@ local g_ViolationPatterns = {"%sswitch%(", "Needs a space after \"switch\""}, {"%scatch%(", "Needs a space after \"catch\""}, {"%stemplate<", "Needs a space after \"template\""}, - + -- No space after keyword's parenthesis: {"[^%a#]if %( ", "Remove the space after \"(\""}, {"for %( ", "Remove the space after \"(\""}, {"while %( ", "Remove the space after \"(\""}, {"catch %( ", "Remove the space after \"(\""}, - + -- No space before a closing parenthesis: {" %)", "Remove the space before \")\""}, - + -- Check spaces around "+": {"^[a-zA-Z0-9]+%+[a-zA-Z0-9]+", "Add space around +"}, {"[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%+[a-zA-Z0-9]+", "Add space around +"}, @@ -173,7 +173,7 @@ local g_ViolationPatterns = {"^[a-zA-Z0-9]+%+ [a-zA-Z0-9]+", "Add space before +"}, {"[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%+ [a-zA-Z0-9]+", "Add space before +"}, --]] - + -- Cannot check spaces around "-", because the minus is sometimes used as a hyphen between-words -- Check spaces around "*": @@ -191,7 +191,7 @@ local g_ViolationPatterns = {"^[^\"]*[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%&[a-zA-Z0-9]+", "Add space around &"}, {"^[a-zA-Z0-9]+%& [a-zA-Z0-9]+", "Add space before &"}, {"^[^\"]*[!@#$%%%^&*() %[%]\t][a-zA-Z0-9]+%& [a-zA-Z0-9]+", "Add space before &"}, - + -- Check spaces around "==", "<=" and ">=": {"==[a-zA-Z0-9]+", "Add space after =="}, {"[a-zA-Z0-9]+==", "Add space before =="}, @@ -212,7 +212,7 @@ local g_ViolationPatterns = --- Processes one file local function ProcessFile(a_FileName) assert(type(a_FileName) == "string") - + -- Read the whole file: local f, err = io.open(a_FileName, "r") if (f == nil) then @@ -222,7 +222,7 @@ local function ProcessFile(a_FileName) end local all = f:read("*all") f:close() - + -- Check that the last line is empty - otherwise processing won't work properly: local lastChar = string.byte(all, string.len(all)) if ((lastChar ~= 13) and (lastChar ~= 10)) then @@ -231,9 +231,9 @@ local function ProcessFile(a_FileName) ReportViolation(a_FileName, numLines, 1, 1, "Missing empty line at file end") return end - + -- Process each line separately: - -- Ref.: http://stackoverflow.com/questions/10416869/iterate-over-possibly-empty-lines-in-a-way-that-matches-the-expectations-of-exis + -- Ref.: https://stackoverflow.com/questions/10416869/iterate-over-possibly-empty-lines-in-a-way-that-matches-the-expectations-of-exis local lineCounter = 1 local lastIndentLevel = 0 local isLastLineControl = false @@ -244,7 +244,7 @@ local function ProcessFile(a_FileName) for _, pat in ipairs(g_ViolationPatterns) do ReportViolationIfFound(a_Line, a_FileName, lineCounter, pat[1], pat[2]) end - + -- Check that divider comments are well formed - 80 slashes plus optional indent: local dividerStart, dividerEnd = a_Line:find("/////*") if (dividerStart) then @@ -260,7 +260,7 @@ local function ProcessFile(a_FileName) end end end - + -- Check the indent level change from the last line, if it's too much, report: local indentStart, indentEnd = a_Line:find("\t+") local indentLevel = 0 @@ -273,7 +273,7 @@ local function ProcessFile(a_FileName) end lastIndentLevel = indentLevel end - + -- Check that control statements have braces on separate lines after them: -- Note that if statements can be broken into multiple lines, in which case this test is not taken if (isLastLineControl) then @@ -304,12 +304,12 @@ end --- Processes one item - a file or a folder local function ProcessItem(a_ItemName) assert(type(a_ItemName) == "string") - + -- Skip files / folders that should be ignored if (g_ShouldIgnoreFile[a_ItemName]) then return end - + local ext = a_ItemName:match("%.([^/%.]-)$") if (g_ShouldProcessExt[ext]) then ProcessFile(a_ItemName) @@ -340,7 +340,7 @@ local CmdLineHandlers = table.insert(ToProcess, fnam) return a_Idx + 2 -- skip the filename in param parsing end, - + -- "-g" checks files reported by git as being committed. ["-g"] = function (a_Args, a_Idx) local f = io.popen("git diff --cached --name-only --diff-filter=ACMR") @@ -348,7 +348,7 @@ local CmdLineHandlers = table.insert(ToProcess, fnam) end end, - + -- "-h" prints help and exits ["-h"] = function (a_Args, a_Idx) print([[ @@ -368,7 +368,7 @@ Only .cpp and .h files are ever checked. ]]) os.exit(0) end, - + -- "-l listfile" loads the list of files to check from the specified listfile ["-l"] = function (a_Args, a_Idx) local listFile = a_Args[a_Idx + 1] @@ -380,7 +380,7 @@ Only .cpp and .h files are ever checked. end return a_Idx + 2 -- Skip the listfile in param parsing end, - + -- "--" reads the list of files from stdin ["--"] = function (a_Args, a_Idx) for fnam in io.lines() do @@ -425,7 +425,7 @@ for _, fnam in ipairs(ToProcess) do if (fnam:sub(1, 2) == "./") then fnam = fnam:sub(3) end - + ProcessItem(fnam) end @@ -440,7 +440,3 @@ if (g_NumViolations > 0) then else os.exit(0) end - - - - diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index 3f94ec3d0..708dc0550 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -67,10 +67,10 @@ public: /** Generates the array of templated size into a_Values, based on given min coords. */ virtual void GetInts(int a_MinX, int a_MinZ, Values & a_Values) = 0; - + }; -// Code adapted from http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer +// Code adapted from https://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer template<int... > struct sSeq @@ -92,7 +92,7 @@ struct sGens<0, S...> template<class Gen, class... Args> class cIntGenFactory { - + public: typedef Gen Generator; @@ -101,7 +101,7 @@ public: m_args(std::make_tuple<Args...>(std::forward<Args>(a_args)...)) { } - + template <class LhsGen> std::shared_ptr<Gen> construct(LhsGen&& a_Lhs) { @@ -111,13 +111,13 @@ public: private: std::tuple<Args...> m_args; - + template <class LhsGen, int... S> std::shared_ptr<Gen> construct_impl(LhsGen&& a_Lhs, sSeq<S...>) { return std::make_shared<Gen>(std::get<S>(m_args)..., std::forward<LhsGen>(a_Lhs)); } - + }; template<class T, class RhsGen, class... Args> @@ -1466,7 +1466,3 @@ protected: Underlying m_Underlying; Underlying m_Alteration; }; - - - - diff --git a/src/Noise/Noise.h b/src/Noise/Noise.h index 4c99cee5b..03f61643d 100644 --- a/src/Noise/Noise.h +++ b/src/Noise/Noise.h @@ -68,12 +68,12 @@ class cCubicNoise public: /** Maximum size of each dimension of the query arrays. */ static const int MAX_SIZE = 512; - - + + /** Creates a new instance with the specified seed. */ cCubicNoise(int a_Seed); - - + + /** Fills a 2D array with the values of the noise. */ void Generate2D( NOISE_DATATYPE * a_Array, ///< Array to generate into [x + a_SizeX * y] @@ -81,8 +81,8 @@ public: NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, ///< Noise-space coords of the array in the X direction NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY ///< Noise-space coords of the array in the Y direction ) const; - - + + /** Fills a 3D array with the values of the noise. */ void Generate3D( NOISE_DATATYPE * a_Array, ///< Array to generate into [x + a_SizeX * y + a_SizeX * a_SizeY * z] @@ -91,9 +91,9 @@ public: NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY, ///< Noise-space coords of the array in the Y direction NOISE_DATATYPE a_StartZ, NOISE_DATATYPE a_EndZ ///< Noise-space coords of the array in the Z direction ) const; - + protected: - + /** Noise used for integral random values. */ cNoise m_Noise; @@ -115,8 +115,8 @@ protected: -/** Improved noise, as described by Ken Perlin: http://mrl.nyu.edu/~perlin/paper445.pdf -Implementation adapted from Perlin's Java implementation: http://mrl.nyu.edu/~perlin/noise/ */ +/** Improved noise, as described by Ken Perlin: https://mrl.nyu.edu/~perlin/paper445.pdf +Implementation adapted from Perlin's Java implementation: https://mrl.nyu.edu/~perlin/noise/ */ class cImprovedNoise { public: @@ -132,8 +132,8 @@ public: NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, ///< Noise-space coords of the array in the X direction NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY ///< Noise-space coords of the array in the Y direction ) const; - - + + /** Fills a 3D array with the values of the noise. */ void Generate3D( NOISE_DATATYPE * a_Array, ///< Array to generate into [x + a_SizeX * y + a_SizeX * a_SizeY * z] @@ -324,12 +324,3 @@ inline NOISE_DATATYPE ClampedLerp(NOISE_DATATYPE a_Val1, NOISE_DATATYPE a_Val2, } return Lerp(a_Val1, a_Val2, a_Ratio); } - - - - - - - - - diff --git a/src/OSSupport/IsThread.cpp b/src/OSSupport/IsThread.cpp index e295d5f25..3f75951ba 100644 --- a/src/OSSupport/IsThread.cpp +++ b/src/OSSupport/IsThread.cpp @@ -12,7 +12,7 @@ #if defined(_MSC_VER) && defined(_DEBUG) - // Code adapted from MSDN: http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx + // Code adapted from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx const DWORD MS_VC_EXCEPTION = 0x406D1388; #pragma pack(push, 8) @@ -144,7 +144,3 @@ bool cIsThread::Wait(void) LOGD("Thread %s finished", m_ThreadName.c_str()); return true; } - - - - diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h index fa6813cd7..0c28f5623 100644 --- a/src/OSSupport/IsThread.h +++ b/src/OSSupport/IsThread.h @@ -17,6 +17,7 @@ In the descending class' constructor call the Start() method to start the thread #pragma once #include <thread> +#include <atomic> @@ -30,7 +31,7 @@ protected: virtual void Execute(void) = 0; /** The overriden Execute() method should check this value periodically and terminate if this is true. */ - volatile bool m_ShouldTerminate; + std::atomic<bool> m_ShouldTerminate; public: cIsThread(const AString & a_ThreadName); diff --git a/src/OSSupport/StackTrace.cpp b/src/OSSupport/StackTrace.cpp index 3534bc03d..030566065 100644 --- a/src/OSSupport/StackTrace.cpp +++ b/src/OSSupport/StackTrace.cpp @@ -35,14 +35,10 @@ void PrintStackTrace(void) #else #ifdef __GLIBC__ // Use the backtrace() function to get and output the stackTrace: - // Code adapted from http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes + // Code adapted from https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes void * stackTrace[30]; auto numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace)); backtrace_symbols_fd(stackTrace, numItems, STDERR_FILENO); #endif #endif } - - - - diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp index 9eb8122d3..4747ace72 100644 --- a/src/Protocol/MojangAPI.cpp +++ b/src/Protocol/MojangAPI.cpp @@ -67,7 +67,7 @@ static const AString & GetCACerts(void) // Starfield G2 cert // This is the data of the root certs for Starfield Technologies, the CA that used to sign sessionserver.mojang.com's cert - // Downloaded from http://certs.starfieldtech.com/repository/ + // Downloaded from https://certs.starfieldtech.com/repository/ "-----BEGIN CERTIFICATE-----\n" "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n" "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n" @@ -118,7 +118,7 @@ static const AString & GetCACerts(void) "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n" "-----END CERTIFICATE-----\n" ); - + return Cert; } @@ -152,7 +152,7 @@ cMojangAPI::sProfile::sProfile( } ] */ - + // Parse the Textures and TexturesSignature from the Profile: if (!a_Properties.isArray()) { @@ -272,7 +272,7 @@ AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_U { // Convert the playername to lowercase: AString lcPlayerName = StrToLower(a_PlayerName); - + // Request the cache to query the name if not yet cached: if (!a_UseOnlyCached) { @@ -280,7 +280,7 @@ AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_U PlayerNames.push_back(lcPlayerName); CacheNamesToUUIDs(PlayerNames); } - + // Retrieve from cache: cCSLock Lock(m_CSNameToUUID); cProfileMap::const_iterator itr = m_NameToUUID.find(lcPlayerName); @@ -300,7 +300,7 @@ AString cMojangAPI::GetPlayerNameFromUUID(const AString & a_UUID, bool a_UseOnly { // Normalize the UUID to lowercase short format that is used as the map key: AString UUID = MakeUUIDShort(a_UUID); - + // Retrieve from caches: { cCSLock Lock(m_CSUUIDToProfile); @@ -325,7 +325,7 @@ AString cMojangAPI::GetPlayerNameFromUUID(const AString & a_UUID, bool a_UseOnly CacheUUIDToProfile(UUID); return GetPlayerNameFromUUID(a_UUID, true); } - + // No value found, none queried. Return an error: return ""; } @@ -342,13 +342,13 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player { PlayerNames.push_back(StrToLower(*itr)); } // for itr - a_PlayerNames[] - + // Request the cache to populate any names not yet contained: if (!a_UseOnlyCached) { CacheNamesToUUIDs(PlayerNames); } - + // Retrieve from cache: size_t idx = 0; AStringVector res; @@ -367,7 +367,7 @@ AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_Player - + void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID) { @@ -475,7 +475,7 @@ AString cMojangAPI::MakeUUIDShort(const AString & a_UUID) // Already is a short UUID, only lowercase return StrToLower(a_UUID); } - + case 36: { // Remove the dashes from the string by appending together the parts between them: @@ -507,7 +507,7 @@ AString cMojangAPI::MakeUUIDDashed(const AString & a_UUID) // Already is a dashed UUID, only lowercase return StrToLower(a_UUID); } - + case 32: { // Insert dashes at the proper positions: @@ -541,7 +541,7 @@ void cMojangAPI::LoadCachesFromDisk(void) SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)"); db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)"); - + // Retrieve all entries: { SQLite::Statement stmt(db, "SELECT PlayerName, UUID, DateTime FROM PlayerNameToUUID"); @@ -587,11 +587,11 @@ void cMojangAPI::SaveCachesToDisk(void) SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)"); db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)"); - + // Remove all entries: db.exec("DELETE FROM PlayerNameToUUID"); db.exec("DELETE FROM UUIDToProfile"); - + // Save all cache entries - m_PlayerNameToUUID: Int64 LimitDateTime = time(nullptr) - MAX_AGE; { @@ -658,7 +658,7 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames) } } // for itr - a_PlayerNames[] } // Lock(m_CSNameToUUID) - + QueryNamesToUUIDs(NamesToQuery); } @@ -720,7 +720,7 @@ void cMojangAPI::QueryNamesToUUIDs(AStringVector & a_NamesToQuery) continue; } Response.erase(0, idxHeadersEnd + 4); - + // Parse the returned string into Json: Json::Reader reader; if (!reader.parse(Response, root, false) || !root.isArray()) @@ -729,7 +729,7 @@ void cMojangAPI::QueryNamesToUUIDs(AStringVector & a_NamesToQuery) LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); continue; } - + // Store the returned results into cache: Json::Value::UInt JsonCount = root.size(); Int64 Now = time(nullptr); @@ -748,7 +748,7 @@ void cMojangAPI::QueryNamesToUUIDs(AStringVector & a_NamesToQuery) NotifyNameUUID(JsonName, JsonUUID); } // for idx - root[] } // cCSLock (m_CSNameToUUID) - + // Also cache the UUIDToName: { cCSLock Lock(m_CSUUIDToName); @@ -774,7 +774,7 @@ void cMojangAPI::QueryNamesToUUIDs(AStringVector & a_NamesToQuery) void cMojangAPI::CacheUUIDToProfile(const AString & a_UUID) { ASSERT(a_UUID.size() == 32); - + // Check if already present: { cCSLock Lock(m_CSUUIDToProfile); @@ -783,7 +783,7 @@ void cMojangAPI::CacheUUIDToProfile(const AString & a_UUID) return; } } - + QueryUUIDToProfile(a_UUID); } @@ -796,7 +796,7 @@ void cMojangAPI::QueryUUIDToProfile(const AString & a_UUID) // Create the request address: AString Address = m_UUIDToProfileAddress; ReplaceString(Address, "%UUID%", a_UUID); - + // Create the HTTP request: AString Request; Request += "GET " + Address + " HTTP/1.0\r\n"; // We need to use HTTP 1.0 because we don't handle Chunked transfer encoding @@ -832,7 +832,7 @@ void cMojangAPI::QueryUUIDToProfile(const AString & a_UUID) return; } Response.erase(0, idxHeadersEnd + 4); - + // Parse the returned string into Json: Json::Reader reader; Json::Value root; @@ -943,7 +943,3 @@ void cMojangAPI::Update(void) } } } - - - - diff --git a/src/Root.cpp b/src/Root.cpp index ed9076268..1fbbaed3c 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -767,7 +767,7 @@ int cRoot::GetVirtualRAMUsage(void) } return -1; #elif defined(__linux__) - // Code adapted from http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process + // Code adapted from https://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process std::ifstream StatFile("/proc/self/status"); if (!StatFile.good()) { @@ -785,7 +785,7 @@ int cRoot::GetVirtualRAMUsage(void) } return -1; #elif defined (__APPLE__) - // Code adapted from http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process + // Code adapted from https://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process struct task_basic_info t_info; mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; @@ -819,7 +819,7 @@ int cRoot::GetPhysicalRAMUsage(void) } return -1; #elif defined(__linux__) - // Code adapted from http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process + // Code adapted from https://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process std::ifstream StatFile("/proc/self/status"); if (!StatFile.good()) { @@ -837,7 +837,7 @@ int cRoot::GetPhysicalRAMUsage(void) } return -1; #elif defined (__APPLE__) - // Code adapted from http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process + // Code adapted from https://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process struct task_basic_info t_info; mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index cc71e048b..76b9fdbde 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -21,7 +21,7 @@ AString & AppendVPrintf(AString & str, const char * format, va_list args) { ASSERT(format != nullptr); - + char buffer[2048]; int len; #ifdef va_copy @@ -47,7 +47,7 @@ AString & AppendVPrintf(AString & str, const char * format, va_list args) #ifdef va_copy va_end(argsCopy); #endif - + // The result did not fit into the static buffer, use a dynamic buffer: #ifdef _MSC_VER // for MS CRT, we need to calculate the result length @@ -57,7 +57,7 @@ AString & AppendVPrintf(AString & str, const char * format, va_list args) return str; } #endif // _MSC_VER - + // Allocate a buffer and printf into it: #ifdef va_copy va_copy(argsCopy, args); @@ -232,7 +232,7 @@ AString TrimString(const AString & str) { return ""; } - + size_t end = len; while (end >= start) { @@ -242,7 +242,7 @@ AString TrimString(const AString & str) } --end; } - + return str.substr(start, end - start + 1); } @@ -396,7 +396,7 @@ AString & RawBEToUTF8(const char * a_RawData, size_t a_NumShorts, AString & a_UT // UTF-8 conversion code adapted from: -// http://stackoverflow.com/questions/2867123/convert-utf-16-to-utf-8-under-windows-and-linux-in-c +// https://stackoverflow.com/questions/2867123/convert-utf-16-to-utf-8-under-windows-and-linux-in-c //////////////////////////////////////////////////////////////////////////////// // Begin of Unicode, Inc.'s code / information @@ -524,7 +524,7 @@ std::u16string UTF8ToRawBEUTF16(const AString & a_UTF8) { return UTF16; } - + // The cases all fall through. See "Note A" below. switch (extraBytesToRead) { @@ -609,7 +609,7 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, siz char line[512]; char * p; char * q; - + a_Out.reserve(a_Size / a_BytesPerLine * (18 + 6 * a_BytesPerLine)); for (size_t i = 0; i < a_Size; i += a_BytesPerLine) { @@ -953,7 +953,7 @@ bool SplitZeroTerminatedStrings(const AString & a_Strings, AStringVector & a_Out a_Output.push_back(a_Strings.substr(start, size - start)); res = true; } - + return res; } @@ -1000,7 +1000,3 @@ AString StringsConcat(const AStringVector & a_Strings, char a_Separator) } return res; } - - - - diff --git a/src/World.h b/src/World.h index 04c9bb4de..e9206e176 100644 --- a/src/World.h +++ b/src/World.h @@ -509,20 +509,11 @@ public: /** Calls the callback for each furnace in the specified chunk; returns true if all furnaces processed, false if the callback aborted by returning true */ bool ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback); // Exported in ManualBindings.cpp - /** Does an explosion with the specified strength at the specified coordinate - a_SourceData exact type depends on the a_Source: - | esOther | void * | - | esPrimedTNT | cTNTEntity * | - | esMonster | cMonster * | - | esBed | cVector3i * | - | esEnderCrystal | Vector3i * | - | esGhastFireball | cGhastFireball * | - | esWitherSkullBlack | TBD | - | esWitherSkullBlue | TBD | - | esWitherBirth | cMonster * | - | esPlugin | void * | - */ - virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData) override; // tolua_export + /** Does an explosion with the specified strength at the specified coordinates. + Executes the HOOK_EXPLODING and HOOK_EXPLODED hooks as part of the processing. + a_SourceData exact type depends on the a_Source, see the declaration of the esXXX constants in BlockID.h for details. + Exported to Lua manually in ManualBindings_World.cpp in order to support the variable a_SourceData param. */ + virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData) override; /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ virtual bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback) override; // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index 70570f7d0..1a81a6469 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -91,7 +91,7 @@ bool cParsedNBT::ReadString(size_t & a_StringStart, size_t & a_StringLen) NEEDBYTES(2); a_StringStart = m_Pos + 2; a_StringLen = static_cast<size_t>(GetBEShort(m_Data + m_Pos)); - NEEDBYTES(a_StringLen); + NEEDBYTES(2 + a_StringLen); m_Pos += 2 + a_StringLen; return true; } @@ -110,7 +110,12 @@ bool cParsedNBT::ReadCompound(void) for (;;) { NEEDBYTES(1); - eTagType TagType = static_cast<eTagType>(m_Data[m_Pos]); + const char TagTypeNum = m_Data[m_Pos]; + if ((TagTypeNum < TAG_Min) || (TagTypeNum > TAG_Max)) + { + return false; + } + eTagType TagType = static_cast<eTagType>(TagTypeNum); m_Pos++; if (TagType == TAG_End) { @@ -258,7 +263,6 @@ bool cParsedNBT::ReadTag(void) #endif case TAG_Min: { - ASSERT(!"Unhandled NBT tag type"); return false; } } // switch (iType) |