summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/ManualBindings.cpp5
-rw-r--r--src/Bindings/PluginLua.cpp2
-rw-r--r--src/BlockEntities/CommandBlockEntity.cpp3
-rw-r--r--src/BlockEntities/MobHeadEntity.cpp2
-rw-r--r--src/ByteBuffer.cpp2
-rw-r--r--src/ChunkMap.cpp5
-rw-r--r--src/Entities/Entity.cpp3
-rw-r--r--src/Mobs/AggressiveMonster.cpp4
-rw-r--r--src/Noise.cpp2
-rw-r--r--src/OSSupport/GZipFile.cpp2
-rw-r--r--src/Protocol/Authenticator.cpp33
-rw-r--r--src/Protocol/Protocol17x.cpp8
-rw-r--r--src/Statistics.cpp139
-rw-r--r--src/Statistics.h116
-rw-r--r--src/WebAdmin.cpp5
-rw-r--r--src/WorldStorage/WSSCompact.cpp10
16 files changed, 323 insertions, 18 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 92b410481..b3f75aff1 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -1750,7 +1750,6 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
{
return 0;
}
- cLuaChunkStay * ChunkStay = new cLuaChunkStay(*Plugin);
// Read the params:
cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 1, NULL);
@@ -1760,8 +1759,12 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
L.LogStackTrace();
return 0;
}
+
+ cLuaChunkStay * ChunkStay = new cLuaChunkStay(*Plugin);
+
if (!ChunkStay->AddChunks(2))
{
+ delete ChunkStay;
return 0;
}
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index dcc816839..cb55715a6 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -1042,7 +1042,7 @@ bool cPluginLua::OnPluginMessage(cClientHandle & a_Client, const AString & a_Cha
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLUGIN_MESSAGE];
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
{
- m_LuaState.Call((int)(**itr), &a_Client, a_Channel, a_Message);
+ m_LuaState.Call((int)(**itr), &a_Client, a_Channel, a_Message, cLuaState::Return, res);
if (res)
{
return true;
diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp
index 96ca0ac37..146ad915b 100644
--- a/src/BlockEntities/CommandBlockEntity.cpp
+++ b/src/BlockEntities/CommandBlockEntity.cpp
@@ -21,7 +21,8 @@
cCommandBlockEntity::cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_World) :
super(E_BLOCK_COMMAND_BLOCK, a_X, a_Y, a_Z, a_World),
m_ShouldExecute(false),
- m_IsPowered(false)
+ m_IsPowered(false),
+ m_Result(0)
{}
diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp
index c0a1781f6..dc9c18d58 100644
--- a/src/BlockEntities/MobHeadEntity.cpp
+++ b/src/BlockEntities/MobHeadEntity.cpp
@@ -14,6 +14,8 @@
cMobHeadEntity::cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World),
+ m_Type(SKULL_TYPE_SKELETON),
+ m_Rotation(SKULL_ROTATION_NORTH),
m_Owner("")
{
}
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index c634dc308..24f91b195 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -887,9 +887,7 @@ void cByteBuffer::AdvanceReadPos(size_t a_Count)
void cByteBuffer::CheckValid(void) const
{
- ASSERT(m_ReadPos >= 0);
ASSERT(m_ReadPos < m_BufferSize);
- ASSERT(m_WritePos >= 0);
ASSERT(m_WritePos < m_BufferSize);
}
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 0fb6988b5..537d491c9 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1654,7 +1654,10 @@ void cChunkMap::AddEntity(cEntity * a_Entity)
{
cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ());
- if ((Chunk == NULL) || !Chunk->IsValid())
+ if (
+ (Chunk == NULL) || // Chunk not present at all
+ (!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
+ )
{
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
a_Entity, a_Entity->GetClass(), a_Entity->GetUniqueID()
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 7c8e18b51..2d325805b 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -53,6 +53,8 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d
, m_TicksSinceLastVoidDamage(0)
, m_IsSwimming(false)
, m_IsSubmerged(false)
+ , m_AirLevel(0)
+ , m_AirTickTimer(0)
, m_HeadYaw( 0.0 )
, m_Rot(0.0, 0.0, 0.0)
, m_Pos(a_X, a_Y, a_Z)
@@ -441,6 +443,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType)
}
}
ASSERT(!"Invalid damage type!");
+ return false;
}
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 3e5f72dbf..447bf3549 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -108,14 +108,14 @@ void cAggressiveMonster::Attack(float a_Dt)
bool cAggressiveMonster::IsMovingToTargetPosition()
{
- float epsilon = 0.000000000001;
+ static const float epsilon = 0.000000000001f;
// Difference between destination x and target x is negligible (to 10^-12 precision)
if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon)
{
return false;
}
// Difference between destination z and target z is negligible (to 10^-12 precision)
- else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon)
+ else if (fabsf((float)m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon)
{
return false;
}
diff --git a/src/Noise.cpp b/src/Noise.cpp
index efbb128c3..95a022ea3 100644
--- a/src/Noise.cpp
+++ b/src/Noise.cpp
@@ -744,6 +744,8 @@ void cCubicNoise::CalcFloorFrac(
int * a_Same, int & a_NumSame
) const
{
+ ASSERT(a_Size > 0);
+
NOISE_DATATYPE val = a_Start;
NOISE_DATATYPE dif = (a_End - a_Start) / (a_Size - 1);
for (int i = 0; i < a_Size; i++)
diff --git a/src/OSSupport/GZipFile.cpp b/src/OSSupport/GZipFile.cpp
index 7a8433f4f..22d887783 100644
--- a/src/OSSupport/GZipFile.cpp
+++ b/src/OSSupport/GZipFile.cpp
@@ -11,7 +11,7 @@
cGZipFile::cGZipFile(void) :
- m_File(NULL)
+ m_File(NULL), m_Mode(fmRead)
{
}
diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp
index e0fcc0007..bbc656eda 100644
--- a/src/Protocol/Authenticator.cpp
+++ b/src/Protocol/Authenticator.cpp
@@ -165,6 +165,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)pers, strlen(pers))) != 0)
{
LOGWARNING("cAuthenticator: ctr_drbg_init returned %d", ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ entropy_free(&entropy);
return false;
}
@@ -175,6 +179,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if (ret < 0)
{
LOGWARNING("cAuthenticator: x509_crt_parse returned -0x%x", -ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ entropy_free(&entropy);
return false;
}
@@ -182,6 +190,10 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret = net_connect(&server_fd, m_Server.c_str(), 443)) != 0)
{
LOGWARNING("cAuthenticator: Can't connect to %s: %d", m_Server.c_str(), ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ entropy_free(&entropy);
return false;
}
@@ -189,6 +201,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret = ssl_init(&ssl)) != 0)
{
LOGWARNING("cAuthenticator: ssl_init returned %d", ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ net_close(server_fd);
+ ssl_free(&ssl);
+ entropy_free(&entropy);
+ memset(&ssl, 0, sizeof(ssl));
return false;
}
ssl_set_endpoint(&ssl, SSL_IS_CLIENT);
@@ -203,6 +222,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if ((ret != POLARSSL_ERR_NET_WANT_READ) && (ret != POLARSSL_ERR_NET_WANT_WRITE))
{
LOGWARNING("cAuthenticator: ssl_handshake returned -0x%x", -ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ net_close(server_fd);
+ ssl_free(&ssl);
+ entropy_free(&entropy);
+ memset(&ssl, 0, sizeof(ssl));
return false;
}
}
@@ -223,6 +249,13 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
if (ret <= 0)
{
LOGWARNING("cAuthenticator: ssl_write returned %d", ret);
+
+ // Free all resources which have been initialized up to this line
+ x509_crt_free(&cacert);
+ net_close(server_fd);
+ ssl_free(&ssl);
+ entropy_free(&entropy);
+ memset(&ssl, 0, sizeof(ssl));
return false;
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 2cc0adbfb..6fa928215 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -639,9 +639,11 @@ void cProtocol172::SendLoginSuccess(void)
{
ASSERT(m_State == 2); // State: login?
- cPacketizer Pkt(*this, 0x02); // Login success packet
- Pkt.WriteString(m_Client->GetUUID());
- Pkt.WriteString(m_Client->GetUsername());
+ {
+ cPacketizer Pkt(*this, 0x02); // Login success packet
+ Pkt.WriteString(m_Client->GetUUID());
+ Pkt.WriteString(m_Client->GetUsername());
+ }
m_State = 3; // State = Game
}
diff --git a/src/Statistics.cpp b/src/Statistics.cpp
new file mode 100644
index 000000000..2c980d98e
--- /dev/null
+++ b/src/Statistics.cpp
@@ -0,0 +1,139 @@
+
+// Statistics.cpp
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "Statistics.h"
+
+
+
+cStatInfo cStatInfo::ms_Info[statCount] = {
+ // The order must match the order of enum eStatistic
+
+ // http://minecraft.gamepedia.com/Achievements
+
+ /* Type | Name | Prerequisite */
+ cStatInfo(achOpenInv, "openInventory"),
+ cStatInfo(achMineWood, "mineWood", achOpenInv),
+ cStatInfo(achCraftWorkbench, "buildWorkBench", achMineWood),
+ cStatInfo(achCraftPickaxe, "buildPickaxe", achCraftWorkbench),
+ cStatInfo(achCraftFurnace, "buildFurnace", achCraftPickaxe),
+ cStatInfo(achAcquireIron, "acquireIron", achCraftFurnace),
+ cStatInfo(achCraftHoe, "buildHoe", achCraftWorkbench),
+ cStatInfo(achMakeBread, "makeBread", achCraftHoe),
+ cStatInfo(achBakeCake, "bakeCake", achCraftHoe),
+ cStatInfo(achCraftBetterPick, "buildBetterPickaxe", achCraftPickaxe),
+ cStatInfo(achCookFish, "cookFish", achAcquireIron),
+ cStatInfo(achOnARail, "onARail", achAcquireIron),
+ cStatInfo(achCraftSword, "buildSword", achCraftWorkbench),
+ cStatInfo(achKillMonster, "killEnemy", achCraftSword),
+ cStatInfo(achKillCow, "killCow", achCraftSword),
+ cStatInfo(achFlyPig, "flyPig", achKillCow),
+ cStatInfo(achSnipeSkeleton, "snipeSkeleton", achKillMonster),
+ cStatInfo(achDiamonds, "diamonds", achAcquireIron),
+ cStatInfo(achEnterPortal, "portal", achDiamonds),
+ cStatInfo(achReturnToSender, "ghast", achEnterPortal),
+ cStatInfo(achBlazeRod, "blazeRod", achEnterPortal),
+ cStatInfo(achBrewPotion, "potion", achBlazeRod),
+ cStatInfo(achEnterTheEnd, "theEnd", achBlazeRod),
+ cStatInfo(achDefeatDragon, "theEnd2", achEnterTheEnd),
+ cStatInfo(achCraftEnchantTable, "enchantments", achDiamonds),
+ cStatInfo(achOverkill, "overkill", achCraftEnchantTable),
+ cStatInfo(achBookshelf, "bookcase", achCraftEnchantTable),
+ cStatInfo(achExploreAllBiomes, "exploreAllBiomes", achEnterTheEnd),
+ cStatInfo(achSpawnWither, "spawnWither", achDefeatDragon),
+ cStatInfo(achKillWither, "killWither", achSpawnWither),
+ cStatInfo(achFullBeacon, "fullBeacon", achKillWither),
+ cStatInfo(achBreedCow, "breedCow", achKillCow),
+ cStatInfo(achThrowDiamonds, "diamondsToYou", achDiamonds),
+
+ // http://minecraft.gamepedia.com/Statistics
+
+ /* Type | Name */
+ cStatInfo(statGamesQuit, "stat.leaveGame"),
+ cStatInfo(statMinutesPlayed, "stat.playOneMinute"),
+ cStatInfo(statDistWalked, "stat.walkOnCm"),
+ cStatInfo(statDistSwum, "stat.swimOneCm"),
+ cStatInfo(statDistFallen, "stat.fallOneCm"),
+ cStatInfo(statDistClimbed, "stat.climbOneCm"),
+ cStatInfo(statDistFlown, "stat.flyOneCm"),
+ cStatInfo(statDistMinecart, "stat.minecartOneCm"),
+ cStatInfo(statDistBoat, "stat.boatOneCm"),
+ cStatInfo(statDistPig, "stat.pigOneCm"),
+ cStatInfo(statDistHorse, "stat.horseOneCm"),
+ cStatInfo(statJumps, "stat.jump"),
+ cStatInfo(statItemsDropped, "stat.drop"),
+ cStatInfo(statDamageDealt, "stat.damageDealth"),
+ cStatInfo(statDamageTaken, "stat.damageTaken"),
+ cStatInfo(statDeaths, "stat.deaths"),
+ cStatInfo(statMobKills, "stat.mobKills"),
+ cStatInfo(statAnimalsBred, "stat.animalsBred"),
+ cStatInfo(statPlayerKills, "stat.playerKills"),
+ cStatInfo(statFishCaught, "stat.fishCaught"),
+ cStatInfo(statJunkFished, "stat.junkFished"),
+ cStatInfo(statTreasureFished, "stat.treasureFished")
+};
+
+
+
+
+
+
+cStatInfo::cStatInfo()
+ : m_Type(statInvalid)
+ , m_Depends(statInvalid)
+{}
+
+
+
+
+
+cStatInfo::cStatInfo(const eStatistic a_Type, const AString & a_Name, const eStatistic a_Depends)
+ : m_Type(a_Type)
+ , m_Name(a_Name)
+ , m_Depends(a_Depends)
+{}
+
+
+
+
+
+const AString & cStatInfo::GetName(const eStatistic a_Type)
+{
+ ASSERT((a_Type > statInvalid) && (a_Type < statCount));
+
+ return ms_Info[a_Type].m_Name;
+}
+
+
+
+
+
+eStatistic cStatInfo::GetType(const AString & a_Name)
+{
+ for (unsigned int i = 0; i < ARRAYCOUNT(ms_Info); ++i)
+ {
+ if (NoCaseCompare(ms_Info[i].m_Name, a_Name))
+ {
+ return ms_Info[i].m_Type;
+ }
+ }
+
+ return statInvalid;
+}
+
+
+
+
+
+eStatistic cStatInfo::GetPrerequisite(const eStatistic a_Type)
+{
+ ASSERT((a_Type > statInvalid) && (a_Type < statCount));
+
+ return ms_Info[a_Type].m_Depends;
+}
+
+
+
+
+
diff --git a/src/Statistics.h b/src/Statistics.h
new file mode 100644
index 000000000..540df38cc
--- /dev/null
+++ b/src/Statistics.h
@@ -0,0 +1,116 @@
+
+// Statistics.h
+
+
+
+
+#pragma once
+
+
+
+
+enum eStatistic
+{
+ // The order must match the order of cStatInfo::ms_Info
+
+ statInvalid = -1,
+
+ /* Achievements */
+ achOpenInv, /* Taking Inventory */
+ achMineWood, /* Getting Wood */
+ achCraftWorkbench, /* Benchmarking */
+ achCraftPickaxe, /* Time to Mine! */
+ achCraftFurnace, /* Hot Topic */
+ achAcquireIron, /* Acquire Hardware */
+ achCraftHoe, /* Time to Farm! */
+ achMakeBread, /* Bake Bread */
+ achBakeCake, /* The Lie */
+ achCraftBetterPick, /* Getting an Upgrade */
+ achCookFish, /* Delicious Fish */
+ achOnARail, /* On A Rail */
+ achCraftSword, /* Time to Strike! */
+ achKillMonster, /* Monster Hunter */
+ achKillCow, /* Cow Tipper */
+ achFlyPig, /* When Pigs Fly */
+ achSnipeSkeleton, /* Sniper Duel */
+ achDiamonds, /* DIAMONDS! */
+ achEnterPortal, /* We Need to Go Deeper */
+ achReturnToSender, /* Return to Sender */
+ achBlazeRod, /* Into Fire */
+ achBrewPotion, /* Local Brewery */
+ achEnterTheEnd, /* The End? */
+ achDefeatDragon, /* The End. */
+ achCraftEnchantTable, /* Enchanter */
+ achOverkill, /* Overkill */
+ achBookshelf, /* Librarian */
+ achExploreAllBiomes, /* Adventuring Time */
+ achSpawnWither, /* The Beginning? */
+ achKillWither, /* The Beginning. */
+ achFullBeacon, /* Beaconator */
+ achBreedCow, /* Repopulation */
+ achThrowDiamonds, /* Diamonds to you! */
+
+ /* Statistics */
+ statGamesQuit,
+ statMinutesPlayed,
+ statDistWalked,
+ statDistSwum,
+ statDistFallen,
+ statDistClimbed,
+ statDistFlown,
+ statDistDove,
+ statDistMinecart,
+ statDistBoat,
+ statDistPig,
+ statDistHorse,
+ statJumps,
+ statItemsDropped,
+ statDamageDealt,
+ statDamageTaken,
+ statDeaths,
+ statMobKills,
+ statAnimalsBred,
+ statPlayerKills,
+ statFishCaught,
+ statJunkFished,
+ statTreasureFished,
+
+ statCount
+};
+
+
+
+
+
+
+/** Class used to store and query statistic-related information. */
+class cStatInfo
+{
+public:
+
+ cStatInfo();
+
+ cStatInfo(const eStatistic a_Type, const AString & a_Name, const eStatistic a_Depends = statInvalid);
+
+ /** Type -> Name */
+ static const AString & GetName(const eStatistic a_Type);
+
+ /** Name -> Type */
+ static eStatistic GetType(const AString & a_Name);
+
+ /** Returns stat prerequisite. (Used for achievements) */
+ static eStatistic GetPrerequisite(const eStatistic a_Type);
+
+private:
+
+ eStatistic m_Type;
+
+ AString m_Name;
+
+ eStatistic m_Depends;
+
+ static cStatInfo ms_Info[statCount];
+};
+
+
+
diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp
index a3b3cc5be..737705d7c 100644
--- a/src/WebAdmin.cpp
+++ b/src/WebAdmin.cpp
@@ -285,11 +285,6 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
Content = GetDefaultPage();
}
- if (ShouldWrapInTemplate && (URL.size() > 1))
- {
- Content += "\n<p><a href='" + BaseURL + "'>Go back</a></p>";
- }
-
int MemUsageKiB = cRoot::GetPhysicalRAMUsage();
if (MemUsageKiB > 0)
{
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index c07c9e96f..359bac4a8 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -468,7 +468,15 @@ cWSSCompact::cPAKFile::cPAKFile(const AString & a_FileName, int a_LayerX, int a_
for (int i = 0; i < NumChunks; i++)
{
sChunkHeader * Header = new sChunkHeader;
- READ(*Header);
+
+ // Here we do not use the READ macro, as it does not free the resources
+ // allocated with new in case of error.
+ if (f.Read(Header, sizeof(*Header)) != sizeof(*Header))
+ {
+ LOGERROR("ERROR READING %s FROM FILE %s (line %d); file offset %d", "Header", m_FileName.c_str(), __LINE__, f.Tell());
+ delete Header;
+ return;
+ }
m_ChunkHeaders.push_back(Header);
} // for i - chunk headers