From 20b715257284ea486b0bf20358167bea2fe6f7a6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 28 May 2015 13:03:28 +0100 Subject: Potential crash fixes * Potentially addresses my comment in #1969 * Probably fixes #2145 --- src/ClientHandle.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 765ccdee2..9644679d7 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1902,7 +1902,7 @@ void cClientHandle::Tick(float a_Dt) if (m_TicksSinceLastPacket > 600) // 30 seconds time-out { SendDisconnect("Nooooo!! You timed out! D: Come back!"); - Destroy(); + return; } if (m_Player == nullptr) @@ -2013,7 +2013,6 @@ void cClientHandle::ServerTick(float a_Dt) if (m_TicksSinceLastPacket > 600) // 30 seconds { SendDisconnect("Nooooo!! You timed out! D: Come back!"); - Destroy(); } } @@ -2186,6 +2185,7 @@ void cClientHandle::SendDisconnect(const AString & a_Reason) { LOGD("Sending a DC: \"%s\"", StripColorCodes(a_Reason).c_str()); m_Protocol->SendDisconnect(a_Reason); + Destroy(); m_HasSentDC = true; } } @@ -2922,7 +2922,6 @@ void cClientHandle::PacketBufferFull(void) // Too much data in the incoming queue, the server is probably too busy, kick the client: LOGERROR("Too much data in queue for client \"%s\" @ %s, kicking them.", m_Username.c_str(), m_IPString.c_str()); SendDisconnect("Server busy"); - Destroy(); } @@ -2936,7 +2935,6 @@ void cClientHandle::PacketUnknown(UInt32 a_PacketType) AString Reason; Printf(Reason, "Unknown [C->S] PacketType: 0x%x", a_PacketType); SendDisconnect(Reason); - Destroy(); } @@ -2947,7 +2945,6 @@ void cClientHandle::PacketError(UInt32 a_PacketType) { LOGERROR("Protocol error while parsing packet type 0x%02x; disconnecting client \"%s\"", a_PacketType, m_Username.c_str()); SendDisconnect("Protocol error"); - Destroy(); } @@ -2963,7 +2960,7 @@ void cClientHandle::SocketClosed(void) LOGD("Client %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, "Player disconnected"); } - if (m_State < csDestroying) + if ((m_State < csDestroying) && (m_Player != nullptr)) { cWorld * World = m_Player->GetWorld(); if (World != nullptr) -- cgit v1.2.3 From f1540173da442878e132b0bbca1f8f60141e1cd0 Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Thu, 28 May 2015 17:45:47 +0300 Subject: AI - Sane Skeleton --- src/Entities/ArrowEntity.cpp | 21 +++++++++++---------- src/Mobs/AggressiveMonster.cpp | 3 ++- src/Mobs/Monster.cpp | 11 +++++++++-- src/Mobs/Monster.h | 9 ++++++--- src/Mobs/Skeleton.cpp | 7 ++++--- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 32952100c..9b8f77cbc 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -84,7 +84,7 @@ void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFa int X = BlockHit.x, Y = BlockHit.y, Z = BlockHit.z; m_HitBlockPos = Vector3i(X, Y, Z); - + // Broadcast arrow hit sound m_World->BroadcastSoundEffect("random.bowhit", (double)X, (double)Y, (double)Z, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); @@ -115,7 +115,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) Damage += ExtraDamage; } - int KnockbackAmount = 1; + // int KnockbackAmount = 1; int PunchLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPunch); if (PunchLevel > 0) { @@ -130,8 +130,9 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) a_EntityHit.SetSpeed(FinalSpeed); } - a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); - + // a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); // TODO fix knockback. + a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 0); // Until knockback is fixed. + if (IsOnFire() && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming()) { a_EntityHit.StartBurning(100); @@ -139,7 +140,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) // Broadcast successful hit sound GetWorld()->BroadcastSoundEffect("random.successful_hit", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - + Destroy(); } @@ -176,7 +177,7 @@ void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); m_Timer += a_Dt; - + if (m_bIsCollected) { if (m_Timer > std::chrono::milliseconds(500)) @@ -190,7 +191,7 @@ void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Destroy(); return; } - + if (m_IsInGround) { if (!m_HasTeleported) // Sent a teleport already, don't do again @@ -205,17 +206,17 @@ void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) m_HitGroundTimer += a_Dt; } } - + int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - + if (Chunk == nullptr) { // Inside an unloaded chunk, abort return; } - + if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? { m_IsInGround = false; // Yes, begin simulating physics again diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 648599999..93f7cdb72 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -80,9 +80,10 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3d AttackDirection(m_Target->GetPosition() + Vector3d(0, m_Target->GetHeight(), 0) - MyHeadPosition); - if (ReachedFinalDestination() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast(AttackDirection.Length()))) + if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast(AttackDirection.Length()))) { // Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls) + StopMovingToPosition(); Attack(a_Dt); } } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 3fbee9a65..c67850248 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -517,8 +517,15 @@ void cMonster::SetPitchAndYawFromDestination() } - - Vector3d BodyDistance = m_NextWayPointPosition - GetPosition(); + Vector3d BodyDistance; + if (!m_IsFollowingPath && (m_Target != nullptr)) + { + BodyDistance = m_Target->GetPosition() - GetPosition(); + } + else + { + BodyDistance = m_NextWayPointPosition - GetPosition(); + } double BodyRotation, BodyPitch; BodyDistance.Normalize(); VectorToEuler(BodyDistance.x, BodyDistance.y, BodyDistance.z, BodyRotation, BodyPitch); diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index c4043b0e5..fa23df3db 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -193,13 +193,16 @@ protected: If no suitable position is found, returns cChunkDef::Height. */ int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ); - /** Returns if the ultimate, final destination has been reached */ - bool ReachedFinalDestination(void) { return ((m_FinalDestination - GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange)); } + /** Returns if the ultimate, final destination has been reached. */ + bool ReachedFinalDestination(void) { return ((m_FinalDestination - GetPosition()).Length() < GetWidth()/2); } + + /** Returns whether or not the target is close enough for attack. */ + bool TargetIsInRange(void) { return ((m_FinalDestination - GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange)); } /** Returns if the intermediate waypoint of m_NextWayPointPosition has been reached */ bool ReachedNextWaypoint(void) { return ((m_NextWayPointPosition - GetPosition()).SqrLength() < 0.25); } - /** Returns if a monster can reach a given height by jumping */ + /** Returns if a monster can reach a given height by jumping. */ inline bool DoesPosYRequireJump(int a_PosY) { return ((a_PosY > POSY_TOINT) && (a_PosY == POSY_TOINT + 1)); diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index f99404669..d1a481960 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -50,12 +50,13 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSkeleton::Attack(std::chrono::milliseconds a_Dt) { + cFastRandom Random; m_AttackInterval += (static_cast(a_Dt.count()) / 1000) * m_AttackRate; if ((m_Target != nullptr) && (m_AttackInterval > 3.0)) { - // Setting this higher gives us more wiggle room for attackrate - Vector3d Speed = GetLookVector() * 20; - Speed.y = Speed.y + 1; + Vector3d Inaccuracy = Vector3d(Random.NextFloat(0.5) - 0.25, Random.NextFloat(0.5) - 0.25, Random.NextFloat(0.5) - 0.25); + Vector3d Speed = (m_Target->GetPosition() + Inaccuracy - GetPosition()) * 5; + Speed.y = Speed.y - 1 + Random.NextInt(3); cArrowEntity * Arrow = new cArrowEntity(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed); if (Arrow == nullptr) { -- cgit v1.2.3 From e6ba181bd420e148ce86fc6b7a05df23cbddf362 Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Thu, 28 May 2015 22:39:39 +0300 Subject: Removed stray "exit" from compile.sh --- compile.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/compile.sh b/compile.sh index 329d79d81..1e965aecc 100755 --- a/compile.sh +++ b/compile.sh @@ -85,7 +85,6 @@ if [[ $MISSING_PROGRAMS != "" ]]; then missingDepsExit fi -exit # Echo: Branch choice. echo echo "You can choose between 2 branches:" -- cgit v1.2.3 From e7214dff656a7b8b3f71d585ea2a0dd6afeba0d6 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 28 May 2015 22:12:12 +0200 Subject: Updated DumpInfo plugin. cPluginManager:GetAllPlugins is deprecated --- MCServer/Plugins/DumpInfo/Init.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/MCServer/Plugins/DumpInfo/Init.lua b/MCServer/Plugins/DumpInfo/Init.lua index 1faa8d60f..2c5998e36 100644 --- a/MCServer/Plugins/DumpInfo/Init.lua +++ b/MCServer/Plugins/DumpInfo/Init.lua @@ -33,15 +33,17 @@ function HandleDumpPluginRequest(a_Request) ]] -- Loop through each plugin that is found. - for PluginName, k in pairs(cPluginManager:Get():GetAllPlugins()) do - -- Check if there is a file called 'Info.lua' or 'info.lua' - if (cFile:Exists("Plugins/" .. PluginName .. "/Info.lua")) then - Content = Content .. "\n\n" - Content = Content .. "\t" .. PluginName .. "\n" - Content = Content .. "\t
\n" - Content = Content .. "\n" + cPluginManager:Get():ForEachPlugin( + function(a_Plugin) + -- Check if there is a file called 'Info.lua' + if (cFile:Exists("Plugins/" .. a_Plugin:GetName() .. "/Info.lua")) then + Content = Content .. "\n\n" + Content = Content .. "\t" .. a_Plugin:GetName() .. "\n" + Content = Content .. "\t
\n" + Content = Content .. "\n" + end end - end + ) Content = Content .. [[ ]] -- cgit v1.2.3 From 15d49d0cb9819eb9d544f50e8b491ca8f796b743 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 28 May 2015 22:22:59 +0200 Subject: Fixed Info.lua documentation The AdditionalInformation table is called AdditionalInfo --- MCServer/Plugins/APIDump/InfoFile.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/APIDump/InfoFile.html b/MCServer/Plugins/APIDump/InfoFile.html index 3fff06d20..adaae2cb6 100644 --- a/MCServer/Plugins/APIDump/InfoFile.html +++ b/MCServer/Plugins/APIDump/InfoFile.html @@ -15,7 +15,7 @@
  • Introduction
  • The overall structure
  • -
  • AdditionalInformation table
  • +
  • AdditionalInfo table
  • Commands table
  • ConsoleCommands table
  • Permissions table
  • @@ -51,7 +51,7 @@ g_PluginInfo = Description = "This is an example plugin that shows how to use the Info.lua file", -- The following members will be documented in greater detail later: - AdditionalInformation = {}, + AdditionalInfo = {}, Commands = {}, ConsoleCommands = {}, Permissions = {}, @@ -63,13 +63,13 @@ g_PluginInfo =
    -

    AdditionalInformation table

    +

    AdditionalInfo table

    This table is used for more detailed description of the plugin. If there is any non-trivial setup process, dependencies, describe them here. This is where the description should get detailed. Don't worry about using several paragraphs of text here, if it makes the plugin easier to understand.

    The table should have the following layout:

    -AdditionalInformation =
    +AdditionalInfo =
     {
     	{
     		Title = "Chapter 1",
    -- 
    cgit v1.2.3